多语言优化

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

@@ -39,6 +39,7 @@
<script setup lang="ts">
import { computed } from 'vue'
import { useDictStore } from '@/store/modules/dict'
import { useI18n } from 'vue-i18n'
defineOptions({ name: 'SaCheckbox', inheritAttrs: false })
@@ -69,6 +70,7 @@
const modelValue = defineModel<(string | number)[]>()
const dictStore = useDictStore()
const { t, te, locale } = useI18n()
const canConvertToNumberStrict = (value: any) => {
if (value == null) return false
@@ -81,9 +83,20 @@
}
const options = computed(() => {
// 让字典选项在切换语言时可响应更新
locale.value
const list = dictStore.getByCode(props.dict) || []
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) => {
let newValue = item.value
@@ -101,7 +114,11 @@
return {
...item,
value: newValue
value: newValue,
label: (() => {
const key = `dict.${props.dict}.${newValue}`
return te(key) ? t(key) : item.label
})()
}
})
})