Skip to content

Commit 5dc05f9

Browse files
committed
cleanup
fix: multi-tab add rename(key,name)
1 parent aadb1a1 commit 5dc05f9

File tree

9 files changed

+119
-15
lines changed

9 files changed

+119
-15
lines changed

babel.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV)
2+
3+
const plugins = []
4+
if (IS_PROD) {
5+
plugins.push('transform-remove-console')
6+
}
7+
18
module.exports = {
29
presets: [
310
'@vue/app',
@@ -7,7 +14,8 @@ module.exports = {
714
'useBuiltIns': 'entry'
815
}
916
]
10-
]
17+
],
18+
plugins
1119
// if your use import on Demand, Use this code
1220
// ,
1321
// plugins: [

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"wangeditor": "^3.1.1"
3737
},
3838
"devDependencies": {
39-
"@ant-design/colors": "^3.1.0",
39+
"@ant-design/colors": "^3.2.1",
4040
"@babel/polyfill": "7.2.5",
4141
"@vue/cli-plugin-babel": "^3.11.0",
4242
"@vue/cli-plugin-eslint": "^3.11.0",
@@ -48,6 +48,7 @@
4848
"babel-eslint": "^10.0.3",
4949
"babel-jest": "^23.6.0",
5050
"babel-plugin-import": "^1.11.0",
51+
"babel-plugin-transform-remove-console": "^6.9.4",
5152
"eslint": "^5.8.0",
5253
"eslint-plugin-html": "^5.0.0",
5354
"eslint-plugin-vue": "^5.2.3",

src/components/MultiTab/MultiTab.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ export default {
2424
return
2525
}
2626
this.closeThat(val)
27+
}).$on('rename', ({ key, name }) => {
28+
console.log('rename', key, name)
29+
try {
30+
const item = this.pages.find(item => item.path === key)
31+
item.meta.customTitle = name
32+
this.$forceUpdate()
33+
} catch (e) {
34+
}
2735
})
2836
2937
this.pages.push(this.$route)
@@ -129,7 +137,7 @@ export default {
129137
return (
130138
<a-tab-pane
131139
style={{ height: 0 }}
132-
tab={this.renderTabPane(page.meta.title, page.fullPath)}
140+
tab={this.renderTabPane(page.meta.customTitle || page.meta.title, page.fullPath)}
133141
key={page.fullPath} closable={pages.length > 1}
134142
>
135143
</a-tab-pane>)

src/components/MultiTab/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const api = {
1010
open: function (config) {
1111
events.$emit('open', config)
1212
},
13+
rename: function (key, name) {
14+
events.$emit('rename', { key: key, name: name })
15+
},
1316
/**
1417
* close current page
1518
*/

src/config/router.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export const asyncRouterMap = [
3636
name: 'Workplace',
3737
component: () => import('@/views/dashboard/Workplace'),
3838
meta: { title: '工作台', keepAlive: true, permission: [ 'dashboard' ] }
39+
},
40+
{
41+
path: '/dashboard/test-work',
42+
name: 'TestWork',
43+
component: () => import('@/views/dashboard/TestWork'),
44+
meta: { title: '测试功能', keepAlive: true, permission: [ 'dashboard' ] }
3945
}
4046
]
4147
},

