HeaderCom.vue 5.0 KB

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