封装表格操作列按钮

效果图:

界面引用

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>
相关推荐
千寻技术帮7 小时前
10382_基于Springboot的高校排课管理系统
mysql·vue·毕设·spingboot·高校排课
IT教程资源C7 小时前
(N_115)基于springboot,vue教务管理系统
mysql·vue·前后端分离·springboot教务系统
沧澜sincerely8 小时前
WebSocket 实时聊天功能
网络·websocket·vue·springboot
苏打水com8 小时前
第二十篇:Day58-60 前端性能优化进阶——从“能用”到“好用”(对标职场“体验优化”需求)
前端·css·vue·html·js
Jeking2178 小时前
进阶流程图绘制工具 Unione Flow Editor-- 直击行业痛点:高扩展性解决方案解析
vue·流程图·workflow·unione flow·flow editor·unione cloud
旧梦星轨9 小时前
掌握 Vite 环境配置:从 .env 文件到运行模式的完整实践
前端·前端框架·node.js·vue·react
sg_knight10 小时前
模块热替换 (HMR):前端开发的“魔法”与提速秘籍
前端·javascript·vue·浏览器·web·模块化·hmr
李慕婉学姐20 小时前
【开题答辩过程】以《基于Android的出租车运行监测系统设计与实现》为例,不知道这个选题怎么做的,不知道这个选题怎么开题答辩的可以进来看看
java·后端·vue
苏打水com1 天前
第十五篇:Day43-45 前端性能优化进阶——从“可用”到“极致”(对标职场“高并发场景优化”需求)
前端·css·vue·html·js