@kyfe/ks-query-table 0.0.2 → 0.0.3

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 (75) hide show
  1. package/index.js +35386 -7
  2. package/package.json +7 -5
  3. package/query-table.common.js.map +1 -0
  4. package/query-table.css +1 -0
  5. package/query-table.umd.js +35396 -0
  6. package/query-table.umd.js.map +1 -0
  7. package/query-table.umd.min.js +11 -0
  8. package/query-table.umd.min.js.map +1 -0
  9. package/README.md +0 -45
  10. package/api/index.js +0 -12
  11. package/assets/horizontal-back.svg +0 -1
  12. package/components/pe-table/cell.js +0 -184
  13. package/components/pe-table/collapse.js +0 -334
  14. package/components/pe-table/empty.vue +0 -48
  15. package/components/pe-table/header.js +0 -328
  16. package/components/pe-table/images/abnormal.png +0 -0
  17. package/components/pe-table/images/empty.png +0 -0
  18. package/components/pe-table/images/fold.svg +0 -1
  19. package/components/pe-table/images/sort.svg +0 -1
  20. package/components/pe-table/images/sorting.svg +0 -1
  21. package/components/pe-table/images/unfold.svg +0 -1
  22. package/components/pe-table/index.vue +0 -837
  23. package/components/pe-table/load-more.js +0 -46
  24. package/components/pe-table/props/index.js +0 -183
  25. package/components/pe-table/row.vue +0 -118
  26. package/components/pe-table/scrollbar.js +0 -424
  27. package/components/pe-table/stretch-damping.js +0 -112
  28. package/components/pe-table/style/cell.less +0 -89
  29. package/components/pe-table/style/empty.less +0 -48
  30. package/components/pe-table/style/header.less +0 -141
  31. package/components/pe-table/style/index.less +0 -88
  32. package/components/pe-table/style/load-more.less +0 -61
  33. package/components/pe-table/style/row.less +0 -6
  34. package/components/pe-table/table-loading.vue +0 -119
  35. package/components/pe-table/table-total.vue +0 -53
  36. package/components/pe-table/utils/animate.js +0 -80
  37. package/components/pe-table/utils/columns.js +0 -290
  38. package/components/pe-table/utils/data.js +0 -12
  39. package/components/pe-table/utils/fixed.js +0 -69
  40. package/components/pe-table/utils/formatter.js +0 -327
  41. package/components/pe-table/utils/render-cells.js +0 -424
  42. package/components/pe-table/utils/slot.js +0 -28
  43. package/components/pe-table/utils/tools.js +0 -84
  44. package/components/pe-table/utils/touch-scroll.js +0 -417
  45. package/components/query-table/index.vue +0 -492
  46. package/components/query-table/mixins/column-mixin.js +0 -102
  47. package/components/query-table/mixins/column-setting.js +0 -143
  48. package/components/query-table/mixins/data-mixin.js +0 -502
  49. package/components/query-table/mixins/pagination-mixin.js +0 -25
  50. package/components/query-table/mixins/table-fixed.js +0 -111
  51. package/components/query-table/mixins/table-horizontal.js +0 -119
  52. package/components/table-horizontal.vue +0 -99
  53. package/components/table-pagination.vue +0 -32
  54. package/components/table-settings/assets/arrpw-up.svg +0 -1
  55. package/components/table-settings/assets/disabled-down.svg +0 -1
  56. package/components/table-settings/assets/disabled-up.svg +0 -1
  57. package/components/table-settings/assets/down.svg +0 -1
  58. package/components/table-settings/assets/up.svg +0 -1
  59. package/components/table-settings/index.less +0 -294
  60. package/components/table-settings/index.vue +0 -260
  61. package/components/table-settings/settings.vue +0 -479
  62. package/components/table-settings/test.js +0 -626
  63. package/components/table-settings//344/270/252/346/200/247/350/256/276/347/275/256.md +0 -0
  64. package/components/tooltip.js +0 -124
  65. package/hooks/use-cache-promise.js +0 -27
  66. package/hooks/use-column-config.js +0 -186
  67. package/hooks/use-encryption.js +0 -0
  68. package/hooks/use-generic-search.js +0 -95
  69. package/store/column-store.js +0 -0
  70. package/styles/table.less +0 -24
  71. package/utils/column.js +0 -36
  72. package/utils/config.js +0 -12
  73. package/utils/encryption.js +0 -32
  74. package/utils/http.js +0 -1
  75. package/utils/localStorage.js +0 -35
