commonHeaders.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <div class="proheader">
  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" :icon="item.icon"
  11. :class="getColor(item.showBac)" @click="changeRoute(item)">
  12. {{item.name}}
  13. </el-button>
  14. </el-button-group>
  15. <div class="userMsg">
  16. <!-- <span style="margin-right: 10px">{{userName}}</span> -->
  17. <el-tooltip class="box-item" effect="light" content="用户设置">
  18. <el-icon :size="size" :color="color" @click="changePersonRole">
  19. <Avatar />
  20. </el-icon>
  21. </el-tooltip>
  22. </div>
  23. <div class="divider" style="margin: 0 20px">|</div>
  24. <div class="settingStop">
  25. <!-- @click="changeSetting" -->
  26. <el-tooltip class="box-item" effect="light" content="系统设置">
  27. <el-icon size="small" :color="color" @click="changeSetting">
  28. <Setting />
  29. </el-icon>
  30. </el-tooltip>
  31. <el-tooltip class="box-item" effect="light" content="退出">
  32. <el-icon :size="size" :color="color" @click="backLogin" style="margin: 0 15px">
  33. <SwitchButton />
  34. </el-icon>
  35. </el-tooltip>
  36. </div>
  37. </div>
  38. </el-header>
  39. </el-container>
  40. </div>
  41. </template>
  42. <script>
  43. import httpRequest from '@/utils/request.js'
  44. import {
  45. apiGetpersonalInformation
  46. } from '@/api/api'
  47. import {
  48. removeToken
  49. } from '@/utils/auth'
  50. export default {
  51. name: 'headerCom',
  52. data() {
  53. return {
  54. leftIndex: '1',
  55. currentTime: '',
  56. showRole: true,
  57. menuData: [],
  58. rainW: false,
  59. userName: ''
  60. }
  61. },
  62. created() {
  63. this.menuData = [{
  64. index: '/home',
  65. icon: 'Menu',
  66. name: '首页',
  67. showBac: true
  68. },
  69. {
  70. index: '/generatingCap/dataFilter/prepare',
  71. icon: 'Histogram',
  72. name: '发电能力分析'
  73. },
  74. {
  75. index: '/intelligentReport/reporting',
  76. icon: 'PictureFilled',
  77. name: '智能报表'
  78. },
  79. {
  80. index: '/powerPrediction/index',
  81. icon: 'TrendCharts',
  82. name: '功率预测'
  83. },
  84. ]
  85. },
  86. mounted() {
  87. let that = this;
  88. let userMes = JSON.parse(window.sessionStorage.getItem('userMessage'))
  89. that.userName = userMes ? userMes.role : 'administrator'
  90. if (this.$route.query.markKey) {
  91. that.userName = that.$route.query.userid
  92. }
  93. if (userMes && userMes.role === 'ordinaryUser') {
  94. that.showRole = false
  95. }
  96. // that.getUserMes(userMes.userId)
  97. debugger
  98. that.showHeader(that.$route)
  99. },
  100. watch: {
  101. $route: {
  102. handler: function (route) {
  103. console.log('route', route)
  104. this.showHeader(route)
  105. },
  106. immediate: true
  107. }
  108. },
  109. methods: {
  110. showHeader(route) {
  111. this.menuData.forEach(it => {
  112. if (route.path.indexOf('powerPrediction') > -1) {
  113. httpRequest.defaults.baseURL = process.env.VUE_APP_BASE_URL;
  114. if (it.name === '功率预测') {
  115. it.showBac = true
  116. } else {
  117. it.showBac = false
  118. }
  119. } else if (route.path.indexOf('intelligentReport') > -1) {
  120. httpRequest.defaults.baseURL = process.env.VUE_APP_REPORT_URL;
  121. if (it.name === '智能报表') {
  122. it.showBac = true
  123. } else {
  124. it.showBac = false
  125. }
  126. } else if (route.path.indexOf('generatingCap') > -1) {
  127. httpRequest.defaults.baseURL = process.env.VUE_APP_GENERAT_URL;
  128. if (it.name === '发电能力分析') {
  129. it.showBac = true
  130. } else {
  131. it.showBac = false
  132. }
  133. } else if (route.path === '/home') {
  134. if (it.name === '首页') {
  135. it.showBac = true
  136. } else {
  137. it.showBac = false
  138. }
  139. } else {
  140. it.showBac = false
  141. }
  142. })
  143. },
  144. changeRoute(item) {
  145. window.sessionStorage.setItem('headerRoute', item.index)
  146. this.$router.push({
  147. path: item.index
  148. })
  149. this.$emit('headerName', item.name)
  150. },
  151. async backLogin() {
  152. let loginName = this.userName
  153. if (loginName) {
  154. await this.LogoutInfor(loginName)
  155. }
  156. },
  157. // 插入登出信息
  158. LogoutInfor(name) {
  159. let that = this
  160. let onlyData = JSON.parse(window.sessionStorage.getItem('userDatamsg'))
  161. let loginData = JSON.parse(window.sessionStorage.getItem('loginMsg'))
  162. if (onlyData) {
  163. let paramsLogin = onlyData ? onlyData.identifier : loginData.identific
  164. let params = {
  165. identifier: paramsLogin,
  166. loginName: name
  167. }
  168. apiGetinsertLogoutInformation(params).then(datas => {
  169. if (datas) {
  170. let url = location.origin + '/#/login'
  171. window.open(url, '_self')
  172. location.reload()
  173. removeToken()
  174. }
  175. })
  176. } else {
  177. let url = location.origin + '/#/login'
  178. window.open(url, '_self')
  179. location.reload()
  180. removeToken()
  181. }
  182. },
  183. changeSetting() {
  184. this.$router.push({
  185. path: '/systemSettings/Overview'
  186. })
  187. },
  188. changePersonRole() {
  189. this.$router.push({
  190. path: '/personnelRole'
  191. })
  192. },
  193. getStyle() {
  194. if (this.$route.path === '/weather') {
  195. if (this.rainW) {
  196. return 'weatherSty'
  197. } else {
  198. return 'headerSty'
  199. }
  200. }
  201. },
  202. getColor(val) {
  203. let strWea = ''
  204. if (val) {
  205. strWea = 'changeBacksty'
  206. } else {
  207. strWea = 'defaultBacksty'
  208. }
  209. return strWea
  210. },
  211. //获取个人信息
  212. getUserMes(id) {
  213. let params = {
  214. userId: id
  215. }
  216. apiGetpersonalInformation(params).then(datas => {
  217. window.sessionStorage.setItem('userInfo', JSON.stringify(datas.data.user))
  218. })
  219. },
  220. changeDate(date) {
  221. var y = date.getFullYear();
  222. var m = date.getMonth() + 1;
  223. m = m < 10 ? ('0' + m) : m;
  224. var d = date.getDate();
  225. d = d < 10 ? ('0' + d) : d;
  226. var h = date.getHours();
  227. h = h < 10 ? ('0' + h) : h;
  228. var minute = date.getMinutes();
  229. minute = minute < 10 ? ('0' + minute) : minute;
  230. var second = date.getSeconds();
  231. second = second < 10 ? ('0' + second) : second;
  232. return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second
  233. },
  234. nowTime() {
  235. let that = this;
  236. let date = new Date()
  237. this.statusTimer = setInterval(function () {
  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. that.currentTime = y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
  250. }, 1000)
  251. },
  252. handleSelect(index) {
  253. if (this.leftIndex === index) return
  254. this.leftIndex = index
  255. // this.$router.push({path: index})
  256. console.log(index)
  257. }
  258. }
  259. }
  260. </script>
  261. <style lang="less">
  262. .proheader {
  263. // position: fixed;
  264. // top: 0;
  265. width: 100%;
  266. z-index: 1999;
  267. height: 60px;
  268. .weatherSty {
  269. background: rgb(74, 87, 100);
  270. }
  271. .headerSty {
  272. // background: rgb(13, 104, 188);
  273. // background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#373590), to(#645fef));
  274. }
  275. .el-header {
  276. padding: 0 10px;
  277. display: flex;
  278. justify-content: space-between;
  279. // background: rgb(13, 104, 188);
  280. // background: rgba(96,103,105,.75);
  281. color: #fff;
  282. line-height: 60px;
  283. height: 60px !important;
  284. .logoSty {
  285. padding: 10px 0 0 0;
  286. img {
  287. width: 310px;
  288. }
  289. }
  290. .proMenu {
  291. display: flex;
  292. align-items: center;
  293. .el-button-group {
  294. .changeBacksty {
  295. background: linear-gradient(0deg, transparent, #000);
  296. }
  297. .defaultBacksty {
  298. background-color: #000 !important;
  299. }
  300. .defaultweathersty {
  301. background-color: #0d68bc !important;
  302. }
  303. .defaultweatherRainsty {
  304. background-color: #4a5764 !important;
  305. }
  306. .el-button {
  307. background-color: #373590;
  308. border-color: #8679df;
  309. padding: 0 20px;
  310. &:hover {
  311. background-color: #504bb5;
  312. }
  313. }
  314. }
  315. .userMsg {
  316. margin-left: 150px;
  317. .el-icon {
  318. cursor: pointer;
  319. }
  320. }
  321. .divider {
  322. position: relative;
  323. top: -3px;
  324. }
  325. .settingStop {
  326. .el-icon {
  327. cursor: pointer;
  328. }
  329. }
  330. }
  331. }
  332. }
  333. </style>