tianheng-ui 0.1.49 → 0.1.50

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tianheng-ui",
3
3
  "description": "A Vue.js project",
4
- "version": "0.1.49",
4
+ "version": "0.1.50",
5
5
  "author": "shu lang <403732931@qq.com>",
6
6
  "license": "MIT",
7
7
  "private": false,
@@ -216,9 +216,9 @@ export default {
216
216
  trigger: "change"
217
217
  });
218
218
  }
219
- this.hendleRemoteData(item);
219
+ this.hendleElementRemoteData(item);
220
220
  },
221
- hendleRemoteData(item) {
221
+ hendleElementRemoteData(item) {
222
222
  if (!item.options.remote) return;
223
223
  if (item.type === "upload" || item.type === "button") return;
224
224
  const api = this.formConfig.config.network[item.options.remoteFunc];
@@ -233,25 +233,38 @@ export default {
233
233
  for (let e of api.inParams) {
234
234
  const value =
235
235
  getProperty(this.models, e.pAlias) ||
236
- getProperty(this.query, e.pAlias);
237
- setProperty(params, e.pAlias, value || null);
236
+ getProperty(this.query, e.pAlias) ||
237
+ null;
238
+ setProperty(params, e.pAlias, value);
238
239
  }
239
240
  if (api.needPage) {
240
241
  params.pageNum = 1;
241
242
  params.pageSize = 20;
242
243
  }
243
- if (["POST", "PUT"].includes(api.method)) requestConfig.data = params;
244
- else requestConfig.params = requestConfig;
244
+ if (["get", "delete"].includes(api.method.toLowerCase()))
245
+ requestConfig.params = params;
246
+ else requestConfig.data = params;
245
247
 
246
248
  this.axios(requestConfig).then(res => {
249
+ const props = {
250
+ value: item.options.props.value || "value",
251
+ label: item.options.props.label || "label",
252
+ children: item.options.props.children || "children"
253
+ };
254
+ const initOptions = list => {
255
+ return list.map(element => {
256
+ const dic = {
257
+ value: element[props.value],
258
+ label: element[props.label]
259
+ };
260
+ if (element[props.children] && element[props.children].length) {
261
+ dic.children = initOptions(element[props.children]);
262
+ }
263
+ return dic;
264
+ });
265
+ };
247
266
  const resultData = res.data.records ? res.data.records : res.data;
248
- item.options.remoteOptions = resultData.map(element => {
249
- return {
250
- value: element[item.options.props.value || "value"],
251
- label: element[item.options.props.label || "label"],
252
- children: element[item.options.props.children || "children"]
253
- };
254
- });
267
+ item.options.remoteOptions = initOptions(resultData);
255
268
  });
256
269
  },
257
270
  handleButtonSubmit(val) {
@@ -177,7 +177,7 @@
177
177
  <el-tooltip
178
178
  slot="label"
179
179
  effect="light"
180
- content="开启后,列表接口值修改,会触发 remote-params 回调,用于从服务器查询字段,"
180
+ content="开启后,字段接口值修改,会触发 remote-params 回调,用于从服务器查询字段"
181
181
  placement="top"
182
182
  >
183
183
  <span style="color: #409EFF;">远程字段</span>
@@ -484,3 +484,34 @@ export const deepMerge = (target, other) => {
484
484
  }
485
485
  return target;
486
486
  };
487
+
488
+ // 链式读取对象属性
489
+ export const getProperty = (obj = {}, str = "") => {
490
+ let dic = deepClone(obj);
491
+ const props = str.replace(/\[(\w+)\]/g, ".$1"); // 处理数组下标
492
+ const keys = props.split(".");
493
+ for (const key of keys) {
494
+ dic = dic[key] || "";
495
+ }
496
+ return dic;
497
+ };
498
+
499
+ // 链式设置对象属性
500
+ export const setProperty = (obj = {}, str = "", value = "", isClone) => {
501
+ let dic = isClone ? deepClone(obj) : obj;
502
+ let propValue = "";
503
+ const props = str.replace(/\[(\w+)\]/g, ".$1"); // 处理数组下标
504
+ const keys = props.split(".");
505
+ for (let i = 0; i < keys.length; i++) {
506
+ const key = keys[i];
507
+ if (keys.length === 1) {
508
+ dic[key] = value;
509
+ } else if (i === keys.length - 1) {
510
+ propValue[key] = value;
511
+ } else {
512
+ if (!dic[key]) dic[key] = {};
513
+ propValue = dic[key];
514
+ }
515
+ }
516
+ return dic;
517
+ };
@@ -79,7 +79,7 @@
79
79
  <el-tooltip
80
80
  slot="label"
81
81
  effect="light"
82
- content="开启后,列表接口值修改,会触发 remote-params 回调,用于从服务器查询字段,"
82
+ content="开启后,列表接口值修改,会触发 remote-params 回调,用于从服务器查询字段"
83
83
  placement="top"
84
84
  >
85
85
  <span style="color: #409EFF;">远程字段</span>
@@ -724,6 +724,9 @@ export default {
724
724
  "config.table.mounted.api"(val) {
725
725
  this.handleFieldsApiChange(val, true);
726
726
  },
727
+ "config.table.fields.remote"(bool) {
728
+ if (bool) this.handleFieldsApiChange(this.config.table.mounted.api, true);
729
+ },
727
730
  "config.tools.add.show"(bool) {
728
731
  if (bool) this.handleFieldsApiChange(this.config.tools.add.api);
729
732
  },
@@ -817,8 +820,8 @@ export default {
817
820
 
818
821
  if (this.config.table.fields.remote) {
819
822
  const callback = res => {
820
- api.inParams = res.inParams;
821
- api.outParams = res.outParams;
823
+ api.inParams = deepClone(res.inParams);
824
+ api.outParams = deepClone(res.outParams);
822
825
  initParams(api.inParams, null, false);
823
826
  initParams(api.outParams, null, false);
824
827
  if (isFields) {
@@ -830,8 +833,8 @@ export default {
830
833
  };
831
834
  this.$emit("remote-params", apiId, callback);
832
835
  } else {
833
- initParams(api.inParams, null, false);
834
- initParams(api.outParams, null, false);
836
+ initParams(deepClone(api.inParams), null, false);
837
+ initParams(deepClone(api.outParams), null, false);
835
838
  if (isFields) {
836
839
  this.fieldsData.inParams = deepClone(api.inParams || []);
837
840
  initParams(this.fieldsData.inParams, null, true);