canvasEditPage.vue
8.36 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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<template>
<div class="layout hom-layout" v-loading="loading">
<draggable
class="dragArea list-group"
:list="componentsData"
group="pageEdit"
@change="pageChange"
>
<div class="list-group-item" v-for="(item,index) in componentsData" :key="index" :class="[{'on':activeComponent == index},'item-'+item.type]" @click="selectComponent(item,index)">
<component v-show="!item.isEmpty" :isNoData.sync='item.isEmpty' :is="componentMap[terminal-1].get(item.type)" :componentContent="item.componentContent" :terminal="terminal" :typeId="typeId" :shopId="shopId" @cleckLoading="cleckLoading"></component>
<div class="no-data" v-show="item.isEmpty">
<i class="iconfont icon-kong"></i>
<p>暂无数据<br>请在右边窗口编辑内容</p>
</div>
<div class="btns">
<span @click="delComponent(item,index)"><i class="iconfont icon-shanchu"></i></span>
</div>
</div>
</draggable>
</div>
</template>
<script>
import draggable from 'vuedraggable'
import componentMap from './canvasShow/componentMap'
import { mapGetters, mapMutations } from 'vuex'
export default {
// import testData from '@@/config/testData3'
name: 'canvasEditPage',
components: {
draggable
},
props: {
terminal: {
type: Number,
default: 4
},
typeId: {
type: Number,
default: 1
},
shopId: {
type: Number,
default: 0
}
},
data () {
return {
activeComponent: -1,
componentMap: componentMap,
loading: false
}
},
mounted () {
// this.setComponentsData(testData)
},
computed: {
...mapGetters([
'componentsData'
])
},
methods: {
...mapMutations({
setActiveComponent: 'SET_ACTIVECOMPONENT',
setComponentsData: 'SET_COMPONENTSDATA'
}),
// 画布添加或者移动了组件
pageChange (e) {
if (e.added) {
this.activeComponent = e.added.newIndex
e.added.element.index = e.added.newIndex
this.setActiveComponent(e.added.element)
}
if (e.moved) {
this.activeComponent = e.moved.newIndex
e.moved.element.index = e.moved.newIndex
this.setActiveComponent(e.moved.element)
}
this.$emit('showRightBox', true)
},
// 选中组件
selectComponent (item, index) {
this.activeComponent = index
item.index = index
this.setActiveComponent(item)
this.$emit('showRightBox', true)
},
// 删除组件
delComponent (item, index) {
this.$confirm('确定删除吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.activeComponent = -1
this.componentsData.splice(index, 1)
this.$emit('showRightBox', false)
}).catch(() => {
})
},
cleckLoading(){
if(typeof(uni) !== 'undefined'){
uni.getStorage({
key: 'sendNum',
success: function (res) {
let sendNum = res.data;
this.loading = parseInt(sendNum) !== 0
}
})
} else {
let sendNum = localStorage.getItem('sendNum')
this.loading = parseInt(sendNum) !== 0
}
},
// 检查组件是否为空
checkIsNoData(dataList) {
for(let i=0;i<dataList.length;i++){
const newVal = dataList[i].componentContent
let isEmpty = true
let _data = ''
switch (dataList[i].type){
case 'banner':
_data=newVal.bannerData
_data.forEach(function(value ){
if(value.bannerUrl){
isEmpty = false
}
})
break
case 'notice':
case 'text':
case 'imageTextNav':
case 'imageText':
case 'imageTextList':
case 'brandList':
case 'categoryList':
case 'assistDiv':
isEmpty = false
break
case 'productList':
_data = newVal.productData
if((_data.sourceType=='1' && _data.productIdList.length > 0) || (_data.sourceType=='2' && _data.categoryId != 0)){
isEmpty = false
}
break
case 'custom':
_data=newVal.imgData
_data.forEach(function(value ){
if(value.src){
isEmpty = false
}
})
break
case 'groupList':
if(this.typeId === 1){
isEmpty = false
}
else {
if(newVal.shopGroupWorkId){
isEmpty = false
}
}
break
case 'spikeList':
if(newVal.shopSeckillId){
isEmpty = false
}
break
case 'discountList':
if(newVal.discountId){
isEmpty = false
}
break
case 'priceList':
if(newVal.priceId){
isEmpty = false
}
break
case 'vip':
isEmpty = false
break
case 'coupon':
if(newVal.selectedCoupon.length > 0){
isEmpty = false
}
break
case 'newProduct':
_data = newVal.productData
if((_data.sourceType=='1' && _data.productIdList.length > 0) || (_data.sourceType=='2' && _data.categoryId != 0)){
isEmpty = false
}
break
case 'shop':
_data=newVal.imgTextData
_data.forEach(function(value ){
if(value.img){
isEmpty = false
}
})
break
}
dataList[i].isEmpty = isEmpty
this.$forceUpdate()
}
console.log(dataList)
},
},
// 监控组件是否为空
watch: {
'componentsData': {
handler(newVal, oldVal) {
this.checkIsNoData(newVal)
},
deep: true
}
}
}
</script>
<style lang="scss" scoped>
.hom-layout {
background-color: #fff;
::v-deep .sortable-chosen {
.contentBox {
display: none;
}
.cloneText {
display: block;
width: 100%;
height: 50px;
line-height: 50px;
font-size: 18px;
text-align: center;
background-color: $mainColor;
color: #fff;
}
}
.list-group {
min-height: calc(100vh - 50px);
}
.list-group-item {
position: relative;
cursor: move;
background-color: #fff;
min-height: 100px;
&.item-assistDiv,&.item-notice,&.item-text{
min-height: 0px;
}
.btns {
display: none;
}
&:hover {
&:after {
content: '';
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
border: 1px $mainColor dashed;
z-index: 2;
}
}
&.on {
&:after {
content: '';
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
border: 1px $mainColor solid;
z-index: 2;
}
.btns {
display: block;
position: absolute;
right: -13px;
top: 50%;
margin-top: -13px;
z-index: 3;
span {
display: block;
width: 26px;
height: 26px;
line-height: 26px;
text-align: center;
color: #666;
background-color: #fff;
box-shadow: 0 0 2px rgba(51, 51, 51, 0.2);
cursor: pointer;
}
}
}
}
}
.no-data {
width: 100%;
display: flex;
height: 300px;
-webkit-box-align: center;
align-items: center;
-webkit-box-pack: center;
justify-content: center;
color: #999;
text-align: center;
font-size: 16px;
line-height: 1.8;
.iconfont {
font-size: 100px;
color: $mainColor;
margin-right: 50px;
}
}
</style>
<style lang="scss">
.warp {
width: 690px;
margin: 0 auto;
max-width: 100%;
&.terminal4 {
width: 1200px;
max-width: 100%;
}
}
.flex-box {
display: flex;
}
</style>