Skip to content

Commit 84e10d6

Browse files
author
Lison
authored
Merge pull request #1062 from iview/2.0
2.0
2 parents 614c0bf + c45d437 commit 84e10d6

File tree

9 files changed

+35
-14
lines changed

9 files changed

+35
-14
lines changed

src/components/main/components/header-bar/custom-bread-crumb/custom-bread-crumb.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</div>
1010
</template>
1111
<script>
12-
import { showTitle } from '_c/common/util'
12+
import { showTitle } from '@/libs/util'
1313
import CommonIcon from '_c/common-icon'
1414
import './custom-bread-crumb.less'
1515
export default {

src/components/main/components/side-menu/mixin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import CommonIcon from '_c/common-icon'
2+
import { showTitle } from '@/libs/util'
23
export default {
34
components: {
45
CommonIcon
56
},
67
methods: {
78
showTitle (item) {
8-
return this.$config.useI18n ? this.$t(item.name) : ((item.meta && item.meta.title) || item.name)
9+
return showTitle(item, this)
910
},
1011
showChildren (item) {
1112
return item.children && (item.children.length > 1 || (item.meta && item.meta.showAlways))

src/config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626
plugin: {
2727
'error-store': {
2828
showInHeader: true, // 设为false后不会在顶部显示错误日志徽标
29-
developmentOff: false // 设为true后在开发环境不会收集错误信息,方便开发中排查错误
29+
developmentOff: true // 设为true后在开发环境不会收集错误信息,方便开发中排查错误
3030
}
3131
}
3232
}

src/libs/util.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,27 @@ export const getBreadCrumbList = (route, homeRoute) => {
7474
return [{...homeItem, to: homeRoute.path}, ...res]
7575
}
7676

77-
export const getRouteTitleHandled = route => {
77+
export const getRouteTitleHandled = (route) => {
7878
let router = {...route}
7979
let meta = {...route.meta}
80-
if (meta.title && typeof meta.title === 'function') meta.title = meta.title(router)
80+
let title = ''
81+
if (meta.title) {
82+
if (typeof meta.title === 'function') title = meta.title(router)
83+
else title = meta.title
84+
}
85+
meta.title = title
8186
router.meta = meta
8287
return router
8388
}
8489

85-
export const showTitle = (item, vm) => vm.$config.useI18n ? vm.$t(item.name) : ((item.meta && item.meta.title) || item.name)
90+
export const showTitle = (item, vm) => {
91+
let title = item.meta.title
92+
if (vm.$config.useI18n) {
93+
if (title.includes('{{') && title.includes('}}') && vm.$config.useI18n) title = title.replace(/({{[\s\S]+?}})/, (m, str) => str.replace(/{{([\s\S]*)}}/, (m, _) => vm.$t(_.trim())))
94+
else title = vm.$t(item.name)
95+
} else title = (item.meta && item.meta.title) || item.name
96+
return title
97+
}
8698

8799
/**
88100
* @description 本地存储和获取标签导航列表

src/locale/lang/en-US.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ export default {
3232
buttonText: 'Show Modal',
3333
'i18n-tip': 'Note: Only this page is multi-language, other pages do not add language content to the multi-language package.',
3434
error_store_page: 'Error Collection',
35-
error_logger_page: 'Error Logger'
35+
error_logger_page: 'Error Logger',
36+
query: 'Query',
37+
params: 'Params'
3638
}

src/locale/lang/zh-CN.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default {
3232
buttonText: '显示模态框',
3333
'i18n-tip': '注:仅此页做了多语言,其他页面没有在多语言包中添加语言内容',
3434
error_store_page: '错误收集',
35-
error_logger_page: '错误日志'
36-
35+
error_logger_page: '错误日志',
36+
query: '带参路由',
37+
params: '动态路由'
3738
}

src/locale/lang/zh-TW.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ export default {
3232
buttonText: '顯示模態框',
3333
'i18n-tip': '注:僅此頁做了多語言,其他頁面沒有在多語言包中添加語言內容',
3434
error_store_page: '錯誤收集',
35-
error_logger_page: '錯誤日誌'
35+
error_logger_page: '錯誤日誌',
36+
query: '帶參路由',
37+
params: '動態路由'
3638
}

src/router/routers.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import parentView from '@/components/parent-view'
44
/**
55
* iview-admin中meta除了原生参数外可配置的参数:
66
* meta: {
7+
* title: { String|Number|Function }
8+
* 显示在侧边栏、面包屑和标签栏的文字
9+
* 使用'{{ 多语言字段 }}'形式结合多语言使用,例子看多语言的路由配置;
10+
* 可以传入一个回调函数,参数是当前路由对象,例子看动态路由和带参路由
711
* hideInMenu: (false) 设为true后在左侧菜单不会显示该页面选项
812
* notCache: (false) 设为true后页面不会缓存
913
* access: (null) 可访问该页面的权限数组,当前路由设置的权限会影响子路由
@@ -235,7 +239,7 @@ export default [
235239
name: 'i18n_page',
236240
meta: {
237241
icon: 'md-planet',
238-
title: '国际化'
242+
title: 'i18n - {{ i18n_page }}'
239243
},
240244
component: () => import('@/view/i18n/i18n-page.vue')
241245
}
@@ -363,7 +367,7 @@ export default [
363367
name: 'params',
364368
meta: {
365369
icon: 'md-flower',
366-
title: route => `动态路由-${route.params.id}`,
370+
title: route => `{{ params }}-${route.params.id}`,
367371
notCache: true,
368372
beforeCloseName: 'before_close_normal'
369373
},
@@ -374,7 +378,7 @@ export default [
374378
name: 'query',
375379
meta: {
376380
icon: 'md-flower',
377-
title: route => `带参路由-${route.query.id}`,
381+
title: route => `{{ query }}-${route.query.id}`,
378382
notCache: true
379383
},
380384
component: () => import('@/view/argu-page/query.vue')

src/view/tools-methods/tools-methods.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default {
3939
name: 'tools_methods_page',
4040
methods: {
4141
...mapMutations([
42-
'addTag',
4342
'closeTag'
4443
]),
4544
createTagParams () {

0 commit comments

Comments
 (0)