85 lines
1.5 KiB
Vue
85 lines
1.5 KiB
Vue
<!-- components/GlobalLoading.vue -->
|
|
<template>
|
|
<view v-if="visible" class="global-loading">
|
|
<view class="loading-mask"></view>
|
|
<view class="loading-content">
|
|
<view class="loading-spinner"></view>
|
|
<text class="loading-text">{{ text }}</text>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref } from 'vue'
|
|
|
|
const visible = ref(false)
|
|
const text = ref('加载中...')
|
|
|
|
// 显示
|
|
function show(loadingText = '加载中...') {
|
|
visible.value = true
|
|
text.value = loadingText
|
|
}
|
|
|
|
// 隐藏
|
|
function hide() {
|
|
visible.value = false
|
|
}
|
|
|
|
// 挂载到全局
|
|
if (typeof uni !== 'undefined') {
|
|
uni.$globalLoading = { show, hide }
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.global-loading {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
z-index: 9999;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.loading-mask {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background-color: rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
.loading-content {
|
|
position: relative;
|
|
background-color: rgba(0, 0, 0, 0.7);
|
|
border-radius: 16rpx;
|
|
padding: 32rpx 48rpx;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
gap: 20rpx;
|
|
}
|
|
|
|
.loading-spinner {
|
|
width: 48rpx;
|
|
height: 48rpx;
|
|
border: 4rpx solid rgba(255, 255, 255, 0.3);
|
|
border-top-color: #fff;
|
|
border-radius: 50%;
|
|
animation: spin 0.8s linear infinite;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
|
|
.loading-text {
|
|
color: #fff;
|
|
font-size: 24rpx;
|
|
}
|
|
</style> |