tianheng-ui 0.1.27 → 0.1.28

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.27",
4
+ "version": "0.1.28",
5
5
  "author": "shu lang <403732931@qq.com>",
6
6
  "license": "MIT",
7
7
  "private": false,
@@ -46,7 +46,7 @@
46
46
  @change="handleFieldsApiChange"
47
47
  >
48
48
  <el-option
49
- v-for="item in config.network"
49
+ v-for="item in apiOptions"
50
50
  :key="item.id"
51
51
  :label="item.label"
52
52
  :value="item.id"
@@ -127,7 +127,7 @@
127
127
 
128
128
  <script>
129
129
  export default {
130
- props: ["config"],
130
+ props: ["config", "apiOptions"],
131
131
  data() {
132
132
  return {
133
133
  collapseValue: [
@@ -150,22 +150,8 @@ export default {
150
150
  };
151
151
  },
152
152
  methods: {
153
- handleFieldsApiChange(val) {
154
- const dataArr = this.config.network.filter(item => {
155
- return item.id === val;
156
- });
157
- if (dataArr.length && dataArr[0].paramsOut) {
158
- const fields = dataArr[0].paramsOut.map(item => {
159
- return {
160
- label: item.note || item.name,
161
- alias: item.name,
162
- prop: item.name,
163
- type: "input",
164
- align: "left"
165
- };
166
- });
167
- this.$emit("fieldsChange", fields);
168
- } else this.$emit("fieldsChange", []);
153
+ handleFieldsApiChange() {
154
+ this.$emit("fieldsChange");
169
155
  },
170
156
  formValidate() {
171
157
  return new Promise((resolve, reject) => {
@@ -117,7 +117,7 @@ export default {
117
117
  },
118
118
  watch: {
119
119
  config(val) {
120
- this.setJSON(val);
120
+ this.setConfig(val);
121
121
  },
122
122
  formJson: {
123
123
  handler(val) {
@@ -262,7 +262,7 @@ export default {
262
262
  onInputChange(value, field) {
263
263
  this.$emit("on-change", field, value, this.models);
264
264
  },
265
- setJSON(json) {
265
+ setConfig(json) {
266
266
  this.formJson = json;
267
267
  this.generateModle(this.formJson.list);
268
268
  }
@@ -66,12 +66,12 @@
66
66
  <el-tooltip
67
67
  slot="label"
68
68
  effect="dark"
69
- content="表单提交时的入参名,对应数据表中的字段"
69
+ content="表单提交时的入参名,对应数据表中的字段,非必要不修改!"
70
70
  placement="top"
71
71
  >
72
72
  <span style="color: #409EFF;">字段标识</span>
73
73
  </el-tooltip>
74
- <el-input v-model="data.model" readonly></el-input>
74
+ <el-input v-model="data.model"></el-input>
75
75
  </el-form-item>
76
76
  </el-collapse-item>
77
77
 
@@ -772,29 +772,32 @@ export const layoutComponents = [
772
772
  export const templateComponents = [];
773
773
 
774
774
  export const baseConfig = {
775
- fieldsType: "fieldsApi",
776
- fieldsApi: "",
777
- ui: "element",
778
- title: "",
779
- width: "",
780
- labelWidth: 100,
781
- labelPosition: "right",
782
- labelSuffix: ":",
783
- size: "small",
784
- disabled: false,
785
- hideLabel: false,
786
- mounted: { api: "" },
787
- eventScript: [
788
- {
789
- id: "mounted",
790
- label: "mounted",
791
- value: ""
792
- },
793
- {
794
- id: "refresh",
795
- label: "refresh",
796
- value: ""
797
- }
798
- ],
799
- network: []
775
+ list: [],
776
+ config: {
777
+ fieldsType: "fieldsApi",
778
+ fieldsApi: "",
779
+ ui: "element",
780
+ title: "",
781
+ width: "",
782
+ labelWidth: 100,
783
+ labelPosition: "right",
784
+ labelSuffix: ":",
785
+ size: "small",
786
+ disabled: false,
787
+ hideLabel: false,
788
+ mounted: { api: "" },
789
+ eventScript: [
790
+ {
791
+ id: "mounted",
792
+ label: "mounted",
793
+ value: ""
794
+ },
795
+ {
796
+ id: "refresh",
797
+ label: "refresh",
798
+ value: ""
799
+ }
800
+ ],
801
+ network: []
802
+ }
800
803
  };
@@ -158,6 +158,7 @@
158
158
  <form-config
159
159
  v-if="configTab == 'form'"
160
160
  :config="formConfig.config"
161
+ :apiOptions="apiOptions"
161
162
  @fieldsChange="handleFieldsChange"
162
163
  ref="formConfigRef"
163
164
  ></form-config>
@@ -197,12 +198,7 @@ export default {
197
198
  GenerateForm
198
199
  },
199
200
  props: {
200
- config: {
201
- type: Object,
202
- default: () => {
203
- return { config: {}, list: [] };
204
- }
205
- },
201
+ config: Object,
206
202
  oauthConfig: {
207
203
  type: Object,
208
204
  default: () => {
@@ -261,7 +257,7 @@ export default {
261
257
  this.layoutComponents = layoutComponents;
262
258
  this.baseConfig = deepClone(baseConfig);
263
259
  return {
264
- formConfig: this.config,
260
+ formConfig: this.baseConfig,
265
261
  widgetFormSelect: {},
266
262
  widgetValue: {},
267
263
  configTab: "form",
@@ -294,27 +290,18 @@ export default {
294
290
  deep: true,
295
291
  handler: function(val) {
296
292
  this.$emit("update:config", val);
297
- // this.$emit("on-change", val);
298
293
  }
299
294
  },
300
295
  config(val) {
301
- if (val && val.config) {
302
- val.config = Object.assign(this.baseConfig, val.config);
303
- }
304
- this.setJSON(val);
296
+ this.setConfig(val);
305
297
  },
306
- apiOptions(val) {
307
- if (val) {
308
- this.formConfig.config.network = val;
309
- }
298
+ apiOptions() {
299
+ this.handleFieldsChange();
310
300
  }
311
301
  },
312
302
  created() {
313
303
  this.initConfig();
314
- this.formConfig.config = Object.assign(
315
- this.baseConfig,
316
- this.formConfig.config
317
- );
304
+ this.formConfig = Object.assign(this.baseConfig, this.config);
318
305
 
319
306
  if (this.formConfig.list && this.formConfig.list.length) {
320
307
  this.widgetFormSelect = this.formConfig.list[0];
@@ -372,7 +359,7 @@ export default {
372
359
  case "import-excel":
373
360
  case "import-json":
374
361
  case "import-template":
375
- this.setJSON(data);
362
+ this.setConfig(data);
376
363
  break;
377
364
  case "clear":
378
365
  this.handleClear();
@@ -385,8 +372,21 @@ export default {
385
372
  handleWidgetConfigUpdate(val) {
386
373
  this.widgetFormSelect = Object.assign(this.widgetFormSelect, val);
387
374
  },
388
- handleFieldsChange(val) {
389
- this.fields = val;
375
+ handleFieldsChange() {
376
+ const dataArr = this.apiOptions.filter(item => {
377
+ return item.id === this.formConfig.config.fieldsApi;
378
+ });
379
+ if (dataArr.length && dataArr[0].paramsOut) {
380
+ this.fields = dataArr[0].paramsOut.map(item => {
381
+ return {
382
+ label: item.note || item.name,
383
+ alias: item.name,
384
+ prop: item.name,
385
+ type: "input",
386
+ align: "left"
387
+ };
388
+ });
389
+ } else this.fields = [];
390
390
  },
391
391
  clear() {
392
392
  this.handleClear();
@@ -397,6 +397,7 @@ export default {
397
397
  this.$refs.formConfigRef.formValidate().then(res => {
398
398
  if (res) {
399
399
  const data = deepClone(this.formConfig);
400
+ data.config.network = this.apiOptions;
400
401
  resolve(data);
401
402
  } else {
402
403
  reject();
@@ -418,6 +419,7 @@ export default {
418
419
  return reject();
419
420
  }
420
421
  const data = deepClone(this.formConfig);
422
+ data.config.network = this.apiOptions;
421
423
  resolve(data);
422
424
  });
423
425
  }
@@ -425,12 +427,14 @@ export default {
425
427
  getHtml() {
426
428
  return generateCode(JSON.stringify(this.formConfig));
427
429
  },
428
- setJSON(json) {
429
- this.formConfig = json;
430
+ setConfig(val) {
431
+ this.formConfig = Object.assign(this.baseConfig, val);
430
432
 
431
- if (json.list.length > 0) {
432
- this.widgetFormSelect = json.list[0];
433
+ if (this.formConfig.list.length > 0) {
434
+ this.widgetFormSelect = this.formConfig.list[0];
433
435
  }
436
+
437
+ this.handleFieldsChange();
434
438
  }
435
439
  }
436
440
  };
@@ -35,7 +35,6 @@
35
35
  type="text"
36
36
  size="medium"
37
37
  icon="el-icon-view"
38
- disabled
39
38
  @click="handleDialogOpen('preview')"
40
39
  >预览
41
40
  </el-button>
@@ -129,7 +128,9 @@
129
128
  @on-close="handleDialogClose"
130
129
  @on-affirm="handleDialogAffirm"
131
130
  >
132
- <template v-if="dialog.action === 'preview'"></template>
131
+ <template v-if="dialog.action === 'preview'">
132
+ <th-table-generate :config="config"> </th-table-generate>
133
+ </template>
133
134
  <template v-else-if="dialog.action === 'importJson'">
134
135
  <el-alert
135
136
  type="info"
@@ -94,6 +94,7 @@ export default {
94
94
  name: "thTableGenerate",
95
95
  components: { Search, Tools },
96
96
  props: {
97
+ config: Object,
97
98
  oauthConfig: {
98
99
  type: Object,
99
100
  default: () => {
@@ -144,17 +145,25 @@ export default {
144
145
  errorMessage: ""
145
146
  };
146
147
  },
147
- created() {
148
- this.axios = Axios.init(this.oauthConfig);
149
- const code = this.$route.path.split("/").pop();
150
- this.id = code;
148
+ watch: {
149
+ config(val) {
150
+ this.tableJson = val;
151
+ this.initConfig();
152
+ },
153
+ oauthConfig(val) {
154
+ this.initAxios();
155
+ }
156
+ },
157
+ created() {},
158
+ mounted() {
159
+ this.tableJson = this.config;
160
+ this.initAxios();
151
161
  this.initConfig();
152
162
  },
153
- mounted() {},
154
163
  methods: {
155
- // 初始化组件配置
156
- initConfig() {
157
- this.initData();
164
+ // 初始组件网络
165
+ initAxios() {
166
+ this.axios = Axios.init(this.oauthConfig);
158
167
 
159
168
  if (this.oauthConfig.token) {
160
169
  const oauthInfo = {
@@ -162,11 +171,6 @@ export default {
162
171
  baseUrl: this.oauthConfig.baseUrl
163
172
  };
164
173
  sessionStorage.setItem("th_oauth_info", JSON.stringify(oauthInfo));
165
- }
166
-
167
- const info = sessionStorage.getItem("th_oauth_info");
168
- if (info) {
169
- this.requestConfigData();
170
174
  } else if (this.oauthConfig.oauth) {
171
175
  // 模拟授权认证流程
172
176
  this.axios({
@@ -181,93 +185,67 @@ export default {
181
185
  };
182
186
  sessionStorage.setItem("th_oauth_info", JSON.stringify(oauthInfo));
183
187
  // this.axios.defaults.baseURL = this.oauthConfig.baseUrl;
184
- this.requestConfigData();
185
188
  });
186
- } else {
187
- this.requestConfigData();
188
189
  }
189
190
  },
190
- initData() {
191
- this.tableJson = {};
192
- this.errorMessage = "";
193
- },
194
- // 获取配置信息
195
- requestConfigData() {
196
- this.axios({
197
- url: this.network.page.url,
198
- method: this.network.page.method,
199
- headers: this.network.page.headers,
200
- data: { ...this.network.page.params, moduleId: this.id }
201
- })
202
- .then(res => {
203
- const resultData = res.data;
204
- if (!resultData) {
205
- this.tableJson = null;
206
- return;
207
- }
208
- this.tableJson = JSON.parse(resultData.pageConfig);
209
- // 网络请求
210
- this.networkConfig = this.tableJson.network;
191
+ // 处理配置信息
192
+ initConfig() {
193
+ // 网络请求
194
+ this.networkConfig = this.tableJson.network;
211
195
 
212
- // 搜索栏
213
- this.searchConfig = this.tableJson.search;
214
- if (this.searchConfig.show) {
215
- this.searchConfig.options.map(item => {
216
- this.$set(this.searchData, item.prop, item.defaultValue || "");
217
- });
218
- }
196
+ // 搜索栏
197
+ this.searchConfig = this.tableJson.search;
198
+ if (this.searchConfig.show) {
199
+ this.searchConfig.options.map(item => {
200
+ this.$set(this.searchData, item.prop, item.defaultValue || "");
201
+ });
202
+ }
219
203
 
220
- // table
221
- for (let i = 0; i < this.tableJson.table.options.length; i++) {
222
- const element = this.tableJson.table.options[i];
223
- delete element.type;
224
- }
225
- if (this.tableJson.table.sequence) {
204
+ // table
205
+ for (let i = 0; i < this.tableJson.table.options.length; i++) {
206
+ const element = this.tableJson.table.options[i];
207
+ delete element.type;
208
+ }
209
+ if (this.tableJson.table.sequence) {
210
+ this.tableJson.table.options.unshift({
211
+ type: "index",
212
+ label: "序号"
213
+ });
214
+ }
215
+ const action = {
216
+ label: "操作",
217
+ hide: true,
218
+ slot: "action",
219
+ fixed: "right",
220
+ actions: []
221
+ };
222
+
223
+ // 按position处理按钮,1:公共区,2:行内区
224
+ for (const key in this.tableJson.tools) {
225
+ if (Object.hasOwnProperty.call(this.tableJson.tools, key)) {
226
+ const element = this.tableJson.tools[key];
227
+ if (!element.show) continue;
228
+ if (key === "batchDelete") {
226
229
  this.tableJson.table.options.unshift({
227
- type: "index",
228
- label: "序号"
230
+ type: "selection"
229
231
  });
230
232
  }
231
- const action = {
232
- label: "操作",
233
- hide: true,
234
- slot: "action",
235
- fixed: "right",
236
- actions: []
237
- };
238
-
239
- // 按position处理按钮,1:公共区,2:行内区
240
- for (const key in this.tableJson.tools) {
241
- if (Object.hasOwnProperty.call(this.tableJson.tools, key)) {
242
- const element = this.tableJson.tools[key];
243
- if (!element.show) continue;
244
- if (key === "batchDelete") {
245
- this.tableJson.table.options.unshift({
246
- type: "selection"
247
- });
248
- }
249
- const dic = toolsItemConfig(key, element);
250
- dic.form = element.form;
251
- if (element.position === 1 || element.position === 'header') {
252
- this.toolsConfig.show = true;
253
- this.toolsConfig.options.push(dic);
254
- } else if (element.position === 2 || element.position === 'row') {
255
- action.hide = false;
256
- action.actions.push(dic);
257
- }
258
- }
233
+ const dic = toolsItemConfig(key, element);
234
+ dic.form = element.form;
235
+ if (element.position === 1 || element.position === "header") {
236
+ this.toolsConfig.show = true;
237
+ this.toolsConfig.options.push(dic);
238
+ } else if (element.position === 2 || element.position === "row") {
239
+ action.hide = false;
240
+ action.actions.push(dic);
259
241
  }
260
- action.width = action.actions.length * 60 + 20;
261
- this.tableJson.table.options.push(action);
242
+ }
243
+ }
244
+ action.width = action.actions.length * 60 + 20;
245
+ this.tableJson.table.options.push(action);
262
246
 
263
- this.tableConfig = this.tableJson.table;
264
- this.requestListData();
265
- })
266
- .catch(err => {
267
- this.errorMessage = err.message;
268
- this.tableJson = null;
269
- this.$emit("error");
270
- });
247
+ this.tableConfig = this.tableJson.table;
248
+ this.requestListData();
271
249
  },
272
250
  requestListData() {
273
251
  if (!this.networkConfig.mounted) return;
@@ -30,18 +30,13 @@
30
30
  import WidgetTools from "./WidgetTools.vue";
31
31
  import WidgetTable from "./widgetTable.vue";
32
32
  import WidgetConfig from "./widgetConfig.vue";
33
- import { deepClone, deepMerge } from "./util/index";
33
+ import { deepClone } from "./util/index";
34
34
  import { baseConfig } from "./custom/config";
35
35
  export default {
36
36
  name: "ThTableMaking",
37
37
  components: { WidgetTools, WidgetTable, WidgetConfig },
38
38
  props: {
39
- config: {
40
- type: Object,
41
- default: () => {
42
- return {};
43
- }
44
- },
39
+ config: Object,
45
40
 
46
41
  /**
47
42
  * 表单配置列表。
@@ -88,7 +83,7 @@ export default {
88
83
  data() {
89
84
  this.baseConfig = deepClone(baseConfig);
90
85
  return {
91
- tableConfig: this.config,
86
+ tableConfig: this.baseConfig,
92
87
  client: "monitor"
93
88
  };
94
89
  },
@@ -108,7 +103,7 @@ export default {
108
103
  }
109
104
  },
110
105
  mounted() {
111
- this.tableConfig = Object.assign(this.baseConfig, this.tableConfig);
106
+ this.tableConfig = Object.assign(this.baseConfig, this.config);
112
107
  },
113
108
  methods: {
114
109
  handleNetwork() {
@@ -490,10 +490,14 @@ export default {
490
490
  },
491
491
  watch: {
492
492
  config(val) {
493
+ this.handleFieldsApiChange(val.table.mounted.api)
493
494
  this.handleFields();
494
495
  },
495
496
  fields(val) {
496
497
  this.handleFields();
498
+ },
499
+ apiOptions(){
500
+ this.handleFieldsApiChange(this.config.table.mounted.api)
497
501
  }
498
502
  },
499
503
  computed: {