header.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. {{siteinfo.enterprisename}}<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.replace({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','acitveApp','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.go(0)
  75. })
  76. },
  77. async getWeather () {
  78. const res = await axios.get(this.url)
  79. console.log(res)
  80. this.weather = res.data.data
  81. },
  82. siteInfos () {
  83. this.$store.dispatch('querySiteInfo',{
  84. "classname": "webmanage.site.site",
  85. "method": "querySite",
  86. "content": {}
  87. })
  88. },
  89. loginOut () {
  90. this.$confirm('是否要退出当前账号?', '提示', {
  91. confirmButtonText: '确定',
  92. cancelButtonText: '取消',
  93. type: 'warning'
  94. }).then(() => {
  95. sessionStorage.clear()
  96. this.$router.push('/')
  97. location.reload(true);
  98. }).catch((err) => {
  99. console.log(err)
  100. this.$message({
  101. type: 'info',
  102. message: '已取消'
  103. });
  104. });
  105. },
  106. changeAccount () {
  107. this.$router.push('/accounts')
  108. },
  109. //跳转到应用,并设设置激活模块
  110. handelMenuAppClick (app,type) {
  111. let system = JSON.parse(sessionStorage.getItem('module_info'))
  112. let mod = system.filter(e=>{return e.systemid === app.systemid})[0].modules.filter(e=>{return e.systemmoduleid === app.systemmoduleid})[0]
  113. let clickApp = mod.apps.filter(e=>{return e.systemappid === app.systemappid})
  114. sessionStorage.setItem('active_modules',JSON.stringify(mod))
  115. this.$emit('getModules',system.filter(e=>{return e.systemid === app.systemid})[0].modules,type)
  116. this.$store.dispatch('setActiveApp',{name:app.systemappname,app:clickApp[0],val:this.searchValue})
  117. this.$router.push({path:clickApp[0].path})
  118. },
  119. },
  120. mounted () {
  121. this.siteInfos()
  122. this.getWeather()
  123. this.accountInfo = JSON.parse(sessionStorage.getItem('active_account'))
  124. this.accountList = JSON.parse(sessionStorage.getItem('account_list')).filter(e=>{
  125. return e.siteid !== this.accountInfo.siteid
  126. })
  127. },
  128. }
  129. </script>
  130. <style>
  131. .el-header{
  132. height: 50px !important;
  133. }
  134. .search_panel{
  135. position: relative;
  136. }
  137. .search_panel i{
  138. position: absolute;
  139. right:0px;
  140. height: 30px;
  141. width: 30px;
  142. text-align: center;
  143. line-height: 30px;
  144. color:#333
  145. }
  146. .search_panel input{
  147. background: rgba(255, 255, 255, .2);
  148. height: 30px;
  149. line-height: 30px;
  150. width: 300px;
  151. padding: 0 30px 0 20px;
  152. border:none;
  153. border-radius: 30px;
  154. color:#fff;
  155. outline: none;
  156. }
  157. .search_panel input::placeholder{
  158. color:#fff;
  159. }
  160. .search_panel input:focus{
  161. background: #fff;
  162. color:#333
  163. }
  164. .search_panel input:focus::placeholder{
  165. color:#333;
  166. }
  167. </style>
  168. <style scoped>
  169. .flex{
  170. display: flex;
  171. align-items: center;
  172. justify-content: space-between;
  173. background: none;
  174. color:#fff
  175. }
  176. .right-operation{
  177. padding: 0 20px;
  178. }
  179. .search_panel{
  180. margin: 16px 0;
  181. }
  182. .weather{
  183. font-size: 12px;
  184. margin-right:16px;
  185. color:#f1f2f3;
  186. transition: .2s linear;
  187. border-radius: 4px;
  188. padding: 5px 40px;
  189. }
  190. .weather:hover{
  191. background-color: rgba(255 ,255,255,.2) !important;
  192. }
  193. .appLink{
  194. padding:2px 5px;
  195. border:1px solid #f1f2f3;
  196. border-radius: 5px;
  197. margin-bottom: 10px;
  198. margin-left:5px;
  199. cursor: pointer;
  200. font-size: 12px;
  201. }
  202. .app-flex{
  203. display: flex;
  204. align-items: center;
  205. flex-wrap: wrap;
  206. }
  207. .avatar-mini{
  208. display: inline-block;
  209. position: relative;
  210. height:20px;
  211. width: 20px;
  212. line-height: 20px;
  213. text-align: center;
  214. margin-right: 5px;
  215. color:#fff;
  216. font-size: 12px;
  217. font-weight: 500;
  218. border-radius: 100%;
  219. background: #3874F6;
  220. }
  221. </style>