产品库自动化,自动根据pages下的内容生成pages.json

This commit is contained in:
aixianling
2021-11-15 14:23:50 +08:00
parent 5440b43b9c
commit aa4f0c8837
6 changed files with 86 additions and 623 deletions

1
.gitignore vendored
View File

@@ -23,3 +23,4 @@ yarn-error.log*
*.sw* *.sw*
/package-lock.json /package-lock.json
/.hbuilderx/launch.json /.hbuilderx/launch.json
/src/pages.json

78
bin/serve.js Normal file
View File

@@ -0,0 +1,78 @@
const fsExtra = require('fs-extra')
const path = require('path')
const fs = require('fs')
/**
* 将函数封装成promise
*/
const promisify = fn => {
return function () {
let args = arguments;
return new Promise(function (resolve, reject) {
[].push.call(args, function (err, result) {
if (err) {
console.log(err)
reject(err);
} else {
resolve(result);
}
});
fn.apply(null, args);
});
}
}
const readdir = promisify(fs.readdir)
const stat = promisify(fs.stat)
/**
* 封装打印工具
*/
const chalk = require('chalk')
const {log} = console
const chalkTag = {
info: msg => log([chalk.bgBlue.black(' INFO '), msg].join(' ')),
done: msg => log([chalk.bgGreen.black(' DONE '), msg].join(' ')),
warn: msg => log([chalk.bgYellow.black(' WARN '), msg].join(' ')),
error: msg => log([chalk.bgRed.black(' ERROR '), msg].join(' ')),
}
/**
* 遍历应用的方法
*/
const findApp = (dir, cb) => {
return readdir(dir).then(apps => {
return Promise.all(apps?.map(e => {
let cPath = path.join(dir, e)
return stat(cPath).then(state => {
if (state?.isDirectory()) {
return findApp(cPath, cb)
} else if (state?.isFile()) {
cb && cb(cPath)
}
})
}) || [])
})
}
const start = () => {
chalkTag.info('开始生成pages.json...')
let json = {
easycom: {
"^u-(.*)": "@/uview/components/u-$1/u-$1.vue"
},
pages: [],
globalStyle: {
pageOrientation: "auto",
navigationStyle: "custom"
}
}
findApp('src/pages', file => {
if (/.*\\(.+)\.vue/g.test(file)) {
json.pages.push({path: file.replace(/^src\\(.*).vue/g, '$1').replace(/\\/g,'/')})
}
}).then(() => {
fsExtra.outputJson('src/pages.json', json, () => {
chalkTag.done('生成pages.json')
})
})
}
start();

View File

