surprise
2023-12-05 6ecef4176f6d9df60cd1a753a36e09cd96bce9b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<template>
  <Popup
    ref="pop"
    :title="title"
    @close="close"
    showBtn="true"
    @yes="sendData"
    @cancel="close(true)"
  >
    <div class="treeContainer">
      <el-tree
        ref="tree"
        show-checkbox
        :data="treeData"
        node-key="id"
        default-expand-all
        :render-content="renderContent"
        :expand-on-click-node="false"
        :auto-expand-parent="false"
        :default-checked-keys="defaultChecked"
      >
      </el-tree>
    </div>
  </Popup>
</template>
 
<script>
import Popup from "@tools/Popup";
import baseVuex from "@mixin/baseVuex";
export default {
  name: "tree",
  components: { Popup },
  mixins: [baseVuex],
  data() {
    return {
      isOpen: false,
      title: "展示数据选取",
      actionType: "",
      defaultChecked: [],
      isUpdate: false,
    };
  },
  methods: {
    open(actionType, defaultChecked = [], isUpdate = false) {
      this.isUpdate = isUpdate;
      this.defaultChecked = defaultChecked;
      this.actionType = actionType;
      this.$refs.pop.open();
      this.isOpen = true;
    },
    close(isCancel) {
      Object.assign(this.$data, this.$options.data());
      if (isCancel) {
        this.$refs.pop.close();
      }
      this.isOpen = false;
    },
    // 完成选择,传递数据
    sendData() {
      if (this.isUpdate) {
        this.$emit("updateData", this.$refs.tree.getCheckedKeys());
        this.close(true);
        return;
      }
      this.$emit("success", this.$refs.tree.getCheckedKeys(), this.actionType);
      this.close(true);
    },
    // 渲染
    renderContent(h, { node, data }) {
      return (
        <span class="custom-tree-node">
          <span>
            <i class={data.children ? "el-icon-folder" : ""}></i>
            {data.name}
          </span>
        </span>
      );
    },
  },
};
</script>
 
<style lang="less" scoped>
.treeContainer {
  max-height: 500px;
  overflow-y: auto;
  overflow-x: hidden;
  &::-webkit-scrollbar {
    /*滚动条整体样式*/
    width: 8px;
    /*高宽分别对应横竖滚动条的尺寸*/
    height: 8px;
    scrollbar-arrow-color: red;
  }
 
  &::-webkit-scrollbar-thumb {
    border-radius: 5px;
    -webkit-box-shadow: inset 0 0 5px rgba(218, 218, 218, 0.2);
    box-shadow: inset 0 0 5px rgba(218, 218, 218, 0.2);
    background: #797979;
    scrollbar-arrow-color: red;
  }
 
  &::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 5px rgba(218, 218, 218, 0.2);
    box-shadow: inset 0 0 5px rgba(218, 218, 218, 0.2);
    border-radius: 0;
    background: rgba(218, 218, 218, 0.1);
  }
  .el-tree {
    background: transparent;
    color: #fff;
  }
 
  /deep/ .el-tree-node__content:hover {
    background-color: rgba(245, 247, 250, 0.2);
  }
 
  /deep/ .el-tree-node:focus > .el-tree-node__content {
    background-color: rgba(245, 247, 250, 0.2);
  }
 
  /deep/ .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 10px;
 
    i {
      margin-right: 5px;
    }
  }
}
.btnContainer {
  margin-top: 10px;
  display: flex;
  justify-content: space-evenly;
}
</style>