header.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="flex">
  3. <el-popover
  4. placement="top"
  5. width="300">
  6. <div class="app-flex">
  7. <p class="appLink" v-for="app in menuApp" :key="app.index" @click="handelMenuAppClick(app,'app')">{{app.systemappname}}</p>
  8. </div>
  9. <div slot="reference" class="search_panel">
  10. <input @focus="colorWhite = false" @blur="colorWhite = true" placeholder="输入搜索内容" v-model="searchValue"/>
  11. <i class="el-icon-search" :style="colorWhite?'color:#fff':'color:#000'"></i>
  12. </div>
  13. </el-popover>
  14. <div class="right-operation flex-align-center">
  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. <el-dropdown>
  20. <span class="el-dropdown-link">
  21. <div class="flex">
  22. {{accountInfo.sitename}}<i class="el-icon-arrow-down el-icon--right"></i>
  23. </div>
  24. </span>
  25. <el-dropdown-menu style="width:200px;text-align:center" slot="dropdown">
  26. <el-dropdown-item @click.native="$router.push({path:'/user_center'})">个人中心</el-dropdown-item>
  27. <!-- <el-dropdown-item v-if="canChangeSite" @click.native="$router.replace({path:'/accounts'})">切换账号</el-dropdown-item> -->
  28. <el-dropdown-item v-for="item in accountList" :key="item.index" divided @click.native="selectAccount(item)">
  29. <div class="flex-align-center flex-between">
  30. <p><span class="avatar-mini">{{item.enterprisename?item.enterprisename.substr(0, 1):item.sitename.substr(0, 1)}}</span><span>{{item.enterprisename?item.enterprisename:item.sitename}}</span></p>
  31. <small>{{item.name}}</small>
  32. </div>
  33. </el-dropdown-item>
  34. <el-dropdown-item divided @click.native="loginOut()">退出登录</el-dropdown-item>
  35. </el-dropdown-menu>
  36. </el-dropdown>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. import {mapGetters} from 'vuex'
  42. import axios from 'axios'
  43. export default {
  44. data () {
  45. return {
  46. accountInfo:{},
  47. url:"http://weather.cma.cn/api/weather/view?stationid=",
  48. weather:{},
  49. searchValue:'',
  50. accountList:[],
  51. colorWhite:true
  52. }
  53. },
  54. computed:{
  55. ...mapGetters({
  56. siteinfo:'siteinfo',
  57. menuApp:'menuApp'
  58. }),
  59. canChangeSite () {
  60. let accounts = JSON.parse(sessionStorage.getItem('account_list'))
  61. if (accounts.length > 1) return true
  62. }
  63. },
  64. methods:{
  65. // 选择登录账号
  66. selectAccount (item) {
  67. let arr = ['module_info','activeApp','active_modules','folderid']
  68. arr.forEach(key=>{
  69. sessionStorage.removeItem(key)
  70. })
  71. sessionStorage.setItem('active_account',JSON.stringify(item))
  72. this.basicData.query_userauth().then(()=>{
  73. this.basicData.querySite_Parameter()
  74. this.$router.replace({path:'/home'})
  75. })
  76. },
  77. async getWeather () {
  78. const res = await axios.get(this.url)
  79. this.weather = res.data.data
  80. },
  81. siteInfos () {
  82. this.$store.dispatch('querySiteInfo',{
  83. "classname": "webmanage.site.site",
  84. "method": "querySite",
  85. "content": {}
  86. })
  87. },
  88. loginOut () {
  89. this.$confirm('是否要退出当前账号?', '提示', {
  90. confirmButtonText: '确定',
  91. cancelButtonText: '取消',
  92. type: 'warning'
  93. }).then(() => {
  94. sessionStorage.clear()
  95. this.$router.push('/')
  96. }).catch((err) => {
  97. console.log(err)
  98. this.$message({
  99. type: 'info',
  100. message: '已取消'
  101. });
  102. });
  103. },
  104. changeAccount () {
  105. this.$router.push('/accounts')
  106. },
  107. //跳转到应用,并设设置激活模块
  108. handelMenuAppClick (app,type) {
  109. let system = JSON.parse(sessionStorage.getItem('module_info'))
  110. let mod = system.filter(e=>{return e.systemid === app.systemid})[0].modules.filter(e=>{return e.systemmoduleid === app.systemmoduleid})[0]
  111. let clickApp = mod.apps.filter(e=>{return e.systemappid === app.systemappid})
  112. sessionStorage.setItem('active_modules',JSON.stringify(mod))
  113. this.$emit('getModules',system.filter(e=>{return e.systemid === app.systemid})[0].modules,type)
  114. this.$store.dispatch('setActiveApp',{name:app.systemappname,app:clickApp[0],val:this.searchValue})
  115. this.$router.push({path:clickApp[0].path})
  116. },
  117. },
  118. mounted () {
  119. this.siteInfos()
  120. // this.getWeather()
  121. this.accountInfo = JSON.parse(sessionStorage.getItem('active_account'))
  122. this.accountList = JSON.parse(sessionStorage.getItem('account_list')).filter(e=>{
  123. return e.siteid !== this.accountInfo.siteid
  124. })
  125. },
  126. }
  127. </script>
  128. <style>
  129. .el-header{
  130. height: 50px !important;
  131. }
  132. .search_panel{
  133. position: relative;
  134. }
  135. .search_panel i{
  136. position: absolute;
  137. right:0px;
  138. height: 30px;
  139. width: 30px;
  140. text-align: center;
  141. line-height: 30px;
  142. color:#333
  143. }
  144. .search_panel input{
  145. background: rgba(255, 255, 255, .2);
  146. height: 30px;
  147. line-height: 30px;
  148. width: 300px;
  149. padding: 0 30px 0 20px;
  150. border:none;
  151. border-radius: 30px;
  152. color:#fff;
  153. outline: none;
  154. }
  155. .search_panel input::placeholder{
  156. color:#fff;
  157. }
  158. .search_panel input:focus{
  159. background: #fff;
  160. color:#333
  161. }
  162. .search_panel input:focus::placeholder{
  163. color:#333;
  164. }
  165. </style>
  166. <style scoped>
  167. .flex{
  168. display: flex;
  169. align-items: center;
  170. justify-content: space-between;
  171. background: none;
  172. color:#fff
  173. }
  174. .right-operation{
  175. padding: 0 20px;
  176. }
  177. .search_panel{
  178. margin: 16px 0;
  179. }
  180. .weather{
  181. font-size: 12px;
  182. margin-right:16px;
  183. color:#f1f2f3;
  184. transition: .2s linear;
  185. border-radius: 4px;
  186. padding: 5px 40px;
  187. }
  188. .weather:hover{
  189. background-color: rgba(255 ,255,255,.2) !important;
  190. }
  191. .appLink{
  192. padding:2px 5px;
  193. border:1px solid #f1f2f3;
  194. border-radius: 5px;
  195. margin-bottom: 10px;
  196. margin-left:5px;
  197. cursor: pointer;
  198. font-size: 12px;
  199. }
  200. .app-flex{
  201. display: flex;
  202. align-items: center;
  203. flex-wrap: wrap;
  204. }
  205. .avatar-mini{
  206. display: inline-block;
  207. position: relative;
  208. height:20px;
  209. width: 20px;
  210. line-height: 20px;
  211. text-align: center;
  212. margin-right: 5px;
  213. color:#fff;
  214. font-size: 12px;
  215. font-weight: 500;
  216. border-radius: 100%;
  217. background: #3874F6;
  218. }
  219. </style>