vxe-table 3.20.4 → 3.20.6
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/LICENSE +20 -20
- package/README.md +106 -106
- package/es/grid/style.css +4 -0
- package/es/grid/style.min.css +1 -1
- package/es/index.css +1 -1
- package/es/index.esm.js +1 -2
- package/es/index.min.css +1 -1
- package/es/style.css +1 -1
- package/es/style.min.css +1 -1
- package/es/table/src/methods.js +51 -22
- package/es/table/src/table.js +36 -0
- package/es/table/src/util.js +3 -4
- package/es/table/style.css +48 -18
- package/es/ui/index.js +1 -1
- package/es/ui/src/log.js +1 -1
- package/es/vxe-grid/style.css +4 -0
- package/es/vxe-grid/style.min.css +1 -1
- package/es/vxe-table/style.css +48 -18
- package/lib/grid/style/style.css +4 -0
- package/lib/grid/style/style.min.css +1 -1
- package/lib/index.common.js +1 -2
- package/lib/index.css +1 -1
- package/lib/index.min.css +1 -1
- package/lib/index.umd.js +3252 -1877
- package/lib/index.umd.min.js +1 -1
- package/lib/style.css +1 -1
- package/lib/style.min.css +1 -1
- package/lib/table/src/methods.js +4 -3
- package/lib/table/src/methods.min.js +1 -1
- package/lib/table/src/table.js +44 -0
- package/lib/table/src/table.min.js +1 -1
- package/lib/table/src/util.js +4 -6
- package/lib/table/src/util.min.js +1 -1
- package/lib/table/style/style.css +48 -18
- package/lib/ui/index.js +1 -1
- package/lib/ui/index.min.js +1 -1
- package/lib/ui/src/log.js +1 -1
- package/lib/ui/src/log.min.js +1 -1
- package/lib/v-x-e-table/index.js +1 -2
- package/lib/v-x-e-table/index.min.js +1 -1
- package/lib/vxe-colgroup/index.js +1 -2
- package/lib/vxe-colgroup/index.min.js +1 -1
- package/lib/vxe-column/index.js +1 -2
- package/lib/vxe-column/index.min.js +1 -1
- package/lib/vxe-grid/index.js +1 -2
- package/lib/vxe-grid/index.min.js +1 -1
- package/lib/vxe-grid/style/style.css +4 -0
- package/lib/vxe-grid/style/style.min.css +1 -1
- package/lib/vxe-table/index.js +1 -2
- package/lib/vxe-table/index.min.js +1 -1
- package/lib/vxe-table/style/style.css +48 -18
- package/lib/vxe-toolbar/index.js +1 -2
- package/lib/vxe-toolbar/index.min.js +1 -1
- package/lib/vxe-ui/index.js +1 -2
- package/lib/vxe-ui/index.min.js +1 -1
- package/lib/vxe-v-x-e-table/index.js +1 -2
- package/lib/vxe-v-x-e-table/index.min.js +1 -1
- package/package.json +93 -93
- package/packages/colgroup/index.ts +22 -22
- package/packages/column/index.ts +22 -22
- package/packages/components.ts +42 -42
- package/packages/grid/index.ts +22 -22
- package/packages/grid/src/grid.ts +1935 -1935
- package/packages/index.ts +4 -4
- package/packages/locale/lang/ar-EG.ts +832 -832
- package/packages/locale/lang/de-DE.ts +832 -832
- package/packages/locale/lang/en-US.ts +832 -832
- package/packages/locale/lang/es-ES.ts +832 -832
- package/packages/locale/lang/fr-FR.ts +832 -832
- package/packages/locale/lang/hu-HU.ts +832 -832
- package/packages/locale/lang/hy-AM.ts +832 -832
- package/packages/locale/lang/id-ID.ts +832 -832
- package/packages/locale/lang/it-IT.ts +832 -832
- package/packages/locale/lang/ja-JP.ts +832 -832
- package/packages/locale/lang/ko-KR.ts +832 -832
- package/packages/locale/lang/ms-MY.ts +832 -832
- package/packages/locale/lang/nb-NO.ts +832 -832
- package/packages/locale/lang/pt-BR.ts +832 -832
- package/packages/locale/lang/ru-RU.ts +832 -832
- package/packages/locale/lang/th-TH.ts +832 -832
- package/packages/locale/lang/ug-CN.ts +832 -832
- package/packages/locale/lang/uk-UA.ts +832 -832
- package/packages/locale/lang/uz-UZ.ts +832 -832
- package/packages/locale/lang/vi-VN.ts +832 -832
- package/packages/locale/lang/zh-CHT.ts +832 -832
- package/packages/locale/lang/zh-CN.ts +832 -832
- package/packages/locale/lang/zh-HK.ts +3 -3
- package/packages/locale/lang/zh-MO.ts +3 -3
- package/packages/locale/lang/zh-TC.ts +3 -3
- package/packages/locale/lang/zh-TW.ts +3 -3
- package/packages/table/index.ts +49 -49
- package/packages/table/module/custom/mixin.ts +369 -369
- package/packages/table/module/custom/panel.ts +1461 -1461
- package/packages/table/module/edit/mixin.ts +1123 -1123
- package/packages/table/module/export/export-panel.ts +658 -658
- package/packages/table/module/export/import-panel.ts +319 -319
- package/packages/table/module/export/mixin.ts +1693 -1693
- package/packages/table/module/export/util.ts +24 -24
- package/packages/table/module/filter/mixin.ts +507 -507
- package/packages/table/module/filter/panel.ts +329 -329
- package/packages/table/module/keyboard/mixin.ts +513 -513
- package/packages/table/module/menu/mixin.ts +329 -329
- package/packages/table/module/menu/panel.ts +212 -212
- package/packages/table/module/validator/mixin.ts +626 -626
- package/packages/table/render/index.ts +1456 -1456
- package/packages/table/src/body.ts +969 -969
- package/packages/table/src/cell.ts +1285 -1285
- package/packages/table/src/column.ts +205 -205
- package/packages/table/src/columnInfo.ts +228 -228
- package/packages/table/src/footer.ts +388 -388
- package/packages/table/src/group.ts +51 -51
- package/packages/table/src/header.ts +602 -602
- package/packages/table/src/methods.ts +12939 -12912
- package/packages/table/src/props.ts +311 -311
- package/packages/table/src/store.ts +15 -15
- package/packages/table/src/table.ts +2502 -2460
- package/packages/table/src/util.ts +1012 -1012
- package/packages/toolbar/index.ts +18 -18
- package/packages/toolbar/src/toolbar.ts +856 -856
- package/packages/ui/index.ts +530 -530
- package/packages/ui/src/anime.ts +52 -52
- package/packages/ui/src/comp.ts +3 -3
- package/packages/ui/src/dom.ts +236 -236
- package/packages/ui/src/log.ts +8 -8
- package/packages/ui/src/utils.ts +56 -56
- package/packages/ui/src/vn.ts +65 -65
- package/packages/v-x-e-table/index.ts +4 -4
- package/styles/all.scss +7 -7
- package/styles/base.scss +16 -16
- package/styles/components/grid.scss +89 -85
- package/styles/components/icon.scss +225 -225
- package/styles/components/old-icon.scss +715 -715
- package/styles/components/table-module/all.scss +6 -6
- package/styles/components/table-module/custom.scss +527 -527
- package/styles/components/table-module/export.scss +130 -130
- package/styles/components/table-module/filter.scss +130 -130
- package/styles/components/table-module/menu.scss +81 -81
- package/styles/components/table.scss +2679 -2679
- package/styles/components/toolbar.scss +119 -119
- package/styles/default.scss +2 -2
- package/styles/helpers/baseMixin.scss +95 -95
- package/styles/index.scss +3 -3
- package/styles/modules.scss +5 -5
- package/styles/theme/base.scss +93 -93
- package/styles/theme/dark.scss +49 -49
- package/styles/theme/light.scss +44 -44
- package/styles/variable.scss +43 -43
- package/types/all.d.ts +53 -53
- package/types/index.d.ts +4 -4
- /package/es/{iconfont.1773644050430.ttf → iconfont.1773972972913.ttf} +0 -0
- /package/es/{iconfont.1773644050430.woff → iconfont.1773972972913.woff} +0 -0
- /package/es/{iconfont.1773644050430.woff2 → iconfont.1773972972913.woff2} +0 -0
- /package/lib/{iconfont.1773644050430.ttf → iconfont.1773972972913.ttf} +0 -0
- /package/lib/{iconfont.1773644050430.woff → iconfont.1773972972913.woff} +0 -0
- /package/lib/{iconfont.1773644050430.woff2 → iconfont.1773972972913.woff2} +0 -0
|
@@ -1,1123 +1,1123 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import { VxeUI } from '../../../ui'
|
|
3
|
-
import { isEnableConf } from '../../../ui/src/utils'
|
|
4
|
-
import { getCellValue, setCellValue, getRowid } from '../../src/util'
|
|
5
|
-
import { removeClass, addClass } from '../../../ui/src/dom'
|
|
6
|
-
import { warnLog, errLog } from '../../../ui/src/log'
|
|
7
|
-
|
|
8
|
-
import type { VxeTableConstructor, TableInternalData, VxeTableDefines, TableReactData, VxeTablePrivateMethods } from '../../../../types'
|
|
9
|
-
|
|
10
|
-
const { getConfig, renderer, getI18n } = VxeUI
|
|
11
|
-
|
|
12
|
-
const browseObj = XEUtils.browse()
|
|
13
|
-
|
|
14
|
-
function getEditColumnModel (row: any, column: VxeTableDefines.ColumnInfo) {
|
|
15
|
-
const { model, editRender } = column
|
|
16
|
-
if (editRender) {
|
|
17
|
-
model.value = getCellValue(row, column)
|
|
18
|
-
model.update = false
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function setEditColumnModel (row: any, column: VxeTableDefines.ColumnInfo) {
|
|
23
|
-
const { model, editRender } = column
|
|
24
|
-
if (editRender && model.update) {
|
|
25
|
-
setCellValue(row, column, model.value)
|
|
26
|
-
model.update = false
|
|
27
|
-
model.value = null
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function removeCellSelectedClass ($xeTable: VxeTableConstructor & VxeTablePrivateMethods) {
|
|
32
|
-
const el = $xeTable.$refs.refElem as HTMLDivElement
|
|
33
|
-
if (el) {
|
|
34
|
-
const cell = el.querySelector('.col--selected')
|
|
35
|
-
if (cell) {
|
|
36
|
-
removeClass(cell, 'col--selected')
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function syncActivedCell ($xeTable: VxeTableConstructor & VxeTablePrivateMethods) {
|
|
42
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
43
|
-
|
|
44
|
-
const { editStore, tableColumn } = reactData
|
|
45
|
-
const editOpts = $xeTable.computeEditOpts
|
|
46
|
-
const { actived } = editStore
|
|
47
|
-
const { row, column } = actived
|
|
48
|
-
if (row || column) {
|
|
49
|
-
if (editOpts.mode === 'row') {
|
|
50
|
-
tableColumn.forEach((column) => setEditColumnModel(row, column))
|
|
51
|
-
} else {
|
|
52
|
-
setEditColumnModel(row, column)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function insertTreeRow ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, newRecords: any[], isAppend: boolean) {
|
|
58
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
59
|
-
|
|
60
|
-
const { tableFullTreeData, afterFullData, fullDataRowIdData, fullAllDataRowIdData } = internalData
|
|
61
|
-
const treeOpts = $xeTable.computeTreeOpts
|
|
62
|
-
const { rowField, parentField, mapChildrenField } = treeOpts
|
|
63
|
-
const childrenField = treeOpts.children || treeOpts.childrenField
|
|
64
|
-
const funcName = isAppend ? 'push' : 'unshift'
|
|
65
|
-
newRecords.forEach((item) => {
|
|
66
|
-
const parentRowId = item[parentField]
|
|
67
|
-
const rowid = getRowid($xeTable, item)
|
|
68
|
-
const matchObj = parentRowId ? XEUtils.findTree(tableFullTreeData, (item) => parentRowId === item[rowField], { children: mapChildrenField }) : null
|
|
69
|
-
if (matchObj) {
|
|
70
|
-
const { item: parentRow } = matchObj
|
|
71
|
-
const parentRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)]
|
|
72
|
-
const parentLevel = parentRest ? parentRest.level : 0
|
|
73
|
-
let pChilds = parentRow[childrenField]
|
|
74
|
-
let pMapChilds = parentRow[mapChildrenField]
|
|
75
|
-
if (!XEUtils.isArray(pChilds)) {
|
|
76
|
-
pChilds = parentRow[childrenField] = []
|
|
77
|
-
}
|
|
78
|
-
if (!XEUtils.isArray(pMapChilds)) {
|
|
79
|
-
pMapChilds = parentRow[mapChildrenField] = []
|
|
80
|
-
}
|
|
81
|
-
pChilds[funcName](item)
|
|
82
|
-
pMapChilds[funcName](item)
|
|
83
|
-
const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: pChilds, parent: parentRow, level: parentLevel + 1, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
|
|
84
|
-
fullDataRowIdData[rowid] = rest
|
|
85
|
-
fullAllDataRowIdData[rowid] = rest
|
|
86
|
-
} else {
|
|
87
|
-
if (parentRowId) {
|
|
88
|
-
warnLog('vxe.error.unableInsert')
|
|
89
|
-
}
|
|
90
|
-
afterFullData[funcName](item)
|
|
91
|
-
tableFullTreeData[funcName](item)
|
|
92
|
-
const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: tableFullTreeData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
|
|
93
|
-
fullDataRowIdData[rowid] = rest
|
|
94
|
-
fullAllDataRowIdData[rowid] = rest
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// function insertGroupRow ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, newRecords: any[], isAppend: boolean) {
|
|
100
|
-
|
|
101
|
-
// }
|
|
102
|
-
|
|
103
|
-
function handleInsertRowAt ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, records: any[], targetRowOrRowid: any, isInsertNextRow?: any) {
|
|
104
|
-
const props = $xeTable
|
|
105
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
106
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
107
|
-
|
|
108
|
-
const { treeConfig } = props
|
|
109
|
-
const { isRowGroupStatus } = reactData
|
|
110
|
-
const { tableFullTreeData, afterFullData, mergeBodyList, tableFullData, fullDataRowIdData, fullAllDataRowIdData, insertRowMaps, removeRowMaps } = internalData
|
|
111
|
-
const treeOpts = $xeTable.computeTreeOpts
|
|
112
|
-
const { transform, parentField, rowField, mapChildrenField } = treeOpts
|
|
113
|
-
const childrenField = treeOpts.children || treeOpts.childrenField
|
|
114
|
-
if (!XEUtils.isArray(records)) {
|
|
115
|
-
records = [records]
|
|
116
|
-
}
|
|
117
|
-
let targetRow = targetRowOrRowid
|
|
118
|
-
if (XEUtils.isString(targetRowOrRowid) || XEUtils.isNumber(targetRowOrRowid)) {
|
|
119
|
-
const rowRest = fullAllDataRowIdData[targetRowOrRowid]
|
|
120
|
-
if (rowRest) {
|
|
121
|
-
targetRow = rowRest.row
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const newRecords: any[] = $xeTable.defineField(records.map(record => Object.assign(treeConfig && transform ? { [mapChildrenField]: [], [childrenField]: [] } : {}, record)))
|
|
125
|
-
let treeRecords: any[] = []
|
|
126
|
-
if (treeConfig && transform) {
|
|
127
|
-
treeRecords = XEUtils.toArrayTree(newRecords, { key: rowField, parentKey: parentField, children: childrenField })
|
|
128
|
-
}
|
|
129
|
-
if (XEUtils.eqNull(targetRow)) {
|
|
130
|
-
// 如果为虚拟树
|
|
131
|
-
if (treeConfig && transform) {
|
|
132
|
-
insertTreeRow($xeTable, newRecords, false)
|
|
133
|
-
} else if (isRowGroupStatus) {
|
|
134
|
-
// 如果分组
|
|
135
|
-
if (treeConfig) {
|
|
136
|
-
throw new Error(getI18n('vxe.error.noTree', ['insert']))
|
|
137
|
-
}
|
|
138
|
-
errLog(getI18n('vxe.error.noGroup', ['insert']))
|
|
139
|
-
// insertGroupRow($xeTable, newRecords, false)
|
|
140
|
-
} else {
|
|
141
|
-
newRecords.forEach(item => {
|
|
142
|
-
const rowid = getRowid($xeTable, item)
|
|
143
|
-
const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: afterFullData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
|
|
144
|
-
fullDataRowIdData[rowid] = rest
|
|
145
|
-
fullAllDataRowIdData[rowid] = rest
|
|
146
|
-
afterFullData.unshift(item)
|
|
147
|
-
tableFullData.unshift(item)
|
|
148
|
-
})
|
|
149
|
-
// 刷新单元格合并
|
|
150
|
-
mergeBodyList.forEach((mergeItem: any) => {
|
|
151
|
-
const { row: mergeRowIndex } = mergeItem
|
|
152
|
-
if (mergeRowIndex >= 0) {
|
|
153
|
-
mergeItem.row = mergeRowIndex + newRecords.length
|
|
154
|
-
}
|
|
155
|
-
})
|
|
156
|
-
}
|
|
157
|
-
} else {
|
|
158
|
-
if (targetRow === -1) {
|
|
159
|
-
// 如果为虚拟树
|
|
160
|
-
if (treeConfig && transform) {
|
|
161
|
-
insertTreeRow($xeTable, newRecords, true)
|
|
162
|
-
} else if (isRowGroupStatus) {
|
|
163
|
-
// 如果分组
|
|
164
|
-
if (treeConfig) {
|
|
165
|
-
throw new Error(getI18n('vxe.error.noTree', ['insert']))
|
|
166
|
-
}
|
|
167
|
-
errLog(getI18n('vxe.error.noGroup', ['insert']))
|
|
168
|
-
// insertGroupRow($xeTable, newRecords, true)
|
|
169
|
-
} else {
|
|
170
|
-
newRecords.forEach(item => {
|
|
171
|
-
const rowid = getRowid($xeTable, item)
|
|
172
|
-
const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: afterFullData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
|
|
173
|
-
fullDataRowIdData[rowid] = rest
|
|
174
|
-
fullAllDataRowIdData[rowid] = rest
|
|
175
|
-
afterFullData.push(item)
|
|
176
|
-
tableFullData.push(item)
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
} else {
|
|
180
|
-
// 如果为虚拟树
|
|
181
|
-
if (treeConfig && transform) {
|
|
182
|
-
const matchMapObj = XEUtils.findTree(tableFullTreeData, item => targetRow[rowField] === item[rowField], { children: mapChildrenField })
|
|
183
|
-
if (matchMapObj) {
|
|
184
|
-
const { parent: parentRow } = matchMapObj
|
|
185
|
-
const parentMapChilds = parentRow ? parentRow[mapChildrenField] : tableFullTreeData
|
|
186
|
-
const parentRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)]
|
|
187
|
-
const parentLevel = parentRest ? parentRest.level : 0
|
|
188
|
-
treeRecords.forEach((row, i) => {
|
|
189
|
-
if (parentRow) {
|
|
190
|
-
if (row[parentField] !== parentRow[rowField]) {
|
|
191
|
-
errLog('vxe.error.errProp', [`${parentField}=${row[parentField]}`, `${parentField}=${parentRow[rowField]}`])
|
|
192
|
-
row[parentField] = parentRow[rowField]
|
|
193
|
-
}
|
|
194
|
-
} else {
|
|
195
|
-
if (row[parentField] !== null) {
|
|
196
|
-
if (!XEUtils.eqNull(row[parentField])) {
|
|
197
|
-
errLog('vxe.error.errProp', [`${parentField}=${row[parentField]}`, 'null'])
|
|
198
|
-
}
|
|
199
|
-
row[parentField] = null
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
let targetIndex = matchMapObj.index + i
|
|
203
|
-
if (isInsertNextRow) {
|
|
204
|
-
targetIndex = targetIndex + 1
|
|
205
|
-
}
|
|
206
|
-
parentMapChilds.splice(targetIndex, 0, row)
|
|
207
|
-
})
|
|
208
|
-
XEUtils.eachTree(treeRecords, (item) => {
|
|
209
|
-
const rowid = getRowid($xeTable, item)
|
|
210
|
-
const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: parentMapChilds, parent: parentRow, level: parentLevel + 1, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
|
|
211
|
-
if (item[childrenField]) {
|
|
212
|
-
item[mapChildrenField] = item[childrenField]
|
|
213
|
-
}
|
|
214
|
-
fullDataRowIdData[rowid] = rest
|
|
215
|
-
fullAllDataRowIdData[rowid] = rest
|
|
216
|
-
}, { children: childrenField })
|
|
217
|
-
// 源
|
|
218
|
-
if (parentRow) {
|
|
219
|
-
const matchObj = XEUtils.findTree(tableFullTreeData, item => targetRow[rowField] === item[rowField], { children: childrenField })
|
|
220
|
-
if (matchObj) {
|
|
221
|
-
const parentChilds = matchObj.items
|
|
222
|
-
let targetIndex = matchObj.index
|
|
223
|
-
if (isInsertNextRow) {
|
|
224
|
-
targetIndex = targetIndex + 1
|
|
225
|
-
}
|
|
226
|
-
parentChilds.splice(targetIndex, 0, ...treeRecords)
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
} else {
|
|
230
|
-
warnLog('vxe.error.unableInsert')
|
|
231
|
-
insertTreeRow($xeTable, newRecords, true)
|
|
232
|
-
}
|
|
233
|
-
} else if (isRowGroupStatus) {
|
|
234
|
-
// 如果分组
|
|
235
|
-
if (treeConfig) {
|
|
236
|
-
throw new Error(getI18n('vxe.error.noTree', ['insert']))
|
|
237
|
-
}
|
|
238
|
-
errLog(getI18n('vxe.error.noGroup', ['insert']))
|
|
239
|
-
} else {
|
|
240
|
-
if (treeConfig) {
|
|
241
|
-
throw new Error(getI18n('vxe.error.noTree', ['insert']))
|
|
242
|
-
}
|
|
243
|
-
let afIndex = -1
|
|
244
|
-
// 如果是可视索引
|
|
245
|
-
if (XEUtils.isNumber(targetRow)) {
|
|
246
|
-
if (targetRow < afterFullData.length) {
|
|
247
|
-
afIndex = targetRow
|
|
248
|
-
}
|
|
249
|
-
} else {
|
|
250
|
-
afIndex = $xeTable.findRowIndexOf(afterFullData, targetRow)
|
|
251
|
-
}
|
|
252
|
-
// 如果是插入指定行的下一行
|
|
253
|
-
if (isInsertNextRow) {
|
|
254
|
-
afIndex = Math.min(afterFullData.length, afIndex + 1)
|
|
255
|
-
}
|
|
256
|
-
if (afIndex === -1) {
|
|
257
|
-
throw new Error(getI18n('vxe.error.unableInsert'))
|
|
258
|
-
}
|
|
259
|
-
afterFullData.splice(afIndex, 0, ...newRecords)
|
|
260
|
-
const tfIndex = $xeTable.findRowIndexOf(tableFullData, targetRow)
|
|
261
|
-
if (tfIndex > -1) {
|
|
262
|
-
tableFullData.splice(tfIndex + (isInsertNextRow ? 1 : 0), 0, ...newRecords)
|
|
263
|
-
} else {
|
|
264
|
-
tableFullData.push(...newRecords)
|
|
265
|
-
}
|
|
266
|
-
// 刷新单元格合并
|
|
267
|
-
mergeBodyList.forEach((mergeItem: any) => {
|
|
268
|
-
const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
|
|
269
|
-
if (mergeRowIndex >= afIndex) {
|
|
270
|
-
mergeItem.row = mergeRowIndex + newRecords.length
|
|
271
|
-
} else if (isInsertNextRow ? (mergeRowIndex + mergeRowspan >= afIndex) : (mergeRowIndex + mergeRowspan > afIndex)) {
|
|
272
|
-
mergeItem.rowspan = mergeRowspan + newRecords.length
|
|
273
|
-
}
|
|
274
|
-
})
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const handleStatus = (newRow: any) => {
|
|
280
|
-
const rowid = getRowid($xeTable, newRow)
|
|
281
|
-
// 如果是被删除的数据,则还原状态
|
|
282
|
-
if (removeRowMaps[rowid]) {
|
|
283
|
-
delete removeRowMaps[rowid]
|
|
284
|
-
if (insertRowMaps[rowid]) {
|
|
285
|
-
delete insertRowMaps[rowid]
|
|
286
|
-
}
|
|
287
|
-
} else {
|
|
288
|
-
insertRowMaps[rowid] = newRow
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
// 如果为虚拟树
|
|
292
|
-
if (treeConfig && transform) {
|
|
293
|
-
XEUtils.eachTree(treeRecords, handleStatus, { children: mapChildrenField })
|
|
294
|
-
} else {
|
|
295
|
-
newRecords.forEach(handleStatus)
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
reactData.removeRowFlag++
|
|
299
|
-
reactData.insertRowFlag++
|
|
300
|
-
$xeTable.cacheRowMap(false)
|
|
301
|
-
$xeTable.updateScrollYStatus()
|
|
302
|
-
$xeTable.handleTableData(treeConfig && transform)
|
|
303
|
-
if (!(treeConfig && transform)) {
|
|
304
|
-
$xeTable.updateAfterDataIndex()
|
|
305
|
-
}
|
|
306
|
-
$xeTable.updateFooter()
|
|
307
|
-
$xeTable.handleUpdateBodyMerge()
|
|
308
|
-
$xeTable.checkSelectionStatus()
|
|
309
|
-
if (reactData.scrollYLoad) {
|
|
310
|
-
$xeTable.updateScrollYSpace()
|
|
311
|
-
}
|
|
312
|
-
return $xeTable.$nextTick().then(() => {
|
|
313
|
-
$xeTable.updateCellAreas()
|
|
314
|
-
return $xeTable.recalculate(true)
|
|
315
|
-
}).then(() => {
|
|
316
|
-
return {
|
|
317
|
-
row: newRecords.length ? newRecords[newRecords.length - 1] : null,
|
|
318
|
-
rows: newRecords
|
|
319
|
-
}
|
|
320
|
-
})
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function handleInsertChildRowAt ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, records: any, parentRowOrParentId: any, targetRowOrRowid: any, isInsertNextRow?: boolean) {
|
|
324
|
-
const props = $xeTable
|
|
325
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
326
|
-
|
|
327
|
-
const { treeConfig } = props
|
|
328
|
-
const { fullAllDataRowIdData } = internalData
|
|
329
|
-
const treeOpts = $xeTable.computeTreeOpts
|
|
330
|
-
const { transform, rowField, parentField } = treeOpts
|
|
331
|
-
if (treeConfig && transform) {
|
|
332
|
-
if (!XEUtils.isArray(records)) {
|
|
333
|
-
records = [records]
|
|
334
|
-
}
|
|
335
|
-
let parentRow = parentRowOrParentId
|
|
336
|
-
if (XEUtils.isString(parentRowOrParentId) || XEUtils.isNumber(parentRowOrParentId)) {
|
|
337
|
-
const rowRest = fullAllDataRowIdData[parentRowOrParentId]
|
|
338
|
-
if (rowRest) {
|
|
339
|
-
parentRow = rowRest.row
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return handleInsertRowAt($xeTable, records.map((item: any) => Object.assign({}, item, { [parentField]: parentRow[rowField] })), targetRowOrRowid, isInsertNextRow)
|
|
343
|
-
} else {
|
|
344
|
-
errLog('vxe.error.errProp', ['tree-config.transform=false', 'tree-config.transform=true'])
|
|
345
|
-
}
|
|
346
|
-
return Promise.resolve({ row: null, rows: [] })
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function handleClearEdit ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, evnt: Event | null, targetRow?: any) {
|
|
350
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
351
|
-
|
|
352
|
-
const { editStore } = reactData
|
|
353
|
-
const { actived, focused } = editStore
|
|
354
|
-
const { row, column } = actived
|
|
355
|
-
const validOpts = $xeTable.computeValidOpts
|
|
356
|
-
if (row || column) {
|
|
357
|
-
if (targetRow && getRowid($xeTable, targetRow) !== getRowid($xeTable, row)) {
|
|
358
|
-
return $xeTable.$nextTick()
|
|
359
|
-
}
|
|
360
|
-
syncActivedCell($xeTable)
|
|
361
|
-
actived.args = null
|
|
362
|
-
actived.row = null
|
|
363
|
-
actived.column = null
|
|
364
|
-
$xeTable.updateFooter()
|
|
365
|
-
$xeTable.dispatchEvent('edit-closed', {
|
|
366
|
-
row,
|
|
367
|
-
rowIndex: $xeTable.getRowIndex(row),
|
|
368
|
-
$rowIndex: $xeTable.getVMRowIndex(row),
|
|
369
|
-
column,
|
|
370
|
-
columnIndex: $xeTable.getColumnIndex(column),
|
|
371
|
-
$columnIndex: $xeTable.getVMColumnIndex(column)
|
|
372
|
-
}, evnt || null)
|
|
373
|
-
}
|
|
374
|
-
focused.row = null
|
|
375
|
-
focused.column = null
|
|
376
|
-
if (validOpts.autoClear) {
|
|
377
|
-
if (validOpts.msgMode !== 'full' || getConfig().cellVaildMode === 'obsolete') {
|
|
378
|
-
if ($xeTable.clearValidate) {
|
|
379
|
-
return $xeTable.clearValidate()
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
return $xeTable.$nextTick().then(() => $xeTable.updateCellAreas())
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
function handleEditActive ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, params: any, evnt: Event | null, isFocus: boolean, isPos: boolean) {
|
|
387
|
-
const props = $xeTable
|
|
388
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
389
|
-
const $xeGrid = $xeTable.$xeGrid
|
|
390
|
-
|
|
391
|
-
const { editConfig, mouseConfig } = props
|
|
392
|
-
const { editStore, tableColumn } = reactData
|
|
393
|
-
const editOpts = $xeTable.computeEditOpts
|
|
394
|
-
const { mode } = editOpts
|
|
395
|
-
const { actived, focused } = editStore
|
|
396
|
-
const { row, column } = params
|
|
397
|
-
const { editRender } = column
|
|
398
|
-
const cell = (params.cell || $xeTable.getCellElement(row, column))
|
|
399
|
-
const beforeEditMethod = editOpts.beforeEditMethod || editOpts.activeMethod
|
|
400
|
-
params.cell = cell
|
|
401
|
-
if (cell && isEnableConf(editConfig) && isEnableConf(editRender)) {
|
|
402
|
-
// 激活编辑
|
|
403
|
-
if (!$xeTable.isPendingByRow(row) && !$xeTable.isAggregateRecord(row)) {
|
|
404
|
-
if (actived.row !== row || (mode === 'cell' ? actived.column !== column : false)) {
|
|
405
|
-
// 判断是否禁用编辑
|
|
406
|
-
let type: 'edit-disabled' | 'edit-activated' = 'edit-disabled'
|
|
407
|
-
if (!beforeEditMethod || beforeEditMethod({ ...params, $table: $xeTable, $grid: $xeGrid })) {
|
|
408
|
-
if (mouseConfig) {
|
|
409
|
-
$xeTable.clearSelected()
|
|
410
|
-
if ($xeTable.clearCellAreas) {
|
|
411
|
-
$xeTable.clearCellAreas()
|
|
412
|
-
$xeTable.clearCopyCellArea()
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
$xeTable.closeTooltip()
|
|
416
|
-
if (actived.column) {
|
|
417
|
-
handleClearEdit($xeTable, evnt)
|
|
418
|
-
}
|
|
419
|
-
type = 'edit-activated'
|
|
420
|
-
column.renderHeight = cell.offsetHeight
|
|
421
|
-
actived.args = params
|
|
422
|
-
actived.row = row
|
|
423
|
-
actived.column = column
|
|
424
|
-
if (mode === 'row') {
|
|
425
|
-
tableColumn.forEach((column: any) => getEditColumnModel(row, column))
|
|
426
|
-
} else {
|
|
427
|
-
getEditColumnModel(row, column)
|
|
428
|
-
}
|
|
429
|
-
const afterEditMethod = editOpts.afterEditMethod
|
|
430
|
-
$xeTable.$nextTick(() => {
|
|
431
|
-
if (isFocus) {
|
|
432
|
-
$xeTable.handleFocus(params, evnt)
|
|
433
|
-
}
|
|
434
|
-
if (afterEditMethod) {
|
|
435
|
-
afterEditMethod({ ...params, $table: $xeTable, $grid: $xeGrid })
|
|
436
|
-
}
|
|
437
|
-
})
|
|
438
|
-
}
|
|
439
|
-
$xeTable.dispatchEvent(type, {
|
|
440
|
-
row,
|
|
441
|
-
rowIndex: $xeTable.getRowIndex(row),
|
|
442
|
-
$rowIndex: $xeTable.getVMRowIndex(row),
|
|
443
|
-
column,
|
|
444
|
-
columnIndex: $xeTable.getColumnIndex(column),
|
|
445
|
-
$columnIndex: $xeTable.getVMColumnIndex(column)
|
|
446
|
-
}, evnt)
|
|
447
|
-
|
|
448
|
-
// v4已废弃
|
|
449
|
-
if (type === 'edit-activated') {
|
|
450
|
-
$xeTable.dispatchEvent('edit-actived', {
|
|
451
|
-
row,
|
|
452
|
-
rowIndex: $xeTable.getRowIndex(row),
|
|
453
|
-
$rowIndex: $xeTable.getVMRowIndex(row),
|
|
454
|
-
column,
|
|
455
|
-
columnIndex: $xeTable.getColumnIndex(column),
|
|
456
|
-
$columnIndex: $xeTable.getVMColumnIndex(column)
|
|
457
|
-
}, evnt)
|
|
458
|
-
}
|
|
459
|
-
} else {
|
|
460
|
-
const { column: oldColumn } = actived
|
|
461
|
-
if (mouseConfig) {
|
|
462
|
-
$xeTable.clearSelected()
|
|
463
|
-
if ($xeTable.clearCellAreas) {
|
|
464
|
-
$xeTable.clearCellAreas()
|
|
465
|
-
$xeTable.clearCopyCellArea()
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
if (oldColumn !== column) {
|
|
469
|
-
const { model: oldModel } = oldColumn
|
|
470
|
-
if (oldModel.update) {
|
|
471
|
-
setCellValue(row, oldColumn, oldModel.value)
|
|
472
|
-
}
|
|
473
|
-
if ($xeTable.clearValidate) {
|
|
474
|
-
$xeTable.clearValidate(row, column)
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
column.renderHeight = cell.offsetHeight
|
|
478
|
-
actived.args = params
|
|
479
|
-
actived.column = column
|
|
480
|
-
if (isPos) {
|
|
481
|
-
setTimeout(() => {
|
|
482
|
-
$xeTable.handleFocus(params, evnt)
|
|
483
|
-
})
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
focused.column = null
|
|
487
|
-
focused.row = null
|
|
488
|
-
$xeTable.focus()
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return $xeTable.$nextTick()
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
function handleEditCell ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, row: any, fieldOrColumn: string | VxeTableDefines.ColumnInfo, isPos: boolean) {
|
|
495
|
-
const props = $xeTable
|
|
496
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
497
|
-
|
|
498
|
-
const { editConfig } = props
|
|
499
|
-
const column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
|
|
500
|
-
if (row && column && isEnableConf(editConfig) && isEnableConf(column.editRender) && !$xeTable.isAggregateRecord(row)) {
|
|
501
|
-
return Promise.resolve(isPos ? $xeTable.scrollToRow(row, column) : null).then(() => {
|
|
502
|
-
const cell = $xeTable.getCellElement(row, column)
|
|
503
|
-
if (cell) {
|
|
504
|
-
handleEditActive($xeTable, {
|
|
505
|
-
row,
|
|
506
|
-
rowIndex: $xeTable.getRowIndex(row),
|
|
507
|
-
column,
|
|
508
|
-
columnIndex: $xeTable.getColumnIndex(column),
|
|
509
|
-
cell,
|
|
510
|
-
$table: $xeTable
|
|
511
|
-
}, null, isPos, isPos)
|
|
512
|
-
internalData._lastCallTime = Date.now()
|
|
513
|
-
}
|
|
514
|
-
return $xeTable.$nextTick()
|
|
515
|
-
})
|
|
516
|
-
}
|
|
517
|
-
return $xeTable.$nextTick()
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
export default {
|
|
521
|
-
methods: {
|
|
522
|
-
/**
|
|
523
|
-
* 往表格中插入临时数据
|
|
524
|
-
*
|
|
525
|
-
* @param {*} records
|
|
526
|
-
*/
|
|
527
|
-
_insert (records: any) {
|
|
528
|
-
return handleInsertRowAt(this, records, null)
|
|
529
|
-
},
|
|
530
|
-
/**
|
|
531
|
-
* 往表格指定行中插入临时数据
|
|
532
|
-
* 如果 row 为空则从插入到顶部
|
|
533
|
-
* 如果 row 为 -1 则从插入到底部
|
|
534
|
-
* 如果 row 为有效行则插入到该行的位置
|
|
535
|
-
* @returns
|
|
536
|
-
*/
|
|
537
|
-
_insertAt (records: any, targetRowOrRowid: any) {
|
|
538
|
-
return handleInsertRowAt(this, records, targetRowOrRowid)
|
|
539
|
-
},
|
|
540
|
-
_insertNextAt (records: any, targetRowOrRowid: any) {
|
|
541
|
-
return handleInsertRowAt(this, records, targetRowOrRowid, true)
|
|
542
|
-
},
|
|
543
|
-
_insertChild (records: any, parentRowOrParentId: any) {
|
|
544
|
-
return handleInsertChildRowAt(this, records, parentRowOrParentId, null)
|
|
545
|
-
},
|
|
546
|
-
_insertChildAt (records: any, parentRowOrParentId: any, targetRowOrRowid: any) {
|
|
547
|
-
return handleInsertChildRowAt(this, records, parentRowOrParentId, targetRowOrRowid)
|
|
548
|
-
},
|
|
549
|
-
_insertChildNextAt (records: any, parentRowOrParentId: any, targetRowOrRowid: any) {
|
|
550
|
-
return handleInsertChildRowAt(this, records, parentRowOrParentId, targetRowOrRowid, true)
|
|
551
|
-
},
|
|
552
|
-
/**
|
|
553
|
-
* 删除指定行数据
|
|
554
|
-
* 如果传 row 则删除一行
|
|
555
|
-
* 如果传 rows 则删除多行
|
|
556
|
-
* 如果为空则删除所有
|
|
557
|
-
*/
|
|
558
|
-
_remove (rows: any[]) {
|
|
559
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
560
|
-
const props = $xeTable
|
|
561
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
562
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
563
|
-
|
|
564
|
-
const { treeConfig } = props
|
|
565
|
-
const { editStore, isRowGroupStatus } = reactData
|
|
566
|
-
const { tableFullTreeData, selectCheckboxMaps, afterFullData, mergeBodyList, tableFullData, pendingRowMaps, insertRowMaps, removeRowMaps } = internalData
|
|
567
|
-
const checkboxOpts = $xeTable.computeCheckboxOpts
|
|
568
|
-
const treeOpts = $xeTable.computeTreeOpts
|
|
569
|
-
const { transform, mapChildrenField } = treeOpts
|
|
570
|
-
const childrenField = treeOpts.children || treeOpts.childrenField
|
|
571
|
-
const { actived } = editStore
|
|
572
|
-
const { checkField } = checkboxOpts
|
|
573
|
-
let delList: any[] = []
|
|
574
|
-
if (!rows) {
|
|
575
|
-
rows = tableFullData
|
|
576
|
-
} else if (!XEUtils.isArray(rows)) {
|
|
577
|
-
rows = [rows]
|
|
578
|
-
}
|
|
579
|
-
// 如果是新增,则保存记录
|
|
580
|
-
rows.forEach(row => {
|
|
581
|
-
if (!$xeTable.isInsertByRow(row)) {
|
|
582
|
-
const rowid = getRowid($xeTable, row)
|
|
583
|
-
removeRowMaps[rowid] = row
|
|
584
|
-
}
|
|
585
|
-
})
|
|
586
|
-
// 如果绑定了多选属性,则更新状态
|
|
587
|
-
if (!checkField) {
|
|
588
|
-
rows.forEach((row) => {
|
|
589
|
-
const rowid = getRowid(this, row)
|
|
590
|
-
if (selectCheckboxMaps[rowid]) {
|
|
591
|
-
delete selectCheckboxMaps[rowid]
|
|
592
|
-
}
|
|
593
|
-
})
|
|
594
|
-
reactData.updateCheckboxFlag++
|
|
595
|
-
}
|
|
596
|
-
// 从数据源中移除
|
|
597
|
-
if (tableFullData === rows) {
|
|
598
|
-
rows = delList = tableFullData.slice(0)
|
|
599
|
-
internalData.tableFullData = []
|
|
600
|
-
internalData.afterFullData = []
|
|
601
|
-
$xeTable.clearMergeCells()
|
|
602
|
-
} else {
|
|
603
|
-
// 如果为虚拟树
|
|
604
|
-
if (treeConfig && transform) {
|
|
605
|
-
rows.forEach((row) => {
|
|
606
|
-
const rowid = getRowid($xeTable, row)
|
|
607
|
-
const matchMapObj = XEUtils.findTree(tableFullTreeData, item => rowid === getRowid($xeTable, item), { children: mapChildrenField })
|
|
608
|
-
if (matchMapObj) {
|
|
609
|
-
const rItems = matchMapObj.items.splice(matchMapObj.index, 1)
|
|
610
|
-
delList.push(rItems[0])
|
|
611
|
-
}
|
|
612
|
-
const matchObj = XEUtils.findTree(tableFullTreeData, item => rowid === getRowid($xeTable, item), { children: childrenField })
|
|
613
|
-
if (matchObj) {
|
|
614
|
-
matchObj.items.splice(matchObj.index, 1)
|
|
615
|
-
}
|
|
616
|
-
const afIndex = $xeTable.findRowIndexOf(afterFullData, row)
|
|
617
|
-
if (afIndex > -1) {
|
|
618
|
-
afterFullData.splice(afIndex, 1)
|
|
619
|
-
}
|
|
620
|
-
})
|
|
621
|
-
} else if (isRowGroupStatus) {
|
|
622
|
-
// 如果分组
|
|
623
|
-
warnLog(getI18n('vxe.error.noGroup', ['remove']))
|
|
624
|
-
} else {
|
|
625
|
-
rows.forEach((row) => {
|
|
626
|
-
const tfIndex = $xeTable.findRowIndexOf(tableFullData, row)
|
|
627
|
-
if (tfIndex > -1) {
|
|
628
|
-
const rItems = tableFullData.splice(tfIndex, 1)
|
|
629
|
-
delList.push(rItems[0])
|
|
630
|
-
}
|
|
631
|
-
const afIndex = $xeTable.findRowIndexOf(afterFullData, row)
|
|
632
|
-
if (afIndex > -1) {
|
|
633
|
-
// 刷新单元格合并
|
|
634
|
-
mergeBodyList.forEach((mergeItem) => {
|
|
635
|
-
const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
|
|
636
|
-
if (mergeRowIndex > afIndex) {
|
|
637
|
-
mergeItem.row = mergeRowIndex - 1
|
|
638
|
-
} else if (mergeRowIndex + mergeRowspan > afIndex) {
|
|
639
|
-
mergeItem.rowspan = mergeRowspan - 1
|
|
640
|
-
}
|
|
641
|
-
})
|
|
642
|
-
afterFullData.splice(afIndex, 1)
|
|
643
|
-
}
|
|
644
|
-
})
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
// 如果当前行被激活编辑,则清除激活状态
|
|
648
|
-
if (actived.row && $xeTable.findRowIndexOf(rows, actived.row) > -1) {
|
|
649
|
-
$xeTable.clearEdit()
|
|
650
|
-
}
|
|
651
|
-
// 从新增中移除已删除的数据
|
|
652
|
-
rows.forEach((row: any) => {
|
|
653
|
-
const rowid = getRowid($xeTable, row)
|
|
654
|
-
if (insertRowMaps[rowid]) {
|
|
655
|
-
delete insertRowMaps[rowid]
|
|
656
|
-
}
|
|
657
|
-
if (pendingRowMaps[rowid]) {
|
|
658
|
-
delete pendingRowMaps[rowid]
|
|
659
|
-
}
|
|
660
|
-
})
|
|
661
|
-
reactData.removeRowFlag++
|
|
662
|
-
reactData.insertRowFlag++
|
|
663
|
-
reactData.pendingRowFlag++
|
|
664
|
-
$xeTable.cacheRowMap(false)
|
|
665
|
-
$xeTable.handleTableData(treeConfig && transform)
|
|
666
|
-
$xeTable.updateFooter()
|
|
667
|
-
$xeTable.handleUpdateBodyMerge()
|
|
668
|
-
if (!(treeConfig && transform)) {
|
|
669
|
-
$xeTable.updateAfterDataIndex()
|
|
670
|
-
}
|
|
671
|
-
$xeTable.checkSelectionStatus()
|
|
672
|
-
if (reactData.scrollYLoad) {
|
|
673
|
-
$xeTable.updateScrollYSpace()
|
|
674
|
-
}
|
|
675
|
-
return $xeTable.$nextTick().then(() => {
|
|
676
|
-
$xeTable.updateCellAreas()
|
|
677
|
-
return $xeTable.recalculate(true)
|
|
678
|
-
}).then(() => {
|
|
679
|
-
return { row: delList.length ? delList[delList.length - 1] : null, rows: delList }
|
|
680
|
-
})
|
|
681
|
-
},
|
|
682
|
-
/**
|
|
683
|
-
* 删除复选框选中的数据
|
|
684
|
-
*/
|
|
685
|
-
_removeCheckboxRow () {
|
|
686
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
687
|
-
|
|
688
|
-
return $xeTable.remove($xeTable.getCheckboxRecords()).then((params: any) => {
|
|
689
|
-
$xeTable.clearCheckboxRow()
|
|
690
|
-
return params
|
|
691
|
-
})
|
|
692
|
-
},
|
|
693
|
-
/**
|
|
694
|
-
* 删除单选框选中的数据
|
|
695
|
-
*/
|
|
696
|
-
_removeRadioRow () {
|
|
697
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
698
|
-
|
|
699
|
-
const radioRecord = $xeTable.getRadioRecord()
|
|
700
|
-
return $xeTable.remove(radioRecord || []).then((params: any) => {
|
|
701
|
-
$xeTable.clearRadioRow()
|
|
702
|
-
return params
|
|
703
|
-
})
|
|
704
|
-
},
|
|
705
|
-
/**
|
|
706
|
-
* 删除当前行选中的数据
|
|
707
|
-
*/
|
|
708
|
-
_removeCurrentRow () {
|
|
709
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
710
|
-
|
|
711
|
-
const currentRecord = $xeTable.getCurrentRecord()
|
|
712
|
-
return $xeTable.remove(currentRecord || []).then((params: any) => {
|
|
713
|
-
$xeTable.clearCurrentRow()
|
|
714
|
-
return params
|
|
715
|
-
})
|
|
716
|
-
},
|
|
717
|
-
/**
|
|
718
|
-
* 获取表格数据集,包含新增、删除、修改
|
|
719
|
-
*/
|
|
720
|
-
_getRecordset () {
|
|
721
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
722
|
-
|
|
723
|
-
const removeRecords = $xeTable.getRemoveRecords()
|
|
724
|
-
const pendingRecords = $xeTable.getPendingRecords()
|
|
725
|
-
const delRecords = removeRecords.concat(pendingRecords)
|
|
726
|
-
// 如果已经被删除,则无需放到更新数组
|
|
727
|
-
const updateRecords = $xeTable.getUpdateRecords().filter((row: any) => {
|
|
728
|
-
return !delRecords.some((item) => $xeTable.eqRow(item, row))
|
|
729
|
-
})
|
|
730
|
-
return {
|
|
731
|
-
insertRecords: $xeTable.getInsertRecords(),
|
|
732
|
-
removeRecords,
|
|
733
|
-
updateRecords,
|
|
734
|
-
pendingRecords
|
|
735
|
-
}
|
|
736
|
-
},
|
|
737
|
-
/**
|
|
738
|
-
* 获取新增的临时数据
|
|
739
|
-
*/
|
|
740
|
-
_getInsertRecords () {
|
|
741
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
742
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
743
|
-
|
|
744
|
-
const { fullAllDataRowIdData, insertRowMaps } = internalData
|
|
745
|
-
const insertRecords: any[] = []
|
|
746
|
-
XEUtils.each(insertRowMaps, (row, rowid) => {
|
|
747
|
-
if (fullAllDataRowIdData[rowid]) {
|
|
748
|
-
insertRecords.push(row)
|
|
749
|
-
}
|
|
750
|
-
})
|
|
751
|
-
return insertRecords
|
|
752
|
-
},
|
|
753
|
-
/**
|
|
754
|
-
* 获取已删除的数据
|
|
755
|
-
*/
|
|
756
|
-
_getRemoveRecords () {
|
|
757
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
758
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
759
|
-
|
|
760
|
-
const { removeRowMaps } = internalData
|
|
761
|
-
const removeRecords: any[] = []
|
|
762
|
-
XEUtils.each(removeRowMaps, (row) => {
|
|
763
|
-
removeRecords.push(row)
|
|
764
|
-
})
|
|
765
|
-
return removeRecords
|
|
766
|
-
},
|
|
767
|
-
/**
|
|
768
|
-
* 获取更新数据
|
|
769
|
-
* 只精准匹配 row 的更改
|
|
770
|
-
* 如果是树表格,子节点更改状态不会影响父节点的更新状态
|
|
771
|
-
*/
|
|
772
|
-
_getUpdateRecords () {
|
|
773
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
774
|
-
const props = $xeTable
|
|
775
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
776
|
-
|
|
777
|
-
const { keepSource, treeConfig } = props
|
|
778
|
-
const { tableFullData } = internalData
|
|
779
|
-
const treeOpts = $xeTable.computeTreeOpts
|
|
780
|
-
if (keepSource) {
|
|
781
|
-
syncActivedCell($xeTable)
|
|
782
|
-
if (treeConfig) {
|
|
783
|
-
return XEUtils.filterTree(tableFullData, row => $xeTable.isUpdateByRow(row), treeOpts)
|
|
784
|
-
}
|
|
785
|
-
return tableFullData.filter((row) => $xeTable.isUpdateByRow(row))
|
|
786
|
-
}
|
|
787
|
-
return []
|
|
788
|
-
},
|
|
789
|
-
/**
|
|
790
|
-
* 处理激活编辑
|
|
791
|
-
*/
|
|
792
|
-
handleEdit (params: any, evnt: any) {
|
|
793
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
794
|
-
|
|
795
|
-
return handleEditActive($xeTable, params, evnt, true, true)
|
|
796
|
-
},
|
|
797
|
-
/**
|
|
798
|
-
* @deprecated
|
|
799
|
-
*/
|
|
800
|
-
handleActived (params: any, evnt: any) {
|
|
801
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
802
|
-
|
|
803
|
-
return $xeTable.handleEdit(params, evnt)
|
|
804
|
-
},
|
|
805
|
-
_getColumnModel (row: any, column: VxeTableDefines.ColumnInfo) {
|
|
806
|
-
getEditColumnModel(row, column)
|
|
807
|
-
},
|
|
808
|
-
_setColumnModel (row: any, column: VxeTableDefines.ColumnInfo) {
|
|
809
|
-
setEditColumnModel(row, column)
|
|
810
|
-
},
|
|
811
|
-
_syncActivedCell () {
|
|
812
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
813
|
-
|
|
814
|
-
syncActivedCell($xeTable)
|
|
815
|
-
},
|
|
816
|
-
_clearActived (row: any) {
|
|
817
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
818
|
-
|
|
819
|
-
warnLog('vxe.error.delFunc', ['clearActived', 'clearEdit'])
|
|
820
|
-
// 即将废弃
|
|
821
|
-
return $xeTable.clearEdit(row)
|
|
822
|
-
},
|
|
823
|
-
/**
|
|
824
|
-
* 清除激活的编辑
|
|
825
|
-
*/
|
|
826
|
-
_clearEdit (row: any) {
|
|
827
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
828
|
-
|
|
829
|
-
return handleClearEdit($xeTable, null, row)
|
|
830
|
-
},
|
|
831
|
-
/**
|
|
832
|
-
* 取消编辑
|
|
833
|
-
*/
|
|
834
|
-
handleClearEdit (evnt: Event | null, targetRow?: any) {
|
|
835
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
836
|
-
|
|
837
|
-
return handleClearEdit($xeTable, evnt, targetRow)
|
|
838
|
-
},
|
|
839
|
-
_getActiveRecord () {
|
|
840
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
841
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
842
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
843
|
-
|
|
844
|
-
warnLog('vxe.error.delFunc', ['getActiveRecord', 'getEditCell'])
|
|
845
|
-
const { editStore } = reactData
|
|
846
|
-
const { fullAllDataRowIdData } = internalData
|
|
847
|
-
const { args, row } = editStore.actived
|
|
848
|
-
if (args && row && fullAllDataRowIdData[getRowid($xeTable, row)]) {
|
|
849
|
-
return Object.assign({}, args, { row })
|
|
850
|
-
}
|
|
851
|
-
return null
|
|
852
|
-
},
|
|
853
|
-
_getEditRecord () {
|
|
854
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
855
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
856
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
857
|
-
|
|
858
|
-
warnLog('vxe.error.delFunc', ['getEditRecord', 'getEditCell'])
|
|
859
|
-
const { editStore } = reactData
|
|
860
|
-
const { fullAllDataRowIdData } = internalData
|
|
861
|
-
const { args, row } = editStore.actived
|
|
862
|
-
if (args && row && fullAllDataRowIdData[getRowid($xeTable, row)]) {
|
|
863
|
-
return Object.assign({}, args, { row })
|
|
864
|
-
}
|
|
865
|
-
return null
|
|
866
|
-
},
|
|
867
|
-
_getEditCell () {
|
|
868
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
869
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
870
|
-
|
|
871
|
-
const { editStore } = reactData
|
|
872
|
-
const { row, column } = editStore.actived
|
|
873
|
-
if (column && row) {
|
|
874
|
-
return {
|
|
875
|
-
row,
|
|
876
|
-
rowIndex: $xeTable.getRowIndex(row),
|
|
877
|
-
column,
|
|
878
|
-
columnIndex: $xeTable.getColumnIndex(column)
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
return null
|
|
882
|
-
},
|
|
883
|
-
_isActiveByRow (row: any) {
|
|
884
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
885
|
-
|
|
886
|
-
warnLog('vxe.error.delFunc', ['isActiveByRow', 'isEditByRow'])
|
|
887
|
-
// 即将废弃
|
|
888
|
-
return $xeTable.isEditByRow(row)
|
|
889
|
-
},
|
|
890
|
-
/**
|
|
891
|
-
* 判断行是否为激活编辑状态
|
|
892
|
-
* @param {Row} row 行对象
|
|
893
|
-
*/
|
|
894
|
-
_isEditByRow (row: any) {
|
|
895
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
896
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
897
|
-
|
|
898
|
-
const { editStore } = reactData
|
|
899
|
-
return editStore.actived.row === row
|
|
900
|
-
},
|
|
901
|
-
/**
|
|
902
|
-
* 处理聚焦
|
|
903
|
-
*/
|
|
904
|
-
handleFocus (params: any) {
|
|
905
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
906
|
-
|
|
907
|
-
const { row, column, cell } = params
|
|
908
|
-
const { editRender } = column
|
|
909
|
-
const editOpts = $xeTable.computeEditOpts
|
|
910
|
-
if (isEnableConf(editRender)) {
|
|
911
|
-
const compRender = renderer.get(editRender.name)
|
|
912
|
-
let autoFocus = editRender.autofocus || editRender.autoFocus
|
|
913
|
-
let autoSelect = editRender.autoSelect || editRender.autoselect
|
|
914
|
-
let inputElem
|
|
915
|
-
// 是否启用聚焦
|
|
916
|
-
if (editOpts.autoFocus) {
|
|
917
|
-
if (!autoFocus && compRender) {
|
|
918
|
-
autoFocus = compRender.tableAutoFocus || compRender.tableAutofocus || (compRender as any).autoFocus || compRender.autofocus
|
|
919
|
-
}
|
|
920
|
-
if (!autoSelect && compRender) {
|
|
921
|
-
autoSelect = compRender.tableAutoSelect || (compRender as any).autoSelect || compRender.autoselect
|
|
922
|
-
}
|
|
923
|
-
// 如果指定了聚焦 class
|
|
924
|
-
if (XEUtils.isFunction(autoFocus)) {
|
|
925
|
-
inputElem = autoFocus.call($xeTable, params)
|
|
926
|
-
} else if (autoFocus) {
|
|
927
|
-
if (autoFocus === true) {
|
|
928
|
-
// 自动匹配模式,会自动匹配第一个可输入元素
|
|
929
|
-
inputElem = cell.querySelector('input,textarea')
|
|
930
|
-
} else {
|
|
931
|
-
inputElem = cell.querySelector(autoFocus)
|
|
932
|
-
}
|
|
933
|
-
if (inputElem) {
|
|
934
|
-
inputElem.focus()
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
if (inputElem) {
|
|
939
|
-
if (autoSelect) {
|
|
940
|
-
inputElem.select()
|
|
941
|
-
} else {
|
|
942
|
-
// 保持一致行为,光标移到末端
|
|
943
|
-
if (browseObj.msie) {
|
|
944
|
-
const textRange = inputElem.createTextRange()
|
|
945
|
-
textRange.collapse(false)
|
|
946
|
-
textRange.select()
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
} else {
|
|
950
|
-
// 是否自动定位
|
|
951
|
-
if (editOpts.autoPos) {
|
|
952
|
-
if (!column.fixed) {
|
|
953
|
-
// 显示到可视区中
|
|
954
|
-
$xeTable.scrollToRow(row, column)
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
},
|
|
960
|
-
_setActiveRow (row: any) {
|
|
961
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
962
|
-
|
|
963
|
-
warnLog('vxe.error.delFunc', ['setActiveRow', 'setEditRow'])
|
|
964
|
-
// 即将废弃
|
|
965
|
-
return $xeTable.setEditRow(row)
|
|
966
|
-
},
|
|
967
|
-
/**
|
|
968
|
-
* 激活行编辑
|
|
969
|
-
*/
|
|
970
|
-
_setEditRow (row: any, fieldOrColumn: any) {
|
|
971
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
972
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
973
|
-
|
|
974
|
-
const { visibleColumn } = internalData
|
|
975
|
-
let column: any = XEUtils.find(visibleColumn, column => isEnableConf(column.editRender))
|
|
976
|
-
let isPos = false
|
|
977
|
-
if (fieldOrColumn) {
|
|
978
|
-
isPos = true
|
|
979
|
-
if (fieldOrColumn !== true) {
|
|
980
|
-
column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
return handleEditCell($xeTable, row, column, isPos)
|
|
984
|
-
},
|
|
985
|
-
_setActiveCell (row: any, fieldOrColumn: any) {
|
|
986
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
987
|
-
|
|
988
|
-
warnLog('vxe.error.delFunc', ['setActiveCell', 'setEditCell'])
|
|
989
|
-
// 即将废弃
|
|
990
|
-
return $xeTable.setEditCell(row, fieldOrColumn)
|
|
991
|
-
},
|
|
992
|
-
/**
|
|
993
|
-
* 激活单元格编辑
|
|
994
|
-
*/
|
|
995
|
-
_setEditCell (row: any, fieldOrColumn: any) {
|
|
996
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
997
|
-
|
|
998
|
-
return handleEditCell($xeTable, row, fieldOrColumn, true)
|
|
999
|
-
},
|
|
1000
|
-
/**
|
|
1001
|
-
* 只对 trigger=dblclick 有效,选中单元格
|
|
1002
|
-
*/
|
|
1003
|
-
_setSelectCell (row: any, fieldOrColumn: string | VxeTableDefines.ColumnInfo) {
|
|
1004
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1005
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
1006
|
-
|
|
1007
|
-
const { tableData } = reactData
|
|
1008
|
-
const editOpts = $xeTable.computeEditOpts
|
|
1009
|
-
const column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
|
|
1010
|
-
if (row && column && editOpts.trigger !== 'manual') {
|
|
1011
|
-
const rowIndex = $xeTable.findRowIndexOf(tableData, row)
|
|
1012
|
-
if (rowIndex > -1) {
|
|
1013
|
-
const cell = $xeTable.getCellElement(row, column)
|
|
1014
|
-
const params = {
|
|
1015
|
-
row,
|
|
1016
|
-
rowIndex,
|
|
1017
|
-
column,
|
|
1018
|
-
columnIndex: $xeTable.getColumnIndex(column),
|
|
1019
|
-
cell
|
|
1020
|
-
}
|
|
1021
|
-
$xeTable.handleSelected(params, {})
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
return $xeTable.$nextTick()
|
|
1025
|
-
},
|
|
1026
|
-
/**
|
|
1027
|
-
* 处理选中源
|
|
1028
|
-
*/
|
|
1029
|
-
handleSelected (params: any, evnt: any) {
|
|
1030
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1031
|
-
const props = $xeTable
|
|
1032
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
1033
|
-
|
|
1034
|
-
const { mouseConfig } = props
|
|
1035
|
-
const { editStore } = reactData
|
|
1036
|
-
const mouseOpts = $xeTable.computeMouseOpts
|
|
1037
|
-
const editOpts = $xeTable.computeEditOpts
|
|
1038
|
-
const { actived, selected } = editStore
|
|
1039
|
-
const { row, column } = params
|
|
1040
|
-
const isMouseSelected = mouseConfig && mouseOpts.selected
|
|
1041
|
-
const selectMethod = () => {
|
|
1042
|
-
if (isMouseSelected && (selected.row !== row || selected.column !== column)) {
|
|
1043
|
-
if (actived.row !== row || (editOpts.mode === 'cell' ? actived.column !== column : false)) {
|
|
1044
|
-
handleClearEdit($xeTable, evnt)
|
|
1045
|
-
$xeTable.clearSelected()
|
|
1046
|
-
if ($xeTable.clearCellAreas) {
|
|
1047
|
-
$xeTable.clearCellAreas()
|
|
1048
|
-
$xeTable.clearCopyCellArea()
|
|
1049
|
-
}
|
|
1050
|
-
selected.args = params
|
|
1051
|
-
selected.row = row
|
|
1052
|
-
selected.column = column
|
|
1053
|
-
if (isMouseSelected) {
|
|
1054
|
-
$xeTable.addCellSelectedClass()
|
|
1055
|
-
}
|
|
1056
|
-
$xeTable.focus()
|
|
1057
|
-
if (evnt) {
|
|
1058
|
-
$xeTable.dispatchEvent('cell-selected', params, evnt)
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
return $xeTable.$nextTick()
|
|
1063
|
-
}
|
|
1064
|
-
return selectMethod()
|
|
1065
|
-
},
|
|
1066
|
-
/**
|
|
1067
|
-
* 获取选中的单元格
|
|
1068
|
-
*/
|
|
1069
|
-
_getSelectedCell () {
|
|
1070
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1071
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
1072
|
-
|
|
1073
|
-
const { editStore } = reactData
|
|
1074
|
-
const { row, column } = editStore.selected
|
|
1075
|
-
if (row && column) {
|
|
1076
|
-
return {
|
|
1077
|
-
row,
|
|
1078
|
-
column
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
return null
|
|
1082
|
-
},
|
|
1083
|
-
/**
|
|
1084
|
-
* 清除所选中源状态
|
|
1085
|
-
*/
|
|
1086
|
-
_clearSelected () {
|
|
1087
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1088
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
1089
|
-
|
|
1090
|
-
const { editStore } = reactData
|
|
1091
|
-
const { selected } = editStore
|
|
1092
|
-
selected.row = null
|
|
1093
|
-
selected.column = null
|
|
1094
|
-
removeCellSelectedClass($xeTable)
|
|
1095
|
-
return $xeTable.$nextTick()
|
|
1096
|
-
},
|
|
1097
|
-
reColTitleSdCls () {
|
|
1098
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1099
|
-
const internalData = $xeTable as unknown as TableInternalData
|
|
1100
|
-
|
|
1101
|
-
const { elemStore } = internalData
|
|
1102
|
-
const headerElem = elemStore['main-header-list']
|
|
1103
|
-
if (headerElem) {
|
|
1104
|
-
XEUtils.arrayEach(headerElem.querySelectorAll('.col--title-selected'), elem => removeClass(elem, 'col--title-selected'))
|
|
1105
|
-
}
|
|
1106
|
-
},
|
|
1107
|
-
addCellSelectedClass () {
|
|
1108
|
-
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1109
|
-
const reactData = $xeTable as unknown as TableReactData
|
|
1110
|
-
|
|
1111
|
-
const { editStore } = reactData
|
|
1112
|
-
const { selected } = editStore
|
|
1113
|
-
const { row, column } = selected
|
|
1114
|
-
removeCellSelectedClass($xeTable)
|
|
1115
|
-
if (row && column) {
|
|
1116
|
-
const cell = $xeTable.getCellElement(row, column)
|
|
1117
|
-
if (cell) {
|
|
1118
|
-
addClass(cell, 'col--selected')
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
} as any
|
|
1123
|
-
} as any
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import { VxeUI } from '../../../ui'
|
|
3
|
+
import { isEnableConf } from '../../../ui/src/utils'
|
|
4
|
+
import { getCellValue, setCellValue, getRowid } from '../../src/util'
|
|
5
|
+
import { removeClass, addClass } from '../../../ui/src/dom'
|
|
6
|
+
import { warnLog, errLog } from '../../../ui/src/log'
|
|
7
|
+
|
|
8
|
+
import type { VxeTableConstructor, TableInternalData, VxeTableDefines, TableReactData, VxeTablePrivateMethods } from '../../../../types'
|
|
9
|
+
|
|
10
|
+
const { getConfig, renderer, getI18n } = VxeUI
|
|
11
|
+
|
|
12
|
+
const browseObj = XEUtils.browse()
|
|
13
|
+
|
|
14
|
+
function getEditColumnModel (row: any, column: VxeTableDefines.ColumnInfo) {
|
|
15
|
+
const { model, editRender } = column
|
|
16
|
+
if (editRender) {
|
|
17
|
+
model.value = getCellValue(row, column)
|
|
18
|
+
model.update = false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function setEditColumnModel (row: any, column: VxeTableDefines.ColumnInfo) {
|
|
23
|
+
const { model, editRender } = column
|
|
24
|
+
if (editRender && model.update) {
|
|
25
|
+
setCellValue(row, column, model.value)
|
|
26
|
+
model.update = false
|
|
27
|
+
model.value = null
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function removeCellSelectedClass ($xeTable: VxeTableConstructor & VxeTablePrivateMethods) {
|
|
32
|
+
const el = $xeTable.$refs.refElem as HTMLDivElement
|
|
33
|
+
if (el) {
|
|
34
|
+
const cell = el.querySelector('.col--selected')
|
|
35
|
+
if (cell) {
|
|
36
|
+
removeClass(cell, 'col--selected')
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function syncActivedCell ($xeTable: VxeTableConstructor & VxeTablePrivateMethods) {
|
|
42
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
43
|
+
|
|
44
|
+
const { editStore, tableColumn } = reactData
|
|
45
|
+
const editOpts = $xeTable.computeEditOpts
|
|
46
|
+
const { actived } = editStore
|
|
47
|
+
const { row, column } = actived
|
|
48
|
+
if (row || column) {
|
|
49
|
+
if (editOpts.mode === 'row') {
|
|
50
|
+
tableColumn.forEach((column) => setEditColumnModel(row, column))
|
|
51
|
+
} else {
|
|
52
|
+
setEditColumnModel(row, column)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function insertTreeRow ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, newRecords: any[], isAppend: boolean) {
|
|
58
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
59
|
+
|
|
60
|
+
const { tableFullTreeData, afterFullData, fullDataRowIdData, fullAllDataRowIdData } = internalData
|
|
61
|
+
const treeOpts = $xeTable.computeTreeOpts
|
|
62
|
+
const { rowField, parentField, mapChildrenField } = treeOpts
|
|
63
|
+
const childrenField = treeOpts.children || treeOpts.childrenField
|
|
64
|
+
const funcName = isAppend ? 'push' : 'unshift'
|
|
65
|
+
newRecords.forEach((item) => {
|
|
66
|
+
const parentRowId = item[parentField]
|
|
67
|
+
const rowid = getRowid($xeTable, item)
|
|
68
|
+
const matchObj = parentRowId ? XEUtils.findTree(tableFullTreeData, (item) => parentRowId === item[rowField], { children: mapChildrenField }) : null
|
|
69
|
+
if (matchObj) {
|
|
70
|
+
const { item: parentRow } = matchObj
|
|
71
|
+
const parentRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)]
|
|
72
|
+
const parentLevel = parentRest ? parentRest.level : 0
|
|
73
|
+
let pChilds = parentRow[childrenField]
|
|
74
|
+
let pMapChilds = parentRow[mapChildrenField]
|
|
75
|
+
if (!XEUtils.isArray(pChilds)) {
|
|
76
|
+
pChilds = parentRow[childrenField] = []
|
|
77
|
+
}
|
|
78
|
+
if (!XEUtils.isArray(pMapChilds)) {
|
|
79
|
+
pMapChilds = parentRow[mapChildrenField] = []
|
|
80
|
+
}
|
|
81
|
+
pChilds[funcName](item)
|
|
82
|
+
pMapChilds[funcName](item)
|
|
83
|
+
const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: pChilds, parent: parentRow, level: parentLevel + 1, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
|
|
84
|
+
fullDataRowIdData[rowid] = rest
|
|
85
|
+
fullAllDataRowIdData[rowid] = rest
|
|
86
|
+
} else {
|
|
87
|
+
if (parentRowId) {
|
|
88
|
+
warnLog('vxe.error.unableInsert')
|
|
89
|
+
}
|
|
90
|
+
afterFullData[funcName](item)
|
|
91
|
+
tableFullTreeData[funcName](item)
|
|
92
|
+
const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: tableFullTreeData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
|
|
93
|
+
fullDataRowIdData[rowid] = rest
|
|
94
|
+
fullAllDataRowIdData[rowid] = rest
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// function insertGroupRow ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, newRecords: any[], isAppend: boolean) {
|
|
100
|
+
|
|
101
|
+
// }
|
|
102
|
+
|
|
103
|
+
function handleInsertRowAt ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, records: any[], targetRowOrRowid: any, isInsertNextRow?: any) {
|
|
104
|
+
const props = $xeTable
|
|
105
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
106
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
107
|
+
|
|
108
|
+
const { treeConfig } = props
|
|
109
|
+
const { isRowGroupStatus } = reactData
|
|
110
|
+
const { tableFullTreeData, afterFullData, mergeBodyList, tableFullData, fullDataRowIdData, fullAllDataRowIdData, insertRowMaps, removeRowMaps } = internalData
|
|
111
|
+
const treeOpts = $xeTable.computeTreeOpts
|
|
112
|
+
const { transform, parentField, rowField, mapChildrenField } = treeOpts
|
|
113
|
+
const childrenField = treeOpts.children || treeOpts.childrenField
|
|
114
|
+
if (!XEUtils.isArray(records)) {
|
|
115
|
+
records = [records]
|
|
116
|
+
}
|
|
117
|
+
let targetRow = targetRowOrRowid
|
|
118
|
+
if (XEUtils.isString(targetRowOrRowid) || XEUtils.isNumber(targetRowOrRowid)) {
|
|
119
|
+
const rowRest = fullAllDataRowIdData[targetRowOrRowid]
|
|
120
|
+
if (rowRest) {
|
|
121
|
+
targetRow = rowRest.row
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const newRecords: any[] = $xeTable.defineField(records.map(record => Object.assign(treeConfig && transform ? { [mapChildrenField]: [], [childrenField]: [] } : {}, record)))
|
|
125
|
+
let treeRecords: any[] = []
|
|
126
|
+
if (treeConfig && transform) {
|
|
127
|
+
treeRecords = XEUtils.toArrayTree(newRecords, { key: rowField, parentKey: parentField, children: childrenField })
|
|
128
|
+
}
|
|
129
|
+
if (XEUtils.eqNull(targetRow)) {
|
|
130
|
+
// 如果为虚拟树
|
|
131
|
+
if (treeConfig && transform) {
|
|
132
|
+
insertTreeRow($xeTable, newRecords, false)
|
|
133
|
+
} else if (isRowGroupStatus) {
|
|
134
|
+
// 如果分组
|
|
135
|
+
if (treeConfig) {
|
|
136
|
+
throw new Error(getI18n('vxe.error.noTree', ['insert']))
|
|
137
|
+
}
|
|
138
|
+
errLog(getI18n('vxe.error.noGroup', ['insert']))
|
|
139
|
+
// insertGroupRow($xeTable, newRecords, false)
|
|
140
|
+
} else {
|
|
141
|
+
newRecords.forEach(item => {
|
|
142
|
+
const rowid = getRowid($xeTable, item)
|
|
143
|
+
const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: afterFullData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
|
|
144
|
+
fullDataRowIdData[rowid] = rest
|
|
145
|
+
fullAllDataRowIdData[rowid] = rest
|
|
146
|
+
afterFullData.unshift(item)
|
|
147
|
+
tableFullData.unshift(item)
|
|
148
|
+
})
|
|
149
|
+
// 刷新单元格合并
|
|
150
|
+
mergeBodyList.forEach((mergeItem: any) => {
|
|
151
|
+
const { row: mergeRowIndex } = mergeItem
|
|
152
|
+
if (mergeRowIndex >= 0) {
|
|
153
|
+
mergeItem.row = mergeRowIndex + newRecords.length
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
if (targetRow === -1) {
|
|
159
|
+
// 如果为虚拟树
|
|
160
|
+
if (treeConfig && transform) {
|
|
161
|
+
insertTreeRow($xeTable, newRecords, true)
|
|
162
|
+
} else if (isRowGroupStatus) {
|
|
163
|
+
// 如果分组
|
|
164
|
+
if (treeConfig) {
|
|
165
|
+
throw new Error(getI18n('vxe.error.noTree', ['insert']))
|
|
166
|
+
}
|
|
167
|
+
errLog(getI18n('vxe.error.noGroup', ['insert']))
|
|
168
|
+
// insertGroupRow($xeTable, newRecords, true)
|
|
169
|
+
} else {
|
|
170
|
+
newRecords.forEach(item => {
|
|
171
|
+
const rowid = getRowid($xeTable, item)
|
|
172
|
+
const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: afterFullData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
|
|
173
|
+
fullDataRowIdData[rowid] = rest
|
|
174
|
+
fullAllDataRowIdData[rowid] = rest
|
|
175
|
+
afterFullData.push(item)
|
|
176
|
+
tableFullData.push(item)
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
// 如果为虚拟树
|
|
181
|
+
if (treeConfig && transform) {
|
|
182
|
+
const matchMapObj = XEUtils.findTree(tableFullTreeData, item => targetRow[rowField] === item[rowField], { children: mapChildrenField })
|
|
183
|
+
if (matchMapObj) {
|
|
184
|
+
const { parent: parentRow } = matchMapObj
|
|
185
|
+
const parentMapChilds = parentRow ? parentRow[mapChildrenField] : tableFullTreeData
|
|
186
|
+
const parentRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)]
|
|
187
|
+
const parentLevel = parentRest ? parentRest.level : 0
|
|
188
|
+
treeRecords.forEach((row, i) => {
|
|
189
|
+
if (parentRow) {
|
|
190
|
+
if (row[parentField] !== parentRow[rowField]) {
|
|
191
|
+
errLog('vxe.error.errProp', [`${parentField}=${row[parentField]}`, `${parentField}=${parentRow[rowField]}`])
|
|
192
|
+
row[parentField] = parentRow[rowField]
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
if (row[parentField] !== null) {
|
|
196
|
+
if (!XEUtils.eqNull(row[parentField])) {
|
|
197
|
+
errLog('vxe.error.errProp', [`${parentField}=${row[parentField]}`, 'null'])
|
|
198
|
+
}
|
|
199
|
+
row[parentField] = null
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
let targetIndex = matchMapObj.index + i
|
|
203
|
+
if (isInsertNextRow) {
|
|
204
|
+
targetIndex = targetIndex + 1
|
|
205
|
+
}
|
|
206
|
+
parentMapChilds.splice(targetIndex, 0, row)
|
|
207
|
+
})
|
|
208
|
+
XEUtils.eachTree(treeRecords, (item) => {
|
|
209
|
+
const rowid = getRowid($xeTable, item)
|
|
210
|
+
const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: parentMapChilds, parent: parentRow, level: parentLevel + 1, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
|
|
211
|
+
if (item[childrenField]) {
|
|
212
|
+
item[mapChildrenField] = item[childrenField]
|
|
213
|
+
}
|
|
214
|
+
fullDataRowIdData[rowid] = rest
|
|
215
|
+
fullAllDataRowIdData[rowid] = rest
|
|
216
|
+
}, { children: childrenField })
|
|
217
|
+
// 源
|
|
218
|
+
if (parentRow) {
|
|
219
|
+
const matchObj = XEUtils.findTree(tableFullTreeData, item => targetRow[rowField] === item[rowField], { children: childrenField })
|
|
220
|
+
if (matchObj) {
|
|
221
|
+
const parentChilds = matchObj.items
|
|
222
|
+
let targetIndex = matchObj.index
|
|
223
|
+
if (isInsertNextRow) {
|
|
224
|
+
targetIndex = targetIndex + 1
|
|
225
|
+
}
|
|
226
|
+
parentChilds.splice(targetIndex, 0, ...treeRecords)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
warnLog('vxe.error.unableInsert')
|
|
231
|
+
insertTreeRow($xeTable, newRecords, true)
|
|
232
|
+
}
|
|
233
|
+
} else if (isRowGroupStatus) {
|
|
234
|
+
// 如果分组
|
|
235
|
+
if (treeConfig) {
|
|
236
|
+
throw new Error(getI18n('vxe.error.noTree', ['insert']))
|
|
237
|
+
}
|
|
238
|
+
errLog(getI18n('vxe.error.noGroup', ['insert']))
|
|
239
|
+
} else {
|
|
240
|
+
if (treeConfig) {
|
|
241
|
+
throw new Error(getI18n('vxe.error.noTree', ['insert']))
|
|
242
|
+
}
|
|
243
|
+
let afIndex = -1
|
|
244
|
+
// 如果是可视索引
|
|
245
|
+
if (XEUtils.isNumber(targetRow)) {
|
|
246
|
+
if (targetRow < afterFullData.length) {
|
|
247
|
+
afIndex = targetRow
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
afIndex = $xeTable.findRowIndexOf(afterFullData, targetRow)
|
|
251
|
+
}
|
|
252
|
+
// 如果是插入指定行的下一行
|
|
253
|
+
if (isInsertNextRow) {
|
|
254
|
+
afIndex = Math.min(afterFullData.length, afIndex + 1)
|
|
255
|
+
}
|
|
256
|
+
if (afIndex === -1) {
|
|
257
|
+
throw new Error(getI18n('vxe.error.unableInsert'))
|
|
258
|
+
}
|
|
259
|
+
afterFullData.splice(afIndex, 0, ...newRecords)
|
|
260
|
+
const tfIndex = $xeTable.findRowIndexOf(tableFullData, targetRow)
|
|
261
|
+
if (tfIndex > -1) {
|
|
262
|
+
tableFullData.splice(tfIndex + (isInsertNextRow ? 1 : 0), 0, ...newRecords)
|
|
263
|
+
} else {
|
|
264
|
+
tableFullData.push(...newRecords)
|
|
265
|
+
}
|
|
266
|
+
// 刷新单元格合并
|
|
267
|
+
mergeBodyList.forEach((mergeItem: any) => {
|
|
268
|
+
const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
|
|
269
|
+
if (mergeRowIndex >= afIndex) {
|
|
270
|
+
mergeItem.row = mergeRowIndex + newRecords.length
|
|
271
|
+
} else if (isInsertNextRow ? (mergeRowIndex + mergeRowspan >= afIndex) : (mergeRowIndex + mergeRowspan > afIndex)) {
|
|
272
|
+
mergeItem.rowspan = mergeRowspan + newRecords.length
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const handleStatus = (newRow: any) => {
|
|
280
|
+
const rowid = getRowid($xeTable, newRow)
|
|
281
|
+
// 如果是被删除的数据,则还原状态
|
|
282
|
+
if (removeRowMaps[rowid]) {
|
|
283
|
+
delete removeRowMaps[rowid]
|
|
284
|
+
if (insertRowMaps[rowid]) {
|
|
285
|
+
delete insertRowMaps[rowid]
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
insertRowMaps[rowid] = newRow
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// 如果为虚拟树
|
|
292
|
+
if (treeConfig && transform) {
|
|
293
|
+
XEUtils.eachTree(treeRecords, handleStatus, { children: mapChildrenField })
|
|
294
|
+
} else {
|
|
295
|
+
newRecords.forEach(handleStatus)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
reactData.removeRowFlag++
|
|
299
|
+
reactData.insertRowFlag++
|
|
300
|
+
$xeTable.cacheRowMap(false)
|
|
301
|
+
$xeTable.updateScrollYStatus()
|
|
302
|
+
$xeTable.handleTableData(treeConfig && transform)
|
|
303
|
+
if (!(treeConfig && transform)) {
|
|
304
|
+
$xeTable.updateAfterDataIndex()
|
|
305
|
+
}
|
|
306
|
+
$xeTable.updateFooter()
|
|
307
|
+
$xeTable.handleUpdateBodyMerge()
|
|
308
|
+
$xeTable.checkSelectionStatus()
|
|
309
|
+
if (reactData.scrollYLoad) {
|
|
310
|
+
$xeTable.updateScrollYSpace()
|
|
311
|
+
}
|
|
312
|
+
return $xeTable.$nextTick().then(() => {
|
|
313
|
+
$xeTable.updateCellAreas()
|
|
314
|
+
return $xeTable.recalculate(true)
|
|
315
|
+
}).then(() => {
|
|
316
|
+
return {
|
|
317
|
+
row: newRecords.length ? newRecords[newRecords.length - 1] : null,
|
|
318
|
+
rows: newRecords
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function handleInsertChildRowAt ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, records: any, parentRowOrParentId: any, targetRowOrRowid: any, isInsertNextRow?: boolean) {
|
|
324
|
+
const props = $xeTable
|
|
325
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
326
|
+
|
|
327
|
+
const { treeConfig } = props
|
|
328
|
+
const { fullAllDataRowIdData } = internalData
|
|
329
|
+
const treeOpts = $xeTable.computeTreeOpts
|
|
330
|
+
const { transform, rowField, parentField } = treeOpts
|
|
331
|
+
if (treeConfig && transform) {
|
|
332
|
+
if (!XEUtils.isArray(records)) {
|
|
333
|
+
records = [records]
|
|
334
|
+
}
|
|
335
|
+
let parentRow = parentRowOrParentId
|
|
336
|
+
if (XEUtils.isString(parentRowOrParentId) || XEUtils.isNumber(parentRowOrParentId)) {
|
|
337
|
+
const rowRest = fullAllDataRowIdData[parentRowOrParentId]
|
|
338
|
+
if (rowRest) {
|
|
339
|
+
parentRow = rowRest.row
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return handleInsertRowAt($xeTable, records.map((item: any) => Object.assign({}, item, { [parentField]: parentRow[rowField] })), targetRowOrRowid, isInsertNextRow)
|
|
343
|
+
} else {
|
|
344
|
+
errLog('vxe.error.errProp', ['tree-config.transform=false', 'tree-config.transform=true'])
|
|
345
|
+
}
|
|
346
|
+
return Promise.resolve({ row: null, rows: [] })
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function handleClearEdit ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, evnt: Event | null, targetRow?: any) {
|
|
350
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
351
|
+
|
|
352
|
+
const { editStore } = reactData
|
|
353
|
+
const { actived, focused } = editStore
|
|
354
|
+
const { row, column } = actived
|
|
355
|
+
const validOpts = $xeTable.computeValidOpts
|
|
356
|
+
if (row || column) {
|
|
357
|
+
if (targetRow && getRowid($xeTable, targetRow) !== getRowid($xeTable, row)) {
|
|
358
|
+
return $xeTable.$nextTick()
|
|
359
|
+
}
|
|
360
|
+
syncActivedCell($xeTable)
|
|
361
|
+
actived.args = null
|
|
362
|
+
actived.row = null
|
|
363
|
+
actived.column = null
|
|
364
|
+
$xeTable.updateFooter()
|
|
365
|
+
$xeTable.dispatchEvent('edit-closed', {
|
|
366
|
+
row,
|
|
367
|
+
rowIndex: $xeTable.getRowIndex(row),
|
|
368
|
+
$rowIndex: $xeTable.getVMRowIndex(row),
|
|
369
|
+
column,
|
|
370
|
+
columnIndex: $xeTable.getColumnIndex(column),
|
|
371
|
+
$columnIndex: $xeTable.getVMColumnIndex(column)
|
|
372
|
+
}, evnt || null)
|
|
373
|
+
}
|
|
374
|
+
focused.row = null
|
|
375
|
+
focused.column = null
|
|
376
|
+
if (validOpts.autoClear) {
|
|
377
|
+
if (validOpts.msgMode !== 'full' || getConfig().cellVaildMode === 'obsolete') {
|
|
378
|
+
if ($xeTable.clearValidate) {
|
|
379
|
+
return $xeTable.clearValidate()
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return $xeTable.$nextTick().then(() => $xeTable.updateCellAreas())
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function handleEditActive ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, params: any, evnt: Event | null, isFocus: boolean, isPos: boolean) {
|
|
387
|
+
const props = $xeTable
|
|
388
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
389
|
+
const $xeGrid = $xeTable.$xeGrid
|
|
390
|
+
|
|
391
|
+
const { editConfig, mouseConfig } = props
|
|
392
|
+
const { editStore, tableColumn } = reactData
|
|
393
|
+
const editOpts = $xeTable.computeEditOpts
|
|
394
|
+
const { mode } = editOpts
|
|
395
|
+
const { actived, focused } = editStore
|
|
396
|
+
const { row, column } = params
|
|
397
|
+
const { editRender } = column
|
|
398
|
+
const cell = (params.cell || $xeTable.getCellElement(row, column))
|
|
399
|
+
const beforeEditMethod = editOpts.beforeEditMethod || editOpts.activeMethod
|
|
400
|
+
params.cell = cell
|
|
401
|
+
if (cell && isEnableConf(editConfig) && isEnableConf(editRender)) {
|
|
402
|
+
// 激活编辑
|
|
403
|
+
if (!$xeTable.isPendingByRow(row) && !$xeTable.isAggregateRecord(row)) {
|
|
404
|
+
if (actived.row !== row || (mode === 'cell' ? actived.column !== column : false)) {
|
|
405
|
+
// 判断是否禁用编辑
|
|
406
|
+
let type: 'edit-disabled' | 'edit-activated' = 'edit-disabled'
|
|
407
|
+
if (!beforeEditMethod || beforeEditMethod({ ...params, $table: $xeTable, $grid: $xeGrid })) {
|
|
408
|
+
if (mouseConfig) {
|
|
409
|
+
$xeTable.clearSelected()
|
|
410
|
+
if ($xeTable.clearCellAreas) {
|
|
411
|
+
$xeTable.clearCellAreas()
|
|
412
|
+
$xeTable.clearCopyCellArea()
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
$xeTable.closeTooltip()
|
|
416
|
+
if (actived.column) {
|
|
417
|
+
handleClearEdit($xeTable, evnt)
|
|
418
|
+
}
|
|
419
|
+
type = 'edit-activated'
|
|
420
|
+
column.renderHeight = cell.offsetHeight
|
|
421
|
+
actived.args = params
|
|
422
|
+
actived.row = row
|
|
423
|
+
actived.column = column
|
|
424
|
+
if (mode === 'row') {
|
|
425
|
+
tableColumn.forEach((column: any) => getEditColumnModel(row, column))
|
|
426
|
+
} else {
|
|
427
|
+
getEditColumnModel(row, column)
|
|
428
|
+
}
|
|
429
|
+
const afterEditMethod = editOpts.afterEditMethod
|
|
430
|
+
$xeTable.$nextTick(() => {
|
|
431
|
+
if (isFocus) {
|
|
432
|
+
$xeTable.handleFocus(params, evnt)
|
|
433
|
+
}
|
|
434
|
+
if (afterEditMethod) {
|
|
435
|
+
afterEditMethod({ ...params, $table: $xeTable, $grid: $xeGrid })
|
|
436
|
+
}
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
$xeTable.dispatchEvent(type, {
|
|
440
|
+
row,
|
|
441
|
+
rowIndex: $xeTable.getRowIndex(row),
|
|
442
|
+
$rowIndex: $xeTable.getVMRowIndex(row),
|
|
443
|
+
column,
|
|
444
|
+
columnIndex: $xeTable.getColumnIndex(column),
|
|
445
|
+
$columnIndex: $xeTable.getVMColumnIndex(column)
|
|
446
|
+
}, evnt)
|
|
447
|
+
|
|
448
|
+
// v4已废弃
|
|
449
|
+
if (type === 'edit-activated') {
|
|
450
|
+
$xeTable.dispatchEvent('edit-actived', {
|
|
451
|
+
row,
|
|
452
|
+
rowIndex: $xeTable.getRowIndex(row),
|
|
453
|
+
$rowIndex: $xeTable.getVMRowIndex(row),
|
|
454
|
+
column,
|
|
455
|
+
columnIndex: $xeTable.getColumnIndex(column),
|
|
456
|
+
$columnIndex: $xeTable.getVMColumnIndex(column)
|
|
457
|
+
}, evnt)
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
const { column: oldColumn } = actived
|
|
461
|
+
if (mouseConfig) {
|
|
462
|
+
$xeTable.clearSelected()
|
|
463
|
+
if ($xeTable.clearCellAreas) {
|
|
464
|
+
$xeTable.clearCellAreas()
|
|
465
|
+
$xeTable.clearCopyCellArea()
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (oldColumn !== column) {
|
|
469
|
+
const { model: oldModel } = oldColumn
|
|
470
|
+
if (oldModel.update) {
|
|
471
|
+
setCellValue(row, oldColumn, oldModel.value)
|
|
472
|
+
}
|
|
473
|
+
if ($xeTable.clearValidate) {
|
|
474
|
+
$xeTable.clearValidate(row, column)
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
column.renderHeight = cell.offsetHeight
|
|
478
|
+
actived.args = params
|
|
479
|
+
actived.column = column
|
|
480
|
+
if (isPos) {
|
|
481
|
+
setTimeout(() => {
|
|
482
|
+
$xeTable.handleFocus(params, evnt)
|
|
483
|
+
})
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
focused.column = null
|
|
487
|
+
focused.row = null
|
|
488
|
+
$xeTable.focus()
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return $xeTable.$nextTick()
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function handleEditCell ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, row: any, fieldOrColumn: string | VxeTableDefines.ColumnInfo, isPos: boolean) {
|
|
495
|
+
const props = $xeTable
|
|
496
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
497
|
+
|
|
498
|
+
const { editConfig } = props
|
|
499
|
+
const column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
|
|
500
|
+
if (row && column && isEnableConf(editConfig) && isEnableConf(column.editRender) && !$xeTable.isAggregateRecord(row)) {
|
|
501
|
+
return Promise.resolve(isPos ? $xeTable.scrollToRow(row, column) : null).then(() => {
|
|
502
|
+
const cell = $xeTable.getCellElement(row, column)
|
|
503
|
+
if (cell) {
|
|
504
|
+
handleEditActive($xeTable, {
|
|
505
|
+
row,
|
|
506
|
+
rowIndex: $xeTable.getRowIndex(row),
|
|
507
|
+
column,
|
|
508
|
+
columnIndex: $xeTable.getColumnIndex(column),
|
|
509
|
+
cell,
|
|
510
|
+
$table: $xeTable
|
|
511
|
+
}, null, isPos, isPos)
|
|
512
|
+
internalData._lastCallTime = Date.now()
|
|
513
|
+
}
|
|
514
|
+
return $xeTable.$nextTick()
|
|
515
|
+
})
|
|
516
|
+
}
|
|
517
|
+
return $xeTable.$nextTick()
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export default {
|
|
521
|
+
methods: {
|
|
522
|
+
/**
|
|
523
|
+
* 往表格中插入临时数据
|
|
524
|
+
*
|
|
525
|
+
* @param {*} records
|
|
526
|
+
*/
|
|
527
|
+
_insert (records: any) {
|
|
528
|
+
return handleInsertRowAt(this, records, null)
|
|
529
|
+
},
|
|
530
|
+
/**
|
|
531
|
+
* 往表格指定行中插入临时数据
|
|
532
|
+
* 如果 row 为空则从插入到顶部
|
|
533
|
+
* 如果 row 为 -1 则从插入到底部
|
|
534
|
+
* 如果 row 为有效行则插入到该行的位置
|
|
535
|
+
* @returns
|
|
536
|
+
*/
|
|
537
|
+
_insertAt (records: any, targetRowOrRowid: any) {
|
|
538
|
+
return handleInsertRowAt(this, records, targetRowOrRowid)
|
|
539
|
+
},
|
|
540
|
+
_insertNextAt (records: any, targetRowOrRowid: any) {
|
|
541
|
+
return handleInsertRowAt(this, records, targetRowOrRowid, true)
|
|
542
|
+
},
|
|
543
|
+
_insertChild (records: any, parentRowOrParentId: any) {
|
|
544
|
+
return handleInsertChildRowAt(this, records, parentRowOrParentId, null)
|
|
545
|
+
},
|
|
546
|
+
_insertChildAt (records: any, parentRowOrParentId: any, targetRowOrRowid: any) {
|
|
547
|
+
return handleInsertChildRowAt(this, records, parentRowOrParentId, targetRowOrRowid)
|
|
548
|
+
},
|
|
549
|
+
_insertChildNextAt (records: any, parentRowOrParentId: any, targetRowOrRowid: any) {
|
|
550
|
+
return handleInsertChildRowAt(this, records, parentRowOrParentId, targetRowOrRowid, true)
|
|
551
|
+
},
|
|
552
|
+
/**
|
|
553
|
+
* 删除指定行数据
|
|
554
|
+
* 如果传 row 则删除一行
|
|
555
|
+
* 如果传 rows 则删除多行
|
|
556
|
+
* 如果为空则删除所有
|
|
557
|
+
*/
|
|
558
|
+
_remove (rows: any[]) {
|
|
559
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
560
|
+
const props = $xeTable
|
|
561
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
562
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
563
|
+
|
|
564
|
+
const { treeConfig } = props
|
|
565
|
+
const { editStore, isRowGroupStatus } = reactData
|
|
566
|
+
const { tableFullTreeData, selectCheckboxMaps, afterFullData, mergeBodyList, tableFullData, pendingRowMaps, insertRowMaps, removeRowMaps } = internalData
|
|
567
|
+
const checkboxOpts = $xeTable.computeCheckboxOpts
|
|
568
|
+
const treeOpts = $xeTable.computeTreeOpts
|
|
569
|
+
const { transform, mapChildrenField } = treeOpts
|
|
570
|
+
const childrenField = treeOpts.children || treeOpts.childrenField
|
|
571
|
+
const { actived } = editStore
|
|
572
|
+
const { checkField } = checkboxOpts
|
|
573
|
+
let delList: any[] = []
|
|
574
|
+
if (!rows) {
|
|
575
|
+
rows = tableFullData
|
|
576
|
+
} else if (!XEUtils.isArray(rows)) {
|
|
577
|
+
rows = [rows]
|
|
578
|
+
}
|
|
579
|
+
// 如果是新增,则保存记录
|
|
580
|
+
rows.forEach(row => {
|
|
581
|
+
if (!$xeTable.isInsertByRow(row)) {
|
|
582
|
+
const rowid = getRowid($xeTable, row)
|
|
583
|
+
removeRowMaps[rowid] = row
|
|
584
|
+
}
|
|
585
|
+
})
|
|
586
|
+
// 如果绑定了多选属性,则更新状态
|
|
587
|
+
if (!checkField) {
|
|
588
|
+
rows.forEach((row) => {
|
|
589
|
+
const rowid = getRowid(this, row)
|
|
590
|
+
if (selectCheckboxMaps[rowid]) {
|
|
591
|
+
delete selectCheckboxMaps[rowid]
|
|
592
|
+
}
|
|
593
|
+
})
|
|
594
|
+
reactData.updateCheckboxFlag++
|
|
595
|
+
}
|
|
596
|
+
// 从数据源中移除
|
|
597
|
+
if (tableFullData === rows) {
|
|
598
|
+
rows = delList = tableFullData.slice(0)
|
|
599
|
+
internalData.tableFullData = []
|
|
600
|
+
internalData.afterFullData = []
|
|
601
|
+
$xeTable.clearMergeCells()
|
|
602
|
+
} else {
|
|
603
|
+
// 如果为虚拟树
|
|
604
|
+
if (treeConfig && transform) {
|
|
605
|
+
rows.forEach((row) => {
|
|
606
|
+
const rowid = getRowid($xeTable, row)
|
|
607
|
+
const matchMapObj = XEUtils.findTree(tableFullTreeData, item => rowid === getRowid($xeTable, item), { children: mapChildrenField })
|
|
608
|
+
if (matchMapObj) {
|
|
609
|
+
const rItems = matchMapObj.items.splice(matchMapObj.index, 1)
|
|
610
|
+
delList.push(rItems[0])
|
|
611
|
+
}
|
|
612
|
+
const matchObj = XEUtils.findTree(tableFullTreeData, item => rowid === getRowid($xeTable, item), { children: childrenField })
|
|
613
|
+
if (matchObj) {
|
|
614
|
+
matchObj.items.splice(matchObj.index, 1)
|
|
615
|
+
}
|
|
616
|
+
const afIndex = $xeTable.findRowIndexOf(afterFullData, row)
|
|
617
|
+
if (afIndex > -1) {
|
|
618
|
+
afterFullData.splice(afIndex, 1)
|
|
619
|
+
}
|
|
620
|
+
})
|
|
621
|
+
} else if (isRowGroupStatus) {
|
|
622
|
+
// 如果分组
|
|
623
|
+
warnLog(getI18n('vxe.error.noGroup', ['remove']))
|
|
624
|
+
} else {
|
|
625
|
+
rows.forEach((row) => {
|
|
626
|
+
const tfIndex = $xeTable.findRowIndexOf(tableFullData, row)
|
|
627
|
+
if (tfIndex > -1) {
|
|
628
|
+
const rItems = tableFullData.splice(tfIndex, 1)
|
|
629
|
+
delList.push(rItems[0])
|
|
630
|
+
}
|
|
631
|
+
const afIndex = $xeTable.findRowIndexOf(afterFullData, row)
|
|
632
|
+
if (afIndex > -1) {
|
|
633
|
+
// 刷新单元格合并
|
|
634
|
+
mergeBodyList.forEach((mergeItem) => {
|
|
635
|
+
const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
|
|
636
|
+
if (mergeRowIndex > afIndex) {
|
|
637
|
+
mergeItem.row = mergeRowIndex - 1
|
|
638
|
+
} else if (mergeRowIndex + mergeRowspan > afIndex) {
|
|
639
|
+
mergeItem.rowspan = mergeRowspan - 1
|
|
640
|
+
}
|
|
641
|
+
})
|
|
642
|
+
afterFullData.splice(afIndex, 1)
|
|
643
|
+
}
|
|
644
|
+
})
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
// 如果当前行被激活编辑,则清除激活状态
|
|
648
|
+
if (actived.row && $xeTable.findRowIndexOf(rows, actived.row) > -1) {
|
|
649
|
+
$xeTable.clearEdit()
|
|
650
|
+
}
|
|
651
|
+
// 从新增中移除已删除的数据
|
|
652
|
+
rows.forEach((row: any) => {
|
|
653
|
+
const rowid = getRowid($xeTable, row)
|
|
654
|
+
if (insertRowMaps[rowid]) {
|
|
655
|
+
delete insertRowMaps[rowid]
|
|
656
|
+
}
|
|
657
|
+
if (pendingRowMaps[rowid]) {
|
|
658
|
+
delete pendingRowMaps[rowid]
|
|
659
|
+
}
|
|
660
|
+
})
|
|
661
|
+
reactData.removeRowFlag++
|
|
662
|
+
reactData.insertRowFlag++
|
|
663
|
+
reactData.pendingRowFlag++
|
|
664
|
+
$xeTable.cacheRowMap(false)
|
|
665
|
+
$xeTable.handleTableData(treeConfig && transform)
|
|
666
|
+
$xeTable.updateFooter()
|
|
667
|
+
$xeTable.handleUpdateBodyMerge()
|
|
668
|
+
if (!(treeConfig && transform)) {
|
|
669
|
+
$xeTable.updateAfterDataIndex()
|
|
670
|
+
}
|
|
671
|
+
$xeTable.checkSelectionStatus()
|
|
672
|
+
if (reactData.scrollYLoad) {
|
|
673
|
+
$xeTable.updateScrollYSpace()
|
|
674
|
+
}
|
|
675
|
+
return $xeTable.$nextTick().then(() => {
|
|
676
|
+
$xeTable.updateCellAreas()
|
|
677
|
+
return $xeTable.recalculate(true)
|
|
678
|
+
}).then(() => {
|
|
679
|
+
return { row: delList.length ? delList[delList.length - 1] : null, rows: delList }
|
|
680
|
+
})
|
|
681
|
+
},
|
|
682
|
+
/**
|
|
683
|
+
* 删除复选框选中的数据
|
|
684
|
+
*/
|
|
685
|
+
_removeCheckboxRow () {
|
|
686
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
687
|
+
|
|
688
|
+
return $xeTable.remove($xeTable.getCheckboxRecords()).then((params: any) => {
|
|
689
|
+
$xeTable.clearCheckboxRow()
|
|
690
|
+
return params
|
|
691
|
+
})
|
|
692
|
+
},
|
|
693
|
+
/**
|
|
694
|
+
* 删除单选框选中的数据
|
|
695
|
+
*/
|
|
696
|
+
_removeRadioRow () {
|
|
697
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
698
|
+
|
|
699
|
+
const radioRecord = $xeTable.getRadioRecord()
|
|
700
|
+
return $xeTable.remove(radioRecord || []).then((params: any) => {
|
|
701
|
+
$xeTable.clearRadioRow()
|
|
702
|
+
return params
|
|
703
|
+
})
|
|
704
|
+
},
|
|
705
|
+
/**
|
|
706
|
+
* 删除当前行选中的数据
|
|
707
|
+
*/
|
|
708
|
+
_removeCurrentRow () {
|
|
709
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
710
|
+
|
|
711
|
+
const currentRecord = $xeTable.getCurrentRecord()
|
|
712
|
+
return $xeTable.remove(currentRecord || []).then((params: any) => {
|
|
713
|
+
$xeTable.clearCurrentRow()
|
|
714
|
+
return params
|
|
715
|
+
})
|
|
716
|
+
},
|
|
717
|
+
/**
|
|
718
|
+
* 获取表格数据集,包含新增、删除、修改
|
|
719
|
+
*/
|
|
720
|
+
_getRecordset () {
|
|
721
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
722
|
+
|
|
723
|
+
const removeRecords = $xeTable.getRemoveRecords()
|
|
724
|
+
const pendingRecords = $xeTable.getPendingRecords()
|
|
725
|
+
const delRecords = removeRecords.concat(pendingRecords)
|
|
726
|
+
// 如果已经被删除,则无需放到更新数组
|
|
727
|
+
const updateRecords = $xeTable.getUpdateRecords().filter((row: any) => {
|
|
728
|
+
return !delRecords.some((item) => $xeTable.eqRow(item, row))
|
|
729
|
+
})
|
|
730
|
+
return {
|
|
731
|
+
insertRecords: $xeTable.getInsertRecords(),
|
|
732
|
+
removeRecords,
|
|
733
|
+
updateRecords,
|
|
734
|
+
pendingRecords
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
/**
|
|
738
|
+
* 获取新增的临时数据
|
|
739
|
+
*/
|
|
740
|
+
_getInsertRecords () {
|
|
741
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
742
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
743
|
+
|
|
744
|
+
const { fullAllDataRowIdData, insertRowMaps } = internalData
|
|
745
|
+
const insertRecords: any[] = []
|
|
746
|
+
XEUtils.each(insertRowMaps, (row, rowid) => {
|
|
747
|
+
if (fullAllDataRowIdData[rowid]) {
|
|
748
|
+
insertRecords.push(row)
|
|
749
|
+
}
|
|
750
|
+
})
|
|
751
|
+
return insertRecords
|
|
752
|
+
},
|
|
753
|
+
/**
|
|
754
|
+
* 获取已删除的数据
|
|
755
|
+
*/
|
|
756
|
+
_getRemoveRecords () {
|
|
757
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
758
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
759
|
+
|
|
760
|
+
const { removeRowMaps } = internalData
|
|
761
|
+
const removeRecords: any[] = []
|
|
762
|
+
XEUtils.each(removeRowMaps, (row) => {
|
|
763
|
+
removeRecords.push(row)
|
|
764
|
+
})
|
|
765
|
+
return removeRecords
|
|
766
|
+
},
|
|
767
|
+
/**
|
|
768
|
+
* 获取更新数据
|
|
769
|
+
* 只精准匹配 row 的更改
|
|
770
|
+
* 如果是树表格,子节点更改状态不会影响父节点的更新状态
|
|
771
|
+
*/
|
|
772
|
+
_getUpdateRecords () {
|
|
773
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
774
|
+
const props = $xeTable
|
|
775
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
776
|
+
|
|
777
|
+
const { keepSource, treeConfig } = props
|
|
778
|
+
const { tableFullData } = internalData
|
|
779
|
+
const treeOpts = $xeTable.computeTreeOpts
|
|
780
|
+
if (keepSource) {
|
|
781
|
+
syncActivedCell($xeTable)
|
|
782
|
+
if (treeConfig) {
|
|
783
|
+
return XEUtils.filterTree(tableFullData, row => $xeTable.isUpdateByRow(row), treeOpts)
|
|
784
|
+
}
|
|
785
|
+
return tableFullData.filter((row) => $xeTable.isUpdateByRow(row))
|
|
786
|
+
}
|
|
787
|
+
return []
|
|
788
|
+
},
|
|
789
|
+
/**
|
|
790
|
+
* 处理激活编辑
|
|
791
|
+
*/
|
|
792
|
+
handleEdit (params: any, evnt: any) {
|
|
793
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
794
|
+
|
|
795
|
+
return handleEditActive($xeTable, params, evnt, true, true)
|
|
796
|
+
},
|
|
797
|
+
/**
|
|
798
|
+
* @deprecated
|
|
799
|
+
*/
|
|
800
|
+
handleActived (params: any, evnt: any) {
|
|
801
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
802
|
+
|
|
803
|
+
return $xeTable.handleEdit(params, evnt)
|
|
804
|
+
},
|
|
805
|
+
_getColumnModel (row: any, column: VxeTableDefines.ColumnInfo) {
|
|
806
|
+
getEditColumnModel(row, column)
|
|
807
|
+
},
|
|
808
|
+
_setColumnModel (row: any, column: VxeTableDefines.ColumnInfo) {
|
|
809
|
+
setEditColumnModel(row, column)
|
|
810
|
+
},
|
|
811
|
+
_syncActivedCell () {
|
|
812
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
813
|
+
|
|
814
|
+
syncActivedCell($xeTable)
|
|
815
|
+
},
|
|
816
|
+
_clearActived (row: any) {
|
|
817
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
818
|
+
|
|
819
|
+
warnLog('vxe.error.delFunc', ['clearActived', 'clearEdit'])
|
|
820
|
+
// 即将废弃
|
|
821
|
+
return $xeTable.clearEdit(row)
|
|
822
|
+
},
|
|
823
|
+
/**
|
|
824
|
+
* 清除激活的编辑
|
|
825
|
+
*/
|
|
826
|
+
_clearEdit (row: any) {
|
|
827
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
828
|
+
|
|
829
|
+
return handleClearEdit($xeTable, null, row)
|
|
830
|
+
},
|
|
831
|
+
/**
|
|
832
|
+
* 取消编辑
|
|
833
|
+
*/
|
|
834
|
+
handleClearEdit (evnt: Event | null, targetRow?: any) {
|
|
835
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
836
|
+
|
|
837
|
+
return handleClearEdit($xeTable, evnt, targetRow)
|
|
838
|
+
},
|
|
839
|
+
_getActiveRecord () {
|
|
840
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
841
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
842
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
843
|
+
|
|
844
|
+
warnLog('vxe.error.delFunc', ['getActiveRecord', 'getEditCell'])
|
|
845
|
+
const { editStore } = reactData
|
|
846
|
+
const { fullAllDataRowIdData } = internalData
|
|
847
|
+
const { args, row } = editStore.actived
|
|
848
|
+
if (args && row && fullAllDataRowIdData[getRowid($xeTable, row)]) {
|
|
849
|
+
return Object.assign({}, args, { row })
|
|
850
|
+
}
|
|
851
|
+
return null
|
|
852
|
+
},
|
|
853
|
+
_getEditRecord () {
|
|
854
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
855
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
856
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
857
|
+
|
|
858
|
+
warnLog('vxe.error.delFunc', ['getEditRecord', 'getEditCell'])
|
|
859
|
+
const { editStore } = reactData
|
|
860
|
+
const { fullAllDataRowIdData } = internalData
|
|
861
|
+
const { args, row } = editStore.actived
|
|
862
|
+
if (args && row && fullAllDataRowIdData[getRowid($xeTable, row)]) {
|
|
863
|
+
return Object.assign({}, args, { row })
|
|
864
|
+
}
|
|
865
|
+
return null
|
|
866
|
+
},
|
|
867
|
+
_getEditCell () {
|
|
868
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
869
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
870
|
+
|
|
871
|
+
const { editStore } = reactData
|
|
872
|
+
const { row, column } = editStore.actived
|
|
873
|
+
if (column && row) {
|
|
874
|
+
return {
|
|
875
|
+
row,
|
|
876
|
+
rowIndex: $xeTable.getRowIndex(row),
|
|
877
|
+
column,
|
|
878
|
+
columnIndex: $xeTable.getColumnIndex(column)
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
return null
|
|
882
|
+
},
|
|
883
|
+
_isActiveByRow (row: any) {
|
|
884
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
885
|
+
|
|
886
|
+
warnLog('vxe.error.delFunc', ['isActiveByRow', 'isEditByRow'])
|
|
887
|
+
// 即将废弃
|
|
888
|
+
return $xeTable.isEditByRow(row)
|
|
889
|
+
},
|
|
890
|
+
/**
|
|
891
|
+
* 判断行是否为激活编辑状态
|
|
892
|
+
* @param {Row} row 行对象
|
|
893
|
+
*/
|
|
894
|
+
_isEditByRow (row: any) {
|
|
895
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
896
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
897
|
+
|
|
898
|
+
const { editStore } = reactData
|
|
899
|
+
return editStore.actived.row === row
|
|
900
|
+
},
|
|
901
|
+
/**
|
|
902
|
+
* 处理聚焦
|
|
903
|
+
*/
|
|
904
|
+
handleFocus (params: any) {
|
|
905
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
906
|
+
|
|
907
|
+
const { row, column, cell } = params
|
|
908
|
+
const { editRender } = column
|
|
909
|
+
const editOpts = $xeTable.computeEditOpts
|
|
910
|
+
if (isEnableConf(editRender)) {
|
|
911
|
+
const compRender = renderer.get(editRender.name)
|
|
912
|
+
let autoFocus = editRender.autofocus || editRender.autoFocus
|
|
913
|
+
let autoSelect = editRender.autoSelect || editRender.autoselect
|
|
914
|
+
let inputElem
|
|
915
|
+
// 是否启用聚焦
|
|
916
|
+
if (editOpts.autoFocus) {
|
|
917
|
+
if (!autoFocus && compRender) {
|
|
918
|
+
autoFocus = compRender.tableAutoFocus || compRender.tableAutofocus || (compRender as any).autoFocus || compRender.autofocus
|
|
919
|
+
}
|
|
920
|
+
if (!autoSelect && compRender) {
|
|
921
|
+
autoSelect = compRender.tableAutoSelect || (compRender as any).autoSelect || compRender.autoselect
|
|
922
|
+
}
|
|
923
|
+
// 如果指定了聚焦 class
|
|
924
|
+
if (XEUtils.isFunction(autoFocus)) {
|
|
925
|
+
inputElem = autoFocus.call($xeTable, params)
|
|
926
|
+
} else if (autoFocus) {
|
|
927
|
+
if (autoFocus === true) {
|
|
928
|
+
// 自动匹配模式,会自动匹配第一个可输入元素
|
|
929
|
+
inputElem = cell.querySelector('input,textarea')
|
|
930
|
+
} else {
|
|
931
|
+
inputElem = cell.querySelector(autoFocus)
|
|
932
|
+
}
|
|
933
|
+
if (inputElem) {
|
|
934
|
+
inputElem.focus()
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
if (inputElem) {
|
|
939
|
+
if (autoSelect) {
|
|
940
|
+
inputElem.select()
|
|
941
|
+
} else {
|
|
942
|
+
// 保持一致行为,光标移到末端
|
|
943
|
+
if (browseObj.msie) {
|
|
944
|
+
const textRange = inputElem.createTextRange()
|
|
945
|
+
textRange.collapse(false)
|
|
946
|
+
textRange.select()
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
} else {
|
|
950
|
+
// 是否自动定位
|
|
951
|
+
if (editOpts.autoPos) {
|
|
952
|
+
if (!column.fixed) {
|
|
953
|
+
// 显示到可视区中
|
|
954
|
+
$xeTable.scrollToRow(row, column)
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
},
|
|
960
|
+
_setActiveRow (row: any) {
|
|
961
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
962
|
+
|
|
963
|
+
warnLog('vxe.error.delFunc', ['setActiveRow', 'setEditRow'])
|
|
964
|
+
// 即将废弃
|
|
965
|
+
return $xeTable.setEditRow(row)
|
|
966
|
+
},
|
|
967
|
+
/**
|
|
968
|
+
* 激活行编辑
|
|
969
|
+
*/
|
|
970
|
+
_setEditRow (row: any, fieldOrColumn: any) {
|
|
971
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
972
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
973
|
+
|
|
974
|
+
const { visibleColumn } = internalData
|
|
975
|
+
let column: any = XEUtils.find(visibleColumn, column => isEnableConf(column.editRender))
|
|
976
|
+
let isPos = false
|
|
977
|
+
if (fieldOrColumn) {
|
|
978
|
+
isPos = true
|
|
979
|
+
if (fieldOrColumn !== true) {
|
|
980
|
+
column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
return handleEditCell($xeTable, row, column, isPos)
|
|
984
|
+
},
|
|
985
|
+
_setActiveCell (row: any, fieldOrColumn: any) {
|
|
986
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
987
|
+
|
|
988
|
+
warnLog('vxe.error.delFunc', ['setActiveCell', 'setEditCell'])
|
|
989
|
+
// 即将废弃
|
|
990
|
+
return $xeTable.setEditCell(row, fieldOrColumn)
|
|
991
|
+
},
|
|
992
|
+
/**
|
|
993
|
+
* 激活单元格编辑
|
|
994
|
+
*/
|
|
995
|
+
_setEditCell (row: any, fieldOrColumn: any) {
|
|
996
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
997
|
+
|
|
998
|
+
return handleEditCell($xeTable, row, fieldOrColumn, true)
|
|
999
|
+
},
|
|
1000
|
+
/**
|
|
1001
|
+
* 只对 trigger=dblclick 有效,选中单元格
|
|
1002
|
+
*/
|
|
1003
|
+
_setSelectCell (row: any, fieldOrColumn: string | VxeTableDefines.ColumnInfo) {
|
|
1004
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1005
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
1006
|
+
|
|
1007
|
+
const { tableData } = reactData
|
|
1008
|
+
const editOpts = $xeTable.computeEditOpts
|
|
1009
|
+
const column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
|
|
1010
|
+
if (row && column && editOpts.trigger !== 'manual') {
|
|
1011
|
+
const rowIndex = $xeTable.findRowIndexOf(tableData, row)
|
|
1012
|
+
if (rowIndex > -1) {
|
|
1013
|
+
const cell = $xeTable.getCellElement(row, column)
|
|
1014
|
+
const params = {
|
|
1015
|
+
row,
|
|
1016
|
+
rowIndex,
|
|
1017
|
+
column,
|
|
1018
|
+
columnIndex: $xeTable.getColumnIndex(column),
|
|
1019
|
+
cell
|
|
1020
|
+
}
|
|
1021
|
+
$xeTable.handleSelected(params, {})
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return $xeTable.$nextTick()
|
|
1025
|
+
},
|
|
1026
|
+
/**
|
|
1027
|
+
* 处理选中源
|
|
1028
|
+
*/
|
|
1029
|
+
handleSelected (params: any, evnt: any) {
|
|
1030
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1031
|
+
const props = $xeTable
|
|
1032
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
1033
|
+
|
|
1034
|
+
const { mouseConfig } = props
|
|
1035
|
+
const { editStore } = reactData
|
|
1036
|
+
const mouseOpts = $xeTable.computeMouseOpts
|
|
1037
|
+
const editOpts = $xeTable.computeEditOpts
|
|
1038
|
+
const { actived, selected } = editStore
|
|
1039
|
+
const { row, column } = params
|
|
1040
|
+
const isMouseSelected = mouseConfig && mouseOpts.selected
|
|
1041
|
+
const selectMethod = () => {
|
|
1042
|
+
if (isMouseSelected && (selected.row !== row || selected.column !== column)) {
|
|
1043
|
+
if (actived.row !== row || (editOpts.mode === 'cell' ? actived.column !== column : false)) {
|
|
1044
|
+
handleClearEdit($xeTable, evnt)
|
|
1045
|
+
$xeTable.clearSelected()
|
|
1046
|
+
if ($xeTable.clearCellAreas) {
|
|
1047
|
+
$xeTable.clearCellAreas()
|
|
1048
|
+
$xeTable.clearCopyCellArea()
|
|
1049
|
+
}
|
|
1050
|
+
selected.args = params
|
|
1051
|
+
selected.row = row
|
|
1052
|
+
selected.column = column
|
|
1053
|
+
if (isMouseSelected) {
|
|
1054
|
+
$xeTable.addCellSelectedClass()
|
|
1055
|
+
}
|
|
1056
|
+
$xeTable.focus()
|
|
1057
|
+
if (evnt) {
|
|
1058
|
+
$xeTable.dispatchEvent('cell-selected', params, evnt)
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
return $xeTable.$nextTick()
|
|
1063
|
+
}
|
|
1064
|
+
return selectMethod()
|
|
1065
|
+
},
|
|
1066
|
+
/**
|
|
1067
|
+
* 获取选中的单元格
|
|
1068
|
+
*/
|
|
1069
|
+
_getSelectedCell () {
|
|
1070
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1071
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
1072
|
+
|
|
1073
|
+
const { editStore } = reactData
|
|
1074
|
+
const { row, column } = editStore.selected
|
|
1075
|
+
if (row && column) {
|
|
1076
|
+
return {
|
|
1077
|
+
row,
|
|
1078
|
+
column
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return null
|
|
1082
|
+
},
|
|
1083
|
+
/**
|
|
1084
|
+
* 清除所选中源状态
|
|
1085
|
+
*/
|
|
1086
|
+
_clearSelected () {
|
|
1087
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1088
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
1089
|
+
|
|
1090
|
+
const { editStore } = reactData
|
|
1091
|
+
const { selected } = editStore
|
|
1092
|
+
selected.row = null
|
|
1093
|
+
selected.column = null
|
|
1094
|
+
removeCellSelectedClass($xeTable)
|
|
1095
|
+
return $xeTable.$nextTick()
|
|
1096
|
+
},
|
|
1097
|
+
reColTitleSdCls () {
|
|
1098
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1099
|
+
const internalData = $xeTable as unknown as TableInternalData
|
|
1100
|
+
|
|
1101
|
+
const { elemStore } = internalData
|
|
1102
|
+
const headerElem = elemStore['main-header-list']
|
|
1103
|
+
if (headerElem) {
|
|
1104
|
+
XEUtils.arrayEach(headerElem.querySelectorAll('.col--title-selected'), elem => removeClass(elem, 'col--title-selected'))
|
|
1105
|
+
}
|
|
1106
|
+
},
|
|
1107
|
+
addCellSelectedClass () {
|
|
1108
|
+
const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
|
|
1109
|
+
const reactData = $xeTable as unknown as TableReactData
|
|
1110
|
+
|
|
1111
|
+
const { editStore } = reactData
|
|
1112
|
+
const { selected } = editStore
|
|
1113
|
+
const { row, column } = selected
|
|
1114
|
+
removeCellSelectedClass($xeTable)
|
|
1115
|
+
if (row && column) {
|
|
1116
|
+
const cell = $xeTable.getCellElement(row, column)
|
|
1117
|
+
if (cell) {
|
|
1118
|
+
addClass(cell, 'col--selected')
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
} as any
|
|
1123
|
+
} as any
|