@hzab/data-model 1.0.1 → 1.0.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 +4 -0
- package/package.json +1 -1
- package/src/data-model.js +11 -6
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/data-model.js
CHANGED
|
@@ -71,9 +71,12 @@ class DataModel {
|
|
|
71
71
|
this.multipleDeleteResMap = multipleDeleteResMap;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
getApiUrl(api, record, ctx = this.ctx) {
|
|
74
|
+
getApiUrl(api, record, ctx = this.ctx, opt) {
|
|
75
|
+
const { from } = opt ?? {};
|
|
75
76
|
if (!api) {
|
|
76
|
-
|
|
77
|
+
const errMsg = `${from ?? ""} api 不能为空。`;
|
|
78
|
+
console.error(`Error ${errMsg} 具体入参:api、record、ctx、opt:`, api, record, ctx, opt);
|
|
79
|
+
throw new Error(errMsg);
|
|
77
80
|
}
|
|
78
81
|
let apiUrl = api;
|
|
79
82
|
const params = _.merge({}, record, ctx);
|
|
@@ -94,7 +97,7 @@ class DataModel {
|
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
return new Promise((resolve, reject) => {
|
|
97
|
-
const apiUrl = this.getApiUrl(this.getApi, query, ctx);
|
|
100
|
+
const apiUrl = this.getApiUrl(this.getApi, query, ctx, { from: "get" });
|
|
98
101
|
this.axios
|
|
99
102
|
.get(apiUrl, {
|
|
100
103
|
...this.axiosConf,
|
|
@@ -132,7 +135,7 @@ class DataModel {
|
|
|
132
135
|
resultList = await this.getListFunc(query);
|
|
133
136
|
} else {
|
|
134
137
|
const getPro = new Promise((resolve, reject) => {
|
|
135
|
-
const apiUrl = this.getApiUrl(this.getListApi, q, ctx);
|
|
138
|
+
const apiUrl = this.getApiUrl(this.getListApi, q, ctx, { from: "getList" });
|
|
136
139
|
this.axios
|
|
137
140
|
.get(apiUrl, {
|
|
138
141
|
...this.axiosConf,
|
|
@@ -167,7 +170,7 @@ class DataModel {
|
|
|
167
170
|
_params = this.createReqMap(_params);
|
|
168
171
|
}
|
|
169
172
|
return new Promise((resolve, reject) => {
|
|
170
|
-
const apiUrl = this.getApiUrl(this.createApi, _params, ctx);
|
|
173
|
+
const apiUrl = this.getApiUrl(this.createApi, _params, ctx, { from: "create" });
|
|
171
174
|
const opt = { ...this.axiosConf };
|
|
172
175
|
if (_params instanceof FormData) {
|
|
173
176
|
opt.headers = { "Content-Type": "multipart/form-data" };
|
|
@@ -196,7 +199,7 @@ class DataModel {
|
|
|
196
199
|
_params = this.updateReqMap(_params);
|
|
197
200
|
}
|
|
198
201
|
return new Promise((resolve, reject) => {
|
|
199
|
-
const apiUrl = this.getApiUrl(this.updateApi, _params, ctx);
|
|
202
|
+
const apiUrl = this.getApiUrl(this.updateApi, _params, ctx, { from: "update" });
|
|
200
203
|
const opt = { ...this.axiosConf };
|
|
201
204
|
if (_params instanceof FormData) {
|
|
202
205
|
opt.headers = { "Content-Type": "multipart/form-data" };
|
|
@@ -237,6 +240,7 @@ class DataModel {
|
|
|
237
240
|
this.deleteApi,
|
|
238
241
|
Object.assign(_.cloneDeep(_config), _config.params, _config.data),
|
|
239
242
|
ctx,
|
|
243
|
+
{ from: "delete" },
|
|
240
244
|
);
|
|
241
245
|
this.axios
|
|
242
246
|
.delete(apiUrl, { ...this.axiosConf, ..._config })
|
|
@@ -274,6 +278,7 @@ class DataModel {
|
|
|
274
278
|
this.multipleDeleteApi,
|
|
275
279
|
Object.assign(_.cloneDeep(_config), _config.params, _config.data),
|
|
276
280
|
ctx,
|
|
281
|
+
{ from: "multipleDelete" },
|
|
277
282
|
);
|
|
278
283
|
this.axios
|
|
279
284
|
.delete(apiUrl, { ...this.axiosConf, ..._config })
|