|
@@ -3,7 +3,8 @@ import {
|
|
|
YeIMUniSDKDefines
|
|
|
} from '@/uni_modules/wzJun1-YeIM-Uni-SDK/js_sdk/yeim-uni-sdk.min.js'
|
|
|
import {
|
|
|
- login
|
|
|
+ login,
|
|
|
+ sendSystem
|
|
|
} from '@/request/api/chat.js'
|
|
|
import md5 from '@/js_sdk/js-md5/build/md5.min.js';
|
|
|
import config from "@/config";
|
|
@@ -20,6 +21,7 @@ const connect = success => {
|
|
|
token: uni.getStorageSync('chatToken'),
|
|
|
success: (response) => {
|
|
|
if (response.code === 200) {
|
|
|
+ $chat.listenerList();
|
|
|
if (success) success();
|
|
|
}
|
|
|
},
|
|
@@ -42,12 +44,12 @@ const logins = () => {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
-export default {
|
|
|
+const $chat = {
|
|
|
init() {
|
|
|
//初始化YeIMUniSDK
|
|
|
uni.$YeIMUniSDKDefines = YeIMUniSDKDefines;
|
|
|
uni.$YeIM = YeIMUniSDK.init({
|
|
|
- baseURL: config.imBaseUrl, // YeIMServer http url (如无特殊需求,服务端启动后仅需修改ip或者域名即可)
|
|
|
+ baseURL: config.baseUrl + '/im', // YeIMServer http url (如无特殊需求,服务端启动后仅需修改ip或者域名即可)
|
|
|
socketURL: config.socketURL, // YeIMServer socket url(如无特殊需求,服务端启动后仅需修改ip或者域名即可)
|
|
|
/**
|
|
|
* 日志等级
|
|
@@ -103,24 +105,25 @@ export default {
|
|
|
src: res.tempFilePaths[0],
|
|
|
success: image => {
|
|
|
//创建图片消息
|
|
|
- let message = YeIMUniSDK.getInstance().createImageMessage({
|
|
|
- toId: userId, //接收者用户ID字符串
|
|
|
- conversationType: YeIMUniSDKDefines
|
|
|
- .CONVERSATION_TYPE
|
|
|
- .PRIVATE, //会话类型:私聊
|
|
|
- body: {
|
|
|
- file: {
|
|
|
- tempFilePath: res.tempFilePaths[
|
|
|
- 0], //本地图片临时路径
|
|
|
- width: image.width, //图片宽度
|
|
|
- height: image.height //图片高度
|
|
|
+ let message = YeIMUniSDK.getInstance()
|
|
|
+ .createImageMessage({
|
|
|
+ toId: userId, //接收者用户ID字符串
|
|
|
+ conversationType: YeIMUniSDKDefines
|
|
|
+ .CONVERSATION_TYPE
|
|
|
+ .PRIVATE, //会话类型:私聊
|
|
|
+ body: {
|
|
|
+ file: {
|
|
|
+ tempFilePath: res.tempFilePaths[
|
|
|
+ 0], //本地图片临时路径
|
|
|
+ width: image.width, //图片宽度
|
|
|
+ height: image.height //图片高度
|
|
|
+ }
|
|
|
+ },
|
|
|
+ extra: "",
|
|
|
+ onProgress: (progress) => {
|
|
|
+ console.log(progress);
|
|
|
}
|
|
|
- },
|
|
|
- extra: "",
|
|
|
- onProgress: (progress) => {
|
|
|
- console.log(progress);
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
//发送消息
|
|
|
YeIMUniSDK.getInstance().sendMessage({
|
|
|
message: message,
|
|
@@ -176,20 +179,6 @@ export default {
|
|
|
//监听会话列表更新
|
|
|
YeIMUniSDK.getInstance().addEventListener(YeIMUniSDKDefines.EVENT.CONVERSATION_LIST_CHANGED, (
|
|
|
list) => {
|
|
|
- let badge = 0;
|
|
|
- for (let i = 0; i < list.length; i++) {
|
|
|
- badge += list[i].unread
|
|
|
- }
|
|
|
- if (!badge) {
|
|
|
- uni.removeTabBarBadge({
|
|
|
- index: 1
|
|
|
- })
|
|
|
- } else {
|
|
|
- uni.setTabBarBadge({
|
|
|
- index: 1,
|
|
|
- text: String(badge)
|
|
|
- })
|
|
|
- }
|
|
|
uni.$emit('changeChatList', list);
|
|
|
});
|
|
|
})
|
|
@@ -197,5 +186,37 @@ export default {
|
|
|
clearConversationUnread(conversationId) {
|
|
|
//清除指定会话未读数,并给对方发送已读回执
|
|
|
YeIMUniSDK.getInstance().clearConversationUnread(conversationId);
|
|
|
+ },
|
|
|
+ sendSystemMessage(success) {
|
|
|
+ let timestamp = (new Date()).getTime() + 86400 * 1000; //1000天后过期
|
|
|
+ let sign = md5('system' + timestamp + "50abd47112ebe8c5a73f4694c96a49ce");
|
|
|
+ login({
|
|
|
+ userId: 'system',
|
|
|
+ timestamp: timestamp,
|
|
|
+ sign: sign
|
|
|
+ }).then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ uni.setStorageSync('systemChatToken', res.data.token);
|
|
|
+ sendSystem({
|
|
|
+ body: {
|
|
|
+ text: "2"
|
|
|
+ },
|
|
|
+ conversationId: "4",
|
|
|
+ conversationType: "private",
|
|
|
+ extra: "",
|
|
|
+ from: 'system',
|
|
|
+ fromUserInfo: {},
|
|
|
+ isDeleted: 0,
|
|
|
+ isRead: 0,
|
|
|
+ isRevoke: 0,
|
|
|
+ status: "unSend",
|
|
|
+ time: new Date().getTime(),
|
|
|
+ to: 1,
|
|
|
+ type: "text",
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
+export default $chat;
|