bi-element-ui 0.1.51 → 0.1.55

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.
Files changed (43) hide show
  1. package/.browserslistrc +3 -3
  2. package/.eslintrc.js +287 -287
  3. package/.prettierrc +7 -7
  4. package/README.md +148 -148
  5. package/cypress.json +3 -3
  6. package/lib/bi-element-ui.common.js +24760 -24638
  7. package/lib/bi-element-ui.css +1 -1
  8. package/lib/bi-element-ui.umd.js +24760 -24638
  9. package/lib/bi-element-ui.umd.min.js +2 -279
  10. package/lib/static/img/swiperBg.png +0 -0
  11. package/package.json +57 -57
  12. package/src/App.vue +42 -42
  13. package/src/components/BiDatePicker/datePickerOption.js +229 -229
  14. package/src/components/BiDatePicker/index.vue +74 -74
  15. package/src/components/BiTable/columu.vue +104 -104
  16. package/src/components/BiTable/forced.js +76 -76
  17. package/src/components/BiTable/index.js +6 -6
  18. package/src/components/BiTable/render.vue +13 -13
  19. package/src/components/BiTable/table.vue +202 -202
  20. package/src/components/BiTableColumn/Group.vue +277 -277
  21. package/src/components/BiTableColumn/api.js +16 -16
  22. package/src/components/BiTableColumn/index.vue +614 -614
  23. package/src/components/BiTooltipIcon/index.vue +71 -71
  24. package/src/components/EditBtn.vue +15 -15
  25. package/src/components/FreeButton/index.vue +69 -69
  26. package/src/components/Pagination/index.vue +104 -104
  27. package/src/components/Pagination/scrollTo.js +69 -69
  28. package/src/main.js +18 -18
  29. package/src/router/index.js +39 -39
  30. package/src/store/index.js +11 -11
  31. package/src/table.js +463 -463
  32. package/src/views/Date.vue +132 -132
  33. package/src/views/Home.vue +330 -330
  34. package/src/views/Scene.vue +140 -140
  35. package/src/views/Table.vue +220 -220
  36. package/src/views/showData.vue +455 -455
  37. package/tests/e2e/.eslintrc.js +10 -10
  38. package/tests/e2e/plugins/index.js +25 -25
  39. package/tests/e2e/specs/test.js +8 -8
  40. package/tests/e2e/support/commands.js +25 -25
  41. package/tests/e2e/support/index.js +20 -20
  42. package/tests/unit/example.spec.js +13 -13
  43. package//345/211/215/347/253/257ui/346/240/267/345/274/217/350/247/204/350/214/203.md +101 -101
