starfish-form-custom 1.0.0
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 +2 -0
- package/auto-imports.d.ts +9 -0
- package/components.d.ts +68 -0
- package/dist/formAction-28d86b6a.mjs +446 -0
- package/dist/index-04830c0b.mjs +126 -0
- package/dist/index-eab8ef70.mjs +519 -0
- package/dist/index-f7ea052c.mjs +241 -0
- package/dist/main-96327b2e.mjs +5051 -0
- package/dist/starfish-form-a18a5409.mjs +328 -0
- package/dist/starfish-form.mjs +36 -0
- package/dist/style.css +377 -0
- package/dist/types/form/src/common/Loading.vue.d.ts +3 -0
- package/dist/types/form/src/env.d.ts +15 -0
- package/dist/types/form/src/main.d.ts +43 -0
- package/dist/types/form/src/starfish-form.vue.d.ts +40 -0
- package/dist/types/form/src/utils/customHooks.d.ts +2 -0
- package/dist/types/form/src/utils/fieldConfig.d.ts +78 -0
- package/dist/types/form/src/utils/fieldProps.d.ts +43 -0
- package/dist/types/starfish-form.d.ts +3 -0
- package/package.json +42 -0
- package/src/common/KeyValueConfig.vue +145 -0
- package/src/common/KeyValueConfigMult.vue +139 -0
- package/src/common/Loading.vue +14 -0
- package/src/common/action.vue +76 -0
- package/src/common/formAction.vue +298 -0
- package/src/common/listConfig.vue +45 -0
- package/src/common/panel.vue +61 -0
- package/src/common/radiogroup.vue +31 -0
- package/src/components/CheckBox/index.vue +42 -0
- package/src/components/ColorSelect/index.vue +49 -0
- package/src/components/Date/index.vue +39 -0
- package/src/components/DateTime/index.vue +39 -0
- package/src/components/InputNumber/index.vue +48 -0
- package/src/components/JsonEditor/index.vue +167 -0
- package/src/components/Radio/index.vue +42 -0
- package/src/components/RichText/index.vue +60 -0
- package/src/components/Rule/index.vue +365 -0
- package/src/components/Rule/ruleform.json +315 -0
- package/src/components/Rule/rules.js +91 -0
- package/src/components/Selected/index.vue +50 -0
- package/src/components/Selecteds/index.vue +50 -0
- package/src/components/ShowRule/index.vue +50 -0
- package/src/components/Slider/index.vue +38 -0
- package/src/components/Switch/index.vue +61 -0
- package/src/components/Text/index.vue +48 -0
- package/src/components/TextArea/index.vue +49 -0
- package/src/components/Time/index.vue +36 -0
- package/src/env.d.ts +15 -0
- package/src/layout/Divider.vue +30 -0
- package/src/layout/Info.vue +69 -0
- package/src/layout/Tabs.vue +75 -0
- package/src/layout/collapse.vue +78 -0
- package/src/layout/grid.vue +88 -0
- package/src/layout/table.vue +80 -0
- package/src/main.ts +62 -0
- package/src/starfish-form.vue +265 -0
- package/src/styles/action.scss +25 -0
- package/src/styles/collapse.scss +15 -0
- package/src/styles/custom-cpm.scss +5 -0
- package/src/styles/divider.scss +16 -0
- package/src/styles/form-action.scss +92 -0
- package/src/styles/formedit.scss +69 -0
- package/src/styles/grid.scss +12 -0
- package/src/styles/index.scss +12 -0
- package/src/styles/keyvalueConfig.scss +56 -0
- package/src/styles/rule.scss +17 -0
- package/src/styles/showrule.scss +5 -0
- package/src/styles/table.scss +19 -0
- package/src/styles/tabs.scss +5 -0
- package/src/utils/customHooks.ts +22 -0
- package/src/utils/fieldConfig.ts +961 -0
- package/src/utils/fieldProps.ts +50 -0
- package/stats.html +4949 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="starfish-tabs_box">
|
|
3
|
+
<el-tabs v-model="activeName">
|
|
4
|
+
<el-tab-pane :label="colItem.name" :name="colItem.name" v-for="(colItem, index) in item.data.items" :key="index">
|
|
5
|
+
<template v-if="drag">
|
|
6
|
+
<draggable class="draggable-box" animation="300" ghostClass="itemGhost" v-model="colItem.list" @add="addControl($event, colItem.list, index)" group="starfish-form" @choose="chooseClick($event, colItem.list)" item-key="id" @update="changePos($event, colItem.list)">
|
|
7
|
+
<template #item="{ element, index }">
|
|
8
|
+
<Shape v-if="element.data" :active="currentId == element.id" :currentIndex="index" :currentId="element.id" :len="colItem.list.length" :item="element"> <component :is="element.ControlType" :drag="true" :item="element" :data="{}"></component></Shape>
|
|
9
|
+
</template>
|
|
10
|
+
</draggable>
|
|
11
|
+
</template>
|
|
12
|
+
<template v-else-if="!drag && colItem.list.length > 0">
|
|
13
|
+
<template v-for="listItem in colItem.list" >
|
|
14
|
+
<el-form-item :prop="listItem.data.fieldName" v-if="!listItem.layout" :key="listItem.id">
|
|
15
|
+
<component ref="controlObj" @change="$emit('change')" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false"></component>
|
|
16
|
+
</el-form-item>
|
|
17
|
+
<template v-else>
|
|
18
|
+
<component ref="controlObj" :key="listItem.id" @change="$emit('change')" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false"></component>
|
|
19
|
+
</template>
|
|
20
|
+
</template>
|
|
21
|
+
</template>
|
|
22
|
+
</el-tab-pane>
|
|
23
|
+
</el-tabs>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import { defineComponent, ref, computed, inject, getCurrentInstance } from "vue";
|
|
28
|
+
import { getFormConfig } from "../utils/fieldConfig";
|
|
29
|
+
import fieldProps from "../utils/fieldProps";
|
|
30
|
+
import { useWatch } from "../utils/customHooks";
|
|
31
|
+
export default defineComponent({
|
|
32
|
+
ControlType: "Tabs", // 必须与文件名匹配
|
|
33
|
+
nameCn: "标签页",
|
|
34
|
+
icon: "icon-zhediemianban",
|
|
35
|
+
layout: true,
|
|
36
|
+
formConfig: getFormConfig("Tabs", [
|
|
37
|
+
{ fieldName: "items", component: "Panel", label: "折叠面板" },
|
|
38
|
+
{ fieldName: "accordion", component: "Switch", label: "手风琴模式" },
|
|
39
|
+
]),
|
|
40
|
+
props: {
|
|
41
|
+
...fieldProps,
|
|
42
|
+
},
|
|
43
|
+
setup(props) {
|
|
44
|
+
const activeName = ref(props.item.data.items[0].name);
|
|
45
|
+
const { formStore, store } = inject("control") || {};
|
|
46
|
+
const { proxy } = getCurrentInstance() as any;
|
|
47
|
+
const currentId = computed(() => {
|
|
48
|
+
return formStore.get("currentId");
|
|
49
|
+
});
|
|
50
|
+
useWatch(props);
|
|
51
|
+
return {
|
|
52
|
+
activeName,
|
|
53
|
+
currentId,
|
|
54
|
+
addControl(e: any, list: any, index: number) {
|
|
55
|
+
props.item.data.items[index].list = list.map((item: any) => {
|
|
56
|
+
return proxy.$Flex.jsonToForm(item);
|
|
57
|
+
});
|
|
58
|
+
formStore.setFormCurrentId(props.item.data.items[index].list[e.newIndex].id);
|
|
59
|
+
formStore.setFormCurrentIndex(e.newIndex);
|
|
60
|
+
store.set("curList", props.item.data.items[index].list);
|
|
61
|
+
},
|
|
62
|
+
chooseClick(e: any, list: any) {
|
|
63
|
+
formStore.setFormCurrentId(list[e.oldIndex].id);
|
|
64
|
+
formStore.setFormCurrentIndex(e.oldIndex);
|
|
65
|
+
store.set("curList", list);
|
|
66
|
+
},
|
|
67
|
+
changePos(e: any, list: any) {
|
|
68
|
+
formStore.setFormCurrentId(list[e.newIndex]?.id);
|
|
69
|
+
formStore.setFormCurrentIndex(e.newIndex);
|
|
70
|
+
store.set("curList", list);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
</script>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="collapse_box">
|
|
3
|
+
<div class="control">
|
|
4
|
+
<el-collapse v-model="activeName" :accordion="item.data.accordion">
|
|
5
|
+
<el-collapse-item :title="colItem.name" :name="colItem.name" v-for="(colItem, index) in item.data.items" :key="index">
|
|
6
|
+
<template v-if="drag">
|
|
7
|
+
<draggable class="draggable-box" animation="300" ghostClass="itemGhost" v-model="colItem.list" @add="addControl($event, colItem.list, index)" group="starfish-form" @choose="chooseClick($event, colItem.list)" item-key="id" @update="changePos($event, colItem.list)">
|
|
8
|
+
<template #item="{ element, index }">
|
|
9
|
+
<Shape v-if="element.data" :active="currentId == element.id" :currentIndex="index" :currentId="element.id" :len="colItem.list.length" :item="element"> <component :is="element.ControlType" :drag="true" :item="element" :data="{}"></component></Shape>
|
|
10
|
+
</template>
|
|
11
|
+
</draggable>
|
|
12
|
+
</template>
|
|
13
|
+
<template v-else-if="!drag && colItem.list.length > 0">
|
|
14
|
+
<template v-for="listItem in colItem.list" >
|
|
15
|
+
<el-form-item :prop="listItem.data.fieldName" v-if="!listItem.layout" :key="listItem.id">
|
|
16
|
+
<!-- v-if="listItem.show" -->
|
|
17
|
+
<component ref="controlObj" @change="$emit('change')" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false" ></component>
|
|
18
|
+
</el-form-item>
|
|
19
|
+
<template v-else>
|
|
20
|
+
<component ref="controlObj" @change="$emit('change')" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :key="listItem.id" :drag="false" ></component>
|
|
21
|
+
</template>
|
|
22
|
+
</template>
|
|
23
|
+
</template>
|
|
24
|
+
</el-collapse-item>
|
|
25
|
+
</el-collapse>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
</template>
|
|
29
|
+
<script lang="ts">
|
|
30
|
+
import { defineComponent, ref, computed, inject, getCurrentInstance } from "vue";
|
|
31
|
+
import { getFormConfig } from "../utils/fieldConfig";
|
|
32
|
+
import fieldProps from "../utils/fieldProps";
|
|
33
|
+
import { useWatch } from "../utils/customHooks";
|
|
34
|
+
export default defineComponent({
|
|
35
|
+
ControlType: "Collapse", // 必须与文件名匹配
|
|
36
|
+
nameCn: "折叠面板",
|
|
37
|
+
icon: "icon-zhediemianban",
|
|
38
|
+
layout: true,
|
|
39
|
+
formConfig: getFormConfig("Collapse", [
|
|
40
|
+
{ fieldName: "items", component: "Panel", label: "折叠面板" },
|
|
41
|
+
{ fieldName: "accordion", component: "Switch", label: "手风琴模式" },
|
|
42
|
+
]),
|
|
43
|
+
props: {
|
|
44
|
+
...fieldProps,
|
|
45
|
+
},
|
|
46
|
+
setup(props) {
|
|
47
|
+
const activeName = ref(props.item.data.items[0].name);
|
|
48
|
+
const { formStore, store } = inject("control") || {};
|
|
49
|
+
const { proxy } = getCurrentInstance() as any;
|
|
50
|
+
const currentId = computed(() => {
|
|
51
|
+
return formStore.get("currentId");
|
|
52
|
+
});
|
|
53
|
+
useWatch(props);
|
|
54
|
+
return {
|
|
55
|
+
activeName,
|
|
56
|
+
currentId,
|
|
57
|
+
addControl(e: any, list: any, index: number) {
|
|
58
|
+
props.item.data.items[index].list = list.map((item: any) => {
|
|
59
|
+
return proxy.$Flex.jsonToForm(item);
|
|
60
|
+
});
|
|
61
|
+
formStore.setFormCurrentId(props.item.data.items[index].list[e.newIndex].id);
|
|
62
|
+
formStore.setFormCurrentIndex(e.newIndex);
|
|
63
|
+
store.set("curList", props.item.data.items[index].list);
|
|
64
|
+
},
|
|
65
|
+
chooseClick(e: any, list: any) {
|
|
66
|
+
formStore.setFormCurrentId(list[e.oldIndex].id);
|
|
67
|
+
formStore.setFormCurrentIndex(e.oldIndex);
|
|
68
|
+
store.set("curList", list);
|
|
69
|
+
},
|
|
70
|
+
changePos(e: any, list: any) {
|
|
71
|
+
formStore.setFormCurrentId(list[e.newIndex]?.id);
|
|
72
|
+
formStore.setFormCurrentIndex(e.newIndex);
|
|
73
|
+
store.set("curList", list);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
</script>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="starfish-grid_box">
|
|
3
|
+
<el-row :gutter="item.data.gutter">
|
|
4
|
+
<template v-if="drag">
|
|
5
|
+
<el-col class="grid-col" v-for="(colItem, index) in gridList" :key="index" :span="colItem.span">
|
|
6
|
+
<draggable class="draggable-box" animation="300" ghostClass="itemGhost" v-model="colItem.list" @add="addControl($event, index)" group="starfish-form" @choose="chooseClick($event, index)" item-key="id" @update="changePos($event, index)">
|
|
7
|
+
<template #item="{ element, index }">
|
|
8
|
+
<Shape v-if="element.data" :active="currentId == element.id" :currentId="element.id" :currentIndex="index" :list="colItem.list">
|
|
9
|
+
<component :is="element.ControlType" :drag="true" :item="element" :data="{}"></component>
|
|
10
|
+
</Shape>
|
|
11
|
+
</template>
|
|
12
|
+
</draggable>
|
|
13
|
+
</el-col>
|
|
14
|
+
</template>
|
|
15
|
+
<template v-else-if="!drag && item.data.columns.length > 0">
|
|
16
|
+
<el-col class="grid-col" v-for="(colItem, index) in item.data.columns" :key="index" :span="colItem.span">
|
|
17
|
+
<template v-for="listItem in colItem.list" >
|
|
18
|
+
<el-form-item :prop="listItem.data.fieldName" :key="listItem.id" v-if="!listItem.layout">
|
|
19
|
+
<component ref="controlObj" @change="$emit('change')" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false"></component>
|
|
20
|
+
</el-form-item>
|
|
21
|
+
<template v-else>
|
|
22
|
+
<component ref="controlObj" @change="$emit('change')" :key="listItem.id" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false"></component>
|
|
23
|
+
</template>
|
|
24
|
+
</template>
|
|
25
|
+
</el-col>
|
|
26
|
+
</template>
|
|
27
|
+
</el-row>
|
|
28
|
+
</div>
|
|
29
|
+
</template>
|
|
30
|
+
<script lang="ts">
|
|
31
|
+
import { defineComponent, inject, computed, getCurrentInstance, nextTick } from "vue";
|
|
32
|
+
import { getFormConfig } from "../utils/fieldConfig";
|
|
33
|
+
import fieldProps from "../utils/fieldProps";
|
|
34
|
+
import { useWatch } from "../utils/customHooks";
|
|
35
|
+
export default defineComponent({
|
|
36
|
+
ControlType: "Grid", // 必须与文件名匹配
|
|
37
|
+
nameCn: "栅格布局",
|
|
38
|
+
icon: "icon-35zhage",
|
|
39
|
+
layout: true,
|
|
40
|
+
formConfig: getFormConfig(
|
|
41
|
+
"Grid",
|
|
42
|
+
[
|
|
43
|
+
{ fieldName: "gutter", component: "InputNumber" },
|
|
44
|
+
{ fieldName: "columns", component: "ListConfig" },
|
|
45
|
+
],
|
|
46
|
+
["required", "rule", "tip"]
|
|
47
|
+
),
|
|
48
|
+
props: {
|
|
49
|
+
...fieldProps,
|
|
50
|
+
},
|
|
51
|
+
setup(props) {
|
|
52
|
+
console.log(props);
|
|
53
|
+
const gridList = computed(() => props.item.data.columns);
|
|
54
|
+
const { proxy } = getCurrentInstance() as any;
|
|
55
|
+
const { formStore, store } = inject("control") || {};
|
|
56
|
+
const chooseClick = (e: any, index: number) => {
|
|
57
|
+
formStore.setFormCurrentId(gridList.value[index].list[e.oldIndex]?.id);
|
|
58
|
+
formStore.setFormCurrentIndex(e.oldIndex);
|
|
59
|
+
store.set("curList", gridList.value[index].list);
|
|
60
|
+
};
|
|
61
|
+
const currentId = computed(() => {
|
|
62
|
+
return formStore.get("currentId");
|
|
63
|
+
});
|
|
64
|
+
useWatch(props);
|
|
65
|
+
return {
|
|
66
|
+
gridList,
|
|
67
|
+
chooseClick,
|
|
68
|
+
currentId,
|
|
69
|
+
changePos(e: any, index: number) {
|
|
70
|
+
formStore.setFormCurrentId(gridList.value[index].list[e.newIndex]?.id);
|
|
71
|
+
formStore.setFormCurrentIndex(e.newIndex);
|
|
72
|
+
store.set("curList", gridList.value[index].list);
|
|
73
|
+
},
|
|
74
|
+
async addControl(e: any, index: number) {
|
|
75
|
+
gridList.value.forEach((colItem: any) => {
|
|
76
|
+
colItem.list = colItem.list.map((item: any) => {
|
|
77
|
+
return proxy.$Flex.jsonToForm(item);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
await nextTick();
|
|
81
|
+
formStore.setFormCurrentId(gridList.value[index].list[e.newIndex].id);
|
|
82
|
+
formStore.setFormCurrentIndex(e.newIndex);
|
|
83
|
+
store.set("curList", gridList.value[index].list);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
</script>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="starfish-table_box">
|
|
3
|
+
<table class="table_layout" :class="item.data.borderShow ? 'table_layout_border' : ''">
|
|
4
|
+
<tr v-for="(trItem, index) in item.data.trs" :key="index">
|
|
5
|
+
<td v-for="(tdItem, tdIndex) in trItem.tds" :key="tdIndex">
|
|
6
|
+
<template v-if="drag">
|
|
7
|
+
<draggable class="draggable-box" animation="300" ghostClass="itemGhost" v-model="tdItem.list" @add="addControl($event, tdItem.list, index, tdIndex)" group="starfish-form" @choose="chooseClick($event, tdItem.list)" item-key="id" @update="changePos($event, tdItem.list)">
|
|
8
|
+
<template #item="{ element, index }">
|
|
9
|
+
<Shape v-if="element.data" :active="currentId == element.id" :currentIndex="index" :currentId="element.id" :len="tdItem.list.length" :item="element"> <component :is="element.ControlType" :drag="true" :item="element" :data="{}"></component></Shape>
|
|
10
|
+
</template>
|
|
11
|
+
</draggable>
|
|
12
|
+
</template>
|
|
13
|
+
<template v-else-if="!drag && tdItem.list.length > 0">
|
|
14
|
+
<template v-for="listItem in tdItem.list">
|
|
15
|
+
<el-form-item :prop="listItem.data.fieldName" :key="listItem.id" v-if="!listItem.layout">
|
|
16
|
+
<component ref="controlObj" @change="$emit('change')" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false" ></component>
|
|
17
|
+
</el-form-item>
|
|
18
|
+
<template v-else>
|
|
19
|
+
<component ref="controlObj" @change="$emit('change')" :key="listItem.id" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false" ></component>
|
|
20
|
+
</template>
|
|
21
|
+
</template>
|
|
22
|
+
</template>
|
|
23
|
+
</td>
|
|
24
|
+
</tr>
|
|
25
|
+
</table>
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
<script lang="ts">
|
|
29
|
+
import { defineComponent, getCurrentInstance, inject, computed } from "vue";
|
|
30
|
+
import { getFormConfig } from "../utils/fieldConfig";
|
|
31
|
+
import fieldProps from "../utils/fieldProps";
|
|
32
|
+
import { useWatch } from "../utils/customHooks";
|
|
33
|
+
export default defineComponent({
|
|
34
|
+
ControlType: "TableLayout",
|
|
35
|
+
nameCn: "表格布局",
|
|
36
|
+
icon: "icon-biaoge1",
|
|
37
|
+
layout: true,
|
|
38
|
+
props: {
|
|
39
|
+
...fieldProps,
|
|
40
|
+
},
|
|
41
|
+
formConfig: getFormConfig(
|
|
42
|
+
"TableLayout",
|
|
43
|
+
[
|
|
44
|
+
// { fieldName: "borderShow", component: "Switch", label: "是否显示边框" },
|
|
45
|
+
// {fieldName: 'borderWidth', component: 'InputNumber', label: "边框宽度"}
|
|
46
|
+
],
|
|
47
|
+
["required", "rule", "tip"]
|
|
48
|
+
),
|
|
49
|
+
setup(props) {
|
|
50
|
+
const { proxy } = getCurrentInstance() as any;
|
|
51
|
+
const { formStore, store } = inject("control") || {};
|
|
52
|
+
const currentId = computed(() => {
|
|
53
|
+
return formStore.get("currentId");
|
|
54
|
+
});
|
|
55
|
+
useWatch(props);
|
|
56
|
+
return {
|
|
57
|
+
currentId,
|
|
58
|
+
chooseClick(e: any, list: any[]) {
|
|
59
|
+
formStore.setFormCurrentId(list[e.oldIndex].id);
|
|
60
|
+
formStore.setFormCurrentIndex(e.oldIndex);
|
|
61
|
+
store.set("curList", list);
|
|
62
|
+
},
|
|
63
|
+
changePos(e: any, list: any[]) {
|
|
64
|
+
formStore.setFormCurrentId(list[e.newIndex]?.id);
|
|
65
|
+
formStore.setFormCurrentIndex(e.newIndex);
|
|
66
|
+
store.set("curList", list);
|
|
67
|
+
},
|
|
68
|
+
addControl(e: any, list: any[], trIndex: number, tdIndex: number) {
|
|
69
|
+
props.item.data.trs[trIndex].tds[tdIndex].list = list.map((item: any) => {
|
|
70
|
+
return proxy.$Flex.jsonToForm(item);
|
|
71
|
+
});
|
|
72
|
+
formStore.setFormCurrentId(props.item.data.trs[trIndex].tds[tdIndex].list[e.newIndex].id);
|
|
73
|
+
formStore.setFormCurrentIndex(e.newIndex);
|
|
74
|
+
store.set("curList", props.item.data.trs[trIndex].tds[tdIndex].list);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
</script>
|
|
80
|
+
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { App, defineAsyncComponent } from "vue";
|
|
2
|
+
import "./styles/index.scss";
|
|
3
|
+
import { getFormConfig } from "./utils/fieldConfig";
|
|
4
|
+
import _ from "@/utils/_";
|
|
5
|
+
import Loading from "@/common/Loading.vue";
|
|
6
|
+
|
|
7
|
+
const utilFuns: any = {};
|
|
8
|
+
const files: any = import.meta.glob(["./common/*", "./components/*/*", "./layout/*", "!./components/RichText/index.vue", "!./components/JsonEditor/index.vue", "!./components/Rule/index.vue", "!./common/formAction.vue"], { eager: true });
|
|
9
|
+
Object.keys(files).forEach((fileName) => {
|
|
10
|
+
const result = files[fileName].default;
|
|
11
|
+
if (fileName.indexOf(".vue") != -1) {
|
|
12
|
+
utilFuns[result.ControlType] = result;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
// 富文本
|
|
16
|
+
const RichText = defineAsyncComponent({
|
|
17
|
+
loader: () => import("./components/RichText/index.vue"),
|
|
18
|
+
loadingComponent: Loading,
|
|
19
|
+
});
|
|
20
|
+
RichText.ControlType = "RichText"; // 必须与文件名匹配
|
|
21
|
+
RichText.nameCn = "富文本";
|
|
22
|
+
RichText.icon = "icon-textEdit";
|
|
23
|
+
RichText.formConfig = getFormConfig("RichText");
|
|
24
|
+
utilFuns[RichText.ControlType] = RichText;
|
|
25
|
+
// json编辑器
|
|
26
|
+
const jsonEditor = defineAsyncComponent({
|
|
27
|
+
loader: () => import("./components/JsonEditor/index.vue"),
|
|
28
|
+
loadingComponent: Loading,
|
|
29
|
+
});
|
|
30
|
+
jsonEditor.ControlType = "JsonEditor"; // 必须与文件名匹配
|
|
31
|
+
jsonEditor.nameCn = "JSON编辑";
|
|
32
|
+
jsonEditor.icon = "icon-json-full";
|
|
33
|
+
jsonEditor.formConfig = getFormConfig("JsonEditor", [{ fieldName: "default", component: "JsonEditor" }]);
|
|
34
|
+
jsonEditor.rule = _.getJsonValidate();
|
|
35
|
+
utilFuns[jsonEditor.ControlType] = jsonEditor;
|
|
36
|
+
|
|
37
|
+
const formAction = defineAsyncComponent({
|
|
38
|
+
loader: () => import("./common/formAction.vue"),
|
|
39
|
+
loadingComponent: Loading,
|
|
40
|
+
});
|
|
41
|
+
formAction.ControlType = "FormAction"; // 必须与文件名匹配
|
|
42
|
+
formAction.isHide = true;
|
|
43
|
+
utilFuns[formAction.ControlType] = formAction;
|
|
44
|
+
// 规则
|
|
45
|
+
const Rule = defineAsyncComponent({
|
|
46
|
+
loader: () => import("./components/Rule/index.vue"),
|
|
47
|
+
loadingComponent: Loading,
|
|
48
|
+
});
|
|
49
|
+
Rule.ControlType = "Rule"; // 必须与文件名匹配
|
|
50
|
+
Rule.rule = _.getJsonValidate();
|
|
51
|
+
utilFuns[Rule.ControlType] = Rule;
|
|
52
|
+
const install = (app: App) => {
|
|
53
|
+
app.config.globalProperties.$formcomponents = utilFuns;
|
|
54
|
+
// for (const key in utilFuns) {
|
|
55
|
+
// app.component(key, utilFuns[key]);
|
|
56
|
+
// }
|
|
57
|
+
};
|
|
58
|
+
export const Dynamicform = defineAsyncComponent(() => import("./starfish-form.vue"));
|
|
59
|
+
|
|
60
|
+
export default {
|
|
61
|
+
install,
|
|
62
|
+
};
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="starfish-dynamicform">
|
|
3
|
+
<el-form ref="ruleForm" :model="formResult" :rules="rules" label-width="120px" class="demo-ruleForm" :size="globalConfig.size || 'large'" :validate-on-rule-change="false">
|
|
4
|
+
<template v-for="item in allFormList" >
|
|
5
|
+
<el-form-item :prop="item.data.fieldName" v-if="!item.layout && item.show" :key="item.id">
|
|
6
|
+
<component ref="controlObj" @change="handleControlChange" :is="item.ControlType" v-bind="globalConfig" :item="item" :data="formResult || '{}'" :drag="false"></component>
|
|
7
|
+
</el-form-item>
|
|
8
|
+
<template v-else-if="item.show">
|
|
9
|
+
<component ref="controlObj" @change="handleControlChange" :is="item.ControlType" :key="item.id" v-bind="globalConfig" :item="item" :data="formResult || '{}'" :drag="false"></component>
|
|
10
|
+
</template>
|
|
11
|
+
</template>
|
|
12
|
+
</el-form>
|
|
13
|
+
</div>
|
|
14
|
+
</template>
|
|
15
|
+
<script lang="ts">
|
|
16
|
+
import { defineComponent, ref, onMounted, getCurrentInstance, toRaw, PropType } from "vue";
|
|
17
|
+
export default defineComponent({
|
|
18
|
+
name: "Dynamicform",
|
|
19
|
+
props: {
|
|
20
|
+
allFormList: {
|
|
21
|
+
type: Array as PropType<any>,
|
|
22
|
+
default() {
|
|
23
|
+
return [];
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
formResult: {
|
|
27
|
+
type: Object,
|
|
28
|
+
default() {
|
|
29
|
+
return {};
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
globalConfig: {
|
|
33
|
+
type: Object,
|
|
34
|
+
default() {
|
|
35
|
+
return {};
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
setup(props: any, { emit }) {
|
|
40
|
+
const { proxy } = getCurrentInstance() as any;
|
|
41
|
+
const rules: any = ref({});
|
|
42
|
+
const ruleForm = ref();
|
|
43
|
+
const controlObj = ref();
|
|
44
|
+
props.allFormList?.forEach((item: any) => {
|
|
45
|
+
getRules(item);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function getFormListRules(rules: any[]) {
|
|
49
|
+
const result: any[] = [];
|
|
50
|
+
if (Array.isArray(rules) && rules && rules.length > 0) {
|
|
51
|
+
rules.forEach((item) => {
|
|
52
|
+
if (item.type == "enum") {
|
|
53
|
+
const func = eval(`(${item.value})`);
|
|
54
|
+
result.push({
|
|
55
|
+
validator: func,
|
|
56
|
+
trigger: "blur",
|
|
57
|
+
});
|
|
58
|
+
} else if (item.type == "func") {
|
|
59
|
+
const mainData = props.formResult;
|
|
60
|
+
const func = eval(`((rule, value, callback, mainData = mainData) => {${item.value.func}})`);
|
|
61
|
+
result.push({
|
|
62
|
+
validator: func,
|
|
63
|
+
trigger: "blur",
|
|
64
|
+
});
|
|
65
|
+
console.log('mainData', mainData)
|
|
66
|
+
} else if (item.type == "high") {
|
|
67
|
+
if (item.value.ruleType == 5) {
|
|
68
|
+
result.push({
|
|
69
|
+
validator: eval(item.value.validor),
|
|
70
|
+
trigger: item.value.trigger,
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// let high = JSON.parse(JSON.stringify(item.value));
|
|
75
|
+
// delete high.ruleType;
|
|
76
|
+
result.push(item.value);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getRules(item: any) {
|
|
84
|
+
if (!item.layout) {
|
|
85
|
+
let rule: any[] = [];
|
|
86
|
+
if (item.data.required) {
|
|
87
|
+
rule.push({
|
|
88
|
+
required: true,
|
|
89
|
+
message: "请输入" + item.data.label,
|
|
90
|
+
trigger: "blur",
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (typeof item.data.rule == "string") {
|
|
94
|
+
rule = rule.concat(proxy.$Flex.tryParseJson(item.data.rule));
|
|
95
|
+
} else {
|
|
96
|
+
rule = rule.concat(getFormListRules(item.data.rule));
|
|
97
|
+
}
|
|
98
|
+
// 特殊的jsoneditor表单要单独处理
|
|
99
|
+
if (item.data.json) {
|
|
100
|
+
rule.push(...proxy.$Flex.getJsonValidate());
|
|
101
|
+
}
|
|
102
|
+
rules.value[item.data.fieldName] = rule;
|
|
103
|
+
} else if (item.layout) {
|
|
104
|
+
if (item.ControlType == "Grid") {
|
|
105
|
+
item.data.columns.forEach((colItem: any) => {
|
|
106
|
+
colItem.list.forEach((listItem: any) => {
|
|
107
|
+
getRules(listItem);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
} else if (item.ControlType == "TableLayout") {
|
|
111
|
+
const trs = item.data.trs;
|
|
112
|
+
trs.forEach((trItem: any) => {
|
|
113
|
+
trItem.tds.forEach((tdItem: any) => {
|
|
114
|
+
tdItem.list.forEach((listItem: any) => {
|
|
115
|
+
getRules(listItem);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
} else if (item.ControlType == "Collapse" || item.ControlType == "Tabs") {
|
|
120
|
+
const items = item.data.items;
|
|
121
|
+
items.forEach((colItem: any) => {
|
|
122
|
+
colItem.list.forEach((listItem: any) => {
|
|
123
|
+
getRules(listItem);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const handleControlChange = () => {
|
|
131
|
+
const allFormLists: any = props.allFormList;
|
|
132
|
+
allFormLists.forEach((item: any) => {
|
|
133
|
+
if (item.data.showRule === "{}") {
|
|
134
|
+
item.show = true;
|
|
135
|
+
} else {
|
|
136
|
+
try {
|
|
137
|
+
if (Array.isArray(item.data.showRule)) {
|
|
138
|
+
item.show = conditionChange(transformData(toRaw(item.data.showRule)));
|
|
139
|
+
} else {
|
|
140
|
+
item.show = conditionChange(toRaw(item.data.showRule));
|
|
141
|
+
}
|
|
142
|
+
} catch (e) {
|
|
143
|
+
item.show = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
executeFunc("updated");
|
|
148
|
+
emit("change");
|
|
149
|
+
};
|
|
150
|
+
function transformData(data: any) {
|
|
151
|
+
/**普通模式转为高级模式的数据结构,方便复用 */
|
|
152
|
+
const r: any = [];
|
|
153
|
+
data.forEach((item: any) => {
|
|
154
|
+
r.push({
|
|
155
|
+
type: "andgroup",
|
|
156
|
+
result: item.map((d: any) => {
|
|
157
|
+
return {
|
|
158
|
+
type: "data",
|
|
159
|
+
data: d,
|
|
160
|
+
};
|
|
161
|
+
}),
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
const result = {
|
|
165
|
+
type: "orgroup",
|
|
166
|
+
result: r,
|
|
167
|
+
};
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
function conditionChange(data: any) {
|
|
171
|
+
if (data.type == "andgroup") {
|
|
172
|
+
const result = data.result
|
|
173
|
+
.map((item: any) => {
|
|
174
|
+
const r = conditionChange(item);
|
|
175
|
+
return r;
|
|
176
|
+
})
|
|
177
|
+
.find((item: boolean) => {
|
|
178
|
+
return item == false;
|
|
179
|
+
});
|
|
180
|
+
return result === undefined ? true : result;
|
|
181
|
+
} else if (data.type == "orgroup") {
|
|
182
|
+
const result = data.result
|
|
183
|
+
.map((item: any) => {
|
|
184
|
+
const r = conditionChange(item);
|
|
185
|
+
return r;
|
|
186
|
+
})
|
|
187
|
+
.find((item: boolean) => {
|
|
188
|
+
return item == true;
|
|
189
|
+
});
|
|
190
|
+
return result === undefined ? false : result;
|
|
191
|
+
} else if (data.type == "data") {
|
|
192
|
+
const result = data.data;
|
|
193
|
+
const formResults: any = props.formResult;
|
|
194
|
+
const value = formResults[result.field];
|
|
195
|
+
let isShow = false;
|
|
196
|
+
switch (result.logic) {
|
|
197
|
+
case "=":
|
|
198
|
+
isShow = value == result.value;
|
|
199
|
+
break;
|
|
200
|
+
case "!=":
|
|
201
|
+
isShow = value != result.value;
|
|
202
|
+
break;
|
|
203
|
+
case "in":
|
|
204
|
+
if (Array.isArray(value)) {
|
|
205
|
+
value.find((item) => {
|
|
206
|
+
if (result.value.include(item)) {
|
|
207
|
+
isShow = result.value.includes(item);
|
|
208
|
+
return item;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
} else {
|
|
212
|
+
isShow = result.value.includes(value);
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
case "not in":
|
|
216
|
+
if (Array.isArray(value)) {
|
|
217
|
+
value.find((item) => {
|
|
218
|
+
if (!result.value.include(item)) {
|
|
219
|
+
isShow = !result.value.includes(item);
|
|
220
|
+
return item;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
isShow = !result.value.includes(value);
|
|
225
|
+
}
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
return isShow;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function reset() {
|
|
232
|
+
ruleForm.value.resetFields();
|
|
233
|
+
}
|
|
234
|
+
function getValidate() {
|
|
235
|
+
return new Promise((resolve) => {
|
|
236
|
+
ruleForm.value.validate((valide: boolean) => {
|
|
237
|
+
resolve(valide);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
onMounted(() => {
|
|
242
|
+
handleControlChange();
|
|
243
|
+
executeFunc("mounted");
|
|
244
|
+
});
|
|
245
|
+
function executeFunc(funcName: string) {
|
|
246
|
+
const mountedAction = props.globalConfig.action?.find((item: any) => {
|
|
247
|
+
if (item.type == funcName) {
|
|
248
|
+
return item;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
if (mountedAction) {
|
|
252
|
+
eval(`(function(){${mountedAction.funcStr}}).call(proxy)`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
rules,
|
|
257
|
+
ruleForm,
|
|
258
|
+
controlObj,
|
|
259
|
+
handleControlChange,
|
|
260
|
+
reset,
|
|
261
|
+
getValidate,
|
|
262
|
+
};
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
</script>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.starfish-formitem-action {
|
|
2
|
+
.label {
|
|
3
|
+
align-self: flex-start;
|
|
4
|
+
}
|
|
5
|
+
.el-collapse-item {
|
|
6
|
+
border: 1px solid #ebeef5;
|
|
7
|
+
border-bottom-color: #e1e1e1;
|
|
8
|
+
.el-collapse-item__header {
|
|
9
|
+
background: #ebeef5;
|
|
10
|
+
height: 20px;
|
|
11
|
+
line-height: 20px;
|
|
12
|
+
padding: 5px;
|
|
13
|
+
font-size: 12px;
|
|
14
|
+
&.is-active {
|
|
15
|
+
border-bottom-color: transparent;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
.el-collapse-item__content {
|
|
19
|
+
padding: 5px;
|
|
20
|
+
.el-button + .el-button {
|
|
21
|
+
margin-left: 5px;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|