@bdsoft/element 1.1.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 (238) hide show
  1. package/README.md +90 -0
  2. package/global/index.ts +6 -0
  3. package/global/register-properties.ts +10 -0
  4. package/index.html +13 -0
  5. package/index.js +84 -0
  6. package/package-form/core/components/formCreate.js +274 -0
  7. package/package-form/core/components/fragment.js +12 -0
  8. package/package-form/core/factory/context.js +257 -0
  9. package/package-form/core/factory/creator.js +63 -0
  10. package/package-form/core/factory/maker.js +17 -0
  11. package/package-form/core/factory/manager.js +79 -0
  12. package/package-form/core/factory/node.js +85 -0
  13. package/package-form/core/factory/parser.js +28 -0
  14. package/package-form/core/frame/api.js +599 -0
  15. package/package-form/core/frame/attrs.js +12 -0
  16. package/package-form/core/frame/dataDriver.js +76 -0
  17. package/package-form/core/frame/fetch.js +119 -0
  18. package/package-form/core/frame/formCreate.js +274 -0
  19. package/package-form/core/frame/index.js +760 -0
  20. package/package-form/core/frame/provider.js +288 -0
  21. package/package-form/core/frame/util.js +274 -0
  22. package/package-form/core/handler/context.js +380 -0
  23. package/package-form/core/handler/effect.js +122 -0
  24. package/package-form/core/handler/index.js +111 -0
  25. package/package-form/core/handler/inject.js +145 -0
  26. package/package-form/core/handler/input.js +197 -0
  27. package/package-form/core/handler/lifecycle.js +43 -0
  28. package/package-form/core/handler/loader.js +373 -0
  29. package/package-form/core/handler/page.js +46 -0
  30. package/package-form/core/handler/render.js +29 -0
  31. package/package-form/core/index.js +12 -0
  32. package/package-form/core/package.json +15 -0
  33. package/package-form/core/parser/html.js +17 -0
  34. package/package-form/core/render/cache.js +47 -0
  35. package/package-form/core/render/index.js +31 -0
  36. package/package-form/core/render/render.js +393 -0
  37. package/package-form/element-form/components/checkbox/package.json +17 -0
  38. package/package-form/element-form/components/checkbox/src/component.jsx +110 -0
  39. package/package-form/element-form/components/checkbox/src/index.js +3 -0
  40. package/package-form/element-form/components/frame/package.json +17 -0
  41. package/package-form/element-form/components/frame/src/IconCircleClose.vue +14 -0
  42. package/package-form/element-form/components/frame/src/IconDelete.vue +12 -0
  43. package/package-form/element-form/components/frame/src/IconDocument.vue +12 -0
  44. package/package-form/element-form/components/frame/src/IconFolderOpened.vue +12 -0
  45. package/package-form/element-form/components/frame/src/IconView.vue +12 -0
  46. package/package-form/element-form/components/frame/src/component.jsx +349 -0
  47. package/package-form/element-form/components/frame/src/index.js +3 -0
  48. package/package-form/element-form/components/frame/src/style.css +66 -0
  49. package/package-form/element-form/components/group/package.json +17 -0
  50. package/package-form/element-form/components/group/src/component.jsx +314 -0
  51. package/package-form/element-form/components/group/src/index.js +3 -0
  52. package/package-form/element-form/components/group/src/style.css +125 -0
  53. package/package-form/element-form/components/index.js +22 -0
  54. package/package-form/element-form/components/radio/package.json +17 -0
  55. package/package-form/element-form/components/radio/src/component.jsx +101 -0
  56. package/package-form/element-form/components/radio/src/index.js +3 -0
  57. package/package-form/element-form/components/select/package.json +17 -0
  58. package/package-form/element-form/components/select/src/component.jsx +52 -0
  59. package/package-form/element-form/components/select/src/index.js +3 -0
  60. package/package-form/element-form/components/subform/package.json +14 -0
  61. package/package-form/element-form/components/subform/src/component.jsx +76 -0
  62. package/package-form/element-form/components/subform/src/index.js +3 -0
  63. package/package-form/element-form/components/tree/package.json +17 -0
  64. package/package-form/element-form/components/tree/src/component.jsx +62 -0
  65. package/package-form/element-form/components/tree/src/index.js +3 -0
  66. package/package-form/element-form/components/upload/package.json +17 -0
  67. package/package-form/element-form/components/upload/src/IconUpload.vue +12 -0
  68. package/package-form/element-form/components/upload/src/component.jsx +129 -0
  69. package/package-form/element-form/components/upload/src/index.js +3 -0
  70. package/package-form/element-form/components/upload/src/style.css +11 -0
  71. package/package-form/element-form/index.js +8 -0
  72. package/package-form/element-form/package.json +16 -0
  73. package/package-form/element-form/src/components/icon/IconWarning.vue +12 -0
  74. package/package-form/element-form/src/components/index.js +22 -0
  75. package/package-form/element-form/src/core/alias.js +34 -0
  76. package/package-form/element-form/src/core/api.js +208 -0
  77. package/package-form/element-form/src/core/config.js +62 -0
  78. package/package-form/element-form/src/core/index.js +60 -0
  79. package/package-form/element-form/src/core/maker.js +76 -0
  80. package/package-form/element-form/src/core/manager.js +315 -0
  81. package/package-form/element-form/src/core/provider.js +79 -0
  82. package/package-form/element-form/src/parsers/datePicker.js +31 -0
  83. package/package-form/element-form/src/parsers/hidden.js +12 -0
  84. package/package-form/element-form/src/parsers/index.js +17 -0
  85. package/package-form/element-form/src/parsers/input.js +21 -0
  86. package/package-form/element-form/src/parsers/row.js +10 -0
  87. package/package-form/element-form/src/parsers/select.js +15 -0
  88. package/package-form/element-form/src/parsers/slider.js +21 -0
  89. package/package-form/element-form/src/parsers/timePicker.js +17 -0
  90. package/package-form/element-form/src/style/index.css +52 -0
  91. package/package.json +17 -0
  92. package/src/App.vue +28 -0
  93. package/src/assets/css/element.scss +179 -0
  94. package/src/assets/css/layout.scss +215 -0
  95. package/src/assets/css/tailwind.scss +67 -0
  96. package/src/assets/images/banner.gif +0 -0
  97. package/src/assets/images/banner.png +0 -0
  98. package/src/assets/images/bg1.svg +22 -0
  99. package/src/assets/images/bg2.png +0 -0
  100. package/src/assets/images/ff.png +0 -0
  101. package/src/assets/images/home-file1.png +0 -0
  102. package/src/assets/images/ky.png +0 -0
  103. package/src/assets/images/menu/add.png +0 -0
  104. package/src/assets/images/menu/del.png +0 -0
  105. package/src/assets/images/menu/down.png +0 -0
  106. package/src/assets/images/menu/dr.png +0 -0
  107. package/src/assets/images/menu/edit.png +0 -0
  108. package/src/assets/images/menu/kx.png +0 -0
  109. package/src/assets/images/menu/mb.png +0 -0
  110. package/src/assets/images/menu/pz.png +0 -0
  111. package/src/assets/images/menu/save.png +0 -0
  112. package/src/assets/images/menu/sj.png +0 -0
  113. package/src/assets/images/menu/sjk.png +0 -0
  114. package/src/assets/images/menu/up.png +0 -0
  115. package/src/assets/images/po-i.png +0 -0
  116. package/src/assets/images/po1-i1.png +0 -0
  117. package/src/assets/images/po1-i2.png +0 -0
  118. package/src/assets/images/po1-i3.png +0 -0
  119. package/src/assets/images/po1-i4.png +0 -0
  120. package/src/assets/images/po1-i5.png +0 -0
  121. package/src/assets/images/po1-i6.png +0 -0
  122. package/src/assets/images/po1-i7.png +0 -0
  123. package/src/assets/images/po1-i8.png +0 -0
  124. package/src/assets/images/po2-i1.png +0 -0
  125. package/src/assets/images/po2-i2.png +0 -0
  126. package/src/assets/images/po3-i1.png +0 -0
  127. package/src/assets/images/po4-i1.png +0 -0
  128. package/src/assets/images/po5-i1.png +0 -0
  129. package/src/assets/images/po6-i1.png +0 -0
  130. package/src/assets/images/po6-i2.png +0 -0
  131. package/src/assets/images/po7-i1.png +0 -0
  132. package/src/assets/images/tj1.png +0 -0
  133. package/src/assets/images/tj2.png +0 -0
  134. package/src/assets/images/tj3.png +0 -0
  135. package/src/components/3dcloudwords/index.js +346 -0
  136. package/src/components/3dcloudwords/index.vue +99 -0
  137. package/src/components/3dcloudwords/readme.md +66 -0
  138. package/src/components/badge/index.js +167 -0
  139. package/src/components/badge/index.scss +166 -0
  140. package/src/components/badge/index.vue +98 -0
  141. package/src/components/badge/readme.md +18 -0
  142. package/src/components/basic/Finish.vue +107 -0
  143. package/src/components/basic/button.vue +19 -0
  144. package/src/components/basic/readme.md +7 -0
  145. package/src/components/button/index.vue +48 -0
  146. package/src/components/button/readme.md +62 -0
  147. package/src/components/carousel/index.vue +104 -0
  148. package/src/components/carousel/readme.md +12 -0
  149. package/src/components/chartconfig/index.vue +141 -0
  150. package/src/components/chartconfig/readme.md +25 -0
  151. package/src/components/contextMenu/hookContxtMenu.js +41 -0
  152. package/src/components/contextMenu/index.vue +245 -0
  153. package/src/components/contextMenu/readme.md +55 -0
  154. package/src/components/contextMenu/useElementBounding.js +40 -0
  155. package/src/components/countup/countUp.js +196 -0
  156. package/src/components/countup/index.vue +112 -0
  157. package/src/components/countup/readme.md +9 -0
  158. package/src/components/empty/assets/build.png +0 -0
  159. package/src/components/empty/assets/emptybg.gif +0 -0
  160. package/src/components/empty/assets/emptybg.png +0 -0
  161. package/src/components/empty/assets/emptybg2.jpg +0 -0
  162. package/src/components/empty/assets/emptybg3.jpg +0 -0
  163. package/src/components/empty/assets/wuxiao.png +0 -0
  164. package/src/components/empty/assets/wuxiao.webp +0 -0
  165. package/src/components/empty/building.vue +117 -0
  166. package/src/components/empty/empty.vue +120 -0
  167. package/src/components/empty/index.js +12 -0
  168. package/src/components/empty/invalid.vue +56 -0
  169. package/src/components/error/Error.vue +79 -0
  170. package/src/components/error/readme.md +20 -0
  171. package/src/components/form/Form.vue +84 -0
  172. package/src/components/form/FormItem.vue +143 -0
  173. package/src/components/form/data.js +52 -0
  174. package/src/components/form/readme.md +69 -0
  175. package/src/components/layout/banner.vue +412 -0
  176. package/src/components/layout/bar.vue +43 -0
  177. package/src/components/layout/layout1.vue +60 -0
  178. package/src/components/layout/layout2.vue +134 -0
  179. package/src/components/layout/layout3.vue +107 -0
  180. package/src/components/layout/layout4.vue +66 -0
  181. package/src/components/layout/nav.vue +333 -0
  182. package/src/components/layout/readme.md +61 -0
  183. package/src/components/loading/index.vue +122 -0
  184. package/src/components/loading/readme.md +6 -0
  185. package/src/components/notice/NoticeList.vue +198 -0
  186. package/src/components/notice/NoticeListPaging.vue +281 -0
  187. package/src/components/notice/NoticeView.vue +92 -0
  188. package/src/components/notice/readme.md +1 -0
  189. package/src/components/pagination/index.vue +100 -0
  190. package/src/components/pagination/readme.md +19 -0
  191. package/src/components/pagination/scroll-to.js +51 -0
  192. package/src/components/progress/bar.vue +72 -0
  193. package/src/components/progress/progress.vue +58 -0
  194. package/src/components/screenfull/index.js +3 -0
  195. package/src/components/screenfull/index.vue +65 -0
  196. package/src/components/screenfull/package.json +15 -0
  197. package/src/components/screenfull/readme.md +6 -0
  198. package/src/components/statisticalCount/index.vue +80 -0
  199. package/src/components/statisticalCount/readme.md +21 -0
  200. package/src/components/username/index.vue +79 -0
  201. package/src/components/username/readme.md +22 -0
  202. package/src/components/username//346/225/210/346/236/234/345/233/276.png +0 -0
  203. package/src/index.js +82 -0
  204. package/src/utils/index.js +32 -0
  205. package/src/xm_components/HeadSearch/hook/hookSearch.js +96 -0
  206. package/src/xm_components/HeadSearch/index.vue +206 -0
  207. package/src/xm_components/HeadSearch/readme.md +12 -0
  208. package/src/xm_components/HeadSearch//346/220/234/347/264/242/345/210/227/350/241/250.png +0 -0
  209. package/src/xm_components/Milestone/index.vue +212 -0
  210. package/src/xm_components/Milestone/readme.md +15 -0
  211. package/src/xm_components/readme.md +1 -0
  212. package/utils/coms/load.jsx +10 -0
  213. package/utils/func.js +32 -0
  214. package/utils/hookDialog.js +38 -0
  215. package/utils/hookPage.js +49 -0
  216. package/utils/index.js +5 -0
  217. package/utils/lib/console.js +39 -0
  218. package/utils/lib/debounce.js +19 -0
  219. package/utils/lib/deepextend.js +51 -0
  220. package/utils/lib/deepset.js +14 -0
  221. package/utils/lib/extend.js +28 -0
  222. package/utils/lib/index.js +13 -0
  223. package/utils/lib/json.js +90 -0
  224. package/utils/lib/mergeprops.js +62 -0
  225. package/utils/lib/mitt.js +43 -0
  226. package/utils/lib/modify.js +8 -0
  227. package/utils/lib/slot.js +19 -0
  228. package/utils/lib/toarray.js +5 -0
  229. package/utils/lib/tocase.js +11 -0
  230. package/utils/lib/todate.js +10 -0
  231. package/utils/lib/toline.js +10 -0
  232. package/utils/lib/tostring.js +7 -0
  233. package/utils/lib/type.js +45 -0
  234. package/utils/lib/unique.js +6 -0
  235. package/utils/message.js +166 -0
  236. package/utils/package.json +16 -0
  237. package/utils/type.js +45 -0
  238. package/vite.config.js +51 -0
