5
5
<div class =" multi-tab-test" >
6
6
<h4 >多标签组件测试功能</h4 >
7
7
<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 >
10
40
</div >
11
41
<a-divider />
12
42
<div class =" page-loading-test" >
20
50
<script >
21
51
export default {
22
52
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
+ },
23
63
methods: {
24
64
handleCloseCurrentTab () {
25
65
this .$multiTab .closeCurrentPage () // or this.$multiTab.close()
@@ -43,6 +83,30 @@ export default {
43
83
setTimeout (() => {
44
84
this .$loading .hide ()
45
85
}, 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
+ })
46
110
}
47
111
}
48
112
}
0 commit comments