多语言优化

This commit is contained in:
2026-03-19 15:40:06 +08:00
parent db0e420a8f
commit 333e85f7d9
45 changed files with 864 additions and 276 deletions

View File

@@ -45,6 +45,7 @@
<script setup lang="ts">
import { computed } from 'vue'
import { useDictStore } from '@/store/modules/dict'
import { useI18n } from 'vue-i18n'
defineOptions({ name: 'SaRadio', inheritAttrs: false })
@@ -82,6 +83,7 @@
const modelValue = defineModel<string | number | undefined>()
const dictStore = useDictStore()
const { t, te, locale } = useI18n()
// 判断能否转成数字
const canConvertToNumberStrict = (value: any) => {
@@ -97,10 +99,21 @@
// 核心逻辑:在 computed 中处理数据类型转换
const options = computed(() => {
// 让字典选项在切换语言时可响应更新
locale.value
const list = dictStore.getByCode(props.dict) || []
// 如果没有指定 valueType直接返回原始字典
if (!props.valueType) return list
if (!props.valueType) {
return list.map((item) => {
const key = `dict.${props.dict}.${item.value}`
return {
...item,
label: te(key) ? t(key) : item.label
}
})
}
// 如果指定了类型,进行映射转换
return list.map((item) => {
@@ -119,7 +132,11 @@
return {
...item,
value: newValue
value: newValue,
label: (() => {
const key = `dict.${props.dict}.${newValue}`
return te(key) ? t(key) : item.label
})()
}
})
})