index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div :class="{ 'pt-[48px]': currentPath !== '' }">
  3. <div
  4. v-if="currentPath !== ''"
  5. class="fixed z-50 top-0 left-0 shadow-sm w-[100vw]"
  6. >
  7. <div class="max-w-[1800px] mx-auto h-[48px] flex bg-sky-600">
  8. <div class="leading-[48px] px-8 font-black text-white">Indent APP</div>
  9. <div class="flex">
  10. <div
  11. v-for="item in navList"
  12. :key="item.key"
  13. @click="$router.push(item.path)"
  14. class="cursor-pointer h-[100%] w-[100px] leading-[48px] px-4 no-underline text-white hover:font-bold flex justify-center"
  15. :class="{
  16. 'font-bold': currentPath === item.key,
  17. 'bg-sky-900': currentPath === item.key,
  18. }"
  19. >
  20. {{ item.key }}
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. <router-view class="bg-white" />
  26. </div>
  27. </template>
  28. <script lang="ts" setup>
  29. import { defineComponent, provide, computed } from 'vue'
  30. import { useRoute, useRouter } from 'vue-router'
  31. import Cookie from 'js-cookie'
  32. defineComponent({
  33. name: 'IndentManageIndex',
  34. })
  35. provide('mediaRegExp', /^(https?:)?\/\/.+(.com.au\/|.com\/)/)
  36. const $route = useRoute()
  37. const token = Cookie.get('indent-token')
  38. const originQuery = $route.query as {
  39. [key: string]: string
  40. }
  41. if (originQuery.id) {
  42. Cookie.set('indent-crm-id', originQuery.id || '')
  43. }
  44. if (originQuery.full_name) {
  45. Cookie.set('indent-crm-fullname', originQuery.full_name || '')
  46. }
  47. const $router = useRouter()
  48. // 访问非登录页, 未登录状态调整登录页
  49. if (!token && $route.path !== '/indent-manage/login') {
  50. const params: any = {
  51. origin: encodeURIComponent($route.path),
  52. }
  53. if (originQuery.u?.length && originQuery.p?.length) {
  54. params.action = 'autoLogin'
  55. params.p = originQuery.p.trim()
  56. params.u = originQuery.u.trim()
  57. }
  58. console.log('未登录重定向')
  59. $router.replace({
  60. path: '/indent-manage/login',
  61. query: params,
  62. })
  63. } else if (originQuery.u) {
  64. console.log('已登录')
  65. $router.replace({ path: $route.path })
  66. }
  67. const navList = [
  68. {
  69. key: 'indent',
  70. path: '/indent-manage/indent/list',
  71. },
  72. {
  73. key: 'product',
  74. path: '/indent-manage/product/list',
  75. },
  76. {
  77. key: 'supplier',
  78. path: '/indent-manage/supplier/list',
  79. },
  80. {
  81. key: 'user',
  82. path: '/indent-manage/user',
  83. },
  84. ]
  85. let currentPath = computed(() => {
  86. let result = ''
  87. if (/indent-manage\/indent/.test($route.path)) {
  88. result = 'indent'
  89. } else if (/indent-manage\/product/.test($route.path)) {
  90. result = 'product'
  91. } else if (/indent-manage\/user/.test($route.path)) {
  92. result = 'user'
  93. } else if (/indent-manage\/supplier/.test($route.path)) {
  94. result = 'supplier'
  95. }
  96. return result
  97. })
  98. </script>
  99. <style>
  100. .bg-white {
  101. background-color: #fefefe;
  102. }
  103. </style>