tianheng-ui 0.1.36 → 0.1.38

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