AppHeader.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <header class="app-header">
  3. <h1 class="app-header-title">前期研究前置报告计划管理系统</h1>
  4. <div class="app-header-right">
  5. <div class="app-header-datetime">
  6. <div class="app-header-time">{{ currentTime }}</div>
  7. <div class="app-header-date">{{ currentDate }}</div>
  8. </div>
  9. <div class="app-header-divider"></div>
  10. <div class="app-header-user">
  11. <span class="app-header-avatar">苏</span>
  12. <span class="app-header-username">苏小苏</span>
  13. </div>
  14. <button type="button" class="app-header-logout" @click="handleLogout">
  15. 退出
  16. </button>
  17. </div>
  18. </header>
  19. </template>
  20. <script setup>
  21. import { onBeforeUnmount, onMounted, ref } from "vue";
  22. import { useRouter } from "vue-router";
  23. import { ElMessage } from "element-plus";
  24. import { loginout } from "@/api/login";
  25. import globalStore from "@/store/modules/global";
  26. defineOptions({
  27. name: "AppHeader",
  28. });
  29. const router = useRouter();
  30. const global = globalStore();
  31. const currentTime = ref("");
  32. const currentDate = ref("");
  33. let timer = null;
  34. const WEEKDAYS = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
  35. const padZero = (num) => String(num).padStart(2, "0");
  36. const updateDateTime = () => {
  37. const now = new Date();
  38. currentTime.value = `${padZero(now.getHours())}:${padZero(now.getMinutes())}:${padZero(now.getSeconds())}`;
  39. currentDate.value = `${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日 ${WEEKDAYS[now.getDay()]}`;
  40. };
  41. const handleLogout = async () => {
  42. try {
  43. await loginout();
  44. } catch (error) {
  45. console.error(error);
  46. } finally {
  47. global.logout();
  48. ElMessage.success("已退出登录");
  49. router.replace({ name: "login" });
  50. }
  51. };
  52. onMounted(() => {
  53. updateDateTime();
  54. timer = window.setInterval(updateDateTime, 1000);
  55. });
  56. onBeforeUnmount(() => {
  57. if (timer) {
  58. clearInterval(timer);
  59. timer = null;
  60. }
  61. });
  62. </script>
  63. <style scoped lang="scss">
  64. .app-header {
  65. box-sizing: border-box;
  66. flex-shrink: 0;
  67. display: flex;
  68. align-items: center;
  69. justify-content: space-between;
  70. padding: 17px 40px;
  71. background: linear-gradient(135deg, #238be5 60%);
  72. box-shadow: 0px 4px 12px 0px rgba(34, 125, 205, 0.1);
  73. border-radius: 0;
  74. }
  75. .app-header-title {
  76. margin: 0;
  77. font-family: PingFang SC, PingFang SC;
  78. font-weight: 600;
  79. font-size: 28px;
  80. color: #ffffff;
  81. line-height: 39px;
  82. letter-spacing: 2px;
  83. text-align: left;
  84. }
  85. .app-header-right {
  86. display: flex;
  87. align-items: center;
  88. flex-shrink: 0;
  89. gap: 40px;
  90. }
  91. .app-header-datetime {
  92. display: flex;
  93. flex-direction: column;
  94. }
  95. .app-header-time {
  96. font-family: PingFang SC, PingFang SC;
  97. font-weight: 500;
  98. font-size: 15px;
  99. color: #ffffff;
  100. line-height: 21px;
  101. text-align: right;
  102. }
  103. .app-header-date {
  104. font-family: PingFang SC, PingFang SC;
  105. font-weight: 400;
  106. font-size: 14px;
  107. color: rgba(255, 255, 255, 0.8);
  108. line-height: 20px;
  109. text-align: right;
  110. font-style: normal;
  111. }
  112. .app-header-divider {
  113. width: 1px;
  114. height: 32px;
  115. background: rgba(255, 255, 255, 0.6);
  116. }
  117. .app-header-user {
  118. display: flex;
  119. align-items: center;
  120. gap: 8px;
  121. }
  122. .app-header-avatar {
  123. box-sizing: border-box;
  124. display: inline-flex;
  125. align-items: center;
  126. justify-content: center;
  127. width: 36px;
  128. height: 36px;
  129. background: #e6f8ff;
  130. border-radius: 18px;
  131. font-family: PingFang SC, PingFang SC;
  132. font-weight: 600;
  133. font-size: 16px;
  134. line-height: 22px;
  135. text-align: center;
  136. font-style: normal;
  137. text-transform: none;
  138. color: #238be5;
  139. }
  140. .app-header-username {
  141. font-family: PingFang SC, PingFang SC;
  142. font-weight: 500;
  143. font-size: 15px;
  144. color: rgba(255, 255, 255, 0.9);
  145. line-height: 21px;
  146. text-align: left;
  147. font-style: normal;
  148. }
  149. .app-header-logout {
  150. margin: 0;
  151. padding: 6px 16px;
  152. border-radius: 2px;
  153. border: 1px solid #ffffff;
  154. background: transparent;
  155. font-family: PingFang SC, PingFang SC;
  156. font-weight: 400;
  157. font-size: 14px;
  158. color: #ffffff;
  159. line-height: 20px;
  160. text-align: left;
  161. cursor: pointer;
  162. }
  163. </style>