index.vue
5.33 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<template>
<el-popover popper-class="gl-col" width="260" trigger="click">
<div>
<div class="gl-title">
表头字段配置
<el-tooltip content="可拖动位置" popper-class="gl-tip" placement="bottom" effect="light">
<i class="gl-icon-circle-question"></i>
</el-tooltip>
</div>
<div class="gl-content">
<el-checkbox-group v-model="innerValue" @change="changeFn">
<vuedraggable v-model="innerOptionsList" draggable=".item" group="tableClomns" animation="10" @start="startHook" @end="endHook">
<template v-for="(item, index) in innerOptionsList">
<template v-if="item.children">
<subOption :key="'tableOpt' + index" :class="{ item: !disabledList.includes(item[attr]) }" :innerOptionsObj="item" :disabledList="disabledList" :attr="attr" :attrLabel="attrLabel" @start="onStartFn" @end="onEndFn" @change="subChange"></subOption>
</template>
<template v-else>
<el-checkbox :key="'tableOpt' + index" :class="{ item: !disabledList.includes(item[attr]) }" :label="item[attr]" :disabled="disabledList.includes(item[attr])">{{ item[attrLabel] }}</el-checkbox>
</template>
</template>
</vuedraggable>
</el-checkbox-group>
</div>
<div class="gl-btns">
<el-button plain size="small" class="btn-three">重置</el-button>
<el-button type="primary" size="small">确定</el-button>
</div>
</div>
<el-button plain size="small" class="btn-three" icon="gl-icon-cog" round slot="reference"></el-button>
</el-popover>
</template>
<script>
import vuedraggable from 'vuedraggable'
import subOption from './sub.vue'
export default {
name: 'GLTableOption',
props: {
// 可选列表
optionsList: {
type: Array,
default: () => []
},
// 默认可选列表关联的属性
attr: {
type: String,
default: 'prop'
},
// 默认可选列表关联的文本属性
attrLabel: {
type: String,
default: 'label'
}
},
data() {
return {
innerValue: [], //父项选中的值
innerOptionsList: [],
disabledList: [],
subSelectArr: [], //子项选中的值
allCheckbox: [] //总的勾选项(包含子项)
}
},
mounted() {
this.innerOptionsList = this.getOrderList()
this.innerValue = this.getCheckAttrList('checkItem')
this.disabledList = this.getCheckAttrList('disabledCheck')
// setTimeout(() => {
// this.getCheckList()
// })
},
methods: {
// 获取选中项的对应的attr属性数组
getCheckAttrList(propertyName) {
return this.innerOptionsList.filter(item => item[propertyName]).map(item => item[this.attr])
},
//排序order(将禁用项提前)
getOrderList() {
return this.optionsList.sort((a, b) => {
if (!a.order) a.order = 0
if (!b.order) b.order = 0
return b.order - a.order
})
},
startHook() {
//拖拽开始
this.$emit('start')
},
endHook() {
//拖拽结束
this.$emit('end', this.innerOptionsList)
},
onStartFn() {
this.startHook()
},
onEndFn(list) {
// console.log('list: ', list)
this.endHook()
},
// 当绑定值变化时触发的事件
changeFn(selectList) {
console.log('selectList: ', selectList)
//选中的checkbox项
let res = selectList.concat(this.subSelectArr)
// 绑定值变化
this.$emit('change', this.getCheckList(), res)
},
subChange(selectList) {
this.subSelectArr = selectList
let res = this.innerValue.concat(selectList)
//总的勾选项
this.allCheckbox = res
// 绑定值变化
this.$emit('change', this.getCheckList(), res)
},
// @vuese
// 获取选中的列表配置项
// @arg 参数1选择的列表(树),参数2选中的项(attr)
getCheckList() {
if (this.innerOptionsList.length === 0) return
const resultArr = this.copySelectData(this.innerOptionsList, [])
return resultArr
},
// 克隆选中的树状结构
copySelectData(originData = [], resultData = []) {
originData.forEach(item => {
if (item.children) {
let temp = {
...item,
children: this.copySelectData([...item.children], [])
}
if (temp.children.length !== 0) {
resultData.push(temp)
}
} else {
if (this.allCheckbox.includes(item[this.attr])) {
resultData.push({ ...item })
}
}
})
return resultData
}
},
components: {
vuedraggable,
subOption
}
}
</script>
<style lang="scss">
// 配置表单项
.gl-col {
.gl-title {
}
.gl-content {
margin-top: 10px;
padding-top: 10px;
padding-bottom: 10px;
border-top: 1px solid #e8e8ea;
border-bottom: 1px solid #e8e8ea;
.el-checkbox {
display: block;
}
}
.gl-btns {
padding-top: 16px;
padding-bottom: 6px;
text-align: right;
}
}
.gl-tip.el-tooltip__popper.is-light {
color: #666666;
border: 0;
box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.08);
.popper__arrow {
border-bottom-color: rgba(0, 0, 0, 0.05) !important;
// box-shadow: 0 -4px 12px 0 rgba(0,0,0,0.1);
&:after {
// display: none;
// border: 0;
}
}
}
</style>