@hzab/data-model 1.1.0 → 1.2.0

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,11 @@
1
+ # @hzab/data-model@1.2.0
2
+
3
+ - feat: 增删改查 axiosConf 允许独立配置 xxxAxiosConf。如: createAxiosConf
4
+
5
+ # @hzab/data-model@1.1.1
6
+
7
+ - fix: formData header 覆盖问题修复
8
+
1
9
  # @hzab/data-model@1.1.0
2
10
 
3
11
  - formData 问题修复
package/README.md CHANGED
@@ -49,6 +49,18 @@ const listDM = new DataModel({
49
49
  axios,
50
50
  // axios 相关配置
51
51
  axiosConf,
52
+ // getList 接口 axios 相关配置
53
+ getListAxiosConf,
54
+ // get 接口 axios 相关配置
55
+ getAxiosConf,
56
+ // create 接口 axios 相关配置
57
+ createAxiosConf,
58
+ // update 接口 axios 相关配置
59
+ updateAxiosConf,
60
+ // delete 接口 axios 相关配置
61
+ deleteAxiosConf,
62
+ // multipleDelete 接口 axios 相关配置
63
+ multipleDeleteAxiosConf,
52
64
  // 列表接口 get 入参枚举函数
53
65
  getListReqMap,
54
66
  // 列表接口 get 出参枚举函数
@@ -99,34 +111,40 @@ function Demo({ orgId }) {
99
111
 
100
112
  ## DataModel
101
113
 
102
- | 参数 | 类型 | 必填 | 默认值 | 说明 |
103
- | -------------------- | -------- | ---- | ------ | ------------------------------------------- |
104
- | query | Object | 否 | - | query 参数对象 |
105
- | createApi | string | 否 | - | post 接口地址 |
106
- | getApi | string | 否 | - | 详情 get 接口地址 |
107
- | getListApi | string | 否 | - | 列表 get 接口地址 |
108
- | updateApi | string | 否 | - | put 接口地址 |
109
- | deleteApi | string | 否 | - | delete 接口地址 |
110
- | multipleDeleteApi | string | 否 | - | 批量删除 delete 接口地址 |
111
- | createMap | Function | 否 | - | createApi 接口提交前的处理函数 |
112
- | getMap | Function | 否 | - | getApi 接口返回结果的处理函数 |
113
- | getListMap | Function | 否 | - | getListApi 接口返回结果的处理函数 |
114
- | getListFunc | Function | 否 | - | 自定义的列表请求函数,优先级高于 getListApi |
115
- | updateMap | Function | 否 | - | updateApi 接口提交前的处理函数 |
116
- | axios | Object | 否 | - | axios 实例对象 |
117
- | axiosConf | Object | 否 | - | axios 相关配置 |
118
- | getListReqMap | Function | 否 | - | 列表接口 get 入参枚举函数 |
119
- | getListResMap | Function | 否 | - | 列表接口 get 出参枚举函数 |
120
- | getReqMap | Function | 否 | - | 详情接口 get 入参枚举函数 |
121
- | getResMap | Function | 否 | - | 详情接口 get 出参枚举函数 |
122
- | createReqMap | Function | 否 | - | 新增接口 get 入参枚举函数 |
123
- | createResMap | Function | 否 | - | 新增接口 get 出参枚举函数 |
124
- | updateReqMap | Function | 否 | - | 编辑接口 get 入参枚举函数 |
125
- | updateResMap | Function | 否 | - | 编辑接口 get 出参枚举函数 |
126
- | deleteReqMap | Function | 否 | - | 删除接口 get 入参枚举函数 |
127
- | deleteResMap | Function | 否 | - | 删除接口 get 出参枚举函数 |
128
- | multipleDeleteReqMap | Function | 否 | - | 批量删除接口 get 入参枚举函数 |
129
- | multipleDeleteResMap | Function | 否 | - | 批量删除接口 get 出参枚举函数 |
114
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
115
+ | ----------------------- | -------- | ---- | ------ | ------------------------------------------- |
116
+ | query | Object | 否 | - | query 参数对象 |
117
+ | createApi | string | 否 | - | post 接口地址 |
118
+ | getApi | string | 否 | - | 详情 get 接口地址 |
119
+ | getListApi | string | 否 | - | 列表 get 接口地址 |
120
+ | updateApi | string | 否 | - | put 接口地址 |
121
+ | deleteApi | string | 否 | - | delete 接口地址 |
122
+ | multipleDeleteApi | string | 否 | - | 批量删除 delete 接口地址 |
123
+ | createMap | Function | 否 | - | createApi 接口提交前的处理函数 |
124
+ | getMap | Function | 否 | - | getApi 接口返回结果的处理函数 |
125
+ | getListMap | Function | 否 | - | getListApi 接口返回结果的处理函数 |
126
+ | getListFunc | Function | 否 | - | 自定义的列表请求函数,优先级高于 getListApi |
127
+ | updateMap | Function | 否 | - | updateApi 接口提交前的处理函数 |
128
+ | axios | Object | 否 | - | axios 实例对象 |
129
+ | axiosConf | Object | 否 | - | axios 相关配置 |
130
+ | getListAxiosConf | Object | 否 | - | getList 接口 axios 相关配置 |
131
+ | getAxiosConf | Object | 否 | - | get 接口 axios 相关配置 |
132
+ | createAxiosConf | Object | 否 | - | create 接口 axios 相关配置 |
133
+ | updateAxiosConf | Object | 否 | - | update 接口 axios 相关配置 |
134
+ | deleteAxiosConf | Object | 否 | - | delete 接口 axios 相关配置 |
135
+ | multipleDeleteAxiosConf | Object | 否 | - | multipleDelete 接口 axios 相关配置 |
136
+ | getListReqMap | Function | 否 | - | 列表接口 get 入参枚举函数 |
137
+ | getListResMap | Function | 否 | - | 列表接口 get 出参枚举函数 |
138
+ | getReqMap | Function | 否 | - | 详情接口 get 入参枚举函数 |
139
+ | getResMap | Function | 否 | - | 详情接口 get 出参枚举函数 |
140
+ | createReqMap | Function | 否 | - | 新增接口 get 入参枚举函数 |
141
+ | createResMap | Function | 否 | - | 新增接口 get 出参枚举函数 |
142
+ | updateReqMap | Function | 否 | - | 编辑接口 get 入参枚举函数 |
143
+ | updateResMap | Function | 否 | - | 编辑接口 get 出参枚举函数 |
144
+ | deleteReqMap | Function | 否 | - | 删除接口 get 入参枚举函数 |
145
+ | deleteResMap | Function | 否 | - | 删除接口 get 出参枚举函数 |
146
+ | multipleDeleteReqMap | Function | 否 | - | 批量删除接口 get 入参枚举函数 |
147
+ | multipleDeleteResMap | Function | 否 | - | 批量删除接口 get 出参枚举函数 |
130
148
 
131
149
  ## useDataModel
132
150
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/data-model",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "data model",
5
5
  "main": "src",
6
6
  "scripts": {
package/src/data-model.js CHANGED
@@ -69,6 +69,21 @@ class DataModel {
69
69
  this.deleteResMap = deleteResMap;
70
70
  this.multipleDeleteReqMap = multipleDeleteReqMap;
71
71
  this.multipleDeleteResMap = multipleDeleteResMap;
72
+
73
+ const {
74
+ getListAxiosConf,
75
+ getAxiosConf,
76
+ createAxiosConf,
77
+ updateAxiosConf,
78
+ deleteAxiosConf,
79
+ multipleDeleteAxiosConf,
80
+ } = params || {};
81
+ this.getListAxiosConf = getListAxiosConf;
82
+ this.getAxiosConf = getAxiosConf;
83
+ this.createAxiosConf = createAxiosConf;
84
+ this.updateAxiosConf = updateAxiosConf;
85
+ this.deleteAxiosConf = deleteAxiosConf;
86
+ this.multipleDeleteAxiosConf = multipleDeleteAxiosConf;
72
87
  }
73
88
 
74
89
  getApiUrl(api, record, ctx = this.ctx, opt) {
@@ -88,7 +103,7 @@ class DataModel {
88
103
  return apiUrl;
89
104
  }
90
105
 
91
- get(q = {}, ctx = {}) {
106
+ get(q = {}, ctx = {}, axiosConf) {
92
107
  let query = _.merge({}, this.query, q);
93
108
  query = _.pickBy(query, (val) => !_.isNil(val) && val !== "");
94
109
 
@@ -101,6 +116,8 @@ class DataModel {
101
116
  this.axios
102
117
  .get(apiUrl, {
103
118
  ...this.axiosConf,
119
+ ...this.getAxiosConf,
120
+ ...axiosConf,
104
121
  params: query,
105
122
  })
106
123
  .then((response) => {
@@ -122,7 +139,7 @@ class DataModel {
122
139
  });
123
140
  }
124
141
 
125
- async getList(q, ctx) {
142
+ async getList(q, ctx, axiosConf) {
126
143
  let query = _.merge({}, this.query, q);
127
144
  query = _.pickBy(query, (val) => !_.isNil(val) && val !== "");
128
145
 
@@ -139,6 +156,8 @@ class DataModel {
139
156
  this.axios
140
157
  .get(apiUrl, {
141
158
  ...this.axiosConf,
159
+ ...this.getListAxiosConf,
160
+ ...axiosConf,
142
161
  params: query,
143
162
  })
144
163
  .then((response) => {
@@ -164,16 +183,20 @@ class DataModel {
164
183
  return resultList;
165
184
  }
166
185
 
167
- create(params, ctx) {
186
+ create(params, ctx, axiosConf) {
168
187
  return new Promise((resolve, reject) => {
169
- const opt = { ...this.axiosConf };
188
+ const opt = {
189
+ ...this.axiosConf,
190
+ ...this.createAxiosConf,
191
+ ...axiosConf,
192
+ };
170
193
  let _params = _.cloneDeep(formDataToObj(params));
171
194
  if (this.createReqMap) {
172
195
  _params = this.createReqMap(_params, params);
173
196
  }
174
197
  const apiUrl = this.getApiUrl(this.createApi, _params, ctx, { from: "create" });
175
198
  if (params instanceof FormData) {
176
- opt.headers = { "Content-Type": "multipart/form-data" };
199
+ opt.headers = { ...(opt.headers ?? {}), "Content-Type": "multipart/form-data" };
177
200
  _params = objToFormData(_params);
178
201
  }
179
202
  this.axios
@@ -194,16 +217,16 @@ class DataModel {
194
217
  });
195
218
  }
196
219
 
197
- update(params, ctx) {
220
+ update(params, ctx, axiosConf) {
198
221
  return new Promise((resolve, reject) => {
199
- const opt = { ...this.axiosConf };
222
+ const opt = { ...this.axiosConf, ...this.updateAxiosConf, ...axiosConf };
200
223
  let _params = _.cloneDeep(formDataToObj(params));
201
224
  if (this.updateReqMap) {
202
225
  _params = this.updateReqMap(_params, params);
203
226
  }
204
227
  const apiUrl = this.getApiUrl(this.updateApi, _params, ctx, { from: "update" });
205
228
  if (params instanceof FormData) {
206
- opt.headers = { "Content-Type": "multipart/form-data" };
229
+ opt.headers = { ...(opt.headers ?? {}), "Content-Type": "multipart/form-data" };
207
230
  _params = objToFormData(_params);
208
231
  }
209
232
  this.axios
@@ -245,7 +268,7 @@ class DataModel {
245
268
  { from: "delete" },
246
269
  );
247
270
  this.axios
248
- .delete(apiUrl, { ...this.axiosConf, ..._config })
271
+ .delete(apiUrl, { ...this.axiosConf, ...this.deleteAxiosConf, ..._config })
249
272
  .then((response) => {
250
273
  this.handleRes(
251
274
  response,
@@ -283,7 +306,7 @@ class DataModel {
283
306
  { from: "multipleDelete" },
284
307
  );
285
308
  this.axios
286
- .delete(apiUrl, { ...this.axiosConf, ..._config })
309
+ .delete(apiUrl, { ...this.axiosConf, ...this.multipleDeleteAxiosConf, ..._config })
287
310
  .then((response) => {
288
311
  this.handleRes(
289
312
  response,