|
|
@@ -13,7 +13,9 @@ const util = require('./utils/util.js')
|
|
|
const baseMethod = require('./api/pages/baseMethod.js')
|
|
|
const baseRoute = require('./api/pages/baseRoute.js')
|
|
|
//初始化国际化语言设置
|
|
|
-const LangUtils = require( './utils/LangUtils')
|
|
|
+const LangUtils = require('./utils/LangUtils')
|
|
|
+//app.js
|
|
|
+const api = require('/utils/api.js');
|
|
|
|
|
|
// 引入文件系统管理器模块
|
|
|
const fs = wx.getFileSystemManager();
|
|
|
@@ -21,45 +23,50 @@ const fs = wx.getFileSystemManager();
|
|
|
const folderPath = '/api/pages'; // 将此处的'/path/to/folder'替换为实际的文件夹路径
|
|
|
// 定义递归函数,用于读取指定目录下所有的.js文件
|
|
|
function readJsFiles(dirPath) {
|
|
|
- let returnFiles = []
|
|
|
+ let returnFiles = []
|
|
|
// 读取当前目录下的文件列表
|
|
|
const files = fs.readdirSync(dirPath);
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
|
const file = files[i];
|
|
|
// 构建完整路径
|
|
|
- let fullpath = dirPath + '/' + file;
|
|
|
+ let fullpath = dirPath + '/' + file;
|
|
|
|
|
|
// 如果是js文件就返回
|
|
|
if (file.endsWith('.js')) {
|
|
|
// fullpath = '@' + fullpath
|
|
|
- console.log('f1',fullpath);
|
|
|
+ console.log('f1', fullpath);
|
|
|
let item = require(fullpath);
|
|
|
- console.log('f2',item);
|
|
|
- if(file != 'baseMethod.js' && file != 'baseRoute.js'){
|
|
|
- item.name = file.replace('.js','');
|
|
|
+ console.log('f2', item);
|
|
|
+ if (file != 'baseMethod.js' && file != 'baseRoute.js') {
|
|
|
+ item.name = file.replace('.js', '');
|
|
|
returnFiles.push(item);
|
|
|
}
|
|
|
- }else if(fs.statSync(fullpath).isDirectory()){
|
|
|
- console.log('b3',fullpath);
|
|
|
+ } else if (fs.statSync(fullpath).isDirectory()) {
|
|
|
+ console.log('b3', fullpath);
|
|
|
// 如果是文件夹则递归调用自身处理子级文件夹
|
|
|
let returns = readJsFiles(fullpath);
|
|
|
- returns.forEach(it=>{
|
|
|
+ returns.forEach(it => {
|
|
|
returnFiles.push(it);
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
return returnFiles;
|
|
|
}
|
|
|
-function setRouteService(){
|
|
|
-
|
|
|
+function setRouteService() {
|
|
|
+
|
|
|
}
|
|
|
App({
|
|
|
- onLaunch() {
|
|
|
+ onLaunch() {
|
|
|
console.log("onLaunch");
|
|
|
// LangUtils.setTabBarLang();
|
|
|
},
|
|
|
+
|
|
|
+
|
|
|
globalData: {
|
|
|
userInfo: null,
|
|
|
+ openid: null,
|
|
|
+ unionid: null,
|
|
|
+ sessionkey: null,
|
|
|
},
|
|
|
})
|
|
|
try {
|
|
|
@@ -67,30 +74,30 @@ try {
|
|
|
let files = readJsFiles(folderPath);
|
|
|
let app = getApp();
|
|
|
let routeUrl = {}
|
|
|
- files.forEach(m=>{
|
|
|
+ files.forEach(m => {
|
|
|
// console.log('values',values,m['routeUrl']);
|
|
|
- app.globalData[Object.keys(m)[0]] =Object.assign( Object.values(m)[0],baseMethod.baseService)
|
|
|
+ app.globalData[Object.keys(m)[0]] = Object.assign(Object.values(m)[0], baseMethod.baseService)
|
|
|
// 如果没有路由,就建一个路由
|
|
|
- if(!m['routeUrl']){
|
|
|
+ if (!m['routeUrl']) {
|
|
|
m['routeUrl'] = {}
|
|
|
m['routeUrl'][m.name] = {}
|
|
|
// 加入共通路由
|
|
|
- m['routeUrl'][m.name] = Object.assign(m['routeUrl'][m.name],baseRoute.routeUrl)
|
|
|
- }else{
|
|
|
- util.objectMergeByMainJs(m['routeUrl'][m.name],baseRoute.routeUrl)
|
|
|
+ m['routeUrl'][m.name] = Object.assign(m['routeUrl'][m.name], baseRoute.routeUrl)
|
|
|
+ } else {
|
|
|
+ util.objectMergeByMainJs(m['routeUrl'][m.name], baseRoute.routeUrl)
|
|
|
}
|
|
|
- if(m.name != 'common'){
|
|
|
+ if (m.name != 'common') {
|
|
|
routeUrl[m.name] = m['routeUrl'][m.name];
|
|
|
}
|
|
|
})
|
|
|
app.globalData['routeUrl'] = routeUrl;
|
|
|
// 输出结果
|
|
|
- console.log('文件列表:', files,baseMethod,routeUrl);
|
|
|
+ console.log('文件列表:', files, baseMethod, routeUrl);
|
|
|
// 国际化的初始化
|
|
|
LangUtils.initLang();
|
|
|
let langSrc = LangUtils.getLangSrc()
|
|
|
- console.log('langSrc',langSrc);
|
|
|
- app.globalData['lang'] = {...langSrc.items};
|
|
|
+ console.log('langSrc', langSrc);
|
|
|
+ app.globalData['lang'] = { ...langSrc.items };
|
|
|
} catch (error) {
|
|
|
console.error('读取文件夹失败:', error);
|
|
|
}
|