Browse Source

修复聊天异常

zhengnaiwen_citu 6 months ago
parent
commit
2c48bf77a9

+ 3 - 0
hooks/useDictionaries.js

@@ -12,6 +12,9 @@ import {
 
 // const setDict = (type, val, cacheTime = 7200) => {
 const setDict = (type, val) => {
+  if (!val) {
+    return
+  }
   if (type === 'areaTreeData') {
     const obj = val.data.find(e => e.name === '中国')
     val.data = obj?.children ? obj.children.map(e =>{

+ 27 - 48
hooks/useIM.js

@@ -214,9 +214,6 @@ export const useIM = () => {
   async function resetConfig () {
     try {
       const { uid, wssUrl, token } = await getKey()
-      if (!wssUrl) {
-        return
-      }
       IM.setUid(uid)
       // 单机模式可以直接设置地址
       WKSDK.shared().config.addr = 'wss://' + wssUrl// 默认端口为5200 + wsUrl 
@@ -227,6 +224,7 @@ export const useIM = () => {
       console.log(error)
     }
   }
+
   return {
     resetConfig
   }
@@ -330,26 +328,31 @@ async function syncConversation () {
 
 // 发起聊天
 export async function initChart (userId, enterpriseId) {
-  const channel = ref()
-  // const list = ref([])
-  const query = {
-    userId,
-    enterpriseId
-  }
-  // 创建聊天频道
-  const { data } = await getChatKey(query)
-  const { uid } = data
-  const _channel = new Channel(uid, ChannelTypePerson)
-  channel.value = _channel
-  const conversation = WKSDK.shared().conversationManager.findConversation(_channel)
-  if(!conversation) {
-    // 如果最近会话不存在,则创建一个空的会话
-    WKSDK.shared().conversationManager.createEmptyConversation(_channel)
-  }
-  const res = await getMoreMessages(1, _channel)
-  return {
-    channel,
-    ...res
+  try {
+    const channel = ref()
+    // const list = ref([])
+    const query = {
+      userId,
+      enterpriseId
+    }
+    // 创建聊天频道
+    const { data } = await getChatKey(query)
+    console.log(data, 'data')
+    const { uid } = data
+    const _channel = new Channel(uid, ChannelTypePerson)
+    channel.value = _channel
+    const conversation = WKSDK.shared().conversationManager.findConversation(_channel)
+    if(!conversation) {
+      // 如果最近会话不存在,则创建一个空的会话
+      WKSDK.shared().conversationManager.createEmptyConversation(_channel)
+    }
+    const res = await getMoreMessages(1, _channel)
+    return {
+      channel,
+      ...res
+    }
+  } catch (error) {
+    console.log(error)
   }
 }
 
@@ -382,32 +385,8 @@ export function send (text, _channel, type) {
     WKSDK.shared().chatManager.send(_text, _channel)
     return
   }
-  // if (type === 101) {
-  //   _text = new ObjectContent(text)
-  //   WKSDK.shared().chatManager.send(_text, _channel)
-  //   // console.log(_text)
-  //   return
-  // }
-  // if (type === 102) {
-  //   _text = new ObjectContent2(text)
-  //   WKSDK.shared().chatManager.send(_text, _channel)
-  //   // console.log(_text)
-  //   return
-  // }
-  // // 求职者拒绝面试邀请
-  // if (type === 103) {
-  //   _text = new ObjectContent3(text)
-  //   WKSDK.shared().chatManager.send(_text, _channel)
-  //   return
-  // }
-  // // 求职者接受面试邀请
-  // if (type === 104) {
-  //   _text = new ObjectContent4(text)
-  //   WKSDK.shared().chatManager.send(_text, _channel)
-  //   return
-  // }
   _text = new MessageText(text)
-  // console.log(_text)
+  console.log(WKSDK.shared().chatManager, 111111)
   WKSDK.shared().chatManager.send(_text, _channel)
 }
 

+ 1 - 1
pages/index/communicate.vue

@@ -50,7 +50,7 @@ import layoutPage from '@/layout'
 // import { getAccessToken } from '@/utils/request'
 // import { showAuthModal } from '@/hooks/useModal'
 import { getConversationSync } from '@/api/common'
-import { onShow, onLoad } from '@dcloudio/uni-app'
+import { onShow, onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
 import { getUserAvatar } from '@/utils/avatar'
 import { timesTampChange } from '@/utils/date'
 import { userStore } from '@/store/user'

+ 1 - 1
pages/index/position.vue

@@ -205,7 +205,7 @@ const loadingMore = () => { // 加载更多
   z-index: 1;
   position: sticky;
   box-shadow: 0px 10rpx 12rpx 0px rgba(195, 195, 195, .25);
-  top: 100rpx;
+  top: 120rpx;
 }
 .px-0 { padding-left: 0 !important; padding-right: 0 !important; }
 .pb-10 {

+ 20 - 2
pagesA/chart/index.vue

@@ -148,16 +148,20 @@
     <view class="box-bottom">
       <view class="box-bottom-tool" style="display: flex; justify-content: space-between;">
         <uni-tag :text="isSendResume ? '简历已投递' : '发送简历'" :disabled="isSendResume" type="success" @tap="handleFindResume"/>
-        <uni-tag text="发 送" type="success" @click="handleSend"/>
+        <!-- <uni-tag text="发 送" type="success" @tap="handleSend"/> -->
       </view>
       
-      <view class="d-flex align-end">
+      <view class="d-flex align-end textBox">
         <textarea
           v-model="inputValue"
+          :cursor-spacing="25"
+          :show-confirm-bar="false"
+          :disable-default-padding="true"
           confirm-type="send"
           auto-height
           @confirm="handleSend"
         />
+        <text class="submitBtn" @tap="handleSend">发 送</text>
       </view>
     </view>
     <uni-popup ref="popup" background-color="#fff">
@@ -779,6 +783,9 @@ onLoad(async (options) => {
     &-tool {
       margin-bottom: 40rpx;
     }
+    .textBox {
+      align-items: flex-end;
+    }
     textarea {
       border-radius: 10rpx;
       width: 100%;
@@ -788,6 +795,17 @@ onLoad(async (options) => {
       box-sizing: border-box;
       background: #FFF;
     }
+    .submitBtn {
+      width: 140rpx;
+      line-height: 80rpx;
+      height: 80rpx;
+      font-size: 28rpx;
+      background: #18bc37;
+      color: #FFF;
+      margin-left: 20rpx;
+      text-align: center;
+      border-radius: 10rpx;
+    }
   }
   .popup-title {
     padding: 30rpx 20rpx;

+ 4 - 0
pagesB/positionDetail/index.vue

@@ -379,6 +379,10 @@ const popupClose = () => {
 
 // 发起聊天
 async function handleSend () {
+  if (!getAccessToken()) {
+    showAuthModal()
+    return
+  }
   const userId = info.value.contact.userId
   const enterpriseId = info.value.contact.enterpriseId
   const textObj = {