Skip to content

Commit 9adf80c

Browse files
author
puhui999
committed
add: 改造vue2中的RightToolbar到vue3中
1 parent 7697e5c commit 9adf80c

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

src/components/RightToolbar/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import RightToolbar from './src/index.vue'
2+
3+
export interface columnsType {
4+
key?: number
5+
label?: string
6+
visible?: boolean
7+
}
8+
9+
export { RightToolbar }
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<template>
2+
<div :style="style">
3+
<el-row justify="end">
4+
<el-tooltip
5+
class="item"
6+
effect="dark"
7+
:content="showSearch ? '隐藏搜索' : '显示搜索'"
8+
placement="top"
9+
v-if="search"
10+
>
11+
<el-button circle @click="toggleSearch()">
12+
<Icon icon="ep:search" />
13+
</el-button>
14+
</el-tooltip>
15+
<el-tooltip class="item" effect="dark" content="刷新" placement="top">
16+
<el-button circle @click="refresh()">
17+
<Icon icon="ep:refresh" />
18+
</el-button>
19+
</el-tooltip>
20+
<el-tooltip class="item" effect="dark" content="显隐列" placement="top" v-if="isColumns">
21+
<el-button circle @click="showColumn()">
22+
<Icon icon="ep:menu" />
23+
</el-button>
24+
</el-tooltip>
25+
</el-row>
26+
<el-dialog :title="title" v-model="open" append-to-body>
27+
<el-transfer
28+
:titles="['显示', '隐藏']"
29+
v-model="value"
30+
:data="columns"
31+
@change="dataChange"
32+
/>
33+
</el-dialog>
34+
</div>
35+
</template>
36+
<script lang="ts" setup name="RightToolbar">
37+
import type { CSSProperties } from 'vue'
38+
import type { columnsType } from '@/components/RightToolbar'
39+
import { propTypes } from '@/utils/propTypes'
40+
// 显隐数据
41+
const value = ref<number[]>([])
42+
// 弹出层标题
43+
const title = ref('显示/隐藏')
44+
// 是否显示弹出层
45+
const open = ref(false)
46+
47+
const props = defineProps({
48+
showSearch: propTypes.bool.def(true),
49+
columns: {
50+
type: Array as PropType<columnsType[]>,
51+
default: () => []
52+
},
53+
search: propTypes.bool.def(true),
54+
gutter: propTypes.number.def(10)
55+
})
56+
const isColumns = computed(() => props.columns?.length > 0)
57+
const style = computed((): CSSProperties => {
58+
const ret: CSSProperties = {}
59+
if (props.gutter) {
60+
ret.marginRight = `${props.gutter / 2}px`
61+
}
62+
return ret
63+
})
64+
const emit = defineEmits(['update:showSearch', 'queryTable'])
65+
// 搜索
66+
const toggleSearch = () => {
67+
emit('update:showSearch', !props.showSearch)
68+
}
69+
// 刷新
70+
const refresh = () => {
71+
emit('queryTable')
72+
}
73+
// 右侧列表元素变化
74+
const dataChange = (data: number[]) => {
75+
props.columns.forEach((item) => {
76+
const key: number = item.key!
77+
item.visible = !data.includes(key)
78+
})
79+
}
80+
// 打开显隐列dialog
81+
const showColumn = () => {
82+
open.value = true
83+
}
84+
// 显隐列初始默认隐藏列
85+
const init = () => {
86+
props.columns.forEach((item, index) => {
87+
if (item.visible === false) {
88+
value.value.push(index)
89+
}
90+
})
91+
}
92+
init()
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>

0 commit comments

Comments
 (0)