home.vue 7.7 KB

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