HeaderCom.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <div class="header">
  3. <div class="header-logo">
  4. <img src="@/assets/datang.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>
  19. 账号:{{
  20. ($store.state.auth &&
  21. $store.state.auth.userInfo &&
  22. $store.state.auth.userInfo.userInfo &&
  23. $store.state.auth.userInfo.userInfo.loginName) ||
  24. ""
  25. }}
  26. </p>
  27. </div>
  28. <el-divider></el-divider>
  29. <div class="cursor-pointer boxmini">
  30. <p>
  31. 角色:{{
  32. ($store.state.auth &&
  33. $store.state.auth.userInfo &&
  34. $store.state.auth.userInfo.role &&
  35. $store.state.auth.userInfo.role.roleDescription) ||
  36. ""
  37. }}
  38. </p>
  39. </div>
  40. <el-divider></el-divider>
  41. <div class="cursor-pointer boxmini">
  42. <p>主题切换:</p>
  43. <el-select
  44. v-model="currentTheme"
  45. placeholder="Select theme"
  46. @change="changeTheme"
  47. size="mini"
  48. >
  49. <el-option
  50. v-for="(item, index) in colorData"
  51. :key="index"
  52. :label="item.lable"
  53. :value="item.value"
  54. >
  55. <span style="float: left">{{ item.lable }}</span>
  56. <el-color-picker
  57. disabled
  58. v-model="item.color"
  59. size="mini"
  60. style="float: right"
  61. >
  62. </el-color-picker>
  63. </el-option>
  64. </el-select>
  65. </div>
  66. <el-divider></el-divider>
  67. <div class="cursor-pointer boxmini">
  68. <p>图表主题:</p>
  69. <el-select
  70. size="mini"
  71. v-model="color1"
  72. @change="updateChartColor"
  73. placeholder="选择配色方案"
  74. style="width: 200px"
  75. >
  76. <el-option
  77. v-for="(scheme, index) in colorSchemes"
  78. :key="index"
  79. :label="scheme.label"
  80. :value="scheme.colors"
  81. >
  82. <!-- :style="getOptionStyle(scheme.colors)" -->
  83. <span
  84. v-for="color in scheme.colors.slice(0, 8)"
  85. :style="{
  86. background: color,
  87. width: '20px',
  88. height: '20px',
  89. display: 'inline-block',
  90. }"
  91. ></span>
  92. </el-option>
  93. </el-select>
  94. </div>
  95. <el-divider></el-divider>
  96. <div class="cursor-pointer boxmini" @click="skip(1)">
  97. <p class="logout">退出登录</p>
  98. </div>
  99. </div>
  100. </el-popover>
  101. </div>
  102. </div>
  103. </template>
  104. <script>
  105. import { userLogout } from "@/api/system";
  106. import { mapActions } from "vuex";
  107. import { colorSchemes } from "@/views/overview/js/colors";
  108. export default {
  109. data() {
  110. return {
  111. color1: [], // 默认颜色
  112. // 配色方案列表(每个方案是一个颜色数组)
  113. colorSchemes: [...colorSchemes],
  114. currentDate: "",
  115. currentTheme: this.$store.state.themes.theme,
  116. colorData: [
  117. { lable: "黄色", value: "light", color: "#82780ccf" },
  118. { lable: "深色", value: "dark", color: "#607d8b" },
  119. { lable: "绿色", value: "green", color: "#008080" },
  120. { lable: "蓝色", value: "blue", color: "#1B3B7F" },
  121. ],
  122. };
  123. },
  124. components: {},
  125. watch: {
  126. "$store.state.themes.theme": {
  127. handler(newTheme) {
  128. this.currentTheme = newTheme;
  129. },
  130. immediate: true,
  131. },
  132. },
  133. mounted() {
  134. this.updateCurrentDateTime();
  135. setInterval(this.updateCurrentDateTime, 1000);
  136. },
  137. methods: {
  138. ...mapActions("themes", ["themeChange", "switchTheme"]),
  139. updateChartColor() {
  140. // console.log("this.color1", this.color1);
  141. this.themeChange(this.color1);
  142. },
  143. // 根据配色方案设置每个选项的样式
  144. getOptionStyle(scheme) {
  145. return {
  146. background: `linear-gradient(to right, ${scheme
  147. .slice(0, 8)
  148. .join(", ")})`,
  149. color: "#fff",
  150. height: "30px",
  151. lineHeight: "30px",
  152. borderRadius: "0px",
  153. };
  154. },
  155. changeTheme(theme) {
  156. this.$store.dispatch("themes/switchTheme", theme);
  157. },
  158. updateCurrentDateTime() {
  159. const now = new Date();
  160. const year = now.getFullYear();
  161. const month = (now.getMonth() + 1).toString().padStart(2, "0");
  162. const day = now.getDate().toString().padStart(2, "0");
  163. const hours = now.getHours().toString().padStart(2, "0");
  164. const minutes = now.getMinutes().toString().padStart(2, "0");
  165. const seconds = now.getSeconds().toString().padStart(2, "0");
  166. // 设置当前时间数据
  167. this.currentDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  168. },
  169. skip() {
  170. this.$emit("setLoding", true);
  171. userLogout({
  172. phone: this.$store.state.auth.userInfo.userInfo.userPhone,
  173. })
  174. .then((res) => {
  175. this.$store.commit("auth/RESET_USER_STATE");
  176. this.$router.push("/login");
  177. })
  178. .catch(() => {
  179. this.$emit("setLoding", false);
  180. });
  181. },
  182. },
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. .header {
  187. display: flex;
  188. justify-content: space-between;
  189. align-items: center;
  190. height: 60px;
  191. padding: 0 20px;
  192. .header-logo {
  193. display: flex;
  194. justify-content: space-between;
  195. align-items: center;
  196. h2 {
  197. padding-left: 10px;
  198. font-weight: 600;
  199. }
  200. img {
  201. width: 30px;
  202. height: 30px;
  203. }
  204. }
  205. .el-breadcrumb {
  206. font-size: 16px;
  207. font-weight: 600;
  208. color: rgb(143, 143, 143);
  209. flex: 1;
  210. }
  211. .personalCenter {
  212. display: flex;
  213. align-items: center;
  214. .current-time {
  215. font-size: 12px;
  216. padding-right: 10px;
  217. }
  218. .remind {
  219. cursor: pointer;
  220. margin-right: 24px;
  221. }
  222. }
  223. }
  224. .boxmini {
  225. display: flex;
  226. p {
  227. font-size: 14px;
  228. font-weight: 600;
  229. width: 120px !important;
  230. }
  231. .logout {
  232. color: #ff0000;
  233. text-align: center;
  234. width: 100%;
  235. }
  236. }
  237. .el-divider--horizontal {
  238. margin: 5px 0;
  239. }
  240. ::v-deep .el-color-picker__mask {
  241. background-color: rgba(255, 255, 255, 0) !important;
  242. }
  243. </style>