From 2115d2c76adeb9e59e1b28e6493789499b2c07e1 Mon Sep 17 00:00:00 2001 From: zdg Date: Tue, 15 Oct 2024 15:33:07 +0800 Subject: [PATCH] =?UTF-8?q?apt=20ppt=20=E4=B8=8A=E4=B8=8B=E8=AF=BE?= =?UTF-8?q?=E3=80=81=E7=BB=A7=E7=BB=AD=E4=B8=8A=E8=AF=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/layout/components/Header.vue | 3 + src/renderer/src/layout/index.vue | 3 + src/renderer/src/plugins/imChat/index.js | 16 ++- src/renderer/src/utils/chat.js | 98 +++++++++++++++++ .../src/views/classManage/classReserv.vue | 6 + .../src/views/classManage/reserv-item-apt.vue | 47 ++------ .../src/views/classManage/reserv-item.vue | 18 +-- .../views/prepare/container/class-start.vue | 28 +++-- .../views/prepare/container/kj-list-item.vue | 104 +++++++++++------- src/renderer/src/views/prepare/index.vue | 79 +++++++++++-- src/renderer/src/views/tool/sphere.vue | 2 +- 11 files changed, 295 insertions(+), 109 deletions(-) create mode 100644 src/renderer/src/utils/chat.js diff --git a/src/renderer/src/layout/components/Header.vue b/src/renderer/src/layout/components/Header.vue index 2d813af..26ff23e 100644 --- a/src/renderer/src/layout/components/Header.vue +++ b/src/renderer/src/layout/components/Header.vue @@ -80,6 +80,8 @@ import { updateUserInfo } from '@/api/system/user' import logoIco from '@/assets/images/logo.png' import { listEvaluation } from '@/api/classManage/index' import { sessionStore } from '@/utils/store' +import Chat from '@/utils/chat' // im 登录初始化 +if (!Chat.imChat) Chat.init() let homeTitle = ref(import.meta.env.VITE_APP_TITLE) const { ipcRenderer } = window.electron || {} @@ -143,6 +145,7 @@ function handleCommand(command) { break case 'logout': logout() + Chat?.logout() // im 退出登录 break default: break diff --git a/src/renderer/src/layout/index.vue b/src/renderer/src/layout/index.vue index 09b8df4..c09647d 100644 --- a/src/renderer/src/layout/index.vue +++ b/src/renderer/src/layout/index.vue @@ -19,8 +19,11 @@ import AppMain from './components/AppMain.vue' import Uploader from './components/Uploader.vue' import AiChart from '@/components/ai-chart/index.vue' import uploaderState from '@/store/modules/uploader' +// import Chat from '@/utils/chat' let uploaderStore = ref(uploaderState()) +// window.test = Chat +// Chat.init() diff --git a/src/renderer/src/plugins/imChat/index.js b/src/renderer/src/plugins/imChat/index.js index 6cf8934..83f007f 100644 --- a/src/renderer/src/plugins/imChat/index.js +++ b/src/renderer/src/plugins/imChat/index.js @@ -70,7 +70,10 @@ export class ImChat { // 日志监听 this.timChat.TIMSetLogCallback({ callback: data => { - this.setConsole('%cchat-log ', data[1]) + const [type, log] = data + if (type == log_level) { // 打印对应日志 + this.setConsole('%cchat-log ', log) + } }, user_data: '' }) @@ -86,7 +89,7 @@ export class ImChat { if (code == 0) { // 初始化成功 this.setConsole('%cim-chat: init', '初始化成功') this.status.isConnect = true - this.setConfig() // 设置日志级别 + // this.setConfig() // 设置日志级别 resolve(this) } else { // 失败:具体请看code console.error('[im-chat]:初始化失败', code) @@ -227,10 +230,11 @@ export class ImChat { }) } // 删除群组 - deleteGroup() { - if (!this.timGroupId) return + deleteGroup(timGroupId) { + const groupId = timGroupId || this.timGroupId + if (!groupId) return return this.timChat.TIMGroupDelete({ - groupId: this.timGroupId, + groupId, data: '', // 用户自定义数据 }) } @@ -249,7 +253,7 @@ export class ImChat { } // 获取群组列表 getGroupList() { - return this.timChat.getGroupList().then(res => { + return this.timChat.TIMGroupGetJoinedGroupList().then(res => { console.log('获取群组列表', res) return res }).catch(error => { diff --git a/src/renderer/src/utils/chat.js b/src/renderer/src/utils/chat.js new file mode 100644 index 0000000..44d962f --- /dev/null +++ b/src/renderer/src/utils/chat.js @@ -0,0 +1,98 @@ +/** +* 实现单例模式 +*/ +import useUserStore from '@/store/modules/user' +import { ImChat } from '@/plugins/imChat' +import * as http from '@/api/apiService' // 自定义api service + +export class Chat { + instance = null; + sdkAppId = 0; // 应用id + sign = ''; // 签名 + imUserId = ''; // 用户id + imChat = null; // IM实例 + + constructor() { + if (!Chat.instance) { // 存在的时候 + Chat.instance = this; + } + return Chat.instance; + } + /** + * 初始化 获取IM签名 + * @param {*} isInit : 是否初始化IM + * @param {*} isLogin : 是否登录IM + * @param {*} callback: 监听消息回调函数 + * @returns Promise + */ + async init(isInit = true, isLogin = true, callback) { + // 特殊处理,只传1个参数且为函数,则默认为callback,isInit和isLogin默认为true + if (typeof isInit == 'function'){ + callback = isInit + isInit = true + isLogin = true + } + const userStore = useUserStore() + const { timuserid: imUserId } = userStore.user + // 获取腾讯云签名 + const res = await http.imChat.getTxCloudSign({imUserId}) + if (res && res.code == 200) { + const { sdkAppId, sign } = res.data + this.sdkAppId = sdkAppId + this.sign = sign + this.imUserId = imUserId + // 初始化IM + if (isInit) return await this.initIM(isLogin, callback) + } + } + // 初始化IM + async initIM(isLogin, callback) { + const imChat = new ImChat(this.sdkAppId, this.sign, this.imUserId) + this.imChat = imChat + await imChat.init() // 初始化IM + callback && this.listenMsg(callback) // 监听消息 + if(isLogin) await imChat.login() // 登录IM + return imChat + } + // 监听消息 + async listenMsg(callback) { + if (!callback) return + if (!this.imChat) return + await this.imChat?.watch(msg => callback(msg)) + } + // 解散群 + async dismissGroup(groupId) { + if (!this.imChat) return + await this.imChat?.deleteGroup(groupId) + } + // 退出登录 + async logout() { + if (!this.imChat) return + await this.imChat?.logout() + imChat = null + this.imChat = null + } + // 发群消息 + async sendMsg(conv_id, msg) { + if (!this.imChat) return + await this.imChat?.sendMsg(conv_id, msg) + } + // 发群消息 + async sendMsgGroup(msg, head, type) { + if (!this.imChat) return + this.imChat?.sendMsgGroup(msg, head, type) + } + // 发群消息 + async sendMsgGroupId(groupId, msg, head, type) { + if (!this.imChat) return + const msgObj = this.imChat?.getMsgObj(head, msg, type) + this.imChat?.sendMsg(groupId, msgObj) + } + // 获取群列表 + async getGroupList() { + if (!this.imChat) return + return await this.imChat?.getGroupList() + } +} + +export default new Chat() \ No newline at end of file diff --git a/src/renderer/src/views/classManage/classReserv.vue b/src/renderer/src/views/classManage/classReserv.vue index b5c6e53..ccb539c 100644 --- a/src/renderer/src/views/classManage/classReserv.vue +++ b/src/renderer/src/views/classManage/classReserv.vue @@ -11,6 +11,7 @@ v-if="item.bookImg" @open-edit="reservDialog.openDialog(item)" @delete-reserv="deleteReserv(item)" + @change="(...o) => emit('change', ...o)" > @@ -34,6 +36,10 @@ import Reserv from '@/views/prepare/container/reserv.vue' import { useToolState } from '@/store/modules/tool' import useUserStore from '@/store/modules/user' import ReservItemApt from '@/views/classManage/reserv-item-apt.vue' +// import Chat from '@/utils/chat' // im 登录初始化 +// if (!Chat.imChat) Chat.init() + +const emit = defineEmits(['change']) const reservDialog = ref(null) const tabOptions = ref(['进行中', '已结束']) const tabActive = ref('进行中') diff --git a/src/renderer/src/views/classManage/reserv-item-apt.vue b/src/renderer/src/views/classManage/reserv-item-apt.vue index 879b406..57f2596 100644 --- a/src/renderer/src/views/classManage/reserv-item-apt.vue +++ b/src/renderer/src/views/classManage/reserv-item-apt.vue @@ -7,14 +7,14 @@ {{item.caption}}
- 已结束 + 已结束 上课中 继续上课 - 下课下课{{ loading?'中...':'' }}
@@ -25,13 +25,14 @@