@kyfe/ks-query-table 0.0.1 → 0.0.2

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 (72) hide show
  1. package/README.md +45 -0
  2. package/api/index.js +12 -0
  3. package/assets/horizontal-back.svg +1 -0
  4. package/components/pe-table/cell.js +184 -0
  5. package/components/pe-table/collapse.js +334 -0
  6. package/components/pe-table/empty.vue +48 -0
  7. package/components/pe-table/header.js +328 -0
  8. package/components/pe-table/images/abnormal.png +0 -0
  9. package/components/pe-table/images/empty.png +0 -0
  10. package/components/pe-table/images/fold.svg +1 -0
  11. package/components/pe-table/images/sort.svg +1 -0
  12. package/components/pe-table/images/sorting.svg +1 -0
  13. package/components/pe-table/images/unfold.svg +1 -0
  14. package/components/pe-table/index.vue +837 -0
  15. package/components/pe-table/load-more.js +46 -0
  16. package/components/pe-table/props/index.js +183 -0
  17. package/components/pe-table/row.vue +118 -0
  18. package/components/pe-table/scrollbar.js +424 -0
  19. package/components/pe-table/stretch-damping.js +112 -0
  20. package/components/pe-table/style/cell.less +89 -0
  21. package/components/pe-table/style/empty.less +48 -0
  22. package/components/pe-table/style/header.less +141 -0
  23. package/components/pe-table/style/index.less +88 -0
  24. package/components/pe-table/style/load-more.less +61 -0
  25. package/components/pe-table/style/row.less +6 -0
  26. package/components/pe-table/table-loading.vue +119 -0
  27. package/components/pe-table/table-total.vue +53 -0
  28. package/components/pe-table/utils/animate.js +80 -0
  29. package/components/pe-table/utils/columns.js +290 -0
  30. package/components/pe-table/utils/data.js +12 -0
  31. package/components/pe-table/utils/fixed.js +69 -0
  32. package/components/pe-table/utils/formatter.js +327 -0
  33. package/components/pe-table/utils/render-cells.js +424 -0
  34. package/components/pe-table/utils/slot.js +28 -0
  35. package/components/pe-table/utils/tools.js +84 -0
  36. package/components/pe-table/utils/touch-scroll.js +417 -0
  37. package/components/query-table/index.vue +492 -0
  38. package/components/query-table/mixins/column-mixin.js +102 -0
  39. package/components/query-table/mixins/column-setting.js +143 -0
  40. package/components/query-table/mixins/data-mixin.js +502 -0
  41. package/components/query-table/mixins/pagination-mixin.js +25 -0
  42. package/components/query-table/mixins/table-fixed.js +111 -0
  43. package/components/query-table/mixins/table-horizontal.js +119 -0
  44. package/components/table-horizontal.vue +99 -0
  45. package/components/table-pagination.vue +32 -0
  46. package/components/table-settings/assets/arrpw-up.svg +1 -0
  47. package/components/table-settings/assets/disabled-down.svg +1 -0
  48. package/components/table-settings/assets/disabled-up.svg +1 -0
  49. package/components/table-settings/assets/down.svg +1 -0
  50. package/components/table-settings/assets/up.svg +1 -0
  51. package/components/table-settings/index.less +294 -0
  52. package/components/table-settings/index.vue +260 -0
  53. package/components/table-settings/settings.vue +479 -0
  54. package/components/table-settings/test.js +626 -0
  55. package/components/table-settings//344/270/252/346/200/247/350/256/276/347/275/256.md +0 -0
  56. package/components/tooltip.js +124 -0
  57. package/hooks/use-cache-promise.js +27 -0
  58. package/hooks/use-column-config.js +186 -0
  59. package/hooks/use-encryption.js +0 -0
  60. package/hooks/use-generic-search.js +95 -0
  61. package/index.js +7 -0
  62. package/package.json +2 -6
  63. package/store/column-store.js +0 -0
  64. package/styles/table.less +24 -0
  65. package/utils/column.js +36 -0
  66. package/utils/config.js +12 -0
  67. package/utils/encryption.js +32 -0
  68. package/utils/http.js +1 -0
  69. package/utils/localStorage.js +35 -0
  70. package/dist/ks-query-table.css +0 -1
  71. package/dist/ks-query-table.umd.min.js +0 -11
  72. package/dist/ks-query-table.umd.min.js.map +0 -1
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ ## 目录说明
2
+
3
+
4
+ - **/assets**: 存放公共资源,如图标。
5
+ - **/components**: 存放组件。
6
+ - **/query-table**: 主组件。
7
+ - **/index.vue**: 主组件。
8
+ - **/mixins**: query-table的mixins。
9
+ - **/column-mixin**: 表格列头相关。
10
+ - **/column-setting**: 个性设置相关。
11
+ - **/data-mixin**: 行数据相关。
12
+ - **/pagination-mixin**: 表格分页相关。
13
+ - **/table-fixed**: 吸顶相关。
14
+ - **/table-horizontal.js**: 横屏相关。
15
+
16
+
17
+ - **/table-horizontal**: 表格横屏组件。
18
+ - **/table-pagination**: 表格分页组件。
19
+ - **table-settings**: 个性设置组件。
20
+ - **tooltip**: 单元格气泡组件。
21
+ - **/demo**: 存放demo。
22
+ - **/hooks**: 存放封装的通用逻辑。与utils不同的是,hooks内部是可以有状态、多实例的。
23
+ - **/use-cache-promise**: 缓存promise结果。
24
+ - **/use-column-config**: 获取列配置
25
+ - **/use-encryption**: 加解密
26
+
27
+
28
+
29
+ - **/index.js**: 项目主入口。
30
+ - **/mixins**: 项目级mixins。
31
+ - **/store**: 存放共享数据。注意,不带响应式。
32
+ - **/column-store**: 列存储
33
+
34
+ - **/styles**: 存放样式。
35
+ - **/utils**: 存放工具函数。
36
+ - **/column**: 列工具
37
+ - **/encryption**: 加解密
38
+ - **/http**: http
39
+
40
+
41
+
42
+ - **/tests**: 存放测试文件,确保代码的质量。
43
+
44
+
45
+ - **README.md**: 项目说明文件,提供项目的基本信息和使用说明。
package/api/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { http } from '../utils/http'
2
+
3
+ export const APPKEY_SYSTEM = '10124'
4
+
5
+ // 获取当前菜单下的通用查询配置
6
+ export const getGenericSearch = () => {
7
+ return http('system.genericSearch.listByMenuId', APPKEY_SYSTEM, { menuId: ksui.menu.id })
8
+ }
9
+
10
+ // 通过id获取详细配置
11
+ export const getGenericSearchById = (params) =>
12
+ http('system.genericSearch.get', APPKEY_SYSTEM, params)
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="24" height="24" viewBox="0 0 24 24"><g><g><path d="M16.799951171875,4.299951171875L8.994601171875,11.999951171875L16.799951171875,19.699951171875L15.684901171875,20.799951171875L7.507864171875,12.733281171875C7.097313171875,12.328281171875,7.097313171875,11.671631171875,7.507864171875,11.266621171875L15.684901171875,3.199951171875L16.799951171875,4.299951171875Z" fill-rule="evenodd" fill="#1C1E23" fill-opacity="1"/></g></g></svg>
@@ -0,0 +1,184 @@
1
+ /** @format */
2
+
3
+ import isFunction from 'lodash/isFunction'
4
+ import './style/cell.less'
5
+
6
+ export default {
7
+ name: 'cellCompoent',
8
+ computed: {
9
+ style() {
10
+ const obj = this.fixed
11
+ ? {
12
+ zIndex: '10',
13
+ }
14
+ : {}
15
+ return {
16
+ width: this.width + 'px',
17
+ transform: `translateX(${this.offset}px)`,
18
+ ...obj,
19
+ }
20
+ },
21
+ fixedClassName() {
22
+ return this.fixed ? 'pe-table-cell__fixed' : ''
23
+ },
24
+ lastFixedClassName() {
25
+ return this.lastFixedCell ? 'pe-table-cell__last-fixed' : ''
26
+ },
27
+ },
28
+ data() {
29
+ return {
30
+ width: 0,
31
+ offset: 0,
32
+ text: '',
33
+ column: undefined,
34
+ fixed: false,
35
+ lastFixedCell: false,
36
+ rowData: undefined,
37
+ handleEvent: undefined,
38
+ cellClassName: undefined,
39
+ globalCellClassName: undefined,
40
+ placeholderSign: false,
41
+ longPressTimer: null,
42
+ }
43
+ },
44
+ mounted() {
45
+ const $cell = this.$refs.cell
46
+ $cell.addEventListener('mousedown', this.startLongPress)
47
+ $cell.addEventListener('mouseup', this.endLongPress)
48
+ $cell.addEventListener('mouseleave', this.endLongPress)
49
+
50
+ $cell.addEventListener('touchstart', this.startLongPress)
51
+ $cell.addEventListener('touchend', this.endLongPress)
52
+ $cell.addEventListener('touchmove', this.endLongPress)
53
+ $cell.addEventListener('touchcancel', this.endLongPress)
54
+ },
55
+ beforeDestroy() {
56
+ const $cell = this.$refs.cell
57
+ $cell.removeEventListener('mousedown', this.startLongPress)
58
+ $cell.removeEventListener('mouseup', this.endLongPress)
59
+ $cell.removeEventListener('mouseleave', this.endLongPress)
60
+
61
+ $cell.removeEventListener('touchstart', this.startLongPress)
62
+ $cell.removeEventListener('touchend', this.endLongPress)
63
+ $cell.removeEventListener('touchmove', this.endLongPress)
64
+ $cell.removeEventListener('touchcancel', this.endLongPress)
65
+ },
66
+ render(h) {
67
+ const { rowCellRender, key } = this.column || {}
68
+ const createContent = () => {
69
+ if (this.placeholderSign) {
70
+ return null
71
+ }
72
+ let labelNode = null
73
+ const params = {
74
+ column: this.column,
75
+ value: this.text,
76
+ rowData: this.originRowData,
77
+ columnIndex: this.columnIndex,
78
+ rowIndex: this.rowIndex,
79
+ }
80
+ const defaultLable = () => <span class="pe-table-cell_label">{this.text}</span>
81
+ if (isFunction(rowCellRender)) {
82
+ labelNode = rowCellRender(h, params)
83
+ if (labelNode === null) {
84
+ labelNode = defaultLable()
85
+ }
86
+ } else {
87
+ labelNode = defaultLable()
88
+ }
89
+ return labelNode
90
+ }
91
+ const content = createContent()
92
+ let classNames = [
93
+ 'pe-table-cell',
94
+ this.globalCellClassName,
95
+ this.cellClassName,
96
+ this.lastFixedClassName,
97
+ this.fixedClassName
98
+ ]
99
+ return (
100
+ <div
101
+ ref="cell"
102
+ class={classNames}
103
+ style={this.style}
104
+ on-click={this.handleClickEvent}
105
+ data-cellkey={key}
106
+ >
107
+ {content}
108
+ </div>
109
+ )
110
+ },
111
+ methods: {
112
+ setContent(text) {
113
+ // 判空,否则没有值会显示undefined,特别是自定义列没有返回的时候
114
+ if (undefined === text) {
115
+ return ''
116
+ }
117
+ this.text = String(text)
118
+ },
119
+ setOffset(offset) {
120
+ this.offset = offset
121
+ },
122
+ reuse({
123
+ id,
124
+ offset,
125
+ text,
126
+ width,
127
+ column,
128
+ fixed,
129
+ lastFixedCell,
130
+ rowData,
131
+ columnIndex,
132
+ rowIndex,
133
+ cellClassName,
134
+ originRowData,
135
+ globalCellClassName,
136
+ placeholderSign,
137
+ }) {
138
+ this.id = id
139
+ this.width = width
140
+ this.column = column
141
+ this.fixed = fixed
142
+ this.lastFixedCell = lastFixedCell
143
+ this.rowData = rowData
144
+ this.columnIndex = columnIndex
145
+ this.rowIndex = rowIndex
146
+ this.cellClassName = cellClassName
147
+ this.globalCellClassName = globalCellClassName
148
+ this.originRowData = originRowData
149
+ this.placeholderSign = placeholderSign
150
+ this.setOffset(offset)
151
+ this.setContent(text)
152
+ },
153
+ handleClickEvent(event) {
154
+ const params = {
155
+ column: this.column,
156
+ rowData: this.originRowData,
157
+ name: 'cell-click',
158
+ rowIndex: this.rowIndex,
159
+ columnIndex: this.columnIndex,
160
+ }
161
+ this.handleEvent && this.handleEvent(event, params)
162
+ },
163
+ handleLongEvent(event, params) {
164
+ this.handleEvent && this.handleEvent(event, params)
165
+ },
166
+ startLongPress(event) {
167
+ this.longPressTimer && this.endLongPress()
168
+ const params = {
169
+ column: this.column,
170
+ rowData: this.originRowData,
171
+ name: 'cell-long',
172
+ rowIndex: this.rowIndex,
173
+ columnIndex: this.columnIndex,
174
+ }
175
+ this.longPressTimer = setTimeout(() => {
176
+ this.handleLongEvent(event, params)
177
+ }, 500);
178
+ },
179
+ endLongPress() {
180
+ clearTimeout(this.longPressTimer)
181
+ this.longPressTimer = null
182
+ },
183
+ },
184
+ }
@@ -0,0 +1,334 @@
1
+ /** @format */
2
+
3
+ // import cloneDeep from 'lodash/cloneDeep'
4
+ // // const queue = []
5
+ // let loading = false
6
+ // export const collapseClass = {
7
+ // bg: 'table2-cell-collapse-bg',
8
+ // colMark: 'table2-cell-collapse_colMark'
9
+ // }
10
+
11
+ // let checkExpandTimer
12
+
13
+ // // // 执行队列中的方法
14
+ // // async function executeQueue() {
15
+ // // // 如果已经有方法在执行或队列为空,则直接返回
16
+ // // if (loading || queue.length === 0) return
17
+
18
+ // // // 获取队列中的第一个方法并执行
19
+ // // const { fn, context, args } = queue.shift()
20
+ // // try {
21
+ // // await fn.apply(context, args)
22
+ // // } catch (error) {
23
+ // // console.error('Error while executing changeCollapseKeys:', error)
24
+ // // } finally {
25
+ // // loading = false
26
+ // // // 继续执行队列中的下一个方法
27
+ // // executeQueue()
28
+ // // }
29
+ // // }
30
+
31
+ // // // 添加方法到队列的函数
32
+ // // function addToQueue(fn, context, args) {
33
+ // // queue.push({ fn, context, args })
34
+ // // }
35
+
36
+ // const collapseType = {
37
+ // expand: 'expand',
38
+ // collapse: 'collapse'
39
+ // }
40
+
41
+ // function formatGroupInfo(group, column) {
42
+ // group.push(column)
43
+ // }
44
+
45
+ // function resetColumnsWidth(collapseAnimationGroup = []) {
46
+ // collapseAnimationGroup.forEach(groupInfo => {
47
+ // groupInfo.columnGroups.forEach(column => {
48
+ // // 解决默认是折叠,然后点击展开
49
+ // if (column.$collapseWidth === undefined) {
50
+ // column.$collapseWidth = column.width
51
+ // }
52
+ // column.width = 0.1
53
+ // })
54
+ // })
55
+ // }
56
+
57
+ // function getCollapseAnimationGroup(collapseKeys, columns) {
58
+ // collapseKeys = cloneDeep(collapseKeys)
59
+ // const groups = []
60
+ // let consecutiveGroup = []
61
+ // columns.forEach(column => {
62
+ // if (collapseKeys.includes(column.key)) {
63
+ // const isChild = column.children && column.children.length
64
+ // if (isChild) {
65
+ // column.children.forEach(childCol => {
66
+ // if (!collapseKeys.includes(childCol.key)) {
67
+ // collapseKeys.push(childCol.key)
68
+ // }
69
+ // })
70
+ // }
71
+ // formatGroupInfo(consecutiveGroup, column)
72
+ // } else {
73
+ // if (consecutiveGroup.length > 0) {
74
+ // groups.push(consecutiveGroup)
75
+ // consecutiveGroup = []
76
+ // }
77
+ // }
78
+ // })
79
+ // consecutiveGroup.length > 0 && groups.push(consecutiveGroup)
80
+ // // 组装配置参数
81
+ // return groups.reduce((res, cur = []) => {
82
+ // res.push({
83
+ // columnGroups: cur,
84
+ // ...cur.reduce(
85
+ // (r, c) => {
86
+ // const { totalWidth } = r
87
+ // r.totalWidth = totalWidth + c.width
88
+ // return r
89
+ // },
90
+ // {
91
+ // totalWidth: 0
92
+ // }
93
+ // )
94
+ // })
95
+ // return res
96
+ // }, [])
97
+ // }
98
+
99
+ // function getCollapseClassNames(labelClassName = '', type) {
100
+ // try {
101
+ // let classNames = labelClassName
102
+ // if (type === 'add') {
103
+ // if (!labelClassName || !labelClassName.includes(collapseClass.bg)) {
104
+ // classNames = `${labelClassName || ''} ${collapseClass.bg}`
105
+ // }
106
+ // } else {
107
+ // classNames = (labelClassName || '').replace(collapseClass.bg, '')
108
+ // }
109
+ // return classNames
110
+ // } catch (e) {
111
+ // return labelClassName
112
+ // }
113
+ // }
114
+
115
+ // function setColumnHighlight(column, visibleFlatColumns) {
116
+ // const collapseColumn = visibleFlatColumns && visibleFlatColumns.find(col => col.key === column.key)
117
+ // if (collapseColumn) collapseColumn.labelClassName = getCollapseClassNames(column.labelClassName, 'add')
118
+ // }
119
+
120
+ // function removeColumnHighlight(column, visibleFlatColumns) {
121
+ // if (column.labelClassName) {
122
+ // const collapseColumn = visibleFlatColumns && visibleFlatColumns.find(col => col.key === column.key)
123
+ // if (collapseColumn) collapseColumn.labelClassName = getCollapseClassNames(column.labelClassName)
124
+ // }
125
+ // }
126
+
127
+ // function createTransitionTime(v = 3) {
128
+ // return `transition: width .${v}s;`
129
+ // }
130
+
131
+ // function setCellCollapseHighlightClass(tds = [], colgroup = [], type, column) {
132
+ // tds.forEach(td => {
133
+ // const [cellEl] = td.children || []
134
+ // if (cellEl && cellEl.classList) {
135
+ // cellEl.classList.add(collapseClass.bg)
136
+ // }
137
+ // })
138
+ // colgroup.forEach(col => {
139
+ // if (col && col.classList) {
140
+ // col.classList.add(collapseClass.colMark)
141
+ // col.style = createTransitionTime()
142
+ // }
143
+ // })
144
+ // // 不做重复采集,场景问题: 当折叠收起子级后,马上再点击,收起父级。则会被重复采集,设置为0.1。
145
+ // if (type === collapseType.collapse && column.width !== 0.1) {
146
+ // column.$collapseWidth = column.width
147
+ // column.width = 0.1
148
+ // } else {
149
+ // column.width = column.$collapseWidth
150
+ // }
151
+ // }
152
+
153
+ // export function removeCellCollapseHighlightClass(tableEl) {
154
+ // loading = false
155
+ // const colgroup = tableEl.querySelectorAll(`.${collapseClass.colMark}`)
156
+ // // if (isRemoveBg) {
157
+ // // const cells = tableEl.querySelectorAll(`.${collapseClass.bg}`)
158
+ // // cells.forEach(el => {
159
+ // // el.classList.remove(collapseClass.bg)
160
+ // // })
161
+ // // }
162
+ // colgroup.forEach(el => {
163
+ // el.classList.remove(collapseClass.colMark)
164
+ // el.style = ''
165
+ // })
166
+ // }
167
+
168
+ // function renderHighlightGroup(collapseAnimationGroup, tableEl, type, callback, vm, emitParams) {
169
+ // try {
170
+ // collapseAnimationGroup.forEach(groupInfo => {
171
+ // groupInfo.columnGroups.forEach(column => {
172
+ // const { key } = column
173
+ // // 设置列背景色高亮
174
+ // column.labelClassName = getCollapseClassNames(column.labelClassName, 'add')
175
+ // column.className = getCollapseClassNames(column.className, 'add')
176
+ // const colgroup = tableEl.querySelectorAll(`[name="${key}"]`)
177
+ // setCellCollapseHighlightClass([], colgroup, type, column)
178
+ // })
179
+ // })
180
+ // const isCollapse = type === collapseType.collapse
181
+ // setTimeout(
182
+ // () => {
183
+ // removeCellCollapseHighlightClass(tableEl, isCollapse)
184
+ // isCollapse && callback()
185
+ // vm.$emit('collapsed', emitParams)
186
+ // // vm._updateTableHeight() // 存在全部一级头点击展开变成二级头,高度计算有误
187
+ // // vm.table._updateTableHeight() // 存在全部一级头点击展开变成二级头,高度计算有误
188
+ // },
189
+ // isCollapse ? 300 : 500
190
+ // )
191
+ // } catch (e) {
192
+ // loading = false
193
+ // }
194
+ // }
195
+
196
+ export default {
197
+ methods: {
198
+ changeCollapseKeys(column) {
199
+ // if (loading) return
200
+ const { collapsed, collapseKeys } = column
201
+ // console.log(key, '---k')
202
+ if (!Array.isArray(collapseKeys) || !this.tableData.length) {
203
+ return
204
+ }
205
+ // loading = true
206
+ const val = !collapsed
207
+ // const visibleFlatColumns = this.visibleFlatColumns
208
+ // const type = collapsed === true ? collapseType.expand : collapseType.collapse
209
+ // const collapseAnimationGroup = getCollapseAnimationGroup(collapseKeys, visibleFlatColumns)
210
+ // const tableEl = this.$el || document
211
+ // const isExpand = type === collapseType.expand
212
+ // clearTimeout(checkExpandTimer)
213
+ // this.checkColumnFreeze(collapseAnimationGroup)
214
+ // if (isExpand) {
215
+ // resetColumnsWidth(collapseAnimationGroup)
216
+ this.updateCollapseMap(collapseKeys, val, column)
217
+ // setColumnHighlight(column, visibleFlatColumns)
218
+ // } else {
219
+ // removeColumnHighlight(column, visibleFlatColumns)
220
+ // }
221
+ // 延迟的目的是为了在做展开的时候先把width:0.1绘制出来
222
+ // setTimeout(
223
+ // () => {
224
+ // const emitParams = { key, column, collapsed: val }
225
+ // renderHighlightGroup(
226
+ // collapseAnimationGroup,
227
+ // tableEl,
228
+ // type,
229
+ // this.updateCollapseMap.bind(this, collapseKeys, val, column),
230
+ // this,
231
+ // emitParams
232
+ // )
233
+ // column.collapsed = type !== collapseType.expand
234
+ // // this.updateColumns()
235
+ // },
236
+ // isExpand ? 20 : 0
237
+ // )
238
+ },
239
+ checkColumnFreeze(columnGroups) {
240
+ try {
241
+ const isAllHide = columnGroups
242
+ .reduce((v, cur) => {
243
+ v.push(...(cur.columnGroups || []).map(col => col.$show))
244
+ return v
245
+ }, [])
246
+ .every(status => status === false)
247
+ if (isAllHide === true) {
248
+ this.table.$message.warning('当前所有被控制列均被隐藏')
249
+ }
250
+ } catch (err) {
251
+ // eslint-disable-next-line
252
+ console.log(err)
253
+ }
254
+ },
255
+ updateCollapseMap(collapseKeys, status, column) {
256
+ const { key } = column
257
+ const visibleFlatColumns = this.visibleFlatColumns
258
+ for (let i = 0; i < collapseKeys.length; i++) {
259
+ const collapseKey = collapseKeys[i]
260
+ this.collapsedMap[collapseKey] = status
261
+ const index = visibleFlatColumns.findIndex(col => col.key === collapseKey)
262
+ if (index > -1) {
263
+ const col = visibleFlatColumns[index] || {}
264
+ const { childKeys = [], parentNodeKeys, collapseKeys = [] } = col
265
+ col.collapseBg = !status ? 'collapse-bg' : ''
266
+ // 子级的状态需要更新:
267
+ childKeys &&
268
+ childKeys.length &&
269
+ childKeys.forEach(k => {
270
+ if (collapseKeys.indexOf(k) > -1) {
271
+ return true
272
+ }
273
+ this.$set(this.collapsedMap, k, status)
274
+ const childCol = visibleFlatColumns.find(col => col.key === k)
275
+ // 更新对应的column的 collapsed 状态, 如果也存在collapseKeys的话。
276
+ if (childCol && childCol.collapseKeys && childCol.collapseKeys.length) {
277
+ childCol.collapsed = status
278
+ }
279
+ })
280
+ // if (collapseKeys && collapseKeys.length) {
281
+ // col.collapsed = collapseKeys.every(k => this.collapsedMap[k])
282
+ // }
283
+ // 如果存在父级,则在展开的情况下父级也必须展开
284
+ if (!status) {
285
+ parentNodeKeys &&
286
+ parentNodeKeys.length &&
287
+ parentNodeKeys.forEach(k => {
288
+ this.$set(this.collapsedMap, k, status)
289
+ })
290
+ } else {
291
+ // 如果子节点有一个展开,那么自己也要展开
292
+ const hasShowChild = childKeys.length && childKeys.some(k => !this.collapsedMap[k])
293
+ if (hasShowChild) {
294
+ this.$set(this.collapsedMap, col.key, !status)
295
+ }
296
+ }
297
+ }
298
+ this.updateVisibleFlatColumnsCol(key, {
299
+ collapsed: status,
300
+ collapseBg: !status ? 'collapse-bg' : ''
301
+ })
302
+ }
303
+ // 判断所有子节点是否被折叠,是则需要折叠自己
304
+ if (column.childKeys && column.childKeys.length) {
305
+ if (column.childKeys.every(k => this.collapsedMap[k])) {
306
+ this.collapsedMap[key] = status
307
+ }
308
+ }
309
+ this.updateColumns()
310
+ this.createHeader()
311
+ this.renderViewportRows()
312
+ this.renderViewportCells()
313
+ // 重新计算滚动条,且保持滚动条位置不变
314
+ this.setScrollOffsetX(this.offsetX)
315
+ this.refreshThumb()
316
+ this.$emit('collapsed')
317
+ },
318
+ updateVisibleFlatColumnsCol(key, obj) {
319
+ const visibleFlatColumns = this.visibleFlatColumns
320
+ const index = visibleFlatColumns.findIndex(col => col.key === key)
321
+ if (index === -1) {
322
+ return
323
+ }
324
+ const col = visibleFlatColumns[index]
325
+ for (const colKey in obj) {
326
+ if (!Object.hasOwnProperty.call(col, colKey)) {
327
+ this.$set(col, colKey, obj[colKey])
328
+ } else {
329
+ col[colKey] = obj[colKey]
330
+ }
331
+ }
332
+ },
333
+ },
334
+ }
@@ -0,0 +1,48 @@
1
+ <script>
2
+ import './style/empty.less'
3
+ export default {
4
+ props: {
5
+ isAbnormal: {
6
+ type: Boolean,
7
+ default: false,
8
+ },
9
+ emptyText: {
10
+ type: String,
11
+ default: '暂无数据',
12
+ },
13
+ headerTotalHeight: {
14
+ type: [Number, String],
15
+ default: 0,
16
+ },
17
+ },
18
+ methods: {
19
+ tableAbnormal() {
20
+ this.$emit('abnormal')
21
+ },
22
+ },
23
+ render() {
24
+ const { isAbnormal, emptyText } = this.$props
25
+ // 无数据
26
+ const createEmptyNode = () => {
27
+ return [<div class="pe-table-empty_bg"></div>, <span class="pe-table-empty_label">{emptyText}</span>]
28
+ }
29
+ // 断网
30
+ const createAbnormal = () => {
31
+ return (
32
+ <div class="abnormal">
33
+ <div class="abnormal-img"></div>
34
+ <div class="abnormal-desc">加载超时,请检查网络</div>
35
+ <ks-button onClick={() => this.tableAbnormal()} plain hairline type="primary" color="#F2412F">
36
+ 重新加载
37
+ </ks-button>
38
+ </div>
39
+ )
40
+ }
41
+ return (
42
+ <div class="pe-table-empty" style={{ top: this.headerTotalHeight + 40 + 'PX' }}>
43
+ {isAbnormal ? createAbnormal() : createEmptyNode()}
44
+ </div>
45
+ )
46
+ },
47
+ }
48
+ </script>