封装表格操作列按钮

效果图:

界面引用

html 复制代码
<template>
  <div>
    <AvueRightButton
      :button-list="[
        {
          label: '配置',
          onClick: () => {},
        },
        {
          label: '新增模块',
          onClick: () => {},
        },
        {
          label: '爬取结果',
          onClick: () => {},
        },
        {
          label: '新增',
          onClick: () => {},
        },
        {
          label: '执行',
          disabled: true,
          type: 'info',
        },
        {
          label: '作废',
          onClick: () => {},
        },
      ]"
    />
  </div>
</template>
<script lang="ts" setup>
import AvueRightButton from "../../components/AvueRightButton/index.vue";
</script>
<style scoped lang="scss"></style>

组件

html 复制代码
<template>
    <div style="display: flex;align-items: center;">
        <el-button v-for="item in flatBtns" :key="item.label" :disabled="item.disabled" link :type="item.type || 'primary'"
        @click="onClick(item)"> {{ item.label }}</el-button>
        <el-dropdown v-if="moreBtns.length > 0" style="margin-left:12px;">
            <el-button link type="primary">更多</el-button>
            <template #dropdown>
                <el-dropdown-menu>
                <div v-for="item in moreBtns" :key="item.label">
                    <el-dropdown-item>
                    <el-button :disabled="item.disabled" link :type="item.type || 'primary'" @click="onClick(item)"> {{ item.label }}
                    </el-button>
                    </el-dropdown-item>
                </div>
                </el-dropdown-menu>
            </template>
        </el-dropdown>
    </div>
</template>
<script setup lang="ts">
import { PropType, ref, watch } from 'vue';

defineOptions({
  name: 'AvueRightButton',
});
const props = defineProps({
  buttonList: {
    default: () => [],
    type: Array as PropType<any[]>
  },
});
const flatBtns = ref<any[]>([]);
const moreBtns = ref<any[]>([]);
watch(
  () => props.buttonList,
  (newList) => {
    const showBtns = newList?.filter((b: any) => (b.vAcl || b.vAcl === undefined) && b.vIf !== false);
    if (showBtns.length > 0) {
      if (showBtns.length <= 4) {
        flatBtns.value = showBtns;
        moreBtns.value = [];
      } else {
        flatBtns.value = showBtns.slice(0, 3);
        moreBtns.value = showBtns.slice(3);
      }
    }else {
      flatBtns.value = [];
      moreBtns.value = [];
    }
  },
  { deep: true, immediate: true },
);
function onClick(item: any) {
  item.onClick();
}
</script>

<style lang="scss" scoped></style>
相关推荐
Cult Of1 天前
Alicea Wind的个人网站开发日志(2)
开发语言·python·vue
Byron07072 天前
从多端割裂到体验统一:基于 Vue 生态的跨端架构落地实战
vue·多端
计算机程序设计小李同学2 天前
基于 Spring Boot + Vue 的龙虾专营店管理系统的设计与实现
java·spring boot·后端·spring·vue
沐墨染2 天前
Vue实战:自动化研判报告组件的设计与实现
前端·javascript·信息可视化·数据分析·自动化·vue
奔跑的呱呱牛2 天前
viewer-utils 图片预览工具库
javascript·vue·react
Cult Of2 天前
Alicea Wind的个人网站开发日志(1)
python·vue
Polaris_YJH2 天前
使用Vue3+Vite+Pinia+elementUI搭建初级企业级项目
前端·javascript·elementui·vue
Mr Xu_2 天前
【Vue3 + ECharts 实战】正确使用 showLoading、resize 与 dispose 避免内存泄漏
前端·信息可视化·vue·echarts
换日线°3 天前
前端炫酷展开效果
前端·javascript·vue
IT北辰3 天前
基于Vue3+python+mysql8.0的财务凭证录入系统,前后端分离完整版(可赠送源码)
python·vue