header.vue 4.1 KB

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