';
floatBtnListHtml += '
建议上传正方形图片
';
floatBtnListHtml += '
';
floatBtnListHtml += '- ';
floatBtnListHtml += '';
floatBtnListHtml += '
';
floatBtnListHtml += '
';
floatBtnListHtml += '
';
floatBtnListHtml += '
';
floatBtnListHtml += '
';
floatBtnListHtml += '
';
floatBtnListHtml += '
';
floatBtnListHtml += 'x';
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,
screenWidth:0,
colorPicker:{}
};
},
created : function(){
if(!this.$parent.data.verify) this.$parent.data.verify = [];
this.$parent.data.verify.push(this.verify);//加载验证方法
this.$parent.data.ignore = ['textColor','pageBgColor','componentBgColor','elementBgColor','marginTop','marginBottom','marginBoth','componentAngle','elementAngle'];//加载忽略内容 -- 其他设置中的属性设置
this.$parent.data.ignoreLoad = true; // 等待忽略数组赋值后加载
getElementPosition(this.$parent);
window.onresize = () => {
return (() => {
window.screenWidth = document.body.clientWidth;
this.screenWidth = window.screenWidth
})()
};
this.changeShowAddItem();//获取默认值
this.list.forEach(function (item) {
if (!item.id) item.id = ns.gen_non_duplicate(10)
})
},
watch : {
list : function(){
this.changeShowAddItem();
getElementPosition(this.$parent)
},
screenWidth(val){
// 为了避免频繁触发resize函数导致页面卡顿,使用定时器
getElementPosition(this.$parent);
},
"$parent.data.btnBottom": function () {
getElementPosition(this.$parent);
}
},
mounted(){
this.fetchAllMenuIconColor();
},
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 == "" && this.$parent.data.list[i].icon == ""){
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;
},
/**
* 选择图标风格
* @param event
* @param index
*/
iconStyle(event, index){
var self = this;
selectIconStyle({
elem: event.currentTarget,
icon: self.list[index].icon,
callback: function (data) {
if (data) {
self.list[index].style = data;
} else {
iconStyleSet({
style: JSON.stringify(self.list[index].style),
query: {
icon: self.list[index].icon
}
}, function(style){
self.list[index].style = style;
})
}
}
})
},
/**
* 渲染颜色组件
* @param id
* @param color
* @param callback
*/
colorRender(id, color, callback){
var self = this;
if (this.colorPicker[id]) return;
setTimeout(function () {
self.colorPicker[id] = Colorpicker.create({
el: id,
color: color,
change: function (elem, hex) {
callback(elem, hex)
}
});
})
},
/**
* 渲染全部菜单颜色选择器
*/
fetchAllMenuIconColor(){
var self = this;
this.list.forEach(function (item, index) {
self.colorRender('float-btn-color-' + index, '', function (elem, color) {
index = $(elem).parents('li').index();
if (self.list[index].style.iconBgColor.length || self.list[index].style.iconBgImg) {
self.list[index].style.iconBgColor = [color];
} else {
self.list[index].style.iconColor = [color];
}
self.$forceUpdate();
})
})
},
add(){
var self = this;
this.list.push({ imageUrl : '', title : '', link : {name: ''}, iconType: 'img', icon: '', style: {fontSize: 60, iconBgColor: [], iconBgColorDeg: 0,iconBgImg: '',bgRadius: 0,iconColor: ['#000'],iconColorDeg: 0}})
this.colorRender('float-btn-color-' + (this.list.length - 1), '', function (elem, color) {
var index = $(elem).parents('li').index();
if (self.list[index].style.iconBgColor.length || self.list[index].style.iconBgImg) {
self.list[index].style.iconBgColor = [color];
} else {
self.list[index].style.iconColor = [color];
}
self.$forceUpdate();
})
},
del(index){
this.list.splice(index, 1);
delete this.colorPicker['float-btn-color-' + index];
}
},
template: floatBtnListHtml
});
/**
* 按钮位置
*/
var btnPosition = '