home.vue 6.6 KB

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