index.js
2.03 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
const popUp = (url) => {
let time = undefined
// 加载弹窗
const showLoading = ({title='加载中...'}={}) => {
let iconUrl = url || ''
//#ifdef APP-PLUS
plus.nativeUI.showWaiting(title, {
color : '#646464',
background : '#f7f7f7',
round : '10px',
loading : {
display : 'block',
icon : '/static/demo/demo.png',
height:'30px',
interval : '50ms'
}
});
//#endif
//#ifdef H5
let div = document.createElement('div')
div.className = 'loadingDiv'
let loadingHtml = `
<div class="loadingDiv-box">
<div class="loadingDiv-box-window">
<img src="${iconUrl}" style="display : none; mode="widthFix" alt="加载中..." class="loadingDiv-box-img" />
<div class="loadingDiv-box-icon" style="background-image: url(${iconUrl});"></div>
</div>
<div class="loadingDiv-box-title">${title}</div>
</div>`
;
div.innerHTML = loadingHtml
document.body.appendChild(div);
let imgData = document.querySelector('.loadingDiv-box-img');
let scale = imgData.naturalHeight ? imgData.naturalWidth/imgData.naturalHeight : 0
let img = document.querySelector('.loadingDiv-box-icon');
let n = 0
time = setInterval(() => {
img.style.backgroundPosition = `${-n*30}px 0px`;
n++;
if(n >= scale){
n = 0
}
}, 100)
//#endif
//#ifndef APP-PLUS || H5
uni.showLoading({
title: title
});
//#endif
}
// 取消加载弹窗
const hideLoading = () => {
//#ifdef APP-PLUS
plus.nativeUI.closeWaiting()
//#endif
//#ifdef H5
let parent = document.querySelector('.loadingDiv');
document.body.removeChild(parent)
clearInterval(time)
time = undefined
//#endif
//#ifndef APP-PLUS || H5
uni.hideLoading();
//#endif
}
// 普通弹窗提示
const showToast = ({title='',duration=1500,icon='none'}) => {
//#ifdef APP-PLUS
plus.nativeUI.toast(title,{
duration : duration
})
//#endif
//#ifndef APP-PLUS
uni.showToast({
title : title,
duration : duration,
icon : icon
});
//#endif
}
return {
showLoading,
hideLoading,
showToast
}
}
export {
popUp
}