tianheng-ui 0.1.12 → 0.1.15

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.
@@ -13,57 +13,82 @@
13
13
  </div>
14
14
  <div v-if="activeTab.value === 0" class="fields">
15
15
  <el-checkbox
16
- :indeterminate="search.isIndeterminate"
17
- v-model="search.isCheckAll"
18
- @change="handleSearchCheckAllChange"
16
+ v-model="searchField.isCheckAll"
17
+ :indeterminate="searchField.isIndeterminate"
18
+ @change="val => handleCheckAllChange(val, 'searchField')"
19
19
  >全选</el-checkbox
20
20
  >
21
- <el-checkbox-group v-model="search.fields" @change="handleChange">
22
- <el-checkbox
23
- v-for="(item, index) in fields"
24
- :label="index"
25
- :key="index"
26
- >{{ item.label }}</el-checkbox
27
- >
28
- </el-checkbox-group>
21
+ <el-checkbox
22
+ v-for="item in fields"
23
+ :label="item.prop"
24
+ :key="`searchField-${item.prop}-${item.isSearch}`"
25
+ :checked="item.isSearch"
26
+ @change="val => handleCheckboxChange(val, 'searchField', item)"
27
+ >{{ item.label }}</el-checkbox
28
+ >
29
29
  </div>
30
30
  <div v-if="activeTab.value === 1" class="fields">
31
31
  <el-checkbox
32
- :indeterminate="table.isIndeterminate"
33
- v-model="table.isCheckAll"
34
- @change="handleTableCheckAllChange"
32
+ v-model="tableField.isCheckAll"
33
+ :indeterminate="tableField.isIndeterminate"
34
+ @change="val => handleCheckAllChange(val, 'tableField')"
35
35
  >全选</el-checkbox
36
36
  >
37
- <el-checkbox-group v-model="table.fields" @change="handleChange">
38
- <el-checkbox
39
- v-for="(item, index) in fields"
40
- :label="index"
41
- :key="index"
42
- >{{ item.label }}</el-checkbox
43
- >
44
- </el-checkbox-group>
37
+ <el-checkbox
38
+ v-for="item in fields"
39
+ :label="item.prop"
40
+ :key="`tableField-${item.prop}-${item.isTable}`"
41
+ :checked="item.isTable"
42
+ @change="val => handleCheckboxChange(val, 'tableField', item)"
43
+ >{{ item.label }}</el-checkbox
44
+ >
45
45
  </div>
46
- <div v-if="activeTab.value === 2" class="tableConfig">
46
+ <div v-if="activeTab.value === 2 && config.table" class="tableConfig">
47
47
  <el-form
48
- :model="tableConfig"
48
+ :model="config"
49
49
  label-position="left"
50
50
  label-width="80px"
51
51
  size="mini"
52
+ :rules="formRules"
53
+ ref="formRef"
52
54
  >
53
55
  <el-collapse v-model="tableCollapse">
54
- <el-collapse-item title="表格配置" name="1">
55
- <el-form-item label="高级查询">
56
- <el-switch v-model="tableConfig.search.show"> </el-switch>
56
+ <el-collapse-item title="表格配置" name="group-table">
57
+ <el-form-item label="列表接口" required prop="table.mounted.api">
58
+ <el-select
59
+ v-model="config.table.mounted.api"
60
+ style="width:100%"
61
+ value-key="id"
62
+ clearable
63
+ placeholder="请选择"
64
+ no-data-text="暂无接口,请前往【接口模块】创建"
65
+ >
66
+ <el-option
67
+ v-for="item in apiOptions"
68
+ :key="item.id"
69
+ :label="item.label"
70
+ :value="item.id"
71
+ >
72
+ </el-option>
73
+ </el-select>
74
+ </el-form-item>
75
+ <el-form-item label="开启查询">
76
+ <el-switch v-model="config.search.show"> </el-switch>
57
77
  </el-form-item>
78
+ <el-form-item label="列表序号">
79
+ <el-switch v-model="config.table.sequence"> </el-switch>
80
+ </el-form-item>
81
+ </el-collapse-item>
82
+ <el-collapse-item title="排序配置" name="group-sort">
58
83
  <el-form-item label="排序类型">
59
- <el-radio-group v-model="tableConfig.table.sort.type">
84
+ <el-radio-group v-model="config.table.sort.type">
60
85
  <el-radio-button label="1">降序</el-radio-button>
61
86
  <el-radio-button label="2">升序</el-radio-button>
62
87
  </el-radio-group>
63
88
  </el-form-item>
64
89
  <el-form-item label="排序字段">
