home.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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.component)">
  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.name}}</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:null,
  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. url:'/sys/permission/qeryPerssion'
  94. }
  95. },
  96. created(){
  97. this.days();
  98. this.queryPerssion();
  99. },
  100. methods: {
  101. queryPerssion(){
  102. this.$http.get(this.url,{params:{userid:this.$store.getters.userid}}).then(res=>{
  103. this.usList=res.data;
  104. })
  105. },
  106. days(){
  107. var da=this.$store.getters.rzdate;
  108. var dt=this.$store.getters.birthdate;
  109. let day = (new Date().getTime()) - (new Date(da).getTime())//日期转时间戳
  110. console.log(day)
  111. let dayCount = Math.floor(day / 86400000) ;//时间戳获取天数
  112. this.day=dayCount;
  113. var ddt=new Date(dt);
  114. var ddr=new Date();
  115. if(ddt.getMonth()==ddr.getMonth()&&ddt.getDay()==ddr.getDay()){
  116. this.isshow=true;
  117. }
  118. },
  119. initMenu(){
  120. console.log("-----------home------------")
  121. this.initWebSocket();
  122. this.loadCount(0);
  123. },
  124. goPage(page){
  125. if(!page){
  126. return false;
  127. }
  128. if(page==='annotationList'){
  129. this.msgCount = 0
  130. }
  131. this.dot[page]=false
  132. this.$router.push({name: page})
  133. },
  134. initWebSocket: function () {
  135. // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
  136. var userId = this.$store.getters.userid;
  137. var token=this.$store.getters.token;
  138. var url = this.$config.apiUrl.replace("https://","wss://").replace("http://","ws://")+"/websocket/"+userId+"/"+token;
  139. console.log('websocket url>>'+url);
  140. this.websock = new WebSocket(url);
  141. this.websock.onopen = this.websocketOnopen;
  142. this.websock.onerror = this.websocketOnerror;
  143. this.websock.onmessage = this.websocketOnmessage;
  144. this.websock.onclose = this.websocketOnclose;
  145. },
  146. websocketOnopen: function () {
  147. console.log("WebSocket连接成功");
  148. //心跳检测重置
  149. //this.heartCheck.reset().start();
  150. },
  151. websocketOnerror: function () {
  152. console.log("WebSocket连接发生错误");
  153. this.reconnect();
  154. },
  155. websocketOnmessage: function (e) {
  156. console.log("-----接收消息-------",e.data);
  157. uni.showModal({
  158. title: '⚡',//⚡❕
  159. showCancel:false,
  160. content: e.data,
  161. confirmText: '确定',
  162. success: res => {
  163. this.$store.commit('SET_TOKEN',"");
  164. uni.navigateTo({
  165. url:'/pages/login/login'
  166. })
  167. }
  168. })
  169. /* var data = eval("(" + e.data + ")"); //解析对象
  170. if(data.cmd == "topic"){
  171. //系统通知
  172. this.loadCount('1')
  173. }else if(data.cmd == "user"){
  174. //用户消息
  175. this.loadCount('2')
  176. } else if(data.cmd == 'email'){
  177. this.loadEmailCount()
  178. } */
  179. //心跳检测重置
  180. //this.heartCheck.reset().start();
  181. },
  182. websocketOnclose: function (e) {
  183. console.log("connection closed (" + e.code + ")");
  184. this.reconnect();
  185. },
  186. websocketSend:function(text) { // 数据发送
  187. try {
  188. this.websock.send(text);
  189. } catch (err) {
  190. console.log("send failed (" + err.code + ")");
  191. }
  192. },
  193. reconnect() {
  194. var that = this;
  195. if(that.lockReconnect) return;
  196. that.lockReconnect = true;
  197. //没连接上会一直重连,设置延迟避免请求过多
  198. setTimeout(function () {
  199. console.info("尝试重连...");
  200. that.initWebSocket();
  201. that.lockReconnect = false;
  202. }, 5000);
  203. },
  204. loadCount(flag){
  205. console.log("loadCount::flag",flag)
  206. let url = '/sys/annountCement/listByUser';
  207. this.$http.get(url).then(res=>{
  208. console.log("res::",res)
  209. if(res.data.success){
  210. let msg1Count = res.data.result.anntMsgTotal;
  211. let msg2Count = res.data.result.sysMsgTotal;
  212. this.msgCount = msg1Count + msg2Count
  213. console.log("this.msgCount",this.msgCount)
  214. }
  215. })
  216. },
  217. loadEmailCount(){
  218. this.dot.mailHome = true
  219. },
  220. getTtemDotInfo(item){
  221. if(item.page==='annotationList' && this.msgCount>0){
  222. return this.msgCount
  223. }
  224. return '';
  225. }
  226. }
  227. }
  228. </script>
  229. <style>
  230. .line2-icon {
  231. width: 60px;
  232. height: 60px;
  233. }
  234. .panlens{
  235. width: 95%;
  236. margin:0 auto;
  237. border-radius:5px 5px 5px 5px;
  238. margin-top: 10px;
  239. background: url(../../static/sy.png);
  240. background-size:100% 100%;
  241. height: 130px;
  242. }
  243. .panlenes{
  244. width: 95%;
  245. margin:0 auto;
  246. border-radius:5px 5px 5px 5px;
  247. margin-top: 10px;
  248. background: url(../../static/bjsr.png) ;
  249. background-size:100% 100%;
  250. height: 130px;
  251. }
  252. .itemt{
  253. width: 95%;
  254. margin:0 auto;
  255. border-radius:5px 5px 5px 5px;
  256. }
  257. .top{
  258. background-color: #5677AC;
  259. width: 100%;
  260. height: 40px;
  261. }
  262. </style>