Skip to content

Commit d8a2eac

Browse files
authored
refactor(base-select): remove tree/grid code from base-select (#2522)
1 parent 554e778 commit d8a2eac

File tree

3 files changed

+1
-104
lines changed

3 files changed

+1
-104
lines changed

examples/sites/demos/pc/app/base-select/size.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ test('mini 尺寸', async ({ page }) => {
5454

5555
await expect(input).toHaveClass(/tiny-input-mini/)
5656
await expect(tag.nth(0)).toHaveClass(/tiny-tag--mini tiny-tag--light/)
57-
expect(height).toBeCloseTo(27, 1)
57+
expect(height).toBeCloseTo(28, 1)
5858
})

packages/renderless/src/base-select/index.ts

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -61,51 +61,6 @@ export const showTip =
6161
}
6262
}
6363

64-
export const gridOnQueryChange =
65-
({ props, vm, constants, state }) =>
66-
(value) => {
67-
const { multiple, valueField, filterMethod, filterable, remote, remoteMethod } = props
68-
69-
if (filterable && typeof filterMethod === 'function') {
70-
const table = vm.$refs.selectGrid.$refs.tinyTable
71-
const fullData = table.afterFullData
72-
73-
vm.$refs.selectGrid.scrollTo(null, 0)
74-
75-
table.afterFullData = filterMethod(value, fullData) || []
76-
77-
vm.$refs.selectGrid
78-
.handleTableData(!value)
79-
.then(() => state.selectEmitter.emit(constants.EVENT_NAME.updatePopper))
80-
81-
state.previousQuery = value
82-
} else if (remote && typeof remoteMethod === 'function') {
83-
state.previousQuery = value
84-
remoteMethod(value, props.extraQueryParams).then((data) => {
85-
// 多选时取远端数据与当前已选数据的并集
86-
if (multiple) {
87-
const selectedIds = state.selected.map((sel) => sel[valueField])
88-
vm.$refs.selectGrid.clearSelection()
89-
vm.$refs.selectGrid.setSelection(
90-
data.filter((row) => ~selectedIds.indexOf(row[valueField])),
91-
true
92-
)
93-
state.remoteData = data.filter((row) => !~selectedIds.indexOf(row[valueField])).concat(state.selected)
94-
} else {
95-
vm.$refs.selectGrid.clearRadioRow()
96-
vm.$refs.selectGrid.setRadioRow(find(data, (item) => props.modelValue === item[props.valueField]))
97-
state.remoteData = data
98-
}
99-
100-
vm.$refs.selectGrid.$refs.tinyTable.lastScrollTop = 0
101-
vm.$refs.selectGrid.loadData(data)
102-
vm.$refs.selectGrid
103-
.handleTableData(!value)
104-
.then(() => state.selectEmitter.emit(constants.EVENT_NAME.updatePopper))
105-
})
106-
}
107-
}
108-
10964
export const defaultOnQueryChange =
11065
({ props, state, constants, api, nextTick }) =>
11166
(value, isInput) => {
@@ -365,7 +320,6 @@ export const setSelected =
365320
state.selected = result
366321
}
367322

368-
vm.$refs.selectTree && vm.$refs.selectTree.setCheckedNodes && vm.$refs.selectTree.setCheckedNodes(state.selected)
369323
state.tips = state.selected.map((item) => (item.state ? item.state.currentLabel : item.currentLabel)).join(',')
370324

371325
setFilteredSelectCls(nextTick, state, props)
@@ -1246,10 +1200,6 @@ export const toVisible =
12461200
if (vm.$refs.input && vm.$refs.input.value === '' && state.selected.length === 0) {
12471201
state.currentPlaceholder = state.cachedPlaceHolder
12481202
}
1249-
1250-
if (vm.$refs.selectGrid) {
1251-
vm.$refs.selectGrid.clearScroll()
1252-
}
12531203
})
12541204

12551205
postOperOfToVisible({ props, state, constants })
@@ -1283,31 +1233,6 @@ export const toHide =
12831233
}
12841234
}
12851235
}
1286-
1287-
if (vm.$refs.selectGrid) {
1288-
let { fullData } = vm.$refs.selectGrid.getTableData()
1289-
if (multiple) {
1290-
const selectedIds = state.selected.map((sel) => sel[valueField])
1291-
vm.$refs.selectGrid.clearSelection()
1292-
vm.$refs.selectGrid.setSelection(
1293-
fullData.filter((row) => ~selectedIds.indexOf(row[valueField])),
1294-
true
1295-
)
1296-
} else {
1297-
vm.$refs.selectGrid.clearRadioRow()
1298-
vm.$refs.selectGrid.setRadioRow(find(fullData, (item) => props.modelValue === item[valueField]))
1299-
}
1300-
1301-
if (filterable && typeof props.filterMethod === 'function') {
1302-
vm.$refs.selectGrid.handleTableData(true)
1303-
} else if (
1304-
filterable &&
1305-
remote &&
1306-
(typeof props.remoteMethod === 'function' || typeof props.initQuery === 'function')
1307-
) {
1308-
vm.$refs.selectGrid.handleTableData()
1309-
}
1310-
}
13111236
}
13121237

