tianheng-ui 0.1.36 → 0.1.37

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.
@@ -5,8 +5,8 @@
5
5
  v-if="searchConfig.show"
6
6
  :data="searchData"
7
7
  :options="searchConfig.options"
8
- @search="requestListData"
9
- @reset="requestListData"
8
+ @search="handleSearchSubmit"
9
+ @reset="handleSearchReset"
10
10
  />
11
11
 
12
12
  <!-- 菜单栏 -->
@@ -17,45 +17,36 @@
17
17
  batchDelete: tableSelectionData.length === 0,
18
18
  export: tableSelectionData.length === 0
19
19
  }"
20
- @click="handleToolsClick"
20
+ @click="handleActionClick"
21
21
  />
22
22
 
23
- <STable v-if="tableConfig" :data="tableData" :config="tableConfig"></STable>
24
-
25
- <!-- 表格 -->
26
- <!-- <th-table
27
- v-if="tableConfig.options.length"
28
- ref="tableRef"
29
- :data="tableData"
30
- :options="tableConfig.options"
31
- :page-info="tableConfig.pageInfo.options"
32
- :show-page="tableConfig.pageInfo.show"
33
- :loading="tableConfig.loading.show"
34
- :loading-text="tableConfig.loading.text"
35
- :empty-text="tableConfig.empty.text"
36
- select-type="single"
37
- border
38
- @selection-change="handleSelectionChange"
39
- @pagination-change="handlePagingChange"
40
- >
41
- <template #action="{scope, option }">
42
- <th-table-action
43
- :actions="option.actions"
44
- @on-click="
45
- (action, callback) => {
46
- handleActionClick(
47
- scope.$index,
48
- scope.row,
49
- action,
50
- callback,
51
- option
52
- );
53
- }
54
- "
55
- >
56
- </th-table-action>
57
- </template>
58
- </th-table> -->
23
+ <template v-if="tableConfig">
24
+ <!-- 表格 -->
25
+ <STable :data="tableData" :config="tableConfig">
26
+ <template #action="{scope, option }">
27
+ <actions
28
+ :scope="scope"
29
+ :options="option.actions"
30
+ @click="handleActionClick"
31
+ ></actions>
32
+ </template>
33
+ </STable>
34
+
35
+ <!-- 分页 -->
36
+ <el-pagination
37
+ v-if="tableConfig.pageInfo.show"
38
+ :style="{ 'text-align': tableConfig.pageInfo.style.align }"
39
+ :small="tableConfig.pageInfo.style.small"
40
+ :background="tableConfig.pageInfo.style.background"
41
+ :disabled="tableConfig.pageInfo.style.disabled"
42
+ :hide-on-single-page="tableConfig.pageInfo.style.hideOnSinglePage"
43
+ :page-size="tableConfig.pageInfo.options.pageSize"
44
+ :page-sizes="tableConfig.pageInfo.options.sizes"
45
+ :layout="tableConfig.pageInfo.options.layout"
46
+ :total="1000"
47
+ >
48
+ </el-pagination>
49
+ </template>
59
50
 
60
51
  <!-- 表单 -->
61
52
  <th-dialog
@@ -67,9 +58,8 @@
67
58
  >
68
59
  <th-form-generate
69
60
  v-if="formConfig"
70
- :data="formConfig"
61
+ :config="formConfig"
71
62
  :value="dialog.data"
72
- :remoteData="remoteData"
73
63
  ref="formGenerate"
74
64
  >
75
65
  </th-form-generate>
@@ -91,10 +81,12 @@
91
81
  import Search from "./custom/items/search/index-pc.vue";
92
82
  import Tools from "./custom/items/tools/index-pc.vue";
93
83
  import STable from "./custom/items/table/index-pc.vue";
84
+ import Actions from "./custom/items/actions/index-pc.vue";
94
85
  import * as Axios from "lib/theme-chalk/js/axios";
