MenuView.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <script setup lang="ts">
  2. import { useRoute, useRouter } from 'vue-router'
  3. import { useUserStore } from '@/stores/modules/user'
  4. import { CaretRight } from '@element-plus/icons-vue'
  5. const route = useRoute()
  6. const router = useRouter()
  7. const userStore = useUserStore()
  8. const isCollapse = defineModel<boolean>()
  9. const menuList = ref()
  10. watch(
  11. () => userStore.username,
  12. () => {
  13. getMenuList()
  14. }
  15. )
  16. const getMenuList = () => {
  17. $api.getMenuList().then((res) => {
  18. if (res.code === 200) {
  19. menuList.value = res.data
  20. }
  21. })
  22. }
  23. getMenuList()
  24. //监听窗口大小
  25. const handler = () => {
  26. return (() => {
  27. let screenWidth = document.body.clientWidth
  28. if (screenWidth < 1400) {
  29. isCollapse.value = true
  30. } else {
  31. isCollapse.value = false
  32. }
  33. })()
  34. }
  35. handler()
  36. const activeMenu = ref()
  37. activeMenu.value = (route.meta?.activeMenu as string) || route.path
  38. // 未登录白名单
  39. const whiteList = ['/login', '/public-tracking', '/public-tracking/detail', '/reset-password']
  40. // 判断是否允许跳转
  41. const isAllowJump = (path: any) => {
  42. // 判断是否登录
  43. if (!whiteList.includes(path) && !localStorage.getItem('username')) {
  44. ElMessage.warning({
  45. message: 'Please log in to use this feature.',
  46. grouping: true
  47. })
  48. if (route.name !== 'Public Tracking') {
  49. router.push({
  50. name: 'Login'
  51. })
  52. }
  53. activeMenu.value = route.path // 保持选中状态不变
  54. return false
  55. }
  56. return true
  57. }
  58. // 路由后置守卫
  59. router.afterEach(() => {
  60. activeMenu.value = (route.meta?.activeMenu as string) || route.path
  61. })
  62. const isVisible = ref(false)
  63. const emits = defineEmits(['changeVisible'])
  64. // 路由跳转函数
  65. const changeRouter = (path: any) => {
  66. if (sessionStorage.getItem('searchTableQeury')) {
  67. sessionStorage.removeItem('searchTableQeury')
  68. }
  69. if (sessionStorage.getItem('searchTableQeuryTracking')) {
  70. sessionStorage.removeItem('searchTableQeuryTracking')
  71. }
  72. if (sessionStorage.getItem('clickParams')) {
  73. sessionStorage.removeItem('clickParams')
  74. sessionStorage.removeItem('reportList')
  75. sessionStorage.removeItem('tagsList')
  76. }
  77. sessionStorage.removeItem('trackingTablePageInfo')
  78. sessionStorage.removeItem('bookingTablePageInfo')
  79. isVisible.value = false
  80. emits('changeVisible', isVisible.value)
  81. isVisible.value = false
  82. let toPath = path
  83. if (path === '/tracking' && !localStorage.getItem('username')) {
  84. toPath = '/public-tracking'
  85. }
  86. // 如果允许跳转,执行跳转
  87. if (isAllowJump(toPath)) {
  88. router.push(toPath)
  89. } else {
  90. // 如果不允许跳转,保持当前 activeMenu 不变
  91. nextTick(() => {
  92. activeMenu.value = (route.meta?.activeMenu as string) || route.path // 确保菜单栏选中状态为当前路径
  93. })
  94. }
  95. }
  96. const handleCollapseClick = () => {
  97. isCollapse.value = !isCollapse.value
  98. }
  99. const menuRef = ref()
  100. // 友情链接
  101. const activeName = ref('1')
  102. // const blogrollList = ref([
  103. // {
  104. // icon: () => import('./images/flag.png'),
  105. // title: 'Kerry Siam Seaport Web Service',
  106. // link: 'https://www.kerrysiamseaport.com/'
  107. // }
  108. // ])
  109. const jumpLink = (link: string) => {
  110. window.open(link, '_blank')
  111. }
  112. </script>
  113. <template>
  114. <div class="left-section">
  115. <el-menu
  116. ref="menuRef"
  117. class="layout-menu"
  118. @select="changeRouter"
  119. :default-active="activeMenu"
  120. :collapse="isCollapse"
  121. >
  122. <template v-for="item in menuList" :key="item.index">
  123. <el-menu-item
  124. :class="{
  125. 'clear-active-style': route.path === '/login' || route.path === '/reset-password'
  126. }"
  127. v-if="item.type !== 'list'"
  128. :index="item.path"
  129. >
  130. <span class="font_family" :class="[`icon-${item.icon}`]"></span>
  131. <template #title>{{ item.label }}</template>
  132. </el-menu-item>
  133. <el-sub-menu v-else :index="item.path">
  134. <template #title>
  135. <div class="font_family" style="font-size: 16px" :class="[`icon-${item.icon}`]"></div>
  136. <span>{{ item.label }}</span>
  137. </template>
  138. <template v-for="childrenItem in item.children" :key="childrenItem.index">
  139. <el-menu-item :index="childrenItem.path">{{ childrenItem.label }}</el-menu-item>
  140. </template>
  141. </el-sub-menu>
  142. </template>
  143. </el-menu>
  144. <div class="blogroll" :class="{ collapse: isCollapse }">
  145. <el-collapse v-model="activeName" accordion>
  146. <el-collapse-item title="REGIONAL SOLUTIONS" name="1" :icon="CaretRight">
  147. <div class="blogroll-content">
  148. <div class="blogroll-item" @click="jumpLink('https://www.ksp.kln.com/')">
  149. <img
  150. style="height: 16px; width: 16px; margin-right: 4px"
  151. src="./images/flag.png"
  152. alt="string"
  153. />
  154. <span class="title">KLN Siam Seaport Web Service</span>
  155. </div>
  156. </div>
  157. </el-collapse-item>
  158. </el-collapse>
  159. </div>
  160. <div class="collapse-icon">
  161. <div @click="handleCollapseClick">
  162. <span
  163. :style="{ transform: isCollapse ? 'rotate(0deg)' : 'rotate(180deg)' }"
  164. class="font_family icon-icon_menu_collapse_b"
  165. ></span>
  166. </div>
  167. </div>
  168. </div>
  169. </template>
  170. <style lang="scss" scoped>
  171. .left-section {
  172. display: flex;
  173. flex-direction: column;
  174. height: calc(100% - 64px);
  175. }
  176. .layout-menu {
  177. flex: 1;
  178. border-bottom: 1px solid var(--color-border);
  179. border-right: none;
  180. .font_family {
  181. margin-left: 4px;
  182. margin-right: 8px;
  183. }
  184. }
  185. .collapse-icon {
  186. display: flex;
  187. justify-content: flex-end;
  188. align-items: center;
  189. height: 56px;
  190. padding-right: 10px;
  191. div {
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. width: 42px;
  196. height: 100%;
  197. cursor: pointer;
  198. }
  199. }
  200. .el-menu-item.is-active {
  201. background-color: var(--color-mune-active-bg);
  202. color: var(--color-theme);
  203. font-weight: 700;
  204. & > span {
  205. color: var(--color-theme);
  206. }
  207. }
  208. .el-menu-item {
  209. height: 40px;
  210. margin: 0 12px 2px;
  211. padding-left: 8px !important;
  212. border-radius: 6px;
  213. color: var(--color-neutral-1);
  214. &:hover {
  215. background-color: var(--color-mune-active-bg);
  216. }
  217. :deep(.el-menu-tooltip__trigger) {
  218. padding-left: 8px;
  219. }
  220. }
  221. li.clear-active-style {
  222. background-color: transparent !important;
  223. color: var(--color-neutral-1) !important;
  224. font-weight: normal !important;
  225. & > span {
  226. color: var(--color-neutral-1) !important;
  227. }
  228. }
  229. :deep(.el-sub-menu__title) {
  230. height: 40px;
  231. margin: 0 12px;
  232. padding-left: 8px !important;
  233. line-height: 40px;
  234. &:hover {
  235. background-color: var(--color-mune-active-bg);
  236. }
  237. }
  238. .el-sub-menu {
  239. margin-bottom: 2px;
  240. .el-menu-item {
  241. padding-left: 36px !important;
  242. }
  243. }
  244. .blogroll {
  245. position: relative;
  246. &.collapse {
  247. display: none;
  248. }
  249. :deep(.el-collapse) {
  250. border-top: none;
  251. .el-collapse-item__arrow {
  252. color: #b5b9bf;
  253. align-self: center;
  254. }
  255. }
  256. :deep(.el-collapse-item__header) {
  257. align-items: normal;
  258. position: sticky;
  259. top: 1px;
  260. height: 40px;
  261. line-height: 42px;
  262. padding: 0 12px;
  263. overflow: hidden;
  264. white-space: nowrap;
  265. font-weight: 700;
  266. }
  267. }
  268. .blogroll-content {
  269. max-height: 180px;
  270. padding: 0 8px;
  271. overflow: auto;
  272. .blogroll-item {
  273. height: 40px;
  274. margin-top: 4px;
  275. padding: 0 8px;
  276. line-height: 40px;
  277. font-size: 12px;
  278. cursor: pointer;
  279. overflow: hidden;
  280. white-space: nowrap;
  281. transition: all 0.3s;
  282. .font_family {
  283. margin-right: 4px;
  284. }
  285. span {
  286. vertical-align: middle;
  287. }
  288. &:hover {
  289. background-color: var(--color-mune-active-bg);
  290. border-radius: 6px;
  291. cursor: pointer;
  292. }
  293. }
  294. }
  295. </style>