header.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div class="commonHeader">
  3. <div style="width: 155px">
  4. <svg-icon v-if="routeMeta.back" icon-class="back" size="48" @click="commonBack" />
  5. <!-- <svg-icon v-else icon-class="LOGO" style="height: 48px; width: 155px" /> -->
  6. </div>
  7. <div v-if="routeMeta.back && routeMeta.title" class="middle-title">
  8. {{ routeMeta.title }}
  9. </div>
  10. <div v-else>
  11. <div class="date">{{ date }}</div>
  12. <div class="time">{{ time }}</div>
  13. </div>
  14. <div>
  15. <el-space>
  16. <div>
  17. <svg-icon @click="messageStatus = !messageStatus" icon-class="lingdang" size="48" class="activeNotice" />
  18. </div>
  19. <div class="task">
  20. <el-progress :percentage="processCount" :show-text="false" :stroke-width="10" />
  21. <div class="process">任务进度: {{ processCount }}%</div>
  22. </div>
  23. <div>
  24. <div class="name">{{ userStore.user.username }}</div>
  25. <div class="work">{{ userStore.user.station }}</div>
  26. </div>
  27. <el-dropdown ref="dropdown1" trigger="contextmenu" @command="handleCommand">
  28. <img v-if="userStore.user.avatar" :alt="userStore.user.avatar" :src="userStore.user.avatar" object-fit="cover"
  29. style="width: 48px; height: 48px; border-radius: 24px" @click="showClick" />
  30. <svg-icon v-else icon-class="head" size="48" @click="showClick" />
  31. <template #dropdown>
  32. <el-dropdown-menu style="width: 150px">
  33. <!-- <el-dropdown-item command="a">Action 1</el-dropdown-item>-->
  34. <el-dropdown-item command="b">退出登录</el-dropdown-item>
  35. <!-- <el-dropdown-item command="c" divided>Action 3</el-dropdown-item>-->
  36. </el-dropdown-menu>
  37. </template>
  38. </el-dropdown>
  39. </el-space>
  40. </div>
  41. <MessageBox v-model="messageStatus" />
  42. </div>
  43. </template>
  44. <script lang="ts" setup>
  45. import dayjs from "dayjs";
  46. import type { DropdownInstance } from "element-plus";
  47. import { logoutApi } from "@/api/auth";
  48. import { useUserStore } from "@/store";
  49. const userStore = useUserStore();
  50. const router = useRouter();
  51. const route = useRoute();
  52. const routeMeta = computed(() => {
  53. return route.meta;
  54. });
  55. const dropdown1 = ref<DropdownInstance>();
  56. const date = dayjs().format("YYYY-MM-DD");
  57. const time = ref(dayjs().format("HH:mm:ss"));
  58. const processCount = ref(50);
  59. const messageStatus = ref(false);
  60. const headUrl = ref("");
  61. let timer: any = -1;
  62. onMounted(() => {
  63. timer = setInterval(() => {
  64. time.value = dayjs().format("HH:mm:ss");
  65. }, 1000);
  66. });
  67. onBeforeUnmount(() => {
  68. if (timer) {
  69. clearInterval(timer);
  70. }
  71. });
  72. const showClick = () => {
  73. if (!dropdown1.value) return;
  74. dropdown1.value.handleOpen();
  75. };
  76. const commonBack = (itemValue) => {
  77. router.back();
  78. };
  79. const handleCommand = (command: string | number | object) => {
  80. if (command === "b") {
  81. logoutApi().then(() => {
  82. localStorage.setItem("token", "");
  83. location.reload();
  84. });
  85. }
  86. };
  87. </script>
  88. <style lang="scss" scoped>
  89. :deep(.el-dropdown-menu__item) {
  90. height: 60px;
  91. display: flex;
  92. align-items: center;
  93. justify-content: center;
  94. font-weight: 500;
  95. font-size: 24px;
  96. color: rgba(0, 0, 0, 0.9);
  97. }
  98. .commonHeader {
  99. height: $navbar-height;
  100. width: 100%;
  101. background-color: #f1f3f5;
  102. display: flex;
  103. justify-content: space-between;
  104. align-items: center;
  105. padding: 16px 24px;
  106. //border: 1px solid red;
  107. .middle-title {
  108. font-weight: 500;
  109. font-size: 38px;
  110. color: rgba(0, 0, 0, 0.9);
  111. line-height: 24px;
  112. text-align: center;
  113. }
  114. .date {
  115. font-weight: 500;
  116. font-size: 14px;
  117. color: rgba(0, 0, 0, 0.6);
  118. line-height: 14px;
  119. text-align: center;
  120. }
  121. .time {
  122. font-weight: 500;
  123. font-size: 20px;
  124. color: rgba(0, 0, 0, 0.9);
  125. line-height: 23px;
  126. }
  127. .head {
  128. width: 48px;
  129. height: 48px;
  130. border-radius: 24px;
  131. }
  132. .name {
  133. font-weight: 500;
  134. font-size: 20px;
  135. color: rgba(0, 0, 0, 0.9);
  136. line-height: 14px;
  137. text-align: right;
  138. }
  139. .work {
  140. font-weight: 500;
  141. font-size: 14px;
  142. color: rgba(0, 0, 0, 0.6);
  143. line-height: 14px;
  144. text-align: right;
  145. margin-top: 5px;
  146. }
  147. .task {
  148. padding-top: 5px;
  149. margin-right: 10px;
  150. }
  151. // .activeNotice {
  152. // animation: swing 0.15s infinite alternate ease-in-out;
  153. // }
  154. // @keyframes swing {
  155. // 0% {
  156. // transform: rotate(-45deg);
  157. // }
  158. // 100% {
  159. // transform: rotate(45deg);
  160. // }
  161. // }
  162. .process {
  163. font-weight: 500;
  164. font-size: 14px;
  165. color: rgba(0, 0, 0, 0.6);
  166. line-height: 14px;
  167. text-align: right;
  168. margin-top: 8px;
  169. }
  170. }
  171. </style>