| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template>
|
| | | <div class="top-right-btn" :style="style">
|
| | | <el-row>
|
| | | <el-tooltip class="item" effect="dark" :content="showSearch ? 'éèæç´¢' : 'æ¾ç¤ºæç´¢'" placement="top" v-if="search">
|
| | | <el-button circle icon="Search" @click="toggleSearch()" />
|
| | | </el-tooltip>
|
| | | <el-tooltip class="item" effect="dark" content="å·æ°" placement="top">
|
| | | <el-button circle icon="Refresh" @click="refresh()" />
|
| | | </el-tooltip>
|
| | | <el-tooltip class="item" effect="dark" content="æ¾éå" placement="top" v-if="columns">
|
| | | <el-button circle icon="Menu" @click="showColumn()" v-if="showColumnsType == 'transfer'"/>
|
| | | <el-dropdown trigger="click" :hide-on-click="false" style="padding-left: 12px" v-if="showColumnsType == 'checkbox'">
|
| | | <el-button circle icon="Menu" />
|
| | | <template #dropdown>
|
| | | <el-dropdown-menu>
|
| | | <!-- å
¨é/åé æé® -->
|
| | | <el-dropdown-item>
|
| | | <el-checkbox :indeterminate="isIndeterminate" v-model="isChecked" @change="toggleCheckAll"> åå±ç¤º </el-checkbox>
|
| | | </el-dropdown-item>
|
| | | <div class="check-line"></div>
|
| | | <template v-for="item in columns" :key="item.key">
|
| | | <el-dropdown-item>
|
| | | <el-checkbox v-model="item.visible" @change="checkboxChange($event, item.label)" :label="item.label" />
|
| | | </el-dropdown-item>
|
| | | </template>
|
| | | </el-dropdown-menu>
|
| | | </template>
|
| | | </el-dropdown>
|
| | | </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-transfer>
|
| | | </el-dialog>
|
| | | </div>
|
| | | </template>
|
| | |
|
| | | <script setup>
|
| | | const props = defineProps({
|
| | | /* æ¯å¦æ¾ç¤ºæ£ç´¢æ¡ä»¶ */
|
| | | showSearch: {
|
| | | type: Boolean,
|
| | | default: true
|
| | | },
|
| | | /* æ¾éåä¿¡æ¯ */
|
| | | columns: {
|
| | | type: Array
|
| | | },
|
| | | /* æ¯å¦æ¾ç¤ºæ£ç´¢å¾æ */
|
| | | search: {
|
| | | type: Boolean,
|
| | | default: true
|
| | | },
|
| | | /* æ¾éåç±»åï¼transferç©¿æ¢æ¡ãcheckboxå¤éæ¡ï¼ */
|
| | | showColumnsType: {
|
| | | type: String,
|
| | | default: "checkbox"
|
| | | },
|
| | | /* å³å¤è¾¹è· */
|
| | | gutter: {
|
| | | type: Number,
|
| | | default: 10
|
| | | },
|
| | | })
|
| | |
|
| | | const emits = defineEmits(['update:showSearch', 'queryTable'])
|
| | |
|
| | | // æ¾éæ°æ®
|
| | | const value = ref([])
|
| | | // å¼¹åºå±æ é¢
|
| | | const title = ref("æ¾ç¤º/éè")
|
| | | // æ¯å¦æ¾ç¤ºå¼¹åºå±
|
| | | const open = ref(false)
|
| | |
|
| | | const style = computed(() => {
|
| | | const ret = {}
|
| | | if (props.gutter) {
|
| | | ret.marginRight = `${props.gutter / 2}px`
|
| | | }
|
| | | return ret
|
| | | })
|
| | |
|
| | | // æ¯å¦å
¨é/åé ç¶æ
|
| | | const isChecked = computed({
|
| | | get: () => props.columns.every(col => col.visible),
|
| | | set: () => {}
|
| | | })
|
| | | const isIndeterminate = computed(() => props.columns.some((col) => col.visible) && !isChecked.value)
|
| | |
|
| | | // æç´¢
|
| | | function toggleSearch() {
|
| | | emits("update:showSearch", !props.showSearch)
|
| | | }
|
| | |
|
| | | // å·æ°
|
| | | function refresh() {
|
| | | emits("queryTable")
|
| | | }
|
| | |
|
| | | // å³ä¾§å表å
ç´ åå
|
| | | function dataChange(data) {
|
| | | for (let item in props.columns) {
|
| | | const key = props.columns[item].key
|
| | | props.columns[item].visible = !data.includes(key)
|
| | | }
|
| | | }
|
| | |
|
| | | // æå¼æ¾éådialog
|
| | | function showColumn() {
|
| | | open.value = true
|
| | | }
|
| | |
|
| | | if (props.showColumnsType == 'transfer') {
|
| | | // æ¾éååå§é»è®¤éèå
|
| | | for (let item in props.columns) {
|
| | | if (props.columns[item].visible === false) {
|
| | | value.value.push(parseInt(item))
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // åå¾é
|
| | | function checkboxChange(event, label) {
|
| | | props.columns.filter(item => item.label == label)[0].visible = event
|
| | | }
|
| | |
|
| | | // 忢å
¨é/åé
|
| | | function toggleCheckAll() {
|
| | | const newValue = !isChecked.value
|
| | | props.columns.forEach((col) => (col.visible = newValue))
|
| | | }
|
| | | </script>
|
| | |
|
| | | <style lang='scss' scoped>
|
| | | :deep(.el-transfer__button) {
|
| | | border-radius: 50%;
|
| | | display: block;
|
| | | margin-left: 0px;
|
| | | }
|
| | | :deep(.el-transfer__button:first-child) {
|
| | | margin-bottom: 10px;
|
| | | }
|
| | | :deep(.el-dropdown-menu__item) {
|
| | | line-height: 30px;
|
| | | padding: 0 17px;
|
| | | }
|
| | | .check-line {
|
| | | width: 90%;
|
| | | height: 1px;
|
| | | background-color: #ccc;
|
| | | margin: 3px auto;
|
| | | }
|
| | | </style>
|