index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <router-view class="bg-white" />
  3. </template>
  4. <script lang="ts" setup>
  5. import { defineComponent, provide } from 'vue'
  6. import { useRoute, useRouter } from 'vue-router'
  7. import Cookie from 'js-cookie'
  8. defineComponent({
  9. name: 'IndentManageIndex',
  10. })
  11. provide('mediaRegExp', /^(https?:)?\/\/.+(.com.au\/|.com\/)/)
  12. const $route = useRoute()
  13. const token = Cookie.get('indent-token')
  14. const originQuery = $route.query as {
  15. [key: string]: string
  16. }
  17. if (originQuery.id) {
  18. Cookie.set('indent-crm-id', originQuery.id || '')
  19. }
  20. if (originQuery.full_name) {
  21. Cookie.set('indent-crm-fullname', originQuery.full_name || '')
  22. }
  23. const $router = useRouter()
  24. // 访问非登录页, 未登录状态调整登录页
  25. if (!token && $route.path !== '/indent-manage/login') {
  26. const params: any = {
  27. origin: encodeURIComponent($route.path),
  28. }
  29. if (originQuery.u?.length && originQuery.p?.length) {
  30. params.action = 'autoLogin'
  31. params.p = originQuery.p.trim()
  32. params.u = originQuery.u.trim()
  33. }
  34. console.log('未登录重定向')
  35. $router.replace({
  36. path: '/indent-manage/login',
  37. query: params,
  38. })
  39. } else if (originQuery.u) {
  40. console.log('已登录')
  41. $router.replace({ path: $route.path })
  42. }
  43. </script>
  44. <style>
  45. .bg-white {
  46. background-color: #fefefe;
  47. }
  48. </style>