src/mock/services/user.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ const userNav = (options) => {
375375
// dashboard
376376
{
377377
'name': 'dashboard',
378-
'parentId': -1,
378+
'parentId': 0,
379379
'id': 1,
380380
'meta': {
381381
'icon': 'dashboard',
@@ -430,7 +430,7 @@ const userNav = (options) => {
430430
// form
431431
{
432432
'name': 'form',
433-
'parentId': -1,
433+
'parentId': 0,
434434
'id': 10,
435435
'meta': {
436436
'icon': 'form',
@@ -470,7 +470,7 @@ const userNav = (options) => {
470470
// list
471471
{
472472
'name': 'list',
473-
'parentId': -1,
473+
'parentId': 0,
474474
'id': 10010,
475475
'meta': {
476476
'icon': 'table',
@@ -556,7 +556,7 @@ const userNav = (options) => {
556556
// profile
557557
{
558558
'name': 'profile',
559-
'parentId': -1,
559+
'parentId': 0,
560560
'id': 10018,
561561
'meta': {
562562
'title': '详情页',
@@ -590,7 +590,7 @@ const userNav = (options) => {
590590
// result
591591
{
592592
'name': 'result',
593-
'parentId': -1,
593+
'parentId': 0,
594594
'id': 10021,
595595
'meta': {
596596
'title': '结果页',
@@ -626,7 +626,7 @@ const userNav = (options) => {
626626
// Exception
627627
{
628628
'name': 'exception',
629-
'parentId': -1,
629+
'parentId': 0,
630630
'id': 10024,
631631
'meta': {
632632
'title': '异常页',
@@ -670,7 +670,7 @@ const userNav = (options) => {
670670
// account
671671
{
672672
'name': 'account',
673-
'parentId': -1,
673+
'parentId': 0,
674674
'id': 10028,
675675
'meta': {
676676
'title': '个人页',
@@ -760,7 +760,9 @@ const userNav = (options) => {
760760
'component': 'NotificationSettings'
761761
}
762762
]
763-
return builder(nav)
763+
const json = builder(nav)
764+
console.log('json', json)
765+
return json
764766
}
765767

766768
Mock.mock(/\/api\/user\/info/, 'get', info)

src/router/generator-routers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const generatorDynamicRouter = (token) => {
8686
const menuNav = []
8787
const childrenNav = []
8888
// 后端数据, 根级树数组, 根级 PID
89-
listToTree(result, childrenNav, -1)
89+
listToTree(result, childrenNav, 0)
9090
rootRouter.children = childrenNav
9191
menuNav.push(rootRouter)
9292
console.log('menuNav', menuNav)
@@ -118,7 +118,7 @@ export const generator = (routerMap, parent) => {
118118
// 该路由对应页面的 组件 :方案1
119119
component: constantRouterComponents[item.component || item.key],
120120
// 该路由对应页面的 组件 :方案2 (动态加载)
121-
// component: () => import(`@/views/${item.component}`),
121+
// component: constantRouterComponents[item.component || item.key] || () => import(`@/views/${item.component}`),
122122

123123
// meta: 页面标题, 菜单图标, 页面权限(供指令权限用,可去掉)
124124
meta: { title: title, icon: icon || undefined, hiddenHeaderContent: hiddenHeaderContent, target: target, permission: item.name }

src/views/dashboard/TestWork.vue

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,38 @@
55
<div class="multi-tab-test">
66
<h4>多标签组件测试功能</h4>
77
<a-button @click="handleCloseCurrentTab" style="margin-right: 16px;">关闭当前页</a-button>
8-
<a-button @click="handleOpenTab">打开 任务列表</a-button>
9-
<a-input ref="tInput" />
8+
<a-button @click="handleOpenTab" style="margin-right: 16px;">打开 任务列表</a-button>
9+
<a-popconfirm :visible="visible" @confirm="confirm" @cancel="cancel" okText="确定" cancelText="取消">
10+
<template v-slot:title>
11+
<div>
12+
<a-form :form="form" layout="inline">
13+
<a-form-item label="自定义名称">
14+
<a-input v-decorator="['tabName', {rules: [{required: true, message: '请输入新的 Tab 名称'}]}]"/>
15+
</a-form-item>
16+
</a-form>
17+
</div>
18+
</template>
19+
<a-button @click="() => visible = !visible" style="margin-right: 16px;">修改当前 Tab 名称</a-button>
20+
</a-popconfirm>
21+
22+
<a-popconfirm :visible="visible2" @confirm="confirm2" @cancel="() => visible2 = false" okText="确定" cancelText="取消">
23+
<template v-slot:title>
24+
<div>
25+
<p>页面 KEY 是由页面的路由 <code>path</code> 决定的</p>
26+
<p>如果要修改某一个页面标题,该页面必须已经被打开在 Tab 栏</p>
27+
<p>后期可以考虑优化到编程式 Tab 栏,就可以没有这种限制</p>
28+
<a-form :form="form2" layout="inline">
29+
<a-form-item label="页面KEY">
30+
<a-input v-decorator="['tabKey', { initialValue: '/dashboard/workplace' }]" />
31+
</a-form-item>
32+
<a-form-item label="自定义名称">
33+
<a-input v-decorator="['tabName', {rules: [{required: true, message: '请输入新的 Tab 名称'}]}]"/>
34+
</a-form-item>
35+
</a-form>
36+
</div>
37+
</template>
38+
<a-button @click="() => visible2 = !visible2">修改某一个 Tab 名称</a-button>
39+
</a-popconfirm>
1040
</div>
1141
<a-divider />
1242
<div class="page-loading-test">
@@ -20,6 +50,16 @@
2050
<script>
2151
export default {
2252
name: 'TestWork',
53+
data () {
54+
return {
55+
visible: false,
56+
visible2: false
57+
}
58+
},
59+
created () {
60+
this.form = this.$form.createForm(this)
61+
this.form2 = this.$form.createForm(this)
62+
},
2363
methods: {
2464
handleCloseCurrentTab () {
2565
this.$multiTab.closeCurrentPage() // or this.$multiTab.close()
@@ -43,6 +83,30 @@ export default {
4383
setTimeout(() => {
4484
this.$loading.hide()
4585
}, 5000)
86+
},
87+
88+
// confirm
89+
confirm (e) {
90+
e.stopPropagation()
91+
const { path } = this.$route
92+
this.form.validateFields((err, values) => {
93+
if (!err) {
94+
this.$multiTab.rename(path, values.tabName)
95+
this.visible = false
96+
}
97+
})
98+
},
99+
cancel () {
100+
this.visible = false
101+
},
102+
confirm2 (e) {
103+
e.stopPropagation()
104+
this.form2.validateFields((err, values) => {
105+
if (!err) {
106+
this.$multiTab.rename(values.tabKey, values.tabName)
107+
this.visible2 = false
108+
}
109+
})
46110
}
47111
}
48112
}

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
dependencies:
1010
tinycolor2 "^1.4.1"
1111

12+
"@ant-design/colors@^3.2.1":
13+
version "3.2.1"
14+
resolved "https://registry.yarnpkg.com/@ant-design/colors/-/colors-3.2.1.tgz#ad86cbf2d1a0039d01586aa73a7ea8a7ce0455a2"
15+
integrity sha512-ibJybOcR1+h2IEr0Yxx4y/Wcz8obEtKvl2EYvxh8ugMkYniGSItpLKGzKNyyqzOaum5jb6fVCyH1aR9VkdpFRA==
16+
dependencies:
17+
tinycolor2 "^1.4.1"
18+
1219
"@ant-design/icons-vue@^2.0.0":
1320
version "2.0.0"
1421
resolved "https://registry.npm.taobao.org/@ant-design/icons-vue/download/@ant-design/icons-vue-2.0.0.tgz#0357f5010a404e9f34a87a4b41b2a08df691dbce"
@@ -2064,6 +2071,11 @@ babel-plugin-transform-es2015-modules-commonjs@^6.26.0, babel-plugin-transform-e
20642071
babel-template "^6.26.0"
20652072
babel-types "^6.26.0"
20662073

2074+
babel-plugin-transform-remove-console@^6.9.4:
2075+
version "6.9.4"
2076+
resolved "https://registry.yarnpkg.com/babel-plugin-transform-remove-console/-/babel-plugin-transform-remove-console-6.9.4.tgz#b980360c067384e24b357a588d807d3c83527780"
2077+
integrity sha1-uYA2DAZzhOJLNXpYjYB9PINSd4A=
2078+
20672079
babel-plugin-transform-strict-mode@^6.24.1:
20682080
version "6.24.1"
20692081
resolved "https://registry.npmjs.org/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758"

0 commit comments

Comments
 (0)