';
floatBtnListHtml += '
建议上传正方形图片,大小建议为33px * 33px
';
floatBtnListHtml += '
';
floatBtnListHtml += '- ';
floatBtnListHtml += '';
floatBtnListHtml += '
';
floatBtnListHtml += '
';
floatBtnListHtml += '';
floatBtnListHtml += '';
floatBtnListHtml += '
';
floatBtnListHtml += '
';
floatBtnListHtml += 'x';
floatBtnListHtml += '';
floatBtnListHtml += ' ';
floatBtnListHtml += '
';
floatBtnListHtml += '
';
floatBtnListHtml += '+';
floatBtnListHtml += '添加一个浮动按钮';
floatBtnListHtml += '
';
// floatBtnListHtml += '
';
// floatBtnListHtml += '+';
// floatBtnListHtml += '添加一个浮动按钮';
// floatBtnListHtml += '
';
floatBtnListHtml += '
';
Vue.component("float-btn-list", {
data: function () {
return {
list: this.$parent.data.list,
maxTip: 3,//最大上传数量提示
showAddItem: true,
systemInfo: {
top: 0,
left: 0,
right: 0,
bottom: 0,
width: 0
},
screenWidth: 0,
typeList: [
{
text: "链接",
value: "link"
},
{
text: "返回顶部",
value: "gotop"
},
{
text: "客服",
value: "custom"
}
]
};
},
created: function () {
if (!this.$parent.data.verify) this.$parent.data.verify = [];
this.$parent.data.verify.push(this.verify);//加载验证方法
this.getElementPosition(this.$parent);
// window.addEventListener('resize', onResize);
window.onresize = () => {
return (() => {
window.screenWidth = document.body.clientWidth
this.screenWidth = window.screenWidth
})()
}
this.changeShowAddItem();//获取默认值
},
watch: {
list: function () {
this.changeShowAddItem();
},
screenWidth(val) {
// 为了避免频繁触发resize函数导致页面卡顿,使用定时器
this.getElementPosition(this.$parent)
}
},
methods: {
verify: function () {
var res = { code: true, message: "" };
if (this.list.length > 0) {
for (var i = 0; i < this.list.length; i++) {
if (this.$parent.data.list[i].imageUrl == "") {
res.code = false;
res.message = "请添加图片";
break;
}
}
} else {
res.code = false;
res.message = "请添加一个浮动按钮";
}
return res;
},
//改变添加浮动按钮
changeShowAddItem() {
if (this.list.length >= this.maxTip) this.showAddItem = false;
else this.showAddItem = true;
},
getElementPosition(e) {
var box = document.querySelector("#viewWrap").getBoundingClientRect()
var box1 = document.querySelector(".screen_center").getBoundingClientRect();
if (this.$parent.data.bottomPosition == 2) {
// this.$parent.data.baseBtnBottom = Math.abs(box1.top) + 20;
this.$parent.data.baseBtnBottom = 150;
var temp = 150 + parseInt(this.$parent.data.btnBottom);
$(".draggable-element .float-btn").css({
left: box1.left + 285,
top: temp,
'margin-right': '15px',
'z-index': 999,
height: '40px'
});
}
else if (this.$parent.data.bottomPosition == 3) {
this.$parent.data.baseBtnBottom = 250
// var temp = 250 + parseInt(this.$parent.data.btnBottom)
var temp = 270;
$(".draggable-element .float-btn").css({
left: box1.left - 30,
top: 'auto',
bottom: temp,
'z-index': 999
});
} else if (this.$parent.data.bottomPosition == 1) {
this.$parent.data.baseBtnBottom = Math.abs(box.top) + 20;
// var temp = Math.abs(box1.top) + parseInt(this.$parent.data.btnBottom) + 20;
var temp = 150 + parseInt(this.$parent.data.btnBottom);
$(".draggable-element .float-btn").css({
left: box1.left,
top: temp,
'z-index': 999,
height: '40px'
});
} else {
this.$parent.data.baseBtnBottom = 250
var temp = 250 + parseInt(this.$parent.data.btnBottom)
$(".draggable-element .float-btn").css({
left: box1.left + 285,
top: 'auto',
bottom: temp,
'margin-right': '15px',
'z-index': 999
});
}
$(".draggable-element .float-btn .edit-attribute").css({
position: 'fixed',
right: '30px',
top: Math.abs(box.top),
})
}
},
template: floatBtnListHtml
});
var searchHtml = '