HeaderCom.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="header">
  3. <div class="header-logo">
  4. <img src="@/assets/logo.png" slot="reference" />
  5. <h2 class="conversion">中能智能</h2>
  6. </div>
  7. <div class="personalCenter">
  8. <p class="current-time">{{ currentDate }}</p>
  9. <el-popover
  10. placement="bottom"
  11. width="220"
  12. trigger="click"
  13. style="cursor: pointer"
  14. >
  15. <img src="@/assets/portrait.png" slot="reference" />
  16. <div>
  17. <div class="cursor-pointer boxmini">
  18. <p>账号:admin</p>
  19. </div>
  20. <el-divider></el-divider>
  21. <div class="cursor-pointer boxmini">
  22. <p>岗位:超级管理员</p>
  23. </div>
  24. <el-divider></el-divider>
  25. <div class="cursor-pointer boxmini">
  26. <p>角色:超级管理员</p>
  27. </div>
  28. <el-divider></el-divider>
  29. <div class="cursor-pointer boxmini">
  30. <p>主题切换:</p>
  31. <el-select
  32. v-model="currentTheme"
  33. placeholder="Select theme"
  34. @change="changeTheme"
  35. size="mini"
  36. >
  37. <el-option
  38. v-for="item in colorData"
  39. :label="item.lable"
  40. :value="item.value"
  41. >
  42. <span style="float: left">{{ item.lable }}</span>
  43. <el-color-picker
  44. v-model="item.color"
  45. size="mini"
  46. style="float: right"
  47. >
  48. </el-color-picker>
  49. </el-option>
  50. </el-select>
  51. </div>
  52. <el-divider></el-divider>
  53. <div class="cursor-pointer boxmini" @click="skip(1)">
  54. <p class="logout">退出登录</p>
  55. </div>
  56. </div>
  57. </el-popover>
  58. </div>
  59. </div>
  60. </template>
  61. <script>
  62. import { userLogout } from "@/api/system";
  63. export default {
  64. data() {
  65. return {
  66. currentDate: "",
  67. currentTheme: this.$store.state.themes.theme,
  68. colorData: [
  69. { lable: "Light", value: "light", color: "#f90" },
  70. { lable: "Dark", value: "dark", color: "#1f2d3d" },
  71. { lable: "Green", value: "green", color: "#008080" },
  72. { lable: "Blue", value: "blue", color: "#409eff" },
  73. ],
  74. };
  75. },
  76. components: {},
  77. watch: {
  78. "$store.state.themes.theme": {
  79. handler(newTheme) {
  80. console.log(newTheme, "newTheme");
  81. this.currentTheme = newTheme;
  82. },
  83. immediate: true,
  84. },
  85. },
  86. mounted() {
  87. this.updateCurrentDateTime();
  88. setInterval(this.updateCurrentDateTime, 1000);
  89. },
  90. methods: {
  91. changeTheme(theme) {
  92. this.$store.dispatch("switchTheme", theme);
  93. },
  94. updateCurrentDateTime() {
  95. const now = new Date();
  96. const year = now.getFullYear();
  97. const month = (now.getMonth() + 1).toString().padStart(2, "0");
  98. const day = now.getDate().toString().padStart(2, "0");
  99. const hours = now.getHours().toString().padStart(2, "0");
  100. const minutes = now.getMinutes().toString().padStart(2, "0");
  101. const seconds = now.getSeconds().toString().padStart(2, "0");
  102. // 设置当前时间数据
  103. this.currentDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  104. },
  105. skip() {
  106. this.$emit("setLoding", true);
  107. userLogout({
  108. phone: this.$store.state.auth.userInfo.userInfo.userPhone,
  109. })
  110. .then((res) => {
  111. this.$store.commit("auth/RESET_USER_STATE");
  112. this.$router.push("/login");
  113. })
  114. .catch(() => {
  115. this.$emit("setLoding", false);
  116. });
  117. },
  118. },
  119. };
  120. </script>
  121. <style lang="scss" scoped>
  122. .header {
  123. display: flex;
  124. justify-content: space-between;
  125. align-items: center;
  126. height: 60px;
  127. background: #fff;
  128. padding: 0 20px;
  129. .header-logo {
  130. display: flex;
  131. justify-content: space-between;
  132. align-items: center;
  133. h2 {
  134. padding-left: 10px;
  135. font-weight: 600;
  136. }
  137. img {
  138. width: 40px;
  139. height: 40px;
  140. }
  141. }
  142. .el-breadcrumb {
  143. font-size: 16px;
  144. font-weight: 600;
  145. color: rgb(143, 143, 143);
  146. flex: 1;
  147. }
  148. .personalCenter {
  149. display: flex;
  150. align-items: center;
  151. .current-time {
  152. font-size: 12px;
  153. padding-right: 10px;
  154. }
  155. .remind {
  156. cursor: pointer;
  157. margin-right: 24px;
  158. }
  159. }
  160. }
  161. .boxmini {
  162. display: flex;
  163. p {
  164. font-size: 14px;
  165. font-weight: 600;
  166. width: 120px !important;
  167. }
  168. .logout {
  169. color: #ff0000;
  170. text-align: center;
  171. width: 100%;
  172. }
  173. }
  174. .el-divider--horizontal {
  175. margin: 5px 0;
  176. }
  177. </style>