tianheng-ui 0.1.48 → 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.48",
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,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
+ };
@@ -802,10 +802,12 @@ export default {
802
802
  return;
803
803
  }
804
804
 
805
- const initParams = (paramsList, pAlias) => {
805
+ const initParams = (paramsList, pAlias, bool) => {
806
806
  paramsList.forEach(item => {
807
- item.elType = "input";
808
- item.align = "left";
807
+ if (bool) {
808
+ item.elType = "input";
809
+ item.align = "left";
810
+ }
809
811
  item.pAlias = pAlias ? `${pAlias}.${item.alias}` : item.alias;
810
812
  if (item.children && item.children.length) {
811
813
  initParams(item.children, item.pAlias);
@@ -817,23 +819,25 @@ export default {
817
819
  const callback = res => {
818
820
  api.inParams = res.inParams;
819
821
  api.outParams = res.outParams;
822
+ initParams(api.inParams, null, false);
823
+ initParams(api.outParams, null, false);
820
824
  if (isFields) {
821
825
  this.fieldsData.inParams = deepClone(res.inParams || []);
822
- initParams(this.fieldsData.inParams);
826
+ initParams(this.fieldsData.inParams, null, true);
823
827
  this.fieldsData.outParams = deepClone(res.outParams || []);
824
- initParams(this.fieldsData.outParams);
828
+ initParams(this.fieldsData.outParams, null, true);
825
829
  }
826
830
  };
827
831
  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;
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
+ }
837
841
  }
838
842
  },
839
843
  handleTreeCheckChange(action) {