优化首页加载

This commit is contained in:
aixianling
2022-05-12 09:49:40 +08:00
parent 7b967a8540
commit 115ba62141
3 changed files with 27 additions and 35 deletions

1
.gitignore vendored
View File

@@ -25,3 +25,4 @@ yarn-error.log*
/.hbuilderx/launch.json
/src/pages.json
/src/mods/project/
/src/pages/apps.json

View File

@@ -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')
})

View File

@@ -22,10 +22,10 @@
</div>
<input class="codeText" v-model="search" placeholder="搜索要查找的应用"/>
<div class="appsPane flex">
<div v-for="app in appsList" :key="app.key" @tap="handleGotoApp(app)" class="appItem flex">
<b v-text="app.name"/>
<div v-for="app in appsList" :key="app.id" @tap="handleGotoApp(app)" class="appItem flex">
<b v-text="app.label"/>
(
<div v-text="app.key"/>
<div v-text="app.name"/>
)
</div>
</div>
@@ -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(() => {