From e181f04c642204e79749af93fa921875ff6c21ba Mon Sep 17 00:00:00 2001 From: baoshiwei <baoshiwei@shlanbao.cn> Date: 星期二, 20 五月 2025 10:46:35 +0800 Subject: [PATCH] refactor(qms): 重构趋势图展示逻辑 --- src/components/RightToolbar/index.vue | 111 +++++++++++++++++++++++++++---------------------------- 1 files changed, 54 insertions(+), 57 deletions(-) diff --git a/src/components/RightToolbar/index.vue b/src/components/RightToolbar/index.vue index becb12c..e8c9d65 100644 --- a/src/components/RightToolbar/index.vue +++ b/src/components/RightToolbar/index.vue @@ -1,57 +1,49 @@ <template> <div class="top-right-btn" :style="style"> <el-row> - <el-tooltip class="item" effect="dark" :content="showSearch ? '闅愯棌鎼滅储' : '鏄剧ず鎼滅储'" placement="top" v-if="search"> + <el-tooltip v-if="search" class="item" effect="dark" :content="showSearch ? '闅愯棌鎼滅储' : '鏄剧ず鎼滅储'" placement="top"> <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()" /> + <el-tooltip v-if="columns" class="item" effect="dark" content="鏄剧ず/闅愯棌鍒�" placement="top"> + <div class="show-btn"> + <el-popover placement="bottom" trigger="click"> + <div class="tree-header">鏄剧ず/闅愯棌鍒�</div> + <el-tree + ref="columnRef" + :data="columns" + show-checkbox + node-key="key" + :props="{ label: 'label', children: 'children' }" + @check="columnChange" + ></el-tree> + <template #reference> + <el-button circle icon="Menu" /> + </template> + </el-popover> + </div> </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, - }, - gutter: { - type: Number, - default: 10, - }, -}) +<script setup lang="ts"> +import { propTypes } from '@/utils/propTypes'; +const props = defineProps({ + showSearch: propTypes.bool.def(true), + columns: propTypes.fieldOption, + search: propTypes.bool.def(true), + gutter: propTypes.number.def(10) +}); + +const columnRef = ref<ElTreeInstance>(); const emits = defineEmits(['update:showSearch', 'queryTable']); -// 鏄鹃殣鏁版嵁 -const value = ref([]); -// 寮瑰嚭灞傛爣棰� -const title = ref("鏄剧ず/闅愯棌"); -// 鏄惁鏄剧ず寮瑰嚭灞� -const open = ref(false); - const style = computed(() => { - const ret = {}; + const ret: any = {}; if (props.gutter) { ret.marginRight = `${props.gutter / 2}px`; } @@ -60,36 +52,33 @@ // 鎼滅储 function toggleSearch() { - emits("update:showSearch", !props.showSearch); + emits('update:showSearch', !props.showSearch); } // 鍒锋柊 function refresh() { - emits("queryTable"); + emits('queryTable'); } -// 鍙充晶鍒楄〃鍏冪礌鍙樺寲 -function dataChange(data) { - for (let item in props.columns) { - const key = props.columns[item].key; - props.columns[item].visible = !data.includes(key); - } -} - -// 鎵撳紑鏄鹃殣鍒梔ialog -function showColumn() { - open.value = true; +// 鏇存敼鏁版嵁鍒楃殑鏄剧ず鍜岄殣钘� +function columnChange(...args: any[]) { + props.columns?.forEach((item) => { + item.visible = args[1].checkedKeys.includes(item.key); + }); } // 鏄鹃殣鍒楀垵濮嬮粯璁ら殣钘忓垪 -for (let item in props.columns) { - if (props.columns[item].visible === false) { - value.value.push(parseInt(item)); - } -} +onMounted(() => { + props.columns?.forEach((item) => { + if (item.visible) { + columnRef.value?.setChecked(item.key, true, false); + // value.value.push(item.key); + } + }); +}); </script> -<style lang='scss' scoped> +<style lang="scss" scoped> :deep(.el-transfer__button) { border-radius: 50%; display: block; @@ -102,4 +91,12 @@ .my-el-transfer { text-align: center; } -</style> \ No newline at end of file +.tree-header { + width: 100%; + line-height: 24px; + text-align: center; +} +.show-btn { + margin-left: 12px; +} +</style> -- Gitblit v1.9.3