commonHeaders.vue 16 KB

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