@skyfox2000/webui 1.3.0 → 1.3.2

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 (28) hide show
  1. package/lib/assets/modules/{file-upload-C4GVmWjB.js → file-upload-BVB9c-eZ.js} +1 -1
  2. package/lib/assets/modules/{form-excel-Cr2hcL1s.js → form-excel-CsQBtfkA.js} +1 -1
  3. package/lib/assets/modules/{index-DjBruVH-.js → index-CaaMz5sz.js} +1 -1
  4. package/lib/assets/modules/{index-D5onbqkl.js → index-k_AnrbPY.js} +2 -2
  5. package/lib/assets/modules/{menuTabs-B9fCWfN1.js → menuTabs-_Ph7P8ES.js} +2 -2
  6. package/lib/assets/modules/{toolIcon-DKTf30Tq.js → toolIcon-QMXCkImG.js} +1 -1
  7. package/lib/assets/modules/{uploadList-D2lisNHt.js → uploadList-CXa3siDj.js} +4 -4
  8. package/lib/assets/modules/{uploadList-CY57np42.js → uploadList-D-FOtndj.js} +370 -366
  9. package/lib/es/AceEditor/index.js +3 -3
  10. package/lib/es/BasicLayout/index.js +3 -3
  11. package/lib/es/Error403/index.js +1 -1
  12. package/lib/es/Error404/index.js +1 -1
  13. package/lib/es/ExcelForm/index.js +4 -4
  14. package/lib/es/UploadForm/index.js +4 -4
  15. package/lib/typings/option.d.ts +9 -8
  16. package/lib/utils/options.d.ts +1 -1
  17. package/lib/webui.css +1 -1
  18. package/lib/webui.es.js +99 -99
  19. package/package.json +1 -1
  20. package/src/components/form/autoComplete/index.vue +1 -1
  21. package/src/components/form/cascader/index.vue +1 -1
  22. package/src/components/form/checkbox/index.vue +1 -1
  23. package/src/components/form/radio/index.vue +1 -1
  24. package/src/components/form/select/index.vue +1 -9
  25. package/src/components/form/switch/index.vue +1 -1
  26. package/src/typings/option.d.ts +9 -8
  27. package/src/utils/options.ts +16 -26
  28. package/src/utils/page.ts +43 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyfox2000/webui",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "后台前端通用组件定义",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -134,7 +134,7 @@ const onSearch = (value: string) => {
134
134
  props.onsearch(search_value, query);
135
135
  }
136
136
 
137
- if (optionCtrl) loadOption(optionCtrl, props);
137
+ if (optionCtrl) loadOption(optionCtrl.autoload, optionCtrl, props);
138
138
  };
139
139
 
140
140
  const onSelected = (value: any) => {
@@ -93,7 +93,7 @@ onMounted(() => {
93
93
  key: 'Id',
94
94
  };
95
95
  }
96
- if (optionCtrl) loadOption(optionCtrl, props);
96
+ if (optionCtrl) loadOption(optionCtrl.autoload, optionCtrl, props);
97
97
  });
98
98
 
99
99
  onUnmounted(() => {
@@ -84,7 +84,7 @@ onMounted(() => {
84
84
  key: 'Id',
85
85
  };
86
86
  }
87
- if (optionCtrl) loadOption(optionCtrl, props);
87
+ if (optionCtrl) loadOption(optionCtrl.autoload, optionCtrl, props);
88
88
  });
89
89
  onUnmounted(() => {
90
90
  if (optionCtrl) unloadOption(optionCtrl, props);
@@ -102,7 +102,7 @@ onMounted(() => {
102
102
  key: 'Id',
103
103
  };
104
104
  }
105
- if (optionCtrl) loadOption(optionCtrl, props);
105
+ if (optionCtrl) loadOption(optionCtrl.autoload, optionCtrl, props);
106
106
  });
