vue通过click和shift实现连续多选功能

vue通过click和shift实现连续多选功能

思路

1. 判断是否是shift+click

2. 判断是否是第一次进行shift + click点击

2.1 若是第一次shift+click点击,则选中当前点击

2.2 若是多次shift+click点击,则进行连续多选操作

3. 若仅为click点击,则进行单击操作

  selectFiles(e, value, index) {
      if (e.shiftKey) { // 点击的时候,按着shift键
        if (this.startClickFile) { // 第二次(或多次)按着shift点击,进行连续多选
          const endClickFileIndex = index
          console.log(this.startClickFileIndex, endClickFileIndex);

          // if (this.startClickFileIndex != endClickFileIndex) {
          let start = ''
          let end = ''
          // 处理起始点
          if (this.startClickFileIndex < endClickFileIndex) {
            start = this.startClickFileIndex - 1
            end = endClickFileIndex + 1
          } else {
            start = endClickFileIndex - 1
            end = this.startClickFileIndex + 1
          }
          // 将起始点以及中间的内容选中
          this.dataList.forEach((item, i) => {
            if (i > start && i < end) {
              this.dataList[i]['active'] = true
            } else {
              this.dataList[i]['active'] = false
            }
            var arr = this.dataList
            this.dataList = []
            this.dataList = arr
          })
          // }
          // this.startClickFile = ''
          // this.startClickFileIndex = -1
        } else { // 第一次按着shift点击,仅选中自身
          this.startClickFile = value
          this.startClickFileIndex = index
          this.dataList[index]['active'] = true
          var arr = this.dataList
          this.dataList = []
          this.dataList = arr
        }
      } else {
        clearTimeout(this.timeOut);
        this.timeOut = setTimeout(() => {
          this.dataList[index]['active'] = value.active ? !value.active : true
          var arr = this.dataList
          this.dataList = []
          this.dataList = arr
        }, 600)
      }


      // this.getCatalog(this.filePath,index,value.active ? !value.active : true)
    },```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值