系统左侧分栏

该代码段展示了一个Vue.js组件,用于创建一个可搜索、有操作按钮(编辑、删除)的左侧栏。用户可以输入名称进行搜索,点击分类会高亮显示,且提供新建、排序功能。此外,每个分类项还包含一个提示信息和可展开的操作菜单。
摘要由CSDN通过智能技术生成

<template>
  <div>
    <el-card shadow="never" :body-style="{ padding: '20px 10px 0px' }" class="left-card">
      <el-input prefix-icon="el-icon-search" placeholder="请输入名称" v-model="typeName" clearable style="margin-bottom: 20px" v-if="isSearch"></el-input>
      <div
        :style="{
          height: `${leftColumnHeight}px`,
          overflow: 'auto',
          paddingRight: '6px',
        }"
      >
        <div v-for="item in filterList" :key="item.typeId" class="left-column-name" :class="{ isActive: item.active }" @click="handleClick(item)">
          <div class="left-column-item">
            <div>
              <span>{{ item.typeName }}</span>
              <span v-if="item.count || item.count == 0" style="font-size: 12px">({{ item.count }})</span>
            </div>
            <div class="item-tips">
              <el-tooltip :content="item.typeName" placement="top" effect="light">
                <vab-icon icon="information-line" class="tips" />
              </el-tooltip>
            </div>
            <!-- isHideButton:是否隐藏每一项中的操作按钮 -->
            <el-popover trigger="hover" placement="right-start" popper-class="app-popper" v-if="isHandle && !item.isHideButton">
              <div style="margin: 0">
                <div>
                  <el-button type="text" @click="handleEdit(item)">编辑</el-button>
                </div>
                <div>
                  <el-button type="text" @click="handleDelete(item)" style="color: #ff3333" v-if="isDelete">删除</el-button>
                </div>
              </div>
              <div slot="reference">
                <vab-icon icon="more-fill" class="vab-popover" />
              </div>
            </el-popover>
          </div>
        </div>
      </div>
      <div class="left-column-bottom" v-if="isHandle">
        <div class="sort" v-if="isSort">
          <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新建</el-button>
          <el-button icon="el-icon-d-caret" @click="handleSort">排序</el-button>
        </div>
        <div class="un-sort" v-else>
          <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新建</el-button>
        </div>
      </div>
    </el-card>
  </div>
</template>
<script>
  export default {
    name: 'LeftColumn',
    props: {
      // 左侧栏目高度
      leftColumnHeight: {
        type: Number,
        default: 564,
      },
      // 是否需要操作按钮(新增/编辑/删除)
      isHandle: {
        type: Boolean,
        default: true,
      },
      // 是否需要删除
      isDelete: {
        type: Boolean,
        default: true,
      },
      // 是否需要输入框搜索
      isSearch: {
        type: Boolean,
        default: true,
      },
      // 是否需要排序
      isSort: {
        type: Boolean,
        default: false,
      },
      // 左侧栏目数据列表 需要字段 类型id:typeId,类型名称:typeName,数量:count
      leftColumnList: {
        type: Array,
        default: () => [],
      },
    },
    data() {
      return {
        // 标题名称
        typeName: '',
        timeout: null,
      }
    },
    computed: {
      // 过滤传入的list,前端查询
      filterList() {
        let arr = []
        if (this.leftColumnList.length > 0) {
          this.leftColumnList.forEach((item) => {
            // 处理列表数据,添加选择样式:active(true/false)
            this.$set(item, 'active', false)
            arr.push(item)
          })
          if (this.typeName) {
            arr = this.leftColumnList.filter((item) => item.typeName.includes(this.typeName))
          }
          if (arr.length > 0) {
            arr[0].active = true
          }
          return arr
        }
      },
    },
    created() {},
    mounted() {
      //初始化
      this.timeout = setTimeout(() => {
        this.$emit('handleClick', this.leftColumnList[0])
      }, 1000)
    },
    watch: {
      filterList(val) {},
    },
    methods: {
      // 点击分类
      handleClick(value) {
        this.filterList.forEach((item) => {
          item.active = false
        })
        value.active = true
        this.$emit('handleClick', value)
      },
      // 新建
      handleAdd() {
        this.$emit('handleAdd')
      },
      // 修改
      handleEdit(value) {
        this.$emit('handleEdit', value)
      },
      // 删除
      handleDelete(value) {
        this.$emit('handleDelete', value)
      },
      // 排序
      handleSort() {
        this.$emit('handleSort')
      },
    },
    beforeDestroy() {
      clearTimeout(this.timeout)
      this.timeout = null
    },
  }
</script>
<style lang="scss" scoped>
  .left-column-name {
    width: 100%;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    margin-bottom: 6px;
    color: #606266;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    border-radius: 6px;
  }

  .left-column-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    & > div:first-child {
      width: 86%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .item-tips {
      flex: 1;
      display: none;
      text-align: center;
    }
    & > span:last-child {
      display: inline-block;
      flex: 1;
      margin-left: 6px;
    }
  }

  .left-column-bottom {
    margin-bottom: 20px;

    .sort {
      display: flex;
      justify-content: space-between;
      align-items: center;

      ::v-deep .el-button {
        width: 48%;
      }
    }

    .un-sort {
      display: flex;
      justify-content: space-between;
      align-items: center;

      ::v-deep .el-button {
        width: 100%;
      }
    }
  }

  .vab-popover {
    display: none;
    font-size: 22px;
  }

  .app-popper {
    margin-left: -10px !important;
  }

  .left-column-name:hover {
    background-color: #eff0f0;
    .item-tips {
      flex: 1;
      display: block;
      text-align: center;
      color: #1684fc;
    }
    .vab-popover {
      display: block;
      color: #1684fc;
      cursor: pointer;
    }
  }

  .isActive {
    color: #fff !important;
    background-color: rgba(51, 148, 254) !important;
    .item-tips {
      flex: 1;
      display: block;
      text-align: center;
      color: #fff !important;
    }
    .vab-popover {
      display: block;
      color: #fff !important;
      cursor: pointer;
    }
  }

  ::v-deep .el-card {
    margin-bottom: 0px !important;
    border-bottom: none;
  }
</style>

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值