完善路由配置,title支持模板语法形式引入多语言配置

This commit is contained in:
zhigang.li@tendcloud.com 2018-11-01 18:26:54 +08:00
parent e23bafc75a
commit 096c1db65f
9 changed files with 32 additions and 14 deletions

View File

@ -9,7 +9,7 @@
</div>
</template>
<script>
import { showTitle } from '_c/common/util'
import { showTitle } from '@/libs/util'
import CommonIcon from '_c/common-icon'
import './custom-bread-crumb.less'
export default {

View File

@ -1,11 +1,12 @@
import CommonIcon from '_c/common-icon'
import { showTitle } from '@/libs/util'
export default {
components: {
CommonIcon
},
methods: {
showTitle (item) {
return this.$config.useI18n ? this.$t(item.name) : ((item.meta && item.meta.title) || item.name)
return showTitle(item, this)
},
showChildren (item) {
return item.children && (item.children.length > 1 || (item.meta && item.meta.showAlways))

View File

@ -26,7 +26,7 @@ export default {
plugin: {
'error-store': {
showInHeader: true, // 设为false后不会在顶部显示错误日志徽标
developmentOff: false // 设为true后在开发环境不会收集错误信息方便开发中排查错误
developmentOff: true // 设为true后在开发环境不会收集错误信息方便开发中排查错误
}
}
}

View File

@ -74,15 +74,27 @@ export const getBreadCrumbList = (route, homeRoute) => {
return [{...homeItem, to: homeRoute.path}, ...res]
}
export const getRouteTitleHandled = route => {
export const getRouteTitleHandled = (route) => {
let router = {...route}
let meta = {...route.meta}
if (meta.title && typeof meta.title === 'function') meta.title = meta.title(router)
let title = ''
if (meta.title) {
if (typeof meta.title === 'function') title = meta.title(router)
else title = meta.title
}
meta.title = title
router.meta = meta
return router
}
export const showTitle = (item, vm) => vm.$config.useI18n ? vm.$t(item.name) : ((item.meta && item.meta.title) || item.name)
export const showTitle = (item, vm) => {
let title = item.meta.title
if (vm.$config.useI18n) {
if (title.includes('{{') && title.includes('}}') && vm.$config.useI18n) title = title.replace(/({{[\s\S]+?}})/, (m, str) => str.replace(/{{([\s\S]*)}}/, (m, _) => vm.$t(_.trim())))
else title = vm.$t(item.name)
} else title = (item.meta && item.meta.title) || item.name
return title
}
/**
* @description 本地存储和获取标签导航列表

View File

@ -32,5 +32,7 @@ export default {
buttonText: 'Show Modal',
'i18n-tip': 'Note: Only this page is multi-language, other pages do not add language content to the multi-language package.',
error_store_page: 'Error Collection',
error_logger_page: 'Error Logger'
error_logger_page: 'Error Logger',
query: 'Query',
params: 'Params'
}

View File

@ -32,6 +32,7 @@ export default {
buttonText: '显示模态框',
'i18n-tip': '注:仅此页做了多语言,其他页面没有在多语言包中添加语言内容',
error_store_page: '错误收集',
error_logger_page: '错误日志'
error_logger_page: '错误日志',
query: '带参路由',
params: '动态路由'
}

View File

@ -32,5 +32,7 @@ export default {
buttonText: '顯示模態框',
'i18n-tip': '注:僅此頁做了多語言,其他頁面沒有在多語言包中添加語言內容',
error_store_page: '錯誤收集',
error_logger_page: '錯誤日誌'
error_logger_page: '錯誤日誌',
query: '帶參路由',
params: '動態路由'
}

View File

@ -4,6 +4,7 @@ import parentView from '@/components/parent-view'
/**
* iview-admin中meta除了原生参数外可配置的参数:
* meta: {
* title: { String|Number|Function } 显示在侧边栏和
* hideInMenu: (false) 设为true后在左侧菜单不会显示该页面选项
* notCache: (false) 设为true后页面不会缓存
* access: (null) 可访问该页面的权限数组当前路由设置的权限会影响子路由
@ -235,7 +236,7 @@ export default [
name: 'i18n_page',
meta: {
icon: 'md-planet',
title: '国际化'
title: 'i18n - {{ i18n_page }}'
},
component: () => import('@/view/i18n/i18n-page.vue')
}
@ -363,7 +364,7 @@ export default [
name: 'params',
meta: {
icon: 'md-flower',
title: route => `动态路由-${route.params.id}`,
title: route => `{{ params }}-${route.params.id}`,
notCache: true,
beforeCloseName: 'before_close_normal'
},
@ -374,7 +375,7 @@ export default [
name: 'query',
meta: {
icon: 'md-flower',
title: route => `带参路由-${route.query.id}`,
title: route => `{{ query }}-${route.query.id}`,
notCache: true
},
component: () => import('@/view/argu-page/query.vue')

View File

@ -39,7 +39,6 @@ export default {
name: 'tools_methods_page',
methods: {
...mapMutations([
'addTag',
'closeTag'
]),
createTagParams () {