resolver-egretimp-plus 0.1.29 → 0.1.31
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/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/loading/loading.scss +1 -1
- 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/rules/parseCondition.js +3 -0
- package/src/rules/rulesDriver.js +2 -2
- package/tsconfig.json +19 -0
- package/vue-shims.d.ts +4 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-tooltip
|
|
3
|
+
ref="tooltip"
|
|
4
|
+
:visible="tooltipVisible"
|
|
5
|
+
:offset="0"
|
|
6
|
+
:placement="placement"
|
|
7
|
+
:show-arrow="false"
|
|
8
|
+
:stop-popper-mouse-event="false"
|
|
9
|
+
teleported
|
|
10
|
+
effect="light"
|
|
11
|
+
pure
|
|
12
|
+
:popper-class="filterClassName"
|
|
13
|
+
persistent
|
|
14
|
+
>
|
|
15
|
+
<template #content>
|
|
16
|
+
<div v-if="multiple">
|
|
17
|
+
<div :class="ns.e('content')">
|
|
18
|
+
<el-scrollbar :wrap-class="ns.e('wrap')">
|
|
19
|
+
<el-checkbox-group
|
|
20
|
+
v-model="filteredValue"
|
|
21
|
+
:class="ns.e('checkbox-group')"
|
|
22
|
+
>
|
|
23
|
+
<el-checkbox
|
|
24
|
+
v-for="filter in filters"
|
|
25
|
+
:key="filter.value"
|
|
26
|
+
:value="filter.value"
|
|
27
|
+
>
|
|
28
|
+
{{ filter.text }}
|
|
29
|
+
</el-checkbox>
|
|
30
|
+
</el-checkbox-group>
|
|
31
|
+
</el-scrollbar>
|
|
32
|
+
</div>
|
|
33
|
+
<div :class="ns.e('bottom')">
|
|
34
|
+
<button
|
|
35
|
+
:class="{ [ns.is('disabled')]: filteredValue.length === 0 }"
|
|
36
|
+
:disabled="filteredValue.length === 0"
|
|
37
|
+
type="button"
|
|
38
|
+
@click="handleConfirm"
|
|
39
|
+
>
|
|
40
|
+
{{ t('el.table.confirmFilter') }}
|
|
41
|
+
</button>
|
|
42
|
+
<button type="button" @click="handleReset">
|
|
43
|
+
{{ t('el.table.resetFilter') }}
|
|
44
|
+
</button>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
<ul v-else :class="ns.e('list')">
|
|
48
|
+
<li
|
|
49
|
+
:class="[
|
|
50
|
+
ns.e('list-item'),
|
|
51
|
+
{
|
|
52
|
+
[ns.is('active')]:
|
|
53
|
+
filterValue === undefined || filterValue === null,
|
|
54
|
+
},
|
|
55
|
+
]"
|
|
56
|
+
@click="handleSelect(null)"
|
|
57
|
+
>
|
|
58
|
+
{{ t('el.table.clearFilter') }}
|
|
59
|
+
</li>
|
|
60
|
+
<li
|
|
61
|
+
v-for="filter in filters"
|
|
62
|
+
:key="filter.value"
|
|
63
|
+
:class="[ns.e('list-item'), ns.is('active', isActive(filter))]"
|
|
64
|
+
:label="filter.value"
|
|
65
|
+
@click="handleSelect(filter.value)"
|
|
66
|
+
>
|
|
67
|
+
{{ filter.text }}
|
|
68
|
+
</li>
|
|
69
|
+
</ul>
|
|
70
|
+
</template>
|
|
71
|
+
<template #default>
|
|
72
|
+
<span
|
|
73
|
+
v-click-outside:[popperPaneRef]="hideFilterPanel"
|
|
74
|
+
:class="[
|
|
75
|
+
`${ns.namespace.value}-table__column-filter-trigger`,
|
|
76
|
+
`${ns.namespace.value}-none-outline`,
|
|
77
|
+
]"
|
|
78
|
+
@click="showFilterPanel"
|
|
79
|
+
>
|
|
80
|
+
<el-icon>
|
|
81
|
+
<arrow-up v-if="column.filterOpened" />
|
|
82
|
+
<arrow-down v-else />
|
|
83
|
+
</el-icon>
|
|
84
|
+
</span>
|
|
85
|
+
</template>
|
|
86
|
+
</el-tooltip>
|
|
87
|
+
</template>
|
|
88
|
+
|
|
89
|
+
<script lang="ts">
|
|
90
|
+
// @ts-nocheck
|
|
91
|
+
import { computed, defineComponent, getCurrentInstance, ref, watch } from 'vue'
|
|
92
|
+
import ElCheckbox from 'element-plus/es/components/checkbox/index.mjs'
|
|
93
|
+
import { ElIcon } from 'element-plus/es/components/icon/index.mjs'
|
|
94
|
+
import { ArrowDown, ArrowUp } from '@element-plus/icons-vue'
|
|
95
|
+
import { ClickOutside } from 'element-plus/es/directives/index.mjs'
|
|
96
|
+
import { useLocale, useNamespace } from 'element-plus/es/hooks/index.mjs'
|
|
97
|
+
import ElTooltip from 'element-plus/es/components/tooltip/index.mjs'
|
|
98
|
+
import ElScrollbar from 'element-plus/es/components/scrollbar/index.mjs'
|
|
99
|
+
import type { Placement } from 'element-plus/es/components/popper/index.mjs.mjs'
|
|
100
|
+
|
|
101
|
+
import type { PropType, WritableComputedRef } from 'vue'
|
|
102
|
+
import type { TableColumnCtx } from './table-column/defaults'
|
|
103
|
+
import type { TableHeader } from './table-header'
|
|
104
|
+
import type { Store } from './store'
|
|
105
|
+
|
|
106
|
+
const { CheckboxGroup: ElCheckboxGroup } = ElCheckbox
|
|
107
|
+
|
|
108
|
+
export default defineComponent({
|
|
109
|
+
name: 'ElTableFilterPanel',
|
|
110
|
+
components: {
|
|
111
|
+
ElCheckbox,
|
|
112
|
+
ElCheckboxGroup,
|
|
113
|
+
ElScrollbar,
|
|
114
|
+
ElTooltip,
|
|
115
|
+
ElIcon,
|
|
116
|
+
ArrowDown,
|
|
117
|
+
ArrowUp,
|
|
118
|
+
},
|
|
119
|
+
directives: { ClickOutside },
|
|
120
|
+
props: {
|
|
121
|
+
placement: {
|
|
122
|
+
type: String as PropType<Placement>,
|
|
123
|
+
default: 'bottom-start',
|
|
124
|
+
},
|
|
125
|
+
store: {
|
|
126
|
+
type: Object as PropType<Store<unknown>>,
|
|
127
|
+
},
|
|
128
|
+
column: {
|
|
129
|
+
type: Object as PropType<TableColumnCtx<unknown>>,
|
|
130
|
+
},
|
|
131
|
+
upDataColumn: {
|
|
132
|
+
type: Function,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
setup(props) {
|
|
136
|
+
const instance = getCurrentInstance()
|
|
137
|
+
const { t } = useLocale()
|
|
138
|
+
const ns = useNamespace('table-filter')
|
|
139
|
+
const parent = instance?.parent as TableHeader
|
|
140
|
+
if (!parent.filterPanels.value[props.column.id]) {
|
|
141
|
+
parent.filterPanels.value[props.column.id] = instance
|
|
142
|
+
}
|
|
143
|
+
const tooltipVisible = ref(false)
|
|
144
|
+
const tooltip = ref<InstanceType<typeof ElTooltip> | null>(null)
|
|
145
|
+
const filters = computed(() => {
|
|
146
|
+
return props.column && props.column.filters
|
|
147
|
+
})
|
|
148
|
+
const filterClassName = computed(() => {
|
|
149
|
+
if (props.column.filterClassName) {
|
|
150
|
+
return `${ns.b()} ${props.column.filterClassName}`
|
|
151
|
+
}
|
|
152
|
+
return ns.b()
|
|
153
|
+
})
|
|
154
|
+
const filterValue = computed({
|
|
155
|
+
get: () => (props.column?.filteredValue || [])[0],
|
|
156
|
+
set: (value: string) => {
|
|
157
|
+
if (filteredValue.value) {
|
|
158
|
+
if (typeof value !== 'undefined' && value !== null) {
|
|
159
|
+
filteredValue.value.splice(0, 1, value)
|
|
160
|
+
} else {
|
|
161
|
+
filteredValue.value.splice(0, 1)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
})
|
|
166
|
+
const filteredValue: WritableComputedRef<unknown[]> = computed({
|
|
167
|
+
get() {
|
|
168
|
+
if (props.column) {
|
|
169
|
+
return props.column.filteredValue || []
|
|
170
|
+
}
|
|
171
|
+
return []
|
|
172
|
+
},
|
|
173
|
+
set(value: unknown[]) {
|
|
174
|
+
if (props.column) {
|
|
175
|
+
props.upDataColumn('filteredValue', value)
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
})
|
|
179
|
+
const multiple = computed(() => {
|
|
180
|
+
if (props.column) {
|
|
181
|
+
return props.column.filterMultiple
|
|
182
|
+
}
|
|
183
|
+
return true
|
|
184
|
+
})
|
|
185
|
+
const isActive = (filter) => {
|
|
186
|
+
return filter.value === filterValue.value
|
|
187
|
+
}
|
|
188
|
+
const hidden = () => {
|
|
189
|
+
tooltipVisible.value = false
|
|
190
|
+
}
|
|
191
|
+
const showFilterPanel = (e: MouseEvent) => {
|
|
192
|
+
e.stopPropagation()
|
|
193
|
+
tooltipVisible.value = !tooltipVisible.value
|
|
194
|
+
}
|
|
195
|
+
const hideFilterPanel = () => {
|
|
196
|
+
tooltipVisible.value = false
|
|
197
|
+
}
|
|
198
|
+
const handleConfirm = () => {
|
|
199
|
+
confirmFilter(filteredValue.value)
|
|
200
|
+
hidden()
|
|
201
|
+
}
|
|
202
|
+
const handleReset = () => {
|
|
203
|
+
filteredValue.value = []
|
|
204
|
+
confirmFilter(filteredValue.value)
|
|
205
|
+
hidden()
|
|
206
|
+
}
|
|
207
|
+
const handleSelect = (_filterValue?: string) => {
|
|
208
|
+
filterValue.value = _filterValue
|
|
209
|
+
if (typeof _filterValue !== 'undefined' && _filterValue !== null) {
|
|
210
|
+
confirmFilter(filteredValue.value)
|
|
211
|
+
} else {
|
|
212
|
+
confirmFilter([])
|
|
213
|
+
}
|
|
214
|
+
hidden()
|
|
215
|
+
}
|
|
216
|
+
const confirmFilter = (filteredValue: unknown[]) => {
|
|
217
|
+
props.store.commit('filterChange', {
|
|
218
|
+
column: props.column,
|
|
219
|
+
values: filteredValue,
|
|
220
|
+
})
|
|
221
|
+
props.store.updateAllSelected()
|
|
222
|
+
}
|
|
223
|
+
watch(
|
|
224
|
+
tooltipVisible,
|
|
225
|
+
(value) => {
|
|
226
|
+
// todo
|
|
227
|
+
if (props.column) {
|
|
228
|
+
props.upDataColumn('filterOpened', value)
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
immediate: true,
|
|
233
|
+
}
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
const popperPaneRef = computed(() => {
|
|
237
|
+
return tooltip.value?.popperRef?.contentRef
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
tooltipVisible,
|
|
242
|
+
multiple,
|
|
243
|
+
filterClassName,
|
|
244
|
+
filteredValue,
|
|
245
|
+
filterValue,
|
|
246
|
+
filters,
|
|
247
|
+
handleConfirm,
|
|
248
|
+
handleReset,
|
|
249
|
+
handleSelect,
|
|
250
|
+
isActive,
|
|
251
|
+
t,
|
|
252
|
+
ns,
|
|
253
|
+
showFilterPanel,
|
|
254
|
+
hideFilterPanel,
|
|
255
|
+
popperPaneRef,
|
|
256
|
+
tooltip,
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
})
|
|
260
|
+
</script>
|
|
@@ -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
|
+
}
|