| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- /**
- * 生成各分包薄壳页面(通用模板页,module 参数由注册表驱动)
- * 用法:node scripts/gen-pages.mjs
- */
- import fs from 'node:fs'
- import path from 'node:path'
- import { fileURLToPath } from 'node:url'
- const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
- const BILL_PKGS = [
- 'packageBasic', 'packageMaterial', 'packagePurchase', 'packageSales',
- 'packageRetail', 'packageWarehouse', 'packageFinance', 'packageProductionLogistics'
- ]
- const REPORT_PKGS = ['packageReport']
- const LIST_VUE = `<template>
- <view class="pkg-list-page">
- <BillListView ref="viewRef" :module-key="moduleKey" />
- <!-- 新增入口(P2 写入能力,表单页按 schema 判定是否可编辑) -->
- <view v-if="canCreate" class="fab" @click="goCreate">
- <text class="fab__text">+</text>
- </view>
- </view>
- </template>
- <script setup lang="ts">
- /**
- * 分包通用列表页壳:注册表 module 参数驱动,挂接页面级生命周期
- */
- import { ref, computed } from 'vue'
- import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app'
- import BillListView from '@/modules/bill/BillListView.vue'
- import { getModule } from '@/modules/registry'
- import { getEntitySchema, BILL_ITEM_MODULES } from '@/modules/bill/formSchemas'
- import { moduleEditPage } from '@/constants/routes'
- const moduleKey = ref('')
- const viewRef = ref<InstanceType<typeof BillListView> | null>(null)
- const canCreate = computed(() => {
- const m = getModule(moduleKey.value)
- if (!m || m.shape === 'report') return false
- if (m.shape === 'entity') return !!getEntitySchema(m.key)
- return BILL_ITEM_MODULES.has(m.key)
- })
- onLoad((options) => {
- moduleKey.value = options?.module || ''
- })
- onReachBottom(() => {
- viewRef.value?.loadMore()
- })
- onPullDownRefresh(async () => {
- await viewRef.value?.refresh()
- uni.stopPullDownRefresh()
- })
- function goCreate() {
- const m = getModule(moduleKey.value)
- if (!m) return
- uni.navigateTo({ url: \`\${moduleEditPage(m.pkg)}?module=\${m.key}\` })
- }
- </script>
- <style lang="scss" scoped>
- .pkg-list-page {
- position: relative;
- }
- .fab {
- position: fixed;
- right: 32rpx;
- bottom: calc(64rpx + env(safe-area-inset-bottom));
- width: 96rpx;
- height: 96rpx;
- border-radius: 50%;
- background: #2979ff;
- display: flex;
- align-items: center;
- justify-content: center;
- box-shadow: 0 8rpx 24rpx rgba(41, 121, 255, 0.35);
- &:active {
- opacity: 0.85;
- }
- &__text {
- color: #fff;
- font-size: 48rpx;
- line-height: 1;
- }
- }
- </style>
- `
- const DETAIL_VUE = `<template>
- <BillDetailView :module-key="moduleKey" :record-id="recordId" />
- </template>
- <script setup lang="ts">
- /**
- * 分包通用详情页壳:module + id 参数驱动
- */
- import { ref } from 'vue'
- import { onLoad } from '@dcloudio/uni-app'
- import BillDetailView from '@/modules/bill/BillDetailView.vue'
- const moduleKey = ref('')
- const recordId = ref('')
- onLoad((options) => {
- moduleKey.value = options?.module || ''
- recordId.value = String(options?.id || '')
- })
- </script>
- `
- const EDIT_VUE = `<template>
- <BillFormView :module-key="moduleKey" :record-id="recordId" />
- </template>
- <script setup lang="ts">
- /**
- * 分包通用编辑页壳:module + id(可选)参数驱动
- */
- import { ref } from 'vue'
- import { onLoad } from '@dcloudio/uni-app'
- import BillFormView from '@/modules/bill/BillFormView.vue'
- const moduleKey = ref('')
- const recordId = ref('')
- onLoad((options) => {
- moduleKey.value = options?.module || ''
- recordId.value = String(options?.id || '')
- })
- </script>
- `
- const REPORT_LIST_VUE = `<template>
- <BillListView ref="viewRef" :module-key="moduleKey" />
- </template>
- <script setup lang="ts">
- /**
- * 报表列表页壳(只读):module 参数驱动
- */
- import { ref } from 'vue'
- import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app'
- import BillListView from '@/modules/bill/BillListView.vue'
- const moduleKey = ref('')
- const viewRef = ref<InstanceType<typeof BillListView> | null>(null)
- onLoad((options) => {
- moduleKey.value = options?.module || ''
- })
- onReachBottom(() => {
- viewRef.value?.loadMore()
- })
- onPullDownRefresh(async () => {
- await viewRef.value?.refresh()
- uni.stopPullDownRefresh()
- })
- </script>
- `
- function write(rel, content) {
- const file = path.join(root, 'src', rel)
- fs.mkdirSync(path.dirname(file), { recursive: true })
- fs.writeFileSync(file, content, 'utf8')
- console.log('generated:', rel)
- }
- for (const pkg of BILL_PKGS) {
- write(`${pkg}/pages/list.vue`, LIST_VUE)
- write(`${pkg}/pages/detail.vue`, DETAIL_VUE)
- write(`${pkg}/pages/edit.vue`, EDIT_VUE)
- }
- for (const pkg of REPORT_PKGS) {
- write(`${pkg}/pages/list.vue`, REPORT_LIST_VUE)
- }
- // pages.json:为列表页开启下拉刷新
- const pagesJsonPath = path.join(root, 'src', 'pages.json')
- const pagesJson = JSON.parse(fs.readFileSync(pagesJsonPath, 'utf8'))
- for (const sub of pagesJson.subPackages) {
- for (const page of sub.pages) {
- if (page.path === 'pages/list') {
- page.style = { ...page.style, enablePullDownRefresh: true }
- }
- }
- }
- fs.writeFileSync(pagesJsonPath, JSON.stringify(pagesJson, null, 2) + '\n', 'utf8')
- console.log('pages.json: enablePullDownRefresh applied to list pages')
|