@@ -1,615 +1,615 @@
1
- <template>
2
-
3
- <el-button
4
- type="primary"
5
- @click="visible = true"
6
- >
7
- 自定义列
8
- <el-dialog
9
- custom-class="bi-column-dialog"
10
- title="自定义列"
11
- :visible.sync="visible"
12
- width="800px"
13
- top="8vh"
14
- append-to-body
15
- @open="handleOpen"
16
- @close="close"
17
- >
18
- <div
19
- class="dialog-body"
20
- style="min-height: 160px"
21
- >
22
- <div class="bi-column-container">
23
- <div class="checkbox-container">
24
- <el-card class="box-card">
25
- <div
26
- slot="header"
27
- class="clearfix"
28
- >
29
- <span>可操作性的列</span>
30
-
31
- </div>
32
- <div
33
- v-for="(item, index) in colList"
34
- :key="index"
35
- class="checkbox-group"
36
- >
37
- <p class="checkbox-title">
38
- <el-checkbox
39
- v-model="item.status"
40
- @change="
41
- (val) => {
42
- return handleCheckGroupAllChange(val, item);
43
- }
44
- "
45
- >{{ item.content }}</el-checkbox>
46
- </p>
47
- <p>
48
- <el-checkbox-group
49
- v-model="checkList"
50
- :true-label="1"
51
- :false-label="0"
52
- @change="handleCheckGroupAll(item)"
53
- >
54
- <el-checkbox
55
- v-for="(city, cityIndex) in item.children"
56
- :key="cityIndex"
57
- :label="city.name"
58
- style="width:120px;margin:0 15px 15px 0;"
59
- >
60
- {{ city.content }}
61
- </el-checkbox>
62
- </el-checkbox-group>
63
- </p>
64
- </div>
65
- </el-card>
66
-
67
- </div>
68
- <div class="column-container">
69
- <el-card class="box-card">
70
- <div
71
- slot="header"
72
- class="column-title"
73
- >
74
- <span>已选{{ columnLength }}列</span>
75
- <el-button
76
- type="text"
77
- @click="clearAll"
78
- >清空全部</el-button>
79
- </div>
80
- <p class="column-group-title">左侧固定列</p>
81
- <div class="column-configurable">
82
- <draggable
83
- v-model="leftColumnList"
84
- group="column"
85
- >
86
- <!-- <transition-group> -->
87
- <div
88
- v-for="column in leftColumnList"
89
- :key="column.prop"
90
- class="selected-column-item"
91
- >
92
- <i class="el-icon-menu"></i>
93
- <div class="column-name">{{ column.content||column.label }}</div>
94
- <i
95
- class="el-icon-close column-close"
96
- @click="closeColumn(column.prop)"
97
- ></i>
98
- </div>
99
- <!-- </transition-group> -->
100
- </draggable>
101
-
102
- </div>
103
-
104
- <p class="column-group-title">中间不固定列</p>
105
- <div class="column-configurable">
106
- <draggable
107
- v-model="columnList"
108
- group="column"
109
- >
110
- <!-- <transition-group> -->
111
- <div
112
- v-for="column in columnList"
113
- :key="column.prop"
114
- class="selected-column-item"
115
- >
116
- <i class="el-icon-menu"></i>
117
- <div class="column-name">{{ column.content||column.label }}</div>
118
- <i
119
- class="el-icon-close column-close"
120
- @click="closeColumn(column.prop)"
121
- ></i>
122
- </div>
123
- <!-- </transition-group> -->
124
- </draggable>
125
- </div>
126
-
127
- <p class="column-group-title">右侧固定列</p>
128
- <div class="column-configurable">
129
- <draggable
130
- v-model="rightColumnList"
131
- group="column"
132
- >
133
- <!-- <transition-group> -->
134
- <div
135
- v-for="column in rightColumnList"
136
- :key="column.prop"
137
- class="selected-column-item"
138
- >
139
- <i class="el-icon-menu"></i>
140
- <div class="column-name">{{ column.content||column.label }}</div>
141
- <i
142
- class="el-icon-close column-close"
143
- @click="closeColumn(column.prop)"
144
- ></i>
145
- </div>
146
- <!-- </transition-group> -->
147
- </draggable>
148
-
149
- </div>
150
-
151
- </el-card>
152
- </div>
153
- </div>
154
- </div>
155
- <span
156
- slot="footer"
157
- class="dialog-footer"
158
- style="display: flex; justify-content: space-between"
159
- >
160
- <span style="display: inline-block; line-height: 32px">
161
- <el-checkbox
162
- v-model="checkAllData"
163
- label="全选"
164
- @change="checkAll"
165
- >
166
- 全选
167
- </el-checkbox>
168
- </span>
169
- <div>
170
- <el-button @click="close">关闭</el-button>
171
- <el-button
172
- type="primary"
173
- @click="ok"
174
- >生效</el-button>
175
- </div>
176
- </span>
177
- </el-dialog>
178
- </el-button>
179
-
180
- </template>
181
-
182
- <script>
183
- import draggable from 'vuedraggable'
184
- export default {
185
- name: 'BiTableColumn',
186
- components: {
187
- draggable
188
- },
189
- props: {
190
- columnName: {
191
- type: String,
192
- require: true,
193
- default: ''
194
- },
195
- listType: {
196
- type: String,
197
- require: true,
198
- default: ''
199
- },
200
- checkData: {
201
- type: Array,
202
- require: true,
203
- default: () => {
204
- return []
205
- }
206
- },
207
- tableColumn: {
208
- type: Array,
209
- default: () => {
210
- return []
211
- }
212
- },
213
- defaultColumn: {
214
- type: Object,
215
- default: () => {
216
- return {
217
- left: [],
218
- center: [],
219
- right: []
220
- }
221
- }
222
- }
223
- },
224
-
225
- data() {
226
- return {
227
- tableColumnList: this.tableColumn,
228
- visible: false,
229
- colList: [],
230
-
231
- checkList: [], // 存放勾选数据
232
- checkAllData: false,
233
-
234
- draggableList: [],
235
- leftColumnList: [],
236
- columnList: [],
237
- rightColumnList: []
238
- }
239
- },
240
- computed: {
241
- columnLength() {
242
- return this.leftColumnList.length + this.columnList.length + this.rightColumnList.length
243
- }
244
- },
245
- watch: {
246
- colList: {
247
- handler(now) {
248
- let i = true
249
- now.forEach((item) => {
250
- item.status = Boolean(item.status)
251
- if (item.status) {
252
- this.checkAllData = item.status
253
- } else {
254
- i = false
255
- }
256
- this.checkAllData = i
257
- })
258
- },
259
-
260
- deep: true
261
- }
262
- },
263
- mounted() {
264
- // console.log(this.tableColumn)
265
- const params = {
266
- type: this.listType
267
- }
268
- this.defaultColumnInit()
269
- this.getList(params)
270
- this.returnColumn()
271
- },
272
- // created() {
273
- // this.list = this.colList
274
- // },
275
- beforeDestroy() {
276
- this.visible = false
277
- },
278
- methods: {
279
- // 获取列表
280
- defaultColumnInit() {
281
- // console.log('defaultColumnInit')
282
- const localData = this.getLocalStorage()
283
- const { left, center, right } = localData || this.defaultColumn
284
-
285
- // this.leftColumnList = []
286
- // this.columnList = []
287
- // this.rightColumnList = []
288
- left.map((prop) => {
289
- this.checkList.push(prop)
290
- const column = this.tableColumnList.find((item) => item.prop === prop)
291
- column && this.leftColumnList.push(column)
292
- })
293
- center.map((prop) => {
294
- this.checkList.push(prop)
295
- const column = this.tableColumnList.find((item) => item.prop === prop)
296
- column && this.columnList.push(column)
297
- })
298
- right.map((prop) => {
299
- this.checkList.push(prop)
300
- const column = this.tableColumnList.find((item) => item.prop === prop)
301
- column && this.rightColumnList.push(column)
302
- })
303
- // console.log(this.checkList)
304
- },
305
- async getList(params) {
306
- // const res = await getTheadList(params)
307
- // if (res.status_code === 1) {
308
- this.colList = [
309
- {
310
- content: '分组1',
311
- status: false,
312
- children: [
313
- {
314
- name: 'date',
315
- content: '日期',
316
- status: false
317
- }
318
- ]
319
- },
320
- {
321
- content: '分组2',
322
- status: false,
323
- children: [
324
- { content: '姓名', name: 'name', status: false },
325
- { content: '省份', name: 'province', status: false },
326
- { content: '市区', name: 'city', status: false }
327
- ]
328
- },
329
- {
330
- content: '分组3',
331
- status: false,
332
- children: [
333
- { content: '地址', name: 'address', status: false },
334
- { content: '地址2', name: 'address2', status: false },
335
- { content: '邮编', name: 'zip', status: false },
336
- { content: 'v-model', name: 'other', status: false }
337
- ]
338
- }
339
- ]
340
-
341
- this.defaultCheck()
342
- // this.defaultCheck()
343
- // }
344
- },
345
- // 全选
346
- checkAll(val) {
347
- this.colList.forEach((item) => {
348
- this.handleCheckGroupAllChange(val, item)
349
- item.status = val
350
- })
351
- if (!val) {
352
- this.checkList = []
353
- }
354
- },
355
- // 全选检查
356
- defaultCheck() {
357
- this.colList.forEach((item) => {
358
- this.handleCheckGroupAll(item)
359
- })
360
- },
361
- deleteArrayItemForIndex(arr, index) {
362
- if (index === -1) {
363
- return
364
- }
365
- return arr.splice(index, 1)
366
- },
367
- // 组全选
368
- handleCheckGroupAllChange(val, item) {
369
- // console.log('handleCheckGroupAllChange')
370
- if (val) {
371
- item.children.map((column) => {
372
- if (this.checkList.indexOf(column.name) === -1) {
373
- this.checkList.push(column.name)
374
- this.insertColumn(column.name)
375
- }
376
- })
377
- } else {
378
- item.children.map((column) => {
379
- this.deleteArrayItemForIndex(this.checkList, this.checkList.indexOf(column.name))
380
- this.removeColumn(column.name)
381
- })
382
- }
383
- },
384
- // 组全选状态
385
- handleCheckGroupAll(item) {
386
- // console.log('handleCheckGroupAll', item)
387
- let flag = 1
388
- item.children.map((column) => {
389
- if (this.checkList.indexOf(column.name) === -1) {
390
- this.removeColumn(column.name)
391
- flag = 0
392
- } else {
393
- this.insertColumn(column.name)
394
- }
395
- })
396
- item.status = flag
397
- },
398
- // 发送数据
399
- async setTheadList() {
400
- // 数组变化调用接口保存全部数据
401
- const params = JSON.parse(JSON.stringify(this.colList))
402
- var arr = []
403
- params.forEach((item) => {
404
- item.status = item.status ? 1 : 0
405
- arr.push(...item.children)
406
- })
407
- // const data = {
408
- // head_info: JSON.stringify(arr)
409
- // }
410
- // await setTheadList(data)
411
- },
412
- clearAll() {
413
- this.checkList = []
414
- this.checkAll(false)
415
- },
416
- closeColumn(name) {
417
- this.deleteArrayItemForIndex(this.checkList, this.checkList.indexOf(name))
418
- this.removeColumn(name)
419
- this.defaultCheck()
420
- },
421
- insertColumn(name) {
422
- const column = this.tableColumnList.find((item) => item.prop === name)
423
-
424
- if (!this.leftColumnList.find((item) => item.prop === name) && !this.rightColumnList.find((item) => item.prop === name) && !this.columnList.find((item) => item.prop === name)) {
425
- this.columnList.push(column)
426
- }
427
- },
428
- removeColumn(name) {
429
- if (this.leftColumnList.length && this.leftColumnList.find((item) => item.prop === name)) {
430
- const columnIndex = this.leftColumnList.findIndex((item) => item.prop === name)
431
- columnIndex > -1 && this.leftColumnList.splice(columnIndex, 1)
432
- }
433
- if (this.columnList.length && this.columnList.find((item) => item.prop === name)) {
434
- const columnIndex = this.columnList.findIndex((item) => item.prop === name)
435
- columnIndex > -1 && this.columnList.splice(columnIndex, 1)
436
- }
437
- if (this.rightColumnList.length && this.rightColumnList.find((item) => item.prop === name)) {
438
- const columnIndex = this.rightColumnList.findIndex((item) => item.prop === name)
439
- columnIndex > -1 && this.rightColumnList.splice(columnIndex, 1)
440
- }
441
- // column.status = false
442
- },
443
- returnColumn() {
444
- this.leftColumnList.map((item) => {
445
- item.fixed = true
446
- })
447
- this.columnList.map((item) => {
448
- item.fixed = false
449
- })
450
- this.rightColumnList.map((item) => {
451
- item.fixed = 'right'
452
- })
453
- this.$emit('handleTableColumn', [...this.leftColumnList, ...this.columnList, ...this.rightColumnList])
454
- },
455
- ok() {
456
- this.returnColumn()
457
- this.saveLocalStorage()
458
- this.visible = false
459
- },
460
- saveLocalStorage() {
461
- const columnData = {
462
- left: [],
463
- center: [],
464
- right: []
465
- }
466
- this.leftColumnList.map(({ prop }) => {
467
- prop && columnData.left.push(prop)
468
- })
469
- this.columnList.map(({ prop }) => {
470
- prop && columnData.center.push(prop)
471
- })
472
- this.rightColumnList.map(({ prop }) => {
473
- prop && columnData.right.push(prop)
474
- })
475
- // console.log(columnData)
476
- localStorage.setItem(this.columnName, JSON.stringify(columnData))
477
- },
478
- getLocalStorage() {
479
- // console.log('name:', this.columnName)
480
- const localData = localStorage.getItem(this.columnName)
481
-
482
- if (localData) {
483
- return JSON.parse(localData)
484
- } else {
485
- return
486
- }
487
- },
488
- handleOpen() {
489
- // console.log('handleOpen')
490
- this.checkList = []
491
- this.rightColumnList = []
492
- this.leftColumnList = []
493
- this.columnList = []
494
- const localData = this.getLocalStorage()
495
- localData && this.defaultColumnInit()
496
- },
497
- // 关闭弹窗
498
- close() {
499
- this.checkList = []
500
- this.rightColumnList = []
501
- this.leftColumnList = []
502
- this.columnList = []
503
- this.visible = false
504
- this.$emit('closeDialog', { visible: false })
505
- }
506
- }
507
- }
508
- </script>
509
-
510
- <style scoped lang="scss">
511
- .bi-column-container {
512
- display: flex;
513
- justify-content: space-between;
514
-
515
- .checkbox-container {
516
- .checkbox-title {
517
- cursor: pointer;
518
- height: 34px;
519
- line-height: 22px;
520
- font-size: 14px;
521
- font-weight: 500;
522
- background-color: #f5f5f5;
523
- color: #333;
524
- position: relative;
525
- padding-left: 12px;
526
- margin-bottom: 12px;
527
- border-radius: 4px;
528
- align-items: center;
529
- display: flex;
530
- }
531
- .el-checkbox-group {
532
- display: flex;
533
- flex-wrap: wrap;
534
- justify-content: space-between;
535
-
536
- margin-bottom: 0;
537
- padding-left: 12px;
538
-
539
- .el-checkbox {
540
- width: 210px !important;
541
- display: block;
542
- float: left;
543
- margin: 0 !important;
544
- min-height: 32px;
545
- max-height: 52px;
546
- line-height: 20px;
547
- }
548
- }
549
- }
550
- .column-container {
551
- margin-left: 20px;
552
- width: 230px;
553
- flex: 0 0 230px;
554
-
555
- .column-title {
556
- display: flex;
557
- justify-content: space-between;
558
- .el-button {
559
- padding: 0;
560
- }
561
- }
562
- .column-group-title {
563
- font-size: 14px;
564
- color: #8c8c8c;
565
- margin: 5px 0;
566
- }
567
- .column-configurable {
568
- .selected-column-item {
569
- cursor: move;
570
- height: 26px;
571
- background: #f0f0f0;
572
- border-radius: 4px;
573
- line-height: 28px;
574
- padding: 0 8px;
575
- margin-top: 0;
576
- display: flex;
577
- align-items: center;
578
- color: #666;
579
- font-size: 14px;
580
- &:not(:first-child) {
581
- margin-top: 8px;
582
- }
583
- .column-name {
584
- // width: 20px;
585
- flex-grow: 2;
586
- margin-left: 8px;
587
- }
588
- .column-close {
589
- cursor: pointer;
590
- }
591
- }
592
- }
593
- }
594
- }
595
- </style>
596
- <style lang="scss">
597
- .bi-column-dialog {
598
- .el-card__header {
599
- background-color: #f8f9fa;
600
- // border: #e0e0e0 1px solid;
601
- box-sizing: border-box;
602
- line-height: 22px;
603
- padding: 8px 12px;
604
- // border-radius: 4px 4px 0 0;
605
- font-weight: 600;
606
- color: #333;
607
- }
608
- .el-card__body {
609
- padding: 12px 16px;
610
- height: 395px;
611
- box-sizing: border-box;
612
- overflow-y: auto;
613
- }
614
- }
1
+ <template>
2
+
3
+ <el-button
4
+ type="primary"
5
+ @click="visible = true"
6
+ >
7
+ 自定义列
8
+ <el-dialog
9
+ custom-class="bi-column-dialog"
10
+ title="自定义列"
11
+ :visible.sync="visible"
12
+ width="800px"
13
+ top="8vh"
14
+ append-to-body
15
+ @open="handleOpen"
16
+ @close="close"
17
+ >
18
+ <div
19
+ class="dialog-body"
20
+ style="min-height: 160px"
21
+ >
22
+ <div class="bi-column-container">
23
+ <div class="checkbox-container">
24
+ <el-card class="box-card">
25
+ <div
26
+ slot="header"
27
+ class="clearfix"
28
+ >
29
+ <span>可操作性的列</span>
30
+
31
+ </div>
32
+ <div
33
+ v-for="(item, index) in colList"
34
+ :key="index"
35
+ class="checkbox-group"
36
+ >
37
+ <p class="checkbox-title">
38
+ <el-checkbox
39
+ v-model="item.status"
40
+ @change="
41
+ (val) => {
42
+ return handleCheckGroupAllChange(val, item);
43
+ }
44
+ "
45
+ >{{ item.content }}</el-checkbox>
46
+ </p>
47
+ <p>
48
+ <el-checkbox-group
49
+ v-model="checkList"
50
+ :true-label="1"
51
+ :false-label="0"
52
+ @change="handleCheckGroupAll(item)"
53
+ >
54
+ <el-checkbox
55
+ v-for="(city, cityIndex) in item.children"
56
+ :key="cityIndex"
57
+ :label="city.name"
58
+ style="width:120px;margin:0 15px 15px 0;"
59
+ >
60
+ {{ city.content }}
61
+ </el-checkbox>
62
+ </el-checkbox-group>
63
+ </p>
64
+ </div>
65
+ </el-card>
66
+
67
+ </div>
68
+ <div class="column-container">
69
+ <el-card class="box-card">
70
+ <div
71
+ slot="header"
72
+ class="column-title"
73
+ >
74
+ <span>已选{{ columnLength }}列</span>
75
+ <el-button
76
+ type="text"
77
+ @click="clearAll"
78
+ >清空全部</el-button>
79
+ </div>
80
+ <p class="column-group-title">左侧固定列</p>
81
+ <div class="column-configurable">
82
+ <draggable
83
+ v-model="leftColumnList"
84
+ group="column"
85
+ >
86
+ <!-- <transition-group> -->
87
+ <div
88
+ v-for="column in leftColumnList"
89
+ :key="column.prop"
90
+ class="selected-column-item"
91
+ >
92
+ <i class="el-icon-menu"></i>
93
+ <div class="column-name">{{ column.content||column.label }}</div>
94
+ <i
95
+ class="el-icon-close column-close"
96
+ @click="closeColumn(column.prop)"
97
+ ></i>
98
+ </div>
99
+ <!-- </transition-group> -->
100
+ </draggable>
101
+
102
+ </div>
103
+
104
+ <p class="column-group-title">中间不固定列</p>
105
+ <div class="column-configurable">
106
+ <draggable
107
+ v-model="columnList"
108
+ group="column"
109
+ >
110
+ <!-- <transition-group> -->
111
+ <div
112
+ v-for="column in columnList"
113
+ :key="column.prop"
114
+ class="selected-column-item"
115
+ >
116
+ <i class="el-icon-menu"></i>
117
+ <div class="column-name">{{ column.content||column.label }}</div>
118
+ <i
119
+ class="el-icon-close column-close"
120
+ @click="closeColumn(column.prop)"
121
+ ></i>
122
+ </div>
123
+ <!-- </transition-group> -->
124
+ </draggable>
125
+ </div>
126
+
127
+ <p class="column-group-title">右侧固定列</p>
128
+ <div class="column-configurable">
129
+ <draggable
130
+ v-model="rightColumnList"
131
+ group="column"
132
+ >
133
+ <!-- <transition-group> -->
134
+ <div
135
+ v-for="column in rightColumnList"
136
+ :key="column.prop"
137
+ class="selected-column-item"
138
+ >
139
+ <i class="el-icon-menu"></i>
140
+ <div class="column-name">{{ column.content||column.label }}</div>
141
+ <i
142
+ class="el-icon-close column-close"
143
+ @click="closeColumn(column.prop)"
144
+ ></i>
145
+ </div>
146
+ <!-- </transition-group> -->
147
+ </draggable>
148
+
149
+ </div>
150
+
151
+ </el-card>
152
+ </div>
153
+ </div>
154
+ </div>
155
+ <span
156
+ slot="footer"
157
+ class="dialog-footer"
158
+ style="display: flex; justify-content: space-between"
159
+ >
160
+ <span style="display: inline-block; line-height: 32px">
161
+ <el-checkbox
162
+ v-model="checkAllData"
163
+ label="全选"
164
+ @change="checkAll"
165
+ >
166
+ 全选
167
+ </el-checkbox>
168
+ </span>
169
+ <div>
170
+ <el-button @click="close">关闭</el-button>
171
+ <el-button
172
+ type="primary"
173
+ @click="ok"
174
+ >生效</el-button>
175
+ </div>
176
+ </span>
177
+ </el-dialog>
178
+ </el-button>
179
+
180
+ </template>
181
+
182
+ <script>
183
+ import draggable from 'vuedraggable'
184
+ export default {
185
+ name: 'BiTableColumn',
186
+ components: {
187
+ draggable
188
+ },
189
+ props: {
190
+ columnName: {
191
+ type: String,
192
+ require: true,
193
+ default: ''
194
+ },
195
+ listType: {
196
+ type: String,
197
+ require: true,
198
+ default: ''
199
+ },
200
+ checkData: {
201
+ type: Array,
202
+ require: true,
203
+ default: () => {
204
+ return []
205
+ }
206
+ },
207
+ tableColumn: {
208
+ type: Array,
209
+ default: () => {
210
+ return []
211
+ }
212
+ },
213
+ defaultColumn: {
214
+ type: Object,
215
+ default: () => {
216
+ return {
217
+ left: [],
218
+ center: [],
219
+ right: []
220
+ }
221
+ }
222
+ }
223
+ },
224
+
225
+ data() {
226
+ return {
227
+ tableColumnList: this.tableColumn,
228
+ visible: false,
229
+ colList: [],
230
+
231
+ checkList: [], // 存放勾选数据
232
+ checkAllData: false,
233
+
234
+ draggableList: [],
235
+ leftColumnList: [],
236
+ columnList: [],
237
+ rightColumnList: []
238
+ }
239
+ },
240
+ computed: {
241
+ columnLength() {
242
+ return this.leftColumnList.length + this.columnList.length + this.rightColumnList.length
243
+ }
244
+ },
245
+ watch: {
246
+ colList: {
247
+ handler(now) {
248
+ let i = true
249
+ now.forEach((item) => {
250
+ item.status = Boolean(item.status)
251
+ if (item.status) {
252
+ this.checkAllData = item.status
253
+ } else {
254
+ i = false
255
+ }
256
+ this.checkAllData = i
257
+ })
258
+ },
259
+
260
+ deep: true
261
+ }
262
+ },
263
+ mounted() {
264
+ // console.log(this.tableColumn)
265
+ const params = {
266
+ type: this.listType
267
+ }
268
+ this.defaultColumnInit()
269
+ this.getList(params)
270
+ this.returnColumn()
271
+ },
272
+ // created() {
273
+ // this.list = this.colList
274
+ // },
275
+ beforeDestroy() {
276
+ this.visible = false
277
+ },
278
+ methods: {
279
+ // 获取列表
280
+ defaultColumnInit() {
281
+ // console.log('defaultColumnInit')
282
+ const localData = this.getLocalStorage()
283
+ const { left, center, right } = localData || this.defaultColumn
284
+
285
+ // this.leftColumnList = []
286
+ // this.columnList = []
287
+ // this.rightColumnList = []
288
+ left.map((prop) => {
289
+ this.checkList.push(prop)
290
+ const column = this.tableColumnList.find((item) => item.prop === prop)
291
+ column && this.leftColumnList.push(column)
292
+ })
293
+ center.map((prop) => {
294
+ this.checkList.push(prop)
295
+ const column = this.tableColumnList.find((item) => item.prop === prop)
296
+ column && this.columnList.push(column)
297
+ })
298
+ right.map((prop) => {
299
+ this.checkList.push(prop)
300
+ const column = this.tableColumnList.find((item) => item.prop === prop)
301
+ column && this.rightColumnList.push(column)
302
+ })
303
+ // console.log(this.checkList)
304
+ },
305
+ async getList(params) {
306
+ // const res = await getTheadList(params)
307
+ // if (res.status_code === 1) {
308
+ this.colList = [
309
+ {
310
+ content: '分组1',
311
+ status: false,
312
+ children: [
313
+ {
314
+ name: 'date',
315
+ content: '日期',
316
+ status: false
317
+ }
318
+ ]
319
+ },
320
+ {
321
+ content: '分组2',
322
+ status: false,
323
+ children: [
324
+ { content: '姓名', name: 'name', status: false },
325
+ { content: '省份', name: 'province', status: false },
326
+ { content: '市区', name: 'city', status: false }
327
+ ]
328
+ },
329
+ {
330
+ content: '分组3',
331
+ status: false,
332
+ children: [
333
+ { content: '地址', name: 'address', status: false },
334
+ { content: '地址2', name: 'address2', status: false },
335
+ { content: '邮编', name: 'zip', status: false },
336
+ { content: 'v-model', name: 'other', status: false }
337
+ ]
338
+ }
339
+ ]
340
+
341
+ this.defaultCheck()
342
+ // this.defaultCheck()
343
+ // }
344
+ },
345
+ // 全选
346
+ checkAll(val) {
347
+ this.colList.forEach((item) => {
348
+ this.handleCheckGroupAllChange(val, item)
349
+ item.status = val
350
+ })
351
+ if (!val) {
352
+ this.checkList = []
353
+ }
354
+ },
355
+ // 全选检查
356
+ defaultCheck() {
357
+ this.colList.forEach((item) => {
358
+ this.handleCheckGroupAll(item)
359
+ })
360
+ },
361
+ deleteArrayItemForIndex(arr, index) {
362
+ if (index === -1) {
363
+ return
364
+ }
365
+ return arr.splice(index, 1)
366
+ },
367
+ // 组全选
368
+ handleCheckGroupAllChange(val, item) {
369
+ // console.log('handleCheckGroupAllChange')
370
+ if (val) {
371
+ item.children.map((column) => {
372
+ if (this.checkList.indexOf(column.name) === -1) {
373
+ this.checkList.push(column.name)
374
+ this.insertColumn(column.name)
375
+ }
376
+ })
377
+ } else {
378
+ item.children.map((column) => {
379
+ this.deleteArrayItemForIndex(this.checkList, this.checkList.indexOf(column.name))
380
+ this.removeColumn(column.name)
381
+ })
382
+ }
383
+ },
384
+ // 组全选状态
385
+ handleCheckGroupAll(item) {
386
+ // console.log('handleCheckGroupAll', item)
387
+ let flag = 1
388
+ item.children.map((column) => {
389
+ if (this.checkList.indexOf(column.name) === -1) {
390
+ this.removeColumn(column.name)
391
+ flag = 0
392
+ } else {
393
+ this.insertColumn(column.name)
394
+ }
395
+ })
396
+ item.status = flag
397
+ },
398
+ // 发送数据
399
+ async setTheadList() {
400
+ // 数组变化调用接口保存全部数据
401
+ const params = JSON.parse(JSON.stringify(this.colList))
402
+ var arr = []
403
+ params.forEach((item) => {
404
+ item.status = item.status ? 1 : 0
405
+ arr.push(...item.children)
406
+ })
407
+ // const data = {
408
+ // head_info: JSON.stringify(arr)
409
+ // }
410
+ // await setTheadList(data)
411
+ },
412
+ clearAll() {
413
+ this.checkList = []
414
+ this.checkAll(false)
415
+ },
416
+ closeColumn(name) {
417
+ this.deleteArrayItemForIndex(this.checkList, this.checkList.indexOf(name))
418
+ this.removeColumn(name)
419
+ this.defaultCheck()
420
+ },
421
+ insertColumn(name) {
422
+ const column = this.tableColumnList.find((item) => item.prop === name)
423
+
424
+ if (!this.leftColumnList.find((item) => item.prop === name) && !this.rightColumnList.find((item) => item.prop === name) && !this.columnList.find((item) => item.prop === name)) {
425
+ this.columnList.push(column)
426
+ }
427
+ },
428
+ removeColumn(name) {
429
+ if (this.leftColumnList.length && this.leftColumnList.find((item) => item.prop === name)) {
430
+ const columnIndex = this.leftColumnList.findIndex((item) => item.prop === name)
431
+ columnIndex > -1 && this.leftColumnList.splice(columnIndex, 1)
432
+ }
433
+ if (this.columnList.length && this.columnList.find((item) => item.prop === name)) {
434
+ const columnIndex = this.columnList.findIndex((item) => item.prop === name)
435
+ columnIndex > -1 && this.columnList.splice(columnIndex, 1)
436
+ }
437
+ if (this.rightColumnList.length && this.rightColumnList.find((item) => item.prop === name)) {
438
+ const columnIndex = this.rightColumnList.findIndex((item) => item.prop === name)
439
+ columnIndex > -1 && this.rightColumnList.splice(columnIndex, 1)
440
+ }
441
+ // column.status = false
442
+ },
443
+ returnColumn() {
444
+ this.leftColumnList.map((item) => {
445
+ item.fixed = true
446
+ })
447
+ this.columnList.map((item) => {
448
+ item.fixed = false
449
+ })
450
+ this.rightColumnList.map((item) => {
451
+ item.fixed = 'right'
452
+ })
453
+ this.$emit('handleTableColumn', [...this.leftColumnList, ...this.columnList, ...this.rightColumnList])
454
+ },
455
+ ok() {
456
+ this.returnColumn()
457
+ this.saveLocalStorage()
458
+ this.visible = false
459
+ },
460
+ saveLocalStorage() {
461
+ const columnData = {
462
+ left: [],
463
+ center: [],
464
+ right: []
465
+ }
466
+ this.leftColumnList.map(({ prop }) => {
467
+ prop && columnData.left.push(prop)
468
+ })
469
+ this.columnList.map(({ prop }) => {
470
+ prop && columnData.center.push(prop)
471
+ })
472
+ this.rightColumnList.map(({ prop }) => {
473
+ prop && columnData.right.push(prop)
474
+ })
475
+ // console.log(columnData)
476
+ localStorage.setItem(this.columnName, JSON.stringify(columnData))
477
+ },
478
+ getLocalStorage() {
479
+ // console.log('name:', this.columnName)
480
+ const localData = localStorage.getItem(this.columnName)
481
+
482
+ if (localData) {
483
+ return JSON.parse(localData)
484
+ } else {
485
+ return
486
+ }
487
+ },
488
+ handleOpen() {
489
+ // console.log('handleOpen')
490
+ this.checkList = []
491
+ this.rightColumnList = []
492
+ this.leftColumnList = []
493
+ this.columnList = []
494
+ const localData = this.getLocalStorage()
495
+ localData && this.defaultColumnInit()
496
+ },
497
+ // 关闭弹窗
498
+ close() {
499
+ this.checkList = []
500
+ this.rightColumnList = []
501
+ this.leftColumnList = []
502
+ this.columnList = []
503
+ this.visible = false
504
+ this.$emit('closeDialog', { visible: false })
505
+ }
506
+ }
507
+ }
508
+ </script>
509
+
510
+ <style scoped lang="scss">
511
+ .bi-column-container {
512
+ display: flex;
513
+ justify-content: space-between;
514
+
515
+ .checkbox-container {
516
+ .checkbox-title {
517
+ cursor: pointer;
518
+ height: 34px;
519
+ line-height: 22px;
520
+ font-size: 14px;
521
+ font-weight: 500;
522
+ background-color: #f5f5f5;
523
+ color: #333;
524
+ position: relative;
525
+ padding-left: 12px;
526
+ margin-bottom: 12px;
527
+ border-radius: 4px;
528
+ align-items: center;
529
+ display: flex;
530
+ }
531
+ .el-checkbox-group {
532
+ display: flex;
533
+ flex-wrap: wrap;
534
+ justify-content: space-between;
535
+
536
+ margin-bottom: 0;
537
+ padding-left: 12px;
538
+
539
+ .el-checkbox {
540
+ width: 210px !important;
541
+ display: block;
542
+ float: left;
543
+ margin: 0 !important;
544
+ min-height: 32px;
545
+ max-height: 52px;
546
+ line-height: 20px;
547
+ }
548
+ }
549
+ }
550
+ .column-container {
551
+ margin-left: 20px;
552
+ width: 230px;
553
+ flex: 0 0 230px;
554
+
555
+ .column-title {
556
+ display: flex;
557
+ justify-content: space-between;
558
+ .el-button {
559
+ padding: 0;
560
+ }
561
+ }
562
+ .column-group-title {
563
+ font-size: 14px;
564
+ color: #8c8c8c;
565
+ margin: 5px 0;
566
+ }
567
+ .column-configurable {
568
+ .selected-column-item {
569
+ cursor: move;
570
+ height: 26px;
571
+ background: #f0f0f0;
572
+ border-radius: 4px;
573
+ line-height: 28px;
574
+ padding: 0 8px;
575
+ margin-top: 0;
576
+ display: flex;
577
+ align-items: center;
578
+ color: #666;
579
+ font-size: 14px;
580
+ &:not(:first-child) {
581
+ margin-top: 8px;
582
+ }
583
+ .column-name {
584
+ // width: 20px;
585
+ flex-grow: 2;
586
+ margin-left: 8px;
587
+ }
588
+ .column-close {
589
+ cursor: pointer;
590
+ }
591
+ }
592
+ }
593
+ }
594
+ }
595
+ </style>
596
+ <style lang="scss">
597
+ .bi-column-dialog {
598
+ .el-card__header {
599
+ background-color: #f8f9fa;
600
+ // border: #e0e0e0 1px solid;
601
+ box-sizing: border-box;
602
+ line-height: 22px;
603
+ padding: 8px 12px;
604
+ // border-radius: 4px 4px 0 0;
605
+ font-weight: 600;
606
+ color: #333;
607
+ }
608
+ .el-card__body {
609
+ padding: 12px 16px;
610
+ height: 395px;
611
+ box-sizing: border-box;
612
+ overflow-y: auto;
613
+ }
614
+ }
615
615
  </style>