commonHeaders.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <div class="proheader" :class="!switchTheme ? 'themeDarks' : 'themeLights'">
  3. <el-container>
  4. <el-header :class="getStyle()">
  5. <div class="logoSty">
  6. <img src="../assets/logoGuo_DB.png" alt="">
  7. </div>
  8. <div class="proMenu">
  9. <div class="proButton">
  10. <div class="buttonItem" v-for="(item,index) in menuData" :key="index"
  11. :class="getColor(item.showBac)" @click="changeRoute(item)">{{item.name}}</div>
  12. </div>
  13. <div class="proSet">
  14. <div class="settingStop">
  15. <el-switch v-model="switchTheme" @change="changSwith">
  16. <template #active-action>
  17. <!-- <span class="custom-active-action">T</span> -->
  18. <img :src="moon_B" alt="" v-if="!switchTheme">
  19. <img :src="sun_W" alt="" v-else>
  20. </template>
  21. <template #inactive-action>
  22. <!-- <span class="custom-inactive-action">F</span> -->
  23. <img :src="moon_B" alt="" v-if="!switchTheme">
  24. <img :src="sun_B" alt="" v-else>
  25. </template>
  26. </el-switch>
  27. <el-tooltip class="box-item" effect="light" content="自动填报工具">
  28. <a href="http://172.16.12.103:9001/script/download">
  29. <img :src="header_wendang" class="Settingitem downItem">
  30. </a>
  31. </el-tooltip>
  32. <el-tooltip class="box-item" effect="light" content="系统设置">
  33. <img :src="header_shezhi" class="Settingitem">
  34. </el-tooltip>
  35. <el-tooltip class="box-item" effect="light" content="退出">
  36. <img :src="header_dianyuan" class="Settingitem rightIm" @click="backLogin">
  37. </el-tooltip>
  38. </div>
  39. </div>
  40. </div>
  41. </el-header>
  42. </el-container>
  43. </div>
  44. </template>
  45. <script>
  46. import httpRequest from '@/utils/request.js'
  47. import header_wendang from '@/assets/images/headerCom/zidongtianbao.png'
  48. import header_shezhi from '@/assets/images/headerCom/shezhi.png'
  49. import header_dianyuan from '@/assets/images/headerCom/guanji.png'
  50. import sun_W from '@/assets/images/headerCom/sun_W.png'
  51. import moon_B from '@/assets/images/headerCom/moon_B.png'
  52. import sun_B from '@/assets/images/headerCom/sun_B.png'
  53. import moon_W from '@/assets/images/headerCom/moon_W.png'
  54. import {
  55. Sunny,
  56. Moon
  57. } from '@element-plus/icons-vue'
  58. import {
  59. apiGetpersonalInformation
  60. } from '@/api/api'
  61. import {
  62. removeToken
  63. } from '@/utils/auth'
  64. export default {
  65. name: 'headerCom',
  66. data() {
  67. return {
  68. SunnyIcon: Sunny,
  69. MoonIcon: Moon,
  70. sun_W: sun_W,
  71. sun_B: sun_B,
  72. moon_B: moon_B,
  73. moon_W: moon_W,
  74. header_wendang: header_wendang,
  75. header_shezhi: header_shezhi,
  76. header_dianyuan: header_dianyuan,
  77. leftIndex: '1',
  78. currentTime: '',
  79. showRole: true,
  80. menuData: [],
  81. rainW: false,
  82. userName: '',
  83. switchTheme: false
  84. }
  85. },
  86. created() {
  87. this.menuData = [{
  88. index: '/home',
  89. icon: 'Menu',
  90. name: '首页',
  91. showBac: true
  92. },
  93. {
  94. index: '/generatingCap/dataFilter/prepare',
  95. icon: 'Histogram',
  96. name: '发电能力分析'
  97. },
  98. {
  99. index: '/intelligentReport/gkjlb?name=xinzhuang',
  100. icon: 'PictureFilled',
  101. name: '智能报表'
  102. },
  103. {
  104. index: '/powerPrediction/index',
  105. icon: 'TrendCharts',
  106. name: '功率预测'
  107. },
  108. ]
  109. },
  110. mounted() {
  111. let that = this;
  112. if (!JSON.parse(window.sessionStorage.getItem('theme'))) {
  113. // window.sessionStorage.setItem('theme', false)
  114. window.sessionStorage.setItem('theme', true) // 默认白色版本
  115. } else {
  116. this.switchTheme = JSON.parse(window.sessionStorage.getItem('theme'))
  117. this.$store.state.theme = this.switchTheme
  118. this.$emit('swichFn', this.switchTheme)
  119. }
  120. let userMes = JSON.parse(window.sessionStorage.getItem('userMessage'))
  121. that.userName = userMes ? userMes.role : 'administrator'
  122. if (this.$route.query.markKey) {
  123. that.userName = that.$route.query.userid
  124. }
  125. if (userMes && userMes.role === 'ordinaryUser') {
  126. that.showRole = false
  127. }
  128. that.showHeader(that.$route)
  129. },
  130. watch: {
  131. $route: {
  132. handler: function (route) {
  133. console.log('route', route)
  134. this.showHeader(route)
  135. },
  136. immediate: true
  137. }
  138. },
  139. methods: {
  140. changSwith(val) {
  141. this.$emit('swichFn', val)
  142. window.sessionStorage.setItem('theme', JSON.stringify(this.switchTheme))
  143. this.$store.state.theme = this.switchTheme
  144. },
  145. showHeader(route) {
  146. this.menuData.forEach(it => {
  147. if (route.path.indexOf('powerPrediction') > -1) {
  148. if (it.name === '功率预测') {
  149. it.showBac = true
  150. } else {
  151. it.showBac = false
  152. }
  153. } else if (route.path.indexOf('intelligentReport') > -1) {
  154. if (it.name === '智能报表') {
  155. it.showBac = true
  156. } else {
  157. it.showBac = false
  158. }
  159. } else if (route.path.indexOf('generatingCap') > -1) {
  160. if (it.name === '发电能力分析') {
  161. it.showBac = true
  162. } else {
  163. it.showBac = false
  164. }
  165. } else if (route.path === '/home') {
  166. if (it.name === '首页') {
  167. it.showBac = true
  168. } else {
  169. it.showBac = false
  170. }
  171. } else {
  172. it.showBac = false
  173. }
  174. })
  175. },
  176. changeRoute(item) {
  177. window.sessionStorage.setItem('headerRoute', item.index)
  178. this.$router.push({
  179. path: item.index
  180. })
  181. this.$emit('headerName', item.name)
  182. },
  183. // async backLogin() {
  184. // let loginName = this.userName
  185. // if (loginName) {
  186. // await this.LogoutInfor(loginName)
  187. // }
  188. // },
  189. backLogin() {
  190. window.sessionStorage.clear()
  191. this.$router.push({
  192. path: "/login"
  193. })
  194. },
  195. // 插入登出信息
  196. LogoutInfor(name) {
  197. let that = this
  198. let onlyData = JSON.parse(window.sessionStorage.getItem('userDatamsg'))
  199. let loginData = JSON.parse(window.sessionStorage.getItem('loginMsg'))
  200. if (onlyData) {
  201. let paramsLogin = onlyData ? onlyData.identifier : loginData.identific
  202. let params = {
  203. identifier: paramsLogin,
  204. loginName: name
  205. }
  206. apiGetinsertLogoutInformation(params).then(datas => {
  207. if (datas) {
  208. let url = location.origin + '/#/login'
  209. window.open(url, '_self')
  210. location.reload()
  211. removeToken()
  212. }
  213. })
  214. } else {
  215. let url = location.origin + '/#/login'
  216. window.open(url, '_self')
  217. location.reload()
  218. removeToken()
  219. }
  220. },
  221. getStyle() {
  222. if (this.$route.path === '/weather') {
  223. if (this.rainW) {
  224. return 'weatherSty'
  225. } else {
  226. return 'headerSty'
  227. }
  228. }
  229. },
  230. getColor(val) {
  231. let strWea = ''
  232. if (val) {
  233. strWea = 'changeBacksty'
  234. } else {
  235. strWea = 'defaultBacksty'
  236. }
  237. return strWea
  238. },
  239. //获取个人信息
  240. getUserMes(id) {
  241. let params = {
  242. userId: id
  243. }
  244. apiGetpersonalInformation(params).then(datas => {
  245. window.sessionStorage.setItem('userInfo', JSON.stringify(datas.data.user))
  246. })
  247. },
  248. changeDate(date) {
  249. var y = date.getFullYear();
  250. var m = date.getMonth() + 1;
  251. m = m < 10 ? ('0' + m) : m;
  252. var d = date.getDate();
  253. d = d < 10 ? ('0' + d) : d;
  254. var h = date.getHours();
  255. h = h < 10 ? ('0' + h) : h;
  256. var minute = date.getMinutes();
  257. minute = minute < 10 ? ('0' + minute) : minute;
  258. var second = date.getSeconds();
  259. second = second < 10 ? ('0' + second) : second;
  260. return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second
  261. },
  262. nowTime() {
  263. let that = this;
  264. let date = new Date()
  265. this.statusTimer = setInterval(function () {
  266. var y = date.getFullYear();
  267. var m = date.getMonth() + 1;
  268. m = m < 10 ? ('0' + m) : m;
  269. var d = date.getDate();
  270. d = d < 10 ? ('0' + d) : d;
  271. var h = date.getHours();
  272. h = h < 10 ? ('0' + h) : h;
  273. var minute = date.getMinutes();
  274. minute = minute < 10 ? ('0' + minute) : minute;
  275. var second = date.getSeconds();
  276. second = second < 10 ? ('0' + second) : second;
  277. that.currentTime = y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
  278. }, 1000)
  279. },
  280. handleSelect(index) {
  281. if (this.leftIndex === index) return
  282. this.leftIndex = index
  283. // this.$router.push({path: index})
  284. console.log(index)
  285. }
  286. }
  287. }
  288. </script>
  289. <style lang="less">
  290. .proheader {
  291. // position: fixed;
  292. // top: 0;
  293. width: 100%;
  294. z-index: 1999;
  295. height: 50px;
  296. .weatherSty {
  297. background: rgb(74, 87, 100);
  298. }
  299. .el-header {
  300. padding: 0 10px;
  301. display: flex;
  302. justify-content: space-between;
  303. // background: rgb(13, 104, 188);
  304. // background: rgba(96,103,105,.75);
  305. color: #fff;
  306. line-height: 50px;
  307. height: 50px !important;
  308. .logoSty {
  309. padding: 8px 0 0 0;
  310. img {
  311. width: 310px;
  312. }
  313. }
  314. .proMenu {
  315. .proButton {
  316. display: flex;
  317. .buttonItem {
  318. cursor: pointer;
  319. width: 130px;
  320. height: 52px;
  321. line-height: 52px;
  322. font-size: 14px;
  323. text-align: center;
  324. }
  325. }
  326. .proSet {
  327. display: flex;
  328. justify-content: center;
  329. // width: 260px;
  330. .settingStop {
  331. display: flex;
  332. // width: 260px;
  333. align-items: center;
  334. justify-content: center;
  335. .el-switch {
  336. margin-left: 26px;
  337. width: 88px;
  338. height: 25px;
  339. .el-switch__input {
  340. width: 88px;
  341. height: 25px;
  342. }
  343. .el-switch__core {
  344. width: 88px;
  345. height: 25px;
  346. border-radius: 13px;
  347. .el-switch__action {
  348. width: 41px;
  349. height: 21px;
  350. border-radius: 11px;
  351. img {
  352. width: 15px;
  353. height: 15px;
  354. }
  355. }
  356. }
  357. }
  358. .el-switch--small.is-checked .el-switch__core .el-switch__action {
  359. width: 41px;
  360. height: 21px;
  361. border-radius: 10px;
  362. left: calc(100% - 41px) !important;
  363. }
  364. .Settingitem {
  365. color: #fff;
  366. margin-left: 30px;
  367. width: 25px;
  368. height: 25px;
  369. cursor: pointer;
  370. }
  371. .rightIm {
  372. margin-right: 30px;
  373. }
  374. .downItem {
  375. position: relative;
  376. top: 7px;
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. .themeDarks {
  384. border-bottom: 1px solid #3a3a3a;
  385. .proMenu {
  386. display: flex;
  387. align-items: center;
  388. .proButton {
  389. border-right: 1px solid #3a3a3a !important;
  390. .buttonItem {
  391. border-left: 1px solid #3a3a3a !important;
  392. }
  393. .changeBacksty {
  394. border-bottom: 3px solid #1C99FF !important;
  395. color: #1C99FF !important;
  396. }
  397. .defaultBacksty {
  398. color: #A2A3A4 !important;
  399. }
  400. .defaultweathersty {
  401. background-color: #0d68bc !important;
  402. }
  403. .defaultweatherRainsty {
  404. background-color: #4a5764 !important;
  405. }
  406. }
  407. .el-switch {
  408. .el-switch__core {
  409. background: #000;
  410. background-image: url('@/assets/images/headerCom/sun_B.png');
  411. background-repeat: no-repeat;
  412. background-position: 58px 2px;
  413. background-size: 20px;
  414. .el-switch__action {
  415. background: #1C99FF;
  416. }
  417. }
  418. }
  419. }
  420. }
  421. .themeLights {
  422. background: linear-gradient(90deg, #1f53b1, #6962b1) !important;
  423. border-bottom: 1px solid #7899ff;
  424. .proMenu {
  425. display: flex;
  426. align-items: center;
  427. .proButton {
  428. border-right: 1px solid #7899ff !important;
  429. .buttonItem {
  430. border-left: 1px solid #7899ff !important;
  431. }
  432. .changeBacksty {
  433. border-bottom: 3px solid #3dc2d3 !important;
  434. color: #fff !important;
  435. }
  436. .defaultBacksty {
  437. color: #B7C6FF !important;
  438. }
  439. .defaultweathersty {
  440. background-color: #0d68bc !important;
  441. }
  442. .defaultweatherRainsty {
  443. background-color: #4a5764 !important;
  444. }
  445. }
  446. .el-switch {
  447. .el-switch__core {
  448. background: #1E3F9A;
  449. background-image: url('@/assets/images/headerCom/moon_W.png');
  450. background-repeat: no-repeat;
  451. background-position: 8px 2px;
  452. background-size: 20px;
  453. .el-switch__action {
  454. background: #fff;
  455. }
  456. }
  457. }
  458. }
  459. }
  460. </style>