-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.vue
241 lines (234 loc) · 6.49 KB
/
index.vue
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<template>
<el-card class="aside-layout" shadow="never">
<div slot="header" class="aside-layout__header clearfix">
<div style="line-height: 28px;">布局操作</div>
</div>
<section class="aside-layout__rowEdit">
<row-select type="addRow" @editRow="onAddRow"/>
<row-select type="editRow" :activeLayOut="activeLayOut" @editRow="onEditRow"/>
<row-select type="deleteRow" @deleteRow="onDeleteRow"/>
</section>
<div class="aside-layout__colitems-wrap">
<draggable
v-model="colitemsGroup"
class="aside-layout__colitems-group"
tag="ul"
:move="checkMove"
v-bind="dragOptions"
@start="dragging = true"
@end="dragging = false"
>
<transition-group type="transition" :name="!dragging ? 'flip-list' : null">
<li
class="aside-layout__colitem"
v-for="(element, idx) in colitemsGroup"
:key="element.prop || idx"
:class="{'aside-layout__colitem--active': element.prop === activeProp}"
@click="onEditComp(element.prop)"
>
<template v-if="element.prop">
<span>{{ element.colGrid ? element.colGrid.span : '' }}</span>
<span>{{ element.prop }}</span>
<div class="colitem-icon colitem-icon--delete" @click="handleRemoveColumn(element, idx)">
<svg viewBox="0 0 28 28" preserveAspectRatio="xMidYMid meet" shape-rendering="geometricPrecision">
<g><path d="M19 9h-3V8a1 1 0 0 0-1-1h-2a1 1 0 0 0-1 1v1H9a1 1 0 1 0 0 2h10a1 1 0 0 0 .004-2H19zM9 20c.021.543.457.979 1 1h8c.55-.004.996-.45 1-1v-7H9v7zm2.02-4.985h2v4h-2v-4zm4 0h2v4h-2v-4z" fill-rule="evenodd"></path></g>
</svg>
</div>
</template>
<template v-else>
<span>{{ element.colGrid ? element.colGrid.span : '' }}</span>
</template>
</li>
</transition-group>
</draggable>
</div>
</el-card>
</template>
<script>
import Draggable from 'vuedraggable'
import RowSelect from './module/row-select'
export default {
name: 'AsidePanel',
components: {
Draggable,
RowSelect
},
props: {
activeSection: Number, // 激活行index
activeProp: String // 激活的prop
},
inject: ['fg'],
data () {
return {
// aside
activeLayout: [],
dragging: false,
dragOptions: {
animation: 200,
group: 'colitem',
disabled: false,
ghostClass: 'ghost'
}
}
},
computed: {
colitemsGroup: {
get () {
return this.fg.layoutSections[this.activeSection] || []
},
set (val) {
this.fg.layoutSections.splice(this.activeSection, 1, val)
}
},
activeLayOut () {
return this.colitemsGroup.map(item => item.colGrid.span)
}
},
methods: {
handleChangeLayout (data) {
const initVal = data.map((val, idx) => {
return {
colGrid: { span: val },
isCustom: 'btn-addCol'
}
})
this.fg.layoutSections.push(initVal)
},
checkMove (e) {
console.log('Future index: ' + e.draggedContext.futureIndex)
},
handleRemoveColumn (element, colIndex) {
const oldSection = {
isCustom: 'btn-addCol',
colGrid: element.colGrid
}
this.fg.layoutSections[this.activeSection].splice(colIndex, 1, oldSection)
this.$emit('deleteComp', element.prop)
},
onAddRow (data) {
const initVal = data.map((val, idx) => {
return {
colGrid: { span: val },
isCustom: 'btn-addCol'
}
})
this.fg.layoutSections.push(initVal)
let _activeSection = this.fg.layoutSections.length - 1
this.$emit('update:activeSection', _activeSection)
this.$emit('deleteComp', '')
},
onEditRow (data) {
let _result = data.map((grid, idx) => {
let _cur = this.colitemsGroup[idx]
if (_cur) {
return { ..._cur, colGrid: { span: grid } }
}
return { colGrid: { span: grid }, isCustom: 'btn-addCol' }
})
// 删除冗余的prop
if (data.length < this.colitemsGroup.length) {
let _delPart = this.colitemsGroup.slice(data.length)
_delPart.forEach(grid => {
this.delModuleAndOption(grid)
})
}
this.fg.layoutSections.splice(this.activeSection, 1, _result)
this.$emit('deleteComp', '')
},
delModuleAndOption (grid) {
// 删除module
if (this.fg.formModel.hasOwnProperty(grid.prop)) this.$delete(this.fg.formModel, grid.prop)
// 删除option
if (this.fg.formOptions.hasOwnProperty(grid.prop)) this.$delete(this.fg.formOptions, grid.prop)
},
onDeleteRow () {
this.colitemsGroup.forEach(grid => {
this.delModuleAndOption(grid)
})
let _activeSection = this.activeSection === 0 ? 0 : this.activeSection - 1
this.fg.layoutSections.splice(this.activeSection, 1)
this.$emit('update:activeSection', _activeSection)
this.$emit('deleteComp', '')
},
onEditComp (prop) {
this.$emit('editComp', prop || '')
}
}
}
</script>
<style lang="less">
@primary: #7367f0;
.aside-layout {
.el-card__header {
background-color: @primary;
padding: 6px 12px;
}
}
</style>
<style lang="less" scoped>
@primary: #7367f0;
@grey: #cfcbcb;
.aside-layout {
height: 100%;
border: 1px solid @primary;
&__header {
font-size: 14px;
color: #ffffff;
}
&__rowEdit {
margin-bottom:12px;
display: flex;
justify-content: space-between;
// & > *:not(:last-child){
// margin-right: 20px;
// }
}
&__colitems-wrap {
margin-top: 20px;
}
&__colitem {
cursor: move;
list-style: none;
background: #f1f5f9;
font-size: 13px;
// min-height: 40px;
font-weight: 600;
color: #32373c;
margin-bottom: 10px;
border-radius: 3px;
padding: 10px;
position: relative;
display: flex;
justify-content:space-between;
line-height: 1.5em;
&--active{
box-shadow: 0 0 10px @grey;
}
.colitem-icon {
display: inline-block;
transition: fill .2s ease;
cursor: pointer;
}
.colitem-icon--delete {
fill: #737e89;
width: 28px;
min-width: 28px;
height: 28px;
margin: -6px;
}
}
&__colitem-action {
display: flex;
flex-direction: column;
font-size: 13px;
align-items: center;
.colitem-action__label {
padding: 8px 16px;
}
}
}
.ghost {
opacity: 0.5;
background: #c8ebfb;
}
</style>