抽取页面对象类

This commit is contained in:
aixianling
2022-11-03 18:09:39 +08:00
parent 1a65407ef7
commit 2dd25ad02c
2 changed files with 39 additions and 21 deletions

View File

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

View File

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