add: 改造vue2中的RightToolbar到vue3中

This commit is contained in:
puhui999 2023-03-21 16:20:03 +08:00
parent 7697e5c358
commit 9adf80c914
2 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,9 @@
import RightToolbar from './src/index.vue'
export interface columnsType {
key?: number
label?: string
visible?: boolean
}
export { RightToolbar }

View File

@ -0,0 +1,104 @@
<template>
<div :style="style">
<el-row justify="end">
<el-tooltip
class="item"
effect="dark"
:content="showSearch ? '隐藏搜索' : '显示搜索'"
placement="top"
v-if="search"
>
<el-button circle @click="toggleSearch()">
<Icon icon="ep:search" />
</el-button>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="刷新" placement="top">
<el-button circle @click="refresh()">
<Icon icon="ep:refresh" />
</el-button>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="显隐列" placement="top" v-if="isColumns">
<el-button circle @click="showColumn()">
<Icon icon="ep:menu" />
</el-button>
</el-tooltip>
</el-row>
<el-dialog :title="title" v-model="open" append-to-body>
<el-transfer
:titles="['显示', '隐藏']"
v-model="value"
:data="columns"
@change="dataChange"
/>
</el-dialog>
</div>
</template>
<script lang="ts" setup name="RightToolbar">
import type { CSSProperties } from 'vue'
import type { columnsType } from '@/components/RightToolbar'
import { propTypes } from '@/utils/propTypes'
//
const value = ref<number[]>([])
//
const title = ref('显示/隐藏')
//
const open = ref(false)
const props = defineProps({
showSearch: propTypes.bool.def(true),
columns: {
type: Array as PropType<columnsType[]>,
default: () => []
},
search: propTypes.bool.def(true),
gutter: propTypes.number.def(10)
})
const isColumns = computed(() => props.columns?.length > 0)
const style = computed((): CSSProperties => {
const ret: CSSProperties = {}
if (props.gutter) {
ret.marginRight = `${props.gutter / 2}px`
}
return ret
})
const emit = defineEmits(['update:showSearch', 'queryTable'])
//
const toggleSearch = () => {
emit('update:showSearch', !props.showSearch)
}
//
const refresh = () => {
emit('queryTable')
}
//
const dataChange = (data: number[]) => {
props.columns.forEach((item) => {
const key: number = item.key!
item.visible = !data.includes(key)
})
}
// dialog
const showColumn = () => {
open.value = true
}
//
const init = () => {
props.columns.forEach((item, index) => {
if (item.visible === false) {
value.value.push(index)
}
})
}
init()
</script>
<style lang="scss" scoped>
:deep(.el-transfer__button) {
border-radius: 50%;
padding: 12px;
display: block;
margin-left: 0px;
}
:deep(.el-transfer__button:first-child) {
margin-bottom: 10px;
}
</style>