header.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div class="flex">
  3. <div class="flex-align-center">
  4. <el-popover
  5. placement="top"
  6. width="400">
  7. <div class="app-flex flex-between">
  8. <p class="appLink" v-for="app in menuApp" :key="app.index">{{app.systemappname}}</p>
  9. </div>
  10. <div slot="reference" class="search_panel">
  11. <input placeholder="输入搜索内容"/>
  12. <i class="el-icon-search"></i>
  13. </div>
  14. </el-popover>
  15. <div class="weather">
  16. <p>今日天气:{{weather.daily?weather.daily[0].dayText:""}}</p>
  17. <p>{{weather.daily?weather.daily[0].low:""}}℃~{{weather.daily?weather.daily[0].high:""}}℃</p>
  18. </div>
  19. </div>
  20. <div class="right-operation">
  21. <el-dropdown>
  22. <span class="el-dropdown-link">
  23. <div class="flex">
  24. {{siteinfo.enterprisename}}<i class="el-icon-arrow-down el-icon--right"></i>
  25. </div>
  26. </span>
  27. <el-dropdown-menu slot="dropdown">
  28. <el-dropdown-item @click.native="$router.replace({path:'/user_center'})">个人中心</el-dropdown-item>
  29. <el-dropdown-item v-if="canChangeSite" @click.native="$router.replace({path:'/accounts'})">切换账号</el-dropdown-item>
  30. <el-dropdown-item divided @click.native="loginOut()">退出登录</el-dropdown-item>
  31. </el-dropdown-menu>
  32. </el-dropdown>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import {mapGetters} from 'vuex'
  38. import axios from 'axios'
  39. export default {
  40. data () {
  41. return {
  42. accountInfo:{},
  43. url:"http://weather.cma.cn/api/weather/view?stationid=",
  44. weather:{}
  45. }
  46. },
  47. computed:{
  48. ...mapGetters({
  49. siteinfo:'siteinfo',
  50. menuApp:'menuApp'
  51. }),
  52. canChangeSite () {
  53. let accounts = JSON.parse(sessionStorage.getItem('account_list'))
  54. if (accounts.length > 1) return true
  55. }
  56. },
  57. methods:{
  58. async getWeather () {
  59. const res = await axios.get(this.url)
  60. console.log(res)
  61. this.weather = res.data.data
  62. },
  63. siteInfos () {
  64. this.$store.dispatch('querySiteInfo',{
  65. "classname": "webmanage.site.site",
  66. "method": "querySite",
  67. "content": {}
  68. })
  69. },
  70. loginOut () {
  71. this.$confirm('是否要退出当前账号?', '提示', {
  72. confirmButtonText: '确定',
  73. cancelButtonText: '取消',
  74. type: 'warning'
  75. }).then(() => {
  76. this.$router.push('/')
  77. sessionStorage.clear()
  78. // location.reload(true);
  79. }).catch((err) => {
  80. console.log(err)
  81. this.$message({
  82. type: 'info',
  83. message: '已取消'
  84. });
  85. });
  86. },
  87. changeAccount () {
  88. this.$router.push('/accounts')
  89. }
  90. },
  91. mounted () {
  92. this.siteInfos()
  93. this.getWeather()
  94. this.accountInfo = JSON.parse(sessionStorage.getItem('active_account'))
  95. },
  96. }
  97. </script>
  98. <style>
  99. .el-header{
  100. height: 50px !important;
  101. }
  102. .search_panel{
  103. position: relative;
  104. }
  105. .search_panel i{
  106. position: absolute;
  107. right:0px;
  108. height: 30px;
  109. width: 30px;
  110. text-align: center;
  111. line-height: 30px;
  112. color:#333
  113. }
  114. .search_panel input{
  115. background: none;
  116. height: 30px;
  117. line-height: 30px;
  118. width: 400px;
  119. padding: 0 30px 0 10px;
  120. border: 1px solid #f1f2f3;
  121. border-radius: 5px;
  122. outline: none;
  123. }
  124. .search_panel input::placeholder{
  125. color:#fff;
  126. }
  127. .search_panel input:focus{
  128. background: #fff;
  129. }
  130. .search_panel input:focus::placeholder{
  131. color:#333;
  132. }
  133. </style>
  134. <style scoped>
  135. .flex{
  136. display: flex;
  137. align-items: center;
  138. justify-content: space-between;
  139. background: none;
  140. color:#fff
  141. }
  142. .logo{
  143. }
  144. .right-operation{
  145. padding: 0 20px;
  146. }
  147. .search_panel{
  148. margin: 16px 0;
  149. }
  150. .weather{
  151. font-size: 14px;
  152. margin-left:16px;
  153. color:#f1f2f3
  154. }
  155. .appLink{
  156. padding:2px 5px;
  157. border:1px solid #f1f2f3;
  158. border-radius: 5px;
  159. margin-bottom: 10px;
  160. cursor: pointer;
  161. }
  162. .app-flex{
  163. display: flex;
  164. align-items: center;
  165. flex-wrap: wrap;
  166. font-size: 12px;
  167. }
  168. </style>