当前位置: 首页 > news >正文

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)
    },```

相关文章:

  • llama.cpp框架下GGUF格式及量化参数全解析
  • 蓝桥杯备赛-基础练习 day1
  • RAGFlow版本升级-Win10系统Docker
  • tomcat负载均衡配置
  • golang字符串常用的系统函数
  • Linux练级宝典->任务管理和守护进程
  • 基于C语言的简单HTTP Web服务器实现
  • 施磊老师c++笔记(五)
  • 【NLP 33、实践 ⑦ 基于Triple Loss作表示型文本匹配】
  • 计算机网络基础:IIS服务器(FTP服务器)
  • [React Native]Stack、Tab和Drawer导航器详解
  • Node.js Web 模块详解
  • Dockerfile Add和Copy的区别。
  • Amazon RDS ProxySQL 探索(一)
  • C语言数据结构:数组
  • 【vue】路由出口监听组件钩子
  • 【Go学习】04-4-Gorm框架-增删改查事务钩子
  • 计算机网络——DHCP
  • 如何精准打点解决卡牌、SLG、开放大世界、放置类游戏卡顿难题
  • body-parser 与 express.json()、express.urlencoded() 会冲突
  • 网站突然打不开了/提高网站排名
  • 福建泉州曾明军的网站/信息检索关键词提取方法
  • 陕西城乡建设厅网站/临沂网站seo
  • 网店美工培训/广州seo工程师
  • 政府网站 html/百度关键词优化软件
  • 宿迁做网站的/现在什么网络推广好