tianheng-ui 0.1.48 → 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.48",
4
+ "version": "0.1.50",
5
5
  "author": "shu lang <403732931@qq.com>",
6
6
  "license": "MIT",
7
7
  "private": false,
@@ -63,7 +63,7 @@
63
63
 
64
64
  <script>
65
65
  import * as Axios from "lib/theme-chalk/js/axios";
66
- import { deepClone } from "./util/index";
66
+ import { deepClone, getProperty, setProperty } from "./util/index";
67
67
  import GenetateFormItem from "./GenerateFormItem";
68
68
 
69
69
  export default {
@@ -216,13 +216,13 @@ 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];
225
- if (!api) return this.$message.warning("未知的请求接口,请检查配置信息");
225
+ if (!api) return this.$message.warning("未知的接口,请检查配置信息");
226
226
 
227
227
  const requestConfig = {
228
228
  url: api.url,
@@ -231,31 +231,80 @@ export default {
231
231
  };
232
232
  const params = {};
233
233
  for (let e of api.inParams) {
234
- params[e.alias] =
235
- eval(`this.models.${e.pAlias}`) ||
236
- eval(`this.query.${e.pAlias}`) ||
234
+ const value =
235
+ getProperty(this.models, e.pAlias) ||
236
+ getProperty(this.query, e.pAlias) ||
237
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) {
258
- this.$emit("button-submit", val);
271
+ const api = this.formConfig.config.network[val];
272
+ if (!api) return this.$message.warning("未知的接口,请检查配置信息");
273
+
274
+ const requestConfig = {
275
+ url: api.url,
276
+ method: api.method,
277
+ headers: api.headers
278
+ };
279
+
280
+ let params = {};
281
+ const inParams = api.inParams;
282
+ const initParams = list => {
283
+ list.map(item => {
284
+ if (item.children) {
285
+ initParams(item.children);
286
+ } else {
287
+ const value = getProperty(this.models, item.pAlias);
288
+ setProperty(params, item.pAlias, value);
289
+ }
290
+ });
291
+ };
292
+ initParams(inParams);
293
+
294
+ if (api.needPage) {
295
+ params.pageNum = 1;
296
+ params.pageSize = 20;
297
+ }
298
+ if (["get", "delete"].includes(api.method.toLowerCase()))
299
+ requestConfig.params = params;
300
+ else requestConfig.data = params;
301
+
302
+ this.$refs.generateForm.validate(valid => {
303
+ if (!valid) return;
304
+ this.axios(requestConfig).then(res => {
305
+ this.$emit("button-submit", requestConfig);
306
+ });
307
+ });
259
308
  },
260
309
  getData() {
261
310
  return new Promise((resolve, reject) => {
@@ -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>
@@ -196,10 +196,10 @@
196
196
  <el-select
197
197
  v-model="config.fields.api"
198
198
  style="width:100%"
199
- clearable
200
199
  placeholder="请选择"
201
- filterable
202
200
  no-data-text="暂无接口,请前往【数据源模块】创建"
201
+ clearable
202
+ filterable
203
203
  >
204
204
  <el-option
205
205
  v-for="item in apiOptions"
@@ -588,10 +588,12 @@ export default {
588
588
  return;
589
589
  }
590
590
 
591
- const initParams = (paramsList, pAlias) => {
591
+ const initParams = (paramsList, pAlias, bool) => {
592
592
  paramsList.forEach(item => {
593
- item.elType = "input";
594
- item.align = "left";
593
+ if (bool) {
594
+ item.elType = "input";
595
+ item.align = "left";
596
+ }
595
597
  item.pAlias = pAlias ? `${pAlias}.${item.alias}` : item.alias;
596
598
  if (item.children && item.children.length) {
597
599
  initParams(item.children, item.pAlias);
@@ -601,25 +603,28 @@ export default {
601
603
 
602
604
  if (this.config.fields.remote) {
603
605
  const callback = res => {
604
- api.inParams = res.inParams;
605
- api.outParams = res.outParams;
606
+ api.inParams = deepClone(res.inParams);
607
+ api.outParams = deepClone(res.outParams);
608
+ initParams(api.inParams, null, false);
609
+ initParams(api.outParams, null, false);
610
+
606
611
  if (isFields) {
607
612
  this.fieldsData.inParams = deepClone(res.inParams || []);
608
- initParams(this.fieldsData.inParams);
613
+ initParams(this.fieldsData.inParams, null, true);
609
614
  this.fieldsData.outParams = deepClone(res.outParams || []);
610
- initParams(this.fieldsData.outParams);
615
+ initParams(this.fieldsData.outParams, null, true);
611
616
  }
612
617
  };
613
618
  this.$emit("remote-params", apiId, callback);
614
- return;
615
- }
616
-
617
- if (isFields) {
618
- this.fieldsData.inParams = deepClone(api.inParams || []);
619
- initParams(this.fieldsData.inParams);
620
- this.fieldsData.outParams = deepClone(api.outParams || []);
621
- initParams(this.fieldsData.outParams);
622
- return;
619
+ } else {
620
+ initParams(api.inParams, null, false);
621
+ initParams(api.outParams, null, false);
622
+ if (isFields) {
623
+ this.fieldsData.inParams = deepClone(api.inParams || []);
624
+ initParams(this.fieldsData.inParams, null, true);
625
+ this.fieldsData.outParams = deepClone(api.outParams || []);
626
+ initParams(this.fieldsData.outParams, null, true);
627
+ }
623
628
  }
624
629
  },
625
630
  formValidate() {
@@ -90,10 +90,10 @@
90
90
  <el-select
91
91
  style="width:100%"
92
92
  v-model="widget.options.remoteFunc"
93
- value-key="id"
93
+ placeholder="请选择"
94
+ no-data-text="暂无数据,请查阅相关文档说明"
94
95
  clearable
95
- placeholder="请选择提交方法"
96
- no-data-text="暂无接口,请前往【接口模块】创建"
96
+ filterable
97
97
  >
98
98
  <el-option
99
99
  v-for="item in apiOptions"
@@ -60,9 +60,10 @@
60
60
  <el-select
61
61
  style="width:100%"
62
62
  v-model="widget.options.remoteFunc"
63
- value-key="id"
64
- placeholder="请选择远端方法"
63
+ placeholder="请选择"
64
+ no-data-text="暂无数据,请查阅相关文档说明"
65
65
  clearable
66
+ filterable
66
67
  >
67
68
  <el-option
68
69
  v-for="item in apiOptions"
@@ -60,19 +60,21 @@
60
60
  <el-form-item label-width="0">
61
61
  <template v-if="widget.options.remote">
62
62
  <el-select
63
- style="width:100%"
64
- v-model="widget.options.remoteFunc"
65
- placeholder="请选择远端方法"
66
- clearable
63
+ style="width:100%"
64
+ v-model="widget.options.remoteFunc"
65
+ placeholder="请选择"
66
+ no-data-text="暂无数据,请查阅相关文档说明"
67
+ clearable
68
+ filterable
69
+ >
70
+ <el-option
71
+ v-for="item in apiOptions"
72
+ :key="item.id"
73
+ :label="item.name"
74
+ :value="item.id"
67
75
  >
68
- <el-option
69
- v-for="item in apiOptions"
70
- :key="item.id"
71
- :label="item.name"
72
- :value="item.id"
73
- >
74
- </el-option>
75
- </el-select>
76
+ </el-option>
77
+ </el-select>
76
78
 
77
79
  <el-input v-model="widget.options.props.value">
78
80
  <div slot="prepend" style="width:50px;">值</div>
@@ -48,19 +48,21 @@
48
48
  <el-form-item label-width="0">
49
49
  <template v-if="widget.options.remote">
50
50
  <el-select
51
- style="width:100%"
52
- v-model="widget.options.remoteFunc"
53
- placeholder="请选择远端方法"
54
- clearable
51
+ style="width:100%"
52
+ v-model="widget.options.remoteFunc"
53
+ placeholder="请选择"
54
+ no-data-text="暂无数据,请查阅相关文档说明"
55
+ clearable
56
+ filterable
57
+ >
58
+ <el-option
59
+ v-for="item in apiOptions"
60
+ :key="item.id"
61
+ :label="item.name"
62
+ :value="item.id"
55
63
  >
56
- <el-option
57
- v-for="item in apiOptions"
58
- :key="item.id"
59
- :label="item.name"
60
- :value="item.id"
61
- >
62
- </el-option>
63
- </el-select>
64
+ </el-option>
65
+ </el-select>
64
66
 
65
67
  <el-input v-model="widget.options.props.value">
66
68
  <div slot="prepend" style="width:50px;">值</div>
@@ -45,19 +45,21 @@
45
45
  <el-form-item label-width="0">
46
46
  <template v-if="widget.options.remote">
47
47
  <el-select
48
- style="width:100%"
49
- v-model="widget.options.remoteFunc"
50
- placeholder="请选择远端方法"
51
- clearable
48
+ style="width:100%"
49
+ v-model="widget.options.remoteFunc"
50
+ placeholder="请选择"
51
+ no-data-text="暂无数据,请查阅相关文档说明"
52
+ clearable
53
+ filterable
54
+ >
55
+ <el-option
56
+ v-for="item in apiOptions"
57
+ :key="item.id"
58
+ :label="item.name"
59
+ :value="item.id"
52
60
  >
53
- <el-option
54
- v-for="item in apiOptions"
55
- :key="item.id"
56
- :label="item.name"
57
- :value="item.id"
58
- >
59
- </el-option>
60
- </el-select>
61
+ </el-option>
62
+ </el-select>
61
63
 
62
64
  <el-input v-model="widget.options.props.value">
63
65
  <div slot="prepend" style="width:50px;">值</div>
@@ -57,18 +57,21 @@
57
57
  <el-form-item label-width="0">
58
58
  <div v-if="widget.options.remote">
59
59
  <el-select
60
- v-model="widget.options.remoteFunc"
61
- style="width:100%;"
62
- placeholder="请选择远端方法"
60
+ style="width:100%"
61
+ v-model="widget.options.remoteFunc"
62
+ placeholder="请选择"
63
+ no-data-text="暂无数据,请查阅相关文档说明"
64
+ clearable
65
+ filterable
66
+ >
67
+ <el-option
68
+ v-for="item in apiOptions"
69
+ :key="item.id"
70
+ :label="item.name"
71
+ :value="item.id"
63
72
  >
64
- <el-option
65
- v-for="item in apiOptions"
66
- :key="item.id"
67
- :label="item.name"
68
- :value="item.id"
69
- >
70
- </el-option>
71
- </el-select>
73
+ </el-option>
74
+ </el-select>
72
75
 
73
76
  <!-- <el-input size="mini" style="" v-model="widget.options.props.value">
74
77
  <template slot="prepend">
@@ -75,9 +75,12 @@
75
75
  </el-radio-group>
76
76
  <el-select
77
77
  v-if="widget.options.remote"
78
- v-model="widget.options.remoteFunc"
79
78
  style="width:100%"
80
- placeholder="请选择远端方法"
79
+ v-model="widget.options.remoteFunc"
80
+ placeholder="请选择"
81
+ no-data-text="暂无数据,请查阅相关文档说明"
82
+ clearable
83
+ filterable
81
84
  >
82
85
  <el-option
83
86
  v-for="item in apiOptions"
@@ -33,28 +33,29 @@ export default {
33
33
  this.axios = Axios.init(JSON.parse(oauthConfig));
34
34
  },
35
35
  methods: {
36
- hendleRemoteData() {
37
- const remoteFunc = this.widget.options.remoteFunc;
38
- const requestConfig = {
39
- url: `/lc/api${remoteFunc.url}`,
40
- method: remoteFunc.method,
41
- headers: remoteFunc.headers
42
- };
43
- let params = { ...remoteFunc.params };
44
- if (remoteFunc.needPage) {
45
- params.pageNum = 1;
46
- params.pageSize = 20;
47
- }
48
- if (remoteFunc.method.toLowerCase() === "get") {
49
- requestConfig.params = params;
50
- } else {
51
- params = Object.assign(params, this.models);
52
- requestConfig.data = params;
53
- }
54
- this.axios(requestConfig).then(res => {
55
- this.$emit("button-submit", requestConfig);
56
- });
57
- }
36
+ // hendleRemoteData() {
37
+ // const remoteFunc = this.config.network[this.widget.options.remoteFunc];
38
+ // console.log(remoteFunc);
39
+ // const requestConfig = {
40
+ // url: remoteFunc.url,
41
+ // method: remoteFunc.method,
42
+ // headers: remoteFunc.headers
43
+ // };
44
+ // let params = { ...remoteFunc.params };
45
+ // if (remoteFunc.needPage) {
46
+ // params.pageNum = 1;
47
+ // params.pageSize = 20;
48
+ // }
49
+ // if (remoteFunc.method.toLowerCase() === "get") {
50
+ // requestConfig.params = params;
51
+ // } else {
52
+ // params = Object.assign(params, this.models);
53
+ // requestConfig.data = params;
54
+ // }
55
+ // this.axios(requestConfig).then(res => {
56
+ // this.$emit("button-submit", requestConfig);
57
+ // });
58
+ // }
58
59
  }
59
60
  };
60
61
  </script>
@@ -81,7 +81,8 @@ export const eventMixin = {
81
81
  }
82
82
  }
83
83
  if (this.widget.type === "button") {
84
- this.hendleRemoteData();
84
+ this.$emit("button-submit", this.widget.options.remoteFunc);
85
+ // this.hendleRemoteData();
85
86
  return;
86
87
  }
87
88
  },
@@ -65,3 +65,34 @@ export const deepClone = (obj, clone) => {
65
65
  }
66
66
  return clone;
67
67
  };
68
+
69
+ // 链式读取对象属性
70
+ export const getProperty = (obj = {}, str = "") => {
71
+ let dic = deepClone(obj);
72
+ const props = str.replace(/\[(\w+)\]/g, ".$1"); // 处理数组下标
73
+ const keys = props.split(".");
74
+ for (const key of keys) {
75
+ dic = dic[key] || "";
76
+ }
77
+ return dic;
78
+ };
79
+
80
+ // 链式设置对象属性
81
+ export const setProperty = (obj = {}, str = "", value = "", isClone) => {
82
+ let dic = isClone ? deepClone(obj) : obj;
83
+ let propValue = "";
84
+ const props = str.replace(/\[(\w+)\]/g, ".$1"); // 处理数组下标
85
+ const keys = props.split(".");
86
+ for (let i = 0; i < keys.length; i++) {
87
+ const key = keys[i];
88
+ if (keys.length === 1) {
89
+ dic[key] = value;
90
+ } else if (i === keys.length - 1) {
91
+ propValue[key] = value;
92
+ } else {
93
+ if (!dic[key]) dic[key] = {};
94
+ propValue = dic[key];
95
+ }
96
+ }
97
+ return dic;
98
+ };
@@ -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
  },
@@ -802,10 +805,12 @@ export default {
802
805
  return;
803
806
  }
804
807
 
805
- const initParams = (paramsList, pAlias) => {
808
+ const initParams = (paramsList, pAlias, bool) => {
806
809
  paramsList.forEach(item => {
807
- item.elType = "input";
808
- item.align = "left";
810
+ if (bool) {
811
+ item.elType = "input";
812
+ item.align = "left";
813
+ }
809
814
  item.pAlias = pAlias ? `${pAlias}.${item.alias}` : item.alias;
810
815
  if (item.children && item.children.length) {
811
816
  initParams(item.children, item.pAlias);
@@ -815,25 +820,27 @@ export default {
815
820
 
816
821
  if (this.config.table.fields.remote) {
817
822
  const callback = res => {
818
- api.inParams = res.inParams;
819
- api.outParams = res.outParams;
823
+ api.inParams = deepClone(res.inParams);
824
+ api.outParams = deepClone(res.outParams);
825
+ initParams(api.inParams, null, false);
826
+ initParams(api.outParams, null, false);
820
827
  if (isFields) {
821
828
  this.fieldsData.inParams = deepClone(res.inParams || []);
822
- initParams(this.fieldsData.inParams);
829
+ initParams(this.fieldsData.inParams, null, true);
823
830
  this.fieldsData.outParams = deepClone(res.outParams || []);
824
- initParams(this.fieldsData.outParams);
831
+ initParams(this.fieldsData.outParams, null, true);
825
832
  }
826
833
  };
827
834
  this.$emit("remote-params", apiId, callback);
828
- return;
829
- }
830
-
831
- if (isFields) {
832
- this.fieldsData.inParams = deepClone(api.inParams || []);
833
- initParams(this.fieldsData.inParams);
834
- this.fieldsData.outParams = deepClone(api.outParams || []);
835
- initParams(this.fieldsData.outParams);
836
- return;
835
+ } else {
836
+ initParams(deepClone(api.inParams), null, false);
837
+ initParams(deepClone(api.outParams), null, false);
838
+ if (isFields) {
839
+ this.fieldsData.inParams = deepClone(api.inParams || []);
840
+ initParams(this.fieldsData.inParams, null, true);
841
+ this.fieldsData.outParams = deepClone(api.outParams || []);
842
+ initParams(this.fieldsData.outParams, null, true);
843
+ }
837
844
  }
838
845
  },
839
846
  handleTreeCheckChange(action) {