tianheng-ui 0.1.47 → 0.1.49

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.47",
4
+ "version": "0.1.49",
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 {
@@ -222,7 +222,7 @@ export default {
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,10 +231,10 @@ 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}`) ||
237
- null;
234
+ const value =
235
+ getProperty(this.models, e.pAlias) ||
236
+ getProperty(this.query, e.pAlias);
237
+ setProperty(params, e.pAlias, value || null);
238
238
  }
239
239
  if (api.needPage) {
240
240
  params.pageNum = 1;
@@ -255,7 +255,43 @@ export default {
255
255
  });
256
256
  },
257
257
  handleButtonSubmit(val) {
258
- this.$emit("button-submit", val);
258
+ const api = this.formConfig.config.network[val];
259
+ if (!api) return this.$message.warning("未知的接口,请检查配置信息");
260
+
261
+ const requestConfig = {
262
+ url: api.url,
263
+ method: api.method,
264
+ headers: api.headers
265
+ };
266
+
267
+ let params = {};
268
+ const inParams = api.inParams;
269
+ const initParams = list => {
270
+ list.map(item => {
271
+ if (item.children) {
272
+ initParams(item.children);
273
+ } else {
274
+ const value = getProperty(this.models, item.pAlias);
275
+ setProperty(params, item.pAlias, value);
276
+ }
277
+ });
278
+ };
279
+ initParams(inParams);
280
+
281
+ if (api.needPage) {
282
+ params.pageNum = 1;
283
+ params.pageSize = 20;
284
+ }
285
+ if (["get", "delete"].includes(api.method.toLowerCase()))
286
+ requestConfig.params = params;
287
+ else requestConfig.data = params;
288
+
289
+ this.$refs.generateForm.validate(valid => {
290
+ if (!valid) return;
291
+ this.axios(requestConfig).then(res => {
292
+ this.$emit("button-submit", requestConfig);
293
+ });
294
+ });
259
295
  },
260
296
  getData() {
261
297
  return new Promise((resolve, reject) => {
@@ -196,9 +196,10 @@
196
196
  <el-select
197
197
  v-model="config.fields.api"
198
198
  style="width:100%"
199
- clearable
200
199
  placeholder="请选择"
201
200
  no-data-text="暂无接口,请前往【数据源模块】创建"
201
+ clearable
202
+ filterable
202
203
  >
203
204
  <el-option
204
205
  v-for="item in apiOptions"
@@ -577,23 +578,22 @@ export default {
577
578
  },
578
579
  handleFieldsApiChange(apiId, isFields) {
579
580
  if (isFields) this.fieldsData = { inParams: [], outParams: [] };
581
+ if (!this.apiOptions.length || !apiId) return;
580
582
 
581
- if (!this.apiOptions.length || !this.config.fields.api || !apiId) {
582
- return;
583
- }
584
583
  const api = this.apiOptions.filter(item => {
585
584
  return item.id === apiId;
586
585
  })[0];
587
-
588
586
  if (!api) {
589
- this.$message.warning("未知的接口名,请检查配置信息");
587
+ this.$message.warning("未知的接口,请检查配置信息");
590
588
  return;
591
589
  }
592
590
 
593
- const initParams = (paramsList, pAlias) => {
591
+ const initParams = (paramsList, pAlias, bool) => {
594
592
  paramsList.forEach(item => {
595
- item.elType = "input";
596
- item.align = "left";
593
+ if (bool) {
594
+ item.elType = "input";
595
+ item.align = "left";
596
+ }
597
597
  item.pAlias = pAlias ? `${pAlias}.${item.alias}` : item.alias;
598
598
  if (item.children && item.children.length) {
599
599
  initParams(item.children, item.pAlias);
@@ -603,25 +603,28 @@ export default {
603
603
 
604
604
  if (this.config.fields.remote) {
605
605
  const callback = res => {
606
- api.inParams = res.inParams;
607
- 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
+
608
611
  if (isFields) {
609
612
  this.fieldsData.inParams = deepClone(res.inParams || []);
610
- initParams(this.fieldsData.inParams);
613
+ initParams(this.fieldsData.inParams, null, true);
611
614
  this.fieldsData.outParams = deepClone(res.outParams || []);
612
- initParams(this.fieldsData.outParams);
615
+ initParams(this.fieldsData.outParams, null, true);
613
616
  }
614
617
  };
615
618
  this.$emit("remote-params", apiId, callback);
616
- return;
617
- }
618
-
619
- if (isFields) {
620
- this.fieldsData.inParams = deepClone(api.inParams || []);
621
- initParams(this.fieldsData.inParams);
622
- this.fieldsData.outParams = deepClone(api.outParams || []);
623
- initParams(this.fieldsData.outParams);
624
- 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
+ }
625
628
  }
626
629
  },
627
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
+ };
@@ -102,6 +102,7 @@
102
102
  placeholder="请选择"
103
103
  no-data-text="暂无接口,请前往【接口模块】创建"
104
104
  filterable
105
+ @change="handleResetTableFields"
105
106
  >
106
107
  <el-option
107
108
  v-for="item in apiOptions"
@@ -782,28 +783,31 @@ export default {
782
783
  },
783
784
  mounted() {},
784
785
  methods: {
786
+ handleResetTableFields() {
787
+ this.config.search.options = [];
788
+ this.config.table.options = [];
789
+ },
785
790
  handleActionConfig(data) {
786
791
  this.dialog = { show: true, data };
787
792
  },
788
793
  handleFieldsApiChange(apiId, isFields) {
789
- if (isFields) {
790
- // this.config.search.options = [];
791
- // this.config.table.options = [];
792
- this.fieldsData = { inParams: [], outParams: [] };
793
- }
794
- if (!apiId) return;
794
+ if (isFields) this.fieldsData = { inParams: [], outParams: [] };
795
+ if (!this.apiOptions.length || !apiId) return;
796
+
795
797
  const api = this.apiOptions.filter(item => {
796
798
  return item.id === apiId;
797
799
  })[0];
798
800
  if (!api) {
799
- this.$message.warning("未知的接口名,请检查配置信息");
801
+ this.$message.warning("未知的接口,请检查配置信息");
800
802
  return;
801
803
  }
802
804
 
803
- const initParams = (paramsList, pAlias) => {
805
+ const initParams = (paramsList, pAlias, bool) => {
804
806
  paramsList.forEach(item => {
805
- item.elType = "input";
806
- item.align = "left";
807
+ if (bool) {
808
+ item.elType = "input";
809
+ item.align = "left";
810
+ }
807
811
  item.pAlias = pAlias ? `${pAlias}.${item.alias}` : item.alias;
808
812
  if (item.children && item.children.length) {
809
813
  initParams(item.children, item.pAlias);
@@ -815,23 +819,25 @@ export default {
815
819
  const callback = res => {
816
820
  api.inParams = res.inParams;
817
821
  api.outParams = res.outParams;
822
+ initParams(api.inParams, null, false);
823
+ initParams(api.outParams, null, false);
818
824
  if (isFields) {
819
825
  this.fieldsData.inParams = deepClone(res.inParams || []);
820
- initParams(this.fieldsData.inParams);
826
+ initParams(this.fieldsData.inParams, null, true);
821
827
  this.fieldsData.outParams = deepClone(res.outParams || []);
822
- initParams(this.fieldsData.outParams);
828
+ initParams(this.fieldsData.outParams, null, true);
823
829
  }
824
830
  };
825
831
  this.$emit("remote-params", apiId, callback);
826
- return;
827
- }
828
-
829
- if (isFields) {
830
- this.fieldsData.inParams = deepClone(api.inParams || []);
831
- initParams(this.fieldsData.inParams);
832
- this.fieldsData.outParams = deepClone(api.outParams || []);
833
- initParams(this.fieldsData.outParams);
834
- return;
832
+ } else {
833
+ initParams(api.inParams, null, false);
834
+ initParams(api.outParams, null, false);
835
+ if (isFields) {
836
+ this.fieldsData.inParams = deepClone(api.inParams || []);
837
+ initParams(this.fieldsData.inParams, null, true);
838
+ this.fieldsData.outParams = deepClone(api.outParams || []);
839
+ initParams(this.fieldsData.outParams, null, true);
840
+ }
835
841
  }
836
842
  },
837
843
  handleTreeCheckChange(action) {
@@ -47,7 +47,7 @@
47
47
  >
48
48
  <div
49
49
  v-for="item in config.search.options"
50
- :key="item.pAlias"
50
+ :key="item.id"
51
51
  class="table-item"
52
52
  >
53
53
  <div class="table-item-custom drag">
@@ -135,7 +135,7 @@
135
135
  >
136
136
  <div
137
137
  v-for="item in config.table.options"
138
- :key="item.pAlias"
138
+ :key="item.id"
139
139
  class="table-item"
140
140
  >
141
141
  <div class="table-item-custom drag">