From 2dd25ad02c0ca09a3adac38bc6a52990c8fb6a31 Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 3 Nov 2022 18:09:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=8F=96=E9=A1=B5=E9=9D=A2=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/pages.js | 25 ++++------------------- src/components/utils/PageBase.js | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 src/components/utils/PageBase.js diff --git a/bin/pages.js b/bin/pages.js index df94196..5c98c1a 100644 --- a/bin/pages.js +++ b/bin/pages.js @@ -1,16 +1,8 @@ const axios = require('axios') const {chalkTag, findPages, fsExtra, fs} = require("./tools"); +const PageBase = require("dvcp-wui/utils/PageBase"); let apps = {list: [], desc: "用于产品库主页面获取应用使用", type: "mp"} const getFileInfo = (app, file) => { - let vue = fs.readFileSync(file).toString() - if (/appName/.test(vue)) { - let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1') - app.label = appName.replace(/(appName:|["'])/g, '')?.trim() - if (/customNavigation/.test(vue)) { - app.style = {navigationStyle: "custom"} - } else - app.style = {navigationBarTitleText: app.label} - } if (/^App/.test(app.name)) { let {name, label} = app, path = app.path.replace(/.+[\\\/]([^\\\/]+)[\\\/]([^\\\/]+)$/g, `/mods/$1/$2`) @@ -56,30 +48,21 @@ const start = () => { Promise.all([ findPages('src/components/pages', file => { if (/.+\\pages\\[^\\]+\.vue/g.test(file)) { - let app = { - path: file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/') - } + const app = new PageBase(file.replace(/^src\\components\\pages\\(.*).vue/g, '$1').replace(/\\/g, '/'), fs.readFileSync(file).toString()) getFileInfo(app, file) return json.subPackages[1].pages.push(app) } }), findPages('src/mods', file => { if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) { - let app = { - name: file.replace(/.*\\([^\\]+).vue/g, '$1'), - path: file.replace(/^src\\mods\\(.*).vue/g, '$1').replace(/\\/g, '/') - } + const app = new PageBase(file.replace(/^src\\mods\\(.*).vue/g, '$1').replace(/\\/g, '/'), fs.readFileSync(file).toString()) getFileInfo(app, file) return json.subPackages[0].pages.push(app) } }), findPages('src/project', file => { if (/.+\\App[^\\]+\\[^\\]+\.vue/g.test(file)) { - let app = { - name: file.replace(/.*\\([^\\]+).vue/g, '$1'), - path: file.replace(/^src\\project\\(.*).vue/g, '$1').replace(/\\/g, '/') - } - console.log(app) + const app = new PageBase(file.replace(/^src\\project\\(.*).vue/g, '$1').replace(/\\/g, '/'), fs.readFileSync(file).toString()) getFileInfo(app, file) return json.subPackages[2].pages.push(app) } diff --git a/src/components/utils/PageBase.js b/src/components/utils/PageBase.js new file mode 100644 index 0000000..2f0d466 --- /dev/null +++ b/src/components/utils/PageBase.js @@ -0,0 +1,35 @@ +export default class PageBase { + constructor(path, vue) { + this.path = path + this.name = path.replace(/.*\\([^\\]+).vue/g, '$1') + this.init(vue) + } + + init(vue) { + if (/customNavigation/.test(vue)) { + this.style = {navigationStyle: "custom"} + } else { + this.style = {navigationBarTitleText: this.label} + //是否开启下拉刷新 + if (/enablePullDownRefresh/.test(vue)) { + this.style.enablePullDownRefresh = true + } + //导航栏标题颜色及状态栏前景颜色,仅支持 black/white + if (/navigationBarTextStyle/.test(vue)) { + this.style.navigationBarTextStyle = vue.replace(/[\s\S]*(navigationBarTextStyle:.+),[\s\S]*/gm, '$1') + } + //导航栏背景颜色(同状态栏背景色) + if (/navigationBarBackgroundColor/.test(vue)) { + this.style.navigationBarBackgroundColor = vue.replace(/[\s\S]*(navigationBarBackgroundColor:.+),[\s\S]*/gm, '$1') + } + //下拉显示出来的窗口的背景色 + if (/backgroundColor/.test(vue)) { + this.style.backgroundColor = vue.replace(/[\s\S]*(backgroundColor:.+),[\s\S]*/gm, '$1') + } + } + if (/appName/.test(vue)) { + let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1') + this.label = appName.replace(/(appName:|["'])/g, '')?.trim() + } + } +}