@builder6/pages 3.2.3 → 3.2.12
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/README.md +426 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,21 +1,438 @@
|
|
|
1
1
|
# Builder6 Pages Module
|
|
2
2
|
|
|
3
|
+
Builder6 Pages 模块为 Builder6 平台提供动态页面管理和渲染能力,支持使用 Amis 低代码框架构建页面,以及 Liquid 模板引擎进行页面定制。该模块是 Builder6 低代码平台的前端核心组件。
|
|
3
4
|
|
|
4
|
-
##
|
|
5
|
+
## 功能特性
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
- **动态页面管理**: 通过数据库配置管理页面,无需重启服务
|
|
8
|
+
- **Amis 集成**: 集成百度 Amis 低代码前端框架
|
|
9
|
+
- **Liquid 模板**: 支持 LiquidJS 模板引擎进行页面定制
|
|
10
|
+
- **Tailwind CSS**: 内置 Tailwind CSS 支持,快速样式开发
|
|
11
|
+
- **组件库集成**: 支持 Steedos Widgets 组件库
|
|
12
|
+
- **页面缓存**: LRU 缓存提升页面加载性能
|
|
13
|
+
- **数据加载器**: DataLoader 优化数据查询性能
|
|
14
|
+
- **项目管理**: 支持页面项目分组管理
|
|
15
|
+
- **响应式设计**: 支持移动端和桌面端适配
|
|
16
|
+
- **实时预览**: 页面编辑器支持实时预览
|
|
17
|
+
|
|
18
|
+
## 安装
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @builder6/pages
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
或
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn add @builder6/pages
|
|
28
|
+
```
|
|
11
29
|
|
|
12
|
-
##
|
|
30
|
+
## 环境变量
|
|
13
31
|
|
|
14
|
-
|
|
32
|
+
### 基本配置
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# 应用根 URL
|
|
15
36
|
B6_ROOT_URL=http://localhost:5100
|
|
37
|
+
|
|
38
|
+
# Amis 包名称(npm 包名或本地路径)
|
|
16
39
|
B6_AMIS_PACKAGE=amis
|
|
40
|
+
|
|
41
|
+
# Amis 版本
|
|
17
42
|
B6_AMIS_VERSION=6.10.0
|
|
43
|
+
|
|
44
|
+
# UNPKG CDN 地址(用于加载前端资源)
|
|
18
45
|
B6_UNPKG_URL=https://unpkg.steedos.cn
|
|
19
|
-
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 组件库配置
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Steedos Widgets 版本
|
|
52
|
+
B6_WIDGETS_VERSION=6.3.11
|
|
53
|
+
|
|
54
|
+
# 使用特定的组件库包
|
|
20
55
|
# B6_WIDGETS_VERSION=@steedos-widgets/liveblocks
|
|
56
|
+
|
|
57
|
+
# 自定义组件库 URL
|
|
58
|
+
B6_WIDGETS_URL=https://unpkg.steedos.cn/@steedos-widgets/core@latest
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 高级配置
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 页面缓存大小(条目数)
|
|
65
|
+
B6_PAGES_CACHE_SIZE=500
|
|
66
|
+
|
|
67
|
+
# 启用页面编辑器
|
|
68
|
+
B6_PAGES_EDITOR_ENABLED=true
|
|
69
|
+
|
|
70
|
+
# 默认主题
|
|
71
|
+
B6_PAGES_THEME=default
|
|
72
|
+
|
|
73
|
+
# 自定义 CSS URL
|
|
74
|
+
B6_PAGES_CUSTOM_CSS_URL=https://example.com/custom.css
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 使用示例
|
|
78
|
+
|
|
79
|
+
### 在 NestJS 应用中集成
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { Module } from '@nestjs/common';
|
|
83
|
+
import { PagesModule } from '@builder6/pages';
|
|
84
|
+
|
|
85
|
+
@Module({
|
|
86
|
+
imports: [PagesModule],
|
|
87
|
+
})
|
|
88
|
+
export class AppModule {}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 创建页面
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { PagesService } from '@builder6/pages';
|
|
95
|
+
|
|
96
|
+
constructor(private pagesService: PagesService) {}
|
|
97
|
+
|
|
98
|
+
async createPage() {
|
|
99
|
+
const page = await this.pagesService.create({
|
|
100
|
+
name: 'dashboard',
|
|
101
|
+
label: '仪表板',
|
|
102
|
+
is_system: false,
|
|
103
|
+
type: 'amis', // 'amis' 或 'liquid'
|
|
104
|
+
schema: {
|
|
105
|
+
type: 'page',
|
|
106
|
+
title: '仪表板',
|
|
107
|
+
body: [
|
|
108
|
+
{
|
|
109
|
+
type: 'service',
|
|
110
|
+
api: '/api/v6/stats',
|
|
111
|
+
body: [
|
|
112
|
+
{
|
|
113
|
+
type: 'cards',
|
|
114
|
+
source: '$items',
|
|
115
|
+
card: {
|
|
116
|
+
body: [
|
|
117
|
+
{
|
|
118
|
+
type: 'tpl',
|
|
119
|
+
tpl: '${label}: ${value}'
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
project: 'project_id'
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return page;
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 使用 Amis Schema
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
// 表单页面示例
|
|
139
|
+
const formPageSchema = {
|
|
140
|
+
type: 'page',
|
|
141
|
+
title: '用户表单',
|
|
142
|
+
body: {
|
|
143
|
+
type: 'form',
|
|
144
|
+
api: 'post:/api/v6/users',
|
|
145
|
+
body: [
|
|
146
|
+
{
|
|
147
|
+
type: 'input-text',
|
|
148
|
+
name: 'name',
|
|
149
|
+
label: '姓名',
|
|
150
|
+
required: true
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
type: 'input-email',
|
|
154
|
+
name: 'email',
|
|
155
|
+
label: '邮箱',
|
|
156
|
+
required: true
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
type: 'select',
|
|
160
|
+
name: 'role',
|
|
161
|
+
label: '角色',
|
|
162
|
+
options: [
|
|
163
|
+
{ label: '管理员', value: 'admin' },
|
|
164
|
+
{ label: '用户', value: 'user' }
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// CRUD 页面示例
|
|
172
|
+
const crudPageSchema = {
|
|
173
|
+
type: 'page',
|
|
174
|
+
title: '用户列表',
|
|
175
|
+
body: {
|
|
176
|
+
type: 'crud',
|
|
177
|
+
api: '/api/v6/users',
|
|
178
|
+
columns: [
|
|
179
|
+
{ name: 'name', label: '姓名' },
|
|
180
|
+
{ name: 'email', label: '邮箱' },
|
|
181
|
+
{ name: 'role', label: '角色', type: 'mapping', map: {
|
|
182
|
+
admin: '<span class="label label-success">管理员</span>',
|
|
183
|
+
user: '<span class="label label-info">用户</span>'
|
|
184
|
+
}}
|
|
185
|
+
],
|
|
186
|
+
bulkActions: [
|
|
187
|
+
{
|
|
188
|
+
label: '批量删除',
|
|
189
|
+
actionType: 'ajax',
|
|
190
|
+
api: 'delete:/api/v6/users/${ids|raw}',
|
|
191
|
+
confirmText: '确定要删除?'
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 使用 Liquid 模板
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
async renderLiquidPage(pageId: string, context: any) {
|
|
202
|
+
// 页面内容使用 Liquid 模板
|
|
203
|
+
const template = `
|
|
204
|
+
<div class="container mx-auto p-4">
|
|
205
|
+
<h1 class="text-2xl font-bold">{{ title }}</h1>
|
|
206
|
+
<ul>
|
|
207
|
+
{% for item in items %}
|
|
208
|
+
<li>{{ item.name }} - {{ item.description }}</li>
|
|
209
|
+
{% endfor %}
|
|
210
|
+
</ul>
|
|
211
|
+
</div>
|
|
212
|
+
`;
|
|
213
|
+
|
|
214
|
+
const rendered = await this.pagesService.renderLiquid(template, context);
|
|
215
|
+
return rendered;
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## 数据模型
|
|
220
|
+
|
|
221
|
+
### b6_pages 对象
|
|
222
|
+
|
|
223
|
+
页面配置存储在 `b6_pages` 对象中:
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
interface Page {
|
|
227
|
+
_id: string;
|
|
228
|
+
name: string; // 页面唯一标识
|
|
229
|
+
label: string; // 页面显示名称
|
|
230
|
+
description?: string; // 页面描述
|
|
231
|
+
is_system: boolean; // 是否系统页面
|
|
232
|
+
type: 'amis' | 'liquid'; // 页面类型
|
|
233
|
+
schema?: object; // Amis schema(type=amis时)
|
|
234
|
+
template?: string; // Liquid 模板(type=liquid时)
|
|
235
|
+
path?: string; // 页面路径
|
|
236
|
+
icon?: string; // 页面图标
|
|
237
|
+
visible?: boolean; // 是否可见
|
|
238
|
+
sort?: number; // 排序
|
|
239
|
+
project?: string; // 所属项目
|
|
240
|
+
owner: string; // 所有者
|
|
241
|
+
space: string; // 租户空间
|
|
242
|
+
created: Date;
|
|
243
|
+
modified: Date;
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### b6_projects 对象
|
|
248
|
+
|
|
249
|
+
项目配置存储在 `b6_projects` 对象中:
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
interface Project {
|
|
253
|
+
_id: string;
|
|
254
|
+
name: string; // 项目名称
|
|
255
|
+
label: string; // 项目显示名称
|
|
256
|
+
description?: string; // 项目描述
|
|
257
|
+
owner: string; // 所有者
|
|
258
|
+
members?: string[]; // 项目成员
|
|
259
|
+
space: string; // 租户空间
|
|
260
|
+
created: Date;
|
|
261
|
+
modified: Date;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## API 端点
|
|
266
|
+
|
|
267
|
+
模块提供以下主要 API 端点:
|
|
268
|
+
|
|
269
|
+
### 页面管理
|
|
270
|
+
|
|
271
|
+
- **GET `/api/v6/pages`**: 获取页面列表
|
|
272
|
+
- **GET `/api/v6/pages/:id`**: 获取页面详情
|
|
273
|
+
- **POST `/api/v6/pages`**: 创建页面
|
|
274
|
+
- **PUT `/api/v6/pages/:id`**: 更新页面
|
|
275
|
+
- **DELETE `/api/v6/pages/:id`**: 删除页面
|
|
276
|
+
|
|
277
|
+
### 页面渲染
|
|
278
|
+
|
|
279
|
+
- **GET `/page/:name`**: 渲染页面(根据 name)
|
|
280
|
+
- **GET `/page/:projectId/:name`**: 渲染项目下的页面
|
|
281
|
+
|
|
282
|
+
### 项目管理
|
|
283
|
+
|
|
284
|
+
- **GET `/api/v6/projects`**: 获取项目列表
|
|
285
|
+
- **GET `/api/v6/projects/:id`**: 获取项目详情
|
|
286
|
+
- **POST `/api/v6/projects`**: 创建项目
|
|
287
|
+
- **PUT `/api/v6/projects/:id`**: 更新项目
|
|
288
|
+
- **DELETE `/api/v6/projects/:id`**: 删除项目
|
|
289
|
+
|
|
290
|
+
## Amis 集成
|
|
291
|
+
|
|
292
|
+
### 使用 Amis 组件
|
|
293
|
+
|
|
294
|
+
Builder6 Pages 集成了完整的 Amis 组件库,支持所有 Amis 组件:
|
|
295
|
+
|
|
296
|
+
- **布局组件**: Page, Container, Grid, Flex, Wrapper
|
|
297
|
+
- **表单组件**: Form, Input, Select, DatePicker, Upload
|
|
298
|
+
- **展示组件**: Table, Cards, List, Chart, Image
|
|
299
|
+
- **功能组件**: Service, Dialog, Drawer, Wizard
|
|
300
|
+
- **交互组件**: Button, Action, Nav, Tabs
|
|
301
|
+
|
|
302
|
+
### Amis API 配置
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
// 配置 API 数据源
|
|
306
|
+
const pageSchema = {
|
|
307
|
+
type: 'page',
|
|
308
|
+
body: {
|
|
309
|
+
type: 'service',
|
|
310
|
+
api: {
|
|
311
|
+
method: 'get',
|
|
312
|
+
url: '/api/v6/users',
|
|
313
|
+
headers: {
|
|
314
|
+
'Authorization': 'Bearer ${token}'
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
body: [
|
|
318
|
+
{
|
|
319
|
+
type: 'table',
|
|
320
|
+
source: '$items',
|
|
321
|
+
columns: [
|
|
322
|
+
{ name: 'name', label: '姓名' },
|
|
323
|
+
{ name: 'email', label: '邮箱' }
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
]
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## Tailwind CSS 支持
|
|
332
|
+
|
|
333
|
+
模块内置 Tailwind CSS 支持,可以直接使用 Tailwind 类名:
|
|
334
|
+
|
|
335
|
+
```html
|
|
336
|
+
<div class="container mx-auto px-4">
|
|
337
|
+
<h1 class="text-3xl font-bold text-gray-900 mb-4">
|
|
338
|
+
Welcome to Builder6
|
|
339
|
+
</h1>
|
|
340
|
+
<p class="text-gray-600 leading-relaxed">
|
|
341
|
+
Build pages with ease using Amis and Tailwind CSS.
|
|
342
|
+
</p>
|
|
343
|
+
</div>
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### 自定义 Tailwind 配置
|
|
347
|
+
|
|
348
|
+
可以通过环境变量加载自定义 CSS:
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
B6_PAGES_CUSTOM_CSS_URL=https://cdn.example.com/custom-tailwind.css
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## 性能优化
|
|
355
|
+
|
|
356
|
+
### 页面缓存
|
|
357
|
+
|
|
358
|
+
使用 LRU 缓存优化页面加载性能:
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
# 设置缓存大小
|
|
362
|
+
B6_PAGES_CACHE_SIZE=1000
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### DataLoader
|
|
366
|
+
|
|
367
|
+
使用 DataLoader 优化数据查询,避免 N+1 查询问题。
|
|
368
|
+
|
|
369
|
+
## 使用场景
|
|
370
|
+
|
|
371
|
+
- **管理后台**: 快速构建管理后台界面
|
|
372
|
+
- **数据看板**: 创建数据可视化仪表板
|
|
373
|
+
- **表单应用**: 构建各类表单应用
|
|
374
|
+
- **工作流界面**: 工作流审批界面
|
|
375
|
+
- **报表系统**: 动态报表和统计页面
|
|
376
|
+
- **移动应用**: 响应式移动端页面
|
|
377
|
+
|
|
378
|
+
## Steedos 依赖
|
|
379
|
+
|
|
380
|
+
该模块依赖以下 Steedos 对象:
|
|
381
|
+
|
|
382
|
+
```yaml
|
|
383
|
+
objects:
|
|
384
|
+
- b6_pages # 页面配置
|
|
385
|
+
- b6_projects # 项目管理
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## 依赖项
|
|
389
|
+
|
|
390
|
+
### 主要依赖
|
|
391
|
+
|
|
392
|
+
- `liquidjs`: ^10.24.0 - Liquid 模板引擎
|
|
393
|
+
- `dataloader`: ^2.2.3 - 数据加载优化
|
|
394
|
+
- `lru-cache`: ^11.2.4 - LRU 缓存
|
|
395
|
+
- `tailwindcss`: ^3.4.19 - CSS 框架
|
|
396
|
+
- `autoprefixer`: ^10.4.23 - CSS 自动前缀
|
|
397
|
+
- `cssnano`: ^7.1.2 - CSS 压缩
|
|
398
|
+
|
|
399
|
+
### Peer Dependencies
|
|
400
|
+
|
|
401
|
+
- `@builder6/core`: ^3.0.10 - 核心功能模块
|
|
402
|
+
- `@builder6/moleculer`: ^3.0.10 - 微服务框架
|
|
403
|
+
- `@nestjs/common`: ^11.0.0 - NestJS 核心
|
|
404
|
+
- `@nestjs/core`: ^11.0.0 - NestJS 核心
|
|
405
|
+
- `@nestjs/swagger`: ^11.0.7 - API 文档
|
|
406
|
+
- `@steedos/auth`: ^3.0 - Steedos 认证
|
|
407
|
+
- `@steedos/objectql`: ^3.0 - Steedos 对象查询
|
|
408
|
+
|
|
409
|
+
## 开发
|
|
410
|
+
|
|
411
|
+
### 构建
|
|
412
|
+
|
|
413
|
+
```bash
|
|
414
|
+
npm run build
|
|
21
415
|
```
|
|
416
|
+
|
|
417
|
+
### 监听模式
|
|
418
|
+
|
|
419
|
+
```bash
|
|
420
|
+
npm run build:watch
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### 格式化代码
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
npm run format
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## 参考资源
|
|
430
|
+
|
|
431
|
+
- [Amis 官方文档](https://aisuda.bce.baidu.com/amis/zh-CN/docs/index)
|
|
432
|
+
- [LiquidJS 文档](https://liquidjs.com/)
|
|
433
|
+
- [Tailwind CSS 文档](https://tailwindcss.com/docs)
|
|
434
|
+
- [Steedos Widgets](https://github.com/steedos/widgets)
|
|
435
|
+
|
|
436
|
+
## License
|
|
437
|
+
|
|
438
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder6/pages",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.12",
|
|
4
4
|
"main": "dist/plugin.module.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "6d6e13fed8d4b3c6de14f84dcb6287c5661ea6f6"
|
|
37
37
|
}
|