列配置

This commit is contained in:
bb_pan 2026-01-26 11:25:59 +08:00
parent a9eeb8b855
commit 0b9b2aa39f
5 changed files with 397 additions and 130 deletions

View File

@ -0,0 +1,15 @@
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_701_3265)">
<path d="M2 17L2 1" stroke="#595959" stroke-width="1.5" stroke-linecap="round"/>
<path d="M16 17L16 1" stroke="#595959" stroke-width="1.5" stroke-linecap="round"/>
<path d="M9 1L9 17" stroke="#595959" stroke-width="1.5" stroke-linecap="round"/>
<circle cx="2" cy="13" r="2" fill="#595959"/>
<circle cx="16" cy="13" r="2" fill="#595959"/>
<circle cx="2" cy="2" r="2" transform="matrix(1 0 0 -1 7 7)" fill="#595959"/>
</g>
<defs>
<clipPath id="clip0_701_3265">
<rect width="18" height="18" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

View File

@ -0,0 +1,210 @@
<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 size="mini" circle icon="el-icon-search" @click="toggleSearch()" />
</el-tooltip> -->
<!-- <el-tooltip class="item" effect="dark" content="刷新" placement="top">
<el-button size="mini" circle icon="el-icon-refresh" @click="refresh()" />
</el-tooltip> -->
<!-- <el-tooltip class="item" effect="dark" content="显隐列" placement="top" v-if="columns">
<el-button size="mini" circle icon="el-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 size="mini" circle icon="el-icon-menu" />
<el-dropdown-menu slot="dropdown" style="max-height: 880px; overflow-y: auto;">
<template>
<el-dropdown-item v-for="(item, index) in columns" :key="index">
<el-checkbox :checked="item.visible" @change="checkboxChange($event, item.label)" :label="item.label" />
</el-dropdown-item>
</template>
</el-dropdown-menu>
</el-dropdown>
</el-tooltip> -->
<el-tooltip class="item" effect="dark" content="列表全屏" placement="top" style="margin-left: 10px">
<el-button
size="mini"
circle
icon="el-icon-full-screen"
@click="toggleFullscreen"
/>
</el-tooltip>
</el-row>
<el-dialog :title="title" :visible.sync="open" append-to-body>
<el-transfer
:titles="['显示', '隐藏']"
v-model="value"
:data="columns"
@change="dataChange"
></el-transfer>
</el-dialog>
</div>
</template>
<script>
export default {
name: "RightToolbar",
data() {
return {
//
value: [],
//
title: "显示/隐藏",
//
open: false,
};
},
props: {
/* 是否显示检索条件 */
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,
},
},
computed: {
style() {
const ret = {};
if (this.gutter) {
ret.marginRight = `${this.gutter / 2}px`;
}
return ret;
}
},
created() {
if (this.showColumnsType == 'transfer') {
//
for (let item in this.columns) {
if (this.columns[item].visible === false) {
this.value.push(parseInt(item));
}
}
}
},
methods: {
//
toggleSearch() {
this.$emit("update:showSearch", !this.showSearch);
},
//
refresh() {
this.$emit("queryTable");
},
//
toggleFullscreen() {
// 1 DOM
let tableEl = document.querySelector('.el-table')
if (!tableEl) {
const tables = Array.from(document.querySelectorAll('.el-table'))
tableEl = tables.find((t) => t.offsetParent !== null)
}
if (!tableEl) {
this.$message.warning('未找到表格区域')
return
}
// 2 DOM
let pagerEl = document.querySelector('.pagination-container')
if (!pagerEl) {
const pagers = Array.from(document.querySelectorAll('.pagination-container'))
pagerEl = pagers.find((p) => p.offsetParent !== null)
}
// 3
let fullscreenEl = tableEl.parentElement
if (pagerEl) {
while (fullscreenEl && (!fullscreenEl.contains(tableEl) || !fullscreenEl.contains(pagerEl))) {
fullscreenEl = fullscreenEl.parentElement
}
}
if (!fullscreenEl) fullscreenEl = tableEl
const doc = document
// 🔐
if (!fullscreenEl.__fsBound) {
fullscreenEl.__oldBg = fullscreenEl.style.background
fullscreenEl.__oldMinHeight = fullscreenEl.style.minHeight
fullscreenEl.__fsBound = true
}
// ===== =====
if (!doc.fullscreenElement) {
fullscreenEl.style.background = '#fff'
fullscreenEl.style.minHeight = '100vh'
const onFsChange = () => {
// 👉 退ESC / API
if (!document.fullscreenElement) {
// 1
fullscreenEl.style.background = fullscreenEl.__oldBg || ''
fullscreenEl.style.minHeight = fullscreenEl.__oldMinHeight || ''
// 2 ref
this.$nextTick(() => {
const tableVm = tableEl.__vue__ || document.querySelector('.el-table')?.__vue__
tableVm?.doLayout()
})
document.removeEventListener('fullscreenchange', onFsChange)
}
}
document.addEventListener('fullscreenchange', onFsChange)
fullscreenEl.requestFullscreen?.()
} else {
// ===== 退=====
doc.exitFullscreen?.()
}
},
dataChange(data) {
for (let item in this.columns) {
const key = this.columns[item].key;
this.columns[item].visible = !data.includes(key);
}
},
// dialog
showColumn() {
this.open = true;
},
//
checkboxChange(event, label) {
this.columns.filter(item => item.label == label)[0].visible = event;
}
},
};
</script>
<style lang="scss" scoped>
::v-deep .el-transfer__button {
border-radius: 50%;
padding: 12px;
display: block;
margin-left: 0px;
}
::v-deep .el-transfer__button:first-child {
margin-bottom: 10px;
}
</style>