@@ -0,0 +1,288 @@
1
+ import {err} from '@bdsoft-element/utils/lib/console';
2
+ import {byCtx, deepGet, invoke, parseFn} from './util';
3
+ import is, {hasProperty} from '@bdsoft-element/utils/lib/type';
4
+ import deepSet from '@bdsoft-element/utils/lib/deepset';
5
+ import {deepCopy} from '@bdsoft-element/utils/lib/deepextend';
6
+ import toArray from '@bdsoft-element/utils/lib/toarray';
7
+ import debounce from '@bdsoft-element/utils/lib/debounce';
8
+
9
+ const loadData = function (fc) {
10
+ const loadData = {
11
+ name: 'loadData',
12
+ _fn: [],
13
+ loaded(inject, rule, api) {
14
+ this.deleted(inject);
15
+ let attrs = toArray(inject.getValue());
16
+ const unwatchs = [];
17
+ attrs.forEach(attr => {
18
+ if (attr && (attr.attr || attr.template)) {
19
+ let fn = (get) => {
20
+ let value;
21
+ if (attr.template) {
22
+ value = fc.$handle.loadStrVar(attr.template, get);
23
+ } else if (attr.handler && is.Function(attr.handler)) {
24
+ value = attr.handler(get, rule, api);
25
+ } else {
26
+ value = get(attr.attr, attr.default);
27
+ }
28
+ if (attr.copy !== false) {
29
+ value = deepCopy(value)
30
+ }
31
+ const _rule = (attr.modify ? rule : inject.getProp());
32
+ if (attr.to === 'child') {
33
+ if (_rule.children) {
34
+ _rule.children[0] = value;
35
+ } else {
36
+ _rule.children = [value];
37
+ }
38
+ } else {
39
+ deepSet(_rule, attr.to || 'options', value);
40
+ }
41
+ api.sync(rule);
42
+ };
43
+ let callback = (get) => fn(get);
44
+ const unwatch = fc.watchLoadData(callback);
45
+ fn = debounce(fn, attr.wait || 300)
46
+ if (attr.watch !== false) {
47
+ unwatchs.push(unwatch);
48
+ } else {
49
+ unwatch();
50
+ }
51
+ }
52
+ })
53
+ this._fn[inject.id] = unwatchs;
54
+ },
55
+ deleted(inject) {
56
+ if (this._fn[inject.id]) {
57
+ this._fn[inject.id].forEach(un => {
58
+ un();
59
+ })
60
+ delete this._fn[inject.id];
61
+ }
62
+ inject.clearProp();
63
+ },
64
+ };
65
+ loadData.watch = loadData.mounted;
66
+ return loadData;
67
+ }
68
+
69
+ const t = function (fc) {
70
+ const t = {
71
+ name: 't',
72
+ _fn: [],
73
+ loaded(inject, rule, api) {
74
+ this.deleted(inject);
75
+ let attrs = inject.getValue() || {};
76
+ const unwatchs = [];
77
+ Object.keys(attrs).forEach(key => {
78
+ const attr = attrs[key];
79
+ if (attr) {
80
+ const isObj = typeof attr === 'object';
81
+ let fn = (get) => {
82
+ let value = fc.t(isObj ? attr.attr : attr, isObj ? attr.params : null, get);
83
+ const _rule = ((isObj && attr.modify) ? rule : inject.getProp());
84
+ if (key === 'child') {
85
+ if (_rule.children) {
86
+ _rule.children[0] = value;
87
+ } else {
88
+ _rule.children = [value];
89
+ }
90
+ } else {
91
+ deepSet(_rule, key, value);
92
+ }
93
+ api.sync(rule);
94
+ };
95
+ let callback = (get) => fn(get);
96
+ const unwatch = fc.watchLoadData(callback);
97
+ fn = debounce(fn, attr.wait || 300)
98
+ if (attr.watch !== false) {
99
+ unwatchs.push(unwatch);
100
+ } else {
101
+ unwatch();
102
+ }
103
+ }
104
+ })
105
+ this._fn[inject.id] = unwatchs;
106
+ },
107
+ deleted(inject) {
108
+ if (this._fn[inject.id]) {
109
+ this._fn[inject.id].forEach(un => {
110
+ un();
111
+ })
112
+ delete this._fn[inject.id];
113
+ }
114
+ inject.clearProp();
115
+ },
116
+ };
117
+ t.watch = t.loaded;
118
+ return t;
119
+ }
120
+
121
+ const componentValidate = {
122
+ name: 'componentValidate',
123
+ load(attr, rule, api) {
124
+ let options = attr.getValue();
125
+ if (!options || options.method === false) {
126
+ attr.clearProp();
127
+ api.clearValidateState([rule.field]);
128
+ } else {
129
+ if (!is.Object(options)) {
130
+ options = {method: options};
131
+ }
132
+ const method = options.method;
133
+ delete options.method;
134
+ attr.getProp().validate = [{
135
+ ...options,
136
+ validator(...args) {
137
+ const ctx = byCtx(rule);
138
+ if (ctx) {
139
+ return api.exec(ctx.id, is.String(method) ? method : 'formCreateValidate', ...args, {
140
+ attr,
141
+ rule,
142
+ api
143
+ });
144
+ }
145
+ }
146
+ }];
147
+ }
148
+ },
149
+ watch(...args) {
150
+ componentValidate.load(...args);
151
+ }
152
+ };
153
+
154
+
155
+ const fetch = function (fc) {
156
+
157
+ function parseOpt(option) {
158
+ if (is.String(option)) {
159
+ option = {
160
+ action: option,
161
+ to: 'options'
162
+ }
163
+ }
164
+ return option;
165
+ }
166
+
167
+ function run(inject, rule, api) {
168
+ let option = inject.value;
169
+ fetchAttr.deleted(inject);
170
+ if (is.Function(option)) {
171
+ option = option(rule, api);
172
+ }
173
+ option = parseOpt(option);
174
+
175
+ const set = (val) => {
176
+ if (val === undefined) {
177
+ inject.clearProp();
178
+ } else {
179
+ deepSet(inject.getProp(), option.to || 'options', val);
180
+ }
181
+ if (val != null && option && option.key && fc.$handle.options.globalData[option.key]) {
182
+ fc.fetchCache.set(fc.$handle.options.globalData[option.key], {status: true, data: val});
183
+ }
184
+ api.sync(rule);
185
+ }
186
+
187
+ if (!option || (!option.action && !option.key)) {
188
+ set(undefined);
189
+ return;
190
+ }
191
+ option = deepCopy(option);
192
+ if (!option.to) {
193
+ option.to = 'options';
194
+ }
195
+
196
+ if (option.key) {
197
+ const item = fc.$handle.options.globalData[option.key];
198
+ if (!item) {
199
+ set(undefined);
200
+ return;
201
+ }
202
+ if (item.type === 'static') {
203
+ set(item.data);
204
+ return;
205
+ } else {
206
+ option = {...option, ...item}
207
+ }
208
+ }
209
+
210
+ const onError = option.onError;
211
+
212
+ const check = () => {
213
+ if (!inject.getValue()) {
214
+ inject.clearProp();
215
+ api.sync(rule);
216
+ return true;
217
+ }
218
+ }
219
+ fetchAttr._fn[inject.id] = fc.watchLoadData(debounce((get, change) => {
220
+ if (change && option.watch === false) {
221
+ return fetchAttr._fn[inject.id]();
222
+ }
223
+ const _option = fc.$handle.loadFetchVar(deepCopy(option), get);
224
+ const config = {
225
+ headers: {},
226
+ ..._option,
227
+ onSuccess(body, flag) {
228
+ if (check()) return;
229
+ let fn = (v) => flag ? v : (hasProperty(v, 'data') ? v.data : v);
230
+ const parse = parseFn(_option.parse);
231
+ if (is.Function(parse)) {
232
+ fn = parse;
233
+ } else if (parse && is.String(parse)) {
234
+ fn = (v) => {
235
+ return deepGet(v, parse);
236
+ }
237
+ }
238
+ set(fn(body, rule, api));
239
+ api.sync(rule);
240
+ },
241
+ onError(e) {
242
+ set(undefined);
243
+ if (check()) return;
244
+ (onError || ((e) => err(e.message || 'fetch fail ' + _option.action)))(e, rule, api);
245
+ }
246
+ };
247
+ fc.$handle.beforeFetch(config, {rule, api}).then(() => {
248
+ if (is.Function(_option.action)) {
249
+ _option.action(rule, api).then((val) => {
250
+ config.onSuccess(val, true);
251
+ }).catch((e) => {
252
+ config.onError(e);
253
+ });
254
+ return;
255
+ }
256
+ invoke(() => fc.create.fetch(config, {inject, rule, api}));
257
+ });
258
+ }, option.wait || 600));
259
+ }
260
+
261
+ const fetchAttr = {
262
+ name: 'fetch',
263
+ _fn: [],
264
+ loaded(...args) {
265
+ run(...args);
266
+ },
267
+ watch(...args) {
268
+ run(...args);
269
+ },
270
+ deleted(inject) {
271
+ if (this._fn[inject.id]) {
272
+ this._fn[inject.id]();
273
+ delete this._fn[inject.id];
274
+ }
275
+ inject.clearProp();
276
+ },
277
+ };
278
+
279
+ return fetchAttr;
280
+ }
281
+
282
+
283
+ export default {
284
+ fetch,
285
+ loadData,
286
+ t,
287
+ componentValidate,
288
+ };
@@ -0,0 +1,274 @@
1
+ import deepExtend from '@bdsoft-element/utils/lib/deepextend';
2
+ import is from '@bdsoft-element/utils/lib/type';
3
+ import mergeProps from '@bdsoft-element/utils/lib/mergeprops';
4
+ import {arrayAttrs, normalAttrs} from './attrs';
5
+ import {logError} from '@bdsoft-element/utils/lib/console';
6
+ import {isVNode} from 'vue';
7
+ import {upper} from '@bdsoft-element/utils/lib/toline';
8
+ import toCase from '@bdsoft-element/utils/lib/tocase';
9
+
10
+ export {parseJson, parseFn, toJson} from '@bdsoft-element/utils/lib/json';
11
+
12
+ export function enumerable(value, writable) {
13
+ return {
14
+ value,
15
+ enumerable: false,
16
+ configurable: false,
17
+ writable: !!writable
18
+ }
19
+ }
20
+
21
+ //todo 优化位置
22
+ export function copyRule(rule, mode) {
23
+ return copyRules([rule], mode || false)[0];
24
+ }
25
+
26
+ export function copyRules(rules, mode) {
27
+ return deepExtend([], [...rules], mode || false);
28
+ }
29
+
30
+ export function mergeRule(rule, merge) {
31
+ mergeProps(Array.isArray(merge) ? merge : [merge], rule, {array: arrayAttrs, normal: normalAttrs});
32
+ return rule;
33
+ }
34
+
35
+ export function getRule(rule) {
36
+ const r = is.Function(rule.getRule) ? rule.getRule() : rule;
37
+ if (!r.type) {
38
+ r.type = 'input';
39
+ }
40
+ return r;
41
+ }
42
+
43
+ export function mergeGlobal(target, merge) {
44
+ if (!target) return merge;
45
+ Object.keys(merge || {}).forEach((k) => {
46
+ if (merge[k]) {
47
+ target[k] = mergeRule(target[k] || {}, merge[k])
48
+ }
49
+ });
50
+ return target;
51
+ }
52
+
53
+ export function funcProxy(that, proxy) {
54
+ Object.defineProperties(that, Object.keys(proxy).reduce((initial, k) => {
55
+ initial[k] = {
56
+ get() {
57
+ return proxy[k]();
58
+ }
59
+ }
60
+ return initial;
61
+ }, {}))
62
+ }
63
+
64
+ export function byCtx(rule) {
65
+ return rule.__fc__ || (rule.__origin__ ? rule.__origin__.__fc__ : null)
66
+ }
67
+
68
+ /**
69
+ * 执行一个函数并捕获可能的错误
70
+ * @param {Function} fn - 要执行的函数
71
+ * @param {any} def - 如果函数执行过程中抛出错误,返回的默认值
72
+ * @returns {any} - 函数执行的结果,如果发生错误则返回默认值
73
+ */
74
+ export function invoke(fn, def) {
75
+ try {
76
+ // 尝试执行传入的函数,并将结果赋值给 def
77
+ def = fn()
78
+ } catch (e) {
79
+ // 如果执行过程中抛出错误,使用 logError 函数记录错误信息
80
+ logError(e);
81
+ }
82
+ // 返回函数执行结果或默认值
83
+ return def;
84
+ }
85
+
86
+
87
+
88
+ export function makeSlotBag() {
89
+ const slotBag = {};
90
+
91
+ const slotName = (n) => n || 'default';
92
+
93
+ return {
94
+ setSlot(slot, vnFn) {
95
+ slot = slotName(slot);
96
+ if (!vnFn || (Array.isArray(vnFn) && vnFn.length))
97
+ return;
98
+ if (!slotBag[slot]) slotBag[slot] = [];
99
+ slotBag[slot].push(vnFn);
100
+ },
101
+ getSlot(slot, val) {
102
+ slot = slotName(slot);
103
+ const children = [];
104
+ (slotBag[slot] || []).forEach(fn => {
105
+ if (Array.isArray(fn)) {
106
+ children.push(...fn);
107
+ } else if (is.Function(fn)) {
108
+ const res = fn(...(val || []));
109
+ if (Array.isArray(res)) {
110
+ children.push(...res);
111
+ } else {
112
+ children.push(res);
113
+ }
114
+ } else if (!is.Undef(fn)) {
115
+ children.push(fn);
116
+ }
117
+ })
118
+ return children;
119
+ },
120
+ getSlots() {
121
+ const slots = {};
122
+ Object.keys(slotBag).forEach(k => {
123
+ slots[k] = (...args) => {
124
+ return this.getSlot(k, args);
125
+ }
126
+ })
127
+ return slots
128
+ },
129
+ slotLen(slot) {
130
+ slot = slotName(slot);
131
+ return slotBag[slot] ? slotBag[slot].length : 0;
132
+ },
133
+ mergeBag(bag) {
134
+ if (!bag) return this;
135
+ const slots = is.Function(bag.getSlots) ? bag.getSlots() : bag;
136
+ if (Array.isArray(bag) || isVNode(bag)) {
137
+ this.setSlot(undefined, () => bag);
138
+ } else {
139
+ Object.keys(slots).forEach(k => {
140
+ this.setSlot(k, slots[k]);
141
+ });
142
+ }
143
+
144
+ return this;
145
+ }
146
+ };
147
+ }
148
+
149
+ export function toProps(rule) {
150
+ const prop = {...(rule.props || {})};
151
+
152
+ Object.keys(rule.on || {}).forEach(k => {
153
+ if(k.indexOf('-') > 0) {
154
+ k = toCase(k);
155
+ }
156
+ const name = `on${upper(k)}`;
157
+ if (Array.isArray(prop[name])) {
158
+ prop[name] = [...prop[name], rule.on[k]];
159
+ } else if (prop[name]) {
160
+ prop[name] = [prop[name], rule.on[k]];
161
+ } else {
162
+ prop[name] = rule.on[k];
163
+ }
164
+ })
165
+ prop.key = rule.key;
166
+ prop.ref = rule.ref;
167
+ prop.class = rule.class;
168
+ prop.id = rule.id;
169
+ prop.style = rule.style;
170
+ if (prop.slot) delete prop.slot;
171
+
172
+ return prop;
173
+ }
174
+
175
+ export function setPrototypeOf(o, proto) {
176
+ Object.setPrototypeOf(o, proto);
177
+ return o;
178
+ }
179
+
180
+
181
+ const changeType = (a, b) => {
182
+ if (typeof a === 'string') {
183
+ return String(b);
184
+ } else if (typeof a === 'number') {
185
+ return Number(b);
186
+ }
187
+ return b;
188
+ }
189
+
190
+ export const condition = {
191
+ '==': (a, b) => {
192
+ return JSON.stringify(a) === JSON.stringify(changeType(a, b));
193
+ },
194
+ '!=': (a, b) => {
195
+ return !condition['=='](a, b);
196
+ },
197
+ '>': (a, b) => {
198
+ return a > b;
199
+ },
200
+ '>=': (a, b) => {
201
+ return a >= b;
202
+ },
203
+ '<': (a, b) => {
204
+ return a < b;
205
+ },
206
+ '<=': (a, b) => {
207
+ return a <= b;
208
+ },
209
+ on(a, b) {
210
+ return a && a.indexOf && a.indexOf(changeType(a[0], b)) > -1;
211
+ },
212
+ notOn(a, b) {
213
+ return !condition.on(a, b);
214
+ },
215
+ in(a, b) {
216
+ return b && b.indexOf && b.indexOf(a) > -1;
217
+ },
218
+ notIn(a, b) {
219
+ return !condition.in(a, b);
220
+ },
221
+ between(a, b) {
222
+ return a > b[0] && a < b[1];
223
+ },
224
+ notBetween(a, b) {
225
+ return a < b[0] || a > b[1];
226
+ },
227
+ empty(a) {
228
+ return is.empty(a);
229
+ },
230
+ notEmpty(a) {
231
+ return !is.empty(a);
232
+ },
233
+ pattern(a, b) {
234
+ return new RegExp(b, 'g').test(a);
235
+ }
236
+ };
237
+
238
+ export function deepGet(val, split) {
239
+ (Array.isArray(split) ? split : (split || '').split('.')).forEach(k => {
240
+ if (val != null) {
241
+ val = val[k];
242
+ }
243
+ });
244
+ return val;
245
+ }
246
+
247
+ export function extractVar(str) {
248
+ const regex = /{{\s*(.*?)\s*}}/g;
249
+ let match;
250
+ const matches = {};
251
+ while ((match = regex.exec(str)) !== null) {
252
+ if (match[1]) {
253
+ matches[match[1]] = true;
254
+ }
255
+ }
256
+ return Object.keys(matches);
257
+ }
258
+
259
+ export function convertFieldToConditions(field) {
260
+ let parts = field.split('.');
261
+ let conditions = [];
262
+ let currentCondition = '';
263
+
264
+ parts.forEach((part, index) => {
265
+ if (index === 0) {
266
+ currentCondition = part;
267
+ } else {
268
+ currentCondition += '.' + part;
269
+ }
270
+ conditions.push(currentCondition);
271
+ });
272
+
273
+ return conditions.join(' && ');
274
+ }