網站首頁 編程語言 正文
一下是封裝好的操作列組件:OperateBtn
<template>
<div class="button-group">
<div
class="visibleButtons"
v-for="(button, index) in visibleButtons"
:key="index"
>
<el-button
link
type="primary"
:icon="button.icon"
@click="button.click"
v-if="button.isshow && button.text !== '刪除'"
>
{{ button.text }}
</el-button>
<el-popconfirm
title="確定刪除嗎?"
width="200px"
@confirm="button.click"
:teleported="false"
placement="bottom"
v-if="button.isshow && button.text === '刪除'"
>
<template #reference>
<el-button
link
type="primary"
:icon="button.icon"
@click.stop="button.del"
>
{{ button.text }}
</el-button>
</template>
</el-popconfirm>
</div>
<el-dropdown v-if="showMore">
<span class="el-dropdown-link">
更多
<el-icon class="el-icon--right">
<arrow-down />
</el-icon>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-for="(button, index) in hiddenButtons"
:key="index"
>
<span v-if="button.text !== '刪除'" @click="button.click">
{{ button.text }}
</span>
<el-popconfirm
title="確定要刪除嗎?"
confirmButtonText="確定"
cancelButtonText="取消"
@confirm="button.click"
v-if="button.text === '刪除'"
>
<template #reference>
<el-button link @click.stop="button.del">
{{ button.text }}
</el-button>
</template>
</el-popconfirm>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</template>
<script lang="ts">
import { defineComponent, computed, ref } from "vue";
interface Item {
text: string;
icon: string;
isshow: boolean;
click: () => void;
del?: () => void; // 這個是可選屬性 不給也沒事
}
export default defineComponent({
name: "ButtonGroup",
props: {
buttons: {
type: Array as () => Item[],
default: () => [],
},
},
setup(props) {
const isshowButtons = () => {
return props.buttons?.filter((item: any) => {
return item.isshow;
});
};
let resultBtn = ref(isshowButtons());
const visibleButtons = computed(() => {
if (resultBtn.value.length <= 3) {
return resultBtn.value;
} else {
return resultBtn.value.slice(0, 2);
}
});
const hiddenButtons = computed(() => {
if (resultBtn.value.length <= 3) {
return [];
} else {
return resultBtn.value.slice(2);
}
});
const showMore = computed(() => {
return resultBtn.value.length > 3;
});
const del = () => {};
return { visibleButtons, hiddenButtons, showMore, del };
},
});
</script>
<style lang="scss" scoped>
.button-group {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
align-items: center;
}
</style>
下面是在el-table中的使用:
<el-table>
<el-table-column align="right">
<operate-btn
:key="scope.row.id" // 子組件必須綁定一個key,不然切換表格分頁的時候,表格操作列不會更新
:buttons="[ // 傳給子組件的值,用來渲染按鈕,包括:按鈕文字、圖標、按鈕的點擊事件、以及按鈕的顯示與隱藏控制
{
text: '編輯',
icon: 'Edit',
click: () => handleEdit(row),
isshow: row.status !== 1 ? true : false,
},
{
text: '訂閱詳情',
icon: 'Warning',
click: () => toAuthDetail(row),
isshow: row.status === 2 ? true : false,
},
{
text: '重新上架',
icon: 'RefreshRight',
click: () => handleRack(row),
isshow: row.status === 3 ? true : false,
},
{
text: '下架申請',
icon: 'BottomRight',
click: () => handleUnShelve(row),
isshow: row.status === 2 ? true : false,
},
{
text: '上架申請',
icon: 'TopRight',
click: () => handleRack(row),
isshow: row.status === 0 || row.status === 4 ? true : false,
},
{
text: '刪除',
icon: 'Delete',
click: () => delApi(row.id),
isshow:
row.status === 0 || row.status === 3 || row.status === 4
? true
: false,
del: () => del($index),
},
// 只有微服務平臺和已上架可見
{
text: '設置流控規則',
icon: 'DataAnalysis',
click: () => openFlowcontrol(row),
isshow: row.status === 2 && row.source === 1 ? true : false,
},
{
text: '設置超時規則',
icon: 'Timer',
click: () => openTimeout(row),
isshow: row.status === 2 && row.source === 1 ? true : false,
},
{
text: '監控',
icon: 'Monitor',
click: () => openMonitor(row),
isshow: row.status === 2 && row.source === 1 ? true : false,
},
]
/>
</el-table-column>
</el-table>
原文鏈接:https://blog.csdn.net/bbt953/article/details/131202872
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-06-01 詳解使用內網穿透工具Ngrok代理本地服務_其它綜合
- 2022-06-07 freertos實時操作系統空閑任務阻塞延時示例解析_操作系統
- 2022-09-04 Linux?sed工具的使用及工作原理_linux shell
- 2022-07-03 C#枚舉類型與位域枚舉Enum_C#教程
- 2022-12-23 Android入門之彈出式對話框的實現_Android
- 2022-12-14 正則表達式(?=)正向先行斷言實戰案例_正則表達式
- 2022-09-04 Redis分布式鎖解決秒殺超賣問題_Redis
- 2022-05-27 hive中的幾種join到底有什么區別_數據庫其它
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支