提交 | 用户 | 时间
|
820397
|
1 |
import { |
H |
2 |
useDictSelectRule, |
|
3 |
useEditorRule, |
|
4 |
useSelectRule, |
|
5 |
useUploadFileRule, |
|
6 |
useUploadImgRule, |
|
7 |
useUploadImgsRule |
|
8 |
} from './config' |
|
9 |
import { Ref } from 'vue' |
|
10 |
import { Menu } from '@/components/FormCreate/src/type' |
|
11 |
import { apiSelectRule } from '@/components/FormCreate/src/config/selectRule' |
|
12 |
|
|
13 |
/** |
|
14 |
* 表单设计器增强 hook |
|
15 |
* 新增 |
|
16 |
* - 文件上传 |
|
17 |
* - 单图上传 |
|
18 |
* - 多图上传 |
|
19 |
* - 字典选择器 |
|
20 |
* - 用户选择器 |
|
21 |
* - 部门选择器 |
|
22 |
* - 富文本 |
|
23 |
*/ |
|
24 |
export const useFormCreateDesigner = async (designer: Ref) => { |
|
25 |
const editorRule = useEditorRule() |
|
26 |
const uploadFileRule = useUploadFileRule() |
|
27 |
const uploadImgRule = useUploadImgRule() |
|
28 |
const uploadImgsRule = useUploadImgsRule() |
|
29 |
|
|
30 |
/** |
|
31 |
* 构建表单组件 |
|
32 |
*/ |
|
33 |
const buildFormComponents = () => { |
|
34 |
// 移除自带的上传组件规则,使用 uploadFileRule、uploadImgRule、uploadImgsRule 替代 |
|
35 |
designer.value?.removeMenuItem('upload') |
|
36 |
// 移除自带的富文本组件规则,使用 editorRule 替代 |
|
37 |
designer.value?.removeMenuItem('fc-editor') |
|
38 |
const components = [editorRule, uploadFileRule, uploadImgRule, uploadImgsRule] |
|
39 |
components.forEach((component) => { |
|
40 |
// 插入组件规则 |
|
41 |
designer.value?.addComponent(component) |
|
42 |
// 插入拖拽按钮到 `main` 分类下 |
|
43 |
designer.value?.appendMenuItem('main', { |
|
44 |
icon: component.icon, |
|
45 |
name: component.name, |
|
46 |
label: component.label |
|
47 |
}) |
|
48 |
}) |
|
49 |
} |
|
50 |
|
|
51 |
const userSelectRule = useSelectRule({ |
|
52 |
name: 'UserSelect', |
|
53 |
label: '用户选择器', |
|
54 |
icon: 'icon-user-o' |
|
55 |
}) |
|
56 |
const deptSelectRule = useSelectRule({ |
|
57 |
name: 'DeptSelect', |
|
58 |
label: '部门选择器', |
|
59 |
icon: 'icon-address-card-o' |
|
60 |
}) |
|
61 |
const dictSelectRule = useDictSelectRule() |
|
62 |
const apiSelectRule0 = useSelectRule({ |
|
63 |
name: 'ApiSelect', |
|
64 |
label: '接口选择器', |
|
65 |
icon: 'icon-server', |
|
66 |
props: [...apiSelectRule] |
|
67 |
}) |
|
68 |
|
|
69 |
/** |
|
70 |
* 构建系统字段菜单 |
|
71 |
*/ |
|
72 |
const buildSystemMenu = () => { |
|
73 |
// 移除自带的下拉选择器组件,使用 currencySelectRule 替代 |
|
74 |
// designer.value?.removeMenuItem('select') |
|
75 |
// designer.value?.removeMenuItem('radio') |
|
76 |
// designer.value?.removeMenuItem('checkbox') |
|
77 |
const components = [userSelectRule, deptSelectRule, dictSelectRule, apiSelectRule0] |
|
78 |
const menu: Menu = { |
|
79 |
name: 'system', |
|
80 |
title: '系统字段', |
|
81 |
list: components.map((component) => { |
|
82 |
// 插入组件规则 |
|
83 |
designer.value?.addComponent(component) |
|
84 |
// 插入拖拽按钮到 `system` 分类下 |
|
85 |
return { |
|
86 |
icon: component.icon, |
|
87 |
name: component.name, |
|
88 |
label: component.label |
|
89 |
} |
|
90 |
}) |
|
91 |
} |
|
92 |
designer.value?.addMenu(menu) |
|
93 |
} |
|
94 |
|
|
95 |
onMounted(async () => { |
|
96 |
await nextTick() |
|
97 |
buildFormComponents() |
|
98 |
buildSystemMenu() |
|
99 |
}) |
|
100 |
} |