From aa4f0c8837b8407d47f297b37bf6713e20172c7f Mon Sep 17 00:00:00 2001 From: aixianling Date: Mon, 15 Nov 2021 14:23:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81=E5=BA=93=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96,=E8=87=AA=E5=8A=A8=E6=A0=B9=E6=8D=AEpages=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AE=B9=E7=94=9F=E6=88=90pages.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + bin/serve.js | 78 ++++++++ package.json | 7 +- src/pages.json | 411 ------------------------------------------ src/pages/app.vue | 174 ------------------ src/pages/loading.vue | 38 +--- 6 files changed, 86 insertions(+), 623 deletions(-) create mode 100644 bin/serve.js delete mode 100644 src/pages.json delete mode 100644 src/pages/app.vue diff --git a/.gitignore b/.gitignore index 33bc4562..daa5353f 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ yarn-error.log* *.sw* /package-lock.json /.hbuilderx/launch.json +/src/pages.json diff --git a/bin/serve.js b/bin/serve.js new file mode 100644 index 00000000..fbfa7d52 --- /dev/null +++ b/bin/serve.js @@ -0,0 +1,78 @@ +const fsExtra = require('fs-extra') +const path = require('path') +const fs = require('fs') +/** + * 将函数封装成promise + */ +const promisify = fn => { + return function () { + let args = arguments; + return new Promise(function (resolve, reject) { + [].push.call(args, function (err, result) { + if (err) { + console.log(err) + reject(err); + } else { + resolve(result); + } + }); + fn.apply(null, args); + }); + } +} + +const readdir = promisify(fs.readdir) +const stat = promisify(fs.stat) +/** + * 封装打印工具 + */ +const chalk = require('chalk') +const {log} = console +const chalkTag = { + info: msg => log([chalk.bgBlue.black(' INFO '), msg].join(' ')), + done: msg => log([chalk.bgGreen.black(' DONE '), msg].join(' ')), + warn: msg => log([chalk.bgYellow.black(' WARN '), msg].join(' ')), + error: msg => log([chalk.bgRed.black(' ERROR '), msg].join(' ')), +} + +/** + * 遍历应用的方法 + */ +const findApp = (dir, cb) => { + return readdir(dir).then(apps => { + return Promise.all(apps?.map(e => { + let cPath = path.join(dir, e) + return stat(cPath).then(state => { + if (state?.isDirectory()) { + return findApp(cPath, cb) + } else if (state?.isFile()) { + cb && cb(cPath) + } + }) + }) || []) + }) +} +const start = () => { + chalkTag.info('开始生成pages.json...') + let json = { + easycom: { + "^u-(.*)": "@/uview/components/u-$1/u-$1.vue" + }, + pages: [], + globalStyle: { + pageOrientation: "auto", + navigationStyle: "custom" + } + } + findApp('src/pages', file => { + if (/.*\\(.+)\.vue/g.test(file)) { + json.pages.push({path: file.replace(/^src\\(.*).vue/g, '$1').replace(/\\/g,'/')}) + } + }).then(() => { + fsExtra.outputJson('src/pages.json', json, () => { + chalkTag.done('生成pages.json') + }) + }) +} + +start(); diff --git a/package.json b/package.json index 80ca1ec6..be343202 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,11 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve --minimize", - "build": "cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build", + "dev": "node bin/serve.js&&cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve --minimize", + "build": "node bin/serve.js&&cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build", "build:mp-weixin": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build", "dev:mp-weixin": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch", - "info": "node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js", - "test:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin jest -i" + "pages": "node bin/serve.js" }, "dependencies": { "@amap/amap-jsapi-loader": "^1.0.1", diff --git a/src/pages.json b/src/pages.json deleted file mode 100644 index b6df234c..00000000 --- a/src/pages.json +++ /dev/null @@ -1,411 +0,0 @@ -{ - "easycom": { - "^u-(.*)": "@/uview/components/u-$1/u-$1.vue" - }, - "pages": [ - { - "path": "pages/loading", - "style": { - "navigationBarTitleText": "欢迎使用村微..." - } - }, - { - "path": "pages/app", - "style": { - "navigationBarTitleText": "应用" - } - }, - { - "path": "pages/login" - }, - { - "path": "pages/notification/notification", - "style": { - "navigationBarTitleText": "通知公告" - } - }, - { - "path": "pages/notification/components/read", - "style": { - "navigationBarTitleText": "接收情况" - } - }, - { - "path": "pages/notification/components/detail", - "style": { - "navigationBarTitleText": "公告详情" - } - }, - { - "path": "pages/notification/components/add", - "style": { - "navigationBarTitleText": "新增公告" - } - }, - { - "path": "pages/workTask/workTask", - "style": { - "navigationBarTitleText": "工作任务" - } - }, - { - "path": "pages/workTask/components/create", - "style": { - "navigationBarTitleText": "创建任务" - } - }, - { - "path": "pages/workTask/components/detail", - "style": { - "navigationBarTitleText": "任务详情" - } - }, - { - "path": "pages/workTask/components/subDetail", - "style": { - "navigationBarTitleText": "任务详情" - } - }, - { - "path": "pages/workTask/components/finishDetail", - "style": { - "navigationBarTitleText": "完成详情" - } - }, - { - "path": "pages/workTask/components/finish", - "style": { - "navigationBarTitleText": "完成任务" - } - }, - { - "path": "pages/documentFlow/documentFlow", - "style": { - "navigationBarTitleText": "公文流转" - } - }, - { - "path": "pages/documentFlow/components/detail", - "style": { - "navigationBarTitleText": "公文详情" - } - }, - { - "path": "pages/documentFlow/components/approval", - "style": { - "navigationBarTitleText": "批示" - } - }, - { - "path": "pages/meetingNotice/meetingNotice", - "style": { - "navigationBarTitleText": "会议通知" - } - }, - { - "path": "pages/meetingNotice/components/addMeeting", - "style": { - "navigationBarTitleText": "发起会议" - } - }, - { - "path": "pages/meetingNotice/components/belongToMe", - "style": { - "navigationBarTitleText": "我发起的" - } - }, - { - "path": "pages/meetingNotice/components/detail", - "style": { - "navigationBarTitleText": "会议详情" - } - }, - { - "path": "pages/meetingNotice/components/meetingList" - }, - { - "path": "pages/askForm/askForm" - }, - { - "path": "pages/askForm/index", - "style": { - "navigationBarTitleText": "问卷表单" - } - }, - { - "path": "pages/askForm/formSetting", - "style": { - "navigationBarTitleText": "设置" - } - }, - { - "path": "pages/askForm/filedConfig", - "style": { - "navigationBarTitleText": "组件设置" - } - }, - { - "path": "pages/askForm/previewForm", - "style": { - "navigationBarTitleText": "表单预览" - } - }, - { - "path": "pages/askForm/addForm", - "style": { - "navigationBarTitleText": "新建调查表单" - } - }, - { - "path": "pages/resident/resident" - }, - { - "path": "pages/resident/comp", - "style": { - "navigationBarTitleText": "居民管理" - } - }, - { - "path": "pages/resident/groupResident" - }, - { - "path": "pages/whereabouts/whereabouts" - }, - { - "path": "pages/interview/interview", - "style": { - "navigationBarTitleText": "调查走访" - } - }, - { - "path": "pages/interview/detail", - "style": { - "navigationBarTitleText": "新增走访" - } - }, - { - "path": "pages/quickReply/quickReply" - }, - { - "path": "pages/quickReply/typeManage" - }, - { - "path": "pages/quickReply/replyDetail" - }, - { - "path": "pages/supermarket/supermarket", - "style": { - "navigationBarTitleText": "信用好超市" - } - }, - { - "path": "pages/supermarket/balance", - "style": { - "navigationBarTitleText": "结算" - } - }, - { - "path": "pages/supermarket/search", - "style": { - "navigationBarTitleText": "搜索" - } - }, - { - "path": "pages/supermarket/components/resultPage/resultPage", - "style": { - "navigationBarTitleText": "结算提交" - } - }, - { - "path": "pages/casuallyask/casuallyask", - "style": { - "navigationBarTitleText": "随心问" - } - }, - { - "path": "pages/casuallyask/casuallyaskDetail", - "style": { - "navigationBarTitleText": "随心问(详情页)" - } - }, - { - "path": "pages/casuallyask/closemsg", - "style": { - "navigationBarTitleText": "关闭留言" - } - }, - { - "path": "pages/casuallyask/truemsg", - "style": { - "navigationBarTitleText": "提交留言" - } - }, - { - "path": "pages/casuallyask/reply", - "style": { - "navigationBarTitleText": "发表回复" - } - }, - { - "path": "pages/workonline/workonline", - "style": { - "navigationBarTitleText": "网上办事" - } - }, - { - "path": "pages/workonline/detail", - "style": { - "navigationBarTitleText": "进度详情" - } - }, - { - "path": "pages/workonline/approvalopinion", - "style": { - "navigationBarTitleText": "进度详情" - } - }, - { - "path": "pages/workonline/truemsg", - "style": { - "navigationBarTitleText": "进度详情" - } - }, - { - "path": "pages/snapshot/snapshot", - "style": { - "navigationBarTitleText": "随手拍" - } - }, - { - "path": "pages/snapshot/snapshotDetail", - "style": { - "navigationBarTitleText": "随手拍详情" - } - }, - { - "path": "pages/snapshot/handleResult", - "style": { - "navigationBarTitleText": "处理结果" - } - }, - { - "path": "pages/snapshot/components/handlePage/handlePage", - "style": { - "navigationBarTitleText": "处理结果" - } - }, - { - "path": "pages/villageQRCode/villageQRCode", - "style": { - "navigationBarTitleText": "一村一码" - } - }, - { - "path": "pages/guardianship/guardianship", - "style": { - "navigationBarTitleText": "智慧监护" - } - }, - { - "path": "pages/guardianship/userDetail", - "style": { - "navigationBarTitleText": "个人详情" - } - }, - { - "path": "pages/guardianship/historyList", - "style": { - "navigationBarTitleText": "历史记录" - } - }, - { - "path": "pages/guardianship/warningDetail", - "style": { - "navigationBarTitleText": "预警" - } - }, - { - "path": "pages/bigHorn/bigHorn", - "style": { - "navigationBarTitleText": "广播通知" - } - }, - { - "path": "pages/bigHorn/playList", - "style": { - "navigationBarTitleText": "播放记录" - } - }, - { - "path": "pages/bigHorn/onlineList", - "style": { - "navigationBarTitleText": "在线设备" - } - }, - { - "path": "pages/bigHorn/onlinePlayList", - "style": { - "navigationBarTitleText": "在播设备" - } - }, - { - "path": "pages/bigHorn/addPlay", - "style": { - "navigationBarTitleText": "音频播放" - } - }, - { - "path": "pages/bigHorn/selectMp3", - "style": { - "navigationBarTitleText": "选择内容" - } - }, - { - "path": "pages/bigHorn/selectEquipment", - "style": { - "navigationBarTitleText": "选择设备" - } - }, - { - "path": "pages/resourcesManage/resourcesManage", - "style": { - "navigationBarTitleText": "媒资管理" - } - }, - { - "path": "pages/resourcesManage/addPlay", - "style": { - "navigationBarTitleText": "媒资管理" - } - }, - { - "path": "pages/resourcesManage/talking", - "style": { - "navigationBarTitleText": "实时喊话" - } - }, - { - "path": "pages/resourcesManage/recording", - "style": { - "navigationBarTitleText": "音频录制" - } - }, - { - "path": "pages/videoSurveillance/videoSurveillance", - "style": { - "navigationBarTitleText": "视频监控" - } - }, - { - "path": "pages/videoSurveillance/monitorDetail", - "style": { - "navigationBarTitleText": "实时监控", - "pageOrientation": "landscape" - } - } - ], - "globalStyle": { - "pageOrientation": "auto", - "navigationStyle": "custom" - } -} diff --git a/src/pages/app.vue b/src/pages/app.vue deleted file mode 100644 index 8f6ee3da..00000000 --- a/src/pages/app.vue +++ /dev/null @@ -1,174 +0,0 @@ - - - - - diff --git a/src/pages/loading.vue b/src/pages/loading.vue index 0674a3a7..0ed6aaba 100644 --- a/src/pages/loading.vue +++ b/src/pages/loading.vue @@ -82,40 +82,10 @@ export default { uni.showLoading({ title: "加载中" }) - this.initAccess()?.then(() => { - uni.hideLoading() - if (this.token) { - if (this.currentApp.name) { - this.redirectTo(this.currentApp.path) - } else if (this.$route.query.url) { - this.redirectTo(this.$route.query.url) - } else { - this.result = { - status: "error", - tips: "应用加载失败", - btn: "重新加载", - btnTap() { - location.href = location.href?.replace("#error", '') - } - } - } - } else if (this.isDev) { - this.result = { - tips: "欢迎进入开发应用", - } - } else { - this.result = { - status: "error", - tips: "应用加载失败", - btn: "重新加载", - btnTap() { - location.href = location.href?.replace("#error", '') - } - } - } - })?.catch(() => { - uni.navigateTo({url: './login'}) - }) + uni.hideLoading() + this.result = { + tips: "欢迎进入开发应用", + } } }