@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 CHANGED
@@ -1,3 +1,8 @@
1
+ # @hzab/data-model@1.0.1
2
+
3
+ - fix: 修复 delete 入参问题
4
+ - fix: getApiUrl :xx 参数替换正则处理
5
+
1
6
  # @hzab/data-model@0.2.3
2
7
 
3
8
  - fix: axios delete 入参写法问题修复
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/data-model",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "data model",
5
5
  "main": "src",
6
6
  "scripts": {
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}`, value);
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
- delete(params, ctx) {
223
- let _params = _.cloneDeep(params);
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
- _params = this.deleteReqMap(_params);
233
+ _config = this.deleteReqMap(_config);
226
234
  }
227
235
  return new Promise((resolve, reject) => {
228
- const apiUrl = this.getApiUrl(this.deleteApi, _params, ctx);
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, params: _params })
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
- multipleDelete(params, ctx) {
248
- let _params = _.cloneDeep(params);
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
- _params = this.multipleDeleteReqMap(_params);
270
+ _config = this.multipleDeleteReqMap(_config);
251
271
  }
252
272
  return new Promise((resolve, reject) => {
253
- const apiUrl = this.getApiUrl(this.multipleDeleteApi, _params, ctx);
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, params: _params })
279
+ .delete(apiUrl, { ...this.axiosConf, ..._config })
256
280
  .then((response) => {
257
281
  this.handleRes(
258
282
  response,