@hzab/list-render 1.6.0 → 1.6.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 +9 -1
- package/package.json +1 -1
- package/src/common/utils.js +3 -3
- package/src/list-render.jsx +43 -17
- package/src/query-render/index.jsx +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
# @hzab/list-render@1.6.2
|
|
2
|
+
|
|
3
|
+
fix: 监听 model query 更改
|
|
4
|
+
|
|
5
|
+
# @hzab/list-render@1.6.1
|
|
6
|
+
|
|
7
|
+
fix: query 搜索条件数据逻辑优化
|
|
8
|
+
|
|
1
9
|
# @hzab/list-render@1.6.0
|
|
2
10
|
|
|
3
11
|
break: 去除 lib,直接使用 src
|
|
4
12
|
|
|
5
13
|
# @hzab/list-render@1.5.1
|
|
6
14
|
|
|
7
|
-
- feat: 新增表格和搜索项之间的插槽,新增 isTableSortXIdex
|
|
15
|
+
- feat: 新增表格和搜索项之间的插槽,新增 isTableSortXIdex table 列表列排序是否按照 x-index 排序
|
|
8
16
|
|
|
9
17
|
# @hzab/list-render@1.5.0
|
|
10
18
|
|
package/package.json
CHANGED
package/src/common/utils.js
CHANGED
|
@@ -89,7 +89,7 @@ export function getDateVal(val, format) {
|
|
|
89
89
|
return dayjs(val).format(format);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export function getFieldList(_schema, fieldList = [], opt = {}) {
|
|
92
|
+
export function getFieldList(_schema, fieldList = [], opt = {},isTableSortXIdex = false) {
|
|
93
93
|
const schema = _schema?.schema || _schema;
|
|
94
94
|
|
|
95
95
|
const { boxList = [] } = opt || {};
|
|
@@ -113,10 +113,11 @@ export function getFieldList(_schema, fieldList = [], opt = {}) {
|
|
|
113
113
|
fieldList.push(field);
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
|
+
isTableSortXIdex && fieldList.sort((a, b) => a["x-index"] - b["x-index"]);
|
|
116
117
|
return fieldList;
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
export function getFieldMap(_schema, fieldMap = {}
|
|
120
|
+
export function getFieldMap(_schema, fieldMap = {}) {
|
|
120
121
|
// const fieldMap = _.keyBy(getFieldList(_schema), "name");
|
|
121
122
|
const schema = _schema?.schema || _schema;
|
|
122
123
|
schema?.properties &&
|
|
@@ -131,7 +132,6 @@ export function getFieldMap(_schema, fieldMap = {}, isTableSortXIdex = false) {
|
|
|
131
132
|
}
|
|
132
133
|
});
|
|
133
134
|
|
|
134
|
-
isTableSortXIdex && fieldList.sort((a, b) => a["x-index"] - b["x-index"]);
|
|
135
135
|
return fieldMap;
|
|
136
136
|
}
|
|
137
137
|
|
package/src/list-render.jsx
CHANGED
|
@@ -35,6 +35,9 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
35
35
|
const formDialogRef = useRef();
|
|
36
36
|
const detailDialogRef = useRef();
|
|
37
37
|
const queryRef = useRef();
|
|
38
|
+
const modelQueryRef = useRef({});
|
|
39
|
+
const formQueryRef = useRef({});
|
|
40
|
+
const paginationQueryRef = useRef({ pageNum: 1, pageSize: 10 });
|
|
38
41
|
|
|
39
42
|
useImperativeHandle(parentRef, () => ({
|
|
40
43
|
getList,
|
|
@@ -53,6 +56,8 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
53
56
|
if (model) {
|
|
54
57
|
if (!model.query) {
|
|
55
58
|
model.query = {};
|
|
59
|
+
} else {
|
|
60
|
+
modelQueryRef.current = model?.query;
|
|
56
61
|
}
|
|
57
62
|
model.query.pageNum = 1;
|
|
58
63
|
}
|
|
@@ -63,6 +68,8 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
63
68
|
if (model && !model?.query) {
|
|
64
69
|
model.query = {};
|
|
65
70
|
}
|
|
71
|
+
modelQueryRef.current = model?.query;
|
|
72
|
+
|
|
66
73
|
}, [model?.query]);
|
|
67
74
|
|
|
68
75
|
useEffect(() => {
|
|
@@ -77,11 +84,11 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
77
84
|
});
|
|
78
85
|
};
|
|
79
86
|
|
|
80
|
-
function getList(query =
|
|
87
|
+
function getList(query = modelQueryRef.current || {}) {
|
|
81
88
|
if (!model?.getList && Array.isArray(props.list)) {
|
|
82
89
|
setListLoading(true);
|
|
83
90
|
const { list } = props;
|
|
84
|
-
const { pageNum = 1, pageSize = 10 } =
|
|
91
|
+
const { pageNum = 1, pageSize = 10 } = modelQueryRef.current || {};
|
|
85
92
|
setList(list.slice(pageSize * (pageNum - 1), pageNum * pageSize));
|
|
86
93
|
setTotal(list.length);
|
|
87
94
|
props.onGetListEnd && props.onGetListEnd({ list, pagination: { pageNum, pageSize } });
|
|
@@ -95,12 +102,26 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
95
102
|
|
|
96
103
|
// remove $timerange
|
|
97
104
|
const _q = _.cloneDeep(query);
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
const _q1 = _.cloneDeep(modelQueryRef.current);
|
|
106
|
+
const _q2 = _.cloneDeep(formQueryRef.current);
|
|
107
|
+
const _q3 = _.cloneDeep(paginationQueryRef.current);
|
|
108
|
+
|
|
109
|
+
const mergedQueries = {
|
|
110
|
+
..._q,
|
|
111
|
+
..._q1,
|
|
112
|
+
..._q2,
|
|
113
|
+
..._q3
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
if (mergedQueries.$timerange !== undefined) {
|
|
117
|
+
delete mergedQueries.$timerange;
|
|
100
118
|
}
|
|
101
119
|
|
|
120
|
+
model.query = mergedQueries;
|
|
121
|
+
|
|
122
|
+
|
|
102
123
|
model
|
|
103
|
-
?.getList(
|
|
124
|
+
?.getList(mergedQueries)
|
|
104
125
|
.then((res) => {
|
|
105
126
|
setList(res.list);
|
|
106
127
|
setTotal(res.pagination?.total);
|
|
@@ -118,19 +139,24 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
118
139
|
if (model && !model.query) {
|
|
119
140
|
model.query = {};
|
|
120
141
|
}
|
|
121
|
-
model.query.pageNum = page;
|
|
122
|
-
model.query.pageSize = size;
|
|
142
|
+
// model.query.pageNum = page;
|
|
143
|
+
// model.query.pageSize = size;
|
|
144
|
+
paginationQueryRef.current = { pageNum: page, pageSize: size };
|
|
123
145
|
getList();
|
|
124
146
|
}
|
|
125
147
|
|
|
126
|
-
function onSearch(
|
|
148
|
+
function onSearch(quer,source) {
|
|
149
|
+
const query = source === "queryRender" ? {...quer} :{...formQueryRef.current, ...quer};
|
|
127
150
|
if (model && !model.query) {
|
|
128
151
|
model.query = {};
|
|
129
152
|
}
|
|
130
|
-
model.query.pageNum = 1;
|
|
153
|
+
// model.query.pageNum = 1;
|
|
154
|
+
paginationQueryRef.current = { ...paginationQueryRef.current, pageNum: 1 };
|
|
155
|
+
|
|
131
156
|
if (model && model.query && !model.query.pageSize) {
|
|
132
157
|
model.query.pageSize = 10;
|
|
133
158
|
}
|
|
159
|
+
formQueryRef.current = query;
|
|
134
160
|
model.query = Object.assign(model.query, query);
|
|
135
161
|
getList(query);
|
|
136
162
|
}
|
|
@@ -152,7 +178,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
152
178
|
return model
|
|
153
179
|
?.create(_data)
|
|
154
180
|
.then((res) => {
|
|
155
|
-
|
|
181
|
+
getList();
|
|
156
182
|
message.success(res._message || "新增成功");
|
|
157
183
|
props.onCreateSuc && props.onCreateSuc(res);
|
|
158
184
|
})
|
|
@@ -254,7 +280,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
254
280
|
.then((res) => {
|
|
255
281
|
message.success(res._message || "删除成功");
|
|
256
282
|
props.onDelSuc && props.onDelSuc(res);
|
|
257
|
-
|
|
283
|
+
getList();
|
|
258
284
|
})
|
|
259
285
|
.catch((err) => {
|
|
260
286
|
handleMessage(err._message);
|
|
@@ -276,9 +302,9 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
276
302
|
queryFormInitialValues={
|
|
277
303
|
queryFormIsExtendModelQuery
|
|
278
304
|
? {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
305
|
+
...queryFormInitialValues,
|
|
306
|
+
...model.query,
|
|
307
|
+
}
|
|
282
308
|
: queryFormInitialValues
|
|
283
309
|
}
|
|
284
310
|
onSearch={onSearch}
|
|
@@ -304,8 +330,8 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
304
330
|
</div>
|
|
305
331
|
</div>
|
|
306
332
|
{Slots.HeaderOthersSuffix && (
|
|
307
|
-
|
|
308
|
-
|
|
333
|
+
<Slots.HeaderOthersSuffix onSearch={onSearch} getList={getList} />
|
|
334
|
+
)}
|
|
309
335
|
<TableRender
|
|
310
336
|
idKey={idKey}
|
|
311
337
|
schema={schema?.schema}
|
|
@@ -330,7 +356,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
330
356
|
<Pagination
|
|
331
357
|
onChange={onPageChange}
|
|
332
358
|
total={total}
|
|
333
|
-
query={model?.query}
|
|
359
|
+
query={{ ...model?.query, ...paginationQueryRef.current }}
|
|
334
360
|
config={props.paginationConf}
|
|
335
361
|
i18n={i18n}
|
|
336
362
|
/>
|
|
@@ -48,12 +48,12 @@ function QueryRender(props, parentRef) {
|
|
|
48
48
|
|
|
49
49
|
if (!beforeQuerySearchResult) return;
|
|
50
50
|
}
|
|
51
|
-
return props.onSearch && props.onSearch(query);
|
|
51
|
+
return props.onSearch && props.onSearch(query, 'queryRender');
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
function onReset() {
|
|
55
55
|
formRef.current?.formRender?.reset();
|
|
56
|
-
props.onSearch && props.onSearch(_.cloneDeep(formRef?.current?.formRender?.values));
|
|
56
|
+
props.onSearch && props.onSearch(_.cloneDeep(formRef?.current?.formRender?.values), 'queryRender');
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
return (
|