index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <div class="boot">
  3. <el-button :loading="loading" v-if="loading">正在初始化...</el-button>
  4. <el-button @click="initService" v-else>重试</el-button>
  5. </div>
  6. </template>
  7. <script lang="ts" setup>
  8. import { ref } from 'vue'
  9. import { ElMessage } from 'element-plus'
  10. import { useRoute, useRouter } from 'vue-router'
  11. import { initBaseData, checkToken } from '@/business/common'
  12. import { sessionData } from '@/stores'
  13. import service from '@/services'
  14. import eventBus from '@/services/bus'
  15. import socket from '@/services/socket'
  16. const route = useRoute()
  17. const router = useRouter()
  18. const loading = ref(false)
  19. const initService = async () => {
  20. loading.value = true
  21. // 等待服务初始化
  22. await service.onReady().catch((err) => {
  23. ElMessage.error(err)
  24. loading.value = false
  25. })
  26. if (sessionData.getLoginInfo('Token')) {
  27. // 等待连接交易服务
  28. await socket.connectTrade().catch((err) => {
  29. ElMessage.error(err)
  30. loading.value = false
  31. })
  32. // 等待令牌效验
  33. await checkToken().catch(() => {
  34. eventBus.$emit('LogoutNotify')
  35. })
  36. // 等待业务数据初始化
  37. await initBaseData().catch((err) => {
  38. ElMessage.error(err)
  39. loading.value = false
  40. })
  41. }
  42. // 路由跳转
  43. const redirect = route.query.redirect
  44. if (redirect) {
  45. router.replace(redirect.toString())
  46. } else {
  47. router.replace('/')
  48. }
  49. }
  50. initService()
  51. </script>
  52. <style lang="less" scoped>
  53. @import './index.less';
  54. </style>