Skip to content

Commit a1a96c3

Browse files
committed
add tabs example
1 parent 2927e08 commit a1a96c3

File tree

3 files changed

+148
-3
lines changed

3 files changed

+148
-3
lines changed

Diff for: src/router/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const DragTable = () => import('../views/example/table/dragTable');
5858
const InlineEditTable = () => import('../views/example/table/inlineEditTable');
5959

6060
const Form = () => import('../views/example/form');
61+
const Tab = () => import('../views/example/tab/index');
6162

6263
/* permission */
6364
const Permission = () => import('../views/permission/index');
@@ -198,16 +199,18 @@ export const asyncRouterMap = [
198199
path: '/table',
199200
component: TableLayout,
200201
redirect: '/table/table',
201-
name: 'table',
202+
name: 'Table',
202203
children: [
203204
{ path: 'dynamictable', component: DynamicTable, name: '动态table' },
204205
{ path: 'dragtable', component: DragTable, name: '拖拽table' },
205206
{ path: 'inline_edit_table', component: InlineEditTable, name: 'table内编辑' },
206207
{ path: 'table', component: Table, name: '综合table' }
207208
]
208209
},
209-
{ path: 'form/edit', component: Form, name: '编辑form', meta: { isEdit: true } },
210-
{ path: 'form/create', component: Form, name: '创建form' }
210+
{ path: 'form/edit', component: Form, name: '编辑Form', meta: { isEdit: true } },
211+
{ path: 'form/create', component: Form, name: '创建Form' },
212+
213+
{ path: 'tab/index', component: Tab, name: 'Tab' }
211214
]
212215
},
213216
{ path: '*', redirect: '/404', hidden: true }

Diff for: src/views/example/tab/components/tabPane.vue

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<template>
2+
<el-table :data="list" border fit highlight-current-row style="width: 100%">
3+
4+
<el-table-column align="center" label="序号" width="65">
5+
<template scope="scope">
6+
<span>{{scope.row.id}}</span>
7+
</template>
8+
</el-table-column>
9+
10+
<el-table-column width="180px" align="center" label="时间">
11+
<template scope="scope">
12+
<span>{{scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
13+
</template>
14+
</el-table-column>
15+
16+
<el-table-column min-width="300px" label="标题">
17+
<template scope="scope">
18+
<span class="link-type" @click="handleUpdate(scope.row)">{{scope.row.title}}</span>
19+
<el-tag>{{scope.row.type}}</el-tag>
20+
</template>
21+
</el-table-column>
22+
23+
<el-table-column width="110px" align="center" label="作者">
24+
<template scope="scope">
25+
<span>{{scope.row.author}}</span>
26+
</template>
27+
</el-table-column>
28+
29+
<el-table-column width="80px" label="重要性">
30+
<template scope="scope">
31+
<wscn-icon-svg v-for="n in +scope.row.importance" icon-class="wujiaoxing" class="meta-item__icon" :key="n" />
32+
</template>
33+
</el-table-column>
34+
35+
<el-table-column align="center" label="阅读数" width="95">
36+
<template scope="scope">
37+
<span>{{scope.row.pageviews}}</span>
38+
</template>
39+
</el-table-column>
40+
41+
<el-table-column class-name="status-col" label="状态" width="90">
42+
<template scope="scope">
43+
<el-tag :type="scope.row.status | statusFilter">{{scope.row.status}}</el-tag>
44+
</template>
45+
</el-table-column>
46+
47+
</el-table>
48+
</template>
49+
50+
<script>
51+
import { fetchList } from 'api/article_table';
52+
53+
export default {
54+
name: 'articleDetail',
55+
props: {
56+
type: {
57+
type: String,
58+
default: 'CN'
59+
}
60+
},
61+
data() {
62+
return {
63+
list: null,
64+
total: null,
65+
listQuery: {
66+
page: 1,
67+
limit: 5,
68+
type: this.type,
69+
sort: '+id'
70+
}
71+
}
72+
},
73+
filters: {
74+
statusFilter(status) {
75+
const statusMap = {
76+
published: 'success',
77+
draft: 'gray',
78+
deleted: 'danger'
79+
};
80+
return statusMap[status]
81+
}
82+
},
83+
created() {
84+
this.getList();
85+
},
86+
methods: {
87+
getList() {
88+
this.$emit('create'); // for test
89+
90+
fetchList(this.listQuery).then(response => {
91+
this.list = response.data.items;
92+
this.total = response.data.total;
93+
})
94+
}
95+
}
96+
}
97+
</script>
98+

Diff for: src/views/example/tab/index.vue

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<template>
2+
<div class="tab-container">
3+
<el-tag type="primary">create times :{{createdTimes}}</el-tag>
4+
<el-tabs style='margin-top:15px;' v-model="activeName" type="border-card">
5+
<el-tab-pane v-for="item in tabMapOptions" :label="item.label" :key='item.key' :name="item.key">
6+
<keep-alive>
7+
<tab-pane v-if='activeName==item.key' :type='item.key' @create='showCreatedTimes'></tab-pane>
8+
</keep-alive>
9+
</el-tab-pane>
10+
</el-tabs>
11+
</div>
12+
</template>
13+
14+
<script>
15+
import tabPane from './components/tabPane'
16+
17+
export default {
18+
name: 'tabDemo',
19+
components: { tabPane },
20+
data() {
21+
return {
22+
tabMapOptions: [
23+
{ label: '中国', key: 'CN' },
24+
{ label: '美国', key: 'US' },
25+
{ label: '日本', key: 'JP' },
26+
{ label: '欧元区', key: 'EU' }
27+
],
28+
activeName: 'CN',
29+
createdTimes: 0
30+
}
31+
},
32+
methods: {
33+
showCreatedTimes() {
34+
this.createdTimes = this.createdTimes + 1;
35+
}
36+
}
37+
}
38+
</script>
39+
40+
<style scoped>
41+
.tab-container{
42+
margin: 30px;
43+
}
44+
</style>

0 commit comments

Comments
 (0)