封装表格操作列按钮

效果图:

界面引用

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>
相关推荐
东东5166 小时前
xxx医患档案管理系统
java·spring boot·vue·毕业设计·智慧城市
码界奇点14 小时前
基于Spring Boot和Vue3的无头内容管理系统设计与实现
java·spring boot·后端·vue·毕业设计·源代码管理
东东51616 小时前
基于Web的智慧城市实验室系统设计与实现vue + ssm
java·前端·人工智能·后端·vue·毕业设计·智慧城市
不甘平凡的小鸟18 小时前
vue3与cef3交互
前端·vue·cef3
武哥聊编程19 小时前
【原创精品】基于Springboot3+Vue3的服装租赁平台
spring boot·mysql·vue·课程设计
weixin_439937761 天前
tortoiseGit 使用
java·前端·git·vue
.切切切 切萝卜2 天前
【vueconfig-proxy代理解决跨域问题】
vue·proxy模式
任小栗2 天前
uniappx实现app壳子,可直接拿来用
vue·uniapp
奔跑的web.2 天前
前端使用7种设计模式的核心原则
前端·javascript·设计模式·typescript·vue
千寻技术帮2 天前
10410_基于Springboot的文化旅游宣传网站
spring boot·后端·vue·源码·旅游·安装·在线旅游