@@ -1,143 +0,0 @@
1
- import { upDateLocalCache } from '../../../hooks/use-generic-search'
2
- import TableSettings from '../../table-settings/index.vue'
3
- import { setLocalStorageItem } from '../../../utils/localStorage'
4
-
5
-
6
- export default {
7
- data() {
8
- return {
9
- showSetting: false,
10
- }
11
- },
12
- methods: {
13
- createTableSetting() {
14
- const $props = this.$props
15
- if (!$props.showSettingDialog) {
16
- return null
17
- }
18
- const slot = this.$slots.default ? this.$slots.default[0] : this.$scopedSlots
19
- const tableSettingAttrs = {
20
- props: {
21
- value: this.showSetting,
22
- tableColumns: this.onlineColumns,
23
- innerTabVisible: this.$props.innerTabVisible,
24
- disabledAutoHideClose: this.$props.disabledAutoHideClose,
25
- isShowHorizontal: this.isShowHorizontal,
26
- },
27
- on: {
28
- input: val => (this.showSetting = val),
29
- confirm: this.settingsConfirm,
30
- initColumns: this.initColumns,
31
- cancel: this.settingsCancel,
32
- back: this.settingsBack,
33
- reset: this.settingsReset,
34
- },
35
- ref: 'tableSettings',
36
- scopedSlots: {
37
- top: slot['setting-top'],
38
- },
39
- }
40
- return <TableSettings {...tableSettingAttrs}></TableSettings>
41
- },
42
- // 打开个性设置弹窗
43
- openSetting() {
44
- this.showSetting = true
45
- },
46
- // 个性设置弹窗关闭确认
47
- settingsConfirm(val) {
48
- // 关闭动画和设置列头同时执行,在低端机器下阻塞进程。
49
- setTimeout(async () => {
50
- this.setOnlineColumns(val)
51
- this.setColsToStorage(val)
52
- await this.saveConfigToHttp(this.onlineColumns)
53
- this.$emit('settingsConfirm', this.onlineColumns)
54
- }, 0)
55
- },
56
- setColsToStorage(clos) {
57
- if (!this.needCache) return
58
- setLocalStorageItem('pe_stocks_quotes_table_fields-' + this.searchCode || '', JSON.stringify(clos))
59
- },
60
- // 个性设置取消
61
- settingsCancel() {
62
- this.$emit('settingsCancel')
63
- },
64
- // 个性设置返回
65
- settingsBack() {
66
- this.$emit('settingsBack')
67
- },
68
- // 个性设置重置
69
- async settingsReset() {
70
- this.resizeColumnMap = this.clearResizeColumnMap()
71
- let val = await this.resetToHttp()
72
- this.setOnlineColumns(val)
73
- this.setColsToStorage(val)
74
- this.$emit('settingsReset', this.onlineColumns)
75
- },
76
- /**
77
- * 用户变更列显示/隐藏后,保存状态
78
- * @param {*} columns
79
- * @returns
80
- */
81
- async saveConfigToHttp(columns) {
82
- if (this.columns.length && !this.forceSaveSettings) {
83
- return
84
- }
85
- this.genericId = await this.getGenericId()
86
- let fieldContent = this.formatFieldContent(columns)
87
- let fieldSnapshot = this.formatFieldSnapshot(columns)
88
- let params = {
89
- genericId: this.genericId,
90
- menuId: ksui.menu.id,
91
- fieldContent: JSON.stringify(fieldContent),
92
- fieldSnapshot: JSON.stringify(fieldSnapshot),
93
- }
94
- await this.$http('system.genericSearch.field.saveOrUpdate', 10124, params)
95
- await upDateLocalCache(params, 'update')
96
- },
97
- /**
98
- * 个性设置重置
99
- * @returns
100
- */
101
- async resetToHttp() {
102
- this.genericId = await this.getGenericId()
103
- let params = {
104
- genericId: this.genericId,
105
- menuId: ksui.menu.id
106
- }
107
- let res = await this.$http('system.genericSearch.field.reset', 10124, params)
108
- window.vant.Toast('重置成功')
109
- let resetCols = JSON.parse(res.genericSearch)
110
- resetCols.forEach(v => this.mergeColumn(v))
111
- // upDateCatch({ id: params.genericId })
112
- await upDateLocalCache({ ...params, fieldContent: res.genericSearch }, 'reset')
113
- return resetCols
114
- },
115
- // 获取show的列
116
- formatFieldContent(columns) {
117
- return columns.filter(v => v.show).map(v => {
118
- if (v.children) {
119
- return {
120
- key: v.key,
121
- child: (v.children || []).filter(c => c.show).map(c => c.key)
122
- }
123
- } else {
124
- return v.key
125
- }
126
- })
127
- },
128
- // 获取快照
129
- formatFieldSnapshot(columns) {
130
- return columns.reduce((prev, cur) => {
131
- let obj = { show: !!cur.show }
132
- if (cur.children && cur.children.length) {
133
- obj.children = cur.children.reduce((p, c) => {
134
- p[c.key] = { show: !!c.show }
135
- return p
136
- }, {})
137
- }
138
- prev[cur.key] = obj
139
- return prev
140
- }, {})
141
- },
142
- }
143
- }
@@ -1,502 +0,0 @@
1
- import cloneDeep from 'lodash/cloneDeep'
2
- import debounce from 'lodash/debounce'
3
- // 无限滚动数据的更新时间,防止用户长时间停留,滑动后数据不更新
4
- const UPDATE_INTERVAL = 5 * 60 * 1000
5
- // 获取全量id的数量
6
- const idsPageSize = 10000
7
- // 每次更新数据的数量
8
- const upLength = Math.ceil(window.screen.width / 44) + 2
9
- // 无限滚动需要多加载的行数
10
- const addRowLength = 500
11
-
12
- export default {
13
- props: {
14
- autoLoadData: {
15
- type: Boolean,
16
- default: true
17
- },
18
- disabledLoading: {
19
- type: Boolean,
20
- default: false
21
- }
22
- },
23
- data() {
24
- return {
25
- // 本次滚动前的开始行
26
- beforeStartRow: 0,
27
- // 本次滚动前的结束行
28
- beforeEndRow: 0,
29
- // 全量的ids
30
- tableScrollIds: [],
31
- // 所有的数据映射map
32
- tableMap: {},
33
- lastReqTime: null, // TODO 需要保证code与数据一致,且是最后一次的请求
34
- // 缓存的排序参数
35
- orderByClauses: null,
36
- // querytable 默认300
37
- innterDelayLoading: 300,
38
- dataFinish_timeStamp: null, // 数据返回时间
39
- idsFinish_timeStamp: null // ids最后返回时间
40
- }
41
- },
42
- computed: {
43
- // 无限滚动用来加载视口数据的key
44
- idsKey() {
45
- // 非无限滚动也需要生成map映射
46
- return this.config.idsKey || this.config.scrollLoad?.idsKey || 'code'
47
- }
48
- },
49
- created() {
50
- this.initDefaultData()
51
- },
52
- mounted() {
53
- if (!this.autoLoadData) {
54
- return
55
- }
56
- this.loadData()
57
- // setTimeout(() => {
58
- // this.loadData()
59
- // }, 50);
60
- // setTimeout(() => {
61
- // this.loadData()
62
- // }, 100);
63
- // setTimeout(() => {
64
- // this.loadData()
65
- // }, 110);
66
- // setTimeout(() => {
67
- // this.loadData()
68
- // }, 140);
69
- },
70
- methods: {
71
- initDefaultData() {
72
- // 不需要响应式
73
- this.loadIdsMap = {}
74
- // 需要更新进表格的数据
75
- this.willUpdateDataArr = []
76
- },
77
- // 处理分页参数
78
- formatPageParams(params, options) {
79
- const { page } = options || {}
80
- params.page = page ? page : 1
81
- return params
82
- },
83
- // 处理当前页总数
84
- formatRowTotal(res) {
85
- const { scrollLoad } = this.config
86
- if (!scrollLoad) {
87
- // 非无限滚动,需要设置为出参表格行数
88
- res.rowTotal = res.rows.length
89
- }
90
- return res
91
- },
92
- // 处理排序参数
93
- formatSortParams(params, options) {
94
- const { reqProp, order } = options || {}
95
- if (!(reqProp || this.orderByClauses)) return params
96
- if (reqProp) {
97
- // 优先使用传入的排序参数,并保存
98
- let _orderByClauses = [{ field: reqProp, orderByMode: order === 'ascending' ? 0 : 1 }]
99
- params.orderByClauses = _orderByClauses
100
- this.orderByClauses = _orderByClauses
101
- } else if (this.orderByClauses) {
102
- // 翻页或其他场景,使用缓存好的排序参数
103
- params.orderByClauses = this.orderByClauses
104
- }
105
- return params
106
- },
107
- // 请求数据
108
- async loadData(options) {
109
- return new Promise(async (resolve, reject) => {
110
- try {
111
- if (!this.disabledLoading) {
112
- this.isLoading = true
113
- }
114
- const { url, appkey, beforeHttp, afterHttp, scrollLoad, afterSetData, firstScreenDataCompleted } = this.config
115
- const now = new Date().valueOf()
116
- this.lastReqTime = now
117
-
118
- // 需要无限滚动,加载全量id
119
- scrollLoad && this.loadTableScrollIds(now, options)
120
- let params = {}
121
-
122
- // 请求前,外部可处理入参
123
- let beforeParams = { url, appkey, params }
124
- // 合并外部return的参数
125
- let $params = typeof beforeHttp === 'function' ? { ...beforeParams, ...await beforeHttp(beforeParams) } : beforeParams
126
-
127
- let { url: _url, appkey: _appkey, params: _params } = $params
128
-
129
- // 每次请求,记录时间戳
130
- let serach_time_stamp = now
131
-
132
- // 处理分页参数
133
- _params = this.formatPageParams(_params, options)
134
- // 处理排序参数
135
- _params = this.formatSortParams(_params, options)
136
-
137
- let res = await this.$http(_url, _appkey, _params)
138
- // 非无限滚动,重复请求,不赋值
139
- if (!scrollLoad && serach_time_stamp < this.lastReqTime) {
140
- return
141
- }
142
-
143
- // 只赋值最后一次的请求
144
- if (serach_time_stamp && this.lastReqTime && serach_time_stamp < this.lastReqTime) return
145
-
146
- // 请求后,外部可处理出参
147
- res = typeof afterHttp === 'function' ? await afterHttp(res) : res
148
- res = this.formatRowTotal(res)
149
-
150
- const { rowTotal, rows } = res
151
-
152
- this.setTableData({ rowTotal, rows }, now)
153
-
154
- // TODO 首屏数据设置完成
155
- typeof afterSetData === 'function' && afterSetData()
156
- typeof firstScreenDataCompleted === 'function' && firstScreenDataCompleted({ rowTotal, rows })
157
- // this.tableData = res.rows
158
- // TODO 取出参配置有问题
159
- !scrollLoad && this.setPage({ page: _params.page, pageTotal: res.pageTotal })
160
- this.isLoading = false
161
- resolve(res)
162
- } catch (error) {
163
- this.checkNetType(error)
164
- // TODO 错误是否需要清空数据
165
- console.error('[query-table-search-error]', error)
166
- reject(error)
167
- }
168
- })
169
- },
170
- // TODO, 暂时处理单元格数据 key都不存在的情况。此方法影响性能,后续要去除
171
- createBaseData() {
172
- // return Object.keys(val).reduce((base, v) => {
173
- // base[v] = '-'
174
- // return base
175
- // }, {})
176
- return {}
177
- },
178
- // 获取无限滚动需要的全量id
179
- async loadTableScrollIds(now, options) {
180
- try {
181
- const { scrollLoad, appkey } = this.config
182
- if (!scrollLoad) return
183
-
184
- const { getIdsUrl, idsBeforeHttp, idsAfterHttp } = scrollLoad
185
-
186
- let params = {}
187
-
188
- // 请求前,外部可处理入参
189
- let idsBeforeParams = { url: getIdsUrl, appkey, params }
190
- // 合并外部return的参数
191
- let $params = typeof idsBeforeHttp === 'function' ? { ...idsBeforeParams, ...await idsBeforeHttp(idsBeforeParams) } : idsBeforeParams
192
-
193
- let { url: _url, appkey: _appkey, params: _params } = $params
194
- // 无限滚动,首页数据需要设置唯一时间戳,用于校验是否为最后一次请求,与首页数据时间戳一致
195
- let serach_time_stamp = now
196
-
197
- // 处理排序参数
198
- _params = this.formatSortParams(_params, options)
199
- // id写死最大请求数量
200
- let res = await this.$http(_url, _appkey, { ..._params, pageSize: idsPageSize })
201
-
202
- // 只赋值最后一次的请求
203
- if (serach_time_stamp && this.lastReqTime && serach_time_stamp < this.lastReqTime) return
204
-
205
- // 请求后,外部可处理出参
206
- res = typeof idsAfterHttp === 'function' ? await idsAfterHttp(res) : res
207
-
208
- // res 需要处理成字符串数组['id1', 'id2]
209
- this.tableScrollIds = res
210
-
211
- this.idsFinish_timeStamp = now
212
-
213
- this.setTableScrollIds()
214
- } catch (error) {
215
- console.error('[query-table-search-ids]', error)
216
- }
217
- },
218
- // 无限滚动过程中加载数据
219
- async scrollLoadData(scrollOptions) {
220
- try {
221
- const { scrollLoad, appkey, url } = this.config
222
- if (!scrollLoad) return
223
-
224
- const { scrollBeforeHttp, scrollAfterHttp } = scrollLoad
225
- let params = {}
226
-
227
- // 请求前,外部可处理入参
228
- let scrollBeforeParams = { url, appkey, params }
229
-
230
- let $params = typeof scrollBeforeHttp === 'function' ? { ...scrollBeforeParams, ...await scrollBeforeHttp(scrollBeforeParams, scrollOptions) } : scrollBeforeParams
231
-
232
- let { url: _url, appkey: _appkey, params: _params } = $params
233
-
234
- let res = await this.$http(_url, _appkey, _params)
235
-
236
- // 请求后,外部可处理出参
237
- res = typeof scrollAfterHttp === 'function' ? await scrollAfterHttp(res) : res
238
-
239
- this.updateTableData(res.rows, 'api')
240
- } catch (error) {
241
- console.error('[query-table-scrollLoadData]', error)
242
- }
243
- // 清空本次请求加载中的ids
244
- this.clearLoadIds(scrollOptions.code)
245
- },
246
- // 清空加载中的ids
247
- clearLoadIds(codes) {
248
- for (let index = 0; index < codes.length; index++) {
249
- delete this.loadIdsMap[codes[index]]
250
- }
251
- },
252
- async setTableData(val, now) {
253
- let { rowTotal, rows, options: scrollData } = val
254
- const nowDateStr = +new Date()
255
- if (!scrollData) {
256
- // 第一页数据,非滚动
257
- this.total = rowTotal
258
- let tableData = []
259
- let item = null
260
- // 设置第一页数据,全部双向绑定
261
- for (let index = 0; index < rows.length; index++) {
262
- item = rows[index]
263
- tableData.push({ ...item, id: 'pe_' + Math.random().toString(), __updateTime: nowDateStr })
264
- }
265
- // 根据总条数设置空行,用于一次展示所有数据,后续滚动过程中请求后合并空数据
266
- for (let index = rows.length; index < rowTotal; index++) {
267
- tableData.push({ ...this.createBaseData(rows[0]), id: 'pe_' + Math.random().toString(), name: '-', selectedFlag: null })
268
- }
269
- this.tableData = tableData
270
-
271
- this.dataFinish_timeStamp = now
272
-
273
- this.setTableScrollIds()
274
-
275
- // 第一页数据,让表格回到顶部
276
- this.$refs.peTable && this.$refs.peTable.scrollToTop()
277
- // 如果有数据,异步存入到map内
278
- setTimeout(() => {
279
- this.tableData.forEach(item => {
280
- if (item.__updateTime) {
281
- this.tableMap[item[this.idsKey]] = item
282
- }
283
- })
284
- }, 0)
285
- } else {
286
- // 滚动加载的数据
287
- this.updateTableData(rows, 'api')
288
- }
289
- },
290
- // 表格滑动拉取数据
291
- tableScrollPullData: debounce(async function (e) {
292
- const { scrollLoad } = this.config
293
- if (!scrollLoad) return
294
- let { startRow, endRow, action, rowsPerViewport } = e
295
-
296
- // code还没请求回来
297
- if (!this.tableScrollIds.length) {
298
- // 保存数据用于code取回来后立即执行
299
- this.beforeStartRow = startRow
300
- this.beforeEndRow = endRow
301
- return
302
- }
303
-
304
- if (action === 'reload') {
305
- // 立即请求
306
- startRow = this.beforeStartRow
307
- endRow = this.beforeEndRow
308
- } else {
309
- // 未产生行数变更时,不调用接口
310
- if (this.beforeStartRow === startRow && this.beforeEndRow === endRow) {
311
- return
312
- } else {
313
- this.beforeStartRow = startRow
314
- this.beforeEndRow = endRow
315
- }
316
- }
317
-
318
-
319
- // TODO ? 业务逻辑
320
- // if (startRow !== undefined && endRow !== undefined && isPullKLine) {
321
- // // 暂时隐藏,后续需要根据调用状态判断是否需要原生方法
322
- // const curCodes = this.tableScrollIds.slice(startRow, endRow)
323
- // try {
324
- // window.ks.callFunc({ method: "preLoadStockKlineToFile", params: { ids: uniq(curCodes) } })
325
- // } catch (error) {
326
- // console.log(error)
327
- // }
328
- // }
329
-
330
- // 优化处理,不重复请求已有数据
331
- let codes = []
332
- // 预加载多一屏数据
333
-
334
- // 是否需要预加载
335
- // 校验下一屏是否是空的
336
- const checkNextViewData = () => {
337
- const nowDateStr = +new Date()
338
- let checkStartRow = startRow
339
- let checkEndRow = endRow + rowsPerViewport
340
- let id = null
341
- let item = null
342
- let load = false
343
- while (checkStartRow <= checkEndRow) {
344
- id = this.tableScrollIds[checkStartRow]
345
- item = this.tableMap[id]
346
- const noItem = id && !item
347
- const oldItem = item && (!item.__updateTime || nowDateStr > UPDATE_INTERVAL + item.__updateTime)
348
- if (id && (noItem || oldItem)) {
349
- load = true
350
- break
351
- }
352
- checkStartRow++
353
- }
354
- return load
355
- }
356
-
357
- if (!checkNextViewData()) {
358
- return
359
- }
360
-
361
- let preloadEndRow = Math.min(endRow + addRowLength, this.tableScrollIds.length)
362
- if (preloadEndRow > 0) {
363
- let i = startRow
364
- const nowDateStr = +new Date()
365
- let id = null
366
- let item = null
367
- while (i <= preloadEndRow) {
368
- // 如果已经有数据,不需要再请求获取
369
- // 加入更新时间,如果超过指定时间需要重新获取
370
- id = this.tableScrollIds[i] || ''
371
- item = this.tableMap[id]
372
-
373
- const noItem = id && !item
374
- const oldItem = item && (!item.__updateTime || nowDateStr > UPDATE_INTERVAL + item.__updateTime)
375
- const idLoad = this.loadIdsMap[id] // 加载中的数据
376
-
377
- if (id && (noItem || oldItem) && !idLoad) {
378
- codes.push(id)
379
- this.loadIdsMap[id] = true
380
- }
381
- i++
382
- }
383
- }
384
-
385
- if (!codes.length) return
386
-
387
- let options = {
388
- code: codes,
389
- startRow,
390
- endRow,
391
- }
392
- this.scrollLoadData(options)
393
-
394
- }, 100),
395
- /**
396
- * 基于ID过滤并合并两个大型数组,保持原始顺序
397
- * @param {Array} arr1 第一个数组(将被过滤)
398
- * @param {Array} arr2 第二个数组(将完整保留)
399
- * @returns {Array} 合并后的新数组
400
- */
401
- filterAndMergeArrays(arr1, arr2) {
402
- // 创建第二个数组的ID集合用于快速查找
403
- const arr2IdSet = new Set()
404
- for (const item of arr2) {
405
- if (item[this.idsKey]) {
406
- arr2IdSet.add(item[this.idsKey])
407
- }
408
- }
409
-
410
- // 过滤第一个数组中存在于第二个数组的项
411
- const filteredArr1 = []
412
- for (const item of arr1) {
413
- if (item[this.idsKey] && !arr2IdSet.has(item[this.idsKey])) {
414
- filteredArr1.push(item)
415
- }
416
- }
417
-
418
- // 合并数组(保持顺序)
419
- return [...filteredArr1, ...arr2]
420
- },
421
- // 更新数据
422
- updateTableData(arr, type, callback) {
423
- // 去除已在队列中的的重复数据,以新的为准,减少更新操作,提升性能
424
- this.willUpdateDataArr = this.filterAndMergeArrays([...this.willUpdateDataArr], arr)
425
- const nowDateStr = +new Date()
426
- const step = () => {
427
- if (this.willUpdateDataArr.length === 0) return
428
- // 每次只更新设置好的行数
429
- let upList = this.willUpdateDataArr.splice(0, upLength)
430
- for (let index = 0; index < upList.length; index++) {
431
- const item = upList[index]
432
- const id = item[this.idsKey]
433
- // 后端返回的直接赋值,实时数据需要该行不为空
434
- if (this.tableMap[id] && (type === 'api' || this.tableMap[id].__updateTime)) {
435
- const oldItem = cloneDeep(this.tableMap[id])
436
- Object.assign(this.tableMap[id], item, { __updateTime: nowDateStr })
437
- callback && callback(this.tableMap[id], oldItem)
438
- }
439
- }
440
- // 每次设置完数据,主动更新
441
- this.$refs?.peTable?.renderViewportRows()
442
- requestAnimationFrame(step)
443
- }
444
- requestAnimationFrame(step)
445
- },
446
- resetTableData(i) {
447
- // 重置下总数
448
- this.total = i
449
- if (this.tableData.length !== i) {
450
- this.tableData = this.tableData.slice(0, i)
451
- }
452
- },
453
- checkSetIds() {
454
- // 数据返回是最新的,并且ids返回是最新的
455
- return this.dataFinish_timeStamp === this.lastReqTime && this.idsFinish_timeStamp === this.lastReqTime
456
- },
457
- // 给每一行数据设置数据需要的id
458
- setTableScrollIds() {
459
- if (!this.config.scrollLoad) return
460
- // 需要首页search 和 ids 是同一轮
461
- if (!this.checkSetIds()) return
462
- let i = Math.min(this.tableData.length, this.tableScrollIds.length)
463
- // 兜底,ids与rowTotal 长度不一致时,用短的
464
- this.resetTableData(i)
465
- let id = null
466
- let item = null
467
- while (i--) {
468
- item = this.tableData[i]
469
- if (item[this.idsKey] === '-' || !item[this.idsKey]) {
470
- id = this.tableScrollIds[i]
471
- item[this.idsKey] = id
472
- this.tableMap[id] = item
473
- this.tableMap[id].__index = i
474
- }
475
- }
476
- const { scrollLoad } = this.config
477
- const { setScrollIdsAfter } = scrollLoad
478
- typeof setScrollIdsAfter === 'function' && setScrollIdsAfter()
479
- },
480
- // 校验网络状态
481
- async checkNetType(e) {
482
- this.isLoading = false
483
- // 后端超时
484
- if (e.data && [27057].includes(e.data.code)) {
485
- this.tableData = []
486
- this.tableIsAbnormal = true
487
- return
488
- }
489
- // 前端取消
490
- if (e.message === (window.networkTimeoutMessage || '请求超时,服务器未响应')) {
491
- this.tableData = []
492
- this.tableIsAbnormal = true
493
- return
494
- }
495
- if (window.ks) {
496
- const netStatus = await window.ks.callFunc({ method: 'getNetType', params: {} })
497
- this.tableData = netStatus === 1 ? [] : this.tableData
498
- this.tableIsAbnormal = netStatus === 1
499
- }
500
- }
501
- }
502
- }
@@ -1,25 +0,0 @@
1
-
2
- export default {
3
- props: {
4
- showPage: Boolean
5
- },
6
- data() {
7
- return {
8
- currentPage: 1,
9
- totalPages: 1
10
- }
11
- },
12
- methods: {
13
- setPage(res) {
14
- if (!this.showPage) {
15
- return
16
- }
17
- this.currentPage = res.page
18
- this.totalPages = res.pageTotal
19
- },
20
- onPageChanged(newPage) {
21
- this.currentPage = newPage
22
- this.loadData({ page: newPage })
23
- },
24
- }
25
- }