<template>
  <view class="container">
    <slot v-if="!loading"></slot>
    <view v-else class="center">
      <!-- loading组件可以自己实现, 不想自己写就找个网站cv一下 -->
      <!-- <loading></loading> -->
      加载中...
    </view>
  </view>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'

defineOptions({
  name: 'Loading',
})

let loading = ref(false)

onMounted(() => {
  loading = getApp().globalData.loading
  uni.$on('pageSwitch', (res) => {
    loading = res
    getApp().globalData.loading = res
  })
})
</script>

<style lang="scss" scoped>
.center {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.6);
}
</style>
