header.vue 5.4 KB

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