@hzab/list-render 1.7.0 → 1.8.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # @hzab/list-render@1.8.2
2
+
3
+ fix: query schema props scope 模式问题修复
4
+ fix: query allowClear 允许外部配置
5
+
1
6
  # @hzab/list-render@1.6.2
2
7
 
3
8
  fix: 监听 model query 更改
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/list-render",
3
- "version": "1.7.0",
3
+ "version": "1.8.2",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -1,7 +1,8 @@
1
+ import _ from "lodash";
1
2
  import { getFieldMap } from "./utils";
2
3
 
3
4
  export const handleQuerySchema = (opt) => {
4
- const { schema, search, filters, onSearch, replaceComList } = opt || {};
5
+ const { schema, search, filters, onSearch, replaceComList, schemaScope } = opt || {};
5
6
  const queryProperties = {};
6
7
  let index = 0;
7
8
  if (search) {
@@ -10,13 +11,13 @@ export const handleQuerySchema = (opt) => {
10
11
  index += 1;
11
12
  }
12
13
 
13
- const fieldMap = getFieldMap(schema);
14
+ const fieldMap = getFieldMap(_.cloneDeep(schema));
14
15
  filters?.forEach((key) => {
15
16
  const item = fieldMap[key];
16
17
  if (item) {
17
18
  const xComponent = item["x-component"];
18
19
  const replaceItem = replaceComList?.find((it) => it.name === key || (!it.name && it.component === xComponent));
19
- // TODO: 优化
20
+
20
21
  const itemConf = {
21
22
  ...item,
22
23
  ...replaceItem,
@@ -25,11 +26,17 @@ export const handleQuerySchema = (opt) => {
25
26
  "x-display": "visible",
26
27
  };
27
28
 
28
- if (!itemConf["x-component-props"]) {
29
+ // 处理 props 不存在、从 scope 中获取的情况
30
+ const comProps = itemConf["x-component-props"];
31
+ if (!comProps) {
29
32
  itemConf["x-component-props"] = {};
33
+ } else if (isScopeKey(comProps)) {
34
+ itemConf["x-component-props"] = getValByScope(comProps, schemaScope) || {};
30
35
  }
31
36
 
32
- itemConf["x-component-props"].allowClear = true;
37
+ if (typeof itemConf["x-component-props"].allowClear !== "boolean") {
38
+ itemConf["x-component-props"].allowClear = true;
39
+ }
33
40
 
34
41
  handleInput(itemConf, opt);
35
42
  handleSelect(itemConf, opt);
@@ -173,7 +180,7 @@ export const handleShortcutSubmit = (conf, opt) => {
173
180
 
174
181
  // 输入框
175
182
  if (isEnterSubmit && xComponent === "Input") {
176
- const onPressEnter = xComponentProps?.onPressEnter;
183
+ const onPressEnter = getSchemaVal(xComponentProps?.onPressEnter, opt);
177
184
  conf["x-component-props"].onPressEnter = function (e, ...args) {
178
185
  e?.preventDefault && e?.preventDefault();
179
186
  // 阻止默认事件,解决单个 input 提交问题
@@ -184,12 +191,12 @@ export const handleShortcutSubmit = (conf, opt) => {
184
191
  // 清除事件
185
192
  handleInputClear(conf, opt);
186
193
  } else if (isChangeSubmit && onChangeList.includes(xComponent)) {
187
- conf["x-component-props"].onChange = handleHoc(xComponentProps?.onChange, onSearch);
194
+ conf["x-component-props"].onChange = handleHoc(xComponentProps?.onChange, onSearch, opt);
188
195
  }
189
196
  // 处理自定义组件快捷提交逻辑
190
197
  const item = customSubmitList?.find((it) => it.component === xComponent);
191
198
  if (item) {
192
- conf["x-component-props"][item.event] = handleHoc(xComponentProps[item.event], onSearch);
199
+ conf["x-component-props"][item.event] = handleHoc(xComponentProps[item.event], onSearch, opt);
193
200
  }
194
201
  };
195
202
 
@@ -199,11 +206,14 @@ export const handleShortcutSubmit = (conf, opt) => {
199
206
  * @param cb
200
207
  * @returns
201
208
  */
202
- export const handleHoc = (source, cb) => {
209
+ export const handleHoc = (source, cb, opt) => {
203
210
  return async function (...args) {
211
+ const { schemaScope } = opt;
212
+ let _source = getSchemaVal(source, schemaScope);
213
+
204
214
  let res = null;
205
- if (source) {
206
- res = await source(...args);
215
+ if (_source) {
216
+ res = await _source(...args);
207
217
  }
208
218
  cb && cb(...args);
209
219
  return res;
@@ -217,8 +227,8 @@ export const handleHoc = (source, cb) => {
217
227
  * @returns
218
228
  */
219
229
  export const handleInputClear = (conf, opt) => {
220
- const { onSearch } = opt || {};
221
- const onChange = conf["x-component-props"]?.onChange;
230
+ const { onSearch, schemaScope } = opt || {};
231
+ const onChange = getSchemaVal(conf["x-component-props"]?.onChange, schemaScope);
222
232
  conf["x-component-props"].onChange = function (e, ...args) {
223
233
  const res = onChange && onChange(e, ...args);
224
234
  if (e.type === "click" && e.target?.value === "") {
@@ -229,4 +239,56 @@ export const handleInputClear = (conf, opt) => {
229
239
  return conf;
230
240
  };
231
241
 
242
+ /**
243
+ * 是否是 scope key
244
+ * @param strKey
245
+ * @returns
246
+ */
247
+ export const isScopeKey = (strKey) => {
248
+ if (typeof strKey !== "string") {
249
+ return false;
250
+ }
251
+ const key = strKey.trim();
252
+ return key.startsWith("{{") && key.endsWith("}}");
253
+ };
254
+
255
+ /**
256
+ * 获取 scope key
257
+ * @param strKey
258
+ * @returns
259
+ */
260
+ export const getScopeKey = (strKey) => {
261
+ if (!isScopeKey(strKey)) {
262
+ return "";
263
+ }
264
+ const key = strKey.trim();
265
+ return key.replace(/^\{\{/, "").replace(/\}\}$/, "");
266
+ };
267
+
268
+ /**
269
+ * 通过字符串获取 schemaScope 中的数据
270
+ * @param strKey
271
+ * @param schemaScope
272
+ * @returns
273
+ */
274
+ export const getSchemaVal = (strKey, schemaScope = {}) => {
275
+ const val = getValByScope(strKey, schemaScope);
276
+ if (!_.isNil(val) && val !== "") {
277
+ return val;
278
+ }
279
+ return strKey;
280
+ };
281
+
282
+ /**
283
+ * 通过字符串获取 schemaScope 中的数据
284
+ * @param strKey
285
+ * @param schemaScope
286
+ * @returns
287
+ */
288
+ export const getValByScope = (strKey, schemaScope = {}) => {
289
+ if (isScopeKey(strKey)) {
290
+ return schemaScope && schemaScope[getScopeKey(strKey)];
291
+ }
292
+ };
293
+
232
294
  export default handleQuerySchema;
@@ -69,7 +69,6 @@ const ListRender = forwardRef(function (props, parentRef) {
69
69
  model.query = {};
70
70
  }
71
71
  modelQueryRef.current = model?.query;
72
-
73
72
  }, [model?.query]);
74
73
 
75
74
  useEffect(() => {
@@ -110,7 +109,7 @@ const ListRender = forwardRef(function (props, parentRef) {
110
109
  ..._q,
111
110
  ..._q1,
112
111
  ..._q2,
113
- ..._q3
112
+ ..._q3,
114
113
  };
115
114
 
116
115
  if (mergedQueries.$timerange !== undefined) {
@@ -119,7 +118,6 @@ const ListRender = forwardRef(function (props, parentRef) {
119
118
 
120
119
  model.query = mergedQueries;
121
120
 
122
-
123
121
  model
124
122
  ?.getList(mergedQueries)
125
123
  .then((res) => {
@@ -145,8 +143,8 @@ const ListRender = forwardRef(function (props, parentRef) {
145
143
  getList();
146
144
  }
147
145
 
148
- function onSearch(quer,source) {
149
- const query = source === "queryRender" ? {...quer} :{...formQueryRef.current, ...quer};
146
+ function onSearch(quer, source) {
147
+ const query = source === "queryRender" ? { ...quer } : { ...formQueryRef.current, ...quer };
150
148
  if (model && !model.query) {
151
149
  model.query = {};
152
150
  }
@@ -302,9 +300,9 @@ const ListRender = forwardRef(function (props, parentRef) {
302
300
  queryFormInitialValues={
303
301
  queryFormIsExtendModelQuery
304
302
  ? {
305
- ...queryFormInitialValues,
306
- ...model.query,
307
- }
303
+ ...queryFormInitialValues,
304
+ ...model.query,
305
+ }
308
306
  : queryFormInitialValues
309
307
  }
310
308
  onSearch={onSearch}
@@ -329,9 +327,7 @@ const ListRender = forwardRef(function (props, parentRef) {
329
327
  )}
330
328
  </div>
331
329
  </div>
332
- {Slots.HeaderOthersSuffix && (
333
- <Slots.HeaderOthersSuffix onSearch={onSearch} getList={getList} />
334
- )}
330
+ {Slots.HeaderOthersSuffix && <Slots.HeaderOthersSuffix onSearch={onSearch} getList={getList} />}
335
331
  <TableRender
336
332
  idKey={idKey}
337
333
  schema={schema?.schema}
@@ -18,6 +18,7 @@ function QueryRender(props, parentRef) {
18
18
  setSchema(
19
19
  handleQuerySchema({
20
20
  ...props?.config,
21
+ schemaScope: props.schemaScope,
21
22
  schema: _.cloneDeep(props.schema),
22
23
  search: props.search,
23
24
  filters: _.cloneDeep(props.filters),
@@ -48,12 +49,12 @@ function QueryRender(props, parentRef) {
48
49
 
49
50
  if (!beforeQuerySearchResult) return;
50
51
  }
51
- return props.onSearch && props.onSearch(query, 'queryRender');
52
+ return props.onSearch && props.onSearch(query, "queryRender");
52
53
  }
53
54
 
54
55
  function onReset() {
55
56
  formRef.current?.formRender?.reset();
56
- props.onSearch && props.onSearch(_.cloneDeep(formRef?.current?.formRender?.values), 'queryRender');
57
+ props.onSearch && props.onSearch(_.cloneDeep(formRef?.current?.formRender?.values), "queryRender");
57
58
  }
58
59
 
59
60
  return (
@@ -54,7 +54,7 @@ function TableRender(props) {
54
54
  scope: props.schemaScope,
55
55
  formilyRef,
56
56
  });
57
- _fieldList.forEach((field) => {
57
+ _fieldList.forEach((field, colIndex) => {
58
58
  const fieldSchemas = formilyRef.current?.fields;
59
59
  if (field.inTable !== false) {
60
60
  const { name, title } = field;
@@ -121,6 +121,7 @@ function TableRender(props) {
121
121
 
122
122
  columns.push({
123
123
  ..._colConf,
124
+ onCell: (record, rowIndex) => (_colConf?.onCell?.({...record, _field: { ...field, ...(fieldSchemas?.[name] || {}) }}, rowIndex) || {}),
124
125
  title: _title,
125
126
  key: name,
126
127
  dataIndex: name,