goeasy移植
This commit is contained in:
@@ -1,15 +1,26 @@
|
||||
/**
|
||||
* PK Mini 模块专用 GoEasy 实例
|
||||
*
|
||||
* 使用前请确保在 src/config/pk-mini.js 中将 GOEASY_ENABLED 设为 true
|
||||
*/
|
||||
import GoEasy from 'goeasy'
|
||||
import { pkIMloginStore } from '@/stores/pk-mini/notice.js'
|
||||
import { PK_MINI_CONFIG, isGoEasyEnabled } from '@/config/pk-mini.js'
|
||||
|
||||
// PK Mini 模块专用 GoEasy 实例
|
||||
let pkGoEasyInstance = null
|
||||
|
||||
// 获取或创建 PK GoEasy 实例
|
||||
export function getPkGoEasy() {
|
||||
if (!isGoEasyEnabled()) {
|
||||
console.warn('[PK GoEasy] GoEasy 未启用,请在 src/config/pk-mini.js 中设置 GOEASY_ENABLED: true')
|
||||
return null
|
||||
}
|
||||
|
||||
if (!pkGoEasyInstance) {
|
||||
pkGoEasyInstance = GoEasy.getInstance({
|
||||
host: 'hangzhou.goeasy.io',
|
||||
appkey: 'PC-a88037e060ed4753bb316ac7239e62d9',
|
||||
host: PK_MINI_CONFIG.GOEASY.HOST,
|
||||
appkey: PK_MINI_CONFIG.GOEASY.APP_KEY,
|
||||
modules: ['im']
|
||||
})
|
||||
}
|
||||
@@ -18,11 +29,19 @@ export function getPkGoEasy() {
|
||||
|
||||
// 初始化 PK GoEasy (在 PkMiniWorkbench 挂载时调用)
|
||||
export function initPkGoEasy() {
|
||||
if (!isGoEasyEnabled()) {
|
||||
console.warn('[PK GoEasy] GoEasy 未启用')
|
||||
return null
|
||||
}
|
||||
return getPkGoEasy()
|
||||
}
|
||||
|
||||
// 链接 IM (登录 IM)
|
||||
export function goEasyLink(data) {
|
||||
if (!isGoEasyEnabled()) {
|
||||
return Promise.reject(new Error('GoEasy 未启用'))
|
||||
}
|
||||
|
||||
const goeasy = getPkGoEasy()
|
||||
const counter = pkIMloginStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -48,6 +67,10 @@ export function goEasyLink(data) {
|
||||
|
||||
// 断开 IM
|
||||
export function goEasyDisConnect() {
|
||||
if (!isGoEasyEnabled()) {
|
||||
return Promise.reject(new Error('GoEasy 未启用'))
|
||||
}
|
||||
|
||||
const goeasy = getPkGoEasy()
|
||||
return new Promise((resolve, reject) => {
|
||||
goeasy.disconnect({
|
||||
@@ -64,6 +87,10 @@ export function goEasyDisConnect() {
|
||||
|
||||
// 获取会话列表
|
||||
export function goEasyGetConversations() {
|
||||
if (!isGoEasyEnabled()) {
|
||||
return Promise.reject(new Error('GoEasy 未启用'))
|
||||
}
|
||||
|
||||
const goeasy = getPkGoEasy()
|
||||
const im = goeasy.im
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -81,6 +108,10 @@ export function goEasyGetConversations() {
|
||||
|
||||
// 获取指定会话的消息列表
|
||||
export function goEasyGetMessages(data) {
|
||||
if (!isGoEasyEnabled()) {
|
||||
return Promise.reject(new Error('GoEasy 未启用'))
|
||||
}
|
||||
|
||||
const goeasy = getPkGoEasy()
|
||||
const im = goeasy.im
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -102,6 +133,10 @@ export function goEasyGetMessages(data) {
|
||||
|
||||
// 发送文本消息
|
||||
export function goEasySendMessage(data) {
|
||||
if (!isGoEasyEnabled()) {
|
||||
return Promise.reject(new Error('GoEasy 未启用'))
|
||||
}
|
||||
|
||||
const goeasy = getPkGoEasy()
|
||||
const im = goeasy.im
|
||||
let textMessage = im.createTextMessage({
|
||||
@@ -128,6 +163,10 @@ export function goEasySendMessage(data) {
|
||||
|
||||
// 发送图片消息
|
||||
export function goEasySendImageMessage(data) {
|
||||
if (!isGoEasyEnabled()) {
|
||||
return Promise.reject(new Error('GoEasy 未启用'))
|
||||
}
|
||||
|
||||
const goeasy = getPkGoEasy()
|
||||
const im = goeasy.im
|
||||
const message = im.createImageMessage({
|
||||
@@ -154,6 +193,10 @@ export function goEasySendImageMessage(data) {
|
||||
|
||||
// 发送 PK 消息
|
||||
export function goEasySendPKMessage(data) {
|
||||
if (!isGoEasyEnabled()) {
|
||||
return Promise.reject(new Error('GoEasy 未启用'))
|
||||
}
|
||||
|
||||
const goeasy = getPkGoEasy()
|
||||
const im = goeasy.im
|
||||
const customData = {
|
||||
@@ -194,6 +237,10 @@ export function goEasySendPKMessage(data) {
|
||||
|
||||
// 消息已读
|
||||
export function goEasyMessageRead(data) {
|
||||
if (!isGoEasyEnabled()) {
|
||||
return Promise.reject(new Error('GoEasy 未启用'))
|
||||
}
|
||||
|
||||
const goeasy = getPkGoEasy()
|
||||
const im = goeasy.im
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -210,3 +257,6 @@ export function goEasyMessageRead(data) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 导出 GoEasy 常量(用于事件监听)
|
||||
export { GoEasy }
|
||||
|
||||
Reference in New Issue
Block a user