<template>
  <view v-if="visible" class="loading-wrap">
    <view class="loading-content">
      <view class="loading-spinner"></view>
      <text v-if="title" class="loading-text">{{ title }}</text>
    </view>
  </view>
</template>

<script setup lang="ts">withDefaults(
  defineProps<{
    visible: boolean
    title?: string
  }>(),
  {
    title: '加载中...'
  }
)
</script>

<style scoped>
.loading-wrap {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  background: rgba(255, 255, 255, 0.6);
}

.loading-content {
  padding: 20px 24px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  margin-top: 10px;
  font-size: 14px;
  color: #fff;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
</style>
