@cicctencent/formily 0.0.0-stage → 0.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/.eslintrc.js +40 -0
- package/.prettierrc.js +28 -0
- package/.vscode/launch.json +23 -0
- package/CHANGELOG.md +8 -0
- package/README.md +22 -2
- package/babel.config.js +3 -0
- package/build/build.js +96 -0
- package/build/rollup.config.bundle.js +63 -0
- package/build/update.version.js +35 -0
- package/dist/index.css +2516 -0
- package/dist/index.js +8377 -0
- package/dist/schema-field/index.css +2466 -0
- package/dist/schema-field/index.js +8213 -0
- package/dist/transform/index.js +551 -0
- package/dist/validate/index.js +1104 -0
- package/dist/vue-form/index.css +2516 -0
- package/dist/vue-form/index.js +8359 -0
- package/docs/.vuepress/client.ts +15 -0
- package/docs/.vuepress/components/code-preview.vue +203 -0
- package/docs/.vuepress/components/highlight.ts +53 -0
- package/docs/.vuepress/config.ts +39 -0
- package/docs/.vuepress/util.ts +7 -0
- package/docs/README.md +30 -0
- package/docs/components/anyOf.md +26 -0
- package/docs/components/array-cards.md +12 -0
- package/docs/components/array-collapse.md +12 -0
- package/docs/components/array-items.md +12 -0
- package/docs/components/array-table.md +12 -0
- package/docs/components/array-tabs.md +16 -0
- package/docs/components/cascader.md +12 -0
- package/docs/components/checkbox.md +12 -0
- package/docs/components/event.md +27 -0
- package/docs/components/hotArea.md +25 -0
- package/docs/components/index.md +4 -0
- package/docs/components/input.md +30 -0
- package/docs/components/layout-group.md +19 -0
- package/docs/components/link.md +22 -0
- package/docs/components/oneOf.md +8 -0
- package/docs/components/radio.md +12 -0
- package/docs/components/rich-editor.md +21 -0
- package/docs/components/select.md +34 -0
- package/docs/components/space.md +11 -0
- package/docs/components/switch.md +20 -0
- package/docs/components/text.md +21 -0
- package/docs/components/time-picker.md +11 -0
- package/docs/components/transfer.md +14 -0
- package/docs/components/upload-button.md +28 -0
- package/docs/demos/any-of/index.vue +66 -0
- package/docs/demos/array-cards/index.vue +105 -0
- package/docs/demos/array-collapse/index.vue +155 -0
- package/docs/demos/array-items/index.vue +171 -0
- package/docs/demos/array-table/index.vue +115 -0
- package/docs/demos/array-tabs/index.vue +56 -0
- package/docs/demos/cascader/index.vue +297 -0
- package/docs/demos/checkbox/index.vue +39 -0
- package/docs/demos/event/index.vue +436 -0
- package/docs/demos/hotArea/index.vue +240 -0
- package/docs/demos/index.vue +36 -0
- package/docs/demos/input/index.vue +46 -0
- package/docs/demos/layout-group/index.vue +51 -0
- package/docs/demos/link/index.vue +32 -0
- package/docs/demos/radio/index.vue +36 -0
- package/docs/demos/rich-editor/index.vue +22 -0
- package/docs/demos/select/index.vue +76 -0
- package/docs/demos/space/index.vue +93 -0
- package/docs/demos/switch/index.vue +31 -0
- package/docs/demos/text/index.vue +38 -0
- package/docs/demos/time-picker/index.vue +39 -0
- package/docs/demos/transfer/index.vue +26 -0
- package/docs/demos/upload-button/index.vue +27 -0
- package/docs/demos/x-data/add-button-title.vue +101 -0
- package/docs/demos/x-data/send-message.vue +33 -0
- package/docs/demos/x-reactions/any-of.vue +40 -0
- package/docs/demos/x-reactions/x-reactions.vue +39 -0
- package/docs/guide/component-extend.md +23 -0
- package/docs/guide/extra-bury-report.md +64 -0
- package/docs/guide/schema.md +22 -0
- package/docs/guide/x-data.md +41 -0
- package/docs/guide/x-reactions.md +20 -0
- package/example/.browserslistrc +4 -0
- package/example/.eslintrc.js +20 -0
- package/example/README.md +24 -0
- package/example/index.html +15 -0
- package/example/jest.config.js +26 -0
- package/example/package.json +50 -0
- package/example/public/favicon.ico +0 -0
- package/example/public/index.html +17 -0
- package/example/src/App.vue +25 -0
- package/example/src/assets/logo.png +0 -0
- package/example/src/components/HelloWorld.vue +148 -0
- package/example/src/components/group/index.vue +16 -0
- package/example/src/components/uploadBtn/index.vue +44 -0
- package/example/src/components/uploadBtn/upload-icon.svg +6 -0
- package/example/src/layout/component/Aside.vue +39 -0
- package/example/src/layout/component/Main.vue +9 -0
- package/example/src/layout/index.vue +15 -0
- package/example/src/main.ts +17 -0
- package/example/src/router/index.ts +99 -0
- package/example/src/shims-vue.d.ts +6 -0
- package/example/src/store/index.ts +9 -0
- package/example/src/views/demo/any-of/data.ts +38 -0
- package/example/src/views/demo/any-of/index.vue +35 -0
- package/example/src/views/demo/array-cards/data.ts +65 -0
- package/example/src/views/demo/array-cards/index.vue +33 -0
- package/example/src/views/demo/array-items/data.ts +29 -0
- package/example/src/views/demo/array-items/index.vue +33 -0
- package/example/src/views/demo/cloud-button/data.ts +14 -0
- package/example/src/views/demo/cloud-button/index.vue +22 -0
- package/example/src/views/demo/color-group/data.ts +15 -0
- package/example/src/views/demo/color-group/index.vue +22 -0
- package/example/src/views/demo/color-picker/data.ts +21 -0
- package/example/src/views/demo/color-picker/index.vue +33 -0
- package/example/src/views/demo/datatime/data.ts +62 -0
- package/example/src/views/demo/datatime/index.vue +22 -0
- package/example/src/views/demo/event/data.ts +184 -0
- package/example/src/views/demo/event/index.vue +33 -0
- package/example/src/views/demo/hot-area/data.ts +196 -0
- package/example/src/views/demo/hot-area/index.vue +33 -0
- package/example/src/views/demo/input/data.ts +39 -0
- package/example/src/views/demo/input/index.vue +33 -0
- package/example/src/views/demo/link/data.ts +23 -0
- package/example/src/views/demo/link/index.vue +22 -0
- package/example/src/views/demo/one-of/data.ts +139 -0
- package/example/src/views/demo/one-of/index.vue +33 -0
- package/example/src/views/demo/rich-editor/data.ts +12 -0
- package/example/src/views/demo/rich-editor/index.vue +24 -0
- package/example/src/views/demo/select/data.ts +38 -0
- package/example/src/views/demo/select/index.vue +33 -0
- package/example/src/views/demo/upload-button/data1.ts +11 -0
- package/example/src/views/demo/upload-button/data2.ts +12 -0
- package/example/src/views/demo/upload-button/index.vue +42 -0
- package/example/tsconfig.json +32 -0
- package/example/vite.config.ts +12 -0
- package/jest.config.js +4 -0
- package/package.json +92 -4
- package/src/components/__builtins__/configs/index.ts +1 -0
- package/src/components/__builtins__/index.ts +2 -0
- package/src/components/__builtins__/shared/create-context.ts +54 -0
- package/src/components/__builtins__/shared/index.ts +7 -0
- package/src/components/__builtins__/shared/loading.ts +20 -0
- package/src/components/__builtins__/shared/portal.ts +43 -0
- package/src/components/__builtins__/shared/resolve-component.ts +22 -0
- package/src/components/__builtins__/shared/transform-component.ts +33 -0
- package/src/components/__builtins__/shared/types.ts +8 -0
- package/src/components/__builtins__/shared/utils.ts +35 -0
- package/src/components/__builtins__/styles/common.scss +22 -0
- package/src/components/__builtins__/styles/element-plus.scss +1094 -0
- package/src/components/any-of/index.ts +20 -0
- package/src/components/array-base/index.ts +413 -0
- package/src/components/array-base/style.scss +53 -0
- package/src/components/array-base/style.ts +2 -0
- package/src/components/array-cards/index.ts +253 -0
- package/src/components/array-cards/style.scss +33 -0
- package/src/components/array-cards/style.ts +7 -0
- package/src/components/array-collapse/index.ts +381 -0
- package/src/components/array-collapse/style.scss +38 -0
- package/src/components/array-collapse/style.ts +10 -0
- package/src/components/array-items/index.ts +213 -0
- package/src/components/array-items/style.scss +82 -0
- package/src/components/array-items/style.ts +4 -0
- package/src/components/array-table/index.ts +567 -0
- package/src/components/array-table/style.scss +84 -0
- package/src/components/array-table/style.ts +11 -0
- package/src/components/array-tabs/index.ts +141 -0
- package/src/components/array-tabs/style.scss +16 -0
- package/src/components/array-tabs/style.ts +5 -0
- package/src/components/base/AnyOf/index.ts +155 -0
- package/src/components/base/AnyOf/index.vue +111 -0
- package/src/components/base/CloudButton/index.ts +46 -0
- package/src/components/base/CloudButton/index.vue +128 -0
- package/src/components/base/ColorGroup/index.ts +57 -0
- package/src/components/base/ColorGroup/index.vue +30 -0
- package/src/components/base/ColorPicker/index.ts +45 -0
- package/src/components/base/ColorPicker/index.vue +50 -0
- package/src/components/base/Container/index.vue +39 -0
- package/src/components/base/HotArea/index.ts +698 -0
- package/src/components/base/HotArea/index.vue +565 -0
- package/src/components/base/HotArea/type.ts +18 -0
- package/src/components/base/Input/index.vue +150 -0
- package/src/components/base/LayoutGroup/index.vue +40 -0
- package/src/components/base/Link/index.vue +43 -0
- package/src/components/base/Middleware/index.ts +235 -0
- package/src/components/base/Middleware/index.vue +169 -0
- package/src/components/base/OneOf/index.ts +105 -0
- package/src/components/base/OneOf/index.vue +85 -0
- package/src/components/base/RichEditor/index.ts +13 -0
- package/src/components/base/RichEditor/index.vue +120 -0
- package/src/components/base/RichEditor/options.ts +24 -0
- package/src/components/base/Select/index.ts +106 -0
- package/src/components/base/Select/index.vue +161 -0
- package/src/components/base/Switch/index.vue +42 -0
- package/src/components/base/Text/index.vue +47 -0
- package/src/components/base/event/index.ts +226 -0
- package/src/components/base/event/index.vue +356 -0
- package/src/components/cascader/index.ts +48 -0
- package/src/components/cascader/style.ts +5 -0
- package/src/components/checkbox/index.ts +166 -0
- package/src/components/checkbox/style.ts +5 -0
- package/src/components/cloud-button/index.ts +21 -0
- package/src/components/color-group/index.ts +18 -0
- package/src/components/color-picker/index.ts +18 -0
- package/src/components/container/index.ts +18 -0
- package/src/components/data-time/index.ts +24 -0
- package/src/components/date-picker/index.ts +51 -0
- package/src/components/date-picker/style.ts +4 -0
- package/src/components/editable/index.ts +261 -0
- package/src/components/editable/style.scss +55 -0
- package/src/components/editable/style.ts +5 -0
- package/src/components/el-form-item/index.ts +21 -0
- package/src/components/el-form-item/style.ts +3 -0
- package/src/components/event/index.ts +16 -0
- package/src/components/form/index.ts +94 -0
- package/src/components/form/style.scss +0 -0
- package/src/components/form/style.ts +3 -0
- package/src/components/form-button-group/index.ts +74 -0
- package/src/components/form-button-group/style.scss +0 -0
- package/src/components/form-button-group/style.ts +4 -0
- package/src/components/form-collapse/index.ts +215 -0
- package/src/components/form-collapse/style.scss +6 -0
- package/src/components/form-collapse/style.ts +4 -0
- package/src/components/form-dialog/index.ts +433 -0
- package/src/components/form-dialog/style.ts +4 -0
- package/src/components/form-drawer/index.ts +424 -0
- package/src/components/form-drawer/style.scss +21 -0
- package/src/components/form-drawer/style.ts +4 -0
- package/src/components/form-grid/index.ts +181 -0
- package/src/components/form-grid/style.scss +5 -0
- package/src/components/form-grid/style.ts +1 -0
- package/src/components/form-item/animation.scss +72 -0
- package/src/components/form-item/grid.scss +171 -0
- package/src/components/form-item/index.ts +642 -0
- package/src/components/form-item/style.scss +521 -0
- package/src/components/form-item/style.ts +2 -0
- package/src/components/form-item/var.scss +17 -0
- package/src/components/form-layout/index.ts +161 -0
- package/src/components/form-layout/style.scss +6 -0
- package/src/components/form-layout/style.ts +1 -0
- package/src/components/form-layout/useResponsiveFormLayout.ts +118 -0
- package/src/components/form-step/index.ts +210 -0
- package/src/components/form-step/style.ts +2 -0
- package/src/components/form-tab/index.ts +172 -0
- package/src/components/form-tab/style.scss +6 -0
- package/src/components/form-tab/style.ts +4 -0
- package/src/components/hot-area/index.ts +20 -0
- package/src/components/index.ts +49 -0
- package/src/components/input/index.ts +35 -0
- package/src/components/input/style.ts +4 -0
- package/src/components/input-number/index.ts +36 -0
- package/src/components/input-number/style.ts +3 -0
- package/src/components/layout-group/index.ts +18 -0
- package/src/components/link/index.ts +18 -0
- package/src/components/middleware/index.ts +21 -0
- package/src/components/one-of/index.ts +20 -0
- package/src/components/placeholder-input/index.ts +21 -0
- package/src/components/placeholder-input/index.vue +87 -0
- package/src/components/preview-text/index.ts +303 -0
- package/src/components/preview-text/style.ts +9 -0
- package/src/components/radio/index.ts +109 -0
- package/src/components/radio/style.ts +3 -0
- package/src/components/reset/index.ts +52 -0
- package/src/components/reset/style.ts +1 -0
- package/src/components/rich-editor/index.ts +18 -0
- package/src/components/row/index.ts +20 -0
- package/src/components/row/index.vue +53 -0
- package/src/components/select/index.ts +19 -0
- package/src/components/select/style.ts +5 -0
- package/src/components/space/index.ts +98 -0
- package/src/components/space/style.scss +24 -0
- package/src/components/space/style.ts +1 -0
- package/src/components/submit/index.ts +59 -0
- package/src/components/submit/style.ts +1 -0
- package/src/components/switch/index.ts +9 -0
- package/src/components/switch/style.ts +1 -0
- package/src/components/text/index.ts +21 -0
- package/src/components/time-picker/index.ts +21 -0
- package/src/components/time-picker/style.ts +4 -0
- package/src/components/transfer/index.ts +12 -0
- package/src/components/transfer/style.ts +1 -0
- package/src/components/upload/index.ts +136 -0
- package/src/components/upload/style.ts +2 -0
- package/src/components/upload-button/index.ts +21 -0
- package/src/components/upload-button/index.vue +199 -0
- package/src/createScemaField.ts +14 -0
- package/src/index.ts +41 -0
- package/src/schema-field/index.ts +11 -0
- package/src/scope.ts +29 -0
- package/src/transform/core.ts +404 -0
- package/src/transform/index.ts +11 -0
- package/src/transform/transform.ts +59 -0
- package/src/transform/utils/constant.ts +79 -0
- package/src/transform/utils/func.ts +145 -0
- package/src/typings/common.ts +37 -0
- package/src/typings/vue-shim.d.ts +7 -0
- package/src/typings/vue-test-utils.d.ts +11 -0
- package/src/utils/anyof_utils.ts +95 -0
- package/src/utils/common.ts +15 -0
- package/src/validate/index.ts +648 -0
- package/src/validate/utils/constant.ts +2 -0
- package/src/vue-form/index.ts +18 -0
- package/src/vue-form/index.vue +106 -0
- package/src/vue-form/useForm.ts +112 -0
- package/tests/data/anyof.ts +40 -0
- package/tests/data/image.ts +472 -0
- package/tests/fixtures/validate.ts +63 -0
- package/tests/unit/transform.spec.ts +253 -0
- package/tests/unit/utils.spec.ts +10 -0
- package/tests/unit/validate.spec.ts +256 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { ref, getCurrentInstance, watch, computed } from 'vue';
|
|
2
|
+
import {
|
|
3
|
+
createForm,
|
|
4
|
+
onFormInit,
|
|
5
|
+
onFormValuesChange,
|
|
6
|
+
} from '@formily/core';
|
|
7
|
+
import { transformSchema } from '../../../transform';
|
|
8
|
+
import { Form } from '@formily/core';
|
|
9
|
+
import { FormilyValidate } from '../../../validate/index';
|
|
10
|
+
import { ElMessage } from '@cicctencent/jtui'
|
|
11
|
+
import { cloneDeep } from '@cicctencent/ark-util'
|
|
12
|
+
interface Event {
|
|
13
|
+
key: string;
|
|
14
|
+
form?: Form;
|
|
15
|
+
schema?: Object;
|
|
16
|
+
lastName?: string;
|
|
17
|
+
}
|
|
18
|
+
export default function (props, emit) {
|
|
19
|
+
const dialogVisible = ref(false);
|
|
20
|
+
const eventList = ref<Array<Event>>([]);
|
|
21
|
+
let formValue: any = '';
|
|
22
|
+
const ctx = getCurrentInstance();
|
|
23
|
+
/** schema 配置 */
|
|
24
|
+
const schema = computed(() => JSON.parse(props?.schema ?? '{}'))
|
|
25
|
+
const schemaConfig = computed(() => {
|
|
26
|
+
if (schema.value?.list?.items) {
|
|
27
|
+
return transformSchema({ schema: schema.value?.list?.items ?? {}, ctx, layout: "horizontal" });
|
|
28
|
+
}
|
|
29
|
+
return {};
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const editorState = computed(()=>{
|
|
33
|
+
const list = props?.modelValue?.list??[];
|
|
34
|
+
return list.length > 0;
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// 打开对话框
|
|
38
|
+
let counter = 0;
|
|
39
|
+
function openDialog() {
|
|
40
|
+
formValue = JSON.parse(JSON.stringify(props.modelValue));
|
|
41
|
+
eventList.value = [];
|
|
42
|
+
// 数据回显
|
|
43
|
+
if (Array.isArray(formValue?.list) && formValue?.list?.length) {
|
|
44
|
+
(formValue.list as any[]).forEach((item,index) => {
|
|
45
|
+
eventList.value.push({
|
|
46
|
+
// 光靠Date.now 不稳定
|
|
47
|
+
key: Date.now() + counter + '',
|
|
48
|
+
lastName: item?.handler?.name,
|
|
49
|
+
});
|
|
50
|
+
counter++
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
eventList.value.forEach((it,index) =>{
|
|
55
|
+
|
|
56
|
+
it.form = createForm({
|
|
57
|
+
effects() {
|
|
58
|
+
onFormInit(form => {
|
|
59
|
+
// 存在自定义组件的回显,必须在init阶段setValues,否则自定义组件拿不到值
|
|
60
|
+
form.setValues(JSON.parse(JSON.stringify(formValue.list[index])));
|
|
61
|
+
});
|
|
62
|
+
onFormValuesChange((form) => {
|
|
63
|
+
console.log('event onFormValuesChange',form.values)
|
|
64
|
+
eventChangeEffect(form,index)
|
|
65
|
+
return;
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
readOnly: props.readOnly,
|
|
69
|
+
})
|
|
70
|
+
it.schema = getSchemaConfig(formValue.list[index]?.handler?.name || '')
|
|
71
|
+
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
// 设置表单
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
dialogVisible.value = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 事件变化副作用
|
|
82
|
+
* @param form
|
|
83
|
+
* @param index
|
|
84
|
+
*/
|
|
85
|
+
function eventChangeEffect(form,index){
|
|
86
|
+
if(eventList.value.length && eventList.value[index].lastName !== form.values?.handler?.name){
|
|
87
|
+
// 记录事件名
|
|
88
|
+
eventList.value[index].lastName = form.values?.handler?.name
|
|
89
|
+
// 重新设置schema
|
|
90
|
+
eventList.value[index].schema = getSchemaConfig(form.values.handler.name)
|
|
91
|
+
//回收字段模型
|
|
92
|
+
form.clearFormGraph("handler.options.*")
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function validate(){
|
|
97
|
+
let validateRes = [];
|
|
98
|
+
eventList.value.forEach(it =>{
|
|
99
|
+
const result = new FormilyValidate({schema: it.schema,data:it.form.values}).validate();
|
|
100
|
+
validateRes = validateRes.concat(result);
|
|
101
|
+
})
|
|
102
|
+
console.log("validateRes",validateRes)
|
|
103
|
+
return validateRes;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function onConfirm() {
|
|
107
|
+
// 触发校验
|
|
108
|
+
eventList.value.forEach(m => m.form.validate())
|
|
109
|
+
// 校验标识 0 通过 -1 不通过
|
|
110
|
+
let validateFlag = 0;
|
|
111
|
+
const validateRes = validate();
|
|
112
|
+
for(let i = 0;i<eventList.value.length;i++){
|
|
113
|
+
const item = eventList.value[i];
|
|
114
|
+
|
|
115
|
+
if( validateRes.length || !item.form.values?.handler?.name){
|
|
116
|
+
validateFlag = -1;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if(validateFlag !== -1){
|
|
122
|
+
const result: any[] = [];
|
|
123
|
+
|
|
124
|
+
eventList.value.forEach(item => {
|
|
125
|
+
const data = {...item.form.values}
|
|
126
|
+
// 记录name, 用于校验
|
|
127
|
+
data.handler = Object.assign(data.handler || {},{ _validateKey: data?.handler?.name})
|
|
128
|
+
result.push({ ...data });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const eventRes = {
|
|
132
|
+
list: [],
|
|
133
|
+
};
|
|
134
|
+
eventRes.list = [...result];
|
|
135
|
+
emit('change', eventRes);
|
|
136
|
+
dialogVisible.value = false;
|
|
137
|
+
}else{
|
|
138
|
+
ElMessage.error({ zIndex: 9999, message: "请补全表单必填信息"});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function onCancel() {
|
|
143
|
+
// ElMessageBox.confirm('放弃本次修改内容?', '提示', {
|
|
144
|
+
// type: 'warning',
|
|
145
|
+
// confirmButtonText: '确定',
|
|
146
|
+
// cancelButtonText: '取消',
|
|
147
|
+
// }).then(() => {
|
|
148
|
+
// dialogVisible.value = false;
|
|
149
|
+
// });
|
|
150
|
+
dialogVisible.value = false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 添加新事件
|
|
155
|
+
*/
|
|
156
|
+
function addEvent() {
|
|
157
|
+
// key生成规则: 当前的时间戳
|
|
158
|
+
const event: Event = {
|
|
159
|
+
key: Date.now() + '',
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
eventList.value.push(event);
|
|
163
|
+
event.schema = getSchemaConfig('')
|
|
164
|
+
event.form = createForm({
|
|
165
|
+
effects() {
|
|
166
|
+
onFormValuesChange((form) => {
|
|
167
|
+
console.log('event onFormValuesChange',form.values)
|
|
168
|
+
eventChangeEffect(form,eventList.value.length - 1 )
|
|
169
|
+
return;
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
readOnly: props.readOnly,
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function getSchemaConfig(eName: string){
|
|
177
|
+
try {
|
|
178
|
+
const root = schema.value.list.items
|
|
179
|
+
const DYNAMIC_INJECT_SCHEMA = cloneDeep(root.properties.handler.properties.options);
|
|
180
|
+
let config;
|
|
181
|
+
if(DYNAMIC_INJECT_SCHEMA[eName]){
|
|
182
|
+
// 不存在事件名
|
|
183
|
+
config = cloneDeep(root)
|
|
184
|
+
config.properties.handler.properties.options = DYNAMIC_INJECT_SCHEMA[eName]
|
|
185
|
+
}else{
|
|
186
|
+
// 存在事件名
|
|
187
|
+
config = cloneDeep(root)
|
|
188
|
+
config.properties.handler.properties.options = {}
|
|
189
|
+
}
|
|
190
|
+
return transformSchema({ schema: config || {}, ctx, layout: "horizontal" })
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error('getSchemaConfig',error)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function onDialogClose() {}
|
|
197
|
+
|
|
198
|
+
function onDialogClosed() {}
|
|
199
|
+
|
|
200
|
+
function onDialogOpened() {}
|
|
201
|
+
|
|
202
|
+
/** 删除事件 */
|
|
203
|
+
function onDeleteEvent(key: string) {
|
|
204
|
+
/** 通过key删除事件,比通过index安全,key是唯一不变的 */
|
|
205
|
+
const index = eventList.value.findIndex(m => m.key === key);
|
|
206
|
+
if (-1 === index) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
eventList.value.splice(index, 1);
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
dialogVisible,
|
|
214
|
+
schemaConfig,
|
|
215
|
+
eventList,
|
|
216
|
+
editorState,
|
|
217
|
+
openDialog,
|
|
218
|
+
onConfirm,
|
|
219
|
+
onCancel,
|
|
220
|
+
onDialogClose,
|
|
221
|
+
onDialogClosed,
|
|
222
|
+
onDialogOpened,
|
|
223
|
+
addEvent,
|
|
224
|
+
onDeleteEvent,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="event-wrap">
|
|
3
|
+
<div class="button-wrap">
|
|
4
|
+
<span class="button-wrap-label" :class="{ 'editor-class': editorState }"
|
|
5
|
+
>事件</span
|
|
6
|
+
>
|
|
7
|
+
<span
|
|
8
|
+
:style="{ opacity: editorState ? '.6' : '1' }"
|
|
9
|
+
class="button-wrap-value"
|
|
10
|
+
@click="openDialog"
|
|
11
|
+
>编辑</span
|
|
12
|
+
>
|
|
13
|
+
</div>
|
|
14
|
+
<el-dialog
|
|
15
|
+
v-model="dialogVisible"
|
|
16
|
+
title="编辑事件"
|
|
17
|
+
:width="800"
|
|
18
|
+
@close="onDialogClose"
|
|
19
|
+
@closed="onDialogClosed"
|
|
20
|
+
@opened="onDialogOpened"
|
|
21
|
+
>
|
|
22
|
+
<div class="event-content">
|
|
23
|
+
<div
|
|
24
|
+
class="event-content--item"
|
|
25
|
+
v-for="(item, index) in eventList"
|
|
26
|
+
:key="item.key"
|
|
27
|
+
>
|
|
28
|
+
<div class="schema-title-box">
|
|
29
|
+
<span class="schema-title-box--title">事件{{ index + 1 }}</span>
|
|
30
|
+
<div
|
|
31
|
+
class="schema-title-box--icon"
|
|
32
|
+
@click="onDeleteEvent(item.key)"
|
|
33
|
+
:style="{ 'pointer-events': readOnly ? 'none' : 'auto' }"
|
|
34
|
+
>
|
|
35
|
+
<!-- 删除图标 -->
|
|
36
|
+
<svg
|
|
37
|
+
t="1677826419297"
|
|
38
|
+
class="icon"
|
|
39
|
+
viewBox="0 0 1024 1024"
|
|
40
|
+
version="1.1"
|
|
41
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
42
|
+
p-id="2805"
|
|
43
|
+
width="18"
|
|
44
|
+
height="18"
|
|
45
|
+
>
|
|
46
|
+
<path
|
|
47
|
+
d="M358.925672 596.814688v30.450522c0 17.248849 13.985526 31.233352 31.233352 31.233352 17.248849 0 31.233352-13.985526 31.233352-31.233352v-30.450522c0-17.248849-13.985526-31.233352-31.233352-31.233352-17.248849 0-31.233352 13.985526-31.233352 31.233352zM602.506317 596.814688v30.450522c0 17.248849 13.985526 31.233352 31.233352 31.233352s31.233352-13.985526 31.233351-31.233352v-30.450522c0-17.248849-13.984503-31.233352-31.233351-31.233352s-31.233352 13.985526-31.233352 31.233352zM437.047937 699.686636c-14.650675 9.104355-19.155269 28.360931-10.04989 43.01263 11.015891 17.73185 41.238216 47.740304 84.651982 47.740304 43.195801 0 73.79368-29.780257 85.059258-47.379077 9.216919-14.391778 5.03262-33.338293-9.237385-42.742477-14.270005-9.393951-33.576723-5.409197-43.159985 8.739035-0.12689 0.188288-13.049201 18.915815-32.661888 18.915815-19.028379 0-30.93864-17.274432-31.772634-18.530028-9.175987-14.412244-28.259624-18.788925-42.829458-9.756202zM907.576407 160.082952H699.352015v-26.882254c0-40.145325-32.692586-72.807213-72.878844-72.807213h-229.046626c-40.186258 0-72.878844 32.661887-72.878844 72.807213v26.882254H116.323309c-17.248849 0-31.233352 13.984503-31.233352 31.233352s13.984503 31.233352 31.233352 31.233351h791.253098c17.248849 0 31.233352-13.984503 31.233352-31.233351s-13.985526-31.233352-31.233352-31.233352z m-270.692119 0H387.014404v-26.882254c0-5.607718 4.768607-10.340509 10.411117-10.340509h229.046627c5.64251 0 10.411117 4.732791 10.411117 10.340509v26.882254z"
|
|
48
|
+
fill="#606266"
|
|
49
|
+
p-id="2806"
|
|
50
|
+
></path>
|
|
51
|
+
<path
|
|
52
|
+
d="M824.286446 259.279185c-17.248849 0-31.233352 13.984503-31.233352 31.233352v530.07261c0 40.089044-32.692586 72.705905-72.878844 72.705906H303.725466c-40.186258 0-72.878844-32.616862-72.878844-72.705906v-530.07261c0-17.248849-13.984503-31.233352-31.233352-31.233352s-31.233352 13.984503-31.233352 31.233352v530.07261c0 74.535577 60.71378 135.172609 135.345548 135.172609h416.448784c74.632791 0 135.345548-60.637032 135.345548-135.172609v-530.07261c0-17.248849-13.984503-31.233352-31.233352-31.233352z"
|
|
53
|
+
fill="#606266"
|
|
54
|
+
p-id="2807"
|
|
55
|
+
></path>
|
|
56
|
+
<path
|
|
57
|
+
d="M355.781052 259.279185c-17.248849 0-31.233352 13.984503-31.233351 31.233352v167.494758c0 17.248849 13.985526 31.233352 31.233351 31.233352 17.248849 0 31.233352-13.985526 31.233352-31.233352v-167.494758c0-17.248849-13.984503-31.233352-31.233352-31.233352zM699.352015 458.007295v-167.494758c0-17.248849-13.984503-31.233352-31.233351-31.233352s-31.233352 13.984503-31.233352 31.233352v167.494758c0 17.248849 13.985526 31.233352 31.233352 31.233352s31.233352-13.984503 31.233351-31.233352zM511.949858 489.240647c17.248849 0 31.233352-13.985526 31.233352-31.233352v-167.494758c0-17.248849-13.985526-31.233352-31.233352-31.233352s-31.233352 13.984503-31.233352 31.233352v167.494758c-0.001023 17.248849 13.984503 31.233352 31.233352 31.233352z"
|
|
58
|
+
fill="#606266"
|
|
59
|
+
p-id="2808"
|
|
60
|
+
></path>
|
|
61
|
+
</svg>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
<FormProvider :form="item.form">
|
|
65
|
+
<SchemaField
|
|
66
|
+
:schema="item.schema"
|
|
67
|
+
:scope="{ filterOptions, ...scopes }"
|
|
68
|
+
/>
|
|
69
|
+
</FormProvider>
|
|
70
|
+
</div>
|
|
71
|
+
<div
|
|
72
|
+
class="add-button"
|
|
73
|
+
@click="addEvent"
|
|
74
|
+
:style="{ 'pointer-events': readOnly ? 'none' : 'auto' }"
|
|
75
|
+
>
|
|
76
|
+
添加事件
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
<template #footer>
|
|
80
|
+
<el-button @click="onCancel"> 取消 </el-button>
|
|
81
|
+
<el-button type="primary" @click="onConfirm"> 确定 </el-button>
|
|
82
|
+
</template>
|
|
83
|
+
</el-dialog>
|
|
84
|
+
</div>
|
|
85
|
+
</template>
|
|
86
|
+
|
|
87
|
+
<script lang="ts" setup>
|
|
88
|
+
import { defineComponent } from 'vue';
|
|
89
|
+
import { FormProvider } from '@formily/vue';
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
import useEvent from './index';
|
|
92
|
+
import * as scopes from '../../../scope';
|
|
93
|
+
defineComponent({
|
|
94
|
+
name: 'FormilyEvent',
|
|
95
|
+
});
|
|
96
|
+
const props = defineProps({
|
|
97
|
+
schema: {
|
|
98
|
+
type: String,
|
|
99
|
+
default: () => {
|
|
100
|
+
return '{}';
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
options: {
|
|
104
|
+
type: Array,
|
|
105
|
+
default: () => [],
|
|
106
|
+
},
|
|
107
|
+
modelValue: {
|
|
108
|
+
type: Object,
|
|
109
|
+
default: () => {
|
|
110
|
+
return {};
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
readOnly: {
|
|
114
|
+
type: Boolean,
|
|
115
|
+
default: false,
|
|
116
|
+
},
|
|
117
|
+
addButtonType: {
|
|
118
|
+
type: String,
|
|
119
|
+
default: 'primary',
|
|
120
|
+
},
|
|
121
|
+
plain: {
|
|
122
|
+
type: Boolean,
|
|
123
|
+
default: true,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
const emits = defineEmits(['change', 'fileUpload']);
|
|
127
|
+
const filterOptions = (eventType: string) => {
|
|
128
|
+
const options: any[] = eventType
|
|
129
|
+
? props.options.filter(
|
|
130
|
+
(op: any) =>
|
|
131
|
+
(Array.isArray(op.eventType) && op.eventType.includes(eventType)) ||
|
|
132
|
+
op.eventType === eventType
|
|
133
|
+
)
|
|
134
|
+
: [];
|
|
135
|
+
return options;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const {
|
|
139
|
+
dialogVisible,
|
|
140
|
+
schemaConfig,
|
|
141
|
+
eventList,
|
|
142
|
+
editorState,
|
|
143
|
+
openDialog,
|
|
144
|
+
onCancel,
|
|
145
|
+
onConfirm,
|
|
146
|
+
onDialogClose,
|
|
147
|
+
onDialogClosed,
|
|
148
|
+
onDialogOpened,
|
|
149
|
+
addEvent,
|
|
150
|
+
onDeleteEvent,
|
|
151
|
+
} = useEvent(props, emits);
|
|
152
|
+
</script>
|
|
153
|
+
|
|
154
|
+
<style lang="scss">
|
|
155
|
+
.event-wrap {
|
|
156
|
+
.button-wrap {
|
|
157
|
+
display: flex;
|
|
158
|
+
align-items: center;
|
|
159
|
+
justify-content: space-between;
|
|
160
|
+
border: none !important;
|
|
161
|
+
padding: 0 18px 16px 18px;
|
|
162
|
+
margin: 0 !important;
|
|
163
|
+
&-value {
|
|
164
|
+
font-style: normal;
|
|
165
|
+
font-weight: 400;
|
|
166
|
+
font-size: 14px;
|
|
167
|
+
line-height: 20px;
|
|
168
|
+
/* identical to box height */
|
|
169
|
+
color: #4b515e;
|
|
170
|
+
&:hover {
|
|
171
|
+
cursor: pointer;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
&-label {
|
|
176
|
+
color: rgba(2, 2, 2, 0.4);
|
|
177
|
+
font-size: 16px;
|
|
178
|
+
line-height: 24px;
|
|
179
|
+
font-weight: 600;
|
|
180
|
+
font-style: normal;
|
|
181
|
+
&.editor-class {
|
|
182
|
+
color: #020202 !important;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.el-dialog {
|
|
188
|
+
box-sizing: border-box;
|
|
189
|
+
padding: 24px 32px;
|
|
190
|
+
}
|
|
191
|
+
.el-dialog__headerbtn {
|
|
192
|
+
opacity: 0.8;
|
|
193
|
+
width: 33px;
|
|
194
|
+
height: 30px;
|
|
195
|
+
top: 24px;
|
|
196
|
+
right: 34px;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.el-dialog__header {
|
|
200
|
+
border-bottom: 1px solid rgba(232, 233, 235, 1);
|
|
201
|
+
margin-right: 0;
|
|
202
|
+
font-style: normal;
|
|
203
|
+
font-weight: 500;
|
|
204
|
+
font-size: 20px;
|
|
205
|
+
line-height: 150%;
|
|
206
|
+
/* identical to box height, or 30px */
|
|
207
|
+
display: flex;
|
|
208
|
+
align-items: center;
|
|
209
|
+
color: #000000;
|
|
210
|
+
padding: 0 0 12px 0;
|
|
211
|
+
}
|
|
212
|
+
.el-dialog__footer {
|
|
213
|
+
border-top: 1px solid rgba(232, 233, 235, 1);
|
|
214
|
+
padding: 16px 0 0 0;
|
|
215
|
+
}
|
|
216
|
+
.el-dialog__body {
|
|
217
|
+
height: 535px;
|
|
218
|
+
overflow-y: scroll;
|
|
219
|
+
&::-webkit-scrollbar {
|
|
220
|
+
display: none;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
.formily-element-plus-array-items-item-list-wrap {
|
|
224
|
+
.formily-element-plus-form-item-label {
|
|
225
|
+
width: 180px;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.formily-element-plus-array-base-addition {
|
|
230
|
+
width: auto;
|
|
231
|
+
top: -2px;
|
|
232
|
+
left: 0;
|
|
233
|
+
position: absolute;
|
|
234
|
+
transform: translateX(120px);
|
|
235
|
+
.el-icon {
|
|
236
|
+
display: none;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
.formily-row {
|
|
240
|
+
position: relative !important;
|
|
241
|
+
.el-button {
|
|
242
|
+
padding: 0;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.el-button + .el-button {
|
|
246
|
+
margin-left: 4px;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/* .formily-element-plus-form-item-layout-horizontal { */
|
|
250
|
+
.formily-element-plus-array-items-item-inner {
|
|
251
|
+
margin-left: 120px !important;
|
|
252
|
+
}
|
|
253
|
+
/* } */
|
|
254
|
+
|
|
255
|
+
.formily-element-plus-form-item-label {
|
|
256
|
+
margin-top: 10px;
|
|
257
|
+
width: 120px;
|
|
258
|
+
}
|
|
259
|
+
.add-button {
|
|
260
|
+
display: flex;
|
|
261
|
+
align-items: center;
|
|
262
|
+
justify-content: center;
|
|
263
|
+
width: 700px;
|
|
264
|
+
height: 30px;
|
|
265
|
+
cursor: pointer;
|
|
266
|
+
border: 1px dashed #999;
|
|
267
|
+
border-radius: 4px;
|
|
268
|
+
color: #333;
|
|
269
|
+
&:hover {
|
|
270
|
+
border-color: var(--el-color-primary);
|
|
271
|
+
color: var(--el-color-primary);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.event-content {
|
|
276
|
+
display: flex;
|
|
277
|
+
flex-wrap: wrap;
|
|
278
|
+
justify-content: space-between;
|
|
279
|
+
|
|
280
|
+
&--item {
|
|
281
|
+
width: 900px;
|
|
282
|
+
/* height: 500px; */
|
|
283
|
+
/* border: 1px solid #999; */
|
|
284
|
+
border-radius: 4px;
|
|
285
|
+
box-sizing: border-box;
|
|
286
|
+
/* padding: 10px; */
|
|
287
|
+
overflow-y: scroll;
|
|
288
|
+
margin-bottom: 40px;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.schema-title-box {
|
|
293
|
+
display: flex;
|
|
294
|
+
align-items: flex-start;
|
|
295
|
+
justify-content: space-between;
|
|
296
|
+
&--title {
|
|
297
|
+
font-style: normal;
|
|
298
|
+
font-weight: 600;
|
|
299
|
+
font-size: 14px;
|
|
300
|
+
line-height: 20px;
|
|
301
|
+
/* identical to box height */
|
|
302
|
+
color: #704528;
|
|
303
|
+
display: flex;
|
|
304
|
+
align-items: center;
|
|
305
|
+
margin-bottom: 22px;
|
|
306
|
+
&::before {
|
|
307
|
+
content: '';
|
|
308
|
+
width: 2px;
|
|
309
|
+
height: 13px;
|
|
310
|
+
background: #704528;
|
|
311
|
+
display: block;
|
|
312
|
+
margin-right: 6px;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
&--icon {
|
|
316
|
+
font-weight: 400;
|
|
317
|
+
font-size: 14px;
|
|
318
|
+
line-height: 20px;
|
|
319
|
+
color: #000000;
|
|
320
|
+
display: flex;
|
|
321
|
+
align-items: center;
|
|
322
|
+
cursor: pointer;
|
|
323
|
+
img {
|
|
324
|
+
display: block;
|
|
325
|
+
width: 20px;
|
|
326
|
+
height: 20px;
|
|
327
|
+
// border: 1px dashed rgba(0, 0, 0, 0.4);
|
|
328
|
+
margin-right: 4px;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.schema-box-content > div {
|
|
335
|
+
.formily-element-plus-form-item-label {
|
|
336
|
+
width: 10px;
|
|
337
|
+
color: rgba(0, 0, 0, 1) !important;
|
|
338
|
+
margin-top: 10px;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.formily-element-plus-form-item-label-content {
|
|
342
|
+
width: 200px;
|
|
343
|
+
}
|
|
344
|
+
.el-input,
|
|
345
|
+
.el-input-number {
|
|
346
|
+
width: 212px !important;
|
|
347
|
+
height: 40px !important;
|
|
348
|
+
}
|
|
349
|
+
.formily-element-plus-form-item {
|
|
350
|
+
flex-basis: 33%;
|
|
351
|
+
flex-grow: 0;
|
|
352
|
+
flex-shrink: 0;
|
|
353
|
+
margin-bottom: 16px !important;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
</style>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
import { connect, mapProps, mapReadPretty, useField } from '@formily/vue';
|
|
3
|
+
import { observer } from '@formily/reactive-vue';
|
|
4
|
+
import { isVoidField, Field } from '@formily/core';
|
|
5
|
+
import { ElCascader } from '@cicctencent/jtui';
|
|
6
|
+
|
|
7
|
+
import { PreviewText } from '../preview-text';
|
|
8
|
+
|
|
9
|
+
export type CascaderProps = typeof ElCascader;
|
|
10
|
+
|
|
11
|
+
// export const Cascader = connect(
|
|
12
|
+
// ElCascader,
|
|
13
|
+
// mapProps({ dataSource: 'options', value: 'modelValue' }),
|
|
14
|
+
// mapReadPretty(PreviewText.Cascader)
|
|
15
|
+
// )
|
|
16
|
+
|
|
17
|
+
export const Cascader = observer(
|
|
18
|
+
defineComponent({
|
|
19
|
+
name: 'FCascader',
|
|
20
|
+
props: ['onChange'],
|
|
21
|
+
setup(props, { attrs, slots }: { [key: string]: any }) {
|
|
22
|
+
const fieldRef:any = useField();
|
|
23
|
+
return () => {
|
|
24
|
+
const field = fieldRef.value as Field;
|
|
25
|
+
const Comp =
|
|
26
|
+
field &&
|
|
27
|
+
!isVoidField(field) &&
|
|
28
|
+
field.pattern === 'readPretty'
|
|
29
|
+
? PreviewText.Cascader
|
|
30
|
+
: ElCascader;
|
|
31
|
+
return h(
|
|
32
|
+
Comp,
|
|
33
|
+
{
|
|
34
|
+
...attrs,
|
|
35
|
+
options: field?.dataSource,
|
|
36
|
+
modelValue: field?.value,
|
|
37
|
+
onChange: (...args: any[]) => {
|
|
38
|
+
props.onChange(...args);
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
slots
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export default Cascader;
|