Skip to content

Commit 58de29e

Browse files
committed
feat (core): 支持 Select 显示图标
1 parent 7433e48 commit 58de29e

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/composables/useLanguageManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export function useLanguageManager(
5353
const languages = await invoke<Language[]>('get_supported_languages')
5454
supportedLanguages.value = languages.map((language) => ({
5555
name: language.name,
56-
value: language.value
56+
value: language.value,
57+
svgUrl: `/icons/${ language.value.replace(/\d+$/, '') }.svg`
5758
}))
5859

5960
// 设置默认语言

src/ui/Select.vue

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@
2323
:aria-expanded="isOpen"
2424
:aria-haspopup="true"
2525
role="combobox">
26-
<span class="block truncate">
27-
{{ selectedLabel || placeholder }}
28-
</span>
26+
<div class="flex space-x-3 items-center truncate">
27+
<!-- 如果是SVG字符串 -->
28+
<div v-if="selectedOption && getSvgIcon(selectedOption)" v-html="getSvgIcon(selectedOption)" class="w-6 h-6"/>
29+
30+
<!-- 如果是SVG URL -->
31+
<img v-else-if="selectedOption && getSvgUrl(selectedOption)" :src="getSvgUrl(selectedOption)" class="w-6 h-6" alt="icon"/>
32+
33+
<span>{{ selectedLabel || placeholder }}</span>
34+
</div>
2935
<span class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
3036
<ChevronUpIcon class="h-5 w-5 text-gray-400 transition-transform duration-200"
3137
:class="{ 'rotate-180': isOpen }"
@@ -71,7 +77,7 @@
7177
@keydown.enter.prevent="selectOption(option)"
7278
@keydown.space.prevent="selectOption(option)"
7379
:class="[
74-
'relative cursor-pointer select-none py-1 my-1 pl-3 pr-9 transition-colors duration-150',
80+
'relative flex space-x-3 items-center cursor-pointer select-none py-1 my-1 pl-3 pr-9 transition-colors duration-150',
7581
isSelected(option)
7682
? 'bg-blue-400 text-white'
7783
: 'text-gray-900 hover:bg-blue-50',
@@ -80,6 +86,12 @@
8086
:aria-selected="isSelected(option)"
8187
role="option"
8288
tabindex="-1">
89+
<!-- 如果是SVG字符串 -->
90+
<div v-if="getSvgIcon(option)" v-html="getSvgIcon(option)" class="w-6 h-6"/>
91+
92+
<!-- 如果是SVG URL -->
93+
<img v-else-if="getSvgUrl(option)" :src="getSvgUrl(option)" class="w-6 h-6" alt="icon"/>
94+
8395
<span :class="['block truncate', isSelected(option) ? 'font-medium' : 'font-normal']">
8496
{{ getOptionLabel(option) }}
8597
</span>
@@ -112,6 +124,8 @@ interface Option
112124
label: string
113125
value: any
114126
disabled?: boolean
127+
svgIcon?: string
128+
svgUrl?: string
115129
116130
[key: string]: any
117131
}
@@ -177,6 +191,8 @@ const normalizedOptions = computed(() => {
177191
...option,
178192
label: option[props.labelKey] || option.label,
179193
value: option[props.valueKey] || option.value,
194+
svgIcon: option.svgIcon || '',
195+
svgUrl: option.svgUrl || '',
180196
disabled: option.disabled || false
181197
}
182198
})
@@ -240,6 +256,8 @@ const updateDropdownPosition = async () => {
240256
// 方法
241257
const getOptionValue = (option: Option) => option.value
242258
const getOptionLabel = (option: Option) => option.label
259+
const getSvgUrl = (option: Option) => option.svgUrl
260+
const getSvgIcon = (option: Option) => option.svgIcon
243261
244262
const isSelected = (option: Option) => {
245263
return option.value === props.modelValue

0 commit comments

Comments
 (0)