App.vue 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <el-config-provider :locale="zhCn">
  3. <app-page v-if="isReady" />
  4. <router-view v-else />
  5. </el-config-provider>
  6. </template>
  7. <!--<script lang="ts">
  8. export default {
  9. name: 'App',
  10. }
  11. </script>-->
  12. <script lang="ts" setup>
  13. import { ref, watch } from 'vue'
  14. import { useRouter, useRoute } from 'vue-router'
  15. import { ElMessageBox } from 'element-plus'
  16. import { logout } from '@/business/common'
  17. import { sessionData } from '@/stores'
  18. import zhCn from 'element-plus/lib/locale/lang/zh-cn'
  19. import eventBus from '@/services/bus'
  20. const route = useRoute()
  21. const router = useRouter()
  22. const isReady = ref(false)
  23. // 接收用户登出通知
  24. eventBus.$on('LogoutNotify', (msg) => {
  25. logout(() => {
  26. if (msg) {
  27. ElMessageBox.alert(msg as string)
  28. }
  29. router.replace({ name: 'login' })
  30. })
  31. })
  32. watch(() => route.name, (routeName) => {
  33. const token = sessionData.getLoginInfo('Token')
  34. if (routeName !== 'boot' && token) {
  35. isReady.value = true
  36. } else {
  37. isReady.value = false
  38. }
  39. })
  40. </script>