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