index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="box">
  3. <view class="main">
  4. <chat-index v-if="pageCur==='chats'"></chat-index>
  5. <friend-index v-if="pageCur==='friends'"></friend-index>
  6. <group-index v-if="pageCur==='groups'"></group-index>
  7. <!-- <dept-index v-if="pageCur==='dept'"></dept-index> -->
  8. <mine-index v-if="pageCur==='mine'"></mine-index>
  9. </view>
  10. <view class="cu-bar tabbar bg-white shadow foot">
  11. <view class="action" @click="navChange" data-cur="chats">
  12. <view>
  13. <image class="tabbarIcon" v-if="pageCur!='chats'" src="/static/tabbar/index.png"></image>
  14. <image class="tabbarIcon" v-if="pageCur==='chats'" src="/static/tabbar/index_cur.png"></image>
  15. <view class="cu-tag badge" v-if="chatStore.allUnReadCount>0">{{ chatStore.allUnReadCount }}</view>
  16. </view>
  17. <view :class="pageCur==='chats'?'text-zblue':'text-gray'">聊天</view>
  18. </view>
  19. <view class="action" @click="navChange" data-cur="friends">
  20. <!-- <view class="iconfont icon-haoyou" :class="pageCur==='friends'?'text-cyan':'text-gray'">
  21. <view class="cu-tag badge" v-if="friendStore.waitValidateList.length>0">{{ friendStore.waitValidateList.length }}</view>
  22. </view> -->
  23. <view>
  24. <image class="tabbarIcon" v-if="pageCur!='friends'" src="/static/tabbar/txl.png"></image>
  25. <image class="tabbarIcon" v-if="pageCur==='friends'" src="/static/tabbar/txl_cur.png"></image>
  26. <view class="cu-tag badge" v-if="friendStore.waitValidateList.length>0">{{ friendStore.waitValidateList.length }}</view>
  27. </view>
  28. <view :class="pageCur==='friends'?'text-zblue':'text-gray'">通讯录</view>
  29. </view>
  30. <view class="action" @click="navChange" data-cur="groups">
  31. <!-- <view class="iconfont icon-qunzhong" :class="pageCur==='groups'?'text-cyan':'text-gray'">
  32. <view class="cu-tag badge" v-if="waitCheckGroupCount>0">{{ waitCheckGroupCount }}</view>
  33. </view> -->
  34. <view>
  35. <image class="tabbarIcon" v-if="pageCur!='groups'" src="/static/tabbar/qunzu.png"></image>
  36. <image class="tabbarIcon" v-if="pageCur==='groups'" src="/static/tabbar/qunzu_cur.png"></image>
  37. <view class="cu-tag badge" v-if="waitCheckGroupCount>0">{{ waitCheckGroupCount }}</view>
  38. </view>
  39. <view :class="pageCur==='groups'?'text-zblue':'text-gray'">群组</view>
  40. </view>
  41. <!-- <view class="action" @click="navChange" data-cur="dept">
  42. <view class="iconfont icon-bumen" :class="pageCur==='dept'?'text-cyan':'text-gray'"></view>
  43. <view :class="pageCur==='dept'?'text-cyan':'text-gray'">组织</view>
  44. </view> -->
  45. <view class="action" @click="navChange" data-cur="mine">
  46. <image class="tabbarIcon" v-if="pageCur==='mine'" src="/static/tabbar/wode_cur.png"></image>
  47. <image class="tabbarIcon" v-if="pageCur!='mine'" src="/static/tabbar/wode.png"></image>
  48. <view :class="pageCur==='mine'?'text-zblue':'text-gray'">我的</view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script setup lang="ts">
  54. import {computed, getCurrentInstance, onMounted, ref} from 'vue';
  55. import ChatIndex from '@/pages/chat/index.vue'
  56. import FriendIndex from '@/pages/friend/index.vue'
  57. import GroupIndex from '@/pages/group/index.vue'
  58. import MineIndex from '@/pages/mine/index.vue'
  59. import {useChatStore} from '@/store/chatStore';
  60. import {useFriendStore} from '@/store/friendStore';
  61. import {useUserStore} from '@/store/userStore';
  62. import UserApi from '@/api/UserApi';
  63. import {onBackPress} from '@dcloudio/uni-app';
  64. import {useWsStore} from "@/store/WsStore";
  65. import {useImmunityStore} from '@/store/immunityStore'
  66. import {useSettingStore} from '@/store/settingStore'
  67. import {useGroupStore} from "@/store/groupStore";
  68. import MessageUtils from "@/utils/MessageUtils";
  69. //@ts-ignore
  70. const {proxy} = getCurrentInstance();
  71. const chatStore = useChatStore();
  72. const userStore = useUserStore();
  73. const friendStore = useFriendStore();
  74. const groupStore = useGroupStore();
  75. const wsStore = useWsStore();
  76. const pageCur = ref('chats');
  77. const backCount = ref(0);
  78. const navChange = (e: any) => {
  79. pageCur.value = e.currentTarget.dataset.cur
  80. }
  81. const waitCheckGroupCount = computed(()=>{
  82. const arr = [...groupStore.waitCheckMap.values()];
  83. if(arr && arr.length===0){
  84. return 0;
  85. }
  86. return arr.reduce((prev, curr)=>{
  87. return prev + curr;
  88. })
  89. })
  90. onBackPress(() => {
  91. backCount.value++;
  92. if (backCount.value > 1) {
  93. return false;
  94. } else {
  95. MessageUtils.message('再按一次返回登录界面')
  96. return true;
  97. }
  98. setTimeout(() => {
  99. backCount.value = 0;
  100. }, 2000)
  101. })
  102. //重置打开的聊天id,说明没有打开聊天窗口
  103. chatStore.setOpenChatId(null);
  104. onMounted(() => {
  105. UserApi.currentUser()
  106. .then((res) => {
  107. if (res && res.data) {
  108. userStore.setUser(res.data);
  109. //加载免打扰
  110. useImmunityStore().loadData()
  111. //加载设置
  112. useSettingStore().loadData()
  113. //加载聊天室
  114. useChatStore().reloadChats()
  115. .then(()=>{
  116. //初始化websocket
  117. console.log('初始化websocket')
  118. if(wsStore.wsRequest.socket?.readyState === 1){
  119. wsStore.checkStatus()
  120. }else {
  121. wsStore.close(true)
  122. wsStore.init()
  123. }
  124. })
  125. }
  126. })
  127. })
  128. </script>
  129. <style scoped lang="scss">
  130. .action {
  131. .iconfont {
  132. font-size: 44upx;
  133. line-height: 1.2;
  134. }
  135. }
  136. .box {
  137. flex-direction: column;
  138. height: 100%;
  139. display: flex;
  140. }
  141. .main {
  142. flex: 1;
  143. background-color: #f8f8f8;
  144. }
  145. .icon-liaotian {
  146. position: relative;
  147. }
  148. .cu-tag.badge {
  149. position: relative;
  150. margin-top: -48rpx;
  151. margin-left:-26rpx;
  152. }
  153. .tabbarIcon{
  154. pading:10rpx;
  155. width:56rpx;
  156. height:56rpx;
  157. }
  158. </style>