From 77aebf5dd28d1da44ac52113f5ae8f57ffb6ed33 Mon Sep 17 00:00:00 2001 From: JEECG <445654970@qq.com> Date: Tue, 24 Sep 2024 22:42:21 +0800 Subject: [PATCH] =?UTF-8?q?=20=E7=A7=9F=E6=88=B7=E5=A5=97=E9=A4=90?= =?UTF-8?q?=E7=9A=84=E8=8F=9C=E5=8D=95=E5=90=8D=E7=A7=B0=E6=B2=A1=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Form/src/jeecg/components/JTreeSelect.vue | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/jeecgboot-vue3/src/components/Form/src/jeecg/components/JTreeSelect.vue b/jeecgboot-vue3/src/components/Form/src/jeecg/components/JTreeSelect.vue index 44aae735..3770c4aa 100644 --- a/jeecgboot-vue3/src/components/Form/src/jeecg/components/JTreeSelect.vue +++ b/jeecgboot-vue3/src/components/Form/src/jeecg/components/JTreeSelect.vue @@ -33,7 +33,7 @@ import { TreeSelect } from 'ant-design-vue'; import { useMessage } from '/@/hooks/web/useMessage'; import { isObject } from '/@/utils/is'; - + import { useI18n } from '/@/hooks/web/useI18n'; enum Api { url = '/sys/dict/loadTreeData', view = '/sys/dict/loadDictItem/', @@ -65,6 +65,7 @@ hiddenNodeKey: propTypes.string.def(''), }); const attrs = useAttrs(); + const { t } = useI18n(); const emit = defineEmits(['change', 'update:value']); const slots = defineSlots(); const { createMessage } = useMessage(); @@ -151,10 +152,10 @@ treeValue.value = result.result.map((item, index) => ({ key: values[index], value: values[index], - label: item, + label: translateTitle(item), })); }else{ - treeValue.value = { key: props.value, value: props.value, label: result.result[0] }; + treeValue.value = { key: props.value, value: props.value, label: translateTitle(result.result[0]) }; } //update-end-author:liaozhiyang date:2023-7-17 for:【issues/5141】使用JtreeSelect 组件 控制台报错 onLoadTriggleChange(result.result[0]); @@ -198,6 +199,7 @@ let res = await defHttp.get({ url: Api.url, params }, { isTransformResponse: false }); if (res.success && res.result) { for (let i of res.result) { + i.title = translateTitle(i.title); i.value = i.key; i.isLeaf = !!i.leaf; } @@ -210,6 +212,16 @@ } } + /** + * 翻译 + * @param text + */ + function translateTitle(text) { + if (text.includes("t('") && t) { + return new Function('t', `return ${text}`)(t); + } + return text; + } /** * 异步加载数据 */ @@ -217,7 +229,7 @@ if (treeNode.dataRef.children) { return Promise.resolve(); } - if(props.url){ + if (props.url) { return Promise.resolve(); } let pid = treeNode.dataRef.key; @@ -234,6 +246,7 @@ let res = await defHttp.get({ url: Api.url, params }, { isTransformResponse: false }); if (res.success) { for (let i of res.result) { + i.title = translateTitle(i.title); i.value = i.key; i.isLeaf = !!i.leaf; } @@ -334,6 +347,7 @@ let res = await defHttp.get({ url, params }, { isTransformResponse: false }); if (res.success && res.result) { for (let i of res.result) { + i.title = translateTitle(i.title); i.key = i.value; i.isLeaf = !!i.leaf; }