網站首頁 編程語言 正文
一下是封裝好的操作列組件: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-02-15 使用數組的sort方法完成項目中的排序功能(數組sort方法與chart圖表展示結合)
- 2022-10-03 Android使用AudioRecord實現錄音功能_Android
- 2022-05-18 ASP.NET?MVC自定義異常過濾器_實用技巧
- 2022-04-16 C++實現二維圖形的打印_C 語言
- 2024-03-14 SpringBoot中事務
- 2022-08-31 python中ndarray數組的索引和切片的使用_python
- 2022-04-01 OpenCV實現摳圖工具_C 語言
- 2022-07-13 Android?Studio實現簡單繪圖板_Android
- 欄目分類
-
- 最近更新
-
- 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同步修改后的遠程分支