im-chat
This commit is contained in:
parent
7fb98309fb
commit
75caf13d8b
|
@ -173,3 +173,15 @@ export function endClass(id) {
|
|||
params: {id}
|
||||
})
|
||||
}
|
||||
/**
|
||||
* @description 获取课堂信息
|
||||
* @param {*} id
|
||||
* @returns
|
||||
*/
|
||||
export function getClassInfo(id) {
|
||||
return request({
|
||||
url: '/smarttalk/classReserv/selectById',
|
||||
method: 'get',
|
||||
params: {id}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ export class ImChat {
|
|||
// this.userSig = sig
|
||||
this.userID = userID
|
||||
window.test = this
|
||||
this.timGroupId = '@TGS#3CYWMK2ON' // 测试使用
|
||||
// this.timGroupId = '@TGS#3CYWMK2ON' // 测试使用
|
||||
if (isInit) return this.init()
|
||||
}
|
||||
// 设置配置
|
||||
|
@ -131,7 +131,6 @@ export class ImChat {
|
|||
} else {
|
||||
if (status == 1) { // 已登录
|
||||
console.log('已登录')
|
||||
this.setGroupMsgReceive()
|
||||
resolve({status, msg:'已登录'})
|
||||
} else if (status == 2) { // 登录中
|
||||
console.log('登录中')
|
||||
|
@ -188,10 +187,10 @@ export class ImChat {
|
|||
return this.timChat.TIMGroupCreate(option).then(res => {
|
||||
if (res && res.code == 0) {
|
||||
const timGroupId = res?.json_param?.create_group_result_groupid
|
||||
if (!!timGroupId){
|
||||
if (!!timGroupId && timGroupId != 'undefined'){
|
||||
this.setConsole('%c创建群组成功', timGroupId)
|
||||
this.timGroupId = timGroupId
|
||||
this.setGroupMsgReceive()
|
||||
// this.setGroupMsgReceive()
|
||||
}
|
||||
}
|
||||
return res
|
||||
|
@ -206,10 +205,12 @@ export class ImChat {
|
|||
})
|
||||
}
|
||||
// 设置群消息接收
|
||||
setGroupMsgReceive() {
|
||||
setGroupMsgReceive(timGroupId) {
|
||||
if (!this.timGroupId) this.timGroupId = timGroupId || ''
|
||||
if (!this.timGroupId) return console.log('timGroupId为空')
|
||||
return this.timChat.TIMMsgSetGroupReceiveMessageOpt({
|
||||
groupId: this.timGroupId,
|
||||
opt: TYPES.TIMReceiveMessageOpt.kTIMRecvMsgOpt_Not_Notify,
|
||||
opt: TYPES.TIMReceiveMessageOpt.kTIMRecvMsgOpt_Receive,
|
||||
data: '', // 用户自定义数据
|
||||
})
|
||||
}
|
||||
|
@ -225,6 +226,8 @@ export class ImChat {
|
|||
}
|
||||
// 发送消息
|
||||
sendMsg(conv_id, msg) {
|
||||
if (!conv_id) return console.log('conv_id为空')
|
||||
if (typeof msg == 'object') msg = JSON.stringify(msg)
|
||||
const option = {
|
||||
conv_id,
|
||||
conv_type: TYPES.TIMConvType.kTIMConv_Group,
|
||||
|
@ -240,12 +243,12 @@ export class ImChat {
|
|||
user_data: '', // 用户自定义数据
|
||||
// callback: (data) => {}
|
||||
}
|
||||
console.log('发送消息', option)
|
||||
return this.timChat.TIMMsgSendMessageV2(option)
|
||||
}
|
||||
// 发送关闭(下课)消息
|
||||
sendMsgClosed(){
|
||||
const msg = this.getMsgObj(MsgEnum.HEADS.MSG_closed, '下课', MsgEnum.TYPES.TEACHER)
|
||||
console.log('发送关闭消息', msg)
|
||||
return this.sendMsg(this.timGroupId, msg)
|
||||
}
|
||||
// 获取消息对象
|
||||
|
|
|
@ -58,7 +58,6 @@ const initImChat = async () => {
|
|||
const createGroup = async (groupName) => {
|
||||
if (!imChatObj.imChat) return
|
||||
await imChatObj.imChat.createGroup(groupName)
|
||||
// emits('change', {type:'createGroup', data: imChat.timGroupId})
|
||||
emits('change', 'createGroup', imChatObj.imChat.timGroupId)
|
||||
}
|
||||
// 退出
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
// 功能说明:electron 悬浮球
|
||||
import { onMounted, ref, reactive, watchEffect } from 'vue'
|
||||
import { useRoute } from 'vue-router';
|
||||
import { ElMessageBox, ElMessage } from 'element-plus'
|
||||
import { ElMessageBox, ElMessage, ElLoading } from 'element-plus'
|
||||
import * as classManageApi from '@/api/classManage'
|
||||
import logo from '@root/resources/icon.png' // logo
|
||||
import boardVue from './components/board.vue' // 画板-子组件
|
||||
|
@ -78,13 +78,26 @@ const btnList = [ // 工具栏按钮列表
|
|||
// === 页面加载完毕 ===
|
||||
onMounted(async() => {
|
||||
setTimeout(() => {
|
||||
getClassInfo() // 获取课堂详情 ex3
|
||||
resetStatus() // 开启重置状态-监听
|
||||
}, 200);
|
||||
})
|
||||
|
||||
|
||||
// ==== 方法 ===
|
||||
// const test = (e) => { console.log('test', e) }
|
||||
// 获取课堂信息
|
||||
const getClassInfo = async () => {
|
||||
const { data } = await classManageApi.getClassInfo(classObj.id)
|
||||
classObj.data = data
|
||||
if(!data.ex3 || data.ex3 == 'undefined') { // 无群直接创建
|
||||
await imChatRef.value.imChatObj.imChat.createGroup(data.className)
|
||||
const timGroupId = imChatRef.value.imChatObj.imChat.timGroupId
|
||||
classManageApi.startClass(classObj.id, timGroupId) // 开始上课
|
||||
} else { // 已创建群
|
||||
// console.log('已创建群: ', data.ex3)
|
||||
imChatRef.value.imChatObj.imChat.timGroupId = data.ex3
|
||||
// imChatRef.value.imChatObj.imChat.setGroupMsgReceive(data.ex3)
|
||||
}
|
||||
}
|
||||
// 切换tab-change
|
||||
const tabChange = (val) => {
|
||||
const bool = !toolStore.isPdfWin && !toolStore.showBoardAll
|
||||
|
@ -108,7 +121,8 @@ const mouseChange = (bool) => {
|
|||
// im-chat: 聊天事件 {type, data}
|
||||
const chatChange = (type, data) => {
|
||||
if (type == 'createGroup') { // 创建群-监听
|
||||
classManageApi.startClass(classObj.id, data)
|
||||
console.log('创建群:', data)
|
||||
!!data && classManageApi.startClass(classObj.id, data)
|
||||
} else if (type == 'msg') { // im-chat 消息监听
|
||||
if (!data) return // 没有msg数据
|
||||
const { msgKey:head, msgcontent:msg, senduserid:sendId, msgType } = data
|
||||
|
@ -167,18 +181,19 @@ const sideChange = async o => {
|
|||
}).then(async() => {
|
||||
await imChatRef.value?.imChatObj?.imChat?.sendMsgClosed() // 发送下课消息
|
||||
// const elMsg = ElMessage.warning({duration:0,message:'正在下课...'})
|
||||
// // 延迟2秒后关闭窗口,如果马上解散群,会导致群组不存在
|
||||
// setTimeout(async() => {
|
||||
// elMsg.close()
|
||||
// toolStore.isToolWin = false
|
||||
// await classManageApi.endClass(route.query.reservId)
|
||||
// await imChatRef.value?.deleteGroup() // 解散群
|
||||
// await imChatRef.value?.logout() // 退出im
|
||||
// ipcMsgSend('tool-sphere:close') // 关闭窗口
|
||||
// }, 2000);
|
||||
const elMsg = ElLoading.service({lock: true, text: '正在下课...', background: 'rgba(0, 0, 0, 0.7)'})
|
||||
// 延迟2秒后关闭窗口,如果马上解散群,会导致群组不存在
|
||||
setTimeout(async() => {
|
||||
elMsg.close()
|
||||
toolStore.isToolWin = false
|
||||
await classManageApi.endClass(route.query.reservId)
|
||||
await imChatRef.value?.deleteGroup() // 解散群
|
||||
await imChatRef.value?.logout() // 退出im
|
||||
ipcMsgSend('tool-sphere:close') // 关闭窗口
|
||||
}, 2000);
|
||||
|
||||
isOver.value = false
|
||||
setIgnore(true) // 开启窗口鼠标-穿透
|
||||
// isOver.value = false
|
||||
// setIgnore(true) // 开启窗口鼠标-穿透
|
||||
}).catch(() => {
|
||||
isOver.value = false
|
||||
setIgnore(true) // 开启窗口鼠标-穿透
|
||||
|
|
Loading…
Reference in New Issue