HeaderView.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <script setup lang="ts">
  2. import DownloadKLNPortal from './components/DownloadKLNPortal.vue'
  3. import ChangePasswordDialog from './components/ChangePasswordDialog.vue'
  4. import LogoutDialog from './components/LogoutDialog.vue'
  5. import { useRouter, useRoute } from 'vue-router'
  6. import { useUserStore } from '@/stores/modules/user'
  7. import { useHeaderSearch } from '@/stores/modules/headerSearch'
  8. import { onBeforeRouteUpdate } from 'vue-router'
  9. import { useLoadingState } from '@/stores/modules/loadingState'
  10. import { useThemeStore } from '@/stores/modules/theme'
  11. const themeStore = useThemeStore()
  12. const userStore = useUserStore()
  13. const route = useRoute()
  14. const router = useRouter()
  15. const headerSearch = useHeaderSearch()
  16. const themePopoverRef = ref()
  17. // 切换系统主题颜色
  18. const toggleThemeMode = (theme: string) => {
  19. themeStore.toggleTheme(theme, true)
  20. }
  21. const searchValue = ref('')
  22. // 用于判断是否在搜索后跳转页面,跳转后清空搜索框的值
  23. const isJumpPageBySearch = ref(false)
  24. const handleSearch = () => {
  25. if (!searchValue.value) {
  26. return
  27. }
  28. // 先判断是否登录
  29. // 未登录
  30. if (!localStorage.getItem('username')) {
  31. $api.getPublicTrackingDetail({ reference_number: searchValue.value }).then((res) => {
  32. if (res.code === 200) {
  33. const { data } = res
  34. if (route.path === '/public-tracking') {
  35. isJumpPageBySearch.value = false
  36. } else {
  37. isJumpPageBySearch.value = true
  38. }
  39. if (data.msg === 'No matches') {
  40. headerSearch.setSearchData({
  41. searchValue: searchValue.value,
  42. searchResult: 'error'
  43. })
  44. router.push({
  45. name: 'Public Tracking'
  46. })
  47. } else if (data.msg === 'Multiple results') {
  48. headerSearch.setSearchData({
  49. searchValue: searchValue.value,
  50. searchResult: 'multiple'
  51. })
  52. router.push({
  53. name: 'Public Tracking'
  54. })
  55. } else {
  56. sessionStorage.setItem('publicTrackingData', JSON.stringify(data.data))
  57. router.push(`/public-tracking/detail?searchNo=${searchValue.value}`)
  58. }
  59. }
  60. })
  61. } else {
  62. const trackingTableLoadingState = useLoadingState()
  63. trackingTableLoadingState.setTrackingTableLoading(true)
  64. // 已登录
  65. $api
  66. .getTrackingTableData({
  67. _textSearch: searchValue.value
  68. })
  69. .then((res) => {
  70. if (res.code === 200) {
  71. // 如果是在tracking页面搜索,那么isJumpPageBySearch不用置为true,跳转路由后直接清空搜索框
  72. if (route.path === '/tracking') {
  73. isJumpPageBySearch.value = false
  74. } else {
  75. isJumpPageBySearch.value = true
  76. }
  77. headerSearch.setSearchData({
  78. searchValue: searchValue.value,
  79. searchResult: '',
  80. trackingData: res.data
  81. })
  82. router.push({
  83. name: 'Tracking'
  84. })
  85. }
  86. })
  87. .finally(() => {
  88. trackingTableLoadingState.setTrackingTableLoading(false)
  89. })
  90. }
  91. }
  92. onBeforeRouteUpdate((to, from, next) => {
  93. if (isJumpPageBySearch.value) {
  94. isJumpPageBySearch.value = false
  95. } else {
  96. searchValue.value = ''
  97. }
  98. next()
  99. })
  100. const downloadKLNPortalRef = ref()
  101. const handleDownload = () => {
  102. downloadKLNPortalRef.value.openDialog()
  103. }
  104. const changePasswordDialogRef = ref()
  105. const handleChangePassword = () => {
  106. changePasswordDialogRef.value.openDialog()
  107. }
  108. const handleUserManual = () => {
  109. try {
  110. $api.getUserGuide().then(async (res) => {
  111. if (res.status !== 200) {
  112. ElMessageBox.alert('The request failed. Please try again later', 'Prompt', {
  113. confirmButtonText: 'OK',
  114. confirmButtonClass: 'el-button--dark'
  115. })
  116. return
  117. }
  118. // 创建一个 Blob 对象
  119. const blob = new Blob([res.data], { type: 'application/pdf' })
  120. const url = URL.createObjectURL(blob)
  121. // 在新标签页中打开 PDF
  122. window.open(url, '_blank')
  123. })
  124. } catch (error) {
  125. ElMessageBox.alert('The request failed. Please try again later', 'Prompt', {
  126. confirmButtonText: 'OK',
  127. confirmButtonClass: 'el-button--dark'
  128. })
  129. }
  130. }
  131. const logoutDialogRef = ref()
  132. const handleLogout = () => {
  133. logoutDialogRef.value.openDialog()
  134. }
  135. const handleLogin = () => {
  136. router.push('/login')
  137. }
  138. </script>
  139. <template>
  140. <div class="layout-toolbar">
  141. <VBreadcrumb></VBreadcrumb>
  142. <div class="right-info">
  143. <el-input
  144. v-model="searchValue"
  145. size="large"
  146. @keyup.enter="handleSearch"
  147. placeholder="Enter Booking/HBL/PO/Container No."
  148. >
  149. <template #prefix>
  150. <span style="margin-top: -1px" class="font_family icon-icon_search_b"></span>
  151. </template>
  152. </el-input>
  153. <!-- <span class="font_family icon-icon_notice_b" style="font-size: 18px"></span>
  154. <span class="font_family icon-icon_language_b" style="font-size: 16px"></span> -->
  155. <el-popover
  156. placement="bottom-end"
  157. :width="400"
  158. trigger="click"
  159. ref="themePopoverRef"
  160. popper-class="toggle-theme-popover"
  161. >
  162. <div>
  163. <div class="header">
  164. <span class="title">Themes</span>
  165. <el-button @click="themePopoverRef.hide()" class="close-icon el-button--text">
  166. <div class="font_family icon-icon_reject_b"></div>
  167. </el-button>
  168. </div>
  169. <div class="tips">
  170. Customize your workspace by changing the appearance and theme color
  171. </div>
  172. <div class="picture-module">
  173. <div class="item" :class="{ active: themeStore.theme === 'light' }">
  174. <img @click="toggleThemeMode('light')" src="./images/light.png" alt="" />
  175. <div v-if="themeStore.theme === 'light'" class="selected-icon">
  176. <span class="font_family icon-icon_confirm_b"></span>
  177. </div>
  178. </div>
  179. <div class="item" :class="{ active: themeStore.theme === 'dark' }">
  180. <img @click="toggleThemeMode('dark')" src="./images/dark.png" alt="" />
  181. <div v-if="themeStore.theme === 'dark'" class="selected-icon">
  182. <span class="font_family icon-icon_confirm_b"></span>
  183. </div>
  184. </div>
  185. </div>
  186. <div class="btn-module">
  187. <div
  188. class="btn-item"
  189. @click="toggleThemeMode('light')"
  190. :class="{ active: themeStore.theme === 'light' }"
  191. >
  192. <span class="font_family icon-icon_light_b"></span>
  193. Light
  194. </div>
  195. <div
  196. class="btn-item"
  197. @click="toggleThemeMode('dark')"
  198. :class="{ active: themeStore.theme === 'dark' }"
  199. >
  200. <span class="font_family icon-icon_dark_b"></span>Dark
  201. </div>
  202. </div>
  203. </div>
  204. <template #reference>
  205. <el-button style="height: 40px; width: 40px" class="el-button--text">
  206. <span class="font_family icon-icon_themes_b" style="font-size: 16px"></span
  207. ></el-button>
  208. <el-tooltip
  209. popper-class="theme-popper-class"
  210. effect="dark"
  211. content="Themes"
  212. placement="top"
  213. :offset="4"
  214. trigger="hover"
  215. >
  216. <el-button style="height: 40px; width: 40px" class="el-button--text">
  217. <span class="font_family icon-icon_themes_b" style="font-size: 16px"></span
  218. ></el-button>
  219. </el-tooltip>
  220. </template>
  221. </el-popover>
  222. <el-popover
  223. placement="bottom-end"
  224. :width="256"
  225. trigger="click"
  226. popper-class="user-config-popover"
  227. >
  228. <div class="title">
  229. <div class="avatar">
  230. <span>{{ userStore.username?.slice(0, 1) }}</span>
  231. </div>
  232. <span class="name">{{ userStore.username }}</span>
  233. </div>
  234. <div class="options">
  235. <div class="item" @click="handleChangePassword">
  236. <span class="font_family icon-icon_password_b"></span>
  237. Change Password
  238. </div>
  239. <div class="item" @click="handleUserManual">
  240. <span class="font_family icon-icon_manual_b"></span>
  241. User Manual
  242. </div>
  243. <div class="item" @click="handleLogout">
  244. <span class="font_family icon-icon_export_b"></span>
  245. Logout
  246. </div>
  247. </div>
  248. <template #reference>
  249. <div class="header-avatar" v-if="userStore.username && userStore.isFirstLogin !== true">
  250. <span style="">{{ userStore.username?.slice(0, 1) }}</span>
  251. </div>
  252. </template>
  253. </el-popover>
  254. <el-button
  255. :class="{ 'el-button--pain-theme': themeStore.theme === 'dark' }"
  256. v-if="!userStore.username || (userStore.username && userStore.isFirstLogin === true)"
  257. class="el-button--main"
  258. style="padding: 8px 10px; margin-right: 10px; margin-left: 0"
  259. plain
  260. @click="handleDownload"
  261. >
  262. <span class="font_family icon-icon_download_b" style="margin-right: 4px"></span>
  263. Download KLN Portal
  264. </el-button>
  265. <el-button
  266. v-if="!userStore.username || (userStore.username && userStore.isFirstLogin === true)"
  267. class="el-button--main"
  268. style="margin-left: -10px"
  269. @click="handleLogin"
  270. >Log in</el-button
  271. >
  272. </div>
  273. <DownloadKLNPortal ref="downloadKLNPortalRef"></DownloadKLNPortal>
  274. <ChangePasswordDialog ref="changePasswordDialogRef"></ChangePasswordDialog>
  275. <LogoutDialog ref="logoutDialogRef"></LogoutDialog>
  276. </div>
  277. </template>
  278. <style lang="scss" scoped>
  279. .header-avatar {
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. width: 24px;
  284. height: 24px;
  285. padding: 2px;
  286. text-align: center;
  287. border-radius: 50%;
  288. background-color: var(--color-theme);
  289. cursor: pointer;
  290. & > span {
  291. display: block;
  292. height: 16px;
  293. color: #fff;
  294. font-size: 16px;
  295. font-weight: 700;
  296. }
  297. }
  298. .layout-toolbar {
  299. display: flex;
  300. justify-content: space-between;
  301. height: 100%;
  302. }
  303. .right-info {
  304. display: flex;
  305. align-items: center;
  306. justify-content: center;
  307. gap: 8px;
  308. height: 100%;
  309. .el-input {
  310. height: 32px;
  311. width: 400px;
  312. :deep(.el-input__wrapper) {
  313. padding-left: 8px;
  314. border-radius: 15px;
  315. color: var(--color-border);
  316. background-color: var(--color-table-header-bg);
  317. .el-input__icon {
  318. font-size: 16px;
  319. font-weight: 600;
  320. color: var(--color-neutral-1);
  321. }
  322. }
  323. :deep(.el-input__inner) {
  324. height: 32px;
  325. }
  326. }
  327. }
  328. </style>
  329. <style lang="scss">
  330. div.el-popover.el-popper.toggle-theme-popover {
  331. width: 400px;
  332. height: 278px;
  333. padding: 16px;
  334. .header {
  335. display: flex;
  336. justify-content: space-between;
  337. align-items: center;
  338. margin-bottom: 8px;
  339. .title {
  340. font-size: 18px;
  341. font-weight: 700;
  342. }
  343. .close-icon {
  344. width: 24px;
  345. cursor: pointer;
  346. }
  347. }
  348. .tips {
  349. color: var(--color-neutral-2);
  350. }
  351. .picture-module {
  352. display: flex;
  353. justify-content: center;
  354. gap: 6px;
  355. margin-top: 16px;
  356. .item {
  357. position: relative;
  358. display: flex;
  359. justify-content: center;
  360. align-items: center;
  361. width: 174px;
  362. height: 108px;
  363. padding: 8px;
  364. img {
  365. width: 154px;
  366. height: 90px;
  367. cursor: pointer;
  368. }
  369. &.active {
  370. border: 2px solid var(--color-theme);
  371. border-radius: 6px;
  372. }
  373. .selected-icon {
  374. position: absolute;
  375. bottom: 8px;
  376. left: 50%;
  377. transform: translateX(-50%);
  378. height: 16px;
  379. span {
  380. height: 16px;
  381. width: 16px;
  382. background-color: var(--color-theme);
  383. color: #fff;
  384. border-radius: 50%;
  385. }
  386. }
  387. }
  388. }
  389. .btn-module {
  390. display: flex;
  391. align-items: center;
  392. justify-content: center;
  393. width: 368px;
  394. height: 40px;
  395. margin-top: 10px;
  396. padding: 0 8px;
  397. background-color: var(--color-toggle-btn-module-bg);
  398. border-radius: 6px;
  399. .btn-item {
  400. display: flex;
  401. align-items: center;
  402. justify-content: center;
  403. gap: 4px;
  404. width: 180px;
  405. height: 32px;
  406. border-radius: 6px;
  407. color: var(--color-neutral-2);
  408. cursor: pointer;
  409. &.active {
  410. background-color: var(--color-toggle-btn-module-active-bg);
  411. color: var(--color-neutral-1);
  412. }
  413. }
  414. }
  415. }
  416. div.el-popover.el-popper.user-config-popover {
  417. padding: 8px;
  418. width: 240px;
  419. border-radius: 12px;
  420. .title {
  421. display: flex;
  422. align-items: center;
  423. gap: 8px;
  424. height: 70px;
  425. border-bottom: 1px solid var(--color-user-config-title-bottom-border);
  426. & > .avatar {
  427. display: flex;
  428. align-items: center;
  429. justify-content: center;
  430. width: 48px;
  431. height: 48px;
  432. padding-top: 7px;
  433. border-radius: 50%;
  434. text-align: center;
  435. background-color: var(--color-theme);
  436. span {
  437. display: block;
  438. color: #fff;
  439. height: 32px;
  440. line-height: 32px;
  441. font-size: 32px;
  442. font-weight: 700;
  443. }
  444. }
  445. }
  446. .options {
  447. .item {
  448. display: flex;
  449. align-items: center;
  450. padding-left: 8px;
  451. gap: 8px;
  452. height: 40px;
  453. line-height: 40px;
  454. &:hover {
  455. background-color: var(--color-mune-active-bg);
  456. border-radius: 6px;
  457. cursor: pointer;
  458. }
  459. }
  460. }
  461. }
  462. div.el-popper.theme-popper-class {
  463. padding: 3px 4px;
  464. }
  465. </style>