107
107
  onUnmounted(() => {
108
108
  if (optionCtrl) unloadOption(optionCtrl, props);
@@ -135,14 +135,6 @@ watch(
135
135
  },
136
136
  );
137
137
 
138
- // watch(
139
- // () => props.params,
140
- // (newVal) => {
141
- // loadOption(true, props, selectOptions, inputFactory, url.value, newVal);
142
- // },
143
- // { deep: true },
144
- // );
145
-
146
138
  onMounted(() => {
147
139
  if (url.value && !url.value.fieldMap) {
148
140
  url.value.fieldMap = {
@@ -154,7 +146,7 @@ onMounted(() => {
154
146
  if (props.dataKey) {
155
147
  const options = JSON.parse(JSON.stringify(OPTIONS.getOptions(props.dataKey)));
156
148
  selectOptions.value = options;
157
- } else if (optionCtrl) loadOption(optionCtrl, props);
149
+ } else if (optionCtrl) loadOption(optionCtrl.autoload, optionCtrl, props);
158
150
  });
159
151
 
160
152
  onUnmounted(() => {
@@ -55,7 +55,7 @@ onMounted(() => {
55
55
  message.error('Switch组件必须有且只有两个选项');
56
56
  return;
57
57
  }
58
- if (optionCtrl) loadOption(optionCtrl, props);
58
+ if (optionCtrl) loadOption(optionCtrl.autoload, optionCtrl, props);
59
59
  });
60
60
 
61
61
  onUnmounted(() => {
@@ -154,6 +154,12 @@ export type OptionControlOption = {
154
154
  * 自动加载数据
155
155
  */
156
156
  autoload: boolean;
157
+ /**
158
+ * 字段转换控制
159
+ * - Key:目的字段
160
+ * - Value:源字段,支持模板 ${}
161
+ */
162
+ fieldMap?: Record<string, string>;
157
163
  };
158
164
 
159
165
  /**
@@ -173,11 +179,12 @@ export type OptionControl = OptionControlOption & {
173
179
  */
174
180
  optionQuery?: ReqParams;
175
181
  /**
176
- * 当前数据
182
+ * 当前传入数据
177
183
  */
178
184
  data: ShallowRef<OptionItemProps[] | undefined>;
179
185
  /**
180
- * 选项数据
186
+ * 实际选项数据
187
+ * - 已转换fieldMap
181
188
  */
182
189
  options: Ref<OptionItemProps[]>;
183
190
  /**
@@ -188,12 +195,6 @@ export type OptionControl = OptionControlOption & {
188
195
  * 选中数据
189
196
  */
190
197
  selectedOptions: Ref<OptionItemProps[]>;
191
- /**
192
- * 字段转换控制
193
- * - Key:目的字段
194
- * - Value:源字段,支持模板 ${}
195
- */
196
- fieldMap?: Record<string, string>;
197
198
  /**
198
199
  * 查询接口
199
200
  * - 优先使用
@@ -8,7 +8,7 @@ import {
8
8
  ReqParams,
9
9
  ResStatus,
10
10
  } from '@skyfox2000/fapi';
11
- import { inject, ref, Ref, watch } from 'vue';
11
+ import { inject, ref, watch } from 'vue';
12
12
  import { OptionItemProps, SelectValue, OptionControl, OptionProps } from '@/typings/option.d';
13
13
  import { ProviderKeys } from '@/typings/page.d';
14
14
  import message from 'vue-m-message';
@@ -20,12 +20,12 @@ import { combineParams } from '@skyfox2000/microbase';
20
20
  * 自动初始化选择项
21
21
  * @param optionCtrl 选项控制器
22
22
  */
23
- export const loadOption = (optionCtrl: OptionControl, props?: OptionProps) => {
23
+ export const loadOption = (load: boolean, optionCtrl: OptionControl, props?: OptionProps) => {
24
24
  if (optionCtrl.inputFactory && props?.reloadEvent) {
25
25
  const inputFactory = optionCtrl.inputFactory.value;
26
26
  /// 接收事件,联动显示或者重新加载数据
27
27
  inputFactory.reloadHandler = (_event: string, params: Record<string, AnyData> | AnyData[]) => {
28
- optionEventHandler(optionCtrl.url!, optionCtrl, params, optionCtrl.options);
28
+ optionEventHandler(optionCtrl.url!, optionCtrl, params);
29
29
  };
30
30
  eventBus.on(props.reloadEvent, inputFactory.reloadHandler);
31
31
  }
@@ -35,13 +35,12 @@ export const loadOption = (optionCtrl: OptionControl, props?: OptionProps) => {
35
35
  watch(
36
36
  () => props.data,
37
37
  () => {
38
- updateOptions(optionCtrl, props.data!, optionCtrl.options, true);
38
+ updateOptions(optionCtrl, props.data!, true);
39
39
  },
40
40
  { deep: true, immediate: true },
41
41
  );
42
42
  } else if (optionCtrl.url && optionCtrl.url.url) {
43
- if (optionCtrl.autoload !== false)
44
- doQueryOptions(optionCtrl.url, optionCtrl, optionCtrl.params ?? {}, optionCtrl.options);
43
+ if (load) doQueryOptions(optionCtrl.url, optionCtrl, optionCtrl.params ?? {});
45
44
  } else {
46
45
  const labelText = ref<string>(inject(ProviderKeys.LabelText, ''));
47
46
  message.error('`' + labelText.value + '` 未配置选项数据!', {
@@ -54,15 +53,9 @@ export const loadOption = (optionCtrl: OptionControl, props?: OptionProps) => {
54
53
  * 组件选项数据更新
55
54
  * @param optionCtrl 选项控制器
56
55
  * @param data 提供的下拉数据
57
- * @param options 实际选择项
58
56
  * @param mapping 是否需要转换字段
59
57
  */
60
- const updateOptions = (
61
- optionCtrl: OptionControl,
62
- data: Record<string, AnyData>[],
63
- options: Ref<OptionItemProps[]>,
64
- mapping: boolean,
65
- ) => {
58
+ const updateOptions = (optionCtrl: OptionControl, data: Record<string, AnyData>[], mapping: boolean) => {
66
59
  if (mapping) {
67
60
  // 转换字段
68
61
  const fieldMap = {
@@ -79,7 +72,7 @@ const updateOptions = (
79
72
  });
80
73
  }
81
74
 
82
- options.value = data as OptionItemProps[];
75
+ optionCtrl.options.value = data as OptionItemProps[];
83
76
  };
84
77
 
85
78
  /**
@@ -93,14 +86,13 @@ const optionEventHandler = (
93
86
  url: IUrlInfo,
94
87
  optionCtrl: OptionControl,
95
88
  params_data: Record<string, AnyData> | AnyData[],
96
- options: Ref<OptionItemProps[]>,
97
89
  ) => {
98
90
  if (Array.isArray(params_data)) {
99
91
  // 数据组仅用于联动显示
100
- updateOptions(optionCtrl, params_data, options, true);
92
+ updateOptions(optionCtrl, params_data, true);
101
93
  } else {
102
94
  // 其它情况使用Query参数
103
- doQueryOptions(url, optionCtrl, params_data, options);
95
+ doQueryOptions(url, optionCtrl, params_data);
104
96
  }
105
97
  };
106
98
 
@@ -118,21 +110,15 @@ export const unloadOption = (optionCtrl: OptionControl, props: OptionProps) => {
118
110
  * @param url 选项接口
119
111
  * @param optionCtrl 选项控制器
120
112
  * @param params 查询条件
121
- * @param options 实际选择项
122
113
  */
123
- const doQueryOptions = (
124
- url: IUrlInfo,
125
- optionCtrl: OptionControl,
126
- params: ReqParams,
127
- options: Ref<OptionItemProps[]>,
128
- ) => {
114
+ const doQueryOptions = (url: IUrlInfo, optionCtrl: OptionControl, params: ReqParams) => {
129
115
  const urlParams = JSON.parse(JSON.stringify(url.params ?? {}));
130
116
  const ctrlParams = JSON.parse(JSON.stringify(optionCtrl.params ?? {}));
131
117
  const newParams: ReqParams = combineParams(urlParams, ctrlParams, params);
132
118
  queryOptions(url, optionCtrl, optionCtrl.fieldMap, newParams).then((results) => {
133
119
  // 使用url,由request负责转换,无需再次map转换
134
120
  const data = results as OptionItemProps[];
135
- updateOptions(optionCtrl, data, options, false);
121
+ updateOptions(optionCtrl, data, false);
136
122
  });
137
123
  };
138
124
 
@@ -164,8 +150,8 @@ const queryOptions = <T>(
164
150
  url: '',
165
151
  cacheTime: 60000,
166
152
  fieldMap: {
167
- ...fieldMap,
168
153
  ...url.fieldMap,
154
+ ...fieldMap,
169
155
  },
170
156
  };
171
157
  const optionUrl = {
@@ -173,8 +159,10 @@ const queryOptions = <T>(
173
159
  ...rest,
174
160
  };
175
161
  optionUrl.loadingText = false;
162
+ console.log(optionUrl.fieldMap, params);
176
163
  if (!params) params = {};
177
164
  if (!params.Query) params.Query = {};
165
+ optionCtrl.optionQuery = params;
178
166
  optionCtrl.isOptionLoading.value = true;
179
167
  return httpPost<T>(optionUrl, params)
180
168
  .then((result: ApiResponse<T> | null) => {
@@ -284,9 +272,11 @@ export const onOptionChanged = (
284
272
  if (inputFactory?.editorCtrl && inputFactory.errInfo?.value.errClass) {
285
273
  formValidate(inputFactory.editorCtrl);
286
274
  }
275
+ optionCtrl.selected.value = values as undefined | string | number | string[] | number[];
287
276
 
288
277
  // 获取选中的选项对象或对象数组
289
278
  const selectedValues = getSelectedValues(values, optionCtrl.options.value);
279
+ optionCtrl.selectedOptions.value = selectedValues as OptionItemProps[];
290
280
 
291
281
  // 如果配置了 formData 和 outFields,将选中的其它属性值映射到 formData 上
292
282
  if (props.formData && props.outFields) {
package/src/utils/page.ts CHANGED
@@ -50,6 +50,10 @@ const defaultOptions: {
50
50
  all: false,
51
51
  allValue: [0, 1],
52
52
  autoload: true,
53
+ fieldMap: {
54
+ label: 'Name',
55
+ value: 'Id',
56
+ },
53
57
  },
54
58
  };
55
59
 
@@ -226,12 +230,12 @@ export const useOptionFactory = (url?: IUrlInfo, props?: OptionProps) => {
226
230
  const optionCtrl: OptionControl = {
227
231
  ...defaultOptions.OptionOption,
228
232
  url: url,
229
- options: ref([]),
230
233
  reload: ref(false),
234
+ optionQuery: {},
231
235
  data: shallowRef([]),
232
236
  selected: ref([]),
233
237
  selectedOptions: ref([]),
234
- optionQuery: {},
238
+ options: ref([]),
235
239
  isOptionLoading: ref(false),
236
240
  };
237
241
 
@@ -240,15 +244,50 @@ export const useOptionFactory = (url?: IUrlInfo, props?: OptionProps) => {
240
244
  () => optionCtrl.reload.value,
241
245
  (newVal) => {
242
246
  if (newVal) {
243
- // 使用 nextTick 或 setTimeout 延迟重置值
244
247
  setTimeout(() => {
245
248
  optionCtrl.reload.value = false;
246
249
  }, 1);
247
- loadOption(optionCtrl, props);
250
+ loadOption(true, optionCtrl, props);
248
251
  }
249
252
  },
250
253
  );
251
254
 
255
+ // // 为 optionCtrl 创建响应式的 params 监听
256
+ // // 使用 Proxy 来拦截 params 的设置,确保能够触发响应式更新
257
+ // const originalParams = optionCtrl.params;
258
+ // const paramsRef = ref(originalParams);
259
+
260
+ // // 使用 Object.defineProperty 来拦截 params 的赋值
261
+ // Object.defineProperty(optionCtrl, 'params', {
262
+ // get() {
263
+ // return paramsRef.value;
264
+ // },
265
+ // set(newParams) {
266
+ // paramsRef.value = newParams;
267
+ // },
268
+ // enumerable: true,
269
+ // configurable: true,
270
+ // });
271
+
272
+ // let isInitialized = false;
273
+
274
+ // // 监听params变化,自动重新加载数据
275
+ // watch(
276
+ // () => paramsRef.value,
277
+ // () => {
278
+ // if (!isInitialized) {
279
+ // isInitialized = true;
280
+ // return;
281
+ // }
282
+ // // 确保有URL且params存在时才自动重新加载
283
+ // // 避免重复加载,通过reload状态控制
284
+ // if (!optionCtrl.reload.value) {
285
+ // optionCtrl.reload.value = true;
286
+ // }
287
+ // },
288
+ // { deep: true },
289
+ // );
290
+
252
291
  return {
253
292
  optionCtrl,
254
293
  };