@hzab/list-render 0.1.3 → 0.1.5
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/README.md +226 -63
- package/docs/form-linkage.md +203 -0
- package/docs/remote-data.md +72 -22
- package/docs/table.md +86 -0
- package/lib/data-model.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +2 -1
- package/src/data-model.js +110 -14
- package/src/index.js +1 -1
- package/src/list-render.jsx +0 -1
- package/src/pagination-render/index.jsx +2 -2
- package/src/table-render/index.jsx +10 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hzab/list-render",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"scripts": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"author": "CaiYansong",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"devDependencies": {
|
|
22
|
+
"@hzab/data-model": "^0.0.3",
|
|
22
23
|
"@hzab/webpack-config": "0.0.12",
|
|
23
24
|
"@types/react": "^18.0.26",
|
|
24
25
|
"@types/react-dom": "^18.0.9",
|
package/src/data-model.js
CHANGED
|
@@ -39,6 +39,33 @@ class DataModel {
|
|
|
39
39
|
this.updateMap = updateMap;
|
|
40
40
|
this.deleteApi = deleteApi;
|
|
41
41
|
this.multipleDeleteApi = multipleDeleteApi;
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
getListReqMap,
|
|
45
|
+
getListResMap,
|
|
46
|
+
getReqMap,
|
|
47
|
+
getResMap,
|
|
48
|
+
createReqMap,
|
|
49
|
+
createResMap,
|
|
50
|
+
updateReqMap,
|
|
51
|
+
updateResMap,
|
|
52
|
+
deleteReqMap,
|
|
53
|
+
deleteResMap,
|
|
54
|
+
multipleDeleteReqMap,
|
|
55
|
+
multipleDeleteResMap,
|
|
56
|
+
} = params || {};
|
|
57
|
+
this.getListReqMap = getListReqMap;
|
|
58
|
+
this.getListResMap = getListResMap;
|
|
59
|
+
this.getReqMap = getReqMap;
|
|
60
|
+
this.getResMap = getResMap;
|
|
61
|
+
this.createReqMap = createReqMap;
|
|
62
|
+
this.createResMap = createResMap;
|
|
63
|
+
this.updateReqMap = updateReqMap;
|
|
64
|
+
this.updateResMap = updateResMap;
|
|
65
|
+
this.deleteReqMap = deleteReqMap;
|
|
66
|
+
this.deleteResMap = deleteResMap;
|
|
67
|
+
this.multipleDeleteReqMap = multipleDeleteReqMap;
|
|
68
|
+
this.multipleDeleteResMap = multipleDeleteResMap;
|
|
42
69
|
}
|
|
43
70
|
|
|
44
71
|
getApiUrl(api, record, ctx = this.ctx) {
|
|
@@ -59,6 +86,10 @@ class DataModel {
|
|
|
59
86
|
let query = _.merge({}, this.query, q);
|
|
60
87
|
query = _.pickBy(query, (val) => !_.isNil(val) && val !== "");
|
|
61
88
|
|
|
89
|
+
if (this.getReqMap) {
|
|
90
|
+
query = this.getReqMap(query);
|
|
91
|
+
}
|
|
92
|
+
|
|
62
93
|
return new Promise((resolve, reject) => {
|
|
63
94
|
const apiUrl = this.getApiUrl(this.getApi, query, ctx);
|
|
64
95
|
this.axios
|
|
@@ -73,6 +104,9 @@ class DataModel {
|
|
|
73
104
|
if (this.getMap) {
|
|
74
105
|
res = this.getMap(res);
|
|
75
106
|
}
|
|
107
|
+
if (this.getResMap) {
|
|
108
|
+
res = this.getResMap(res);
|
|
109
|
+
}
|
|
76
110
|
resolve(res);
|
|
77
111
|
},
|
|
78
112
|
reject,
|
|
@@ -86,6 +120,10 @@ class DataModel {
|
|
|
86
120
|
let query = _.merge({}, this.query, q);
|
|
87
121
|
query = _.pickBy(query, (val) => !_.isNil(val) && val !== "");
|
|
88
122
|
|
|
123
|
+
if (this.getListReqMap) {
|
|
124
|
+
query = this.getListReqMap(query);
|
|
125
|
+
}
|
|
126
|
+
|
|
89
127
|
let resultList = null;
|
|
90
128
|
if (this.getListFunc) {
|
|
91
129
|
resultList = await this.getListFunc(query);
|
|
@@ -105,6 +143,9 @@ class DataModel {
|
|
|
105
143
|
if (this.getListMap) {
|
|
106
144
|
res.list = res.list.map((record) => this.getListMap(record));
|
|
107
145
|
}
|
|
146
|
+
if (this.getListResMap) {
|
|
147
|
+
res = this.getListResMap(res);
|
|
148
|
+
}
|
|
108
149
|
resolve(res);
|
|
109
150
|
},
|
|
110
151
|
reject,
|
|
@@ -118,56 +159,108 @@ class DataModel {
|
|
|
118
159
|
}
|
|
119
160
|
|
|
120
161
|
create(params, ctx) {
|
|
162
|
+
let _params = _.cloneDeep(params);
|
|
163
|
+
if (this.createReqMap) {
|
|
164
|
+
_params = this.createReqMap(_params);
|
|
165
|
+
}
|
|
121
166
|
return new Promise((resolve, reject) => {
|
|
122
|
-
const apiUrl = this.getApiUrl(this.createApi,
|
|
167
|
+
const apiUrl = this.getApiUrl(this.createApi, _params, ctx);
|
|
123
168
|
const opt = { ...this.axiosConf };
|
|
124
|
-
if (
|
|
169
|
+
if (_params instanceof FormData) {
|
|
125
170
|
opt.headers = { "Content-Type": "multipart/form-data" };
|
|
126
171
|
}
|
|
127
172
|
this.axios
|
|
128
|
-
.post(apiUrl,
|
|
173
|
+
.post(apiUrl, _params, opt)
|
|
129
174
|
.then((response) => {
|
|
130
|
-
this.handleRes(
|
|
175
|
+
this.handleRes(
|
|
176
|
+
response,
|
|
177
|
+
(res) => {
|
|
178
|
+
if (this.createResMap) {
|
|
179
|
+
res = this.createResMap(res);
|
|
180
|
+
}
|
|
181
|
+
resolve(res);
|
|
182
|
+
},
|
|
183
|
+
reject,
|
|
184
|
+
);
|
|
131
185
|
})
|
|
132
186
|
.catch((err) => this.errorHandler(err, reject));
|
|
133
187
|
});
|
|
134
188
|
}
|
|
135
189
|
|
|
136
190
|
update(params, ctx) {
|
|
191
|
+
let _params = _.cloneDeep(params);
|
|
192
|
+
if (this.updateReqMap) {
|
|
193
|
+
_params = this.updateReqMap(_params);
|
|
194
|
+
}
|
|
137
195
|
return new Promise((resolve, reject) => {
|
|
138
|
-
const apiUrl = this.getApiUrl(this.updateApi,
|
|
196
|
+
const apiUrl = this.getApiUrl(this.updateApi, _params, ctx);
|
|
139
197
|
const opt = { ...this.axiosConf };
|
|
140
|
-
if (
|
|
198
|
+
if (_params instanceof FormData) {
|
|
141
199
|
opt.headers = { "Content-Type": "multipart/form-data" };
|
|
142
200
|
}
|
|
143
201
|
this.axios
|
|
144
|
-
.put(apiUrl,
|
|
202
|
+
.put(apiUrl, _params, opt)
|
|
145
203
|
.then((response) => {
|
|
146
|
-
this.handleRes(
|
|
204
|
+
this.handleRes(
|
|
205
|
+
response,
|
|
206
|
+
(res) => {
|
|
207
|
+
if (this.updateResMap) {
|
|
208
|
+
res = this.updateResMap(res);
|
|
209
|
+
}
|
|
210
|
+
resolve(res);
|
|
211
|
+
},
|
|
212
|
+
reject,
|
|
213
|
+
);
|
|
147
214
|
})
|
|
148
215
|
.catch((err) => this.errorHandler(err, reject));
|
|
149
216
|
});
|
|
150
217
|
}
|
|
151
218
|
|
|
152
219
|
delete(params, ctx) {
|
|
220
|
+
let _params = _.cloneDeep(params);
|
|
221
|
+
if (this.deleteReqMap) {
|
|
222
|
+
_params = this.deleteReqMap(_params);
|
|
223
|
+
}
|
|
153
224
|
return new Promise((resolve, reject) => {
|
|
154
|
-
const apiUrl = this.getApiUrl(this.deleteApi,
|
|
225
|
+
const apiUrl = this.getApiUrl(this.deleteApi, _params, ctx);
|
|
155
226
|
this.axios
|
|
156
|
-
.delete(apiUrl, { ...this.axiosConf, ...
|
|
227
|
+
.delete(apiUrl, { ...this.axiosConf, ..._params })
|
|
157
228
|
.then((response) => {
|
|
158
|
-
this.handleRes(
|
|
229
|
+
this.handleRes(
|
|
230
|
+
response,
|
|
231
|
+
(res) => {
|
|
232
|
+
if (this.deleteResMap) {
|
|
233
|
+
res = this.deleteResMap(res);
|
|
234
|
+
}
|
|
235
|
+
resolve(res);
|
|
236
|
+
},
|
|
237
|
+
reject,
|
|
238
|
+
);
|
|
159
239
|
})
|
|
160
240
|
.catch((err) => this.errorHandler(err, reject));
|
|
161
241
|
});
|
|
162
242
|
}
|
|
163
243
|
|
|
164
244
|
multipleDelete(params, ctx) {
|
|
245
|
+
let _params = _.cloneDeep(params);
|
|
246
|
+
if (this.multipleDeleteReqMap) {
|
|
247
|
+
_params = this.multipleDeleteReqMap(_params);
|
|
248
|
+
}
|
|
165
249
|
return new Promise((resolve, reject) => {
|
|
166
|
-
const apiUrl = this.getApiUrl(this.multipleDeleteApi,
|
|
250
|
+
const apiUrl = this.getApiUrl(this.multipleDeleteApi, _params, ctx);
|
|
167
251
|
this.axios
|
|
168
|
-
.delete(apiUrl, { ...this.axiosConf, ...
|
|
252
|
+
.delete(apiUrl, { ...this.axiosConf, ..._params })
|
|
169
253
|
.then((response) => {
|
|
170
|
-
this.handleRes(
|
|
254
|
+
this.handleRes(
|
|
255
|
+
response,
|
|
256
|
+
(res) => {
|
|
257
|
+
if (this.multipleDeleteResMap) {
|
|
258
|
+
res = this.multipleDeleteResMap(res);
|
|
259
|
+
}
|
|
260
|
+
resolve(res);
|
|
261
|
+
},
|
|
262
|
+
reject,
|
|
263
|
+
);
|
|
171
264
|
})
|
|
172
265
|
.catch((err) => this.errorHandler(err, reject));
|
|
173
266
|
});
|
|
@@ -189,6 +282,7 @@ class DataModel {
|
|
|
189
282
|
if (_.isObject(_data) && _data.message === undefined) {
|
|
190
283
|
// 前缀 _ 避免与 data 里已有的 message 冲突
|
|
191
284
|
_data._message = message || msg;
|
|
285
|
+
_data._msg = message || msg;
|
|
192
286
|
}
|
|
193
287
|
resolve(_data);
|
|
194
288
|
} else {
|
|
@@ -196,6 +290,7 @@ class DataModel {
|
|
|
196
290
|
error.code = code;
|
|
197
291
|
error.response = response;
|
|
198
292
|
error._message = message || msg;
|
|
293
|
+
error._msg = message || msg;
|
|
199
294
|
reject(error);
|
|
200
295
|
}
|
|
201
296
|
}
|
|
@@ -210,6 +305,7 @@ class DataModel {
|
|
|
210
305
|
if (message) {
|
|
211
306
|
// 前缀 _ 避免与 data 里已有的 message 冲突
|
|
212
307
|
error._message = message;
|
|
308
|
+
error._msg = message;
|
|
213
309
|
}
|
|
214
310
|
return reject(error);
|
|
215
311
|
}
|
package/src/index.js
CHANGED
package/src/list-render.jsx
CHANGED
|
@@ -239,7 +239,6 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
239
239
|
ref={formDialogRef}
|
|
240
240
|
schema={schema}
|
|
241
241
|
dialogConf={props.dialogConf}
|
|
242
|
-
formSlots={props.formSlots}
|
|
243
242
|
formInitialValues={props.formInitialValues}
|
|
244
243
|
onClose={props.onFormDialogClose}
|
|
245
244
|
onSubmit={formState === "edit" ? onEditSubmit : onCreateSubmit}
|
|
@@ -7,7 +7,7 @@ const pageSizeOptions = [10, 20, 50, 100];
|
|
|
7
7
|
|
|
8
8
|
function PaginationRender(props) {
|
|
9
9
|
const [pageSize, setPageSize] = useState(
|
|
10
|
-
props.query?.pageSize || (props.pageSizeOptions ? props.pageSizeOptions[0] : pageSizeOptions[0]),
|
|
10
|
+
props.query?.pageSize || (props.config?.pageSizeOptions ? props.config?.pageSizeOptions[0] : pageSizeOptions[0]),
|
|
11
11
|
);
|
|
12
12
|
const [pageNum, setPageNumber] = useState(props.query?.pageNum || 1);
|
|
13
13
|
|
|
@@ -43,7 +43,7 @@ function PaginationRender(props) {
|
|
|
43
43
|
current={pageNum}
|
|
44
44
|
pageSize={pageSize}
|
|
45
45
|
onChange={onChange}
|
|
46
|
-
pageSizeOptions={props.pageSizeOptions || pageSizeOptions}
|
|
46
|
+
pageSizeOptions={props.config?.pageSizeOptions || pageSizeOptions}
|
|
47
47
|
total={props.total}
|
|
48
48
|
showTotal={(total) => `总条数 ${total} 条`}
|
|
49
49
|
showSizeChanger
|
|
@@ -111,7 +111,7 @@ function TableRender(props) {
|
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
if (props.hasAction !== false) {
|
|
114
|
-
const { hasEdit, hasDel } = props.config || {};
|
|
114
|
+
const { hasEdit, hasDel, hasDelTips } = props.config || {};
|
|
115
115
|
|
|
116
116
|
const _colConf = props.config?.colConf?._$actions || {};
|
|
117
117
|
|
|
@@ -126,14 +126,14 @@ function TableRender(props) {
|
|
|
126
126
|
return <Slots.tableActionsSlot {...slotProps} />;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
//编辑按钮权限
|
|
130
|
+
const _hasEdit = hasEdit && typeof hasEdit === "function" ? hasEdit(record, index) : hasEdit !== false;
|
|
131
|
+
|
|
132
|
+
//删除按钮权限
|
|
133
|
+
const _hasDel = hasDel && typeof hasDel === "function" ? hasEdit(record, index) : hasDel !== false;
|
|
134
|
+
|
|
135
|
+
//删除按钮提示
|
|
136
|
+
const delTips = hasDelTips && typeof hasDelTips === "function" ? hasDelTips(record, index) : hasDelTips || "确认删除该项?";
|
|
137
137
|
|
|
138
138
|
return (
|
|
139
139
|
<div style={{ width: _colConf?.width, maxWidth: "100%" }}>
|
|
@@ -152,7 +152,7 @@ function TableRender(props) {
|
|
|
152
152
|
{_hasDel ? (
|
|
153
153
|
<Popconfirm
|
|
154
154
|
placement="topRight"
|
|
155
|
-
title={
|
|
155
|
+
title={delTips}
|
|
156
156
|
onConfirm={() => {
|
|
157
157
|
props.onDel && props.onDel(record, index);
|
|
158
158
|
}}
|