widgetHtmlSlider.vue
3.38 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
<template>
<div :style="style" v-if="isRouterAlive">
<el-carousel arrow="always" height="100%" class="carousel" :direction="carouselStyle.direction"
:indicator-position="carouselStyle.indicatorPosition" :interval="carouselStyle.interval"
:type="carouselStyle.type" :key="carouselKey">
<el-carousel-item v-for="(url, index) in urlData" :key="index">
<iframe class="carousel-img" :src="url" alt="" />
</el-carousel-item>
</el-carousel>
</div>
</template>
<script>
import Vue from 'vue'
import iframeResize from 'iframe-resizer/js/iframeResizer'
Vue.use(iframeResize)
export default {
name: 'WidgetHtmlSlider',
components: {},
props: {
value: Object,
ispreview: Boolean
},
data() {
return {
options: {},
urlData:[],
optionsSetUp:{},
carouselKey: 0, // 重新渲染组件用
flagInter: null,
isRouterAlive:true,
};
},
mounted () {
// 内嵌iframe时
// this.iframeResizer({log: true,}, this.$refs.iframe);
// this.changeFrameHeight();
},
computed: {
transStyle() {
const obj = this.objToOne(this.options);
return obj;
},
style() {
//整屏显示
return {
position: this.ispreview ? "absolute" : "static",
width: "100%",
height: "100%",
left:"0px",
top:"0px",
};
},
carouselStyle() {
this.initData(this.transStyle);
return {
//imageList: this.isBlank(this.transStyle.imageAdress)?[]:this.transStyle.imageAdress.split(","),
direction: !this.transStyle.tabType ? this.transStyle.tabDirection : 'horizontal',
indicatorPosition: this.transStyle.tabSelector,
interval: this.transStyle.tabTime,
type: this.transStyle.tabType
}
}
},
watch: {
value: {
handler(val) {
this.options = val;
this.optionsSetUp = val.setup;
this.handlerUrlData();
},
deep: true,
},
carouselStyle: {
handler(newValue, oldValue) {
if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
this.carouselKey++;
}
},
},
},
created() {
this.options = this.value;
},
methods: {
reload(){
this.isRouterAlive=false;
this.$nextTick(function(){
this.isRouterAlive=true;
})
},
initData(data) {
let urlUp =[];
if(this.hasOwn(data,"urls")){
urlUp = data['urls'];
}
let urlData = [];
if(this.isNotBlankArray(urlUp)){
for(let i=0;i<urlUp.length;i++){
const url = urlUp[i].url;
urlData[i] = url;
}
}
console.log("12",urlData);
this.urlData = urlData;
this.urlData={...this.urlData};
},
handlerUrlData(){
const data = this.optionsSetUp;
let urlUp =[];
if(this.hasOwn(data,"urls")){
urlUp = data['urls'];
}else if(this.hasOwn(data,"dynamicHtmlSlider")){
urlUp = data['dynamicHtmlSlider'];
}
let urlData = [];
if(this.isNotBlankArray(urlUp)){
for(let i=0;i<urlUp.length;i++){
const url = urlUp[i].url;
urlData[i] = url;
}
}
this.urlData = urlData;
this.urlData={...this.urlData};
},
},
}
</script>
<style scoped lang="scss">
.carousel {
width: 100%;
height: 100%;
}
.carousel-img {
width: 100%;
height: 100%;
}
</style>