65
90
  <el-select
66
- v-model="tableConfig.table.sort.key"
91
+ v-model="config.table.sort.key"
67
92
  placeholder="请选择"
68
93
  clearable
69
94
  >
@@ -76,19 +101,13 @@
76
101
  </el-option>
77
102
  </el-select>
78
103
  </el-form-item>
79
- <el-form-item label="序号">
80
- <el-switch v-model="tableConfig.table.sequence"> </el-switch>
81
- </el-form-item>
82
- <el-form-item label="分页设置">
83
- <el-switch v-model="tableConfig.table.pageInfo.show"> </el-switch>
104
+ </el-collapse-item>
105
+ <el-collapse-item title="分页配置" name="group-pageInfo">
106
+ <el-form-item label="开启分页">
107
+ <el-switch v-model="config.table.pageInfo.show"> </el-switch>
84
108
  </el-form-item>
85
- <el-form-item
86
- v-if="tableConfig.table.pageInfo.show"
87
- label="分页条数"
88
- >
89
- <el-radio-group
90
- v-model="tableConfig.table.pageInfo.options.pageSize"
91
- >
109
+ <el-form-item v-if="config.table.pageInfo.show" label="分页条数">
110
+ <el-radio-group v-model="config.table.pageInfo.options.pageSize">
92
111
  <el-radio-button :label="20">20条</el-radio-button>
93
112
  <el-radio-button :label="50">50条</el-radio-button>
94
113
  <el-radio-button :label="100">100条</el-radio-button>
@@ -96,112 +115,165 @@
96
115
  </el-radio-group>
97
116
  </el-form-item>
98
117
  </el-collapse-item>
99
- <!-- <el-collapse-item title="子表配置" name="2">
100
- <el-form-item label="子表样式">
101
- <el-select v-model="tableConfig.sortField" placeholder="请选择">
102
- <el-option
103
- v-for="item in []"
104
- :key="item.value"
105
- :label="item.label"
106
- :value="item.value"
107
- >
108
- </el-option>
109
- </el-select>
118
+ <el-collapse-item title="提示语配置" name="group-hint">
119
+ <el-form-item label="空数据">
120
+ <el-input
121
+ v-model="config.table.empty.text"
122
+ placeholder="请输入"
123
+ ></el-input>
110
124
  </el-form-item>
125
+ <el-form-item label="加载提示">
126
+ <el-input
127
+ v-model="config.table.loading.text"
128
+ placeholder="请输入"
129
+ ></el-input>
130
+ </el-form-item>
131
+ </el-collapse-item>
132
+ <!-- <el-collapse-item title="数据接口配置" name="group-network">
111
133
  </el-collapse-item> -->
112
- <el-collapse-item name="3">
134
+ <el-collapse-item name="group-button">
113
135
  <template slot="title">
114
136
  <div class="collapse-title">
115
137
  <div>按钮配置</div>
116
138
  <div
117
139
  class="collapse-title-action"
118
- @click.stop="handleActionConfig"
140
+ @click.stop="handleActionConfig()"
119
141
  >
120
142
  配置
121
143
  </div>
122
144
  </div>
123
145
  </template>
124
- <el-form-item label-width="90px">
125
- <el-checkbox v-model="tableConfig.tools.add.show" slot="label"
126
- >新增</el-checkbox
127
- >
146
+ <div
147
+ v-for="(item, index) in Object.values(config.tools)"
148
+ :key="index"
149
+ class="tools-item"
150
+ >
151
+ <el-checkbox v-model="item.show">{{ item.name }}</el-checkbox>
128
152
  <el-input
129
- v-model="tableConfig.tools.add.name"
153
+ v-model="item.text"
130
154
  placeholder="请输入内容"
155
+ size="mini"
131
156
  ></el-input>
132
- </el-form-item>
133
- <el-form-item label-width="90px">
134
- <el-checkbox v-model="tableConfig.tools.edit.show" slot="label"
135
- >编辑</el-checkbox
157
+ <i class="el-icon-set-up" @click="handleActionConfig(item)"></i>
158
+ </div>
159
+ </el-collapse-item>
160
+ </el-collapse>
161
+ </el-form>
162
+ </div>
163
+
164
+ <th-dialog
165
+ v-model="dialog.show"
166
+ title="按钮配置"
167
+ :modal-append-to-body="false"
168
+ :showFooter="false"
169
+ >
170
+ <div class="toolsSeting th-flex_box">
171
+ <el-card class="th-flex_left" style="width:200px;margin-right:10px;">
172
+ <el-tree
173
+ :data="Object.values(config.tools || [])"
174
+ :props="{ label: 'name' }"
175
+ node-key="name"
176
+ @node-click="handleActionConfig"
177
+ ></el-tree>
178
+ </el-card>
179
+ <el-card v-if="dialog.data" class="th-fiex_right">
180
+ <el-form
181
+ ref="form"
182
+ :model="dialog.data"
183
+ label-width="80px"
184
+ size="mini"
185
+ >
186
+ <el-form-item label="按钮模型">
187
+ <el-button
188
+ :type="dialog.data.type"
189
+ :icon="dialog.data.icon"
190
+ :plain="dialog.data.plain"
191
+ :round="dialog.data.round"
192
+ >{{ dialog.data.text }}</el-button
136
193
  >
