shijiplus-web-plugin 0.1.34 → 0.1.36

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.
@@ -0,0 +1,584 @@
1
+ /* eslint-disable */
2
+ <template>
3
+ <div
4
+ ref="plusTableInnerRef"
5
+ :class="['plus-table-wrap', fixedHeader ? 'fixed-header' : '']"
6
+ >
7
+ <div
8
+ ref="searchAreaRef"
9
+ :class="[inlineForm && 'i-flex-wrap nowrap inline-wrap', 'p-search-area']"
10
+ v-if="showSearchArea"
11
+ >
12
+ <div :class="[inlineForm && 'f-grow']">
13
+ <PlusForm>
14
+ <Form :inline="inlineForm" :label-width="parseFloat(formLabelWidth)">
15
+ <slot name="searchArea"></slot>
16
+ <div
17
+ v-if="showButtonArea"
18
+ class="btn-area f-no-shrink i-flex-wrap f-grow"
19
+ >
20
+ <Button v-if="showSeachButton" type="primary" @click="onSearch">
21
+ 搜索
22
+ </Button>
23
+ <Button v-if="showResetButton" type="default" @click="onReset">
24
+ 重置
25
+ </Button>
26
+ <div class="operation-area f-grow f-row justify-end">
27
+ <slot name="operation"> </slot>
28
+ </div>
29
+ </div>
30
+ </Form>
31
+ </PlusForm>
32
+ </div>
33
+ </div>
34
+ <slot name="table">
35
+ <Table
36
+ :style="tableStyle"
37
+ :columns="showColumns"
38
+ :data="pageData"
39
+ :loading="loading"
40
+ :size="sizeType"
41
+ :height="height"
42
+ :noDataText="noDataText"
43
+ @on-selection-change="triggerSelectionChange"
44
+ @on-select-all="triggerSelectAll"
45
+ @on-sort-change="onSortChange"
46
+ @on-filter-change="onFilterChange"
47
+ >
48
+ <template
49
+ v-for="item in showColumns"
50
+ :slot="item.slot"
51
+ slot-scope="{ row, column, index }"
52
+ >
53
+ <slot
54
+ v-if="item.slot"
55
+ :name="item.slot"
56
+ :index="localPaging ? beginIndex + index : index"
57
+ :column="column"
58
+ :row="row"
59
+ >
60
+ {{ slotValue(item, row) }}
61
+ </slot>
62
+ <slot v-else-if="!item.render && !item.key">
63
+ {{ item.title }}-未设置渲染方式
64
+ </slot>
65
+ </template>
66
+ </Table>
67
+ </slot>
68
+ <div ref="footerRef">
69
+ <slot name="footer"></slot>
70
+ <div v-if="showPageArea" class="i-flex-wrap">
71
+ <Page
72
+ style="margin: 16px 0 0 auto"
73
+ :total="totalCount"
74
+ :current="currentPage"
75
+ @on-change="onPageChanged"
76
+ :page-size="pageSize"
77
+ :page-size-opts="[10, 20, 30, 50, 100]"
78
+ :show-total="showPageTotal"
79
+ :show-sizer="showPageSizer"
80
+ show-elevator
81
+ @on-page-size-change="onPageSizeChanged"
82
+ />
83
+ </div>
84
+ </div>
85
+ </div>
86
+ </template>
87
+
88
+ <script>
89
+ import exportMixin from './export-mixin'
90
+ import { exportTableExcel } from '../../../libs/util'
91
+ /**
92
+ * 统一了一些基础方法的写法
93
+ * 提供了refresh方法, 需要刷新当前页面时通过 $refs 调用
94
+ * 需要传递的参数 参考props
95
+ *
96
+ * 通过响应 'on-load-data' 事件加载数据, 事件参数包含 3 个属性
97
+ * currentPage: 读取数据的页码
98
+ * pageSize: 单页数据条数
99
+ * clearCondition: 是否需要清空搜索条件
100
+ */
101
+ export default {
102
+ name: 'PlusTable',
103
+ mixins: [exportMixin],
104
+ props: {
105
+ fixedHeader: {
106
+ type: Boolean,
107
+ default: false
108
+ },
109
+ formLabelWidth: {
110
+ type: [Number, String],
111
+ default: 100
112
+ },
113
+ inlineForm: {
114
+ type: Boolean,
115
+ default: false
116
+ },
117
+ // 表格列定义
118
+ columns: {
119
+ type: Array,
120
+ default() {
121
+ return []
122
+ }
123
+ },
124
+ localPaging: {
125
+ type: Boolean,
126
+ default: false
127
+ },
128
+ // 列表数据, 传入res.data即可
129
+ data: {
130
+ type: [Object, Array],
131
+ default() {
132
+ return {}
133
+ }
134
+ },
135
+ // 表格加载状态, 默认false
136
+ loading: {
137
+ type: Boolean,
138
+ default: false
139
+ },
140
+ noDataText: {
141
+ type: String,
142
+ default: '暂无数据'
143
+ },
144
+ // 显示页码按钮
145
+ showPageArea: {
146
+ type: Boolean,
147
+ default: true
148
+ },
149
+ // 显示搜索按钮
150
+ showSeachButton: {
151
+ type: Boolean,
152
+ default: true
153
+ },
154
+ // 显示重置按钮
155
+ showResetButton: {
156
+ type: Boolean,
157
+ default: true
158
+ },
159
+ // 显示按钮区域
160
+ showButtonArea: {
161
+ type: Boolean,
162
+ default: true
163
+ },
164
+ // 是否显示搜索区, 默认显示
165
+ showSearchArea: {
166
+ type: Boolean,
167
+ default: true
168
+ },
169
+ // 每页条数
170
+ defaultPageSize: {
171
+ type: Number,
172
+ default: 10
173
+ },
174
+ sizeType: {
175
+ type: String,
176
+ default: 'default'
177
+ },
178
+ showPageSizer: {
179
+ type: Boolean,
180
+ default: true
181
+ },
182
+ showPageTotal: {
183
+ type: Boolean,
184
+ default: true
185
+ }
186
+ },
187
+ watch: {
188
+ fixedHeader: {
189
+ handler(val) {
190
+ this.$nextTick(() => {
191
+ let tHeight = this.$refs.plusTableInnerRef.clientHeight
192
+ let tableWidth = this.$refs.plusTableInnerRef.clientWidth
193
+
194
+ // 获取元素的所有计算样式
195
+ var styles = window.getComputedStyle(this.$refs.plusTableInnerRef)
196
+
197
+ var styleHeight = parseFloat(styles.getPropertyValue('height'))
198
+ // 如果您只想获取特定方向的padding值,例如padding-top
199
+ var paddingLeft = parseFloat(styles.getPropertyValue('padding-left'))
200
+ var paddingRight = parseFloat(
201
+ styles.getPropertyValue('padding-right')
202
+ )
203
+ var paddingTop = parseFloat(styles.getPropertyValue('padding-top'))
204
+ var paddingBottom = parseFloat(
205
+ styles.getPropertyValue('padding-bottom')
206
+ )
207
+ if (paddingLeft) {
208
+ tableWidth -= paddingLeft
209
+ }
210
+ if (paddingRight) {
211
+ tableWidth -= paddingRight
212
+ }
213
+ if (paddingTop) {
214
+ tHeight -= paddingTop
215
+ }
216
+ if (paddingBottom) {
217
+ tHeight -= paddingBottom
218
+ }
219
+ this.tableWidth = tableWidth
220
+ if (this.$refs.searchAreaRef) {
221
+ tHeight -= this.$refs.searchAreaRef.clientHeight
222
+ }
223
+ if (this.$refs.footerRef) {
224
+ tHeight -= this.$refs.footerRef.clientHeight
225
+ }
226
+ if (val) {
227
+ this.height = tHeight
228
+ } else {
229
+ let tableWrap =
230
+ this.$refs.plusTableInnerRef.getElementsByClassName(
231
+ 'ivu-table-wrapper'
232
+ )[0]
233
+ if (tableWrap) {
234
+ if (!this.data.data || !this.data.data.length) {
235
+ tableWrap.style.minHeight = tHeight + 'px'
236
+ }
237
+ }
238
+ }
239
+ })
240
+ },
241
+ deep: true,
242
+ immediate: true
243
+ },
244
+ defaultPageSize: {
245
+ handler(val) {
246
+ if (val > 0) {
247
+ this.pageSize = val
248
+ }
249
+ },
250
+ deep: true,
251
+ immediate: true
252
+ },
253
+ data: {
254
+ handler(val) {
255
+ if (val) {
256
+ console.log('-----data--------', val)
257
+ let dataArray = []
258
+ if (val instanceof Array) {
259
+ dataArray = val
260
+ this.totalCount = val.length
261
+ } else {
262
+ dataArray = val.data || []
263
+ this.totalCount = 0
264
+ if (val.meta || val.totalCount) {
265
+ this.totalCount = val.totalCount || val.meta.totalCount
266
+ }
267
+ if (this.totalCount < dataArray.length) {
268
+ this.totalCount = dataArray.length
269
+ }
270
+ }
271
+ // if (this.localPaging) {
272
+ // const sortColumn = this.columns.filter((item) => {
273
+ // return item.sortable
274
+ // })[0]
275
+ // if (sortColumn) {
276
+ // dataArray = dataArray
277
+ // .map((item) => {
278
+ // return item
279
+ // })
280
+ // .sort((a, b) => {
281
+ // if (a[sortColumn.key] && b[sortColumn.key]) {
282
+ // if (sortColumn.sortType == 'desc') {
283
+ // return b[sortColumn.key] - a[sortColumn.key]
284
+ // }
285
+ // return a[sortColumn.key] - b[sortColumn.key]
286
+ // }
287
+ // return 0
288
+ // })
289
+ // }
290
+ // }
291
+
292
+ this.dataList = dataArray
293
+ } else {
294
+ this.dataList = []
295
+ this.totalCount = 0
296
+ }
297
+ },
298
+ deep: true,
299
+ immediate: true
300
+ }
301
+ },
302
+ computed: {
303
+ beginIndex() {
304
+ if (this.localPaging) {
305
+ return (this.currentPage - 1) * this.pageSize
306
+ }
307
+ return 0
308
+ },
309
+ pageData() {
310
+ if (this.localPaging) {
311
+ return this.dataList.slice(
312
+ this.beginIndex,
313
+ this.beginIndex + this.pageSize
314
+ )
315
+ }
316
+ return this.dataList
317
+ },
318
+ tableStyle() {
319
+ if (this.tableWidth) {
320
+ return { width: this.tableWidth + 'px' }
321
+ }
322
+ return {}
323
+ },
324
+ showColumns() {
325
+ return this.columns
326
+ .map((item) => {
327
+ if (!item.render && !item.slot) {
328
+ item.slot = `slot` + item.title
329
+ }
330
+ return item
331
+ })
332
+ .filter((item) => {
333
+ if (item.render) {
334
+ const oldRender = item.render
335
+ item.render = (h, params) => {
336
+ if (this.localPaging) {
337
+ params.index = this.beginIndex + params.index
338
+ }
339
+ return oldRender(h, params)
340
+ }
341
+ } else {
342
+ let realValue = ''
343
+ if (typeof item.defaultValue == 'function') {
344
+ realValue = item.defaultValue()
345
+ } else if (typeof item.defaultValue == 'number') {
346
+ realValue = `${item.defaultValue}`
347
+ } else {
348
+ realValue = item.defaultValue
349
+ }
350
+ if (realValue) {
351
+ item.render = (h, params) => {
352
+ if (!params.row[item.key]) {
353
+ return h('span', realValue)
354
+ }
355
+ return h('span', params.row[item.key])
356
+ }
357
+ }
358
+ }
359
+ if (item.filters) {
360
+ if (typeof item.filterMultiple != 'boolean') {
361
+ item.filterMultiple = false
362
+ }
363
+ if (!item.filterKey) {
364
+ item.filterKey = item.key
365
+ }
366
+ if (!item.filterRemote) {
367
+ item.filterRemote = (value, key, column) => {}
368
+ }
369
+ }
370
+ return !item.hide
371
+ })
372
+ }
373
+ },
374
+ data() {
375
+ return {
376
+ tableWidth: 0,
377
+ height: '',
378
+ dataList: [],
379
+ totalCount: 0,
380
+ currentPage: 1,
381
+ pageSize: 10
382
+ }
383
+ },
384
+ methods: {
385
+ slotValue(col, row) {
386
+ return (col.computeValue && col.computeValue(row)) || row[col.key]
387
+ },
388
+ onReset() {
389
+ this.currentPage = 1
390
+ this.triggerLoadEvent(true)
391
+ },
392
+ onSearch() {
393
+ this.currentPage = 1
394
+ this.triggerLoadEvent(false)
395
+ },
396
+ triggerSelectionChange(selection) {
397
+ this.$emit('on-selection-change', selection)
398
+ },
399
+ triggerSelectAll() {
400
+ this.$emit('on-select-all')
401
+ },
402
+ onSortChange(e) {
403
+ this.$emit('on-sort-change', e)
404
+ },
405
+ onFilterChange(e) {
406
+ this.$emit('on-filter-change', { ...e, value: e._filterChecked })
407
+ },
408
+ onPageSizeChanged(size) {
409
+ this.pageSize = size
410
+ this.triggerLoadEvent(false)
411
+ },
412
+ onPageChanged(idx) {
413
+ this.currentPage = idx
414
+ this.triggerLoadEvent(false)
415
+ },
416
+ refresh() {
417
+ this.triggerLoadEvent(false)
418
+ },
419
+ triggerLoadEvent(clearCondition) {
420
+ let e = {
421
+ currentPage: this.currentPage,
422
+ pageSize: this.pageSize,
423
+ clearCondition: clearCondition
424
+ }
425
+ this.$emit('on-load-data', e)
426
+ },
427
+ tableToExcel(p = { params: {}, apiFun: null, fileName: '' }) {
428
+ return new Promise((resolve, reject) => {
429
+ const { params, apiFun, fileName } = Object.assign({}, p)
430
+ if (!apiFun) {
431
+ // 防止被 外部 destory
432
+ setTimeout(() => {
433
+ this.$Message.error({
434
+ content: '需要指定导出的API'
435
+ })
436
+ }, 100)
437
+ resolve()
438
+ return
439
+ }
440
+ this.invokeExportExcel(
441
+ {
442
+ ...params
443
+ },
444
+ apiFun
445
+ )
446
+ .then((data) => {
447
+ if (data) {
448
+ return exportTableExcel(data, this.columns, fileName)
449
+ }
450
+ })
451
+ .finally(() => {
452
+ resolve()
453
+ })
454
+ })
455
+ }
456
+ },
457
+ mounted() {
458
+ this.onSearch()
459
+ }
460
+ }
461
+ </script>
462
+
463
+ <style lang="less" scoped>
464
+ .plus-table-wrap {
465
+ --sibling-nodes-height: 0px;
466
+ --table-th-bg-color: #f8f8f9;
467
+ background-color: #ffffff;
468
+ padding: 0px;
469
+ box-sizing: border-box;
470
+ &.fixed-header {
471
+ height: calc(~'100% - var(--sibling-nodes-height)');
472
+ }
473
+ .p-search-area {
474
+ position: relative;
475
+ padding-bottom: 16px;
476
+ &.inline-wrap {
477
+ padding-bottom: 0px;
478
+ }
479
+ /deep/.plus-form-wrap {
480
+ .ivu-form-item {
481
+ margin-bottom: 16px;
482
+ margin-right: 44px;
483
+ }
484
+ }
485
+ }
486
+ .btn-area {
487
+ // margin-top: auto;
488
+ button {
489
+ margin-left: 8px;
490
+ height: 32px;
491
+ &:first-child {
492
+ margin-left: 0px;
493
+ }
494
+ }
495
+ }
496
+ .operation-area {
497
+ & > * {
498
+ &:first-child {
499
+ margin-left: 48px !important;
500
+ }
501
+ }
502
+ }
503
+ .ivu-table-wrapper {
504
+ border: none;
505
+ /deep/.ivu-table {
506
+ &::before {
507
+ background-color: transparent;
508
+ }
509
+
510
+ &::after {
511
+ background-color: transparent;
512
+ }
513
+ th {
514
+ height: 54px;
515
+ border-bottom: none;
516
+ background-color: var(--table-th-bg-color);
517
+ .ivu-table-cell {
518
+ font-family: PingFangSC-SNaNpxibold;
519
+ font-weight: 600;
520
+ font-size: 14px;
521
+ color: #515a6e;
522
+ letter-spacing: 0.7px;
523
+ }
524
+ }
525
+ // td {
526
+ // height: 64px;
527
+ // }
528
+ .ivu-table-tip {
529
+ height: ~'calc(100% - 54px)'; // 54 header的高
530
+ table {
531
+ height: 100%;
532
+ }
533
+ }
534
+ .ivu-table-tbody {
535
+ .ivu-table-cell {
536
+ padding-top: 16px;
537
+ padding-bottom: 16px;
538
+ line-height: 1.4;
539
+ }
540
+ }
541
+ }
542
+ /deep/.ivu-table-cell {
543
+ padding-left: 12px;
544
+ padding-right: 12px;
545
+ }
546
+ /deep/.ivu-table-row {
547
+ .ivu-table-cell {
548
+ font-weight: 400;
549
+ font-size: 14px;
550
+ color: #515a6e;
551
+ letter-spacing: 0.7px;
552
+ .ivu-btn {
553
+ margin-right: 4px;
554
+ margin-bottom: 2px;
555
+ margin-top: 2px;
556
+ &:last-child {
557
+ margin-right: 0;
558
+ &:first-child {
559
+ margin-bottom: 0;
560
+ margin-top: 0px;
561
+ }
562
+ }
563
+ }
564
+ }
565
+ }
566
+ }
567
+ /deep/.ivu-page {
568
+ .ivu-page-options-sizer {
569
+ margin-right: 0px;
570
+ }
571
+ }
572
+ }
573
+ .ivu-form-item-error .plus-table-wrap {
574
+ border: #ff0000 1px solid;
575
+ border-radius: var(--border-radius);
576
+ overflow: hidden;
577
+ /deep/.ivu-select-selection {
578
+ border-color: var(--border-color) !important;
579
+ .ivu-select-arrow {
580
+ color: var(--subsidiary-color);
581
+ }
582
+ }
583
+ }
584
+ </style>