From 251d2411f235e23209d57173857e05b637729ce8 Mon Sep 17 00:00:00 2001 From: LiuHao <liuhaoai545@gmail.com> Date: 星期日, 02 四月 2023 01:01:56 +0800 Subject: [PATCH] refactor ts --- src/components/RightToolbar/index.vue | 79 +++++++++++++++++++-------------------- 1 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/components/RightToolbar/index.vue b/src/components/RightToolbar/index.vue index becb12c..fd94360 100644 --- a/src/components/RightToolbar/index.vue +++ b/src/components/RightToolbar/index.vue @@ -1,35 +1,14 @@ -<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()" /> - </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 lang="ts"> +import { TransferKey } from "element-plus"; +import { PropType } from "vue"; -<script setup> const props = defineProps({ showSearch: { type: Boolean, default: true, }, columns: { - type: Array, + type: Array as PropType<FieldOption[]>, }, search: { type: Boolean, @@ -44,14 +23,14 @@ const emits = defineEmits(['update:showSearch', 'queryTable']); // 鏄鹃殣鏁版嵁 -const value = ref([]); +const value = ref<Array<number>>([]); // 寮瑰嚭灞傛爣棰� const title = ref("鏄剧ず/闅愯棌"); // 鏄惁鏄剧ず寮瑰嚭灞� const open = ref(false); const style = computed(() => { - const ret = {}; + const ret: any = {}; if (props.gutter) { ret.marginRight = `${props.gutter / 2}px`; } @@ -69,27 +48,47 @@ } // 鍙充晶鍒楄〃鍏冪礌鍙樺寲 -function dataChange(data) { - for (let item in props.columns) { - const key = props.columns[item].key; - props.columns[item].visible = !data.includes(key); - } +function dataChange(data: TransferKey[]) { + props.columns?.forEach((item) => { + item.visible = !data.includes(item.key); + }) } // 鎵撳紑鏄鹃殣鍒梔ialog -function showColumn() { +const showColumn = () => { open.value = true; } // 鏄鹃殣鍒楀垵濮嬮粯璁ら殣钘忓垪 -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) { + value.value.push(item.key); + } + }) +}) </script> -<style lang='scss' scoped> +<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()" /> + </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> + +<style lang="scss" scoped> :deep(.el-transfer__button) { border-radius: 50%; display: block; @@ -102,4 +101,4 @@ .my-el-transfer { text-align: center; } -</style> \ No newline at end of file +</style> -- Gitblit v1.9.3