提交 | 用户 | 时间
|
759b1c
|
1 |
<template> |
H |
2 |
<div class="top-right-btn" :style="style"> |
|
3 |
<el-row> |
|
4 |
<el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top" v-if="search"> |
|
5 |
<el-button size="mini" circle icon="el-icon-search" @click="toggleSearch()" /> |
|
6 |
</el-tooltip> |
|
7 |
<el-tooltip class="item" effect="dark" content="刷新" placement="top"> |
|
8 |
<el-button size="mini" circle icon="el-icon-refresh" @click="refresh()" /> |
|
9 |
</el-tooltip> |
|
10 |
<el-tooltip class="item" effect="dark" content="显隐列" placement="top" v-if="columns"> |
|
11 |
<el-button size="mini" circle icon="el-icon-menu" @click="showColumn()" /> |
|
12 |
</el-tooltip> |
|
13 |
</el-row> |
|
14 |
<el-dialog :title="title" :visible.sync="open" append-to-body> |
|
15 |
<el-transfer |
|
16 |
:titles="['显示', '隐藏']" |
|
17 |
v-model="value" |
|
18 |
:data="columns" |
|
19 |
@change="dataChange" |
|
20 |
></el-transfer> |
|
21 |
</el-dialog> |
|
22 |
</div> |
|
23 |
</template> |
|
24 |
<script> |
|
25 |
export default { |
|
26 |
name: "RightToolbar", |
|
27 |
data() { |
|
28 |
return { |
|
29 |
// 显隐数据 |
|
30 |
value: [], |
|
31 |
// 弹出层标题 |
|
32 |
title: "显示/隐藏", |
|
33 |
// 是否显示弹出层 |
|
34 |
open: false, |
|
35 |
}; |
|
36 |
}, |
|
37 |
props: { |
|
38 |
showSearch: { |
|
39 |
type: Boolean, |
|
40 |
default: true, |
|
41 |
}, |
|
42 |
columns: { |
|
43 |
type: Array, |
|
44 |
}, |
|
45 |
search: { |
|
46 |
type: Boolean, |
|
47 |
default: true, |
|
48 |
}, |
|
49 |
gutter: { |
|
50 |
type: Number, |
|
51 |
default: 10, |
|
52 |
}, |
|
53 |
}, |
|
54 |
computed: { |
|
55 |
style() { |
|
56 |
const ret = {}; |
|
57 |
if (this.gutter) { |
|
58 |
ret.marginRight = `${this.gutter / 2}px`; |
|
59 |
} |
|
60 |
return ret; |
|
61 |
} |
|
62 |
}, |
|
63 |
created() { |
|
64 |
// 显隐列初始默认隐藏列 |
|
65 |
for (let item in this.columns) { |
|
66 |
if (this.columns[item].visible === false) { |
|
67 |
this.value.push(parseInt(item)); |
|
68 |
} |
|
69 |
} |
|
70 |
}, |
|
71 |
methods: { |
|
72 |
// 搜索 |
|
73 |
toggleSearch() { |
|
74 |
this.$emit("update:showSearch", !this.showSearch); |
|
75 |
}, |
|
76 |
// 刷新 |
|
77 |
refresh() { |
|
78 |
this.$emit("queryTable"); |
|
79 |
}, |
|
80 |
// 右侧列表元素变化 |
|
81 |
dataChange(data) { |
|
82 |
for (let item in this.columns) { |
|
83 |
const key = this.columns[item].key; |
|
84 |
this.columns[item].visible = !data.includes(key); |
|
85 |
} |
|
86 |
}, |
|
87 |
// 打开显隐列dialog |
|
88 |
showColumn() { |
|
89 |
this.open = true; |
|
90 |
}, |
|
91 |
}, |
|
92 |
}; |
|
93 |
</script> |
|
94 |
<style lang="scss" scoped> |
|
95 |
:deep(.el-transfer__button) { |
|
96 |
border-radius: 50%; |
|
97 |
padding: 12px; |
|
98 |
display: block; |
|
99 |
margin-left: 0px; |
|
100 |
} |
|
101 |
:deep(.el-transfer__button:first-child) { |
|
102 |
margin-bottom: 10px; |
|
103 |
} |
|
104 |
</style> |