starfish-editor-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.
Files changed (108) hide show
  1. package/auto-imports.d.ts +10 -0
  2. package/babel.config.js +8 -0
  3. package/components.d.ts +46 -0
  4. package/dist/ConditionModule.js +892 -0
  5. package/dist/ConditionSelect.js +483 -0
  6. package/dist/CustomDialog.js +105 -0
  7. package/dist/formStyle.js +245 -0
  8. package/dist/globalFormList.js +59 -0
  9. package/dist/jsonCode.js +74 -0
  10. package/dist/jsonEditor.js +71 -0
  11. package/dist/main.js +3319 -0
  12. package/dist/starfish-editor.es.js +30 -0
  13. package/dist/style.css +1 -0
  14. package/dist/types/editor/src/common/ConditionSelect/ConditionGroup.vue.d.ts +61 -0
  15. package/dist/types/editor/src/common/ConditionSelect/ConditionModule.vue.d.ts +43 -0
  16. package/dist/types/editor/src/common/ConditionSelect/ConditionTanc.vue.d.ts +48 -0
  17. package/dist/types/editor/src/common/ConditionSelect.vue.d.ts +72 -0
  18. package/dist/types/editor/src/common/CustomDialog.vue.d.ts +25 -0
  19. package/dist/types/editor/src/common/Loading.vue.d.ts +3 -0
  20. package/dist/types/editor/src/common/formJson.d.ts +80 -0
  21. package/dist/types/editor/src/common/jsonCode.vue.d.ts +110 -0
  22. package/dist/types/editor/src/components/ComponentList.vue.d.ts +32 -0
  23. package/dist/types/editor/src/components/FormPreview.vue.d.ts +25 -0
  24. package/dist/types/editor/src/components/Nav.vue.d.ts +9 -0
  25. package/dist/types/editor/src/components/PropsPanel.vue.d.ts +53 -0
  26. package/dist/types/editor/src/components/Shape.vue.d.ts +40 -0
  27. package/dist/types/editor/src/components/Workspace.vue.d.ts +22 -0
  28. package/dist/types/editor/src/components/globalFormList.vue.d.ts +6 -0
  29. package/dist/types/editor/src/components/jsonEditor.vue.d.ts +6 -0
  30. package/dist/types/editor/src/controller/action.d.ts +18 -0
  31. package/dist/types/editor/src/controller/form.d.ts +24 -0
  32. package/dist/types/editor/src/controller/history.d.ts +12 -0
  33. package/dist/types/editor/src/controller/shortcut.d.ts +20 -0
  34. package/dist/types/editor/src/controller/ui.d.ts +10 -0
  35. package/dist/types/editor/src/layouts/ControlEditSize.vue.d.ts +17 -0
  36. package/dist/types/editor/src/layouts/Framework.vue.d.ts +33 -0
  37. package/dist/types/editor/src/layouts/Resizer.vue.d.ts +13 -0
  38. package/dist/types/editor/src/layouts/ShortcutKey.vue.d.ts +8 -0
  39. package/dist/types/editor/src/main.d.ts +5 -0
  40. package/dist/types/editor/src/shims-vue.d.ts +23 -0
  41. package/dist/types/editor/src/starfish-editor.vue.d.ts +109 -0
  42. package/dist/types/editor/src/type.d.ts +224 -0
  43. package/dist/types/editor/src/utils/_.d.ts +33 -0
  44. package/dist/types/editor/src/utils/formKeycon.d.ts +18 -0
  45. package/dist/types/editor/src/utils/shortcutKey.d.ts +3 -0
  46. package/dist/types/editor/src/utils/vm.d.ts +3 -0
  47. package/dist/types/starfish-editor.d.ts +3 -0
  48. package/package.json +55 -0
  49. package/src/common/ConditionSelect/ConditionGroup.vue +167 -0
  50. package/src/common/ConditionSelect/ConditionModule.vue +118 -0
  51. package/src/common/ConditionSelect/ConditionTanc.vue +319 -0
  52. package/src/common/ConditionSelect.vue +268 -0
  53. package/src/common/CustomDialog.vue +77 -0
  54. package/src/common/Loading.vue +10 -0
  55. package/src/common/formJson.ts +143 -0
  56. package/src/common/formStyle.vue +170 -0
  57. package/src/common/jsonCode.vue +45 -0
  58. package/src/components/ComponentList.vue +156 -0
  59. package/src/components/FormPreview.vue +197 -0
  60. package/src/components/Nav.vue +128 -0
  61. package/src/components/NavList.vue +560 -0
  62. package/src/components/PropsPanel.vue +376 -0
  63. package/src/components/Shape.vue +178 -0
  64. package/src/components/Workspace.vue +258 -0
  65. package/src/components/globalFormList.vue +30 -0
  66. package/src/components/jsonEditor.vue +41 -0
  67. package/src/controller/action.ts +37 -0
  68. package/src/controller/form.ts +207 -0
  69. package/src/controller/history.ts +57 -0
  70. package/src/controller/shortcut.ts +81 -0
  71. package/src/controller/ui.ts +91 -0
  72. package/src/layouts/ControlEditSize.vue +52 -0
  73. package/src/layouts/Framework.vue +76 -0
  74. package/src/layouts/Resizer.vue +54 -0
  75. package/src/layouts/ShortcutKey.vue +61 -0
  76. package/src/main.ts +56 -0
  77. package/src/shims-vue.d.ts +23 -0
  78. package/src/starfish-editor.vue +176 -0
  79. package/src/styles/common/normalize.css +455 -0
  80. package/src/styles/component-list.scss +64 -0
  81. package/src/styles/condition-select.scss +176 -0
  82. package/src/styles/control_edit_size.scss +36 -0
  83. package/src/styles/custom-dialog.scss +110 -0
  84. package/src/styles/form-preview.scss +47 -0
  85. package/src/styles/framework.scss +150 -0
  86. package/src/styles/iconfont/iconfont.css +247 -0
  87. package/src/styles/iconfont/iconfont.js +1 -0
  88. package/src/styles/iconfont/iconfont.json +415 -0
  89. package/src/styles/iconfont/iconfont.ttf +0 -0
  90. package/src/styles/iconfont/iconfont.woff +0 -0
  91. package/src/styles/iconfont/iconfont.woff2 +0 -0
  92. package/src/styles/index.scss +18 -0
  93. package/src/styles/nav-list.scss +59 -0
  94. package/src/styles/nav.scss +46 -0
  95. package/src/styles/props-panel.scss +115 -0
  96. package/src/styles/resizer.scss +15 -0
  97. package/src/styles/shape.scss +101 -0
  98. package/src/styles/shortcutkey.scss +44 -0
  99. package/src/styles/variables.scss +36 -0
  100. package/src/styles/work-space.scss +126 -0
  101. package/src/type.ts +240 -0
  102. package/src/utils/_.ts +349 -0
  103. package/src/utils/formKeycon.ts +42 -0
  104. package/src/utils/shortcutKey.ts +46 -0
  105. package/src/utils/vm.ts +3 -0
  106. package/stats.html +4949 -0
  107. package/tsconfig.json +19 -0
  108. package/vite.config.ts +111 -0
@@ -0,0 +1,258 @@
1
+ <template>
2
+ <div class="editor_pages_center" @click="onEditorCenter" tabindex="1">
3
+ <div
4
+ class="canvasBox"
5
+ ref="canvasBox"
6
+ :class="[
7
+ fullScreen ? 'fullScreenBox' : '',
8
+ pageType + '_layout',
9
+ globalDatas.csslist?.join(' '),
10
+ ]"
11
+ :style="`--scale:${scale} `"
12
+ >
13
+ <div
14
+ class="draggable_container"
15
+ ref="dragDom"
16
+ @contextmenu="handleNoDraggable"
17
+ >
18
+ <div class="editForm" ref="editForm" v-show="pasteShow">
19
+ <span @click="handlePaste">粘贴</span>
20
+ </div>
21
+ <draggable
22
+ class="dragArea"
23
+ animation="300"
24
+ ghostClass="itemGhost"
25
+ v-model="allmainList"
26
+ @add="addControl"
27
+ group="starfish-form"
28
+ @choose="chooseClick"
29
+ item-key="id"
30
+ @update="changePos"
31
+ >
32
+ <template #item="{ element, index }">
33
+ <Shape
34
+ :active="currentId == element.id"
35
+ :currentIndex="index"
36
+ :currentId="element.id"
37
+ :item="element"
38
+ :len="allmainList.length"
39
+ >
40
+ <component
41
+ :is="element.ControlType"
42
+ :drag="true"
43
+ :item="element"
44
+ :data="{}"
45
+ v-bind="globalDatas"
46
+ ></component>
47
+ </Shape>
48
+ </template>
49
+ </draggable>
50
+ <div class="form-empty" v-if="allmainList.length == 0">
51
+ 从左侧拖拽来添加字段
52
+ </div>
53
+ </div>
54
+ </div>
55
+ </div>
56
+ </template>
57
+ <script lang="ts">
58
+ import {
59
+ defineComponent,
60
+ ref,
61
+ nextTick,
62
+ computed,
63
+ getCurrentInstance,
64
+ inject,
65
+ } from "vue";
66
+ // import { formcomponents } from "@/pages/Editor";
67
+ // import formStore from "@/store/form";
68
+ // import store from "@/store/index";
69
+ import { paste } from "@/utils/formKeycon";
70
+ import type { Controls, AllFormItem, BaseFormConfig } from "@/type";
71
+ export default defineComponent({
72
+ setup() {
73
+ const { proxy } = getCurrentInstance() as any;
74
+ const { uiControl, store, formStore } = inject<Controls>("control") || {};
75
+ const formcomponents = proxy.$formcomponents;
76
+ // 画布dom
77
+ const canvasBox = ref();
78
+ // 页面默认大小
79
+ const canvasSize = ref(1);
80
+ // 移动的dom
81
+ const dragDom = ref();
82
+ // 粘贴模块是否显示
83
+ const pasteShow = ref(false);
84
+ const editForm = ref();
85
+
86
+ const globalDatas = computed(() => formStore?.get("globalDatas"));
87
+
88
+ const fullScreen = computed(() => uiControl?.get("isFullscreen"));
89
+
90
+ const pageType = computed(() => uiControl?.get("pageType"));
91
+
92
+ /**
93
+ * dynamic: true
94
+ * 代表全局配置可以定义到组件配置中
95
+ */
96
+ const dynamicList = computed(() =>
97
+ formStore?.get("globalFormList")?.filter((item: BaseFormConfig) => {
98
+ if (item.dynamic) {
99
+ return item;
100
+ }
101
+ })
102
+ );
103
+
104
+ const allmainList = computed({
105
+ get() {
106
+ return formStore?.get("allFormList");
107
+ },
108
+ set(value: AllFormItem[]) {
109
+ // 防止引用类型污染
110
+ value = value.map((item: AllFormItem) => {
111
+ console.log(formcomponents[item.ControlType as any]);
112
+ if (!item.data && !item.controlItems) {
113
+ item = proxy.$Flex.deepClone(item);
114
+ const currentComponent = formcomponents[item.ControlType as any];
115
+ item.formConfig = currentComponent.formConfig;
116
+ item.data = item.formConfig.data();
117
+ if (!item.data.fieldName) {
118
+ item.data.fieldName =
119
+ item.ControlType + "_" + proxy.$Flex.generateMixed();
120
+ }
121
+ item.id = proxy.$Flex.generateMixed();
122
+ let controlItems = (
123
+ item.formConfig.morenConfig() as Array<any>
124
+ ).concat(dynamicList.value);
125
+ /**
126
+ * 兼容动作面板,不同表单可能需要的事件不一样
127
+ */
128
+ if (
129
+ currentComponent.actionType &&
130
+ currentComponent.actionType.length > 0
131
+ ) {
132
+ console.log(controlItems);
133
+ controlItems.find((item) => {
134
+ if (item.ControlType == "Action") {
135
+ item.data.formConfig = {
136
+ value: {},
137
+ items: [],
138
+ };
139
+ currentComponent.actionType.forEach(
140
+ (action: string, index: number) => {
141
+ item.data.formConfig.items.push({
142
+ label: action,
143
+ value: action,
144
+ id: index + 1,
145
+ });
146
+ }
147
+ );
148
+ }
149
+ });
150
+ } else {
151
+ controlItems = controlItems.filter((item) => {
152
+ if (item.ControlType !== "Action") {
153
+ return item;
154
+ }
155
+ });
156
+ }
157
+ item.rules = proxy.$Flex.controlFormRule(controlItems, item);
158
+ item.controlItems = controlItems;
159
+ }
160
+ // delete item.formConfig;
161
+ // delete item.icon;
162
+ return item;
163
+ });
164
+ console.log("value", value);
165
+ formStore?.updateAllFormList(value);
166
+ },
167
+ });
168
+ const currentId = computed(() => {
169
+ return formStore?.get("currentId");
170
+ });
171
+
172
+ const handleCanvasScale = () => {
173
+ // 处理页面的放大缩小
174
+ canvasBox.value.style.transform = `scale(${canvasSize.value})`;
175
+ };
176
+ const handleCanvasSize = (size: string) => {
177
+ if (proxy.$Flex.clickCountLimit()) {
178
+ // 限制放大缩小指定范围
179
+ if (size === "add" && canvasSize.value < 1.5) {
180
+ canvasSize.value = Number((canvasSize.value + 0.1).toFixed(2));
181
+ } else if (size === "cut" && canvasSize.value > 0.5) {
182
+ canvasSize.value = Number((canvasSize.value - 0.1).toFixed(2));
183
+ } else if (size === "restore") {
184
+ canvasSize.value = 1;
185
+ }
186
+ handleCanvasScale();
187
+ }
188
+ };
189
+ const chooseClick = (e: any) => {
190
+ formStore?.setFormCurrentId(allmainList.value[e.oldIndex]?.id);
191
+ formStore?.setFormCurrentIndex(e.oldIndex);
192
+ store?.set("curList", allmainList.value);
193
+ };
194
+ const changePos = (e: any) => {
195
+ formStore?.setFormCurrentId(allmainList.value[e.newIndex]?.id);
196
+ formStore?.setFormCurrentIndex(e.newIndex);
197
+ store?.set("curList", allmainList.value);
198
+ };
199
+ const addControl = (e: any) => {
200
+ formStore?.setFormCurrentId(allmainList.value[e.newIndex]?.id);
201
+ formStore?.setFormCurrentIndex(e.newIndex);
202
+ store?.set("curList", allmainList.value);
203
+ };
204
+ const handlePaste = () => {
205
+ pasteShow.value = false;
206
+ paste();
207
+ };
208
+ const handleNoDraggable = (e: any) => {
209
+ if (pasteShow.value) {
210
+ pasteShow.value = false;
211
+ }
212
+ e.preventDefault();
213
+ const path = e.path;
214
+ for (let i = 0; i < path.length; i++) {
215
+ if (
216
+ path[i].getAttribute &&
217
+ path[i].getAttribute("class") &&
218
+ path[i].getAttribute("class").indexOf("shape") >= 0
219
+ ) {
220
+ return;
221
+ }
222
+ }
223
+ const x = e.offsetX;
224
+ const y = e.offsetY;
225
+ nextTick(() => {
226
+ editForm.value.style.left = x + "px";
227
+ editForm.value.style.top = y + "px";
228
+ pasteShow.value = true;
229
+ });
230
+ };
231
+ return {
232
+ scale: computed(() => uiControl?.get<number>("scale")),
233
+ globalDatas,
234
+ canvasBox,
235
+ editForm,
236
+ handleCanvasSize,
237
+ pageType,
238
+ canvasSize,
239
+ dragDom,
240
+ chooseClick,
241
+ addControl,
242
+ changePos,
243
+ allmainList,
244
+ currentId,
245
+ handleNoDraggable,
246
+ handlePaste,
247
+ pasteShow,
248
+ fullScreen,
249
+ onEditorCenter: (e: any) => {
250
+ if (e && e.path && e.path[0].className == "editor_pages_center") {
251
+ formStore?.setFormCurrentId("");
252
+ pasteShow.value = false;
253
+ }
254
+ },
255
+ };
256
+ },
257
+ });
258
+ </script>
@@ -0,0 +1,30 @@
1
+ <template>
2
+ <div>
3
+ <div
4
+ v-for="(item, index) in globalFormLists"
5
+ :key="index"
6
+ class="form_tab3_list"
7
+ >
8
+ <component
9
+ :is="item.ControlType"
10
+ :item="item"
11
+ :data="globalDatas"
12
+ :controlItems="globalFormLists"
13
+ ></component>
14
+ </div>
15
+ </div>
16
+ </template>
17
+ <script lang="ts">
18
+ import { defineComponent, computed, inject } from "vue";
19
+ import type { Controls } from "@/type";
20
+ export default defineComponent({
21
+ setup() {
22
+ const { formStore } = inject<Controls>("control") || {};
23
+ const globalFormLists = computed(() => formStore?.get("globalFormList"));
24
+ const globalDatas = computed(() => formStore?.get("globalDatas"));
25
+ return {
26
+ globalFormLists,globalDatas
27
+ };
28
+ },
29
+ });
30
+ </script>
@@ -0,0 +1,41 @@
1
+ <template>
2
+ <div ref="jsonCenter"></div>
3
+ </template>
4
+ <script>
5
+ import { defineComponent, ref, computed, inject, toRaw, onMounted } from "vue";
6
+ import JSONEditor from "jsoneditor";
7
+ export default defineComponent({
8
+ setup(props, context) {
9
+ const jsonCenter = ref();
10
+ let jsonEditor = undefined;
11
+ const { formStore } = inject("control") || {};
12
+ const allmainList = computed(() => formStore?.get("allFormList"));
13
+ const initFormToJson = (formlist) => {
14
+ return window.VueContext.$Flex.initFormToJson(toRaw(formlist));
15
+ };
16
+ onMounted(() => {
17
+ const result = initJsonCenter();
18
+ context.emit("editor", result);
19
+ });
20
+ function initJsonCenter() {
21
+ const jsonDom = jsonCenter.value;
22
+ if (jsonEditor) {
23
+ jsonEditor?.set(initFormToJson(allmainList.value));
24
+ } else {
25
+ const options = {
26
+ modes: ["text", "code", "view"],
27
+ mode: "code",
28
+ search: false,
29
+ };
30
+ jsonEditor = new JSONEditor(jsonDom, options);
31
+ jsonEditor?.set(initFormToJson(allmainList.value));
32
+ }
33
+ return jsonEditor;
34
+ }
35
+ return {
36
+ initJsonCenter,
37
+ jsonCenter,
38
+ };
39
+ },
40
+ });
41
+ </script>
@@ -0,0 +1,37 @@
1
+ import { reactive } from "vue";
2
+
3
+ const state = reactive({
4
+ action: [
5
+ {
6
+ funcName: "mounted",
7
+ type: "mounted",
8
+ methods: 'mounted',
9
+ funcStr: "",
10
+ disabled: true,
11
+ },
12
+ {
13
+ funcName: "updated",
14
+ type: "updated",
15
+ methods: 'updated',
16
+ funcStr: "",
17
+ disabled: true,
18
+ },
19
+ ],
20
+ currentAction: null,
21
+ });
22
+
23
+ class Action {
24
+ set(name: keyof typeof state, value: any) {
25
+ (state as any)[name] = value;
26
+ }
27
+
28
+ get(name: keyof typeof state) {
29
+ return (state as any)[name];
30
+ }
31
+ }
32
+
33
+ export {state};
34
+
35
+ export type ActionForm = Action;
36
+
37
+ export default new Action();
@@ -0,0 +1,207 @@
1
+ import { reactive } from "vue";
2
+ import history from "@/controller/history";
3
+ import { AllFormItem, FormState, BaseFormConfig } from "@/type";
4
+ import type {fieldTds, fieldsTrs} from 'starfish-form/src/utils/fieldConfig';
5
+ const state = reactive<FormState>({
6
+ allFormList: [], // 存储所有选择的表单控件
7
+ curControl: {}, // 选中的表单控件
8
+ currentIndex: -1, // 选中的控件的索引
9
+ currentId: "",
10
+ preview: false, // 开启预览进行表单验证
11
+ previewShow: false, // 预览是否展示
12
+ save: true, // 保存
13
+ // 下一次保存的时候判断表单是否变更了,而不用变更就改变vuex的save,但是我们监听了save会形成死循环
14
+ formUpdate: false, // 判断表单是否更新
15
+ AllFormResult: [], // 预览和存储到数据库最终结果
16
+ formResult: {}, // 用户在动态表单输入的配置结果
17
+ globalDatas: {},
18
+ globalFormList: [],
19
+ });
20
+
21
+ export { state };
22
+
23
+ class Form {
24
+ updateAllFormList(allFormList: AllFormItem[]) {
25
+ console.log("allForm", allFormList);
26
+ state.allFormList = allFormList;
27
+ // 解决属性面板表单和jsontab切换后,数据不同步问题
28
+ if (state.currentIndex != -1) {
29
+ state.curControl = allFormList[state.currentIndex];
30
+ }
31
+ }
32
+ setHistory() {
33
+ history?.setValue({
34
+ allFormList: window.VueContext.$Flex.deepClone(state.allFormList),
35
+ currentIndex: state.currentIndex,
36
+ currentId: state.currentId,
37
+ curControl: window.VueContext.$Flex.deepClone(state.allFormList[state.currentIndex]),
38
+ });
39
+ }
40
+ setFormCurrentIndex(index: number) {
41
+ state.currentIndex = index;
42
+ }
43
+ setFormCurrentId(id: string) {
44
+ state.currentId = id;
45
+ if (id) {
46
+ const result = this.getCurrentItem(id);
47
+ state.curControl = result || {};
48
+ } else {
49
+ state.curControl = {};
50
+ }
51
+ }
52
+ getCurrentItem(id: string) {
53
+ let result;
54
+ state.allFormList.find((item) => {
55
+ if (item.id == id) {
56
+ result = item;
57
+ return item;
58
+ } else if (item.layout) {
59
+ const res = this.getLayoutCurCtrol(item, id);
60
+ if (res) {
61
+ result = res;
62
+ return item;
63
+ }
64
+ }
65
+ });
66
+ return result;
67
+ }
68
+ getLayoutCurCtrol(item: AllFormItem, id: string): AllFormItem | undefined {
69
+ let result;
70
+ if (item.ControlType == "TableLayout") {
71
+ const trs = item.data.trs;
72
+ if (trs && trs.length > 0) {
73
+ trs.find((trItem: fieldsTrs) => {
74
+ return trItem.tds.find((tdItem: fieldTds) => {
75
+ return tdItem.list.find((listItem: AllFormItem) => {
76
+ if (listItem.layout) {
77
+ if (listItem.id == id) {
78
+ result = listItem;
79
+ } else {
80
+ result = this.getLayoutCurCtrol(listItem, id);
81
+ }
82
+ return result;
83
+ } else if (listItem.id == id) {
84
+ result = listItem;
85
+ return result;
86
+ }
87
+ });
88
+ });
89
+ });
90
+ }
91
+ } else if (item.ControlType == "Grid") {
92
+ const columns = item.data.columns;
93
+ if (columns && columns.length > 0) {
94
+ columns.find((colItem: any) => {
95
+ return colItem.list.find((listItem: any) => {
96
+ if (listItem.layout) {
97
+ if (listItem.id == id) {
98
+ result = listItem;
99
+ } else {
100
+ result = this.getLayoutCurCtrol(listItem, id);
101
+ }
102
+ return result;
103
+ } else if (listItem.id == id) {
104
+ result = listItem;
105
+ return result;
106
+ }
107
+ });
108
+ });
109
+ }
110
+ } else if (item.ControlType == "Collapse" || item.ControlType == "Tabs") {
111
+ const items = item.data.items;
112
+ if (items && items.length > 0) {
113
+ items.find((colItem: any) => {
114
+ return colItem.list.find((listItem: any) => {
115
+ if (listItem.layout) {
116
+ if (listItem.id == id) {
117
+ result = listItem;
118
+ } else {
119
+ result = this.getLayoutCurCtrol(listItem, id);
120
+ }
121
+ return result;
122
+ } else if (listItem.id == id) {
123
+ result = listItem;
124
+ return result;
125
+ }
126
+ });
127
+ });
128
+ }
129
+ }
130
+ return result;
131
+ }
132
+ // 获取默认值和键名组成新对象
133
+ handleDynamicForm() {
134
+ state.formResult = this.getDynamicForm(state.AllFormResult);
135
+ console.log("formResult", state.formResult);
136
+ }
137
+ getDynamicForm(list: BaseFormConfig[]) {
138
+ const data: Record<string, any> = {};
139
+ list.forEach((item: BaseFormConfig) => {
140
+ if (item.layout) {
141
+ if (item.ControlType == "Grid" && item.data.columns) {
142
+ item.data.columns.forEach((colItem: { list: any }) => {
143
+ Object.assign(data, this.getDynamicForm(colItem.list));
144
+ });
145
+ } else if (item.ControlType == "TableLayout") {
146
+ const trs = item.data.trs;
147
+ if (trs && trs.length > 0) {
148
+ trs.forEach((trItem: any) => {
149
+ trItem.tds.forEach((tdItem: { list: BaseFormConfig[] }) => {
150
+ Object.assign(data, this.getDynamicForm(tdItem.list));
151
+ });
152
+ });
153
+ }
154
+ } else if (item.ControlType == "Collapse" || item.ControlType == "Tabs") {
155
+ const items = item.data.items;
156
+ if(items){
157
+ items.forEach((colItem: { list: any }) => {
158
+ Object.assign(data, this.getDynamicForm(colItem.list));
159
+ });
160
+ }
161
+ }
162
+ } else if (!item.layout) {
163
+ if (item.data.itemConfig) {
164
+ if (typeof item.data.itemConfig.value == "string") {
165
+ data[item.data.fieldName] = item.data.itemConfig.value;
166
+ } else {
167
+ // 防止对数据进行劫持监听
168
+ data[item.data.fieldName] = [...item.data.itemConfig.value];
169
+ }
170
+ } else {
171
+ data[item.data.fieldName] = item.data.default;
172
+ }
173
+ }
174
+ });
175
+ return data;
176
+ }
177
+ openPreview(preview: boolean) {
178
+ state.preview = preview;
179
+ }
180
+ setSave(type: boolean) {
181
+ state.save = type;
182
+ }
183
+ setFormUpdate(type: boolean) {
184
+ state.formUpdate = type;
185
+ }
186
+ getControlItems(): AllFormItem[] {
187
+ return state.curControl && state.curControl.controlItems;
188
+ }
189
+ getAllFormList(): AllFormItem[] {
190
+ return state.allFormList;
191
+ }
192
+ setAllFormList(item: AllFormItem): void {
193
+ state.allFormList.push(item);
194
+ }
195
+ set(name: keyof typeof state, value: any) {
196
+ (state as any)[name] = value;
197
+ }
198
+
199
+ get(name: keyof typeof state) {
200
+ return (state as any)[name];
201
+ }
202
+ }
203
+
204
+
205
+ export type formContrl = Form;
206
+
207
+ export default new Form();
@@ -0,0 +1,57 @@
1
+ import { reactive } from "vue";
2
+ import { HistoryState, HistoryItem } from "@/type";
3
+ import formStore from "./form";
4
+
5
+ const state = reactive<HistoryState>({
6
+ historyList: [],
7
+ index: -1,
8
+ maxStep: 20,
9
+ historyFlag: false,
10
+ });
11
+
12
+ class History {
13
+ public setValue(value: HistoryItem) {
14
+ state.historyList.push(value);
15
+ if(state.historyList.length > state.maxStep){
16
+ state.historyList = state.historyList.slice(state.historyList.length - state.maxStep);
17
+ }
18
+ state.index = state.historyList.length - 1;
19
+ }
20
+ public back() {
21
+ if(state.index == -1)return;
22
+ state.index -= 1;
23
+ if (state.index > -1) {
24
+ state.historyFlag = true;
25
+ formStore?.set("allFormList", state.historyList[state.index].allFormList);
26
+ formStore?.set("currentIndex", state.historyList[state.index].currentIndex);
27
+ formStore?.set("curControl", state.historyList[state.index].curControl);
28
+ formStore?.set("currentId", state.historyList[state.index].currentId);
29
+ }else{
30
+ state.historyFlag = true;
31
+ formStore?.set("allFormList", []);
32
+ formStore?.set("currentIndex", -1);
33
+ formStore?.set("curControl", {});
34
+ formStore?.set("currentId", '');
35
+ }
36
+ }
37
+ public go() {
38
+ if (state.index >= state.historyList.length -1) {
39
+ return;
40
+ }
41
+ state.index += 1;
42
+ state.historyFlag = true;
43
+ formStore?.set("allFormList", state.historyList[state.index].allFormList);
44
+ formStore?.set("currentIndex", state.historyList[state.index].currentIndex);
45
+ formStore?.set("curControl", state.historyList[state.index].curControl);
46
+ }
47
+ public get<T>(name: keyof typeof state):T {
48
+ return (state as any)[name];
49
+ }
50
+ public set(name: keyof typeof state, value: any) {
51
+ (state as any)[name] = value;
52
+ }
53
+ }
54
+
55
+ export type hisContrl = History;
56
+
57
+ export default new History();