@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.
- package/index.js +35386 -7
- package/package.json +7 -5
- package/query-table.common.js.map +1 -0
- package/query-table.css +1 -0
- package/query-table.umd.js +35396 -0
- package/query-table.umd.js.map +1 -0
- package/query-table.umd.min.js +11 -0
- package/query-table.umd.min.js.map +1 -0
- package/README.md +0 -45
- package/api/index.js +0 -12
- package/assets/horizontal-back.svg +0 -1
- package/components/pe-table/cell.js +0 -184
- package/components/pe-table/collapse.js +0 -334
- package/components/pe-table/empty.vue +0 -48
- package/components/pe-table/header.js +0 -328
- package/components/pe-table/images/abnormal.png +0 -0
- package/components/pe-table/images/empty.png +0 -0
- package/components/pe-table/images/fold.svg +0 -1
- package/components/pe-table/images/sort.svg +0 -1
- package/components/pe-table/images/sorting.svg +0 -1
- package/components/pe-table/images/unfold.svg +0 -1
- package/components/pe-table/index.vue +0 -837
- package/components/pe-table/load-more.js +0 -46
- package/components/pe-table/props/index.js +0 -183
- package/components/pe-table/row.vue +0 -118
- package/components/pe-table/scrollbar.js +0 -424
- package/components/pe-table/stretch-damping.js +0 -112
- package/components/pe-table/style/cell.less +0 -89
- package/components/pe-table/style/empty.less +0 -48
- package/components/pe-table/style/header.less +0 -141
- package/components/pe-table/style/index.less +0 -88
- package/components/pe-table/style/load-more.less +0 -61
- package/components/pe-table/style/row.less +0 -6
- package/components/pe-table/table-loading.vue +0 -119
- package/components/pe-table/table-total.vue +0 -53
- package/components/pe-table/utils/animate.js +0 -80
- package/components/pe-table/utils/columns.js +0 -290
- package/components/pe-table/utils/data.js +0 -12
- package/components/pe-table/utils/fixed.js +0 -69
- package/components/pe-table/utils/formatter.js +0 -327
- package/components/pe-table/utils/render-cells.js +0 -424
- package/components/pe-table/utils/slot.js +0 -28
- package/components/pe-table/utils/tools.js +0 -84
- package/components/pe-table/utils/touch-scroll.js +0 -417
- package/components/query-table/index.vue +0 -492
- package/components/query-table/mixins/column-mixin.js +0 -102
- package/components/query-table/mixins/column-setting.js +0 -143
- package/components/query-table/mixins/data-mixin.js +0 -502
- package/components/query-table/mixins/pagination-mixin.js +0 -25
- package/components/query-table/mixins/table-fixed.js +0 -111
- package/components/query-table/mixins/table-horizontal.js +0 -119
- package/components/table-horizontal.vue +0 -99
- package/components/table-pagination.vue +0 -32
- package/components/table-settings/assets/arrpw-up.svg +0 -1
- package/components/table-settings/assets/disabled-down.svg +0 -1
- package/components/table-settings/assets/disabled-up.svg +0 -1
- package/components/table-settings/assets/down.svg +0 -1
- package/components/table-settings/assets/up.svg +0 -1
- package/components/table-settings/index.less +0 -294
- package/components/table-settings/index.vue +0 -260
- package/components/table-settings/settings.vue +0 -479
- package/components/table-settings/test.js +0 -626
- package/components/table-settings//344/270/252/346/200/247/350/256/276/347/275/256.md +0 -0
- package/components/tooltip.js +0 -124
- package/hooks/use-cache-promise.js +0 -27
- package/hooks/use-column-config.js +0 -186
- package/hooks/use-encryption.js +0 -0
- package/hooks/use-generic-search.js +0 -95
- package/store/column-store.js +0 -0
- package/styles/table.less +0 -24
- package/utils/column.js +0 -36
- package/utils/config.js +0 -12
- package/utils/encryption.js +0 -32
- package/utils/http.js +0 -1
- package/utils/localStorage.js +0 -35
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
|
|
3
|
-
import cloneDeep from 'lodash/cloneDeep'
|
|
4
|
-
import { createFixedColumnsOnLeft, updateColumnsIndexWidth } from './fixed'
|
|
5
|
-
const key = 'key'
|
|
6
|
-
|
|
7
|
-
function getAllChildKeys(children, acc) {
|
|
8
|
-
const keys = new Set()
|
|
9
|
-
|
|
10
|
-
for (const child of children) {
|
|
11
|
-
const childKey = child[key]
|
|
12
|
-
keys.add(childKey)
|
|
13
|
-
getAllChildKeys(child.children || [], [...acc, childKey]).forEach(
|
|
14
|
-
(subKey) => {
|
|
15
|
-
keys.add(subKey)
|
|
16
|
-
}
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return Array.from(keys)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function createVisibleFlatColumns({
|
|
24
|
-
columns,
|
|
25
|
-
rowCellRender,
|
|
26
|
-
headerCellRender
|
|
27
|
-
}) {
|
|
28
|
-
const stack = cloneDeep(columns)
|
|
29
|
-
|
|
30
|
-
const visibleFlatColumns = []
|
|
31
|
-
const collapsedMap_ = new Map()
|
|
32
|
-
const colsMap = {}
|
|
33
|
-
while (stack.length) {
|
|
34
|
-
const current = stack.shift()
|
|
35
|
-
const currentKey = current[key]
|
|
36
|
-
const {
|
|
37
|
-
children = [],
|
|
38
|
-
fixed,
|
|
39
|
-
width,
|
|
40
|
-
parentNodeKeys = [],
|
|
41
|
-
childKeys = [],
|
|
42
|
-
// parentNodeKey,
|
|
43
|
-
resizable = true,
|
|
44
|
-
minWidth,
|
|
45
|
-
...reset
|
|
46
|
-
} = current
|
|
47
|
-
const { level = 1, collapsed = false, collapseKeys = [] } = reset
|
|
48
|
-
if (collapseKeys.length) {
|
|
49
|
-
for (const k of collapseKeys) {
|
|
50
|
-
collapsedMap_.set(k, collapsed)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const hasChildren = !!children.length
|
|
54
|
-
if (hasChildren) {
|
|
55
|
-
// 继承父级的fixed
|
|
56
|
-
const parentNodeKey = currentKey
|
|
57
|
-
stack.unshift(
|
|
58
|
-
...children.map((child) => ({
|
|
59
|
-
...child,
|
|
60
|
-
parentNodeKeys: [...parentNodeKeys, parentNodeKey],
|
|
61
|
-
fixed,
|
|
62
|
-
parentNodeKey,
|
|
63
|
-
level: level + 1,
|
|
64
|
-
}))
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
|
-
const item = {
|
|
68
|
-
...current,
|
|
69
|
-
width: minWidth || width,
|
|
70
|
-
minWidth,
|
|
71
|
-
parentNodeKeys,
|
|
72
|
-
children,
|
|
73
|
-
level,
|
|
74
|
-
resizable,
|
|
75
|
-
childKeys: getAllChildKeys(children, childKeys),
|
|
76
|
-
rowCellRender: current.rowCellRender || rowCellRender,
|
|
77
|
-
headerCellRender: current.headerCellRender || headerCellRender
|
|
78
|
-
}
|
|
79
|
-
if (item.width) {
|
|
80
|
-
item.width = parseInt(item.width)
|
|
81
|
-
}
|
|
82
|
-
visibleFlatColumns.push(item)
|
|
83
|
-
colsMap[currentKey] = item
|
|
84
|
-
}
|
|
85
|
-
// 子级的折叠状态跟随父级的状态
|
|
86
|
-
collapsedMap_.forEach((value, key) => {
|
|
87
|
-
const { childKeys = [] } = colsMap[key] || {}
|
|
88
|
-
if (childKeys.length) {
|
|
89
|
-
childKeys.forEach((childKey) => {
|
|
90
|
-
if (!collapsedMap_.has(childKey)) {
|
|
91
|
-
collapsedMap_.set(childKey, value)
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
const collapsedMap = Object.fromEntries(collapsedMap_.entries())
|
|
97
|
-
return { visibleFlatColumns, collapsedMap }
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function logError(err, logConf = '') {
|
|
101
|
-
// eslint-disable-next-line
|
|
102
|
-
if (typeof console !== 'undefined') {
|
|
103
|
-
// eslint-disable-next-line
|
|
104
|
-
console.error('%c【KyeTable2】' + err, logConf)
|
|
105
|
-
} else {
|
|
106
|
-
throw err
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// 列配置的显示与否根据祖先节点的状态来决定
|
|
111
|
-
function validateColumnShow(acc, col) {
|
|
112
|
-
const { parentNodeKey } = col
|
|
113
|
-
const parentNode = acc[parentNodeKey]
|
|
114
|
-
return parentNode && parentNode.show === false ? false : col.show
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function computedColumnsWidthInChildKeys(col, columnsKeyMap, collapsedMap) {
|
|
118
|
-
const { width, children = [], childKeys = [] } = col || {}
|
|
119
|
-
if (!children.length && width) {
|
|
120
|
-
return width
|
|
121
|
-
}
|
|
122
|
-
return childKeys.reduce((acc, childKey) => {
|
|
123
|
-
const { children = [], width, show } = columnsKeyMap[childKey] || {}
|
|
124
|
-
// 仅计算未被折叠的宽度和
|
|
125
|
-
if (!children.length && !collapsedMap[childKey] && show) {
|
|
126
|
-
acc += width
|
|
127
|
-
}
|
|
128
|
-
return acc
|
|
129
|
-
}, 0)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function createColumnsKeyMap(visibleFlatColumns = []) {
|
|
133
|
-
const columnKeyMap = visibleFlatColumns.reduce((acc, col) => {
|
|
134
|
-
const { key } = col
|
|
135
|
-
const show = validateColumnShow(acc, col)
|
|
136
|
-
acc[key] = {
|
|
137
|
-
...col,
|
|
138
|
-
show,
|
|
139
|
-
}
|
|
140
|
-
return acc
|
|
141
|
-
}, {})
|
|
142
|
-
return columnKeyMap
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function createFlatColumns (params) {
|
|
146
|
-
const addFixedConfInColumns =
|
|
147
|
-
params.columns && params.columns.length > 0 ? createFixedColumnsOnLeft({ showIndex: params.showIndex }) : []
|
|
148
|
-
const { visibleFlatColumns, collapsedMap } = createVisibleFlatColumns({
|
|
149
|
-
...params,
|
|
150
|
-
columns: [...addFixedConfInColumns, ...params.columns],
|
|
151
|
-
})
|
|
152
|
-
return {
|
|
153
|
-
visibleFlatColumns,
|
|
154
|
-
collapsedMap
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// 根据筛选的列和 折叠选项生成 多表格列配置
|
|
159
|
-
export function createColumns({visibleFlatColumns, collapsedMap = {}, rowKey, headerRowHeight, curMaxIndexVal}) {
|
|
160
|
-
const columnsKeyMap = createColumnsKeyMap(visibleFlatColumns)
|
|
161
|
-
const columnVisibleConfIter = (key) =>
|
|
162
|
-
columnsKeyMap[key].show !== false && !collapsedMap[key]
|
|
163
|
-
const fixedColumnsOnLeft = visibleFlatColumns.filter(
|
|
164
|
-
(column) =>
|
|
165
|
-
(column.fixed === 'left' || column.fixed === true) &&
|
|
166
|
-
columnVisibleConfIter(column.key)
|
|
167
|
-
)
|
|
168
|
-
const normalColumns = visibleFlatColumns.filter(
|
|
169
|
-
(column) => !column.fixed && columnVisibleConfIter(column.key)
|
|
170
|
-
)
|
|
171
|
-
if (curMaxIndexVal >= 10000) {
|
|
172
|
-
updateColumnsIndexWidth(fixedColumnsOnLeft, curMaxIndexVal)
|
|
173
|
-
}
|
|
174
|
-
const mainColumns = [...fixedColumnsOnLeft, ...normalColumns]
|
|
175
|
-
const maxLevel = creatMaxlevel(mainColumns)
|
|
176
|
-
// const headerTotalHeight = maxLevel * headerRowHeight
|
|
177
|
-
|
|
178
|
-
const collapseKeysMap = {}
|
|
179
|
-
function calculateOffsetXAndWidth(arr = [], iter) {
|
|
180
|
-
let offsetX = 0
|
|
181
|
-
return arr.map((col, index) => {
|
|
182
|
-
const width = computedColumnsWidthInChildKeys(
|
|
183
|
-
col,
|
|
184
|
-
columnsKeyMap,
|
|
185
|
-
collapsedMap
|
|
186
|
-
)
|
|
187
|
-
col.width = width
|
|
188
|
-
if (col.collapseKeys && col.collapseKeys.length) {
|
|
189
|
-
if (!collapseKeysMap[col.key]) {
|
|
190
|
-
collapseKeysMap[col.key] = col.collapseKeys
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
if (index > 0) {
|
|
194
|
-
const { width: preWidth, key: preKey } = mainColumns[index - 1]
|
|
195
|
-
offsetX += preWidth
|
|
196
|
-
// 如果上一次是父级,则减去父级的宽度。从父级的起始点开始
|
|
197
|
-
if (col.parentNodeKey === preKey) {
|
|
198
|
-
offsetX -= preWidth
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
col.offsetX = offsetX
|
|
202
|
-
const otherResult = iter(col, index) || {}
|
|
203
|
-
const levelNum =
|
|
204
|
-
col.level !== maxLevel && !col.children.length
|
|
205
|
-
? Math.abs(col.level - maxLevel) + 1
|
|
206
|
-
: 1
|
|
207
|
-
const height = levelNum * headerRowHeight
|
|
208
|
-
const top = (col.level - 1) * headerRowHeight
|
|
209
|
-
return {
|
|
210
|
-
...col,
|
|
211
|
-
originIndex: index,
|
|
212
|
-
...otherResult,
|
|
213
|
-
height: height,
|
|
214
|
-
top,
|
|
215
|
-
[rowKey]: (col.fixed ? 'fixed_left_' : '') + col.key,
|
|
216
|
-
}
|
|
217
|
-
})
|
|
218
|
-
}
|
|
219
|
-
const _mainColumns = calculateOffsetXAndWidth(mainColumns, function (col) {
|
|
220
|
-
const { key } = col
|
|
221
|
-
const fixedLeftKeys = ['_index', '_selection'].indexOf(key) > -1
|
|
222
|
-
return {
|
|
223
|
-
headerCellRender: fixedLeftKeys ? null : col.headerCellRender,
|
|
224
|
-
rowCellRender: fixedLeftKeys ? null : col.rowCellRender,
|
|
225
|
-
}
|
|
226
|
-
})
|
|
227
|
-
// function setPlaceholderSign() {
|
|
228
|
-
// return {
|
|
229
|
-
// placeholderSign: false,
|
|
230
|
-
// }
|
|
231
|
-
// }
|
|
232
|
-
// const _fixedColumnsOnLeft = calculateOffsetXAndWidth(
|
|
233
|
-
// fixedColumnsOnLeft.length
|
|
234
|
-
// ? mainColumns.slice(0, fixedColumnsOnLeft.length)
|
|
235
|
-
// : [],
|
|
236
|
-
// setPlaceholderSign
|
|
237
|
-
// )
|
|
238
|
-
return {
|
|
239
|
-
columns: _mainColumns,
|
|
240
|
-
// fixedColumnsOnLeft: _fixedColumnsOnLeft,
|
|
241
|
-
maxLevel,
|
|
242
|
-
collapseKeysMap
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export function creatMaxlevel(columns) {
|
|
247
|
-
const levelIter = (col) => col.level
|
|
248
|
-
const maxLevel = columns.length ? Math.max(...columns.map(levelIter)) : 1
|
|
249
|
-
return maxLevel
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export function createRenderColumnOption({
|
|
253
|
-
mainColumns,
|
|
254
|
-
maxLevel,
|
|
255
|
-
headerRowHeight,
|
|
256
|
-
}) {
|
|
257
|
-
const {
|
|
258
|
-
tableWidth,
|
|
259
|
-
// renderRowColumns,
|
|
260
|
-
renderCellsColumns,
|
|
261
|
-
renderCellsColumnsWidths,
|
|
262
|
-
} = mainColumns.reduce(
|
|
263
|
-
(obj, col) => {
|
|
264
|
-
if (col.level === 1) {
|
|
265
|
-
obj.tableWidth += col.width
|
|
266
|
-
// obj.renderRowColumns.push(col)
|
|
267
|
-
}
|
|
268
|
-
if (!(col.children && col.children.length)) {
|
|
269
|
-
const levelNum =
|
|
270
|
-
col.level !== maxLevel ? Math.abs(col.level - maxLevel) + 1 : 1
|
|
271
|
-
col.headerRowHeight = levelNum * headerRowHeight
|
|
272
|
-
obj.renderCellsColumns.push(col)
|
|
273
|
-
obj.renderCellsColumnsWidths.push(col.width)
|
|
274
|
-
}
|
|
275
|
-
return obj
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
tableWidth: 0,
|
|
279
|
-
// renderRowColumns: [],
|
|
280
|
-
renderCellsColumns: [],
|
|
281
|
-
renderCellsColumnsWidths: [],
|
|
282
|
-
}
|
|
283
|
-
)
|
|
284
|
-
return {
|
|
285
|
-
tableWidth,
|
|
286
|
-
// renderRowColumns,
|
|
287
|
-
renderCellsColumns,
|
|
288
|
-
renderCellsColumnsWidths,
|
|
289
|
-
}
|
|
290
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function createTableData ({data, columns, rowKey}, indexFormat) {
|
|
2
|
-
return (data || []).reduce((acc, rowData, index) => {
|
|
3
|
-
const _rowData = columns.reduce((row, col) => {
|
|
4
|
-
row[col.key] = rowData[col.key]
|
|
5
|
-
return row
|
|
6
|
-
}, {})
|
|
7
|
-
_rowData[rowKey] = rowData[rowKey] || '_inner_id' + index
|
|
8
|
-
_rowData['$index'] = indexFormat ? indexFormat(index+1,_rowData, rowData): index+1
|
|
9
|
-
acc.push(_rowData)
|
|
10
|
-
return acc
|
|
11
|
-
}, [])
|
|
12
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const COLUMNS_INDEX = {
|
|
2
|
-
label: '序号',
|
|
3
|
-
key: '$index',
|
|
4
|
-
sortable: false,
|
|
5
|
-
// resizable: true,
|
|
6
|
-
width: 40,
|
|
7
|
-
// isInternal: true,
|
|
8
|
-
align: 'left',
|
|
9
|
-
showPopover: false,
|
|
10
|
-
// _internal: true,
|
|
11
|
-
// headerCellRender: function (h, { column }) {
|
|
12
|
-
// // const classes = getCustomHeaderCellAlignClass(column)
|
|
13
|
-
// const classes = []
|
|
14
|
-
// return <div class={classes}>{column.label || '#'}</div>
|
|
15
|
-
// },
|
|
16
|
-
// rowCellRender: function (h, { rowData }) {
|
|
17
|
-
// const index = _index
|
|
18
|
-
// let i = typeof index === 'number' ? index : index
|
|
19
|
-
// if (isNaN(i)) {
|
|
20
|
-
// i = ''
|
|
21
|
-
// }
|
|
22
|
-
// // const classes = getCustomRowCellAlignClass(column)
|
|
23
|
-
// const classes = []
|
|
24
|
-
// return <div class={classes}>{i}</div>
|
|
25
|
-
// }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// 生成索引和复选框的列配置
|
|
29
|
-
export function createFixedColumnsOnLeft({
|
|
30
|
-
showIndex, // 是否添加索引列
|
|
31
|
-
// showSelection,
|
|
32
|
-
// showRadio
|
|
33
|
-
}) {
|
|
34
|
-
const fixedColumnsOnLeft = []
|
|
35
|
-
const obj = {
|
|
36
|
-
level: 1,
|
|
37
|
-
show: true,
|
|
38
|
-
fixed: 'left',
|
|
39
|
-
// resizable: false
|
|
40
|
-
}
|
|
41
|
-
if (showIndex) {
|
|
42
|
-
fixedColumnsOnLeft.unshift({
|
|
43
|
-
...COLUMNS_INDEX,
|
|
44
|
-
...obj,
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
// if (showSelection) {
|
|
48
|
-
// fixedColumnsOnLeft.unshift({
|
|
49
|
-
// ...COLUMNS_SELECTION,
|
|
50
|
-
// ...obj
|
|
51
|
-
// })
|
|
52
|
-
// }
|
|
53
|
-
// if (showRadio) {
|
|
54
|
-
// fixedColumnsOnLeft.unshift({
|
|
55
|
-
// ...COLUMNS_RADIO,
|
|
56
|
-
// ...obj
|
|
57
|
-
// })
|
|
58
|
-
// }
|
|
59
|
-
return fixedColumnsOnLeft
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function updateColumnsIndexWidth(fixedColumnsOnLeft = [], tableDataLength) {
|
|
63
|
-
const showIndexColumn = fixedColumnsOnLeft.find(item => item.key === COLUMNS_INDEX.key)
|
|
64
|
-
let indexCol = String(tableDataLength).length * 10
|
|
65
|
-
const width = indexCol < COLUMNS_INDEX.width ? COLUMNS_INDEX.width : indexCol
|
|
66
|
-
if (showIndexColumn && width > COLUMNS_INDEX.width && width !== showIndexColumn.width) {
|
|
67
|
-
showIndexColumn.width = width
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import dayJs from 'dayjs'
|
|
2
|
-
export const isEmpty = val => val === '' || val === null || val === undefined
|
|
3
|
-
|
|
4
|
-
export const date = (date, fmt = 'YYYY-MM-DD') => {
|
|
5
|
-
let str = date || ''
|
|
6
|
-
if (typeof str === 'string' && str && (str.includes('**') || str.includes('✽✽'))) {
|
|
7
|
-
return str
|
|
8
|
-
}
|
|
9
|
-
return str ? dayJs(str).format(fmt) : str
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const time = (d, fmt = 'YYYY-MM-DD HH:mm:ss') => {
|
|
13
|
-
return date(d, fmt)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const minute = (d, fmt = 'YYYY-MM-DD HH:mm') => {
|
|
17
|
-
return date(d, fmt)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const second = (d, fmt = 'HH:mm:ss') => {
|
|
21
|
-
return date(d, fmt)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const month = (d, fmt = 'YYYY-MM') => {
|
|
25
|
-
return date(d, fmt)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const money = (num, prev = '¥ ', fixed = 2) => {
|
|
29
|
-
if (typeof num !== 'number' && !num) {
|
|
30
|
-
return ''
|
|
31
|
-
}
|
|
32
|
-
if (typeof num === 'string' && (num.includes('**') || num.includes('✽✽'))) {
|
|
33
|
-
return num
|
|
34
|
-
}
|
|
35
|
-
prev = prev === null ? '¥ ' : prev
|
|
36
|
-
return `${prev}${(+num).toFixed(fixed).replace(/\B(?=(\d{3})+(?!\d))/g, ',')}`
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const decimal = (num, precision = 2) => {
|
|
40
|
-
if (typeof num !== 'number' && !num) {
|
|
41
|
-
return ''
|
|
42
|
-
}
|
|
43
|
-
if (typeof num === 'string' && (num.includes('**') || num.includes('✽✽'))) {
|
|
44
|
-
return num
|
|
45
|
-
}
|
|
46
|
-
return `${(+num).toFixed(precision).replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')}`
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const thousands = num => {
|
|
50
|
-
if (typeof num !== 'number' && !num) {
|
|
51
|
-
return ''
|
|
52
|
-
}
|
|
53
|
-
if (typeof num === 'string' && (num.includes('**') || num.includes('✽✽'))) {
|
|
54
|
-
return num
|
|
55
|
-
}
|
|
56
|
-
return (+num).toLocaleString()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 后端时间导出自定义类型
|
|
60
|
-
export const customDateTime = (d, fmt = 'YYYY-MM-DD') => {
|
|
61
|
-
return date(d, fmt)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 9级组织过滤器
|
|
66
|
-
* @param val 投资集团/快递事业部/京津冀大区/取派中心/北京分区/顺义区/顺义取派部/东城片区/顺义八里庄点部@顺义取派部@顺义八里庄点部
|
|
67
|
-
* @param dept Array:9级组织 | 1:部门 | 2:点部
|
|
68
|
-
* @param split 组织、部门、点部 的分隔符,默认为“@”
|
|
69
|
-
* @returns {string} 根据用户保存的点部配置,解析出对应的部门数据
|
|
70
|
-
*/
|
|
71
|
-
export const deptFilter = (val, dept, split = '@') => {
|
|
72
|
-
let index = val && val.indexOf(split)
|
|
73
|
-
if (!index || index === -1) {
|
|
74
|
-
return val
|
|
75
|
-
}
|
|
76
|
-
if (Array.isArray(dept)) {
|
|
77
|
-
let arr = val.substring(0, index).split('/')
|
|
78
|
-
let len = Math.min(arr.length, dept.length)
|
|
79
|
-
let str = ''
|
|
80
|
-
for (let i = 0; i < len; i++) {
|
|
81
|
-
let s = arr[dept[i] - 1]
|
|
82
|
-
if (s) {
|
|
83
|
-
str = `${str}/${s}`
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return str ? str.replace(/^\//, '') : val
|
|
87
|
-
} else if (dept === 1) {
|
|
88
|
-
return val.substring(index + 1, val.lastIndexOf(split))
|
|
89
|
-
} else if (dept === 2) {
|
|
90
|
-
return val.substring(val.lastIndexOf(split) + 1)
|
|
91
|
-
} else {
|
|
92
|
-
return val
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 234333.22 => 23万 4333 234.22 => 234.22 支持金额切换
|
|
97
|
-
export const numberSplit = (val, globalMoneyFormat = true) => {
|
|
98
|
-
// 防止空字符返回为0
|
|
99
|
-
if (val === '') return val
|
|
100
|
-
if (globalMoneyFormat) {
|
|
101
|
-
return money(val)
|
|
102
|
-
}
|
|
103
|
-
let toNumberVal = Number(val)
|
|
104
|
-
if (isNaN(toNumberVal)) {
|
|
105
|
-
return val
|
|
106
|
-
}
|
|
107
|
-
let flag = ''
|
|
108
|
-
if (toNumberVal < 0) {
|
|
109
|
-
flag = '-'
|
|
110
|
-
toNumberVal = Math.abs(toNumberVal)
|
|
111
|
-
}
|
|
112
|
-
if (toNumberVal >= 10000) {
|
|
113
|
-
// 大于等于10000的数据要去掉小数位
|
|
114
|
-
const numStr = Math.floor(toNumberVal) + ''
|
|
115
|
-
const len = numStr.length
|
|
116
|
-
const numArr = []
|
|
117
|
-
// 每4位截取一次,截取小于10000部分的数据
|
|
118
|
-
let itemLast = Number(numStr.substring(len - 4, len))
|
|
119
|
-
// 只有个位数前面要加0 等于0则去掉,不加入数组拼接
|
|
120
|
-
if (itemLast < 10 && itemLast > 0) {
|
|
121
|
-
numArr.unshift('0' + itemLast)
|
|
122
|
-
} else if (itemLast >= 10) {
|
|
123
|
-
numArr.unshift(itemLast)
|
|
124
|
-
}
|
|
125
|
-
let itemCenter = 0
|
|
126
|
-
let itemFirst = 0
|
|
127
|
-
if (len <= 8) {
|
|
128
|
-
// 长度小于等于8, 没有亿位,这个时候万位可以从index = 0 开始截取
|
|
129
|
-
itemCenter = Number(numStr.substring(0, len - 4))
|
|
130
|
-
} else {
|
|
131
|
-
// 长度大于8才有亿, 万位不能再从index = 0开始截取
|
|
132
|
-
itemCenter = Number(numStr.substring(len - 8, len - 4))
|
|
133
|
-
itemFirst = Number(numStr.substring(0, len - 8))
|
|
134
|
-
}
|
|
135
|
-
// 万位和亿位如果大于0才加入数组拼接
|
|
136
|
-
if (itemCenter > 0) numArr.unshift(itemCenter + '万')
|
|
137
|
-
if (itemFirst > 0) numArr.unshift(itemFirst + '亿')
|
|
138
|
-
return flag + numArr.join('')
|
|
139
|
-
}
|
|
140
|
-
return flag + toNumberVal
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// 234333.22 => 23万4333 234.22 => 234.22 不支持金额切换
|
|
144
|
-
export const numberSplitInt = val => {
|
|
145
|
-
// 防止空字符返回为0
|
|
146
|
-
if (val === '') return val
|
|
147
|
-
let toNumberVal = Number(val)
|
|
148
|
-
if (isNaN(toNumberVal)) {
|
|
149
|
-
return val
|
|
150
|
-
}
|
|
151
|
-
let flag = ''
|
|
152
|
-
if (toNumberVal < 0) {
|
|
153
|
-
flag = '-'
|
|
154
|
-
toNumberVal = Math.abs(toNumberVal)
|
|
155
|
-
}
|
|
156
|
-
if (toNumberVal >= 10000) {
|
|
157
|
-
// 大于等于10000的数据要去掉小数位
|
|
158
|
-
const numStr = Math.floor(toNumberVal) + ''
|
|
159
|
-
const len = numStr.length
|
|
160
|
-
const numArr = []
|
|
161
|
-
// 每4位截取一次,截取小于10000部分的数据
|
|
162
|
-
let itemLast = Number(numStr.substring(len - 4, len))
|
|
163
|
-
// 只有个位数前面要加0 等于0则去掉,不加入数组拼接
|
|
164
|
-
if (itemLast < 10 && itemLast > 0) {
|
|
165
|
-
numArr.unshift('0' + itemLast)
|
|
166
|
-
} else if (itemLast >= 10) {
|
|
167
|
-
numArr.unshift(itemLast)
|
|
168
|
-
}
|
|
169
|
-
let itemCenter = 0
|
|
170
|
-
let itemFirst = 0
|
|
171
|
-
if (len <= 8) {
|
|
172
|
-
// 长度小于等于8, 没有亿位,这个时候万位可以从index = 0 开始截取
|
|
173
|
-
itemCenter = Number(numStr.substring(0, len - 4))
|
|
174
|
-
} else {
|
|
175
|
-
// 长度大于8才有亿, 万位不能再从index = 0开始截取
|
|
176
|
-
itemCenter = Number(numStr.substring(len - 8, len - 4))
|
|
177
|
-
itemFirst = Number(numStr.substring(0, len - 8))
|
|
178
|
-
}
|
|
179
|
-
// 万位和亿位如果大于0才加入数组拼接
|
|
180
|
-
if (itemCenter > 0) numArr.unshift(itemCenter + '万')
|
|
181
|
-
if (itemFirst > 0) numArr.unshift(itemFirst + '亿')
|
|
182
|
-
return flag + numArr.join('')
|
|
183
|
-
}
|
|
184
|
-
return flag + toNumberVal
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// 234333.22 => 23万4333.22 234.22 => 234.22
|
|
188
|
-
export const numberSplitFloat = (val, decimal, globalMoneyFormat = false) => {
|
|
189
|
-
// 防止空字符返回为0
|
|
190
|
-
if (val === '') return val
|
|
191
|
-
if (globalMoneyFormat) {
|
|
192
|
-
return money(val)
|
|
193
|
-
}
|
|
194
|
-
return filterNumber(val, decimal)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const filterNumber = (val, decimal) => {
|
|
198
|
-
if (decimal < 0 || !Number.isInteger(decimal)) decimal = void 0
|
|
199
|
-
let toNumberVal = Number(val)
|
|
200
|
-
if (isNaN(toNumberVal)) {
|
|
201
|
-
return val
|
|
202
|
-
}
|
|
203
|
-
let flag = ''
|
|
204
|
-
if (toNumberVal < 0) {
|
|
205
|
-
flag = '-'
|
|
206
|
-
toNumberVal = Math.abs(toNumberVal)
|
|
207
|
-
}
|
|
208
|
-
const numStrArr = String(toNumberVal).split('.')
|
|
209
|
-
const numStr = numStrArr[0]
|
|
210
|
-
const _decimal = decimal == 0 ? '' : decimal || (numStrArr[1] && numStrArr[1].length) || ''
|
|
211
|
-
const decimalNum = numStrArr[1] && _decimal ? `.${numStrArr[1].substring(0, _decimal)}` : ''
|
|
212
|
-
if (toNumberVal >= 10000) {
|
|
213
|
-
const len = numStr.length
|
|
214
|
-
const numArr = []
|
|
215
|
-
// 每4位截取一次,截取小于10000部分的数据
|
|
216
|
-
let itemLast = Number(numStr.substring(len - 4, len))
|
|
217
|
-
// 只有个位数前面要加0 等于0则去掉,不加入数组拼接
|
|
218
|
-
if (itemLast < 10 && itemLast > 0) {
|
|
219
|
-
numArr.unshift('0' + itemLast)
|
|
220
|
-
} else if (itemLast >= 10) {
|
|
221
|
-
numArr.unshift(itemLast)
|
|
222
|
-
}
|
|
223
|
-
let itemCenter = 0
|
|
224
|
-
let itemFirst = 0
|
|
225
|
-
// let itemBillion = 0
|
|
226
|
-
// 处理万亿(兆)级别
|
|
227
|
-
if (len >= 13) {
|
|
228
|
-
const billion = 1e12 // 1万亿
|
|
229
|
-
let billionValue = String(numStr / billion)
|
|
230
|
-
const dotIndex = billionValue.indexOf('.')
|
|
231
|
-
if (dotIndex !== -1) {
|
|
232
|
-
billionValue = billionValue.slice(0, dotIndex + 5) // dotIndex + 5 保留四位小数
|
|
233
|
-
}
|
|
234
|
-
// 长度大于等于13 万亿(兆)级别
|
|
235
|
-
// itemBillion = Number(numStr.substring(0, len - 12)) // 万亿(兆)部分
|
|
236
|
-
// itemFirst = Number(numStr.substring(len - 12, len - 10)) // 亿部分
|
|
237
|
-
// itemCenter = Number(numStr.substring(len - 8, len - 4)) // 万部分
|
|
238
|
-
// return `${itemBillion}${itemFirst ? '.' + itemFirst : ''}万亿`
|
|
239
|
-
return `${billionValue}万亿`
|
|
240
|
-
} else if (len >= 9) {
|
|
241
|
-
// 长度大于8才有亿, 万位不能再从index = 0开始截取
|
|
242
|
-
itemCenter = Number(numStr.substring(len - 8, len - 4))
|
|
243
|
-
itemFirst = Number(numStr.substring(0, len - 8))
|
|
244
|
-
} else {
|
|
245
|
-
// 长度小于9,只有万以下的数值
|
|
246
|
-
itemCenter = Number(numStr.substring(0, len - 4)) // 万部分
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (itemCenter > 0) numArr.unshift(itemCenter + '万')
|
|
250
|
-
if (itemFirst > 0) numArr.unshift(itemFirst + '亿')
|
|
251
|
-
// if (itemBillion > 0) numArr.unshift(itemBillion + '万亿')
|
|
252
|
-
return flag + numArr.join('') + decimalNum
|
|
253
|
-
}
|
|
254
|
-
return flag + Math.floor(toNumberVal) + decimalNum
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// 234333.22 => 23万4333.22 234.22 => 234.22 , null => '-'
|
|
258
|
-
export const formatMoneyByNumber = (val, decimal = 2) => {
|
|
259
|
-
// 金融板块 金额为空时 需要返回 返回‘-’, 且默认2为小数, 默认带前缀 ¥
|
|
260
|
-
if (isEmpty(val)) return '-'
|
|
261
|
-
const num = filterNumber(val, decimal)
|
|
262
|
-
return num.includes('*') || num.includes('✽') ? num : `¥ ${num}`
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
function getFormatter(col = {}, filter) {
|
|
267
|
-
if (!filter) {
|
|
268
|
-
return null
|
|
269
|
-
}
|
|
270
|
-
// 过滤器
|
|
271
|
-
if (col.filter) {
|
|
272
|
-
if (col.filter.type && col.filter.args) {
|
|
273
|
-
let func = filter[col.filter.type]
|
|
274
|
-
if (func) {
|
|
275
|
-
return (row, column, val) => func(val, ...col.filter.args)
|
|
276
|
-
}
|
|
277
|
-
} else {
|
|
278
|
-
// 不显示秒,minute 替换 time
|
|
279
|
-
// if (col.filter === 'time') {
|
|
280
|
-
// col.filter = 'minute'
|
|
281
|
-
// }
|
|
282
|
-
let func = filter[col.filter]
|
|
283
|
-
if (func) {
|
|
284
|
-
// 9级组织
|
|
285
|
-
if (col.filter === 'deptFilter') {
|
|
286
|
-
return (row, column, val) => func(val, column.dept)
|
|
287
|
-
} else {
|
|
288
|
-
return (row, column, val) => func(val)
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return null
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const filter = {
|
|
297
|
-
date,
|
|
298
|
-
time,
|
|
299
|
-
minute,
|
|
300
|
-
second,
|
|
301
|
-
month,
|
|
302
|
-
money,
|
|
303
|
-
decimal,
|
|
304
|
-
thousands,
|
|
305
|
-
customDateTime,
|
|
306
|
-
deptFilter,
|
|
307
|
-
numberSplit,
|
|
308
|
-
numberSplitInt,
|
|
309
|
-
numberSplitFloat,
|
|
310
|
-
formatMoneyByNumber,
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export const tableCellFormatterResult = ({ column = {}, rowData, rowIndex, columnIndex, displayText }) => {
|
|
314
|
-
try {
|
|
315
|
-
const formatter = getFormatter(column, filter)
|
|
316
|
-
if (formatter) {
|
|
317
|
-
displayText = formatter(rowData, column, displayText)
|
|
318
|
-
}
|
|
319
|
-
if (column.formatter && typeof column.formatter === 'function') {
|
|
320
|
-
displayText = column.formatter(rowData, column, displayText, rowIndex, columnIndex)
|
|
321
|
-
}
|
|
322
|
-
return displayText
|
|
323
|
-
} catch (error) {
|
|
324
|
-
console.error(error)
|
|
325
|
-
return displayText
|
|
326
|
-
}
|
|
327
|
-
}
|