TopBar.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <div class="top-bar-box">
  3. <div class="top-bar">
  4. <div class="top-box">
  5. <span>移动安全保卫管理平台</span>
  6. <van-icon name="setting-o" size="26" @click="clickOutLogin" />
  7. </div>
  8. <div class="bottom-box">
  9. <div>
  10. <p class="user-name">{{ userName }}</p>
  11. <p class="introduce-info" v-for="item in rolesList" :key="item.roleId">{{ orgName }} · {{ item.roleName }}</p>
  12. </div>
  13. <van-icon name="arrow" size="20" />
  14. </div>
  15. </div>
  16. <div v-if="showNotice" class="notice-box">
  17. <div>
  18. <van-notice-bar v-if="list.length>0" left-icon="volume-o" mode="closeable" :color="color" :background="background">
  19. <van-swipe
  20. @change="onChange"
  21. vertical
  22. class="notice-swipe"
  23. :autoplay="8000"
  24. :show-indicators="false">
  25. <van-swipe-item v-for="item in list" :key="item.id" @click="clickHandler(item)" >
  26. {{item.alarmTitle}}
  27. </van-swipe-item>
  28. </van-swipe>
  29. </van-notice-bar>
  30. </div>
  31. </div>
  32. <!-- &lt;!&ndash; 天气预警 &ndash;&gt;-->
  33. <!-- <van-swipe v-if="list.length > 0" style="height: 50px" vertical autoplay="2000">-->
  34. <!-- <van-swipe-item v-for="item in list" :key="item.id" @click="clickHandler(item)">-->
  35. <!-- <div class="color" :style="{ color: item.bgc, backgroundColor: '#fff' }">-->
  36. <!-- <van-icon name="warn-o" /> {{ item.alarmTitle }}-->
  37. <!-- </div>-->
  38. <!-- </van-swipe-item>-->
  39. <!-- <template #indicator>-->
  40. <!-- <div class="custom-indicator"></div>-->
  41. <!-- </template>-->
  42. <!-- </van-swipe>-->
  43. </div>
  44. </template>
  45. <script>
  46. import { Icon } from 'vant'
  47. import { mapGetters } from 'vuex'
  48. import { logout, getTheAreaWeather } from '@/api/public'
  49. export default {
  50. components: {
  51. [Icon.name]: Icon
  52. },
  53. props:{
  54. showNotice:{
  55. type:Boolean,
  56. default:true
  57. },
  58. },
  59. data() {
  60. return {
  61. list: [],
  62. show: false,
  63. info: '',
  64. active: this.defaultActive,
  65. rolesList: [],
  66. color: '#ecf9ff',
  67. background: '#4ea2f8'
  68. }
  69. },
  70. computed: {
  71. ...mapGetters(['userName', 'orgName', 'orgId'])
  72. },
  73. created() {},
  74. mounted() {
  75. setTimeout(() => {
  76. if(this.orgId){
  77. this.getTheWeather()
  78. }
  79. }, 100);
  80. // this.rolesList=JSON.parse(window.sessionStorage.getItem('SET_USER_ROLELIST'))||[]
  81. },
  82. methods: {
  83. onChange(index){
  84. let alarmLevel = this.list[index].alarmLevel;
  85. switch (alarmLevel){
  86. case '蓝色':
  87. this.background = '#4ea2f8';
  88. this.color = '#fff';
  89. break;
  90. case '黄色':
  91. this.background = '#eee367';
  92. this.color = '#fff';
  93. break;
  94. case '橙色':
  95. this.background = '#f6b568';
  96. this.color = '#fff';
  97. break;
  98. case '红色':
  99. this.background = '#ef464a';
  100. this.color = '#fff';
  101. }
  102. },
  103. clickOutLogin() {
  104. logout().then(res => {
  105. sessionStorage.clear()
  106. this.$router.replace('/login')
  107. this.$toast('退出登录')
  108. })
  109. },
  110. clickHandler(item) {
  111. console.log(item,'1111111')
  112. this.info = item.alarmContent
  113. this.show = true
  114. },
  115. //获取天气数据
  116. getTheWeather() {
  117. getTheAreaWeather(this.orgId).then(res => {
  118. this.list = res.data || []
  119. this.list.forEach(item => {
  120. if (item.alarmLevel == '橙色') {
  121. item.bgc = '#fa8e00'
  122. } else if (item.alarmLevel == '红色') {
  123. item.bgc = '#fa0008'
  124. } else if (item.alarmLevel == '蓝色') {
  125. item.bgc = '#3788fa'
  126. } else if (item.alarmLevel == '黄色') {
  127. item.bgc = '#e9fa00'
  128. }
  129. })
  130. setTimeout(() => {
  131. this.rolesList = JSON.parse(window.sessionStorage.getItem('SET_USER_ROLELIST')) || []
  132. }, 100)
  133. console.log(this.rolesList)
  134. })
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="scss">
  140. .van-notice-bar{
  141. line-height:60px;
  142. height: 60px;
  143. }
  144. .notice-swipe {
  145. height: 30px;
  146. line-height: 30px;
  147. }
  148. </style>
  149. <style scoped lang="scss">
  150. .top-bar-box{
  151. position: relative;
  152. }
  153. .top-bar {
  154. height: 300px;
  155. width: 100%;
  156. background: url('../assets/img/banner.png') no-repeat center;
  157. background-size: 100% 100%;
  158. padding: 40px;
  159. box-shadow: 0 1px 8px #ccc;
  160. > div {
  161. width: 100%;
  162. display: flex;
  163. justify-content: space-between;
  164. align-items: center;
  165. color: #fff;
  166. }
  167. }
  168. .top-box {
  169. > span {
  170. font-size: 40px;
  171. }
  172. }
  173. .notice-box{
  174. width: 100%;
  175. position: absolute;
  176. bottom: -80;
  177. z-index: 1000;
  178. }
  179. .bottom-box {
  180. padding-top: 50px;
  181. > div {
  182. .user-name {
  183. font-size: 30px;
  184. margin-bottom: 20px;
  185. }
  186. .introduce-info {
  187. font-size: 20px;
  188. }
  189. }
  190. }
  191. </style>