diff --git a/src/layout/navBars/tagsView/tagsView.vue b/src/layout/navBars/tagsView/tagsView.vue
index 100a071daa5947c861090f62dfb82c0cc7b274fc..f971a7c8c7f1f2841f3e00cf6466ca9f3ec945ab 100644
--- a/src/layout/navBars/tagsView/tagsView.vue
+++ b/src/layout/navBars/tagsView/tagsView.vue
@@ -19,7 +19,7 @@
- {{ v.meta.title.indexOf('message') > -1 ? $t(v.meta.title) : v.query ? v.query.tagsViewName : v.params.tagsViewName }}
+ {{ other.getTitle(v) }}
{
- let webTitle = '';
- let globalTitle: string = themeConfig.value.globalTitle;
- router.currentRoute.value.path === '/login'
- ? (webTitle = router.currentRoute.value.meta.title as any)
- : (webTitle = i18n.global.t(router.currentRoute.value.meta.title as any));
- document.title = `${webTitle} - ${globalTitle}` || globalTitle;
+ const {
+ meta: { title },
+ fullPath,
+ } = router.currentRoute.value;
+ const customPath = decodeURI(fullPath);
+ const customTitle = i18n.global.te(customPath) ? i18n.global.t(customPath) : '';
+ const globalTitle: string = themeConfig.value.globalTitle;
+ const pageTitle = i18n.global.t(title as string);
+
+ const webTitle = customTitle || pageTitle;
+
+ document.title = webTitle ? `${webTitle} - ${globalTitle}` : globalTitle;
+ });
+}
+const CUSTOM_PAGE_TITLE = 'CUSTOM_PAGE_TITLE';
+
+interface ITitleI18n {
+ [key: string]: string;
+}
+interface ITitleI18nObj {
+ [routeName: string]: ITitleI18n | string;
+}
+
+/*
+ * 初始化 自定义页面标题
+ */
+export function initCustomTitle(): void {
+ const data: ITitleI18nObj = Local.get(CUSTOM_PAGE_TITLE) || {};
+ Object.entries(data).forEach(([k, v]) => {
+ const type = typeof v;
+ if (type === 'string') {
+ const currentLocale = i18n.global.locale;
+ i18n.global.setLocaleMessage(currentLocale, {
+ ...i18n.global.messages[currentLocale],
+ [k]: v,
+ });
+ } else if (type === 'object') {
+ Object.entries(v).forEach(([lang, title]) => {
+ i18n.global.setLocaleMessage(lang, {
+ ...i18n.global.messages[lang],
+ [k]: title,
+ });
+ });
+ }
});
}
+/*
+ * 设置页面标题 存放再Local中.
+ * @param title 支持string 和 国际化语言 对应kv值
+ * @param routeName 路由名称 可选 不传使用当前路由fullPath
+ * @example setTitle('页面标题') || setTitle({'zh-cn':'页面标题', 'en':'page title'})
+ */
+export function setTitle(title: ITitleI18n | string, path?: string): void {
+ let { fullPath: key } = router.currentRoute.value;
+ key = decodeURI(path || key);
+ const data: ITitleI18nObj = Local.get(CUSTOM_PAGE_TITLE) || {};
+ const type = typeof title;
+
+ if (type === 'string') {
+ const currentLocale = i18n.global.locale;
+ i18n.global.setLocaleMessage(currentLocale, {
+ ...i18n.global.messages[currentLocale],
+ [key]: title,
+ });
+ } else if (type === 'object') {
+ Object.entries(title).map(([k, v]) => {
+ i18n.global.setLocaleMessage(k, {
+ ...i18n.global.messages[k],
+ [key]: v,
+ });
+ });
+ }
+ data[key] = title;
+ Local.set(CUSTOM_PAGE_TITLE, data);
+}
+
+/*
+ * 获取页面标题
+ * @param route 路由对象
+ */
+export function getTitle(route: any): string {
+ // v.meta.title.indexOf('message') > -1 ? $t(v.meta.title) : v.query ? v.query.tagsViewName : v.params.tagsViewName;
+ const {
+ path,
+ query,
+ meta: { title },
+ } = route;
+ let key = path;
+ if (query) {
+ let res: string = '';
+ Object.entries(query).map(([k, v]) => {
+ res += `${k}=${v}&`;
+ });
+ res = res.replace(/&$/, '');
+ key += res ? `?${res}` : '';
+ }
+
+ const customTitle = i18n.global.te(key) ? i18n.global.t(key) : '';
+ return customTitle || i18n.global.t(title);
+}
+
/**
* 图片懒加载
* @param el dom 目标元素
@@ -163,6 +257,8 @@ const other = {
handleEmpty: (list: any) => {
return handleEmpty(list);
},
+ setTitle,
+ getTitle,
};
// 统一批量导出
diff --git a/src/views/params/common/index.vue b/src/views/params/common/index.vue
index 48fb4dec79e6f588cbca364dc9181ce96391e1f8..dc282060062b8dd664251e2cfa90170948fa7a3c 100644
--- a/src/views/params/common/index.vue
+++ b/src/views/params/common/index.vue
@@ -16,12 +16,12 @@