@hzab/list-render 1.6.0 → 1.6.1
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/package.json +1 -1
- package/src/common/utils.js +3 -3
- package/src/list-render.jsx +41 -17
- package/src/query-render/index.jsx +2 -2
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
|
}
|
|
@@ -77,11 +82,11 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
77
82
|
});
|
|
78
83
|
};
|
|
79
84
|
|
|
80
|
-
function getList(query =
|
|
85
|
+
function getList(query = modelQueryRef.current || {}) {
|
|
81
86
|
if (!model?.getList && Array.isArray(props.list)) {
|
|
82
87
|
setListLoading(true);
|
|
83
88
|
const { list } = props;
|
|
84
|
-
const { pageNum = 1, pageSize = 10 } =
|
|
89
|
+
const { pageNum = 1, pageSize = 10 } = modelQueryRef.current || {};
|
|
85
90
|
setList(list.slice(pageSize * (pageNum - 1), pageNum * pageSize));
|
|
86
91
|
setTotal(list.length);
|
|
87
92
|
props.onGetListEnd && props.onGetListEnd({ list, pagination: { pageNum, pageSize } });
|
|
@@ -95,12 +100,26 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
95
100
|
|
|
96
101
|
// remove $timerange
|
|
97
102
|
const _q = _.cloneDeep(query);
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
const _q1 = _.cloneDeep(modelQueryRef.current);
|
|
104
|
+
const _q2 = _.cloneDeep(formQueryRef.current);
|
|
105
|
+
const _q3 = _.cloneDeep(paginationQueryRef.current);
|
|
106
|
+
|
|
107
|
+
const mergedQueries = {
|
|
108
|
+
..._q,
|
|
109
|
+
..._q1,
|
|
110
|
+
..._q2,
|
|
111
|
+
..._q3
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
if (mergedQueries.$timerange !== undefined) {
|
|
115
|
+
delete mergedQueries.$timerange;
|
|
100
116
|
}
|
|
101
117
|
|
|
118
|
+
model.query = mergedQueries;
|
|
119
|
+
|
|
120
|
+
|
|
102
121
|
model
|
|
103
|
-
?.getList(
|
|
122
|
+
?.getList(mergedQueries)
|
|
104
123
|
.then((res) => {
|
|
105
124
|
setList(res.list);
|
|
106
125
|
setTotal(res.pagination?.total);
|
|
@@ -118,19 +137,24 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
118
137
|
if (model && !model.query) {
|
|
119
138
|
model.query = {};
|
|
120
139
|
}
|
|
121
|
-
model.query.pageNum = page;
|
|
122
|
-
model.query.pageSize = size;
|
|
140
|
+
// model.query.pageNum = page;
|
|
141
|
+
// model.query.pageSize = size;
|
|
142
|
+
paginationQueryRef.current = { pageNum: page, pageSize: size };
|
|
123
143
|
getList();
|
|
124
144
|
}
|
|
125
145
|
|
|
126
|
-
function onSearch(
|
|
146
|
+
function onSearch(quer,source) {
|
|
147
|
+
const query = source === "queryRender" ? {...quer} :{...formQueryRef.current, ...quer};
|
|
127
148
|
if (model && !model.query) {
|
|
128
149
|
model.query = {};
|
|
129
150
|
}
|
|
130
|
-
model.query.pageNum = 1;
|
|
151
|
+
// model.query.pageNum = 1;
|
|
152
|
+
paginationQueryRef.current = { ...paginationQueryRef.current, pageNum: 1 };
|
|
153
|
+
|
|
131
154
|
if (model && model.query && !model.query.pageSize) {
|
|
132
155
|
model.query.pageSize = 10;
|
|
133
156
|
}
|
|
157
|
+
formQueryRef.current = query;
|
|
134
158
|
model.query = Object.assign(model.query, query);
|
|
135
159
|
getList(query);
|
|
136
160
|
}
|
|
@@ -152,7 +176,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
152
176
|
return model
|
|
153
177
|
?.create(_data)
|
|
154
178
|
.then((res) => {
|
|
155
|
-
|
|
179
|
+
getList();
|
|
156
180
|
message.success(res._message || "新增成功");
|
|
157
181
|
props.onCreateSuc && props.onCreateSuc(res);
|
|
158
182
|
})
|
|
@@ -254,7 +278,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
254
278
|
.then((res) => {
|
|
255
279
|
message.success(res._message || "删除成功");
|
|
256
280
|
props.onDelSuc && props.onDelSuc(res);
|
|
257
|
-
|
|
281
|
+
getList();
|
|
258
282
|
})
|
|
259
283
|
.catch((err) => {
|
|
260
284
|
handleMessage(err._message);
|
|
@@ -276,9 +300,9 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
276
300
|
queryFormInitialValues={
|
|
277
301
|
queryFormIsExtendModelQuery
|
|
278
302
|
? {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
303
|
+
...queryFormInitialValues,
|
|
304
|
+
...model.query,
|
|
305
|
+
}
|
|
282
306
|
: queryFormInitialValues
|
|
283
307
|
}
|
|
284
308
|
onSearch={onSearch}
|
|
@@ -304,8 +328,8 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
304
328
|
</div>
|
|
305
329
|
</div>
|
|
306
330
|
{Slots.HeaderOthersSuffix && (
|
|
307
|
-
|
|
308
|
-
|
|
331
|
+
<Slots.HeaderOthersSuffix onSearch={onSearch} getList={getList} />
|
|
332
|
+
)}
|
|
309
333
|
<TableRender
|
|
310
334
|
idKey={idKey}
|
|
311
335
|
schema={schema?.schema}
|
|
@@ -330,7 +354,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
330
354
|
<Pagination
|
|
331
355
|
onChange={onPageChange}
|
|
332
356
|
total={total}
|
|
333
|
-
query={model?.query}
|
|
357
|
+
query={{ ...model?.query, ...paginationQueryRef.current }}
|
|
334
358
|
config={props.paginationConf}
|
|
335
359
|
i18n={i18n}
|
|
336
360
|
/>
|
|
@@ -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 (
|