header.vue 5.9 KB

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