@tuoyuan/module-page-select 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,284 @@
1
+ # template-page-select
2
+
3
+ Vue 3 组件:用于选择业务模块、对应页面,编辑页面自带配置参数,区分移动端和web端,产出配置数据供页面渲染、路由绑定使用。
4
+
5
+ ## 功能特性
6
+
7
+ - ✅ 模块与页面二级联动选择
8
+ - ✅ 支持模块、页面数据缓存
9
+ - ✅ 基于 JSON Schema 的动态表单渲染
10
+ - ✅ 区分移动端(mobile)和 Web 端(external)
11
+ - ✅ 支持默认值回显
12
+ - ✅ 自定义数据获取方法
13
+ - ✅ 完整的 TypeScript 类型定义
14
+
15
+ ## 安装
16
+
17
+ ```bash
18
+ npm install template-page-select
19
+ ```
20
+
21
+ ## 使用
22
+
23
+ ### 全局注册
24
+
25
+ ```javascript
26
+ import { createApp } from 'vue'
27
+ import ModulePageSelect from 'template-page-select'
28
+ import App from './App.vue'
29
+
30
+ const app = createApp(App)
31
+ app.use(ModulePageSelect)
32
+ app.mount('#app')
33
+ ```
34
+
35
+ ### 局部引入
36
+
37
+ ```vue
38
+ <template>
39
+ <ModulePageSelect
40
+ type="mobile"
41
+ :fetchModules="getModules"
42
+ :fetchPages="getPages"
43
+ @confirm="handleConfirm"
44
+ />
45
+ </template>
46
+
47
+ <script>
48
+ import ModulePageSelect from 'template-page-select'
49
+
50
+ export default {
51
+ components: {
52
+ ModulePageSelect
53
+ },
54
+ methods: {
55
+ async getModules() {
56
+ // 返回模块列表
57
+ const res = await fetch('/api/modules')
58
+ return res.json()
59
+ },
60
+ async getPages(moduleId, pageType) {
61
+ // 返回页面列表
62
+ const res = await fetch(`/api/pages?moduleId=${moduleId}&type=${pageType}`)
63
+ return res.json()
64
+ },
65
+ handleConfirm(config) {
66
+ console.log('选中配置:', config)
67
+ // config 格式:
68
+ // {
69
+ // module_id: "66613bff9aa40000",
70
+ // module_name: "操作日志",
71
+ // page_id: "6663c53083e40000",
72
+ // page_name: "操作日志",
73
+ // page_type: 1,
74
+ // configJson: {}
75
+ // }
76
+ }
77
+ }
78
+ }
79
+ </script>
80
+ ```
81
+
82
+ ## API
83
+
84
+ ### Props
85
+
86
+ | 参数 | 说明 | 类型 | 可选值 | 默认值 |
87
+ |------|------|------|--------|--------|
88
+ | type | 终端类型 | String | mobile / external | mobile |
89
+ | defaultModuleId | 默认模块ID(用于回显) | String | - | '' |
90
+ | defaultPageId | 默认页面ID(用于回显) | String | - | '' |
91
+ | fetchModules | 自定义模块列表获取方法 | Function | - | null |
92
+ | fetchPages | 自定义页面列表获取方法 | Function(moduleId, pageType) | - | null |
93
+
94
+ ### Events
95
+
96
+ | 事件名 | 说明 | 回调参数 |
97
+ |--------|------|----------|
98
+ | confirm | 确认选择时触发 | config: PageConfig |
99
+ | error | 发生错误时触发 | { type: string, error: Error } |
100
+
101
+ ### 数据格式
102
+
103
+ #### 模块数据格式
104
+
105
+ ```javascript
106
+ {
107
+ id: "66613bff9aa40000",
108
+ name: "操作日志"
109
+ }
110
+ ```
111
+
112
+ #### 页面数据格式
113
+
114
+ ```javascript
115
+ {
116
+ id: "6663c53083e40000",
117
+ name: "操作日志",
118
+ type: 1, // 0: 移动端, 1: Web端
119
+ options: {
120
+ // JSON Schema 格式的配置
121
+ properties: {
122
+ wechatId: {
123
+ type: "string",
124
+ title: "微信ID",
125
+ description: "请输入微信ID"
126
+ },
127
+ groupName: {
128
+ type: "string",
129
+ title: "业务分组"
130
+ }
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ #### 输出配置格式
137
+
138
+ ```javascript
139
+ {
140
+ module_id: "66613bff9aa40000",
141
+ module_name: "操作日志",
142
+ page_id: "6663c53083e40000",
143
+ page_name: "操作日志",
144
+ page_type: 1,
145
+ configJson: {
146
+ wechatId: "xxx",
147
+ groupName: "xxx"
148
+ }
149
+ }
150
+ ```
151
+
152
+ ## 使用示例
153
+
154
+ ### 示例 1:基础通用调用
155
+
156
+ ```vue
157
+ <template>
158
+ <ModulePageSelect
159
+ type="mobile"
160
+ :fetchModules="fetchModules"
161
+ :fetchPages="fetchPages"
162
+ @confirm="handlePageConfirm"
163
+ />
164
+ </template>
165
+
166
+ <script>
167
+ export default {
168
+ methods: {
169
+ async fetchModules() {
170
+ // 实现模块获取逻辑
171
+ return [
172
+ { id: '1', name: '模块1' },
173
+ { id: '2', name: '模块2' }
174
+ ]
175
+ },
176
+ async fetchPages(moduleId, pageType) {
177
+ // 实现页面获取逻辑
178
+ return [
179
+ {
180
+ id: '1',
181
+ name: '页面1',
182
+ type: pageType,
183
+ options: {
184
+ properties: {
185
+ field1: { type: 'string', title: '字段1' }
186
+ }
187
+ }
188
+ }
189
+ ]
190
+ },
191
+ handlePageConfirm(pageConfig) {
192
+ console.log('选中页面配置', pageConfig)
193
+ }
194
+ }
195
+ }
196
+ </script>
197
+ ```
198
+
199
+ ### 示例 2:回显已有页面数据
200
+
201
+ ```vue
202
+ <template>
203
+ <ModulePageSelect
204
+ type="external"
205
+ :defaultModuleId="form.moduleId"
206
+ :defaultPageId="form.pageId"
207
+ :fetchModules="fetchModules"
208
+ :fetchPages="fetchPages"
209
+ @confirm="savePageInfo"
210
+ />
211
+ </template>
212
+
213
+ <script>
214
+ export default {
215
+ data() {
216
+ return {
217
+ form: {
218
+ moduleId: '66613bff9aa40000',
219
+ pageId: '6663c53083e40000'
220
+ }
221
+ }
222
+ },
223
+ methods: {
224
+ async fetchModules() {
225
+ // 获取模块列表
226
+ },
227
+ async fetchPages(moduleId, pageType) {
228
+ // 获取页面列表
229
+ },
230
+ savePageInfo(data) {
231
+ // 存储选中的模块、页面及配置
232
+ this.form.moduleId = data.module_id
233
+ this.form.pageId = data.page_id
234
+ console.log('配置数据:', data.configJson)
235
+ }
236
+ }
237
+ }
238
+ </script>
239
+ ```
240
+
241
+ ## 核心功能说明
242
+
243
+ ### 1. 模块与页面加载逻辑
244
+
245
+ - 初始化优先读取模块缓存,无缓存再请求接口拉取模块列表
246
+ - 切换模块清空旧页面数据,重新获取当前模块下所有页面并缓存
247
+ - 选中页面:加载页面配置
248
+ - 有配置(非空对象)→ 渲染动态表单
249
+ - 无配置(null/{})→ 不展示表单区域
250
+
251
+ ### 2. 动态表单渲染
252
+
253
+ 组件支持基于 JSON Schema 的动态表单渲染,支持以下字段类型:
254
+
255
+ - `string` → 文本输入框
256
+ - `number` / `integer` → 数字输入框
257
+ - `enum` → 下拉选择框
258
+
259
+ ### 3. 配置使用规则
260
+
261
+ 1. 前端用 `page_id` 绑定页面路由
262
+ 2. 后端解析只依赖 `module_id` 和 `page_id`,名称字段仅做展示
263
+ 3. 页面初始化读取 `configJson`,回填表单
264
+ 4. 根据 `page_type` 走不同端逻辑(0: 移动端, 1: Web端)
265
+
266
+ ## 开发
267
+
268
+ ```bash
269
+ # 安装依赖
270
+ npm install
271
+
272
+ # 开发模式
273
+ npm run serve
274
+
275
+ # 构建库文件
276
+ npm run build:lib
277
+
278
+ # 代码检查
279
+ npm run lint
280
+ ```
281
+
282
+ ## License
283
+
284
+ MIT
package/dist/demo.html ADDED
@@ -0,0 +1 @@
1
+ <!doctype html><meta charset="utf-8"><title>module-page-select demo</title><script src="./module-page-select.umd.js"></script><script>console.log(module-page-select)</script>