zdg #144
|
@ -10,7 +10,7 @@ export class ApiService {
|
||||||
static publicHttp(url, data, method, option = {}, type) {
|
static publicHttp(url, data, method, option = {}, type) {
|
||||||
method = method || 'get' // 默认GET
|
method = method || 'get' // 默认GET
|
||||||
const config = { url, method }
|
const config = { url, method }
|
||||||
if (!!data) basic[method=='get'?'params':'data'] = data
|
if (!!data) config[method=='get'?'params':'data'] = data
|
||||||
if (!!option) Object.assign(config, option)
|
if (!!option) Object.assign(config, option)
|
||||||
// 特殊格式处理
|
// 特殊格式处理
|
||||||
if (type == 'file') config.headers = { 'Content-Type': 'multipart/form-data' }
|
if (type == 'file') config.headers = { 'Content-Type': 'multipart/form-data' }
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
* @date 2023-07-03
|
* @date 2023-07-03
|
||||||
*/
|
*/
|
||||||
// const TimRender = require('im_electron_sdk/dist/render')
|
// const TimRender = require('im_electron_sdk/dist/render')
|
||||||
import * as TYPES from './enumbers'
|
import * as TYPES from './enumbers' // sdk相关枚举
|
||||||
|
import MsgEnum from './msgEnum' // 消息相关枚举(自定义)
|
||||||
const API = window.api
|
const API = window.api
|
||||||
// TIM生成签名
|
// TIM生成签名
|
||||||
// import * as GenerateUserSig from './userSig' // 引入签名生成器
|
// import * as GenerateUserSig from './userSig' // 引入签名生成器
|
||||||
|
@ -31,11 +32,12 @@ export class ImChat {
|
||||||
|
|
||||||
constructor(SDKAppID, userSig, userID, isInit) {
|
constructor(SDKAppID, userSig, userID, isInit) {
|
||||||
this.SDKAppID = SDKAppID
|
this.SDKAppID = SDKAppID
|
||||||
// this.userSig = userSig
|
this.userSig = userSig
|
||||||
const sig = 'eJwtjN0KgjAYQN9l16Vzcz8I3RhE9J*JV94IW-ZV6nASWfTurfTynAPnjdLNyXvoFkWIeBhN-gxK1x2cYdCMTQnlYmxW3QpjQKEo4BhjGgrKh6KfBlrtPGOMuDTYDqqfE26BWUjEeIHSrW1cL-SulHd5KI7zxDbpdh1cX0nuX7JK7HtroNerZhnnPpYz9PkCe5Mx1w__'
|
// const sig = 'eJwtjN0KgjAYQN9l16Vzcz8I3RhE9J*JV94IW-ZV6nASWfTurfTynAPnjdLNyXvoFkWIeBhN-gxK1x2cYdCMTQnlYmxW3QpjQKEo4BhjGgrKh6KfBlrtPGOMuDTYDqqfE26BWUjEeIHSrW1cL-SulHd5KI7zxDbpdh1cX0nuX7JK7HtroNerZhnnPpYz9PkCe5Mx1w__'
|
||||||
this.userSig = sig
|
// this.userSig = sig
|
||||||
this.userID = userID
|
this.userID = userID
|
||||||
window.test = this
|
window.test = this
|
||||||
|
this.timGroupId = '@TGS#3CYWMK2ON' // 测试使用
|
||||||
if (isInit) return this.init()
|
if (isInit) return this.init()
|
||||||
}
|
}
|
||||||
// 设置配置
|
// 设置配置
|
||||||
|
@ -60,7 +62,8 @@ export class ImChat {
|
||||||
// 日志监听
|
// 日志监听
|
||||||
this.timChat.TIMSetLogCallback({
|
this.timChat.TIMSetLogCallback({
|
||||||
callback: data => {
|
callback: data => {
|
||||||
console.log('[im-chat]:', data[1])
|
// console.log('[im-chat]:', data[1])
|
||||||
|
this.setConsole('%cchat-log ', data[1])
|
||||||
},
|
},
|
||||||
user_data: ''
|
user_data: ''
|
||||||
})
|
})
|
||||||
|
@ -91,8 +94,20 @@ export class ImChat {
|
||||||
}
|
}
|
||||||
// 监听
|
// 监听
|
||||||
watch(callback) {
|
watch(callback) {
|
||||||
|
// 先移除监听
|
||||||
|
this.timChat.TIMRemoveRecvNewMsgCallback()
|
||||||
|
// 消息监听
|
||||||
this.timChat.TIMAddRecvNewMsgCallback({
|
this.timChat.TIMAddRecvNewMsgCallback({
|
||||||
callback, user_data: {type:'msg'}
|
callback, user_data: this.toStr('msg')
|
||||||
|
})
|
||||||
|
// 群消息监听
|
||||||
|
// 群组系统消息事件包括 加入群、退出群、踢出群、设置管理员、取消管理员、群资料变更、群成员资料变更。此消息是针对所有群组成员下发的
|
||||||
|
this.timChat.TIMSetGroupTipsEventCallback({
|
||||||
|
// callback, user_data: this.toStr('msg-group')
|
||||||
|
callback: (data) => {
|
||||||
|
// console.log('群消息', group_tips_event)
|
||||||
|
this.setConsole('%c群消息', data)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 登录
|
// 登录
|
||||||
|
@ -104,18 +119,19 @@ export class ImChat {
|
||||||
}
|
}
|
||||||
// 获取登录状态
|
// 获取登录状态
|
||||||
// [1,2,3,4] | [已登陆,登录中,未登录,登出中]
|
// [1,2,3,4] | [已登陆,登录中,未登录,登出中]
|
||||||
console.log('登录', this)
|
// console.log('登录', this)
|
||||||
const status = await this.timChat.TIMGetLoginStatus()
|
const status = await this.timChat.TIMGetLoginStatus()
|
||||||
if (status == 3) { // 未登录
|
if (status == 3) { // 未登录
|
||||||
const res = await this.timChat.TIMLogin(option)
|
const res = await this.timChat.TIMLogin(option)
|
||||||
if (res && res.code == 0) {
|
if (res && res.code == 0) {
|
||||||
console.log('登录成功', res)
|
// console.log('登录成功', res)
|
||||||
this.status.isLogin = true
|
this.status.isLogin = true
|
||||||
resolve({status:0, msg:'登录成功', data:res})
|
resolve({status:0, msg:'登录成功', data:res})
|
||||||
} else reject(res)
|
} else reject(res)
|
||||||
} 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('登录中')
|
||||||
|
@ -172,7 +188,11 @@ 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) this.timGroupId = timGroupId
|
if (!!timGroupId){
|
||||||
|
this.setConsole('%c创建群组成功', timGroupId)
|
||||||
|
this.timGroupId = timGroupId
|
||||||
|
this.setGroupMsgReceive()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
|
@ -185,6 +205,14 @@ export class ImChat {
|
||||||
data: '', // 用户自定义数据
|
data: '', // 用户自定义数据
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// 设置群消息接收
|
||||||
|
setGroupMsgReceive() {
|
||||||
|
return this.timChat.TIMMsgSetGroupReceiveMessageOpt({
|
||||||
|
groupId: this.timGroupId,
|
||||||
|
opt: TYPES.TIMReceiveMessageOpt.kTIMRecvMsgOpt_Not_Notify,
|
||||||
|
data: '', // 用户自定义数据
|
||||||
|
})
|
||||||
|
}
|
||||||
// 获取群组列表
|
// 获取群组列表
|
||||||
getGroupList() {
|
getGroupList() {
|
||||||
return this.timChat.getGroupList().then(res => {
|
return this.timChat.getGroupList().then(res => {
|
||||||
|
@ -195,4 +223,54 @@ export class ImChat {
|
||||||
return error
|
return error
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// 发送消息
|
||||||
|
sendMsg(conv_id, msg) {
|
||||||
|
const option = {
|
||||||
|
conv_id,
|
||||||
|
conv_type: TYPES.TIMConvType.kTIMConv_Group,
|
||||||
|
params: {
|
||||||
|
message_elem_array: [{
|
||||||
|
elem_type: TYPES.TIMElemType.kTIMElem_Text,
|
||||||
|
text_elem_content: msg
|
||||||
|
}],
|
||||||
|
// message_conv_id: conv_id,
|
||||||
|
// message_conv_type: TYPES.TIMConvType.kTIMConv_Group,
|
||||||
|
// message_sender: this.userID
|
||||||
|
},
|
||||||
|
user_data: '', // 用户自定义数据
|
||||||
|
// callback: (data) => {}
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
// 获取消息对象
|
||||||
|
getMsgObj(msgHead, msg, type, sender, option={}) {
|
||||||
|
if (!msgHead) throw new Error('msgHead is required')
|
||||||
|
if (!msg) throw new Error('msg is required')
|
||||||
|
if (typeof msg === 'object') msg = JSON.stringify(msg)
|
||||||
|
return {
|
||||||
|
msgKey: msgHead,
|
||||||
|
msgcontent: msg,
|
||||||
|
msgType: type ?? MsgEnum.TYPES.STUDENT, // 默认为学生
|
||||||
|
senduserid: sender ?? this.userID,
|
||||||
|
...option
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置控制台样式
|
||||||
|
setConsole(hearStr,...args) {
|
||||||
|
const css = 'color: #fff;background-color:#2ccb92;padding:3px 5px;border-radius:3px;'
|
||||||
|
const time = new Date().toLocaleTimeString()
|
||||||
|
if (!hearStr) hearStr = '%c' + time
|
||||||
|
console.log(hearStr, css, ...args)
|
||||||
|
}
|
||||||
|
// 获取数据字符串
|
||||||
|
toStr = (data) => {
|
||||||
|
if (typeof data === 'string') data = {type: data}
|
||||||
|
return JSON.stringify(data)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,135 @@
|
||||||
|
/**
|
||||||
|
* @description 消息枚举
|
||||||
|
* @author zdg
|
||||||
|
* @date 2021-07-05 14:07:01
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class MsgEnum {
|
||||||
|
/**
|
||||||
|
* @description: 消息类型
|
||||||
|
*
|
||||||
|
* | 名称 | 含义 | 值(enum) |
|
||||||
|
* | ---- | ---- | ---- |
|
||||||
|
* | SYSTEM | 系统消息 | system |
|
||||||
|
* | TEACHER | 老师消息 | teacher |
|
||||||
|
* | STUDENT | 学生消息 | student |
|
||||||
|
* | NOTICE | 通知消息 | notice |
|
||||||
|
*/
|
||||||
|
static TYPES = {
|
||||||
|
/** @desc: 系统消息 */
|
||||||
|
SYSTEM: 'system',
|
||||||
|
/** @desc: 老师消息 */
|
||||||
|
TEACHER: 'teacher',
|
||||||
|
/** @desc: 学生消息 */
|
||||||
|
STUDENT: 'student',
|
||||||
|
/** @desc: 通知消息 */
|
||||||
|
NOTICE: 'notice'
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @description: 消息头-类型
|
||||||
|
*
|
||||||
|
* | 名称 | 含义 | 值(enum) |
|
||||||
|
* | ---- | ---- | ---- |
|
||||||
|
* | --- | 以下为旧定义-消息头 | --- |
|
||||||
|
* | MSG_closed | 结束课程(下课) | closed |
|
||||||
|
* | MSG_onlineStatus | 在线状态 | onlineStatus |
|
||||||
|
* | MSG_pushQuizOfClassWorkdata2Public | 老师端:把选中的学生习题作业,推到大屏 | pushQuizOfClassWorkdata2Public |
|
||||||
|
* | MSG_pushClassWorkdata2Public | 老师端:把选中的学生作业,推到大屏 | pushClassWorkdata2Public |
|
||||||
|
* | MSG_shareStudentPresentdata2All | 把某个学生的展示成果数据推给全班所有学生 | shareStudentPresentdata2All |
|
||||||
|
* | MSG_pushStudentPresentdata2Public | 老师端:课堂展示活动,把选中的学生展示数据,推到大屏 | pushStudentPresentdata2Public |
|
||||||
|
* | MSG_pushClassWorkPresentList2Public | 老师端:课堂展示活动,任务列表,推到大屏 | pushClassWorkPresentList2Public |
|
||||||
|
* | MSG_activePageType | 课标研读-分页切换 | activePageType |
|
||||||
|
* | MSG_slideFlapping | 幻灯片-切换 | slideFlapping |
|
||||||
|
* | MSG_anmationclick | 幻灯片-动画切换 | anmationclick |
|
||||||
|
* | MSG_classcourseopen | 群组创建成功 | classcourseopen |
|
||||||
|
* | MSG_classquizfeedback | 学生的测练结果反馈 | classquizfeedback |
|
||||||
|
* | MSG_classtaskfeedback | 老师端:接收到学生反馈消息-课堂测练中的其他任务 | classtaskfeedback |
|
||||||
|
* | MSG_studentfeedback | 老师端:学生反馈的消息,具体要看其中的feedbackkey,类别较繁杂 | studentfeedback |
|
||||||
|
* | MSG_studentfeedbackcancel | 老师端:学生反馈的消息取消,如取消学会了,取消困惑 | studentfeedbackcancel |
|
||||||
|
* | MSG_classshowdata | 学生提交的课堂展示数据-要在老师端显示,再由老师选择推送到公屏上 | classshowdata |
|
||||||
|
* | MSG_classWorkOfPresentDataUpdate | 学生在公屏上展示并完善后,保存后,老师端要更新 | classWorkOfPresentDataUpdate |
|
||||||
|
* | MSG_classlecturePagesrc | 课堂讲授活动,选择不同的内容 | classlecturePagesrc |
|
||||||
|
* | --- | 以下为新定义-消息头 | --- |
|
||||||
|
* | MSG_0001 | 点赞 | 0x0001 |
|
||||||
|
* | MSG_0002 | xx | 0x0002 |
|
||||||
|
* | MSG_0003 | xx | 0x0003 |
|
||||||
|
*/
|
||||||
|
static HEADS = {
|
||||||
|
// === 旧定义-消息头(兼容以前) ===
|
||||||
|
/** @desc: 结束课程(下课) */
|
||||||
|
MSG_closed : 'closed',
|
||||||
|
/** @desc: 在线状态 */
|
||||||
|
MSG_onlineStatus : 'onlineStatus',
|
||||||
|
/** @desc: 老师端:把选中的学生习题作业,推到大屏 */
|
||||||
|
MSG_pushQuizOfClassWorkdata2Public : 'pushQuizOfClassWorkdata2Public',
|
||||||
|
/** @desc: 老师端:把选中的学生作业,推到大屏 */
|
||||||
|
MSG_pushClassWorkdata2Public : 'pushClassWorkdata2Public',
|
||||||
|
/** @desc: 把某个学生的展示成果数据推给全班所有学生 */
|
||||||
|
MSG_shareStudentPresentdata2All : 'shareStudentPresentdata2All',
|
||||||
|
/** @desc: 老师端:课堂展示活动,把选中的学生展示数据,推到大屏 */
|
||||||
|
MSG_pushStudentPresentdata2Public : 'pushStudentPresentdata2Public',
|
||||||
|
/** @desc: 老师端:课堂展示活动,任务列表,推到大屏 */
|
||||||
|
MSG_pushClassWorkPresentList2Public : 'pushClassWorkPresentList2Public',
|
||||||
|
/** @desc: 课标研读-分页切换 */
|
||||||
|
MSG_activePageType : 'activePageType',
|
||||||
|
/** @desc: 幻灯片-切换 */
|
||||||
|
MSG_slideFlapping : 'slideFlapping',
|
||||||
|
/** @desc: 幻灯片-动画切换 */
|
||||||
|
MSG_anmationclick : 'anmationclick',
|
||||||
|
/** @desc: 群组创建成功 */
|
||||||
|
MSG_classcourseopen : 'classcourseopen',
|
||||||
|
/** @desc: 学生的测练结果反馈 */
|
||||||
|
MSG_classquizfeedback : 'classquizfeedback',
|
||||||
|
/** @desc: 老师端:接收到学生反馈消息-课堂测练中的其他任务 */
|
||||||
|
MSG_classtaskfeedback : 'classtaskfeedback',
|
||||||
|
/** @desc: 老师端:学生反馈的消息,具体要看其中的feedbackkey,类别较繁杂 */
|
||||||
|
MSG_studentfeedback : 'studentfeedback',
|
||||||
|
/** @desc: 老师端:学生反馈的消息取消,如取消学会了,取消困惑 */
|
||||||
|
MSG_studentfeedbackcancel : 'studentfeedbackcancel',
|
||||||
|
/** @desc: 学生提交的课堂展示数据-要在老师端显示,再由老师选择推送到公屏上 */
|
||||||
|
MSG_classshowdata : 'classshowdata',
|
||||||
|
/** @desc: 学生在公屏上展示并完善后,保存后,老师端要更新 */
|
||||||
|
MSG_classWorkOfPresentDataUpdate : 'classWorkOfPresentDataUpdate',
|
||||||
|
/** @desc: 课堂讲授活动,选择不同的内容 */
|
||||||
|
MSG_classlecturePagesrc : 'classlecturePagesrc',
|
||||||
|
// === 新定义-消息头 ===
|
||||||
|
/** @desc: 点赞 */
|
||||||
|
MSG_0001: 0x0001,
|
||||||
|
MSG_0002: 0x0002,
|
||||||
|
MSG_0003: 0x0003,
|
||||||
|
MSG_0004: 0x0004,
|
||||||
|
MSG_0005: 0x0005,
|
||||||
|
MSG_0006: 0x0006,
|
||||||
|
MSG_0007: 0x0007,
|
||||||
|
MSG_0008: 0x0008,
|
||||||
|
MSG_0009: 0x0009,
|
||||||
|
MSG_0010: 0x000a,
|
||||||
|
MSG_0011: 0x000b,
|
||||||
|
MSG_0012: 0x000c,
|
||||||
|
MSG_0013: 0x000d,
|
||||||
|
MSG_0014: 0x000e,
|
||||||
|
MSG_0015: 0x000f,
|
||||||
|
MSG_0016: 0x0010,
|
||||||
|
MSG_0017: 0x0011,
|
||||||
|
MSG_0018: 0x0012,
|
||||||
|
MSG_0019: 0x0013,
|
||||||
|
MSG_0020: 0x0014,
|
||||||
|
MSG_0021: 0x0015,
|
||||||
|
MSG_0022: 0x0016,
|
||||||
|
MSG_0023: 0x0017,
|
||||||
|
MSG_0024: 0x0018,
|
||||||
|
MSG_0025: 0x0019,
|
||||||
|
MSG_0026: 0x001a,
|
||||||
|
MSG_0027: 0x001b,
|
||||||
|
MSG_0028: 0x001c,
|
||||||
|
MSG_0029: 0x001d,
|
||||||
|
MSG_0030: 0x001e,
|
||||||
|
MSG_0031: 0x001f,
|
||||||
|
MSG_0032: 0x0020,
|
||||||
|
MSG_0033: 0x0021,
|
||||||
|
MSG_0034: 0x0022,
|
||||||
|
MSG_0035: 0x0023,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { MsgEnum as default }
|
|
@ -33,7 +33,7 @@ export function shareStorePlugin({store}) {
|
||||||
|
|
||||||
// 同步数据-发送给主线程-单独
|
// 同步数据-发送给主线程-单独
|
||||||
function stateSync(storeName, key, value) {
|
function stateSync(storeName, key, value) {
|
||||||
console.log('state-change', storeName, key, value)
|
// console.log('state-change', storeName, key, value)
|
||||||
let jsonStr = ''
|
let jsonStr = ''
|
||||||
if (typeof key === 'string') jsonStr = JSON.stringify({[key]:value})
|
if (typeof key === 'string') jsonStr = JSON.stringify({[key]:value})
|
||||||
else if (typeof value === 'object') jsonStr = JSON.stringify(key)
|
else if (typeof value === 'object') jsonStr = JSON.stringify(key)
|
||||||
|
|
|
@ -7,34 +7,48 @@ import * as http from '@/api/apiService' // 自定义api service
|
||||||
// import { ipcMsgSend, ipcHandle, ipcMain, ipcMsgInvoke } from '@/utils/tool' // 相关工具
|
// import { ipcMsgSend, ipcHandle, ipcMain, ipcMsgInvoke } from '@/utils/tool' // 相关工具
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const emits = defineEmits(['change'])
|
const emits = defineEmits(['change'])
|
||||||
let imChat
|
const props = defineProps({
|
||||||
|
isGroup: { type: Boolean, default: false }, // 是否创建群
|
||||||
|
})
|
||||||
|
const imChatObj = reactive({imChat:null})
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// console.log(userStore)
|
// console.log(imChatObj)
|
||||||
initImChat()
|
initImChat()
|
||||||
})
|
})
|
||||||
// 初始化 im-chat
|
// 初始化 im-chat
|
||||||
const initImChat = async () => {
|
const initImChat = async () => {
|
||||||
// console.log('im-chat', userStore.user.timuserid)
|
// console.log('im-chat', userStore.user.timuserid)
|
||||||
try {
|
try {
|
||||||
|
const { timuserid, deptId, userId } = userStore.user
|
||||||
// 获取腾讯云签名
|
// 获取腾讯云签名
|
||||||
const res = await http.imChat.getTxCloudSign()
|
const res = await http.imChat.getTxCloudSign({imUserId: timuserid})
|
||||||
if (res && res.code == 200) {
|
if (res && res.code == 200) {
|
||||||
const { sdkAppId, sign } = res.data
|
const { sdkAppId, sign } = res.data
|
||||||
const { timuserid, deptId, userId } = userStore.user
|
|
||||||
// 群名称
|
// 群名称
|
||||||
const groupName = `${deptId}-classteaching-${userId}`
|
const groupName = `${deptId}-classteaching-${userId}`
|
||||||
// 注册im-chat
|
// 注册im-chat
|
||||||
// await ipcMsgInvoke('im-chat:init', sdkAppId)
|
// await ipcMsgInvoke('im-chat:init', sdkAppId)
|
||||||
imChat = new ImChat(sdkAppId, sign, timuserid)
|
imChatObj.imChat = new ImChat(sdkAppId, sign, timuserid)
|
||||||
// 初始化 im-chat
|
// 初始化 im-chat
|
||||||
await imChat.init()
|
await imChatObj.imChat.init()
|
||||||
// 登录 im-chat
|
// 登录 im-chat
|
||||||
await imChat.login()
|
await imChatObj.imChat.login()
|
||||||
imChat.watch(res => {
|
// 监听 im-chat 消息
|
||||||
console.log('im-chat watch: ', res)
|
imChatObj.imChat.watch((res) => {
|
||||||
|
const [msg] = res[0]?JSON.parse(res[0]):[]
|
||||||
|
imChatObj.imChat.setConsole('%cchat-msg', msg)
|
||||||
|
// 系统消息
|
||||||
|
if(msg.message_sender == '@TIM#SYSTEM'){
|
||||||
|
emits('change', 'msg-system', null, msg)
|
||||||
|
} else { // 普通消息-数据处理
|
||||||
|
(msg?.message_elem_array||[]).forEach(o => {
|
||||||
|
const msgData = !!o.text_elem_content ? JSON.parse(o.text_elem_content)||'' : ''
|
||||||
|
emits('change', 'msg', msgData, msg)
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// 创建群
|
// 创建群
|
||||||
await createGroup(groupName)
|
if (props.isGroup) await createGroup(groupName)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('im-error: ', error)
|
console.log('im-error: ', error)
|
||||||
|
@ -42,17 +56,17 @@ const initImChat = async () => {
|
||||||
}
|
}
|
||||||
// 创建群组
|
// 创建群组
|
||||||
const createGroup = async (groupName) => {
|
const createGroup = async (groupName) => {
|
||||||
if (!imChat) return
|
if (!imChatObj.imChat) return
|
||||||
await imChat.createGroup(groupName)
|
await imChatObj.imChat.createGroup(groupName)
|
||||||
const params = {type:'createGroup', data: imChat.timGroupId}
|
// emits('change', {type:'createGroup', data: imChat.timGroupId})
|
||||||
emits('change', params)
|
emits('change', 'createGroup', imChatObj.imChat.timGroupId)
|
||||||
}
|
}
|
||||||
// 退出
|
// 退出
|
||||||
const logout = () => imChat?.logout()
|
const logout = () => imChatObj.imChat?.logout()
|
||||||
// 解散群
|
// 解散群
|
||||||
const deleteGroup = () => imChat?.deleteGroup()
|
const deleteGroup = () => imChatObj.imChat?.deleteGroup()
|
||||||
|
|
||||||
defineExpose({ logout, deleteGroup, imChat })
|
defineExpose({ logout, deleteGroup, imChatObj })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
<side-vue v-ignore @ignore-mounted="sideMouse" @change="sideChange"></side-vue>
|
<side-vue v-ignore @ignore-mounted="sideMouse" @change="sideChange"></side-vue>
|
||||||
|
|
||||||
<!-- 点赞组件 -->
|
<!-- 点赞组件 -->
|
||||||
<upvote-vue></upvote-vue>
|
<upvote-vue ref="upvoteRef"></upvote-vue>
|
||||||
|
|
||||||
<!-- im-chat 聊天组件 -->
|
<!-- im-chat 聊天组件 -->
|
||||||
<!-- <im-chat ref="imChatRef" @change="chatChange" /> -->
|
<im-chat ref="imChatRef" @change="chatChange" />
|
||||||
|
|
||||||
<!-- 底部工具栏 -->
|
<!-- 底部工具栏 -->
|
||||||
<div class="tool-bottom-all" @mouseenter="mouseChange(0)" @mouseleave="mouseChange(1)">
|
<div class="tool-bottom-all" @mouseenter="mouseChange(0)" @mouseleave="mouseChange(1)">
|
||||||
|
@ -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 { startClass, endClass } from '@/api/classManage'
|
import { ElMessageBox, ElMessage } 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' // 画板-子组件
|
||||||
|
@ -50,14 +50,17 @@ import vDrag from './directive/drag' // 自定义指令-拖拽
|
||||||
import vIgnore from './directive/ignore' // 自定义指令-穿透
|
import vIgnore from './directive/ignore' // 自定义指令-穿透
|
||||||
import { useToolState } from '@/store/modules/tool' // 数据状态-缓存
|
import { useToolState } from '@/store/modules/tool' // 数据状态-缓存
|
||||||
import { ipcMsgSend, ipcHandle, ipcMain, ipcMsgInvoke } from '@/utils/tool' // 相关工具
|
import { ipcMsgSend, ipcHandle, ipcMain, ipcMsgInvoke } from '@/utils/tool' // 相关工具
|
||||||
|
import MsgEnum from '@/plugins/imChat/msgEnum' // 消息头-相关定义(nuem)
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const tabActive = ref('select') // 工具栏当前选中项
|
const tabActive = ref('select') // 工具栏当前选中项
|
||||||
const isFold = ref(false) // 折叠工具栏
|
const isFold = ref(false) // 折叠工具栏
|
||||||
const isDrag = ref(false) // 开始拖拽
|
const isDrag = ref(false) // 开始拖拽
|
||||||
const dragtime = ref(0) // 拖拽时间-计算点击还是拖动
|
const dragtime = ref(0) // 拖拽时间-计算点击还是拖动
|
||||||
const isShow = ref(false) // 是否显示-画板
|
const isShow = ref(false) // 是否显示-画板
|
||||||
|
const isOver = ref(false) // 是否下课
|
||||||
const toolStore = useToolState() // 状态管理
|
const toolStore = useToolState() // 状态管理
|
||||||
const boardVueRef=ref(null) // 画板ref
|
const boardVueRef=ref(null) // 画板ref
|
||||||
|
const upvoteRef = ref(null) // 点赞 ref
|
||||||
const imChatRef = ref(null) // im-chat ref
|
const imChatRef = ref(null) // im-chat ref
|
||||||
const classObj = reactive({ // 课程相关
|
const classObj = reactive({ // 课程相关
|
||||||
id: route.query.reservId, // 课程id
|
id: route.query.reservId, // 课程id
|
||||||
|
@ -75,7 +78,6 @@ const btnList = [ // 工具栏按钮列表
|
||||||
// === 页面加载完毕 ===
|
// === 页面加载完毕 ===
|
||||||
onMounted(async() => {
|
onMounted(async() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log(classObj)
|
|
||||||
resetStatus() // 开启重置状态-监听
|
resetStatus() // 开启重置状态-监听
|
||||||
}, 200);
|
}, 200);
|
||||||
})
|
})
|
||||||
|
@ -103,11 +105,24 @@ const mouseChange = (bool) => {
|
||||||
if (!isShow.value) resBool = !!bool
|
if (!isShow.value) resBool = !!bool
|
||||||
setIgnore(resBool)
|
setIgnore(resBool)
|
||||||
}
|
}
|
||||||
// im-chat: 聊天事件
|
// im-chat: 聊天事件 {type, data}
|
||||||
const chatChange = ({type, data}) => {
|
const chatChange = (type, data) => {
|
||||||
if (type == 'createGroup') { // 创建群
|
if (type == 'createGroup') { // 创建群-监听
|
||||||
// classManageApi.startClass()
|
classManageApi.startClass(classObj.id, data)
|
||||||
|
} else if (type == 'msg') { // im-chat 消息监听
|
||||||
|
if (!data) return // 没有msg数据
|
||||||
|
const { msgKey:head, msgcontent:msg, senduserid:sendId, msgType } = data
|
||||||
|
switch(head) {
|
||||||
|
case MsgEnum.HEADS.MSG_0001:
|
||||||
|
// console.log('点赞:', data)
|
||||||
|
upvoteRef.value.trigger()
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
console.log('未知消息:', data)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// console.log('im-chat-sphere:', type, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 忽略鼠标穿透
|
// 忽略鼠标穿透
|
||||||
|
@ -127,6 +142,10 @@ const resetStatus = () => {
|
||||||
// 侧边工具栏: 移入移出
|
// 侧边工具栏: 移入移出
|
||||||
const sideMouse = e => {
|
const sideMouse = e => {
|
||||||
const {type} = e.detail
|
const {type} = e.detail
|
||||||
|
if (isOver.value && type == 'mouseleave') {
|
||||||
|
setIgnore(false) // 关闭窗口鼠标-穿透
|
||||||
|
return
|
||||||
|
}
|
||||||
mouseChange(type == 'mouseleave')
|
mouseChange(type == 'mouseleave')
|
||||||
}
|
}
|
||||||
// 侧边工具栏: 操作变化
|
// 侧边工具栏: 操作变化
|
||||||
|
@ -140,11 +159,30 @@ const sideChange = async o => {
|
||||||
case 'win': // 窗口
|
case 'win': // 窗口
|
||||||
break
|
break
|
||||||
case 'over': // 下课
|
case 'over': // 下课
|
||||||
toolStore.isToolWin = false
|
isOver.value = true
|
||||||
await classManageApi.endClass(route.query.reservId)
|
ElMessageBox.confirm('确认结束课程吗?', '提示', {
|
||||||
await imChatRef.value?.deleteGroup() // 解散群
|
confirmButtonText: '确定',
|
||||||
await imChatRef.value?.logout() // 退出im
|
cancelButtonText: '取消',
|
||||||
ipcMsgSend('tool-sphere:close') // 关闭窗口
|
type: 'warning'
|
||||||
|
}).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);
|
||||||
|
|
||||||
|
isOver.value = false
|
||||||
|
setIgnore(true) // 开启窗口鼠标-穿透
|
||||||
|
}).catch(() => {
|
||||||
|
isOver.value = false
|
||||||
|
setIgnore(true) // 开启窗口鼠标-穿透
|
||||||
|
})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue