sun-form-v3 1.0.65 → 1.0.67

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. package/package.json +8 -5
  2. package/src/App.vue +9 -0
  3. package/src/assets/font/YouSheBiaoTiHei-2.ttf +0 -0
  4. package/src/assets/font/demo.css +539 -0
  5. package/src/assets/font/demo_index.html +1200 -0
  6. package/src/assets/font/iconfont.css +191 -0
  7. package/src/assets/font/iconfont.js +1 -0
  8. package/src/assets/font/iconfont.json +317 -0
  9. package/src/assets/font/iconfont.ttf +0 -0
  10. package/src/assets/font/iconfont.woff +0 -0
  11. package/src/assets/font/iconfont.woff2 +0 -0
  12. package/src/assets/img/bg_footer.png +0 -0
  13. package/src/assets/img/bg_title.png +0 -0
  14. package/src/assets/img/file.png +0 -0
  15. package/src/assets/img/logo.png +0 -0
  16. package/src/assets/img/logo2.png +0 -0
  17. package/src/assets/img/logo22.png +0 -0
  18. package/src/assets/img/logo23.png +0 -0
  19. package/src/assets/img/logo3.png +0 -0
  20. package/src/assets/img//347/237/251/345/275/242@2x.png +0 -0
  21. package/src/assets/logo.svg +1 -0
  22. package/src/assets/styles/element/index.scss +15 -0
  23. package/src/assets/styles/index.css +3 -0
  24. package/src/components/a.js +14 -0
  25. package/src/components/aDesigner/config.vue +127 -0
  26. package/src/components/aDesigner/design.vue +20 -0
  27. package/src/components/aDesigner/designer.js +342 -0
  28. package/src/components/aDesigner/http.js +292 -0
  29. package/src/components/aDesigner/index.vue +144 -0
  30. package/src/components/aDesigner/panel.vue +144 -0
  31. package/src/components/aDesigner/show.vue +24 -0
  32. package/src/components/widgetCommonComps/commonApiConfig/index.vue +194 -0
  33. package/src/components/widgetCommonComps/commonCard/index.vue +36 -0
  34. package/src/components/widgetCommonComps/commonCodeEditor/editor.vue +219 -0
  35. package/src/components/widgetCommonComps/commonCodeEditor/modalEditor.vue +68 -0
  36. package/src/components/widgetCommonComps/commonCollapseCard/index.vue +10 -0
  37. package/src/components/widgetCommonComps/commonContainer/index.vue +95 -0
  38. package/src/components/widgetCommonComps/commonJsonInput/index.vue +59 -0
  39. package/src/components/widgetCommonComps/commonLabelContainer/index.vue +39 -0
  40. package/src/components/widgetCommonComps/commonSidetree/index.vue +61 -0
  41. package/src/components/widgetCommonComps/commonTypeInput/index.vue +75 -0
  42. package/src/components/widgetCommonComps/commonWidgetLabelContainer/index.vue +55 -0
  43. package/src/components/widgetCommonComps/index copy.js +17 -0
  44. package/src/components/widgetCommonComps/index.js +17 -0
  45. package/src/components/widgetConfigComps/config-input/index.vue +60 -0
  46. package/src/components/widgetConfigComps/index copy.js +13 -0
  47. package/src/components/widgetConfigComps/index.js +17 -0
  48. package/src/components/widgetShowComps/index.js +29 -0
  49. package/src/components/widgetShowComps/widget-form/index.vue +43 -0
  50. package/src/components/widgetShowComps/widget-homepage/index.vue +41 -0
  51. package/src/components/widgetShowComps/widget-input/index.vue +85 -0
  52. package/src/components/widgetShowComps/widget-select/index.vue +31 -0
  53. package/src/designer.js +342 -0
  54. package/src/http.js +292 -0
  55. package/src/index.js +24 -0
  56. package/src/index2.js +23 -0
  57. package/src/main.js +19 -0
  58. package/src/remark.js +708 -0
  59. package/src/testBtn.vue +11 -0
  60. package/src/testInput.vue +12 -0
  61. package/src/util/jsformat.js +568 -0
  62. package/src/widgetConfig.js +1112 -0
  63. package/dist/abap-DfvySaIJ.js +0 -1404
  64. package/dist/apex-B__0irD3.js +0 -332
  65. package/dist/assets/css.worker-OK053IOu.js +0 -84
  66. package/dist/assets/editor.worker-D9iUZyMP.js +0 -11
  67. package/dist/assets/html.worker-CL40hqKM.js +0 -458
  68. package/dist/assets/json.worker-6f9bhSHY.js +0 -42
  69. package/dist/assets/ts.worker-B6g3wjaE.js +0 -37021
  70. package/dist/azcli-CDMGhRmx.js +0 -74
  71. package/dist/bat-0Mk8aqzx.js +0 -106
  72. package/dist/bicep-BBi_I06Z.js +0 -108
  73. package/dist/cameligo-D0G_Zm6X.js +0 -180
  74. package/dist/clojure-o2ZKLeMp.js +0 -767
  75. package/dist/coffee-DOQff5VC.js +0 -238
  76. package/dist/cpp-CQGJnWhD.js +0 -395
  77. package/dist/csharp-C1jLsHl8.js +0 -332
  78. package/dist/csp-C_ttMQaW.js +0 -59
  79. package/dist/css-BC202kVV.js +0 -193
  80. package/dist/cssMode-B2c4O0YS.js +0 -1541
  81. package/dist/cypher-DwtEH7Fi.js +0 -269
  82. package/dist/dart-D9XknsP2.js +0 -287
  83. package/dist/dockerfile-DgsNjqqa.js +0 -136
  84. package/dist/ecl-BAMCHBl6.js +0 -462
  85. package/dist/elixir-CegIttP8.js +0 -575
  86. package/dist/favicon.ico +0 -0
  87. package/dist/flow9-9608t7UV.js +0 -148
  88. package/dist/freemarker2-C0V-2C6A.js +0 -995
  89. package/dist/fsharp-CCtt9-1_.js +0 -223
  90. package/dist/go-CGUIPbct.js +0 -224
  91. package/dist/graphql-BNRIFFIn.js +0 -157
  92. package/dist/handlebars-Dq-D2gGP.js +0 -425
  93. package/dist/hcl-C__KLIXe.js +0 -189
  94. package/dist/html-CHe4dRTt.js +0 -314
  95. package/dist/htmlMode-DmZav6BJ.js +0 -1551
  96. package/dist/index2-CDdAhO0H.js +0 -124690
  97. package/dist/ini-CeKYn_zA.js +0 -77
  98. package/dist/java-Dm24deQl.js +0 -238
  99. package/dist/javascript-e6NjSQC6.js +0 -76
  100. package/dist/jsonMode-pOauncTt.js +0 -1957
  101. package/dist/julia-BImNW7VE.js +0 -517
  102. package/dist/kotlin-BfE79GEb.js +0 -259
  103. package/dist/less-DglNOcaC.js +0 -168
  104. package/dist/lexon-BA0dRz9Q.js +0 -163
  105. package/dist/liquid-DGCC4WOg.js +0 -246
  106. package/dist/lua-DMkWzJcm.js +0 -168
  107. package/dist/m3-sA-5shO8.js +0 -216
  108. package/dist/markdown-OYRB1igA.js +0 -235
  109. package/dist/mdx-GitjX2xy.js +0 -171
  110. package/dist/mips-rRzkJ_7G.js +0 -204
  111. package/dist/msdax-DoVJdUhd.js +0 -381
  112. package/dist/mysql-Ty44IHXo.js +0 -884
  113. package/dist/objective-c-VUfyhYrA.js +0 -189
  114. package/dist/pascal-DkASiYyw.js +0 -257
  115. package/dist/pascaligo-p-ELPlVO.js +0 -170
  116. package/dist/perl-Cjl1FxLZ.js +0 -632
  117. package/dist/pgsql-DjVenF7s.js +0 -857
  118. package/dist/php-CwvGzZOO.js +0 -506
  119. package/dist/pla-Br1iaBIV.js +0 -143
  120. package/dist/postiats-BaeP8zZY.js +0 -913
  121. package/dist/powerquery-CLCshuo8.js +0 -896
  122. package/dist/powershell-CZV50w5N.js +0 -245
  123. package/dist/protobuf-MV3XTewJ.js +0 -426
  124. package/dist/pug-DkDg4c4l.js +0 -408
  125. package/dist/python-BxUPejAm.js +0 -282
  126. package/dist/qsharp-BAtiKA97.js +0 -291
  127. package/dist/r-8ocrd-h-.js +0 -249
  128. package/dist/razor-B0zHeS7k.js +0 -556
  129. package/dist/redis-9sZiddxc.js +0 -308
  130. package/dist/redshift-DQfTOGC0.js +0 -815
  131. package/dist/restructuredtext-DXU-vkgr.js +0 -180
  132. package/dist/ruby-DotfqwMf.js +0 -517
  133. package/dist/rust-BIauJ5KN.js +0 -349
  134. package/dist/sb-CmWMvDEV.js +0 -121
  135. package/dist/scala-C81brEbk.js +0 -376
  136. package/dist/scheme-D0pcFz2x.js +0 -114
  137. package/dist/scss-BOdN2fGG.js +0 -268
  138. package/dist/shell-6E09eAkU.js +0 -227
  139. package/dist/solidity-CWStzA1K.js +0 -1373
  140. package/dist/sophia-76Sb6CWe.js +0 -205
  141. package/dist/sparql-BmZTkOWT.js +0 -207
  142. package/dist/sql-Cs9TBAW5.js +0 -859
  143. package/dist/st-B-rqE1Bu.js +0 -422
  144. package/dist/style.css +0 -1
  145. package/dist/sun-form-v3.es.js +0 -4
  146. package/dist/sun-form-v3.umd.js +0 -1908
  147. package/dist/swift-Btsj6YxQ.js +0 -318
  148. package/dist/systemverilog-B3RHBRa2.js +0 -582
  149. package/dist/tcl-Dpj776pn.js +0 -238
  150. package/dist/tsMode-AhR0apFR.js +0 -886
  151. package/dist/twig-Bb9JmBsE.js +0 -398
  152. package/dist/typescript-DW_IjlW5.js +0 -349
  153. package/dist/typespec-CDWeg3SU.js +0 -123
  154. package/dist/vb-DEXnYwEI.js +0 -378
  155. package/dist/wgsl-D602c1lx.js +0 -445
  156. package/dist/xml-CraN90Vi.js +0 -101
  157. package/dist/yaml-D6yA8dTm.js +0 -212
@@ -0,0 +1,15 @@
1
+ /* 只需要重写你需要的即可 */
2
+ @forward 'element-plus/theme-chalk/src/common/var.scss'with (
3
+ $colors: ('primary': (
4
+ 'base': rgb(85, 132, 255),
5
+ ),
6
+ ),
7
+ );
8
+
9
+
10
+
11
+ @use "element-plus/theme-chalk/src/index.scss"as *;
12
+
13
+ body {
14
+ margin: 0;
15
+ }
@@ -0,0 +1,3 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
@@ -0,0 +1,14 @@
1
+ const modules =
2
+ import.meta.glob('./test**.vue', {
3
+ eager: true
4
+ });
5
+ console.log('modules',modules);
6
+ const components = Object.fromEntries(
7
+ Object.entries(modules).map(([path, module]) => {
8
+ const componentName = module.default.name
9
+ return [componentName, module.default];
10
+ })
11
+ );
12
+ export default {
13
+ ...components,
14
+ };
@@ -0,0 +1,127 @@
1
+ <template>
2
+ <common-card title="基础属性" class="mb-1">
3
+ <div class="w-full">
4
+ <common-label-container label="唯一名称">
5
+ <el-input v-model="chosenWidget.id" disabled>
6
+ <template #append>
7
+ <el-button icon="Refresh" />
8
+ </template>
9
+ </el-input>
10
+ </common-label-container>
11
+ <common-label-container label="组件标签">
12
+ <el-input v-model="chosenWidget.props.label">
13
+ </el-input>
14
+ </common-label-container>
15
+ <common-label-container label="字段名称">
16
+ <el-input v-model="chosenWidget.props.zdname" placeholder="填写会作为表单字段名称">
17
+ </el-input>
18
+ </common-label-container>
19
+ <common-label-container label="默认赋值">
20
+ <common-type-input v-model="chosenWidget.props.value"></common-type-input>
21
+ </common-label-container>
22
+ <common-label-container label="备注内容">
23
+ <el-input v-model="chosenWidget.props.remark" placeholder="填写会有备注提示内容">
24
+ </el-input>
25
+ </common-label-container>
26
+ <common-label-container label="组件宽度">
27
+ <el-slider v-model="chosenWidget.props.width" :step="2" show-stops :max="24" :min="6" />
28
+ </common-label-container>
29
+ <common-label-container label="标签宽度">
30
+ <el-input v-model="chosenWidget.props.labelWidth" placeholder="请填写标签信息">
31
+ </el-input>
32
+ </common-label-container>
33
+ <common-label-container label="标签位置">
34
+ <el-radio-group v-model="chosenWidget.props.labelPosition">
35
+ <el-radio-button value="left" label="居左"></el-radio-button>
36
+ <el-radio-button value="top" label="居上"></el-radio-button>
37
+ </el-radio-group>
38
+ </common-label-container>
39
+ <common-label-container label="标签对齐">
40
+ <el-radio-group v-model="chosenWidget.props.labelAlign">
41
+ <el-radio-button value="left" label="居左"></el-radio-button>
42
+ <el-radio-button value="right" label="居右"></el-radio-button>
43
+ </el-radio-group>
44
+ </common-label-container>
45
+ <common-label-container label="是否隐藏">
46
+ <el-radio-group v-model="chosenWidget.props.hide">
47
+ <el-radio-button :value="false" label="显示"></el-radio-button>
48
+ <el-radio-button :value="true" label="隐藏"></el-radio-button>
49
+ </el-radio-group>
50
+ </common-label-container>
51
+ </div>
52
+ <!-- <common-json-input v-model="data.chosenWidget.props.list"></common-json-input> -->
53
+ <common-api-config :designer="designer" v-if="chosenWidget.props.apiSet"
54
+ v-model="chosenWidget.props.apiSet"></common-api-config>
55
+ <component :ref="chosenWidget.id" :is="getComponent(chosenWidget.type)" :widget="chosenWidget" :designer="designer">
56
+ </component>
57
+ </common-card>
58
+ <common-card title="事件属性">
59
+ <common-label-container label="onCreated">
60
+ <modalEditor v-model="chosenWidget.props.onCreated" :params="['widget', 'self', 'app']" :designer="designer">
61
+ </modalEditor>
62
+ </common-label-container>
63
+ <common-label-container label="onMounted">
64
+ <modalEditor v-model="chosenWidget.props.onMounted" :params="['widget', 'self', 'app']" :designer="designer">
65
+ </modalEditor>
66
+ </common-label-container>
67
+ <common-label-container label="onInput">
68
+ <modalEditor v-model="chosenWidget.props.onInput" :params="['value', 'widget', 'self', 'app']"
69
+ :designer="designer">
70
+ </modalEditor>
71
+ </common-label-container>
72
+ <common-label-container label="onChange">
73
+ <modalEditor v-model="chosenWidget.props.onChange" :params="['value', 'widget', 'self', 'app']"
74
+ :designer="designer">
75
+ </modalEditor>
76
+ </common-label-container>
77
+ <common-label-container label="onFocus">
78
+ <modalEditor v-model="chosenWidget.props.onFocus" :params="['value', 'widget', 'self', 'app']"
79
+ :designer="designer">
80
+ </modalEditor>
81
+ </common-label-container>
82
+ <common-label-container label="onBlur">
83
+ <modalEditor v-model="chosenWidget.props.onBlur" :params="['value', 'widget', 'self', 'app']"
84
+ :designer="designer">
85
+ </modalEditor>
86
+ </common-label-container>
87
+ <common-label-container label="onHandle">
88
+ <modalEditor v-model="chosenWidget.props.onHandle" :params="['widget', 'self', 'app']" :designer="designer">
89
+ </modalEditor>
90
+ </common-label-container>
91
+ </common-card>
92
+ <!-- <common-code-editor v-model="data.chosenWidget.props.value"></common-code-editor> -->
93
+ <!-- <modalEditor v-model="data.chosenWidget.props.value"></modalEditor> -->
94
+ <!-- <CommonTypeInput v-model="data.chosenWidget.props.value"></CommonTypeInput> -->
95
+ <!-- <common-api-config :designer="designer" v-if="chosenWidget.props.apiSet"
96
+ v-model="chosenWidget.props.apiSet"></common-api-config>
97
+ {{ chosenWidget }} -->
98
+ <!-- {{ designer.widgetConfig }} -->
99
+ </template>
100
+
101
+ <script setup>
102
+
103
+ import { ref, reactive, watch, computed, defineAsyncComponent } from 'vue';
104
+ import commonCodeEditor from '../widgetCommonComps/commonCodeEditor/editor.vue'
105
+ import modalEditor from '../widgetCommonComps/commonCodeEditor/modalEditor.vue'
106
+ const modules = import.meta.glob('../widgetConfigComps/**/index.vue');
107
+ const components = Object.fromEntries(
108
+ Object.entries(modules).map(([path, importFn]) => {
109
+ const match = path.match(/\/([^/]+)\/index\.vue$/);
110
+ const componentName = match ? match[1] : null;
111
+ return [componentName, defineAsyncComponent(importFn)];
112
+ })
113
+ );
114
+ const getComponent = (type) => {
115
+ return components['config-' + type] || null;
116
+ };
117
+ defineOptions({ name: "config" })
118
+ let props = defineProps({
119
+ designer: {
120
+ type: Object,
121
+ default: {}
122
+ }
123
+ })
124
+ let designer = props.designer
125
+ let chosenWidget = computed(() => designer.chosenWidget)
126
+ </script>
127
+ <style scoped lang="scss"></style>
@@ -0,0 +1,20 @@
1
+ <template>
2
+ <commonContainer class="h-full w-full" :widget="designer.widgetConfig" :designer="designer">
3
+ <widget-homepage :widget="designer.widgetConfig" :designer="designer"></widget-homepage>
4
+ </commonContainer>
5
+ </template>
6
+
7
+ <script setup>
8
+ import { ref, reactive, toRaw, markRaw } from 'vue';
9
+ let props = defineProps({
10
+ designer: {
11
+ type: Object,
12
+ default: {}
13
+ }
14
+ })
15
+ let designer = props.designer
16
+ let homeWidget = designer.widgetConfig
17
+ defineOptions({ name: "design" })
18
+ </script>
19
+
20
+ <style scoped lang="scss"></style>
@@ -0,0 +1,342 @@
1
+ import XEUtils from "xe-utils"
2
+ import Http from './http'
3
+ import {
4
+ ElNotification
5
+ } from 'element-plus'
6
+ import {
7
+ reactive,
8
+ ref,
9
+ watch
10
+ } from 'vue'
11
+ /**
12
+ * 设计器类,用于管理组件配置和交互
13
+ * @class Designer
14
+ * @param {Object} options 初始化选项,包含组件配置
15
+ */
16
+ class Designer {
17
+ constructor({
18
+ widgetConfig,
19
+ showMode = false
20
+ }) {
21
+ /**
22
+ * 渲染器模式
23
+ */
24
+ this.showMode = ref(showMode)
25
+ /**
26
+ * 反向响应式的组件配置对象
27
+ */
28
+ this.widgetConfig = reactive(widgetConfig);
29
+ /**
30
+ * XEUtils 工具库实例
31
+ */
32
+ this.$utils = XEUtils;
33
+ /**
34
+ * 组件映射表,用于快速查找组件
35
+ */
36
+ this.widgetMap = new Map();
37
+ /**
38
+ * Vue 实例映射表,用于快速查找 Vue 实例
39
+ */
40
+ this.vueInstanceMap = new Map();
41
+ /**
42
+ * 组件ID列表
43
+ */
44
+ this.widgetIds = [];
45
+ /**
46
+ * 当前选中的组件引用
47
+ */
48
+ this.chosenWidget = ref(null);
49
+ /**
50
+ * 操作历史列表
51
+ */
52
+ this.historyList = [];
53
+ /**
54
+ * 操作历史索引
55
+ */
56
+ this.historyIndex = ref(0);
57
+ /**
58
+ * 标记是否在操作历史中
59
+ */
60
+ this.isHistory = false;
61
+ /**
62
+ * Http服务实例,用于发起请求
63
+ */
64
+ this.$http = new Http({
65
+ baseUrl: "/api"
66
+ });
67
+ /**
68
+ * 根据组件配置构建组件映射表
69
+ */
70
+ this.buildWidgetMap(this.widgetConfig);
71
+ /**
72
+ * 监听组件配置的变化,重建组件映射表,并更新选中组件
73
+ */
74
+ watch(() => this.widgetConfig, (val) => {
75
+ this.rebuildWidgetMap();
76
+ this.chosenWidget.value = this.getWidgetById(this.widgetConfig.chosenId);
77
+ }, {
78
+ deep: true,
79
+ immediate: true
80
+ });
81
+ /**
82
+ * 监听组件列表的变化,记录操作历史
83
+ */
84
+ watch(() => this.widgetConfig.widgetList, (val) => {
85
+ if (!this.isHistory) {
86
+ this.historyList.push({
87
+ widgetConfig: this.$utils.clone(this.widgetConfig, true),
88
+ time: this.$utils.toDateString(new Date(), 'HH:mm:ss'),
89
+ index: this.historyList.length
90
+ });
91
+ this.historyIndex.value = this.historyList.length - 1;
92
+ } else {
93
+ this.isHistory = false;
94
+ }
95
+ }, {
96
+ deep: true,
97
+ immediate: true
98
+ });
99
+ }
100
+ eventHandle({
101
+ value = null,
102
+ eventType,
103
+ widget,
104
+ tableItemData
105
+ }) {
106
+ if (!this.showMode) return;
107
+ if (widget.props[eventType]) {
108
+ let funcstr = widget.props[eventType]
109
+ let func = new Function('value', 'widget','self','app', funcstr);
110
+ func(value, widget, this.getVueInstance(widget.id), this)
111
+ }
112
+ }
113
+ /**
114
+ * 设置vue实例
115
+ */
116
+ setVueIncetance(id, vueInstance) {
117
+ this.vueInstanceMap.set(id, vueInstance);
118
+ }
119
+ /**
120
+ * 获取vue实例
121
+ */
122
+ getVueInstance(id) {
123
+ return this.vueInstanceMap.get(id);
124
+ }
125
+ /**
126
+ * 设置当前选中的组件
127
+ * @param {Object} chosenWidget 选中的组件对象
128
+ */
129
+ setChosenWidget(chosenWidget) {
130
+ this.chosenWidget.value = chosenWidget;
131
+ }
132
+ /**
133
+ * 根据组件的apiSet配置发起请求
134
+ * @param {Object} widget 当前组件对象
135
+ */
136
+ requestByApisetConfig(widget) {
137
+ let apiSet = widget.props.apiSet;
138
+ if (!apiSet || !apiSet.apiurl) {
139
+ return;
140
+ }
141
+ let params = {};
142
+ let headers = {};
143
+ let method = apiSet.method;
144
+ if (apiSet.contentType == "FormData") {
145
+ if (method == "post" || method == "put" || method == "patch") {
146
+ method += "FormData";
147
+ }
148
+ }
149
+ if (apiSet.params.length) {
150
+ apiSet.params.forEach(e => {
151
+ params[e.label] = e.value;
152
+ });
153
+ }
154
+ if (apiSet.headers.length) {
155
+ apiSet.headers.forEach(e => {
156
+ headers[e.label] = e.value;
157
+ });
158
+ }
159
+ if (apiSet.paramsFormat) {
160
+ let fun = new Function("params", "widget", "app", apiSet.paramsFormat);
161
+ let paramData = this.$utils.clone(params, true);
162
+ var funcData = fun(paramData, widget, this);
163
+ if (funcData && typeof this.$utils.isPlainObject(funcData)) {
164
+ params = funcData;
165
+ }
166
+ }
167
+ if (apiSet.headersFormat) {
168
+ let fun = new Function("headers", "widget", "app", apiSet.headersFormat);
169
+ let headerData = this.$utils.clone(headers, true);
170
+ var funcData = fun(headerData, widget, this);
171
+ if (funcData && typeof this.$utils.isPlainObject(funcData)) {
172
+ headers = funcData;
173
+ }
174
+ }
175
+ this.$http[method](apiSet.apiurl, params, headers)
176
+ .then(res => {
177
+ if (apiSet.successFormat) {
178
+ let fun = new Function("res", "widget", "app", apiSet.successFormat);
179
+ fun(res, widget, this);
180
+ }
181
+ })
182
+ .catch(err => {
183
+ if (apiSet.errorFormat) {
184
+ let fun = new Function("error", "widget", "app", apiSet.errorFormat);
185
+ fun(err, widget, this);
186
+ }
187
+ });
188
+ }
189
+ /**
190
+ * 根据ID获取组件
191
+ * @param {String} id 组件ID
192
+ * @returns {Object|null} 组件对象或null(如果未找到)
193
+ */
194
+ getWidgetById(id) {
195
+ return this.widgetMap.get(id);
196
+ }
197
+ /**
198
+ * 根据历史索引更新组件配置
199
+ * @param {Object} updates 更新的对象
200
+ */
201
+ updateByHistory(updates) {
202
+ this.isHistory = true;
203
+ this.$utils.destructuring(this.widgetConfig, updates);
204
+ }
205
+ /**
206
+ * 更新组件的属性
207
+ * @param {String} id 组件ID
208
+ * @param {Object} updates 更新的对象
209
+ * @param {Boolean} force 是否强制更新,即使存在相同的ID
210
+ */
211
+ updateWidget(id, updates, force) {
212
+ const widget = this.getWidgetById(id);
213
+ if (widget) {
214
+ console.log('widget', widget);
215
+ console.log('updates', updates);
216
+ if (widget.id !== updates.id) {
217
+ if (this.widgetIds.includes(updates.id) && !force) {
218
+ ElNotification.warning('已经存在相同的id的组件,组件id不允许重复');
219
+ return;
220
+ }
221
+ }
222
+ if (id === 'homepage') {
223
+ if (updates.id !== id) {
224
+ ElNotification.warning('主页面的id不允许修改');
225
+ }
226
+ updates.id = updates.type = 'homepage';
227
+ }
228
+ this.$utils.destructuring(widget, updates);
229
+ } else {
230
+ console.warn(`Widget with id ${id} not found.`);
231
+ }
232
+ }
233
+ /**
234
+ * 重建组件映射表
235
+ */
236
+ rebuildWidgetMap() {
237
+ this.widgetMap.clear();
238
+ this.widgetIds = [];
239
+ this.buildWidgetMap(this.widgetConfig);
240
+ }
241
+ /**
242
+ * 递归构建组件映射表
243
+ * @param {Object} widget 当前组件对象
244
+ */
245
+ buildWidgetMap(widget) {
246
+ this.widgetMap.set(widget.id, widget);
247
+ this.widgetIds.push(widget.id);
248
+ if (widget.widgetList && widget.widgetList.length) {
249
+ widget.widgetList.forEach(widget => {
250
+ this.buildWidgetMap(widget);
251
+ });
252
+ }
253
+ }
254
+ /**
255
+ * 设置当前选中的组件ID
256
+ * @param {String} id 组件ID
257
+ */
258
+ setChosenId(id) {
259
+ this.widgetConfig.chosenId = id;
260
+ }
261
+ /**
262
+ * 获取当前选中的组件ID
263
+ * @returns {String} 当前选中的组件ID
264
+ */
265
+ getChosenId() {
266
+ return this.widgetConfig.chosenId;
267
+ }
268
+ /**
269
+ * 获取初始化的数据对象
270
+ * @param {Object} obj 初始数据对象
271
+ * @returns {Object} 处理后的初始数据对象
272
+ */
273
+ getChosenInitData(obj) {
274
+ obj = this.$utils.clone(obj, true);
275
+ obj.id = this.getUniqueId(obj.type);
276
+ this.setChosenId(obj.id);
277
+ let delkeyArr = ['isForm', 'canAddDataTableQuery', 'canAddDataTableList', 'addToPanel', 'active'];
278
+ let delkey = (key) => {
279
+ delete obj[key];
280
+ }
281
+ delkeyArr.forEach(e => {
282
+ delkey(e);
283
+ });
284
+ return obj;
285
+ }
286
+ /**
287
+ * 生成唯一的ID
288
+ * @param {String} prefix ID前缀
289
+ * @returns {String} 唯一的ID
290
+ */
291
+ getUniqueId(prefix) {
292
+ return prefix + '_' + Math.floor(new Date().getTime() % 100000) + "" + this.$utils.uniqueId();
293
+ }
294
+ /**
295
+ * 获取组件列表
296
+ * @returns {Array} 组件列表
297
+ */
298
+ getWidgetList() {
299
+ return this.widgetConfig.widgetList;
300
+ }
301
+ /**
302
+ * 获取组件配置
303
+ * @returns {Object} 组件配置对象
304
+ */
305
+ getWidgetConfig() {
306
+ return this.widgetConfig;
307
+ }
308
+ /**
309
+ * 更新组件配置
310
+ * @param {Object} config 新的组件配置
311
+ */
312
+ updateWidgetConfig(config) {
313
+ this.widgetConfig = config;
314
+ }
315
+ /**
316
+ * 根据组件ID查找其父组件
317
+ * @param {String} id 组件ID
318
+ * @returns {Object|null} 父组件对象或null(如果未找到)
319
+ */
320
+ getParentWidgetById(id) {
321
+ function recurse(items) {
322
+ for (const item of items) {
323
+ if (item.id === id) {
324
+ let index = items.findIndex(e => e.id === id);
325
+ return {
326
+ widgetList: items,
327
+ index: index
328
+ };
329
+ }
330
+ if (item.widgetList && item.widgetList.length > 0) {
331
+ const activeItem = recurse(item.widgetList);
332
+ if (activeItem) {
333
+ return activeItem;
334
+ }
335
+ }
336
+ }
337
+ return null;
338
+ }
339
+ return recurse(this.widgetConfig.widgetList);
340
+ }
341
+ }
342
+ export default Designer;