优化首页加载
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,3 +25,4 @@ yarn-error.log*
|
|||||||
/.hbuilderx/launch.json
|
/.hbuilderx/launch.json
|
||||||
/src/pages.json
|
/src/pages.json
|
||||||
/src/mods/project/
|
/src/mods/project/
|
||||||
|
/src/pages/apps.json
|
||||||
|
|||||||
34
bin/pages.js
34
bin/pages.js
@@ -1,6 +1,7 @@
|
|||||||
const fsExtra = require('fs-extra')
|
const fsExtra = require('fs-extra')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const axios = require('axios')
|
||||||
/**
|
/**
|
||||||
* 将函数封装成promise
|
* 将函数封装成promise
|
||||||
*/
|
*/
|
||||||
@@ -53,23 +54,8 @@ const findApp = (dir, cb) => {
|
|||||||
}) || [])
|
}) || [])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/**
|
let apps = {list: [], desc: "用于产品库主页面获取应用使用"}
|
||||||
* 迁移apps文件
|
const getFileInfo = (app, file) => {
|
||||||
*/
|
|
||||||
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 vue = fs.readFileSync(file).toString()
|
let vue = fs.readFileSync(file).toString()
|
||||||
if (/customNavigation/.test(vue)) {
|
if (/customNavigation/.test(vue)) {
|
||||||
app.style = {navigationStyle: "custom"}
|
app.style = {navigationStyle: "custom"}
|
||||||
@@ -78,6 +64,13 @@ const setPageStyle = (app, file) => {
|
|||||||
title = appName.replace(/(appName:|["'])/g, '')
|
title = appName.replace(/(appName:|["'])/g, '')
|
||||||
app.style = {navigationBarTitleText: title}
|
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 = () => {
|
const start = () => {
|
||||||
chalkTag.info('开始生成pages.json...')
|
chalkTag.info('开始生成pages.json...')
|
||||||
@@ -107,7 +100,7 @@ const start = () => {
|
|||||||
let app = {
|
let app = {
|
||||||
path: file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
path: file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
||||||
}
|
}
|
||||||
setPageStyle(app, file)
|
getFileInfo(app, file)
|
||||||
return json.subPackages[1].pages.push(app)
|
return json.subPackages[1].pages.push(app)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -117,7 +110,7 @@ const start = () => {
|
|||||||
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
|
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
|
||||||
path: file.replace(/^src\\mods\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
path: file.replace(/^src\\mods\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
||||||
}
|
}
|
||||||
setPageStyle(app, file)
|
getFileInfo(app, file)
|
||||||
return json.subPackages[0].pages.push(app)
|
return json.subPackages[0].pages.push(app)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -127,11 +120,12 @@ const start = () => {
|
|||||||
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
|
name: file.replace(/.*\\([^\\]+).vue/g, '$1'),
|
||||||
path: file.replace(/^src\\project\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
path: file.replace(/^src\\project\\(.*).vue/g, '$1').replace(/\\/g, '/')
|
||||||
}
|
}
|
||||||
setPageStyle(app, file)
|
getFileInfo(app, file)
|
||||||
return json.subPackages[2].pages.push(app)
|
return json.subPackages[2].pages.push(app)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
]).then(() => {
|
]).then(() => {
|
||||||
|
saveApps(apps)
|
||||||
fsExtra.outputJson('src/pages.json', json, () => {
|
fsExtra.outputJson('src/pages.json', json, () => {
|
||||||
chalkTag.done('生成pages.json')
|
chalkTag.done('生成pages.json')
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,10 +22,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<input class="codeText" v-model="search" placeholder="搜索要查找的应用"/>
|
<input class="codeText" v-model="search" placeholder="搜索要查找的应用"/>
|
||||||
<div class="appsPane flex">
|
<div class="appsPane flex">
|
||||||
<div v-for="app in appsList" :key="app.key" @tap="handleGotoApp(app)" class="appItem flex">
|
<div v-for="app in appsList" :key="app.id" @tap="handleGotoApp(app)" class="appItem flex">
|
||||||
<b v-text="app.name"/>
|
<b v-text="app.label"/>
|
||||||
(
|
(
|
||||||
<div v-text="app.key"/>
|
<div v-text="app.name"/>
|
||||||
)
|
)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -54,7 +54,7 @@ export default {
|
|||||||
},
|
},
|
||||||
appsList() {
|
appsList() {
|
||||||
let {search} = this
|
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: {
|
methods: {
|
||||||
@@ -65,19 +65,16 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleGotoApp(app) {
|
handleGotoApp(app) {
|
||||||
uni.navigateTo({url: `/mods${app.path}`})
|
uni.navigateTo({url: `${app.path}`})
|
||||||
},
|
},
|
||||||
getApps() {
|
getApps() {
|
||||||
this.apps = []
|
this.$instance.post("/node/wechatapps/list", null, {
|
||||||
// let applications = require.context('../', true, /\.(\/.+)\/App[^\/]+\.vue$/, 'lazy')
|
baseURL: "http://localhost:12525", params: {size: 999}
|
||||||
// applications.keys().map(path => {
|
}).then(res => {
|
||||||
// applications(path).then(file => {
|
if (res?.data) {
|
||||||
// if (file.default) {
|
this.apps = res.data.records.map(e => ({...e, path: e.libPath}))
|
||||||
// let {name: key, appName: name} = file.default
|
}
|
||||||
// this.apps.push({key, name, path: path.replace(/^\.(.+).vue$/g, '$1')})
|
})
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
},
|
},
|
||||||
getAuth() {
|
getAuth() {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user