更改默认首页菜单名称适配国际化导致菜单管理页无法访问
版本号:
3.8.0
问题描述:
更改默认首页菜单名称适配国际化导致菜单管理页无法访问,只有去数据库里改回非t()的形式才恢复
错误截图:
友情提示:
- 未按格式要求发帖、描述过于简单的,会被直接删掉;
- 描述问题请图文并茂,方便我们理解并快速定位问题;
- 如果使用的不是master,请说明你使用的分支;
// 自定义菜单名称列渲染
columns[0].customRender = function ({text, record}) {
const isDefIndex = checkDefIndex(record)
if (isDefIndex) {
text += '(默认首页)'
}
// update-begin--author:liaozhiyang---date:20240306---for:【QQYUN-8379】菜单管理页菜单国际化
if (text.includes("t('") && t) {
return new Function('t', return ${text})(t);
}
// update-end--author:liaozhiyang---date:20240306---for:【QQYUN-8379】菜单管理页菜单国际化
return text
}
我这里定位到是这里出了问题,请官方尽快修复。
// 自定义菜单名称列渲染 columns[0].customRender = function ({text, record}) { const isDefIndex = checkDefIndex(record) if (isDefIndex) { text += '(默认首页)' } // update-begin--author:liaozhiyang---date:20240306---for:【QQYUN-8379】菜单管理页菜单国际化 if (text.includes("t('") && t) { return new Function('t',
return ${text})(t); } // update-end--author:liaozhiyang---date:20240306---for:【QQYUN-8379】菜单管理页菜单国际化 return text }我这里定位到是这里出了问题,请官方尽快修复。
目前解决方案
columns[0].customRender = function ({ text, record }) {
const isDefIndex = checkDefIndex(record);
if (isDefIndex) {
text += '(默认首页)';
}
// update-begin--author:liaozhiyang---date:20240306---for:【QQYUN-8379】菜单管理页菜单国际化
// if (text.includes("t('") && t) {
// return new Function('t', `return ${text}`)(t);
// }
if (text && typeof text === 'string' && text.includes("t('")) {
try {
// 提取国际化key
const match = text.match(/t\('([^']+)'\)/);
if (match && match[1]) {
return t(match[1]);
}
} catch (e) {
console.error('Menu name translation error:', e);
}
}
// update-end--author:liaozhiyang---date:20240306---for:【QQYUN-8379】菜单管理页菜单国际化
return text;
};
多语言解决方案,默认首页添加到多语言配置文件中,这样就在保持原有功能的基础上实现了多语言
// 自定义菜单名称列渲染
columns[0].customRender = function ({text, record}) {
let displayText = text;
// update-begin--author:liaozhiyang---date:20240306---for:【QQYUN-8379】菜单管理页菜单国际化
// 先处理国际化,避免在添加默认首页标记后影响国际化检查
if (displayText && displayText.includes("t('") && t) {
try {
displayText = new Function('t', return ${displayText})(t);
} catch (error) {
console.warn('国际化处理失败:', error);
// 如果国际化处理失败,使用原始文本
displayText = text;
}
}
// update-end--author:liaozhiyang---date:20240306---for:【QQYUN-8379】菜单管理页菜单国际化
// 在国际化处理完成后,再添加默认首页标记
const isDefIndex = checkDefIndex(record);
if (isDefIndex) {
displayText += (${t('routes.basic.defaultHomePage')});
}
return displayText;
}
zy
最新开源版本,经测试没复现。还有更详细的信息吗?
已修复,下一版本发布。 修复方案同 @doubleHao2