home.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template name="home">
  2. <view>
  3. <scroll-view>
  4. <!-- 轮播 -->
  5. <swiper class="screen-swiper square-dot" :indicator-dots="true" :circular="true"
  6. :autoplay="true" interval="5000" duration="500" :style="[{animation: 'show 0.2s 1'}]">
  7. <swiper-item v-for="(item,index) in swiperList" :key="index">
  8. <image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image>
  9. <video :src="item.url" autoplay loop muted :show-play-btn="false" :controls="false" objectFit="cover" v-if="item.type=='video'"></video>
  10. </swiper-item>
  11. </swiper>
  12. <!-- 中部应用宫格 -->
  13. <view class="bg-white" :style="[{animation: 'show 0.4s 1'}]">
  14. <view class="grid margin-bottom col-2 ">
  15. <navigator v-for="(item,index) in middleApps" :key="index" :url="'/pages/home/' + item.name" class="nav-li" navigateTo
  16. :style="[{animation: 'show ' + ((index+1)*0.2+1) + 's 1'}]" hover-class="none">
  17. <view class="flex align-center">
  18. <image :src="'/static/home/'+item.icon" mode="aspectFill" class="line2-icon"></image>
  19. <view class="text-df">{{item.title}} <br/> <span class="text-light">{{item.text}}</span></view>
  20. </view>
  21. </navigator>
  22. </view>
  23. </view>
  24. <!-- 常用服务 -->
  25. <view class="cu-bar bg-white solid-bottom" :style="[{animation: 'show 0.6s 1'}]">
  26. <view class="action">
  27. <text class='cuIcon-title text-blue'></text>常用服务
  28. </view>
  29. </view>
  30. <view class=" bg-white grid col-3 padding-sm">
  31. <view class="padding-sm animation-slide-bottom" :style="[{animationDelay: (index + 1)*0.1 + 's'}]" v-for="(item,index) in usList" :key="index" @tap="goPage(item.page)">
  32. <view class="padding radius text-center shadow-blur solid-right ">
  33. <!-- <image :src="item.icon" mode="aspectFill" class="line2-icon"></image> -->
  34. <view class="cu-avatar lg "
  35. :style="{background: 'url(' + item.icon + ') no-repeat',backgroundSize:'100upx 100upx'}">
  36. <view class="cu-tag badge" v-if="getTtemDotInfo(item)">{{getTtemDotInfo(item)}}</view>
  37. </view>
  38. <view class="text-lg margin-top">{{item.title}}</view>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 其他服务 -->
  43. <view class="cu-bar bg-white solid-bottom margin-top" :style="[{animation: 'show 0.6s 1'}]">
  44. <view class="action">
  45. <text class='cuIcon-title text-yellow'></text>其他服务
  46. </view>
  47. </view>
  48. <view class=" bg-white grid col-3 padding-sm">
  49. <view class="padding-sm animation-slide-bottom" :style="[{animationDelay: (index + 1)*0.1 + 's'}]" v-for="(item,index) in osList" :key="index">
  50. <view class="padding radius text-center shadow-blur solid-right ">
  51. <view class="cu-avatar lg " :style="{background: 'url(' + item.icon + ') no-repeat',backgroundSize:'100upx 100upx'}"><!-- <view class="cu-tag badge">99</view> --></view>
  52. <view class="text-lg margin-top">{{item.title}}</view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="cu-tabbar-height">
  57. </view>
  58. </scroll-view>
  59. </view>
  60. </template>
  61. <script>
  62. import { us,os } from '@/common/util/work.js'
  63. export default {
  64. name: 'home',
  65. props:{
  66. cur:String,
  67. },
  68. watch: {
  69. cur: {
  70. immediate: true,
  71. handler() {
  72. console.log('watch',this.cur)
  73. this.initMenu()
  74. },
  75. },
  76. },
  77. data() {
  78. return {
  79. swiperList: [
  80. {id:1,type: 'image',url: '/static/banner/banner1.png', link: ''},
  81. {id:2,type: 'image',url: '/static/banner/banner2.jpg', link: ''},
  82. {id:3,type: 'image',url: '/static/banner/banner3.jpg', link: ''},
  83. {id:4,type: 'image',url: '/static/banner/banner4.jpg', link: ''},
  84. ],
  85. middleApps: [
  86. {icon: 'line2_icon1.png', title: '审批', 'text': '个人审批'},
  87. {icon: 'line2_icon2.png', title: '审批稿', 'text': '审批草稿箱'},
  88. ],
  89. usList:us.data,
  90. osList:os.data,
  91. websock:'',
  92. heartCheck:null,
  93. lockReconnect:false,
  94. msgCount:0,
  95. dot:{
  96. mailHome:false
  97. }
  98. }
  99. },
  100. methods: {
  101. initMenu(){
  102. console.log("-----------home------------")
  103. this.initWebSocket();
  104. this.loadCount(0);
  105. },
  106. goPage(page){
  107. if(!page){
  108. return false;
  109. }
  110. if(page==='annotationList'){
  111. this.msgCount = 0
  112. }
  113. this.dot[page]=false
  114. this.$router.push({name: page})
  115. },
  116. initWebSocket: function () {
  117. // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
  118. var userId = this.$store.getters.userid;
  119. var url = this.$config.apiUrl.replace("https://","wss://").replace("http://","ws://")+"/websocket/"+userId;
  120. console.log('websocket url>>'+url);
  121. this.websock = new WebSocket(url);
  122. this.websock.onopen = this.websocketOnopen;
  123. this.websock.onerror = this.websocketOnerror;
  124. this.websock.onmessage = this.websocketOnmessage;
  125. this.websock.onclose = this.websocketOnclose;
  126. },
  127. websocketOnopen: function () {
  128. console.log("WebSocket连接成功");
  129. //心跳检测重置
  130. //this.heartCheck.reset().start();
  131. },
  132. websocketOnerror: function () {
  133. console.log("WebSocket连接发生错误");
  134. this.reconnect();
  135. },
  136. websocketOnmessage: function (e) {
  137. console.log("-----接收消息-------",e.data);
  138. var data = eval("(" + e.data + ")"); //解析对象
  139. if(data.cmd == "topic"){
  140. //系统通知
  141. this.loadCount('1')
  142. }else if(data.cmd == "user"){
  143. //用户消息
  144. this.loadCount('2')
  145. } else if(data.cmd == 'email'){
  146. this.loadEmailCount()
  147. }
  148. //心跳检测重置
  149. //this.heartCheck.reset().start();
  150. },
  151. websocketOnclose: function (e) {
  152. console.log("connection closed (" + e.code + ")");
  153. this.reconnect();
  154. },
  155. websocketSend(text) { // 数据发送
  156. try {
  157. this.websock.send(text);
  158. } catch (err) {
  159. console.log("send failed (" + err.code + ")");
  160. }
  161. },
  162. reconnect() {
  163. var that = this;
  164. if(that.lockReconnect) return;
  165. that.lockReconnect = true;
  166. //没连接上会一直重连,设置延迟避免请求过多
  167. setTimeout(function () {
  168. console.info("尝试重连...");
  169. that.initWebSocket();
  170. that.lockReconnect = false;
  171. }, 5000);
  172. },
  173. loadCount(flag){
  174. console.log("loadCount::flag",flag)
  175. let url = '/sys/annountCement/listByUser';
  176. this.$http.get(url).then(res=>{
  177. console.log("res::",res)
  178. if(res.data.success){
  179. let msg1Count = res.data.result.anntMsgTotal;
  180. let msg2Count = res.data.result.sysMsgTotal;
  181. this.msgCount = msg1Count + msg2Count
  182. console.log("this.msgCount",this.msgCount)
  183. }
  184. })
  185. },
  186. loadEmailCount(){
  187. this.dot.mailHome = true
  188. },
  189. getTtemDotInfo(item){
  190. if(item.page==='annotationList' && this.msgCount>0){
  191. return this.msgCount
  192. }
  193. return '';
  194. }
  195. }
  196. }
  197. </script>
  198. <style>
  199. .line2-icon {
  200. width: 60px;
  201. height: 60px;
  202. }
  203. </style>