View File

@ -1,170 +1,180 @@
<template> <template>
<div class="top-right-btn" :style="style"> <div class="top-right-btn" :style="style">
<el-row> <el-row>
<!-- <el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top" v-if="search"> <el-tooltip class="item" effect="dark" content="列配置" placement="top" v-if="columns">
<el-button size="mini" circle icon="el-icon-search" @click="toggleSearch()" /> <el-popover placement="bottom-end" width="260" trigger="click" v-model="open">
</el-tooltip> --> <div class="column-panel">
<!-- <el-tooltip class="item" effect="dark" content="刷新" placement="top"> <!-- 搜索 -->
<el-button size="mini" circle icon="el-icon-refresh" @click="refresh()" /> <el-input v-model="keyword" size="mini" placeholder="搜索字段" clearable class="search-input" />
</el-tooltip> -->
<!-- <el-tooltip class="item" effect="dark" content="显隐列" placement="top" v-if="columns"> <!-- 操作区 -->
<el-button size="mini" circle icon="el-icon-menu" @click="showColumn()" v-if="showColumnsType == 'transfer'"/> <div class="panel-actions">
<el-dropdown trigger="click" :hide-on-click="false" style="padding-left: 12px" v-if="showColumnsType == 'checkbox'"> <el-checkbox :value="checkAll" :indeterminate="isIndeterminate" @change="onCheckAll"> 全选 </el-checkbox>
<el-button size="mini" circle icon="el-icon-menu" /> <el-link type="primary" :underline="false" @click="resetColumns"> 恢复默认 </el-link>
<el-dropdown-menu slot="dropdown" style="max-height: 880px; overflow-y: auto;"> </div>
<template>
<el-dropdown-item v-for="(item, index) in columns" :key="index"> <!-- 可拖拽列表 -->
<el-checkbox :checked="item.visible" @change="checkboxChange($event, item.label)" :label="item.label" /> <div class="list-wrapper">
</el-dropdown-item> <draggable
</template> v-model="innerColumns"
</el-dropdown-menu> :options="{ handle: '.drag-handle', animation: 150 }"
</el-dropdown> ghost-class="ghost"
</el-tooltip> --> >
<el-tooltip class="item" effect="dark" content="列表全屏" placement="top" style="margin-left: 10px"> <transition-group name="flip-list" tag="div">
<el-button <div v-for="item in innerColumns" :key="item.key" class="column-item" v-show="matchKeyword(item)">
size="mini" <el-checkbox v-model="item.visible">
circle {{ item.label }}
icon="el-icon-full-screen" </el-checkbox>
@click="toggleFullscreen" <span class="drag-handle">
/> <img src="@/assets/images/icon-drag.png" style="width: 10px; height: 15px" alt="" />
</span>
</div>
</transition-group>
</draggable>
</div>
<!-- 底部按钮 -->
<div class="panel-footer">
<el-button size="mini" type="primary" style="width: 100%" @click="applyChange"> </el-button>
</div>
</div>
<!-- 触发按钮 -->
<svg-icon slot="reference" icon-class="menu" class="menu-icon" />
</el-popover>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="列表全屏" placement="top" style="margin: 5px 0 0 10px">
<svg-icon icon-class="full-screen" @click="toggleFullscreen" />
</el-tooltip> </el-tooltip>
</el-row> </el-row>
<el-dialog :title="title" :visible.sync="open" append-to-body>
<el-transfer
:titles="['显示', '隐藏']"
v-model="value"
:data="columns"
@change="dataChange"
></el-transfer>
</el-dialog>
</div> </div>
</template> </template>
<script> <script>
import draggable from 'vuedraggable'
export default { export default {
name: "RightToolbar", name: 'RightToolbarElementDraggable',
data() { components: { draggable },
return {
//
value: [],
//
title: "显示/隐藏",
//
open: false,
};
},
props: { props: {
/* 是否显示检索条件 */
showSearch: {
type: Boolean,
default: true,
},
/* 显隐列信息 */
columns: { columns: {
type: Array, type: Array,
required: true,
}, },
/* 是否显示检索图标 */
search: {
type: Boolean,
default: true,
},
/* 显隐列类型transfer穿梭框、checkbox复选框 */
showColumnsType: {
type: String,
default: "checkbox",
},
/* 右外边距 */
gutter: { gutter: {
type: Number, type: Number,
default: 10, default: 10,
}, },
}, },
data() {
return {
open: false,
keyword: '',
innerColumns: [],
backupColumns: [],
}
},
computed: { computed: {
style() { style() {
const ret = {}; const ret = {}
if (this.gutter) { if (this.gutter) ret.marginRight = `${this.gutter / 2}px`
ret.marginRight = `${this.gutter / 2}px`; return ret
} },
return ret; checkAll() {
} return this.innerColumns.length ? this.innerColumns.every((c) => c.visible) : false
},
isIndeterminate() {
const visCount = this.innerColumns.filter((c) => c.visible).length
return visCount > 0 && visCount < this.innerColumns.length
},
}, },
created() { watch: {
if (this.showColumnsType == 'transfer') { columns: {
// immediate: true,
for (let item in this.columns) { deep: true,
if (this.columns[item].visible === false) { handler(val) {
this.value.push(parseInt(item)); // transfer
} this.innerColumns = val.map((c) => ({ ...c }))
} this.backupColumns = val.map((c) => ({ ...c }))
} },
},
}, },
methods: { methods: {
// matchKeyword(item) {
toggleSearch() { if (!this.keyword) return true
this.$emit("update:showSearch", !this.showSearch); const k = this.keyword.toLowerCase()
return (item.label || '').toLowerCase().includes(k)
}, },
// onCheckAll(val) {
refresh() { this.innerColumns.forEach((c) => (c.visible = val))
this.$emit("queryTable");
}, },
// resetColumns() {
toggleFullscreen() { // columns
// 1 DOM this.innerColumns = this.backupColumns.map((c) => ({ ...c }))
let tableEl = document.querySelector('.el-table') },
applyChange() {
// === dataChange ===
// innerColumns visible / this.columns
this.innerColumns.forEach((col, idx) => {
const target = this.columns.find((c) => c.key === col.key)
if (target) {
target.visible = col.visible
}
})
// splice
const newOrder = this.innerColumns.map((c) => c.key)
const ordered = newOrder.map((k) => this.columns.find((c) => c.key === k)).filter(Boolean)
this.columns.splice(0, this.columns.length, ...ordered)
this.open = false
},
toggleFullscreen() {
let tableEl = document.querySelector('.el-table')
if (!tableEl) { if (!tableEl) {
const tables = Array.from(document.querySelectorAll('.el-table')) const tables = Array.from(document.querySelectorAll('.el-table'))
tableEl = tables.find((t) => t.offsetParent !== null) tableEl = tables.find((t) => t.offsetParent !== null)
} }
if (!tableEl) { if (!tableEl) {
this.$message.warning('未找到表格区域') this.$message.warning('未找到表格区域')
return return
} }
// 2 DOM
let pagerEl = document.querySelector('.pagination-container') let pagerEl = document.querySelector('.pagination-container')
if (!pagerEl) { if (!pagerEl) {
const pagers = Array.from(document.querySelectorAll('.pagination-container')) const pagers = Array.from(document.querySelectorAll('.pagination-container'))
pagerEl = pagers.find((p) => p.offsetParent !== null) pagerEl = pagers.find((p) => p.offsetParent !== null)
} }
// 3
let fullscreenEl = tableEl.parentElement let fullscreenEl = tableEl.parentElement
if (pagerEl) { if (pagerEl) {
while (fullscreenEl && (!fullscreenEl.contains(tableEl) || !fullscreenEl.contains(pagerEl))) { while (fullscreenEl && (!fullscreenEl.contains(tableEl) || !fullscreenEl.contains(pagerEl))) {
fullscreenEl = fullscreenEl.parentElement fullscreenEl = fullscreenEl.parentElement
} }
} }
if (!fullscreenEl) fullscreenEl = tableEl if (!fullscreenEl) fullscreenEl = tableEl
const doc = document const doc = document
// 🔐
if (!fullscreenEl.__fsBound) { if (!fullscreenEl.__fsBound) {
fullscreenEl.__oldBg = fullscreenEl.style.background fullscreenEl.__oldBg = fullscreenEl.style.background
fullscreenEl.__oldMinHeight = fullscreenEl.style.minHeight fullscreenEl.__oldMinHeight = fullscreenEl.style.minHeight
fullscreenEl.__fsBound = true fullscreenEl.__fsBound = true
} }
// ===== =====
if (!doc.fullscreenElement) { if (!doc.fullscreenElement) {
fullscreenEl.style.background = '#fff' fullscreenEl.style.background = '#fff'
fullscreenEl.style.minHeight = '100vh' fullscreenEl.style.minHeight = '100vh'
const onFsChange = () => { const onFsChange = () => {
// 👉 退ESC / API
if (!document.fullscreenElement) { if (!document.fullscreenElement) {
// 1
fullscreenEl.style.background = fullscreenEl.__oldBg || '' fullscreenEl.style.background = fullscreenEl.__oldBg || ''
fullscreenEl.style.minHeight = fullscreenEl.__oldMinHeight || '' fullscreenEl.style.minHeight = fullscreenEl.__oldMinHeight || ''
// 2 ref
this.$nextTick(() => { this.$nextTick(() => {
const tableVm = tableEl.__vue__ || document.querySelector('.el-table')?.__vue__ const tableVm = tableEl.__vue__ || document.querySelector('.el-table')?.__vue__
tableVm?.doLayout() tableVm?.doLayout()
}) })
@ -173,38 +183,68 @@ export default {
} }
document.addEventListener('fullscreenchange', onFsChange) document.addEventListener('fullscreenchange', onFsChange)
fullscreenEl.requestFullscreen && fullscreenEl.requestFullscreen()
fullscreenEl.requestFullscreen?.()
} else { } else {
// ===== 退===== doc.exitFullscreen && doc.exitFullscreen()
doc.exitFullscreen?.()
} }
}, },
dataChange(data) {
for (let item in this.columns) {
const key = this.columns[item].key;
this.columns[item].visible = !data.includes(key);
}
},
// dialog
showColumn() {
this.open = true;
},
//
checkboxChange(event, label) {
this.columns.filter(item => item.label == label)[0].visible = event;
}
}, },
};
</script>
<style lang="scss" scoped>
::v-deep .el-transfer__button {
border-radius: 50%;
padding: 12px;
display: block;
margin-left: 0px;
} }
::v-deep .el-transfer__button:first-child { </script>
margin-bottom: 10px;
<style lang="scss" scoped>
.top-right-btn {
display: flex;
align-items: center;
}
.menu-icon {
cursor: pointer;
font-size: 16px;
}
.column-panel {
padding: 8px;
max-height: 400px;
display: flex;
flex-direction: column;
}
.list-wrapper {
flex: 1;
overflow-y: auto;
}
.search-input {
margin-bottom: 8px;
}
.panel-actions {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.column-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 4px 0;
}
.drag-handle {
cursor: grab;
margin-right: 8px;
color: #999;
user-select: none;
}
.ghost {
opacity: 0.4;
}
.panel-footer {
margin-top: 8px;
} }
</style> </style>

View File

@ -446,7 +446,8 @@ export default {
}, },
created() { created() {
this.getUser() this.getUser()
this.menuList = this.sidebarRouters.filter((route) => !route.hidden) this.menuList = this.sidebarRouters.filter((route) => !route.hidden && route.path !== '/')
console.log('🚀 ~ this.menuList:', this.menuList)
}, },
methods: { methods: {
goWarningDetail(item) { goWarningDetail(item) {
@ -629,10 +630,11 @@ export default {
height: 50px; height: 50px;
line-height: 50px; line-height: 50px;
flex: 1; flex: 1;
gap: 30px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-around; justify-content: center;
margin: 0 20px; // margin: 0 20px;
.menu-item { .menu-item {
height: 50px; height: 50px;
cursor: pointer; cursor: pointer;