-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: select提供选项定制和回显内容定制 #69
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,12 +292,19 @@ export default defineComponent({ | |
}; | ||
|
||
const selectedOptions = computed(() => | ||
Object.values(nodeList.value).filter((option) => { | ||
if (props.multiple) { | ||
return currentValue.value.includes(option.value); | ||
} | ||
return [currentValue.value].includes(option.value); | ||
}), | ||
Object.values(nodeList.value) | ||
.filter((option) => { | ||
if (props.multiple) { | ||
return currentValue.value.includes(option.value); | ||
} | ||
return [currentValue.value].includes(option.value); | ||
}) | ||
.map((option) => { | ||
return { | ||
...option, | ||
label: `${option[props.optionLabelField]}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果用户传了 labelField,没有 optionLabelField,这里应该有问题? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 额好像是 |
||
}; | ||
}), | ||
); | ||
|
||
const focus = (e: Event) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
:onSelect="onSelect" | ||
:isLimit="isLimitRef" | ||
:emptyText="listEmptyText" | ||
:renderOption="$slots.option" | ||
@scroll="onScroll" | ||
@mousedown.prevent | ||
/> | ||
|
@@ -219,9 +220,14 @@ export default defineComponent({ | |
const getOption = (val: SelectValue) => { | ||
let cacheOption; | ||
if (newOptions && newOptions.length) { | ||
cacheOption = newOptions.find( | ||
(option) => option.value === val, | ||
); | ||
cacheOption = newOptions | ||
.map((option) => { | ||
return { | ||
...option, | ||
label: option[props.optionLabelField], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同理 |
||
}; | ||
}) | ||
.find((option) => option.value === val); | ||
if (cacheOption) { | ||
return cacheOption; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<template> | ||
<FSelect :options="optionList" optionLabelField="x"></FSelect> | ||
</template> | ||
<script> | ||
import { reactive } from 'vue'; | ||
|
||
export default { | ||
setup() { | ||
const optionList = reactive([ | ||
{ | ||
value: 'HuNan', | ||
label: '湖南', | ||
x: 'HuNan-湖南', | ||
}, | ||
{ | ||
value: 'HuBei', | ||
label: '湖北', | ||
disabled: true, | ||
x: 'HuBei-湖北', | ||
}, | ||
{ | ||
value: 'ZheJiang', | ||
label: '浙江', | ||
x: 'ZheJiang-浙江', | ||
}, | ||
{ | ||
value: 'GuangDong', | ||
label: '广东', | ||
x: 'GuangDong-广东', | ||
}, | ||
{ | ||
value: 'JiangSu', | ||
label: '江苏', | ||
x: 'JiangSu-江苏', | ||
}, | ||
]); | ||
return { | ||
optionList, | ||
}; | ||
}, | ||
}; | ||
</script> | ||
<style scoped> | ||
.fes-select { | ||
width: 200px; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<template> | ||
<FSelectTree :data="data" optionLabelField="x"></FSelectTree> | ||
</template> | ||
<script> | ||
import { reactive } from 'vue'; | ||
|
||
function createData(level = 1, baseKey = '', prefix = null, suffix = null) { | ||
if (!level) return undefined; | ||
return Array.apply(null, { length: 2 }).map((_, index) => { | ||
const key = '' + baseKey + level + index; | ||
return { | ||
label: createLabel(level), | ||
value: key, | ||
children: createData(level - 1, key, prefix, suffix), | ||
x: `${key}-${createLabel(level)}`, | ||
prefix: prefix ? () => h(PictureOutlined) : null, | ||
suffix: suffix ? () => h(PlusCircleOutlined) : null, | ||
}; | ||
}); | ||
} | ||
|
||
function createLabel(level) { | ||
if (level === 4) return '道生一'; | ||
if (level === 3) return '一生二'; | ||
if (level === 2) return '二生三'; | ||
if (level === 1) return '三生万物'; | ||
} | ||
|
||
export default { | ||
setup() { | ||
const data = reactive(createData(4)); | ||
return { | ||
data, | ||
}; | ||
}, | ||
}; | ||
</script> | ||
<style scoped> | ||
.fes-select-tree { | ||
width: 200px; | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接用 currentValue.value === option.value ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不改了,差别不大