Skip to content

Commit

Permalink
Merge pull request #1062 from iview/2.0
Browse files Browse the repository at this point in the history
2.0
  • Loading branch information
Lison authored Nov 1, 2018
2 parents 614c0bf + c45d437 commit 84e10d6
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/components/main/components/side-menu/mixin.js
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
plugin: {
'error-store': {
showInHeader: true, // 设为false后不会在顶部显示错误日志徽标
developmentOff: false // 设为true后在开发环境不会收集错误信息,方便开发中排查错误
developmentOff: true // 设为true后在开发环境不会收集错误信息,方便开发中排查错误
}
}
}
18 changes: 15 additions & 3 deletions src/libs/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 本地存储和获取标签导航列表
Expand Down
4 changes: 3 additions & 1 deletion src/locale/lang/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
5 changes: 3 additions & 2 deletions src/locale/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default {
buttonText: '显示模态框',
'i18n-tip': '注:仅此页做了多语言,其他页面没有在多语言包中添加语言内容',
error_store_page: '错误收集',
error_logger_page: '错误日志'

error_logger_page: '错误日志',
query: '带参路由',
params: '动态路由'
}
4 changes: 3 additions & 1 deletion src/locale/lang/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ export default {
buttonText: '顯示模態框',
'i18n-tip': '注:僅此頁做了多語言,其他頁面沒有在多語言包中添加語言內容',
error_store_page: '錯誤收集',
error_logger_page: '錯誤日誌'
error_logger_page: '錯誤日誌',
query: '帶參路由',
params: '動態路由'
}
10 changes: 7 additions & 3 deletions src/router/routers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import parentView from '@/components/parent-view'
/**
* iview-admin中meta除了原生参数外可配置的参数:
* meta: {
* title: { String|Number|Function }
* 显示在侧边栏、面包屑和标签栏的文字
* 使用'{{ 多语言字段 }}'形式结合多语言使用,例子看多语言的路由配置;
* 可以传入一个回调函数,参数是当前路由对象,例子看动态路由和带参路由
* hideInMenu: (false) 设为true后在左侧菜单不会显示该页面选项
* notCache: (false) 设为true后页面不会缓存
* access: (null) 可访问该页面的权限数组,当前路由设置的权限会影响子路由
Expand Down Expand Up @@ -235,7 +239,7 @@ export default [
name: 'i18n_page',
meta: {
icon: 'md-planet',
title: '国际化'
title: 'i18n - {{ i18n_page }}'
},
component: () => import('@/view/i18n/i18n-page.vue')
}
Expand Down Expand Up @@ -363,7 +367,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'
},
Expand All @@ -374,7 +378,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')
Expand Down
1 change: 0 additions & 1 deletion src/view/tools-methods/tools-methods.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default {
name: 'tools_methods_page',
methods: {
...mapMutations([
'addTag',
'closeTag'
]),
createTagParams () {
Expand Down

0 comments on commit 84e10d6

Please sign in to comment.