function createPopup(data) {
let loading = uni.getStorageSync('loading')
console.log(loading,'==============')
const $iconUrl = loading.loadingPath? loading.loadingPath: "/static/loading/default/loading.gif";
const iconWidth = loading.loadingWidth || 30
const iconHeight = loading.loadingHeight || 30
const screenWidth = plus.screen.resolutionWidth;
const screenHeight = plus.screen.resolutionHeight;
//弹窗容器宽度
const popupViewWidth = screenWidth * 0.6;
// 弹窗容器的Padding
const viewContentPadding = 20;
// 弹窗容器的宽度
const viewContentWidth = popupViewWidth - (viewContentPadding * 2);
// 弹窗容器高度
let popupViewHeight = viewContentPadding * 3 + 60;
// 弹窗遮罩层
let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层
top: '0px',
left: '0px',
height: '100%',
width: '100%',
backgroundColor: loading.loadingBg? loading.loadingBg: 'rgba(255,255,255,0.8)'
});
// 弹窗内容
let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单
tag: "rect",
top: (screenHeight - popupViewHeight) / 2 + "px",
left: '20%',
height: popupViewHeight + "px",
width: "60%",
});
let elementList = [
// {
// tag: 'rect', //背景色
// color: '#FFFFFF',
// rectStyles: {
// radius: "8px"
// }
// },
// {
// tag: 'font',
// id: 'title',
// text: "加载中",
// textStyles: {
// size: '16px',
// color: "#333",
// weight: "bold",
// verticalAlign: "middle",
// whiteSpace: "normal"
// },
// position: {
// top: 10 + 'px',
// height: "30px",
// }
// },
{
src: $iconUrl,
id: "logo",
tag: "img",
position: {
top: "20px",
left: (popupViewWidth - iconWidth) / 2 + "px",
width: iconWidth +'px',
height: iconHeight +'px',
}
},
];
popupView.draw(elementList);
const showLoading = () => {
// 显示弹窗
maskLayer.show();
popupView.show();
}
const hideLoading = () => {
// 隐藏弹窗
maskLayer.hide();
popupView.hide();
}
// 改变进度条
return {
showLoading,
hideLoading
};
}
const {showLoading,hideLoading} = createPopup()
uni.$showLoading = showLoading
uni.$hideLoading = hideLoading
基于plus.nativeObj.View 的全局loading
最新推荐文章于 2024-05-30 14:37:59 发布