110 lines
2.9 KiB
Vue
110 lines
2.9 KiB
Vue
<!-- <template>
|
|
<div>
|
|
<button @click="openConversationList">打开会话列表</button>
|
|
<button @click="openContact">打开联系人</button>
|
|
<button @click="login">登录</button>
|
|
<button @click="enterRoom">进入聊天室</button>
|
|
<button @click="back">退出</button>
|
|
<button @click="sendMessage">发送消息</button>
|
|
<button @click="destroy">销毁实例</button>
|
|
</div>
|
|
</template>
|
|
<script>
|
|
|
|
import { useIMStore } from "@/store/tim";
|
|
export default {
|
|
methods: {
|
|
// 打开会话列表
|
|
openConversationList() {
|
|
uni.navigateTo({
|
|
url: "/TUIKit/components/TUIConversation/index",
|
|
});
|
|
},
|
|
// 打开联系人
|
|
openContact() {
|
|
uni.navigateTo({
|
|
url: "/TUIKit/components/TUIContact/index",
|
|
});
|
|
},
|
|
back() {
|
|
const { imLogout } = useImStore();
|
|
imLogout();
|
|
},
|
|
async login() {
|
|
const { imLogin } = useImStore();
|
|
const SDKAppID = 1600072268;
|
|
const secretKey =
|
|
"26b5128f10e61038e0197a1c3269499c0196b5e682fea798de2f3b30de044fbf";
|
|
const userID = "test-2";
|
|
const res = genTestUserSig({
|
|
SDKAppID,
|
|
secretKey,
|
|
userID,
|
|
});
|
|
const loginInfo = {
|
|
SDKAppID,
|
|
userID,
|
|
userSig: res.userSig,
|
|
useUploadPlugin: true,
|
|
framework: `vue3`,
|
|
};
|
|
TUILogin.login(loginInfo)
|
|
.then((res) => {})
|
|
.catch((err) => {
|
|
console.log("=======>err", err);
|
|
});
|
|
let isReady = TUIChatEngine.isReady();
|
|
if (isReady) {
|
|
console.log("登录成功");
|
|
} else {
|
|
console.log("登录失败");
|
|
}
|
|
},
|
|
toHome() {
|
|
// const { enterChatRoom } = useImStore();
|
|
// enterChatRoom("test-user4");
|
|
// TUIUserService.switchUserStatus({
|
|
// displayOnlineStatus: true,
|
|
// });
|
|
TUIConversationService.switchConversation("C2Ctest-user3");
|
|
|
|
// uni.navigateTo({
|
|
// url: "/pages/TUIKit/components/TUIChat/index",
|
|
// });
|
|
},
|
|
|
|
async enterRoom() {
|
|
const conversationID = "C2C30117";
|
|
const userId = "Hd2aivfy8771741756216432" || Date.now().toString();
|
|
const imStore = useIMStore();
|
|
const res = await imStore.login(userId);
|
|
if (res) {
|
|
uni.navigateTo({
|
|
url: `/pages/chat/index?conversationID=${conversationID}`,
|
|
});
|
|
}
|
|
},
|
|
|
|
sendMessage() {
|
|
TUIChatService.sendCustomMessage({
|
|
to: "test-user4",
|
|
conversationType: "C2C",
|
|
payload: {
|
|
data: "STARTCONSULT", // 用于标识该消息是骰子类型消息
|
|
description: "开始咨询", // 获取骰子点数
|
|
extension: "",
|
|
},
|
|
});
|
|
},
|
|
destroy() {
|
|
TUIChatEngine.destroy();
|
|
let isReady = TUIChatEngine.isReady();
|
|
if (isReady) {
|
|
console.log("销毁失败");
|
|
} else {
|
|
console.log("销毁成功");
|
|
}
|
|
},
|
|
},
|
|
};
|
|
</script> --> |