137
- <el-input
138
- v-model="tableConfig.tools.edit.name"
139
- placeholder="请输入内容"
140
- ></el-input>
141
194
  </el-form-item>
142
- <el-form-item label-width="90px">
143
- <el-checkbox v-model="tableConfig.tools.detail.show" slot="label"
144
- >详情</el-checkbox
145
- >
146
- <el-input
147
- v-model="tableConfig.tools.detail.name"
148
- placeholder="请输入内容"
149
- ></el-input>
195
+ <el-form-item label="按钮名称">
196
+ <el-input v-model="dialog.data.text"></el-input>
150
197
  </el-form-item>
151
- <el-form-item label-width="90px">
152
- <el-checkbox v-model="tableConfig.tools.delete.show" slot="label"
153
- >删除</el-checkbox
154
- >
155
- <el-input
156
- v-model="tableConfig.tools.delete.name"
157
- placeholder="请输入内容"
158
- ></el-input>
198
+ <el-form-item label="按钮类型">
199
+ <el-radio-group v-model="dialog.data.type">
200
+ <el-radio label="">默认</el-radio>
201
+ <el-radio label="primary">主要按钮</el-radio>
202
+ <el-radio label="success">成功按钮</el-radio>
203
+ <el-radio label="info">信息按钮</el-radio>
204
+ <el-radio label="warning">警告按钮</el-radio>
205
+ <el-radio label="danger">危险按钮</el-radio>
206
+ </el-radio-group>
159
207
  </el-form-item>
160
- <el-form-item label-width="90px">
161
- <el-checkbox
162
- v-model="tableConfig.tools.batchDelete.show"
163
- slot="label"
164
- >批量删除</el-checkbox
165
- >
166
- <el-input
167
- v-model="tableConfig.tools.batchDelete.name"
168
- placeholder="请输入内容"
169
- ></el-input>
208
+ <el-form-item label="按钮空心">
209
+ <el-switch v-model="dialog.data.plain"> </el-switch>
210
+ </el-form-item>
211
+ <el-form-item label="按钮圆角">
212
+ <el-switch v-model="dialog.data.round"> </el-switch>
170
213
  </el-form-item>
171
- <el-form-item label-width="90px">
172
- <el-checkbox v-model="tableConfig.tools.export.show" slot="label"
173
- >导出</el-checkbox
214
+ <el-form-item label="按钮图标">
215
+ <th-icons v-model="dialog.data.icon"></th-icons>
216
+ </el-form-item>
217
+ <el-form-item label="关联表单">
218
+ <el-select
219
+ v-model="dialog.data.form"
220
+ style="width:100%"
221
+ clearable
222
+ placeholder="请关联表单"
223
+ no-data-text="暂无表单,请前往【表单模块】创建"
174
224
  >
175
- <el-input
176
- v-model="tableConfig.tools.export.name"
177
- placeholder="请输入内容"
178
- ></el-input>
225
+ <el-option
226
+ v-for="item in formOptions"
227
+ :key="item.id"
228
+ :label="item.label"
229
+ :value="item.id"
230
+ >
231
+ </el-option>
232
+ </el-select>
179
233
  </el-form-item>
180
- <el-form-item label-width="90px">
181
- <el-checkbox v-model="tableConfig.tools.import.show" slot="label"
182
- >导入</el-checkbox
234
+ <el-form-item label="关联接口">
235
+ <el-select
236
+ v-model="dialog.data.api"
237
+ style="width:100%"
238
+ value-key="id"
239
+ clearable
240
+ placeholder="如关联表单中已配置接口,请勿重复关联"
241
+ no-data-text="暂无接口,请前往【接口模块】创建"
183
242
  >
