33 lines
514 B
JavaScript
33 lines
514 B
JavaScript
// /hooks/useLoading.js
|
|
|
|
const loadingMap = new Set()
|
|
|
|
export function useLoading() {
|
|
|
|
const openLoading = (key = 'default', loadingObj) => {
|
|
loadingMap.add(key)
|
|
|
|
uni.showLoading({
|
|
...loadingObj
|
|
})
|
|
}
|
|
|
|
const closeLoading = (key = 'default') => {
|
|
loadingMap.delete(key)
|
|
|
|
if (loadingMap.size === 0) {
|
|
uni.hideLoading()
|
|
}
|
|
}
|
|
|
|
const clearLoading = () => {
|
|
loadingMap.clear()
|
|
uni.hideLoading()
|
|
}
|
|
|
|
return {
|
|
openLoading,
|
|
closeLoading,
|
|
clearLoading
|
|
}
|
|
} |