86
+ import { deepClone } from "../FormMaking/util";
95
87
  export default {
96
88
  name: "thTableGenerate",
97
- components: { Search, Tools, STable },
89
+ components: { Search, Tools, STable, Actions },
98
90
  props: {
99
91
  config: Object,
100
92
  oauthConfig: {
@@ -116,13 +108,13 @@ export default {
116
108
  default: () => {
117
109
  return {
118
110
  page: {
119
- url: "/preview/getViewManageDetailById",
111
+ url: "/api/lc/viewManage/getOne",
120
112
  method: "POST",
121
113
  params: {}
122
114
  },
123
115
  form: {
124
- url: "/formManage/getFormDetailById",
125
- method: "POST",
116
+ url: "/api/lc/formConfig/getById",
117
+ method: "get",
126
118
  params: {}
127
119
  }
128
120
  };
@@ -139,21 +131,13 @@ export default {
139
131
  searchData: {},
140
132
  toolsConfig: { show: false, options: [] },
141
133
  tableConfig: null,
142
- tableData: [
143
- { id: 1 },
144
- { id: 2 },
145
- { id: 3 },
146
- { id: 4 },
147
- { id: 5 },
148
- { id: 6 },
149
- { id: 7 },
150
- { id: 8 }
151
- ],
134
+ tableData: [],
152
135
  tableSelectionData: [],
136
+ tableActionsConfig: {},
153
137
  dialog: { show: false, data: {}, action: {} },
154
138
  formConfig: null,
155
- remoteData: {},
156
- errorMessage: ""
139
+ errorMessage: "",
140
+ query: {}
157
141
  };
158
142
  },
159
143
  watch: {
@@ -165,7 +149,9 @@ export default {
165
149
  this.initAxios();
166
150
  }
167
151
  },
168
- created() {},
152
+ created() {
153
+ this.query = this.$route.query;
154
+ },
169
155
  mounted() {
170
156
  this.tableJson = this.config;
171
157
  this.initAxios();
@@ -201,18 +187,20 @@ export default {
201
187
  },
202
188
  // 处理配置信息
203
189
  initConfig() {
190
+ if (!this.tableJson.table) return;
191
+
204
192
  // 网络请求
205
- this.networkConfig = this.tableJson.network;
193
+ this.networkConfig = deepClone(this.tableJson.network);
206
194
 
207
195
  // 搜索栏
208
- this.searchConfig = this.tableJson.search;
196
+ this.searchConfig = deepClone(this.tableJson.search);
209
197
  this.searchConfig.options.map(item => {
210
198
  this.$set(this.searchData, item.prop, item.defaultValue || "");
211
199
  });
212
200
 
213
201
  // table
214
- this.tableConfig = this.tableJson.table;
215
- if (this.tableConfig.sequence) {
202
+ this.tableConfig = deepClone(this.tableJson.table);
203
+ if (this.tableJson.table.sequence) {
216
204
  this.tableConfig.options.unshift({
217
205
  type: "index",
218
206
  label: "序号"
@@ -228,8 +216,9 @@ export default {
228
216
 
229
217
  // tools
230
218
  this.toolsConfig = { show: false, options: [] };
219
+
231
220
  // 按position处理按钮,1:公共区,2:行内区
232
- Object.values(this.tableJson.tools).map(item => {
221
+ Object.values(deepClone(this.tableJson.tools)).map(item => {
233
222
  if (!item.show) return;
234
223
  if (item.type === "batchDelete") {
235
224
  this.tableConfig.options.unshift({
@@ -245,27 +234,42 @@ export default {
245
234
  }
246
235
  });
247
236
  action.width = action.actions.length * 60 + 20;
248
- if (!action.hide) this.tableConfig.options.push(action);
237
+ if (!action.hide && action.actions.length)
238
+ this.tableConfig.options.push(action);
249
239
 
250
- // this.requestListData();
240
+ this.requestListData();
251
241
  },
242
+
243
+ // 获取form表单配置
244
+ requestFormConfigData(action) {
245
+ const params = { ...this.network.page.params, id: action.form };
246
+ const config = {
247
+ url: this.network.form.url,
248
+ method: this.network.form.method,
249
+ headers: this.network.form.headers
250
+ };
251
+ if (config.method.toLowerCase() === "get") config.params = params;
252
+ else config.data = params;
253
+
254
+ this.axios(config)
255
+ .then(res => {
256
+ const data = res.data;
257
+ this.formConfig = JSON.parse(data.pageConfig);
258
+ })
259
+ .catch(err => {});
260
+ },
261
+
262
+ // 获取列表数据
252
263
  requestListData() {
253
- if (!this.networkConfig.mounted) return;
264
+ const requestConfig = this.requestInterceptors(
265
+ this.searchData,
266
+ this.tableConfig.mounted.api,
267
+ "list"
268
+ );
269
+ if (!requestConfig) return;
270
+
254
271
  this.tableConfig.loading.show = true;
255
- const apiInfo = this.networkConfig.mounted;
256
- const params = {
257
- ...this.searchData
258
- };
259
- if (this.tableConfig.pageInfo.show) {
260
- params.current = this.tableConfig.pageInfo.options.currentPage;
261
- params.size = this.tableConfig.pageInfo.options.pageSize;
262
- }
263
- this.axios({
264
- url: apiInfo.api,
265
- method: apiInfo.method,
266
- headers: apiInfo.headers,
267
- data: params
268
- })
272
+ this.axios(requestConfig)
269
273
  .then(res => {
270
274
  this.tableConfig.loading.show = false;
271
275
  let data = [];
@@ -281,16 +285,18 @@ export default {
281
285
  this.tableConfig.loading.show = false;
282
286
  });
283
287
  },
288
+
289
+ // 新增
284
290
  requestAddData(data) {
285
- if (!this.networkConfig.add) return;
291
+ const requestConfig = this.requestInterceptors(
292
+ data,
293
+ this.dialog.action.api,
294
+ this.dialog.action.type
295
+ );
296
+ if (!requestConfig) return;
297
+
286
298
  this.dialog.action.loading = true;
287
- const apiInfo = this.networkConfig.add;
288
- this.axios({
289
- url: apiInfo.api,
290
- method: apiInfo.method,
291
- headers: apiInfo.headers,
292
- data: { ...apiInfo.params, ...data }
293
- })
299
+ this.axios(requestConfig)
294
300
  .then(res => {
295
301
  this.dialog.action.loading = false;
296
302
  this.requestListData();
@@ -299,16 +305,18 @@ export default {
299
305
  this.dialog.action.loading = false;
300
306
  });
301
307
  },
308
+
309
+ // 编辑
302
310
  requestEditData(data) {
303
- if (!this.networkConfig.edit) return;
311
+ const requestConfig = this.requestInterceptors(
312
+ data,
313
+ this.dialog.action.api,
314
+ this.dialog.action.type
315
+ );
316
+ if (!requestConfig) return;
317
+
304
318
  this.dialog.action.loading = true;
305
- const apiInfo = this.networkConfig.edit;
306
- this.axios({
307
- url: apiInfo.api,
308
- method: apiInfo.method,
309
- headers: apiInfo.headers,
310
- data: { ...apiInfo.params, ...data }
311
- })
319
+ this.axios(requestConfig)
312
320
  .then(res => {
313
321
  this.dialog.action.loading = false;
314
322
  this.requestListData();
@@ -317,27 +325,34 @@ export default {
317
325
  this.dialog.action.loading = false;
318
326
  });
319
327
  },
320
- requestDeleteData(callback) {
321
- if (!this.networkConfig.delete) return;
322
- this.dialog.action.loading = true;
323
- const apiInfo = this.networkConfig.delete;
324
- this.axios({
325
- url: apiInfo.api,
326
- method: apiInfo.method,
327
- headers: apiInfo.headers,
328
- data: { ...apiInfo.params, id: this.dialog.data.id }
329
- })
328
+
329
+ // 删除
330
+ requestDeleteData(item, action, callback) {
331
+ const requestConfig = this.requestInterceptors(
332
+ item,
333
+ action.api,
334
+ action.type
335
+ );
336
+ action.loading = true;
337
+ this.axios(requestConfig)
330
338
  .then(res => {
331
- callback(true);
332
- this.dialog.action.loading = false;
339
+ action.loading = false;
333
340
  this.requestListData();
341
+ callback(true);
334
342
  })
335
343
  .catch(err => {
336
- this.dialog.action.loading = false;
344
+ action.loading = false;
345
+ callback(false);
337
346
  });
338
347
  },
348
+
349
+ // 批量删除
339
350
  requestBatchDeleteData() {
340
- if (!this.networkConfig.batchDelete) return;
351
+ const requestConfig = this.requestInterceptors(
352
+ this.dialog.data,
353
+ this.dialog.action.api,
354
+ this.dialog.action.type
355
+ );
341
356
  this.$confirm("确认删除多条数据吗?", "操作提示", {
342
357
  confirmButtonText: "删除",
343
358
  cancelButtonText: "取消",
@@ -345,17 +360,8 @@ export default {
345
360
  })
346
361
  .then(() => {
347
362
  this.dialog.action.loading = true;
348
- const data = [];
349
- for (const item of this.tableSelectionData) {
350
- data.push({ id: item.id });
351
- }
352
- const apiInfo = this.networkConfig.batchDelete;
353
- this.axios({
354
- url: apiInfo.api,
355
- method: apiInfo.method,
356
- headers: apiInfo.headers,
357
- data: { ...apiInfo.params, ...data }
358
- })
363
+
364
+ this.axios(requestConfig)
359
365
  .then(res => {
360
366
  callback(true);
361
367
  this.dialog.action.loading = false;
@@ -367,42 +373,87 @@ export default {
367
373
  })
368
374
  .catch(() => {});
369
375
  },
370
- requestFormConfigData(action) {
371
- this.axios({
372
- url: this.network.form.url,
373
- method: this.network.form.method,
374
- headers: this.network.form.headers,
375
- // data: { id: action.form.id }
376
- data: { ...this.network.page.params, id: this.id }
377
- })
378
- .then(res => {
379
- const data = res.data;
380
- data.forEach(item => {
381
- if (item.type === "0" && action.act === "add") {
382
- this.formConfig = JSON.parse(item.pageConfig);
383
- return;
384
- }
385
- if (item.type === "1" && action.act === "edit") {
386
- this.formConfig = JSON.parse(item.pageConfig);
387
- return;
388
- }
389
- });
390
- })
376
+
377
+ // 通用请求
378
+ requestApi(request, callback) {
379
+ if (!request) return;
380
+
381
+ this.axios(request)
382
+ .then(res => {})
391
383
  .catch(err => {});
392
384
  },
393
- handleSearchSubmit(val) {
385
+
386
+ // 请求拦截器,返回请求体
387
+ requestInterceptors(paramsData, networkId, actionType) {
388
+ const config = this.networkConfig[networkId];
389
+ if (!config) {
390
+ this.$message.error("未知的请求接口,请检查配置信息");
391
+ return;
392
+ }
393
+
394
+ const request = {
395
+ url: `api/lc/api/${config.url}`,
396
+ method: config.method,
397
+ headers: { ...config.headers, actionType }
398
+ };
399
+ let params = {};
400
+ switch (actionType) {
401
+ case "list":
402
+ for (let key of Object.keys(config.params)) {
403
+ params[key] = paramsData[key] || this.query[key];
404
+ }
405
+ if (this.tableConfig.pageInfo.show) {
406
+ params.current = this.tableConfig.pageInfo.options.currentPage;
407
+ params.size = this.tableConfig.pageInfo.options.pageSize;
408
+ }
409
+ break;
410
+ case "add":
411
+ case "edit":
412
+ case "delete":
413
+ for (let key of Object.keys(config.params)) {
414
+ params[key] = paramsData[key];
415
+ }
416
+ break;
417
+ case "batchDelete":
418
+ const ids = [];
419
+ for (const item of this.tableSelectionData) {
420
+ ids.push({ id: item.id });
421
+ }
422
+ params.ids = ids;
423
+ break;
424
+
425
+ default:
426
+ break;
427
+ }
428
+
429
+ if (config.method.toLowerCase() === "get") request.params = params;
430
+ else request.data = params;
431
+
432
+ return request;
433
+ },
434
+
435
+ // 搜索提交
436
+ handleSearchSubmit() {
394
437
  this.requestListData();
395
438
  },
396
- handleSearchReset(val) {
439
+ // 搜索重置
440
+ handleSearchReset() {
397
441
  this.requestListData();
398
442
  },
399
- handleToolsClick(action) {
400
- console.log("handleToolsClick =>", action);
443
+
444
+ // 操作事件
445
+ handleActionClick(action, item, callback) {
446
+ console.log("handleActionClick =>", action, item);
401
447
  switch (action.type) {
402
448
  case "add":
403
- this.dialog = { show: true, data: {}, action: action };
449
+ case "edit":
450
+ case "detail":
451
+ this.dialog = { show: true, data: item, action: action };
404
452
  this.requestFormConfigData(action);
405
453
  break;
454
+ case "delete":
455
+ this.requestDeleteData(item, action, callback);
456
+ break;
406
457
  case "batchDelete":
407
458
  this.dialog = { show: false, data: {}, action: action };
408
459
  this.requestBatchDeleteData();
@@ -422,36 +473,18 @@ export default {
422
473
  break;
423
474
  }
424
475
  },
425
- handleActionClick(index, item, action, callback) {
426
- console.log("handleActionClick =>", item, action);
427
- switch (action.act) {
428
- case "edit":
429
- this.dialog = { show: true, data: item, action: action };
430
- this.requestFormConfigData(action);
431
- break;
432
- case "detail":
433
- this.dialog = { show: true, data: item, action: action };
434
- this.requestFormConfigData(action);
435
- break;
436
- case "delete":
437
- this.dialog = { show: false, data: item, action: action };
438
- this.requestDeleteData(callback);
439
- break;
440
476
 
441
- default:
442
- break;
443
- }
444
- },
445
- handleDialogAffirm(val) {
477
+ // 弹窗确认
478
+ handleDialogAffirm() {
446
479
  this.$refs.formGenerate.getData().then(data => {
447
480
  console.log("handleDialogAffirm =>", data);
448
- switch (this.dialog.action.act) {
481
+ switch (this.dialog.action.type) {
449
482
  case "add":
450
483
  this.requestAddData(data);
451
484
  break;
452
485
  case "edit":
453
- this.dialog.data = Object.assign(this.dialog.data, data);
454
- this.requestEditData(this.dialog.data);
486
+ // this.dialog.data = Object.assign(this.dialog.data, data);
487
+ this.requestEditData(data);
455
488
  break;
456
489
 
457
490
  default:
@@ -461,9 +494,11 @@ export default {
461
494
  this.dialog.show = false;
462
495
  });
463
496
  },
497
+ // 弹窗关闭
464
498
  handleDialogClose() {
465
499
  this.formConfig = null;
466
500
  },
501
+
467
502
  handlePagingChange(val) {
468
503
  this.requestListData();
469
504
  },
@@ -139,19 +139,19 @@ export default {
139
139
  }
140
140
  })
141
141
  .catch(err => {
142
- if (!this.tableConfig.table.fieldsTable) {
142
+ if (!this.tableConfig.table.fieldsType) {
143
143
  this.$message.warning("请选择字段表");
144
144
  return reject();
145
145
  }
146
146
  if (
147
- this.tableConfig.table.fieldsTable === "fieldsApi" &&
147
+ this.tableConfig.table.fieldsType === "fieldsApi" &&
148
148
  !this.tableConfig.table.mounted.api
149
149
  ) {
150
150
  this.$message.warning("请选择列表接口");
151
151
  return reject();
152
152
  }
153
153
  if (!this.tableConfig.table.title) {
154
- this.$message.warning("请选择列表名称");
154
+ this.$message.warning("请输入列表名称");
155
155
  return reject();
156
156
  }
157
157
  const data = deepClone(this.tableConfig);