@@ -3,12 +3,11 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve --minimize", "dev": "node bin/serve.js&&cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve --minimize",
"build": "cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build", "build": "node bin/serve.js&&cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build",
"build:mp-weixin": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build", "build:mp-weixin": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build",
"dev:mp-weixin": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch", "dev:mp-weixin": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch",
"info": "node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js", "pages": "node bin/serve.js"
"test:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin jest -i"
}, },
"dependencies": { "dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1", "@amap/amap-jsapi-loader": "^1.0.1",

View File

@@ -1,411 +0,0 @@
{
"easycom": {
"^u-(.*)": "@/uview/components/u-$1/u-$1.vue"
},
"pages": [
{
"path": "pages/loading",
"style": {
"navigationBarTitleText": "欢迎使用村微..."
}
},
{
"path": "pages/app",
"style": {
"navigationBarTitleText": "应用"
}
},
{
"path": "pages/login"
},
{
"path": "pages/notification/notification",
"style": {
"navigationBarTitleText": "通知公告"
}
},
{
"path": "pages/notification/components/read",
"style": {
"navigationBarTitleText": "接收情况"
}
},
{
"path": "pages/notification/components/detail",
"style": {
"navigationBarTitleText": "公告详情"
}
},
{
"path": "pages/notification/components/add",
"style": {
"navigationBarTitleText": "新增公告"
}
},
{
"path": "pages/workTask/workTask",
"style": {
"navigationBarTitleText": "工作任务"
}
},
{
"path": "pages/workTask/components/create",
"style": {
"navigationBarTitleText": "创建任务"
}
},
{
"path": "pages/workTask/components/detail",
"style": {
"navigationBarTitleText": "任务详情"
}
},
{
"path": "pages/workTask/components/subDetail",
"style": {
"navigationBarTitleText": "任务详情"
}
},
{
"path": "pages/workTask/components/finishDetail",
"style": {
"navigationBarTitleText": "完成详情"
}
},
{
"path": "pages/workTask/components/finish",
"style": {
"navigationBarTitleText": "完成任务"
}
},
{
"path": "pages/documentFlow/documentFlow",
"style": {
"navigationBarTitleText": "公文流转"
}
},
{
"path": "pages/documentFlow/components/detail",
"style": {
"navigationBarTitleText": "公文详情"
}
},
{
"path": "pages/documentFlow/components/approval",
"style": {
"navigationBarTitleText": "批示"
}
},
{
"path": "pages/meetingNotice/meetingNotice",
"style": {
"navigationBarTitleText": "会议通知"
}
},
{
"path": "pages/meetingNotice/components/addMeeting",
"style": {
"navigationBarTitleText": "发起会议"
}
},
{
"path": "pages/meetingNotice/components/belongToMe",
"style": {
"navigationBarTitleText": "我发起的"
}
},
{
"path": "pages/meetingNotice/components/detail",
"style": {
"navigationBarTitleText": "会议详情"
}
},
{
"path": "pages/meetingNotice/components/meetingList"
},
{
"path": "pages/askForm/askForm"
},
{
"path": "pages/askForm/index",
"style": {
"navigationBarTitleText": "问卷表单"
}
},
{
"path": "pages/askForm/formSetting",
"style": {
"navigationBarTitleText": "设置"
}
},
{
"path": "pages/askForm/filedConfig",
"style": {
"navigationBarTitleText": "组件设置"
}
},
{
"path": "pages/askForm/previewForm",
"style": {
"navigationBarTitleText": "表单预览"
}
},
{
"path": "pages/askForm/addForm",
"style": {
"navigationBarTitleText": "新建调查表单"
}
},
{
"path": "pages/resident/resident"
},
{
"path": "pages/resident/comp",
"style": {
"navigationBarTitleText": "居民管理"
}
},
{
"path": "pages/resident/groupResident"
},
{
"path": "pages/whereabouts/whereabouts"
},
{
"path": "pages/interview/interview",
"style": {
"navigationBarTitleText": "调查走访"
}
},
{
"path": "pages/interview/detail",
"style": {
"navigationBarTitleText": "新增走访"
}
},
{
"path": "pages/quickReply/quickReply"
},
{
"path": "pages/quickReply/typeManage"
},
{
"path": "pages/quickReply/replyDetail"
},
{
"path": "pages/supermarket/supermarket",
"style": {
"navigationBarTitleText": "信用好超市"
}
},
{
"path": "pages/supermarket/balance",
"style": {
"navigationBarTitleText": "结算"
}
},
{
"path": "pages/supermarket/search",
"style": {
"navigationBarTitleText": "搜索"
}
},
{
"path": "pages/supermarket/components/resultPage/resultPage",
"style": {
"navigationBarTitleText": "结算提交"
}
},
{
"path": "pages/casuallyask/casuallyask",
"style": {
"navigationBarTitleText": "随心问"
}
},
{
"path": "pages/casuallyask/casuallyaskDetail",
"style": {
"navigationBarTitleText": "随心问(详情页)"
}
},
{
"path": "pages/casuallyask/closemsg",
"style": {
"navigationBarTitleText": "关闭留言"
}
},
{
"path": "pages/casuallyask/truemsg",
"style": {
"navigationBarTitleText": "提交留言"
}
},
{
"path": "pages/casuallyask/reply",
"style": {
"navigationBarTitleText": "发表回复"
}
},
{
"path": "pages/workonline/workonline",
"style": {
"navigationBarTitleText": "网上办事"
}
},
{
"path": "pages/workonline/detail",
"style": {
"navigationBarTitleText": "进度详情"
}
},
{
"path": "pages/workonline/approvalopinion",
"style": {
"navigationBarTitleText": "进度详情"
}
},
{
"path": "pages/workonline/truemsg",
"style": {
"navigationBarTitleText": "进度详情"
}
},
{
"path": "pages/snapshot/snapshot",
"style": {
"navigationBarTitleText": "随手拍"
}
},
{
"path": "pages/snapshot/snapshotDetail",
"style": {
"navigationBarTitleText": "随手拍详情"
}
},
{
"path": "pages/snapshot/handleResult",
"style": {
"navigationBarTitleText": "处理结果"
}
},
{
"path": "pages/snapshot/components/handlePage/handlePage",
"style": {
"navigationBarTitleText": "处理结果"
}
},
{
"path": "pages/villageQRCode/villageQRCode",
"style": {
"navigationBarTitleText": "一村一码"
}
},
{
"path": "pages/guardianship/guardianship",
"style": {
"navigationBarTitleText": "智慧监护"
}
},
{
"path": "pages/guardianship/userDetail",
"style": {
"navigationBarTitleText": "个人详情"
}
},
{
"path": "pages/guardianship/historyList",
"style": {
"navigationBarTitleText": "历史记录"
}
},
{
"path": "pages/guardianship/warningDetail",
"style": {
"navigationBarTitleText": "预警"
}
},
{
"path": "pages/bigHorn/bigHorn",
"style": {
"navigationBarTitleText": "广播通知"
}
},
{
"path": "pages/bigHorn/playList",
"style": {
"navigationBarTitleText": "播放记录"
}
},
{
"path": "pages/bigHorn/onlineList",
"style": {
"navigationBarTitleText": "在线设备"
}
},
{
"path": "pages/bigHorn/onlinePlayList",
"style": {
"navigationBarTitleText": "在播设备"
}
},
{
"path": "pages/bigHorn/addPlay",
"style": {
"navigationBarTitleText": "音频播放"
}
},
{
"path": "pages/bigHorn/selectMp3",
"style": {
"navigationBarTitleText": "选择内容"
}
},
{
"path": "pages/bigHorn/selectEquipment",
"style": {
"navigationBarTitleText": "选择设备"
}
},
{
"path": "pages/resourcesManage/resourcesManage",
"style": {
"navigationBarTitleText": "媒资管理"
}
},
{
"path": "pages/resourcesManage/addPlay",
"style": {
"navigationBarTitleText": "媒资管理"
}
},
{
"path": "pages/resourcesManage/talking",
"style": {
"navigationBarTitleText": "实时喊话"
}
},
{
"path": "pages/resourcesManage/recording",
"style": {
"navigationBarTitleText": "音频录制"
}
},
{
"path": "pages/videoSurveillance/videoSurveillance",
"style": {
"navigationBarTitleText": "视频监控"
}
},
{
"path": "pages/videoSurveillance/monitorDetail",
"style": {
"navigationBarTitleText": "实时监控",
"pageOrientation": "landscape"
}
}
],
"globalStyle": {
"pageOrientation": "auto",
"navigationStyle": "custom"
}
}

View File

@@ -1,174 +0,0 @@
<template>
<section class="app">
<u-swiper :list="list" height="240" bg-color="#408CFF"></u-swiper>
<label class="useful-app">常用应用</label>
<u-grid
:col="o.length"
:border="false"
v-for="(o, i) in gridGroup"
:key="i"
>
<u-grid-item v-for="(i, j) in o" :key="j" @click="linkTo(i)">
<u-icon :name="i.icon" :size="100"></u-icon>
<view class="grid-text">{{ i.label }}</view>
</u-grid-item>
</u-grid>
<label class="useful-app notice">通知公告</label>
<section class="list">
<div class="item" v-for="(item, index) in dataList" :key="index">
<label class="title hidden">{{ item.title }}</label>
<div class="content hidden">{{ item.content }}</div>
<div class="date">{{ item.createTime }}</div>
</div>
<u-loadmore :status="status" />
</section>
</section>
</template>
<script>
export default {
name: 'app',
data() {
return {
list: [this.imgHomeUrl + 'banner.png'],
gridGroup: [
[
{
icon: `${this.imgHomeUrl}icon1.png`,
label: '随心问',
link: '/pages/casuallyask/casuallyask'
},
{
icon: `${this.imgHomeUrl}icon2.png`,
label: '随手拍',
link: '/pages/snapshot/snapshot'
},
{
icon: `${this.imgHomeUrl}icon3.png`,
label: '网上办事',
link: '/pages/workonline/workonline'
},
{ icon: `${this.imgHomeUrl}icon4.png`, label: '调查走访' }
],
[
{
icon: `${this.imgHomeUrl}icon5.png`,
label: '信用好超市',
link: '/pages/supermarket/supermarket'
},
{ icon: `${this.imgHomeUrl}icon6.png`, label: '中心工作' },
{ icon: `${this.imgHomeUrl}icon7.png`, label: '会务通知' },
{ icon: `${this.imgHomeUrl}icon8.png`, label: '工作去向' },
{ icon: `${this.imgHomeUrl}icon8.png`, label: '大喇叭' }
]
],
status: 'nomore',
dataList: [],
current: 0
}
},
onLoad() {
this.getList()
},
methods: {
getList() {
if (this.loadingStatus == 'nomore') return
this.$http
.post(`/app/appworkcenternotice/list`, null, {
params: {
withoutToken: true,
current: this.current + 1,
size: 10
}
})
.then(res => {
if (res && res.data) {
this.dataList = res.data.records
}
})
},
linkTo(val) {
if (val.link) {
uni.navigateTo({ url: val.link })
}
}
},
onReachBottom() {
this.getList()
}
}
</script>
<style lang="scss" scoped>
.app {
min-height: 100%;
background-color: #ffffff;
box-sizing: border-box;
padding: 32px;
position: relative;
.grid-text {
font-size: 28px;
color: #333333;
line-height: 46px;
}
.useful-app {
margin-top: 80px;
display: inherit;
font-size: 36px;
font-weight: bold;
color: #333333;
line-height: 50px;
}
.notice {
margin-top: 56px;
}
.list {
margin-top: 38px;
.item {
height: 192px;
background: #f7f9ff;
border-radius: 8px;
box-sizing: border-box;
padding: 20px;
margin-bottom: 32px;
.title {
font-size: 32px;
font-weight: 800;
color: #343d65;
}
.content {
font-size: 28px;
color: #333333;
font-weight: 500;
margin: 20px 0 8px 0;
}
.date {
font-size: 28px;
color: #666666;
}
}
}
.hidden {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
::v-deep .u-indicator-item-round {
background-color: #d8dde6;
}
::v-deep .u-indicator-item-round-active {
background-color: #408cff !important;
}
}
</style>

View File

@@ -82,40 +82,10 @@ export default {
uni.showLoading({ uni.showLoading({
title: "加载中" title: "加载中"
}) })
this.initAccess()?.then(() => { uni.hideLoading()
uni.hideLoading() this.result = {
if (this.token) { tips: "欢迎进入开发应用",
if (this.currentApp.name) { }
this.redirectTo(this.currentApp.path)
} else if (this.$route.query.url) {
this.redirectTo(this.$route.query.url)
} else {
this.result = {
status: "error",
tips: "应用加载失败",
btn: "重新加载",
btnTap() {
location.href = location.href?.replace("#error", '')
}
}
}
} else if (this.isDev) {
this.result = {
tips: "欢迎进入开发应用",
}
} else {
this.result = {
status: "error",
tips: "应用加载失败",
btn: "重新加载",
btnTap() {
location.href = location.href?.replace("#error", '')
}
}
}
})?.catch(() => {
uni.navigateTo({url: './login'})
})
} }
} }
</script> </script>