loulijun2021
2023-06-06 3a9c0a33f8358cd81542994701436fbc99def3da
src/components/DndList/index.vue
@@ -9,7 +9,10 @@
        <draggable :set-data="setData" :list="list1" class="dragArea" animation="300" @end="draggableEnded">
          <div v-for="item in list1" :key="item.id" class="list-complete-item">
            <div style="display: flex">
              <div style="width: 20px;height: 20px;margin-right: 4px;cursor:move"><i class="el-icon-rank" /></div>
              <div style="width: 20px;height: 20px;margin-right: 4px;cursor:move;"><i
                style="font-weight: bolder"
                class="el-icon-rank"
              /></div>
              <el-checkbox :label="item.label" class="list-complete-item-handle" />
            </div>
            <div>
@@ -59,7 +62,7 @@
    return {
      checkedList: this.list1.map(i => i.show ? i.label : '').filter(i => i !== ''), // 列展示值
      checkedListDefaultLabel: this.list1.map(i => i.show ? i.label : '').filter(i => i !== ''), // 重置默认值label
      // checkedListDefaultFixed: this.list1.map(i => i.show ? i.label : '').filter(i => i !== ''), // 重置默认值fixed
      checkedListDefaultFixed: this.list1.map(i => i.fixed), // 重置默认值fixed
      checkedAll: true
    }
  },
@@ -76,8 +79,12 @@
    // 重置
    resetColumn() {
      this.checkedList = this.checkedListDefaultLabel
      this.list1.sort((a, b) => a.id - b.id)// 排序
      this.list1.forEach((i, j) => {
        i.show = !!this.checkedListDefaultLabel.includes(i.label)
      })
      this.checkedListDefaultFixed.forEach((i, j) => {
        this.list1[j].fixed = i
      })
      this.$emit('tableColumnUpdate', this.checkedListDefaultLabel)
    },
@@ -96,26 +103,25 @@
    },
    // 固定到左侧
    fixedToLeft(val) {
      console.log('fixedToLeft', val)
      this.list1.find(i => i.label === val).fixed = this.list1.find(i => i.label === val).fixed !== 'left' ? 'left' : false
      if (this.list1.find(i => i.label === val).show) {
        this.list1.find(i => i.label === val).fixed = this.list1.find(i => i.label === val).fixed !== 'left' ? 'left' : false
      }
      this.$emit('tableColumnUpdate', this.checkedList)
    },
    // 固定到右侧
    fixedToRight(val) {
      console.log('fixedToRight', val)
      this.list1.find(i => i.label === val).fixed = this.list1.find(i => i.label === val).fixed !== 'right' ? 'right' : false
      if (this.list1.find(i => i.label === val).show) {
        this.list1.find(i => i.label === val).fixed = this.list1.find(i => i.label === val).fixed !== 'right' ? 'right' : false
      }
      this.$emit('tableColumnUpdate', this.checkedList)
    },
    // 拖动结束事件
    draggableEnded({ to, from, item, clone, oldIndex, newIndex }) {
      console.log(to, from, item, clone, oldIndex, newIndex)
      // console.log(this.list1, 123456789)
      // console.log(to, from, item, clone, oldIndex, newIndex)
      this.$emit('tableColumnUpdate', this.list1, true)// 传给爷爷  isCopyTrue:复值给爷爷
    },
    // 多选框值改变事件
    checkedListChange(val) {
      console.log(val, 1)
      this.checkedAll = val.length !== 0
      this.list1.forEach((i, j) => {
        i.show = !!val.includes(i.label)
@@ -148,7 +154,7 @@
    .dragArea {
      margin-top: 15px;
      min-height: 50px;
      padding-bottom: 30px;
      //padding-bottom: 30px;
    }
  }
}