From 115ba62141a9304fcec8af9499f874b1ffa3a264 Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 12 May 2022 09:49:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + bin/pages.js | 34 ++++++++++++++-------------------- src/pages/home.vue | 27 ++++++++++++--------------- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index cdb796a..badd2ed 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ yarn-error.log* /.hbuilderx/launch.json /src/pages.json /src/mods/project/ +/src/pages/apps.json diff --git a/bin/pages.js b/bin/pages.js index 52f5168..4e9ac34 100644 --- a/bin/pages.js +++ b/bin/pages.js @@ -1,6 +1,7 @@ const fsExtra = require('fs-extra') const path = require('path') const fs = require('fs') +const axios = require('axios') /** * 将函数封装成promise */ @@ -53,23 +54,8 @@ const findApp = (dir, cb) => { }) || []) }) } -/** - * 迁移apps文件 - */ -const copyFiles = (dir, source = 'src/mods') => { - chalkTag.info(`开始扫描${source}...`) - return new Promise(resolve => { - fsExtra.emptyDir(dir, err => { - if (!err) { - fsExtra.copy(source, dir).then(() => { - chalkTag.done(source + ' 扫描完毕') - resolve() - }) - } - }) - }) -} -const setPageStyle = (app, file) => { +let apps = {list: [], desc: "用于产品库主页面获取应用使用"} +const getFileInfo = (app, file) => { let vue = fs.readFileSync(file).toString() if (/customNavigation/.test(vue)) { app.style = {navigationStyle: "custom"} @@ -78,6 +64,13 @@ const setPageStyle = (app, file) => { title = appName.replace(/(appName:|["'])/g, '') app.style = {navigationBarTitleText: title} } + if (/^App/.test(app.name)) { + let {name, style: {navigationBarTitleText: label}} = app + apps.list.push({id: name, name, label, path: `/mods/${name}/${name}`, libPath: file?.replace(/\\/g, '/')?.replace(/^src(\/.+)\.vue/, '$1')}) + } +} +const saveApps = app => { + axios.post("http://localhost:12525/node/wechatapps/addOrUpdate", app).catch(() => 0) } const start = () => { chalkTag.info('开始生成pages.json...') @@ -107,7 +100,7 @@ const start = () => { let app = { path: file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/') } - setPageStyle(app, file) + getFileInfo(app, file) return json.subPackages[1].pages.push(app) } }), @@ -117,7 +110,7 @@ const start = () => { name: file.replace(/.*\\([^\\]+).vue/g, '$1'), path: file.replace(/^src\\mods\\(.*).vue/g, '$1').replace(/\\/g, '/') } - setPageStyle(app, file) + getFileInfo(app, file) return json.subPackages[0].pages.push(app) } }), @@ -127,11 +120,12 @@ const start = () => { name: file.replace(/.*\\([^\\]+).vue/g, '$1'), path: file.replace(/^src\\project\\(.*).vue/g, '$1').replace(/\\/g, '/') } - setPageStyle(app, file) + getFileInfo(app, file) return json.subPackages[2].pages.push(app) } }) ]).then(() => { + saveApps(apps) fsExtra.outputJson('src/pages.json', json, () => { chalkTag.done('生成pages.json') }) diff --git a/src/pages/home.vue b/src/pages/home.vue index e3b1baa..8255e4f 100644 --- a/src/pages/home.vue +++ b/src/pages/home.vue @@ -22,10 +22,10 @@
-
- +
+ ( -
+
)
@@ -54,7 +54,7 @@ export default { }, appsList() { let {search} = this - return this.apps?.filter(e => !!search ? e.name.indexOf(search) > -1 : true) || [] + return this.apps?.filter(e => !!search ? e.label?.indexOf(search) > -1 : true) || [] }, }, methods: { @@ -65,19 +65,16 @@ export default { } }, handleGotoApp(app) { - uni.navigateTo({url: `/mods${app.path}`}) + uni.navigateTo({url: `${app.path}`}) }, getApps() { - this.apps = [] - // let applications = require.context('../', true, /\.(\/.+)\/App[^\/]+\.vue$/, 'lazy') - // applications.keys().map(path => { - // applications(path).then(file => { - // if (file.default) { - // let {name: key, appName: name} = file.default - // this.apps.push({key, name, path: path.replace(/^\.(.+).vue$/g, '$1')}) - // } - // }) - // }) + this.$instance.post("/node/wechatapps/list", null, { + baseURL: "http://localhost:12525", params: {size: 999} + }).then(res => { + if (res?.data) { + this.apps = res.data.records.map(e => ({...e, path: e.libPath})) + } + }) }, getAuth() { this.$nextTick(() => {