真机调试
This commit is contained in:
parent
c430e7da64
commit
19bf72e848
|
|
@ -1,16 +0,0 @@
|
|||
{ // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
|
||||
// launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数
|
||||
"version": "0.0",
|
||||
"configurations": [{
|
||||
"default" :
|
||||
{
|
||||
"launchtype" : "local"
|
||||
},
|
||||
"mp-weixin" :
|
||||
{
|
||||
"launchtype" : "local"
|
||||
},
|
||||
"type" : "uniCloud"
|
||||
}
|
||||
]
|
||||
}
|
||||
87
App.vue
87
App.vue
|
|
@ -1,93 +1,16 @@
|
|||
<script>
|
||||
import { initLogFiles } from './utils/logManager.js';
|
||||
|
||||
export default {
|
||||
created() {
|
||||
// #ifdef APP-PLUS
|
||||
plus.navigator.closeSplashscreen();
|
||||
|
||||
|
||||
// #endif
|
||||
},
|
||||
// onLaunch: function() {
|
||||
// uni.removeStorageSync('userInfo');
|
||||
// const updateManager = uni.getUpdateManager(); //本API返回全局唯一的版本更新管理器对象: updateManager,用于管理小程序更新。
|
||||
// console.log('---------------------');
|
||||
// console.log(updateManager);
|
||||
// updateManager.onCheckForUpdate((res) => { //当向小程序后台请求完新版本信息,进行回调方法
|
||||
// if (res.hasUpdate) {
|
||||
// updateManager.onUpdateReady((res) => { //当新版本下载完成,会进行回调
|
||||
// uni.showModal({
|
||||
// title: '更新提示',
|
||||
// content: '新版本已经准备好,是否重启应用?',
|
||||
// success(res) {
|
||||
// if (res.confirm) {
|
||||
// // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
// updateManager.applyUpdate();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// updateManager.onUpdateFailed((res) => {
|
||||
// // 新的版本下载失败
|
||||
// uni.showModal({
|
||||
// title: '更新提示',
|
||||
// content: '检查到有新版本,但下载失败,请检查网络设置',
|
||||
// success(res) {
|
||||
// if (res.confirm) {
|
||||
// // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
// updateManager.applyUpdate();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// })
|
||||
|
||||
// // #ifdef APP-PLUS
|
||||
// let userInfo = uni.getStorageSync('userInfo') || '';
|
||||
// console.log("看看缓存",uni.getStorageInfoSync())
|
||||
// console.log("看看缓存token",uni.getStorageSync('token'))
|
||||
// console.log("看看缓存userInfo",uni.getStorageSync('userInfo'))
|
||||
// if(userInfo.id){
|
||||
// uni.getStorage({
|
||||
// key:"token",
|
||||
// success: (res) => {
|
||||
// this.globalData.token = res.token
|
||||
// },
|
||||
// fail: (res) => {
|
||||
// console.log("获取token时出错",res)
|
||||
// }
|
||||
// })
|
||||
// uni.getStorage({
|
||||
// key: 'userInfo',
|
||||
// success: (res) => {
|
||||
// // this.login(res.data)
|
||||
// this.globalData.userInfo = res.userInfo
|
||||
// uni.redirectTo({
|
||||
// url:"/pages/speakingPage/speakingPage",
|
||||
// fail: (res) => {
|
||||
// console.log("页面跳转失败",res)
|
||||
// }
|
||||
// })
|
||||
// },
|
||||
// fail: (res) => {
|
||||
// console.log("获取userInfo时出错",res)
|
||||
// }
|
||||
// })
|
||||
|
||||
// }else{
|
||||
// uni.redirectTo({
|
||||
// url:"/pages/login/login",
|
||||
// fail:function(mes){
|
||||
// console.log(mes)
|
||||
// },
|
||||
// success:function(mes){
|
||||
// console.log(mes)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// // #endif
|
||||
// },
|
||||
onLaunch(options) {
|
||||
// 初始化日志文件系统(解决真机调试问题)
|
||||
initLogFiles();
|
||||
|
||||
uni.setInnerAudioOption({
|
||||
obeyMuteSwitch: false
|
||||
});
|
||||
|
|
|
|||
|
|
@ -53,11 +53,20 @@
|
|||
"libVersion" : "latest",
|
||||
"appid" : "wx58ed81cb59afda38",
|
||||
"setting" : {
|
||||
"urlCheck" : false
|
||||
"urlCheck" : false,
|
||||
"es6" : true,
|
||||
"postcss" : true,
|
||||
"minified" : true
|
||||
},
|
||||
"usingComponents" : true,
|
||||
"optimization" : {
|
||||
"subPackages" : true //是否启用分包优化
|
||||
},
|
||||
"debug" : false,
|
||||
"permission" : {
|
||||
"scope.userLocation" : {
|
||||
"desc" : "你的位置信息将用于小程序位置接口的效果展示"
|
||||
}
|
||||
}
|
||||
},
|
||||
"mp-alipay" : {
|
||||
|
|
|
|||
82
project.config.json
Normal file
82
project.config.json
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
{
|
||||
"description": "项目配置文件",
|
||||
"packOptions": {
|
||||
"ignore": [
|
||||
{
|
||||
"type": "file",
|
||||
"value": ".eslintrc.js"
|
||||
}
|
||||
]
|
||||
},
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"es6": true,
|
||||
"enhance": true,
|
||||
"postcss": true,
|
||||
"preloadBackgroundData": false,
|
||||
"minified": true,
|
||||
"newFeature": false,
|
||||
"coverView": true,
|
||||
"nodeModules": false,
|
||||
"autoAudits": false,
|
||||
"showShadowRootInWxmlPanel": true,
|
||||
"scopeDataCheck": false,
|
||||
"uglifyFileName": false,
|
||||
"checkInvalidKey": true,
|
||||
"checkSiteMap": true,
|
||||
"uploadWithSourceMap": true,
|
||||
"compileHotReLoad": false,
|
||||
"lazyloadPlaceholderEnable": false,
|
||||
"useMultiFrameRuntime": true,
|
||||
"useApiHook": true,
|
||||
"useApiHostProcess": true,
|
||||
"babelSetting": {
|
||||
"ignore": [],
|
||||
"disablePlugins": [],
|
||||
"outputPath": ""
|
||||
},
|
||||
"enableEngineNative": false,
|
||||
"useIsolateContext": true,
|
||||
"userConfirmedBundleSwitch": false,
|
||||
"packNpmManually": false,
|
||||
"packNpmRelationList": [],
|
||||
"minifyWXSS": true,
|
||||
"disableUseStrict": false,
|
||||
"minifyWXML": true,
|
||||
"showES6CompileOption": false,
|
||||
"useCompilerPlugins": false
|
||||
},
|
||||
"compileType": "miniprogram",
|
||||
"libVersion": "2.19.4",
|
||||
"appid": "wx58ed81cb59afda38",
|
||||
"projectname": "buddhism",
|
||||
"debugOptions": {
|
||||
"hidedInDevtools": []
|
||||
},
|
||||
"scripts": {},
|
||||
"staticServerOptions": {
|
||||
"baseURL": "",
|
||||
"servePath": ""
|
||||
},
|
||||
"isGameTourist": false,
|
||||
"condition": {
|
||||
"search": {
|
||||
"list": []
|
||||
},
|
||||
"conversation": {
|
||||
"list": []
|
||||
},
|
||||
"game": {
|
||||
"list": []
|
||||
},
|
||||
"plugin": {
|
||||
"list": []
|
||||
},
|
||||
"gamePlugin": {
|
||||
"list": []
|
||||
},
|
||||
"miniprogram": {
|
||||
"list": []
|
||||
}
|
||||
}
|
||||
}
|
||||
78
utils/debug.js
Normal file
78
utils/debug.js
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* 调试工具函数
|
||||
* 提供安全的日志输出方法,避免真机调试时的文件系统问题
|
||||
*/
|
||||
|
||||
// 是否启用调试模式
|
||||
const DEBUG_MODE = false;
|
||||
|
||||
/**
|
||||
* 安全的日志输出
|
||||
* @param {string} message - 日志消息
|
||||
* @param {string} type - 日志类型 (log, warn, error)
|
||||
*/
|
||||
export function safeLog(message, type = 'log') {
|
||||
if (!DEBUG_MODE) return;
|
||||
|
||||
try {
|
||||
switch (type) {
|
||||
case 'warn':
|
||||
console.warn(message);
|
||||
break;
|
||||
case 'error':
|
||||
console.error(message);
|
||||
break;
|
||||
default:
|
||||
console.log(message);
|
||||
}
|
||||
} catch (e) {
|
||||
// 如果console输出失败,使用uni.showToast
|
||||
uni.showToast({
|
||||
title: typeof message === 'string' ? message : '调试信息',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全的错误处理
|
||||
* @param {Error} error - 错误对象
|
||||
* @param {string} context - 错误上下文
|
||||
*/
|
||||
export function safeError(error, context = '') {
|
||||
if (!DEBUG_MODE) return;
|
||||
|
||||
try {
|
||||
console.error(`[${context}]`, error);
|
||||
} catch (e) {
|
||||
uni.showToast({
|
||||
title: `错误: ${context}`,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调试信息输出
|
||||
* @param {string} message - 调试信息
|
||||
*/
|
||||
export function debug(message) {
|
||||
safeLog(message, 'log');
|
||||
}
|
||||
|
||||
/**
|
||||
* 警告信息输出
|
||||
* @param {string} message - 警告信息
|
||||
*/
|
||||
export function warn(message) {
|
||||
safeLog(message, 'warn');
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误信息输出
|
||||
* @param {string} message - 错误信息
|
||||
*/
|
||||
export function error(message) {
|
||||
safeLog(message, 'error');
|
||||
}
|
||||
143
utils/logManager.js
Normal file
143
utils/logManager.js
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/**
|
||||
* 日志管理工具
|
||||
* 解决微信小程序真机调试时的日志文件访问问题
|
||||
*/
|
||||
|
||||
/**
|
||||
* 初始化日志文件系统
|
||||
* 在应用启动时调用,确保日志文件存在
|
||||
*/
|
||||
export function initLogFiles() {
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
const fs = wx.getFileSystemManager();
|
||||
const logDirPath = `${wx.env.USER_DATA_PATH}/miniprogramLog`;
|
||||
const logFiles = ['log1', 'log2', 'log3'];
|
||||
|
||||
// 检查并创建日志文件的函数
|
||||
function checkAndCreateFiles() {
|
||||
logFiles.forEach(fileName => {
|
||||
const filePath = `${logDirPath}/${fileName}`;
|
||||
fs.access({
|
||||
path: filePath,
|
||||
success: () => {
|
||||
console.log(`Log file ${fileName} exists`);
|
||||
},
|
||||
fail: () => {
|
||||
console.log(`Log file ${fileName} does not exist, creating it`);
|
||||
fs.writeFile({
|
||||
filePath: filePath,
|
||||
data: '',
|
||||
success: () => {
|
||||
console.log(`Log file ${fileName} created successfully`);
|
||||
},
|
||||
fail: err => {
|
||||
console.error(`Failed to create log file ${fileName}`, err);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 创建目录
|
||||
fs.access({
|
||||
path: logDirPath,
|
||||
success: () => {
|
||||
console.log('Log directory exists');
|
||||
checkAndCreateFiles();
|
||||
},
|
||||
fail: () => {
|
||||
console.log('Log directory does not exist, creating it');
|
||||
fs.mkdir({
|
||||
dirPath: logDirPath,
|
||||
success: () => {
|
||||
console.log('Log directory created successfully');
|
||||
checkAndCreateFiles();
|
||||
},
|
||||
fail: err => {
|
||||
console.error('Failed to create log directory', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize log files:', error);
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全的日志写入
|
||||
* @param {string} message - 日志消息
|
||||
* @param {string} level - 日志级别 (info, warn, error)
|
||||
*/
|
||||
export function writeLog(message, level = 'info') {
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
const fs = wx.getFileSystemManager();
|
||||
const logDirPath = `${wx.env.USER_DATA_PATH}/miniprogramLog`;
|
||||
const timestamp = new Date().toISOString();
|
||||
const logEntry = `[${timestamp}] [${level.toUpperCase()}] ${message}\n`;
|
||||
|
||||
fs.appendFile({
|
||||
filePath: `${logDirPath}/log1`,
|
||||
data: logEntry,
|
||||
success: () => {
|
||||
// 日志写入成功
|
||||
},
|
||||
fail: err => {
|
||||
console.error('Failed to write log:', err);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to write log:', error);
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理旧日志文件
|
||||
*/
|
||||
export function cleanOldLogs() {
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
const fs = wx.getFileSystemManager();
|
||||
const logDirPath = `${wx.env.USER_DATA_PATH}/miniprogramLog`;
|
||||
|
||||
fs.readdir({
|
||||
dirPath: logDirPath,
|
||||
success: (res) => {
|
||||
const files = res.files;
|
||||
const now = Date.now();
|
||||
const maxAge = 7 * 24 * 60 * 60 * 1000; // 7天
|
||||
|
||||
files.forEach(fileName => {
|
||||
const filePath = `${logDirPath}/${fileName}`;
|
||||
fs.stat({
|
||||
path: filePath,
|
||||
success: (statRes) => {
|
||||
if (now - statRes.stats.lastAccessedTime > maxAge) {
|
||||
fs.unlink({
|
||||
filePath: filePath,
|
||||
success: () => {
|
||||
console.log(`Deleted old log file: ${fileName}`);
|
||||
},
|
||||
fail: err => {
|
||||
console.error(`Failed to delete old log file: ${fileName}`, err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
fail: err => {
|
||||
console.error('Failed to read log directory:', err);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to clean old logs:', error);
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ export function navigateToPage(pageType, options = {}) {
|
|||
const targetPage = PAGE_TYPE_MAP[pageType];
|
||||
|
||||
if (!targetPage) {
|
||||
console.error('未知的页面类型:', pageType);
|
||||
// 使用uni.showToast替代console,减少文件系统访问
|
||||
uni.showToast({
|
||||
title: '页面配置错误',
|
||||
icon: 'none'
|
||||
|
|
@ -56,7 +56,7 @@ export function navigateToPage(pageType, options = {}) {
|
|||
const defaultOptions = {
|
||||
url: targetPage,
|
||||
fail: (err) => {
|
||||
console.error('页面跳转失败:', err);
|
||||
// 避免在真机调试时输出过多日志
|
||||
uni.showToast({
|
||||
title: '页面开发中',
|
||||
icon: 'none'
|
||||
|
|
@ -83,14 +83,20 @@ export function switchToTab(pageType) {
|
|||
const targetPage = tabRoutes[pageType];
|
||||
|
||||
if (!targetPage) {
|
||||
console.error('未知的TabBar页面类型:', pageType);
|
||||
uni.showToast({
|
||||
title: '页面配置错误',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
uni.switchTab({
|
||||
url: targetPage,
|
||||
fail: (err) => {
|
||||
console.error('TabBar页面跳转失败:', err);
|
||||
uni.showToast({
|
||||
title: '跳转失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user