resolver-egretimp-plus 0.1.30 → 0.1.32
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/dist/h5/index.js +18 -18
- package/dist/theme/element/index.css +1 -1
- package/dist/theme/element/src/components/form.scss +2 -0
- package/dist/web/index.js +128 -128
- package/dist/web/index.js.LICENSE.txt +15 -0
- package/package.json +5 -1
- package/scripts/webpack.config.js +18 -2
- package/src/components/packages-web/CustomComponentTable.jsx +8 -5
- package/src/components/table/index.ts +29 -0
- package/src/components/table/src/composables/use-scrollbar.ts +30 -0
- package/src/components/table/src/config.ts +256 -0
- package/src/components/table/src/filter-panel.vue +260 -0
- package/src/components/table/src/h-helper.ts +34 -0
- package/src/components/table/src/layout-observer.ts +78 -0
- package/src/components/table/src/store/current.ts +85 -0
- package/src/components/table/src/store/expand.ts +76 -0
- package/src/components/table/src/store/helper.ts +74 -0
- package/src/components/table/src/store/index.ts +246 -0
- package/src/components/table/src/store/tree.ts +230 -0
- package/src/components/table/src/store/watcher.ts +543 -0
- package/src/components/table/src/table/defaults.ts +402 -0
- package/src/components/table/src/table/key-render-helper.ts +27 -0
- package/src/components/table/src/table/style-helper.ts +378 -0
- package/src/components/table/src/table/utils-helper.ts +47 -0
- package/src/components/table/src/table-body/defaults.ts +52 -0
- package/src/components/table/src/table-body/events-helper.ts +203 -0
- package/src/components/table/src/table-body/index.ts +119 -0
- package/src/components/table/src/table-body/render-helper.ts +283 -0
- package/src/components/table/src/table-body/styles-helper.ts +164 -0
- package/src/components/table/src/table-column/defaults.ts +237 -0
- package/src/components/table/src/table-column/index.ts +202 -0
- package/src/components/table/src/table-column/render-helper.ts +214 -0
- package/src/components/table/src/table-column/watcher-helper.ts +88 -0
- package/src/components/table/src/table-footer/index.ts +128 -0
- package/src/components/table/src/table-footer/mapState-helper.ts +33 -0
- package/src/components/table/src/table-footer/style-helper.ts +51 -0
- package/src/components/table/src/table-header/event-helper.ts +213 -0
- package/src/components/table/src/table-header/index.ts +244 -0
- package/src/components/table/src/table-header/style.helper.ts +119 -0
- package/src/components/table/src/table-header/utils-helper.ts +94 -0
- package/src/components/table/src/table-layout.ts +259 -0
- package/src/components/table/src/table.vue +389 -0
- package/src/components/table/src/tableColumn.ts +3 -0
- package/src/components/table/src/tokens.ts +5 -0
- package/src/components/table/src/util.ts +521 -0
- package/src/components/table/style/css.ts +5 -0
- package/src/components/table/style/index.ts +5 -0
- package/src/theme/element/components/form.scss +2 -0
- package/tsconfig.json +19 -0
- package/vue-shims.d.ts +4 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { h } from 'vue'
|
|
3
|
+
export function hColgroup(props) {
|
|
4
|
+
const isAuto = props.tableLayout === 'auto'
|
|
5
|
+
let columns = props.columns || []
|
|
6
|
+
if (isAuto) {
|
|
7
|
+
if (columns.every((column) => column.width === undefined)) {
|
|
8
|
+
columns = []
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const getPropsData = (column) => {
|
|
12
|
+
const propsData = {
|
|
13
|
+
key: `${props.tableLayout}_${column.id}`,
|
|
14
|
+
style: {},
|
|
15
|
+
name: undefined,
|
|
16
|
+
}
|
|
17
|
+
if (isAuto) {
|
|
18
|
+
propsData.style = {
|
|
19
|
+
width: `${column.width}px`,
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
propsData.name = column.id
|
|
23
|
+
}
|
|
24
|
+
return propsData
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return h(
|
|
28
|
+
'colgroup',
|
|
29
|
+
{},
|
|
30
|
+
columns.map((column) => h('col', getPropsData(column)))
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
hColgroup.props = ['columns', 'tableLayout']
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
getCurrentInstance,
|
|
5
|
+
onBeforeMount,
|
|
6
|
+
onMounted,
|
|
7
|
+
onUnmounted,
|
|
8
|
+
onUpdated,
|
|
9
|
+
} from 'vue'
|
|
10
|
+
|
|
11
|
+
import type { TableHeader } from './table-header'
|
|
12
|
+
import type TableLayout from './table-layout'
|
|
13
|
+
import type { Table } from './table/defaults'
|
|
14
|
+
|
|
15
|
+
function useLayoutObserver<T>(root: Table<T>) {
|
|
16
|
+
const instance = getCurrentInstance() as TableHeader
|
|
17
|
+
onBeforeMount(() => {
|
|
18
|
+
tableLayout.value.addObserver(instance)
|
|
19
|
+
})
|
|
20
|
+
onMounted(() => {
|
|
21
|
+
onColumnsChange(tableLayout.value)
|
|
22
|
+
onScrollableChange(tableLayout.value)
|
|
23
|
+
})
|
|
24
|
+
onUpdated(() => {
|
|
25
|
+
onColumnsChange(tableLayout.value)
|
|
26
|
+
onScrollableChange(tableLayout.value)
|
|
27
|
+
})
|
|
28
|
+
onUnmounted(() => {
|
|
29
|
+
tableLayout.value.removeObserver(instance)
|
|
30
|
+
})
|
|
31
|
+
const tableLayout = computed(() => {
|
|
32
|
+
const layout = root.layout as TableLayout<T>
|
|
33
|
+
if (!layout) {
|
|
34
|
+
throw new Error('Can not find table layout.')
|
|
35
|
+
}
|
|
36
|
+
return layout
|
|
37
|
+
})
|
|
38
|
+
const onColumnsChange = (layout: TableLayout<T>) => {
|
|
39
|
+
const cols = root.vnode.el?.querySelectorAll('colgroup > col') || []
|
|
40
|
+
if (!cols.length) return
|
|
41
|
+
const flattenColumns = layout.getFlattenColumns()
|
|
42
|
+
const columnsMap = {}
|
|
43
|
+
flattenColumns.forEach((column) => {
|
|
44
|
+
columnsMap[column.id] = column
|
|
45
|
+
})
|
|
46
|
+
for (let i = 0, j = cols.length; i < j; i++) {
|
|
47
|
+
const col = cols[i]
|
|
48
|
+
const name = col.getAttribute('name')
|
|
49
|
+
const column = columnsMap[name]
|
|
50
|
+
if (column) {
|
|
51
|
+
col.setAttribute('width', column.realWidth || column.width)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const onScrollableChange = (layout: TableLayout<T>) => {
|
|
57
|
+
const cols =
|
|
58
|
+
root.vnode.el?.querySelectorAll('colgroup > col[name=gutter]') || []
|
|
59
|
+
for (let i = 0, j = cols.length; i < j; i++) {
|
|
60
|
+
const col = cols[i]
|
|
61
|
+
col.setAttribute('width', layout.scrollY.value ? layout.gutterWidth : '0')
|
|
62
|
+
}
|
|
63
|
+
const ths = root.vnode.el?.querySelectorAll('th.gutter') || []
|
|
64
|
+
for (let i = 0, j = ths.length; i < j; i++) {
|
|
65
|
+
const th = ths[i]
|
|
66
|
+
th.style.width = layout.scrollY.value ? `${layout.gutterWidth}px` : '0'
|
|
67
|
+
th.style.display = layout.scrollY.value ? '' : 'none'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
tableLayout: tableLayout.value,
|
|
73
|
+
onColumnsChange,
|
|
74
|
+
onScrollableChange,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default useLayoutObserver
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { getCurrentInstance, ref, unref } from 'vue'
|
|
3
|
+
import { getRowIdentity } from '../util'
|
|
4
|
+
|
|
5
|
+
import type { Ref } from 'vue'
|
|
6
|
+
import type { Table } from '../table/defaults'
|
|
7
|
+
import type { WatcherPropsData } from '.'
|
|
8
|
+
|
|
9
|
+
function useCurrent<T>(watcherData: WatcherPropsData<T>) {
|
|
10
|
+
const instance = getCurrentInstance() as Table<T>
|
|
11
|
+
const _currentRowKey = ref<string>(null)
|
|
12
|
+
const currentRow: Ref<T> = ref(null)
|
|
13
|
+
|
|
14
|
+
const setCurrentRowKey = (key: string) => {
|
|
15
|
+
instance.store.assertRowKey()
|
|
16
|
+
_currentRowKey.value = key
|
|
17
|
+
setCurrentRowByKey(key)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const restoreCurrentRowKey = () => {
|
|
21
|
+
_currentRowKey.value = null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const setCurrentRowByKey = (key: string) => {
|
|
25
|
+
const { data, rowKey } = watcherData
|
|
26
|
+
let _currentRow = null
|
|
27
|
+
if (rowKey.value) {
|
|
28
|
+
_currentRow = (unref(data) || []).find(
|
|
29
|
+
(item) => getRowIdentity(item, rowKey.value) === key
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
currentRow.value = _currentRow
|
|
33
|
+
instance.emit('current-change', currentRow.value, null)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const updateCurrentRow = (_currentRow: T) => {
|
|
37
|
+
const oldCurrentRow = currentRow.value
|
|
38
|
+
if (_currentRow && _currentRow !== oldCurrentRow) {
|
|
39
|
+
currentRow.value = _currentRow
|
|
40
|
+
instance.emit('current-change', currentRow.value, oldCurrentRow)
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
if (!_currentRow && oldCurrentRow) {
|
|
44
|
+
currentRow.value = null
|
|
45
|
+
instance.emit('current-change', null, oldCurrentRow)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const updateCurrentRowData = () => {
|
|
50
|
+
const rowKey = watcherData.rowKey.value
|
|
51
|
+
// data 为 null 时,解构时的默认值会被忽略
|
|
52
|
+
const data = watcherData.data.value || []
|
|
53
|
+
const oldCurrentRow = currentRow.value
|
|
54
|
+
// 当 currentRow 不在 data 中时尝试更新数据
|
|
55
|
+
if (!data.includes(oldCurrentRow) && oldCurrentRow) {
|
|
56
|
+
if (rowKey) {
|
|
57
|
+
const currentRowKey = getRowIdentity(oldCurrentRow, rowKey)
|
|
58
|
+
setCurrentRowByKey(currentRowKey)
|
|
59
|
+
} else {
|
|
60
|
+
currentRow.value = null
|
|
61
|
+
}
|
|
62
|
+
if (currentRow.value === null) {
|
|
63
|
+
instance.emit('current-change', null, oldCurrentRow)
|
|
64
|
+
}
|
|
65
|
+
} else if (_currentRowKey.value) {
|
|
66
|
+
// 把初始时下设置的 rowKey 转化成 rowData
|
|
67
|
+
setCurrentRowByKey(_currentRowKey.value)
|
|
68
|
+
restoreCurrentRowKey()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
setCurrentRowKey,
|
|
74
|
+
restoreCurrentRowKey,
|
|
75
|
+
setCurrentRowByKey,
|
|
76
|
+
updateCurrentRow,
|
|
77
|
+
updateCurrentRowData,
|
|
78
|
+
states: {
|
|
79
|
+
_currentRowKey,
|
|
80
|
+
currentRow,
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default useCurrent
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { getCurrentInstance, ref } from 'vue'
|
|
3
|
+
import { getKeysMap, getRowIdentity, toggleRowStatus } from '../util'
|
|
4
|
+
|
|
5
|
+
import type { Ref } from 'vue'
|
|
6
|
+
import type { WatcherPropsData } from '.'
|
|
7
|
+
import type { Table } from '../table/defaults'
|
|
8
|
+
|
|
9
|
+
function useExpand<T>(watcherData: WatcherPropsData<T>) {
|
|
10
|
+
const instance = getCurrentInstance() as Table<T>
|
|
11
|
+
const defaultExpandAll = ref(false)
|
|
12
|
+
const expandRows: Ref<T[]> = ref([])
|
|
13
|
+
const updateExpandRows = () => {
|
|
14
|
+
const data = watcherData.data.value || []
|
|
15
|
+
const rowKey = watcherData.rowKey.value
|
|
16
|
+
if (defaultExpandAll.value) {
|
|
17
|
+
expandRows.value = data.slice()
|
|
18
|
+
} else if (rowKey) {
|
|
19
|
+
// TODO:这里的代码可以优化
|
|
20
|
+
const expandRowsMap = getKeysMap(expandRows.value, rowKey)
|
|
21
|
+
expandRows.value = data.reduce((prev: T[], row: T) => {
|
|
22
|
+
const rowId = getRowIdentity(row, rowKey)
|
|
23
|
+
const rowInfo = expandRowsMap[rowId]
|
|
24
|
+
if (rowInfo) {
|
|
25
|
+
prev.push(row)
|
|
26
|
+
}
|
|
27
|
+
return prev
|
|
28
|
+
}, [])
|
|
29
|
+
} else {
|
|
30
|
+
expandRows.value = []
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const toggleRowExpansion = (row: T, expanded?: boolean) => {
|
|
35
|
+
const changed = toggleRowStatus(expandRows.value, row, expanded)
|
|
36
|
+
if (changed) {
|
|
37
|
+
instance.emit('expand-change', row, expandRows.value.slice())
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const setExpandRowKeys = (rowKeys: string[]) => {
|
|
42
|
+
instance.store.assertRowKey()
|
|
43
|
+
// TODO:这里的代码可以优化
|
|
44
|
+
const data = watcherData.data.value || []
|
|
45
|
+
const rowKey = watcherData.rowKey.value
|
|
46
|
+
const keysMap = getKeysMap(data, rowKey)
|
|
47
|
+
expandRows.value = rowKeys.reduce((prev: T[], cur: string) => {
|
|
48
|
+
const info = keysMap[cur]
|
|
49
|
+
if (info) {
|
|
50
|
+
prev.push(info.row)
|
|
51
|
+
}
|
|
52
|
+
return prev
|
|
53
|
+
}, [])
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const isRowExpanded = (row: T): boolean => {
|
|
57
|
+
const rowKey = watcherData.rowKey.value
|
|
58
|
+
if (rowKey) {
|
|
59
|
+
const expandMap = getKeysMap(expandRows.value, rowKey)
|
|
60
|
+
return !!expandMap[getRowIdentity(row, rowKey)]
|
|
61
|
+
}
|
|
62
|
+
return expandRows.value.includes(row)
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
updateExpandRows,
|
|
66
|
+
toggleRowExpansion,
|
|
67
|
+
setExpandRowKeys,
|
|
68
|
+
isRowExpanded,
|
|
69
|
+
states: {
|
|
70
|
+
expandRows,
|
|
71
|
+
defaultExpandAll,
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default useExpand
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { watch } from 'vue'
|
|
3
|
+
import { debounce } from 'lodash-unified'
|
|
4
|
+
import useStore from '.'
|
|
5
|
+
|
|
6
|
+
import type { Store } from '.'
|
|
7
|
+
import type { Table, TableProps } from '../table/defaults'
|
|
8
|
+
|
|
9
|
+
const InitialStateMap = {
|
|
10
|
+
rowKey: 'rowKey',
|
|
11
|
+
defaultExpandAll: 'defaultExpandAll',
|
|
12
|
+
selectOnIndeterminate: 'selectOnIndeterminate',
|
|
13
|
+
indent: 'indent',
|
|
14
|
+
lazy: 'lazy',
|
|
15
|
+
data: 'data',
|
|
16
|
+
['treeProps.hasChildren']: {
|
|
17
|
+
key: 'lazyColumnIdentifier',
|
|
18
|
+
default: 'hasChildren',
|
|
19
|
+
},
|
|
20
|
+
['treeProps.children']: {
|
|
21
|
+
key: 'childrenColumnName',
|
|
22
|
+
default: 'children',
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createStore<T>(table: Table<T>, props: TableProps<T>) {
|
|
27
|
+
if (!table) {
|
|
28
|
+
throw new Error('Table is required.')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const store = useStore<T>()
|
|
32
|
+
// fix https://github.com/ElemeFE/element/issues/14075
|
|
33
|
+
// related pr https://github.com/ElemeFE/element/pull/14146
|
|
34
|
+
store.toggleAllSelection = debounce(store._toggleAllSelection, 10)
|
|
35
|
+
Object.keys(InitialStateMap).forEach((key) => {
|
|
36
|
+
handleValue(getArrKeysValue(props, key), key, store)
|
|
37
|
+
})
|
|
38
|
+
proxyTableProps(store, props)
|
|
39
|
+
return store
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function proxyTableProps<T>(store: Store<T>, props: TableProps<T>) {
|
|
43
|
+
Object.keys(InitialStateMap).forEach((key) => {
|
|
44
|
+
watch(
|
|
45
|
+
() => getArrKeysValue(props, key),
|
|
46
|
+
(value) => {
|
|
47
|
+
handleValue(value, key, store)
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function handleValue<T>(value, propsKey: string, store: Store<T>) {
|
|
54
|
+
let newVal = value
|
|
55
|
+
let storeKey = InitialStateMap[propsKey]
|
|
56
|
+
if (typeof InitialStateMap[propsKey] === 'object') {
|
|
57
|
+
storeKey = storeKey.key
|
|
58
|
+
newVal = newVal || InitialStateMap[propsKey].default
|
|
59
|
+
}
|
|
60
|
+
store.states[storeKey].value = newVal
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function getArrKeysValue<T>(props: TableProps<T>, keys: string) {
|
|
64
|
+
if (keys.includes('.')) {
|
|
65
|
+
const keyList = keys.split('.')
|
|
66
|
+
let value = props
|
|
67
|
+
keyList.forEach((key) => {
|
|
68
|
+
value = value[key]
|
|
69
|
+
})
|
|
70
|
+
return value
|
|
71
|
+
} else {
|
|
72
|
+
return props[keys]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { getCurrentInstance, nextTick, unref } from 'vue'
|
|
3
|
+
import { useNamespace } from 'element-plus/es/hooks/index.mjs'
|
|
4
|
+
import useWatcher from './watcher'
|
|
5
|
+
|
|
6
|
+
import type { Ref } from 'vue'
|
|
7
|
+
import type { TableColumnCtx } from '../table-column/defaults'
|
|
8
|
+
import type { Filter, Sort, Table } from '../table/defaults'
|
|
9
|
+
|
|
10
|
+
interface WatcherPropsData<T> {
|
|
11
|
+
data: Ref<T[]>
|
|
12
|
+
rowKey: Ref<string>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function replaceColumn<T>(
|
|
16
|
+
array: TableColumnCtx<T>[],
|
|
17
|
+
column: TableColumnCtx<T>
|
|
18
|
+
) {
|
|
19
|
+
return array.map((item) => {
|
|
20
|
+
if (item.id === column.id) {
|
|
21
|
+
return column
|
|
22
|
+
} else if (item.children?.length) {
|
|
23
|
+
item.children = replaceColumn(item.children, column)
|
|
24
|
+
}
|
|
25
|
+
return item
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function sortColumn<T>(array: TableColumnCtx<T>[]) {
|
|
30
|
+
array.forEach((item) => {
|
|
31
|
+
item.no = item.getColumnIndex?.()
|
|
32
|
+
if (item.children?.length) {
|
|
33
|
+
sortColumn(item.children)
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
array.sort((cur, pre) => cur.no - pre.no)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function useStore<T>() {
|
|
40
|
+
const instance = getCurrentInstance() as Table<T>
|
|
41
|
+
const watcher = useWatcher<T>()
|
|
42
|
+
const ns = useNamespace('table')
|
|
43
|
+
type StoreStates = typeof watcher.states
|
|
44
|
+
const mutations = {
|
|
45
|
+
setData(states: StoreStates, data: T[]) {
|
|
46
|
+
const dataInstanceChanged = unref(states._data) !== data
|
|
47
|
+
states.data.value = data
|
|
48
|
+
states._data.value = data
|
|
49
|
+
instance.store.execQuery()
|
|
50
|
+
// 数据变化,更新部分数据。
|
|
51
|
+
// 没有使用 computed,而是手动更新部分数据 https://github.com/vuejs/vue/issues/6660#issuecomment-331417140
|
|
52
|
+
instance.store.updateCurrentRowData()
|
|
53
|
+
instance.store.updateExpandRows()
|
|
54
|
+
instance.store.updateTreeData(
|
|
55
|
+
instance.store.states.defaultExpandAll.value
|
|
56
|
+
)
|
|
57
|
+
if (unref(states.reserveSelection)) {
|
|
58
|
+
instance.store.assertRowKey()
|
|
59
|
+
instance.store.updateSelectionByRowKey()
|
|
60
|
+
} else {
|
|
61
|
+
if (dataInstanceChanged) {
|
|
62
|
+
instance.store.clearSelection()
|
|
63
|
+
} else {
|
|
64
|
+
instance.store.cleanSelection()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
instance.store.updateAllSelected()
|
|
68
|
+
if (instance.$ready) {
|
|
69
|
+
instance.store.scheduleLayout()
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
insertColumn(
|
|
74
|
+
states: StoreStates,
|
|
75
|
+
column: TableColumnCtx<T>,
|
|
76
|
+
parent: TableColumnCtx<T>,
|
|
77
|
+
updateColumnOrder: () => void
|
|
78
|
+
) {
|
|
79
|
+
const array = unref(states._columns)
|
|
80
|
+
let newColumns = []
|
|
81
|
+
if (!parent) {
|
|
82
|
+
array.push(column)
|
|
83
|
+
newColumns = array
|
|
84
|
+
} else {
|
|
85
|
+
if (parent && !parent.children) {
|
|
86
|
+
parent.children = []
|
|
87
|
+
}
|
|
88
|
+
parent.children.push(column)
|
|
89
|
+
newColumns = replaceColumn(array, parent)
|
|
90
|
+
}
|
|
91
|
+
sortColumn(newColumns)
|
|
92
|
+
states._columns.value = newColumns
|
|
93
|
+
states.updateOrderFns.push(updateColumnOrder)
|
|
94
|
+
if (column.type === 'selection') {
|
|
95
|
+
states.selectable.value = column.selectable
|
|
96
|
+
states.reserveSelection.value = column.reserveSelection
|
|
97
|
+
}
|
|
98
|
+
if (instance.$ready) {
|
|
99
|
+
instance.store.updateColumns() // hack for dynamics insert column
|
|
100
|
+
instance.store.scheduleLayout()
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
updateColumnOrder(states: StoreStates, column: TableColumnCtx<T>) {
|
|
105
|
+
const newColumnIndex = column.getColumnIndex?.()
|
|
106
|
+
if (newColumnIndex === column.no) return
|
|
107
|
+
|
|
108
|
+
sortColumn(states._columns.value)
|
|
109
|
+
|
|
110
|
+
if (instance.$ready) {
|
|
111
|
+
instance.store.updateColumns()
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
removeColumn(
|
|
116
|
+
states: StoreStates,
|
|
117
|
+
column: TableColumnCtx<T>,
|
|
118
|
+
parent: TableColumnCtx<T>,
|
|
119
|
+
updateColumnOrder: () => void
|
|
120
|
+
) {
|
|
121
|
+
const array = unref(states._columns) || []
|
|
122
|
+
if (parent) {
|
|
123
|
+
parent.children.splice(
|
|
124
|
+
parent.children.findIndex((item) => item.id === column.id),
|
|
125
|
+
1
|
|
126
|
+
)
|
|
127
|
+
// fix #10699, delete parent.children immediately will trigger again
|
|
128
|
+
nextTick(() => {
|
|
129
|
+
if (parent.children?.length === 0) {
|
|
130
|
+
delete parent.children
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
states._columns.value = replaceColumn(array, parent)
|
|
134
|
+
} else {
|
|
135
|
+
const index = array.indexOf(column)
|
|
136
|
+
if (index > -1) {
|
|
137
|
+
array.splice(index, 1)
|
|
138
|
+
states._columns.value = array
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const updateFnIndex = states.updateOrderFns.indexOf(updateColumnOrder)
|
|
143
|
+
updateFnIndex > -1 && states.updateOrderFns.splice(updateFnIndex, 1)
|
|
144
|
+
|
|
145
|
+
if (instance.$ready) {
|
|
146
|
+
instance.store.updateColumns() // hack for dynamics remove column
|
|
147
|
+
instance.store.scheduleLayout()
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
sort(states: StoreStates, options: Sort) {
|
|
152
|
+
const { prop, order, init } = options
|
|
153
|
+
if (prop) {
|
|
154
|
+
const column = unref(states.columns).find(
|
|
155
|
+
(column) => column.property === prop
|
|
156
|
+
)
|
|
157
|
+
if (column) {
|
|
158
|
+
column.order = order
|
|
159
|
+
instance.store.updateSort(column, prop, order)
|
|
160
|
+
instance.store.commit('changeSortCondition', { init })
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
changeSortCondition(states: StoreStates, options: Sort) {
|
|
166
|
+
// 修复 pr https://github.com/ElemeFE/element/pull/15012 导致的 bug
|
|
167
|
+
// https://github.com/element-plus/element-plus/pull/4640
|
|
168
|
+
const { sortingColumn, sortProp, sortOrder } = states
|
|
169
|
+
const columnValue = unref(sortingColumn),
|
|
170
|
+
propValue = unref(sortProp),
|
|
171
|
+
orderValue = unref(sortOrder)
|
|
172
|
+
if (orderValue === null) {
|
|
173
|
+
states.sortingColumn.value = null
|
|
174
|
+
states.sortProp.value = null
|
|
175
|
+
}
|
|
176
|
+
const ignore = { filter: true }
|
|
177
|
+
instance.store.execQuery(ignore)
|
|
178
|
+
|
|
179
|
+
if (!options || !(options.silent || options.init)) {
|
|
180
|
+
instance.emit('sort-change', {
|
|
181
|
+
column: columnValue,
|
|
182
|
+
prop: propValue,
|
|
183
|
+
order: orderValue,
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
instance.store.updateTableScrollY()
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
filterChange(_states: StoreStates, options: Filter<T>) {
|
|
191
|
+
const { column, values, silent } = options
|
|
192
|
+
const newFilters = instance.store.updateFilters(column, values)
|
|
193
|
+
instance.store.execQuery()
|
|
194
|
+
|
|
195
|
+
if (!silent) {
|
|
196
|
+
instance.emit('filter-change', newFilters)
|
|
197
|
+
}
|
|
198
|
+
instance.store.updateTableScrollY()
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
toggleAllSelection() {
|
|
202
|
+
instance.store.toggleAllSelection()
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
rowSelectedChanged(_states, row: T) {
|
|
206
|
+
instance.store.toggleRowSelection(row)
|
|
207
|
+
instance.store.updateAllSelected()
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
setHoverRow(states: StoreStates, row: T) {
|
|
211
|
+
states.hoverRow.value = row
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
setCurrentRow(_states, row: T) {
|
|
215
|
+
instance.store.updateCurrentRow(row)
|
|
216
|
+
},
|
|
217
|
+
}
|
|
218
|
+
const commit = function (name: keyof typeof mutations, ...args) {
|
|
219
|
+
const mutations = instance.store.mutations
|
|
220
|
+
if (mutations[name]) {
|
|
221
|
+
mutations[name].apply(instance, [instance.store.states].concat(args))
|
|
222
|
+
} else {
|
|
223
|
+
throw new Error(`Action not found: ${name}`)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const updateTableScrollY = function () {
|
|
227
|
+
nextTick(() => instance.layout.updateScrollY.apply(instance.layout))
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
ns,
|
|
231
|
+
...watcher,
|
|
232
|
+
mutations,
|
|
233
|
+
commit,
|
|
234
|
+
updateTableScrollY,
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export default useStore
|
|
239
|
+
|
|
240
|
+
class HelperStore<T> {
|
|
241
|
+
Return = useStore<T>()
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
type StoreFilter = Record<string, string[]>
|
|
245
|
+
type Store<T> = HelperStore<T>['Return']
|
|
246
|
+
export type { WatcherPropsData, Store, StoreFilter }
|