@hzab/data-model 1.0.0 → 1.0.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/CHANGELOG.md +5 -0
- package/package.json +1 -1
- package/src/data-model.js +35 -11
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/data-model.js
CHANGED
|
@@ -79,7 +79,7 @@ class DataModel {
|
|
|
79
79
|
const params = _.merge({}, record, ctx);
|
|
80
80
|
_.each(params, (value, key) => {
|
|
81
81
|
if (!_.isString(value) || !_.isNumber(value) || _.isBoolean(value)) {
|
|
82
|
-
apiUrl = apiUrl.replace(`:${key}
|
|
82
|
+
apiUrl = apiUrl.replace(new RegExp(`:${key}$|:${key}(?=\/)`), value);
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
return apiUrl;
|
|
@@ -219,15 +219,27 @@ class DataModel {
|
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
/**
|
|
223
|
+
* 删除接口
|
|
224
|
+
* @param {*} config axios.delete config 参数,
|
|
225
|
+
* @param {*} config.params axios.delete url 参数,
|
|
226
|
+
* @param {*} config.data axios.delete data 参数,
|
|
227
|
+
* @param {*} ctx
|
|
228
|
+
* @returns
|
|
229
|
+
*/
|
|
230
|
+
delete(config, ctx) {
|
|
231
|
+
let _config = _.cloneDeep(config) || {};
|
|
224
232
|
if (this.deleteReqMap) {
|
|
225
|
-
|
|
233
|
+
_config = this.deleteReqMap(_config);
|
|
226
234
|
}
|
|
227
235
|
return new Promise((resolve, reject) => {
|
|
228
|
-
const apiUrl = this.getApiUrl(
|
|
236
|
+
const apiUrl = this.getApiUrl(
|
|
237
|
+
this.deleteApi,
|
|
238
|
+
Object.assign(_.cloneDeep(_config), _config.params, _config.data),
|
|
239
|
+
ctx,
|
|
240
|
+
);
|
|
229
241
|
this.axios
|
|
230
|
-
.delete(apiUrl, { ...this.axiosConf,
|
|
242
|
+
.delete(apiUrl, { ...this.axiosConf, ..._config })
|
|
231
243
|
.then((response) => {
|
|
232
244
|
this.handleRes(
|
|
233
245
|
response,
|
|
@@ -244,15 +256,27 @@ class DataModel {
|
|
|
244
256
|
});
|
|
245
257
|
}
|
|
246
258
|
|
|
247
|
-
|
|
248
|
-
|
|
259
|
+
/**
|
|
260
|
+
* 批量删除接口
|
|
261
|
+
* @param {*} config axios.delete config 参数,
|
|
262
|
+
* @param {*} config.params axios.delete url 参数,
|
|
263
|
+
* @param {*} config.data axios.delete data 参数,
|
|
264
|
+
* @param {*} ctx
|
|
265
|
+
* @returns
|
|
266
|
+
*/
|
|
267
|
+
multipleDelete(config, ctx) {
|
|
268
|
+
let _config = _.cloneDeep(config) || {};
|
|
249
269
|
if (this.multipleDeleteReqMap) {
|
|
250
|
-
|
|
270
|
+
_config = this.multipleDeleteReqMap(_config);
|
|
251
271
|
}
|
|
252
272
|
return new Promise((resolve, reject) => {
|
|
253
|
-
const apiUrl = this.getApiUrl(
|
|
273
|
+
const apiUrl = this.getApiUrl(
|
|
274
|
+
this.multipleDeleteApi,
|
|
275
|
+
Object.assign(_.cloneDeep(_config), _config.params, _config.data),
|
|
276
|
+
ctx,
|
|
277
|
+
);
|
|
254
278
|
this.axios
|
|
255
|
-
.delete(apiUrl, { ...this.axiosConf,
|
|
279
|
+
.delete(apiUrl, { ...this.axiosConf, ..._config })
|
|
256
280
|
.then((response) => {
|
|
257
281
|
this.handleRes(
|
|
258
282
|
response,
|