home.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template name="home">
  2. <div>
  3. <cu-custom bgColor="bg-gradual-pink">
  4. <block slot="content">首页</block>
  5. </cu-custom>
  6. <div class="panlens" v-if='isshow==false'>
  7. <br>
  8. <div style="margin-left: 20px;">
  9. <span style="font-size: 20px;color: #FFFFFF">亲爱的&nbsp&nbsp&nbsp{{this.$store.getters.realname}}</span>
  10. <br>
  11. <br>
  12. <span style="color: #FFFFFF;">今天是您在格克走过的第{{day}}天</span>
  13. </div>
  14. </div>
  15. <div class="panlenes" v-if='isshow==true'>
  16. <br>
  17. <div style="margin-left: 20px;">
  18. <span style="font-size: 20px;color: #FFFFFF;">亲爱的&nbsp&nbsp&nbsp{{this.$store.getters.realname}}</span>
  19. <br>
  20. <br>
  21. <span style="color: #FFFFFF;">今天是您的生日,格克感谢您的付出</span>
  22. <br>
  23. <span style="color: #FFFFFF;">祝您生日快乐!</span>
  24. </div>
  25. </div>
  26. <br>
  27. <div class="itemt">
  28. <view class="cu-bar bg-white solid-bottom" :style="[{animation: 'show 0.6s 1'}]">
  29. <view class="action">
  30. <text class='cuIcon-title text-blue'></text>个人自助
  31. </view>
  32. </view>
  33. <view class=" bg-white grid col-3 padding-sm">
  34. <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)">
  35. <view class="padding radius text-center shadow-blur solid-right ">
  36. <!-- <image :src="item.icon" mode="aspectFill" class="line2-icon"></image> -->
  37. <view class="cu-avatar lg "
  38. :style="{background: 'url(' + item.icon + ') no-repeat',backgroundSize:'95upx 95upx'}">
  39. <view class="cu-tag badge" v-if="getTtemDotInfo(item)">{{getTtemDotInfo(item)}}</view>
  40. </view>
  41. <view class="text-lg margin-top">{{item.title}}</view>
  42. </view>
  43. </view>
  44. </view>
  45. </div>
  46. <!-- 其他服务 -->
  47. <div class="itemt">
  48. <view class="cu-bar bg-white solid-bottom margin-top" :style="[{animation: 'show 0.6s 1'}]">
  49. <view class="action">
  50. <text class='cuIcon-title text-yellow'></text>团队信息
  51. </view>
  52. </view>
  53. <view class=" bg-white grid col-3 padding-sm">
  54. <view class="padding-sm animation-slide-bottom" :style="[{animationDelay: (index + 1)*0.1 + 's'}]" v-for="(item,index) in osList" :key="index" @tap="goPage(item.page)">
  55. <view class="padding radius text-center shadow-blur solid-right ">
  56. <view class="cu-avatar lg " :style="{background: 'url(' + item.icon + ') no-repeat',backgroundSize:'100upx 100upx'}"></view>
  57. <view class="text-lg margin-top">{{item.title}}</view>
  58. </view>
  59. </view>
  60. </view>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import { us,os } from '@/common/util/work.js'
  66. export default {
  67. name: 'home',
  68. props:{
  69. cur:String,
  70. },
  71. watch: {
  72. cur: {
  73. immediate: true,
  74. handler() {
  75. console.log('watch',this.cur)
  76. this.initMenu()
  77. },
  78. },
  79. },
  80. data() {
  81. return {
  82. usList:us.data,
  83. osList:os.data,
  84. websock:'',
  85. heartCheck:null,
  86. lockReconnect:false,
  87. msgCount:0,
  88. day:'',
  89. dot:{
  90. mailHome:false
  91. },
  92. isshow:false
  93. }
  94. },
  95. created(){
  96. this.days()
  97. },
  98. methods: {
  99. days(){
  100. var da=this.$store.getters.rzdate;
  101. var dt=this.$store.getters.birthdate;
  102. let day = (new Date().getTime()) - (new Date(da).getTime())//日期转时间戳
  103. console.log(day)
  104. let dayCount = Math.floor(day / 86400000) ;//时间戳获取天数
  105. this.day=dayCount;
  106. var ddt=new Date(dt);
  107. var ddr=new Date();
  108. if(ddt.getMonth()==ddr.getMonth()&&ddt.getDay()==ddr.getDay()){
  109. this.isshow=true;
  110. }
  111. },
  112. initMenu(){
  113. console.log("-----------home------------")
  114. this.initWebSocket();
  115. this.loadCount(0);
  116. },
  117. goPage(page){
  118. /* this.$router.push({name:'dome'}) */
  119. var org=this.$store.getters.orgCode;
  120. if(!page){
  121. return false;
  122. }
  123. if(page==='annotationList'){
  124. this.msgCount = 0
  125. }
  126. this.dot[page]=false
  127. /* if(page=="usersign" && org=="A01C294"){
  128. this.$router.push({name:'empsign'})
  129. }else if(page=="wages" && org=="A01C294"){
  130. this.$router.push({name:'wagesuser'})
  131. }else{ */
  132. this.$router.push({name: page})
  133. // }
  134. },
  135. initWebSocket: function () {
  136. // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
  137. var userId = this.$store.getters.userid;
  138. var token=this.$store.getters.token;
  139. var url = this.$config.apiUrl.replace("https://","wss://").replace("http://","ws://")+"/websocket/"+userId+"/"+token;
  140. console.log('websocket url>>'+url);
  141. this.websock = new WebSocket(url);
  142. this.websock.onopen = this.websocketOnopen;
  143. this.websock.onerror = this.websocketOnerror;
  144. this.websock.onmessage = this.websocketOnmessage;
  145. this.websock.onclose = this.websocketOnclose;
  146. },
  147. websocketOnopen: function () {
  148. console.log("WebSocket连接成功");
  149. //心跳检测重置
  150. //this.heartCheck.reset().start();
  151. },
  152. websocketOnerror: function () {
  153. console.log("WebSocket连接发生错误");
  154. this.reconnect();
  155. },
  156. websocketOnmessage: function (e) {
  157. console.log("-----接收消息-------",e.data);
  158. uni.showModal({
  159. title: '⚡',//⚡❕
  160. showCancel:false,
  161. content: e.data,
  162. confirmText: '确定',
  163. success: res => {
  164. this.$store.commit('SET_TOKEN',"");
  165. uni.navigateTo({
  166. url:'/pages/login/login'
  167. })
  168. }
  169. })
  170. /* var data = eval("(" + e.data + ")"); //解析对象
  171. if(data.cmd == "topic"){
  172. //系统通知
  173. this.loadCount('1')
  174. }else if(data.cmd == "user"){
  175. //用户消息
  176. this.loadCount('2')
  177. } else if(data.cmd == 'email'){
  178. this.loadEmailCount()
  179. } */
  180. //心跳检测重置
  181. //this.heartCheck.reset().start();
  182. },
  183. websocketOnclose: function (e) {
  184. console.log("connection closed (" + e.code + ")");
  185. this.reconnect();
  186. },
  187. websocketSend:function(text) { // 数据发送
  188. try {
  189. this.websock.send(text);
  190. } catch (err) {
  191. console.log("send failed (" + err.code + ")");
  192. }
  193. },
  194. reconnect() {
  195. var that = this;
  196. if(that.lockReconnect) return;
  197. that.lockReconnect = true;
  198. //没连接上会一直重连,设置延迟避免请求过多
  199. setTimeout(function () {
  200. console.info("尝试重连...");
  201. that.initWebSocket();
  202. that.lockReconnect = false;
  203. }, 5000);
  204. },
  205. loadCount(flag){
  206. console.log("loadCount::flag",flag)
  207. let url = '/sys/annountCement/listByUser';
  208. this.$http.get(url).then(res=>{
  209. console.log("res::",res)
  210. if(res.data.success){
  211. let msg1Count = res.data.result.anntMsgTotal;
  212. let msg2Count = res.data.result.sysMsgTotal;
  213. this.msgCount = msg1Count + msg2Count
  214. console.log("this.msgCount",this.msgCount)
  215. }
  216. })
  217. },
  218. loadEmailCount(){
  219. this.dot.mailHome = true
  220. },
  221. getTtemDotInfo(item){
  222. if(item.page==='annotationList' && this.msgCount>0){
  223. return this.msgCount
  224. }
  225. return '';
  226. }
  227. }
  228. }
  229. </script>
  230. <style>
  231. .line2-icon {
  232. width: 60px;
  233. height: 60px;
  234. }
  235. .panlens{
  236. width: 95%;
  237. margin:0 auto;
  238. border-radius:5px 5px 5px 5px;
  239. margin-top: 10px;
  240. background: url(../../static/sy.png);
  241. background-size:100% 100%;
  242. height: 130px;
  243. }
  244. .panlenes{
  245. width: 95%;
  246. margin:0 auto;
  247. border-radius:5px 5px 5px 5px;
  248. margin-top: 10px;
  249. background: url(../../static/bjsr.png) ;
  250. background-size:100% 100%;
  251. height: 130px;
  252. }
  253. .itemt{
  254. width: 95%;
  255. margin:0 auto;
  256. border-radius:5px 5px 5px 5px;
  257. }
  258. .top{
  259. background-color: #5677AC;
  260. width: 100%;
  261. height: 40px;
  262. }
  263. </style>