184
- <el-input
185
- v-model="tableConfig.tools.import.name"
186
- placeholder="请输入内容"
187
- ></el-input>
243
+ <el-option
244
+ v-for="item in apiOptions"
245
+ :key="item.id"
246
+ :label="item.label"
247
+ :value="item"
248
+ >
249
+ </el-option>
250
+ </el-select>
188
251
  </el-form-item>
189
- </el-collapse-item>
190
- </el-collapse>
191
- </el-form>
192
- </div>
252
+ </el-form>
253
+ </el-card>
254
+ </div>
255
+ </th-dialog>
193
256
  </div>
194
257
  </template>
195
258
 
196
259
  <script>
260
+ import { deepClone } from "../FormMaking/util";
197
261
  export default {
198
262
  props: {
263
+ config: {
264
+ type: Object,
265
+ default: () => {
266
+ return {};
267
+ }
268
+ },
199
269
  fields: {
200
270
  type: Array,
201
271
  default: () => {
202
272
  return [];
203
273
  }
204
- }
274
+ },
275
+ formOptions: Array,
276
+ apiOptions: Array
205
277
  },
206
278
  data() {
207
279
  return {
@@ -211,101 +283,144 @@ export default {
211
283
  { title: "列表属性", value: 2 }
212
284
  ],
213
285
  activeTab: { title: "查询字段", value: 0 },
214
- search: {
215
- fields: [],
286
+ searchField: {
216
287
  isCheckAll: false,
217
288
  isIndeterminate: false
218
289
  },
219
- table: {
220
- fields: [],
290
+ tableField: {
221
291
  isCheckAll: false,
222
292
  isIndeterminate: false
223
293
  },
224
- tableCollapse: ["1", "3"],
225
- tableConfig: {
226
- search: {
227
- show: true,
228
- options: []
229
- },
230
- table: {
231
- options: [],
232
- pageInfo: {
233
- show: true,
234
- options: {
235
- pageCount: 0, // 总页数
236
- pageSize: 20, // 每页展示的条数
237
- currentPage: 1, // 当前页码
238
- total: 0, // 总条数
239
- sizes: [10, 20, 30, 50, 100]
240
- }
241
- },
242
- sort: { type: "1", key: "" },
243
- loading: { show: false, text: "加载中", image: "" },
244
- empty: { show: true, text: "暂无数据", image: "" },
245
- sequence: true //是否显示序号
246
- },
247
- tools: {
248
- add: { show: true, name: "新增", position: 1 },
249
- edit: { show: true, name: "编辑", position: 2 },
250
- detail: { show: false, name: "查看", position: 2 },
251
- delete: { show: true, name: "删除", position: 2 },
252
- batchDelete: { show: false, name: "批量删除", position: 1 },
253
- export: { show: false, name: "导出", position: 1 },
254
- import: { show: false, name: "导入", position: 1 }
255
- },
256
- network: {}
257
- }
294
+ tableCollapse: [
295
+ "group-table",
296
+ "group-pageInfo",
297
+ "group-sort",
298
+ "group-hint",
299
+ "group-network",
300
+ "group-button"
301
+ ],
302
+ formRules: {
303
+ "table.mounted.api": [
304
+ { required: true, message: "请选择列表接口", trigger: "change" }
305
+ ]
306
+ },
307
+ dialog: { show: false, data: null }
258
308
  };
259
309
  },
310
+ watch: {
311
+ config(val) {
312
+ this.handleFields();
313
+ },
314
+ fields(val) {
315
+ this.handleFields();
316
+ }
317
+ },
318
+ computed: {
319
+ searchActiveFields() {
320
+ const data = this.config.search.options.map(item => {
321
+ return item.prop;
322
+ });
323
+ return data;
324
+ },
325
+ tableActiveFields() {
326
+ const data = this.config.table.options.map(item => {
327
+ return item.prop;
328
+ });
329
+ return data;
330
+ }
331
+ },
260
332
  mounted() {},
261
333
  methods: {
334
+ handleFields() {
335
+ this.fields.forEach(item => {
336
+ item.isSearch = this.searchActiveFields.includes(item.prop);
337
+ item.isTable = this.tableActiveFields.includes(item.prop);
338
+ });
339
+ this.searchField = {
340
+ isCheckAll: this.searchActiveFields.length === this.fields.length,
341
+ isIndeterminate:
342
+ this.searchActiveFields.length !== 0 &&
343
+ this.searchActiveFields.length !== this.fields.length
344
+ };
345
+ this.tableField = {
346
+ isCheckAll: this.tableActiveFields.length === this.fields.length,
347
+ isIndeterminate:
348
+ this.tableActiveFields.length !== 0 &&
349
+ this.tableActiveFields.length !== this.fields.length
350
+ };
351
+ },
262
352
  handleTabsSelect(val) {
263
353
  this.activeTab = val;
264
354
  },
265
- handleChange() {
266
- if (this.activeTab.value === 0) {
267
- const count = this.search.fields.length;
268
- this.search.isCheckAll = count === this.fields.length;
269
- this.search.isIndeterminate = count > 0 && count < this.fields.length;
270
- this.$emit("fields-change", {
271
- type: this.activeTab.value,
272
- data: this.search.fields
355
+ handleCheckAllChange(bool, action) {
356
+ if (action === "searchField") {
357
+ this.fields.forEach(item => {
358
+ item.isSearch = bool;
273
359
  });
274
- } else {
275
- const count = this.table.fields.length;
276
- this.table.isCheckAll = count === this.fields.length;
277
- this.table.isIndeterminate = count > 0 && count < this.fields.length;
278
- this.$emit("fields-change", {
279
- type: this.activeTab.value,
280
- data: this.table.fields
360
+ const data = deepClone(this.fields);
361
+ this.config.search.options = bool ? data : [];
362
+ this.searchField = { isCheckAll: bool, isIndeterminate: false };
363
+ return;
364
+ }
365
+ if (action === "tableField") {
366
+ this.fields.forEach(item => {
367
+ item.isTable = bool;
281
368
  });
369
+ const data = deepClone(this.fields);
370
+ this.config.table.options = bool ? data : [];
371
+ this.tableField = { isCheckAll: bool, isIndeterminate: false };
372
+ return;
282
373
  }
283
374
  },
284
- handleSearchCheckAllChange(val) {
285
- const list = [];
286
- if (val) {
287
- for (let i = 0; i < this.fields.length; i++) {
288
- list.push(i);
289
- }
375
+ handleCheckboxChange(bool, action, data) {
376
+ if (action === "searchField") {
377
+ data.isSearch = bool;
378
+ bool
379
+ ? this.config.search.options.push(deepClone(data))
380
+ : (this.config.search.options = this.config.search.options.filter(
381
+ item => {
382
+ return item.prop !== data.prop;
383
+ }
384
+ ));
385
+ this.searchField = {
386
+ isCheckAll: this.config.search.options.length === this.fields.length,
387
+ isIndeterminate:
388
+ this.config.search.options.length !== 0 &&
389
+ this.config.search.options.length !== this.fields.length
390
+ };
391
+ return;
290
392
  }
291
- this.search.fields = list;
292
- this.search.isIndeterminate = false;
293
- this.handleChange();
294
- },
295
- handleTableCheckAllChange(val) {
296
- const list = [];
297
- if (val) {
298
- for (let i = 0; i < this.fields.length; i++) {
299
- list.push(i);
300
- }
393
+ if (action === "tableField") {
394
+ data.isTable = bool;
395
+ bool
396
+ ? this.config.table.options.push(deepClone(data))
397
+ : (this.config.table.options = this.config.table.options.filter(
398
+ item => {
399
+ return item.prop !== data.prop;
400
+ }
401
+ ));
402
+ this.tableField = {
403
+ isCheckAll: this.config.table.options.length === this.fields.length,
404
+ isIndeterminate:
405
+ this.config.table.options.length !== 0 &&
406
+ this.config.table.options.length !== this.fields.length
407
+ };
408
+ return;
301
409
  }
302
- this.table.fields = list;
303
- this.table.isIndeterminate = false;
304
- this.handleChange();
305
410
  },
306
- handleActionConfig() {},
307
- getJson() {
308
- return JSON.parse(JSON.stringify(this.tableConfig));
411
+ handleActionConfig(data) {
412
+ this.dialog = { show: true, data };
413
+ },
414
+ handleFormValidate() {
415
+ return new Promise((resolve, reject) => {
416
+ if (this.$refs.formRef) {
417
+ this.$refs.formRef.validate(valid => {
418
+ resolve(valid);
419
+ });
420
+ } else {
421
+ reject();
422
+ }
423
+ });
309
424
  }
310
425
  }
311
426
  };
@@ -368,6 +483,21 @@ export default {
368
483
  color: #409eff;
369
484
  }
370
485
  }
486
+ .tools-item {
487
+ display: flex;
488
+ align-items: center;
489
+ padding: 7px 0;
490
+
491
+ .el-checkbox {
492
+ width: 140px;
493
+ }
494
+ > i {
495
+ height: 20px;
496
+ line-height: 20px;
497
+ padding-left: 10px;
498
+ cursor: pointer;
499
+ }
500
+ }
371
501
  }
372
502
  }
373
503
  </style>