封装表格操作列按钮

效果图:

界面引用

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>
相关推荐
我的golang之路果然有问题4 小时前
实习中遇到的 CORS 同源策略自己的理解分析
前端·javascript·vue·reactjs·同源策略·cors
刘联其4 小时前
Vue3+Vite +dotenvx读取.env文件参数
vue
椰果uu1 天前
vue-virtual-scroller-虚拟滚动列表:渲染不定高度长列表+可控跳转
前端·javascript·typescript·vue
小和尚敲木头1 天前
记录一次vue3中this引发的开发没有问题,生产发生问题的分析
前端·vue
PieroPc1 天前
用FastAPI 后端 和 Vue3 前端写一个博客系统 例
前端·vue·fastapi
Web项目开发1 天前
VitePress 创建技术文档
vue
四谎真好看2 天前
JavaWeb 学习笔记(Day02)之Vue
笔记·学习·vue·学习笔记·javaweb
Sapphire~2 天前
Vue3-04 自定义组件Person
vue
沐墨染2 天前
大型数据分析组件前端实践:多维度检索与实时交互设计
前端·elementui·数据挖掘·数据分析·vue·交互
@AfeiyuO3 天前
Vue3 高德地图
vue·echarts