HeaderCom.vue 4.6 KB

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