13131238
export const watchVisible =
@@ -1425,23 +1350,6 @@ export const handleCopyClick =
14251350
parent.$el.removeChild(input)
14261351
}
14271352

1428-
export const getcheckedData =
1429-
({ props, state }) =>
1430-
() => {
1431-
const checkedKey = []
1432-
1433-
if (!Array.isArray(state.selected)) {
1434-
return props.modelValue ? [props.modelValue] : [state.selected[props.valueField]]
1435-
} else {
1436-
state.selected.length > 0 &&
1437-
state.selected.forEach((item) => {
1438-
checkedKey.push(item[props.valueField])
1439-
})
1440-
1441-
return checkedKey
1442-
}
1443-
}
1444-
14451353
export const debouncRquest = ({ api, state, props }) =>
14461354
debounce(props.delay, () => {
14471355
if (props.filterable && state.query !== state.selectedLabel) {
@@ -1667,14 +1575,12 @@ export const initQuery =
16671575
return new Promise((resolve) => {
16681576
initData.then((selected) => {
16691577
state.remoteData = selected
1670-
vm.$refs.selectGrid.loadData(selected)
16711578
resolve(selected)
16721579
})
16731580
})
16741581
}
16751582
selected = initData
16761583
state.remoteData = selected
1677-
vm.$refs.selectGrid.loadData(selected)
16781584
}
16791585

16801586
return Promise.resolve(selected)
@@ -1683,7 +1589,6 @@ export const initQuery =
16831589
export const mounted =
16841590
({ api, parent, state, props, vm, designConfig }) =>
16851591
() => {
1686-
state.defaultCheckedKeys = state.gridCheckedData
16871592
const parentEl = parent.$el
16881593
const inputEl = parentEl.querySelector('input[data-tag="tiny-input-inner"]')
16891594

packages/renderless/src/base-select/vue.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
debouncRquest,
33
getChildValue,
4-
getcheckedData,
54
calcOverFlow,
65
toggleCheckAll,
76
handleCopyClick,
@@ -55,7 +54,6 @@ import {
5554
onMouseenterNative,
5655
onMouseleaveNative,
5756
onCopying,
58-
gridOnQueryChange,
5957
defaultOnQueryChange,
6058
queryChange,
6159
toVisible,
@@ -259,8 +257,6 @@ const initStateAdd = ({ computed, props, api, parent }) => {
259257
initialInputHeight: 0,
260258
currentPlaceholder: props.placeholder,
261259
filteredOptionsCount: 0,
262-
gridData: [],
263-
treeData: [],
264260
remoteData: [],
265261
currentKey: props.modelValue,
266262
updateId: '',
@@ -271,12 +267,10 @@ const initStateAdd = ({ computed, props, api, parent }) => {
271267
formItemSize: computed(() => (parent.formItem || { state: {} }).state.formItemSize),
272268
selectDisabled: computed(() => api.computedSelectDisabled()),
273269
isDisplayOnly: computed(() => props.displayOnly || (parent.form || {}).displayOnly),
274-
gridCheckedData: computed(() => api.getcheckedData()),
275270
searchSingleCopy: computed(() => props.allowCopy && !props.multiple && props.filterable),
276271
childrenName: computed(() => 'children'),
277272
tooltipContent: {},
278273
isHidden: false,
279-
defaultCheckedKeys: [],
280274
optionIndexArr: [],
281275
showCollapseTag: false,
282276
exceedMaxVisibleRow: false, // 是否超出默认最大显示行数
@@ -317,7 +311,6 @@ const initApi = ({
317311
showTip: showTip({ props, state, vm }),
318312
onOptionDestroy: onOptionDestroy(state),
319313
setSoftFocus: setSoftFocus({ vm, state }),
320-
getcheckedData: getcheckedData({ props, state }),
321314
resetInputWidth: resetInputWidth({ vm, state }),
322315
resetHoverIndex: resetHoverIndex({ props, state }),
323316
resetDatas: resetDatas({ props, state }),
@@ -338,7 +331,6 @@ const initApi = ({
338331
onMouseenterNative: onMouseenterNative({ state }),
339332
onMouseleaveNative: onMouseleaveNative({ state }),
340333
onCopying: onCopying({ state, vm }),
341-
gridOnQueryChange: gridOnQueryChange({ props, vm, constants, state }),
342334
watchHoverIndex: watchHoverIndex({ state }),
343335
computeOptimizeOpts: computeOptimizeOpts({ props, designConfig }),
344336
computeCollapseTags: computeCollapseTags(props),

0 commit comments

Comments
 (0)