goeasy移植
This commit is contained in:
@@ -22,18 +22,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 用户头像 -->
|
||||
<div class="avatar-section">
|
||||
<el-popover placement="right-end" :width="200" trigger="click">
|
||||
<template #reference>
|
||||
<img class="avatar-img" :src="userInfo.headerIcon || defaultAvatar" alt="avatar" />
|
||||
</template>
|
||||
<div class="avatar-menu">
|
||||
<div class="avatar-name">{{ userInfo.nickName || '用户' }}</div>
|
||||
<div class="menu-item" @click="handleSignIn">签到</div>
|
||||
<div class="menu-item" @click="handleSettings">设置</div>
|
||||
<!-- 签到按钮 -->
|
||||
<div class="sign-in-section">
|
||||
<div class="sign-in-btn" @click="handleSignIn">
|
||||
<span class="material-icons-round sign-icon">event_available</span>
|
||||
<div class="sign-text">签到</div>
|
||||
</div>
|
||||
</el-popover>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -207,49 +201,37 @@ onMounted(() => {
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
.avatar-section {
|
||||
.sign-in-section {
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.avatar-img {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border-radius: 50%;
|
||||
.sign-in-btn {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
border: 2px solid white;
|
||||
transition: all 0.3s ease;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.avatar-img:hover {
|
||||
transform: scale(1.1);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||
.sign-in-btn:hover {
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.avatar-menu {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.avatar-name {
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
border-bottom: 1px solid #eee;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
color: #666;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.menu-item:hover {
|
||||
background-color: #f5f5f5;
|
||||
.sign-icon {
|
||||
font-size: 24px;
|
||||
color: #03aba8;
|
||||
}
|
||||
|
||||
.sign-text {
|
||||
font-size: 10px;
|
||||
color: #03aba8;
|
||||
margin-top: 4px;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<!-- 积分列表 -->
|
||||
<div class="points-container">
|
||||
<div class="points-header">
|
||||
<img class="points-icon" src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Points.png" alt="" />
|
||||
<img class="points-icon" src="@/assets/pk-mini/Points.png" alt="" />
|
||||
<div class="points-text">
|
||||
我的积分: <span class="points-num">{{ currentUser.points || 0 }}</span>
|
||||
</div>
|
||||
|
||||
26
src/config/pk-mini.js
Normal file
26
src/config/pk-mini.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* PK Mini 模块配置
|
||||
*
|
||||
* GoEasy 续费后,将 GOEASY_ENABLED 改为 true 即可开启消息功能
|
||||
*/
|
||||
|
||||
export const PK_MINI_CONFIG = {
|
||||
// GoEasy 开关 - 续费后改为 true
|
||||
GOEASY_ENABLED: true,
|
||||
|
||||
// GoEasy 配置
|
||||
GOEASY: {
|
||||
HOST: 'hangzhou.goeasy.io',
|
||||
APP_KEY: 'BC-a88037e060ed4753bb316ac7239e62d9',
|
||||
},
|
||||
|
||||
// API 基础地址
|
||||
API_BASE_URL: 'http://192.168.2.22:8086/',
|
||||
// API_BASE_URL: 'https://pk.hanxiaokj.cn/',
|
||||
|
||||
// 头像 CDN 地址
|
||||
AVATAR_CDN_PREFIX: 'https://vv-1317974657.cos.ap-shanghai.myqcloud.com/headerIcon/',
|
||||
}
|
||||
|
||||
// 快捷访问
|
||||
export const isGoEasyEnabled = () => PK_MINI_CONFIG.GOEASY_ENABLED
|
||||
@@ -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 }
|
||||
|
||||
@@ -88,19 +88,19 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, onMounted, onUnmounted, nextTick } from 'vue'
|
||||
import { getMainUserData } from '@/utils/pk-mini/storage'
|
||||
import { TimestamptolocalTime } from '@/utils/pk-mini/timeConversion'
|
||||
// GoEasy 暂时禁用(订阅未续费)
|
||||
// import {
|
||||
// goEasyGetConversations,
|
||||
// goEasyGetMessages,
|
||||
// goEasySendMessage,
|
||||
// goEasySendImageMessage,
|
||||
// goEasyMessageRead,
|
||||
// getPkGoEasy
|
||||
// } from '@/utils/pk-mini/goeasy'
|
||||
// import GoEasy from 'goeasy'
|
||||
import { isGoEasyEnabled } from '@/config/pk-mini'
|
||||
import {
|
||||
goEasyGetConversations,
|
||||
goEasyGetMessages,
|
||||
goEasySendMessage,
|
||||
goEasySendImageMessage,
|
||||
goEasyMessageRead,
|
||||
getPkGoEasy,
|
||||
GoEasy
|
||||
} from '@/utils/pk-mini/goeasy'
|
||||
import PictureMessage from '@/components/pk-mini/chat/PictureMessage.vue'
|
||||
import PKMessage from '@/components/pk-mini/chat/PKMessage.vue'
|
||||
import VoiceMessage from '@/components/pk-mini/chat/VoiceMessage.vue'
|
||||
@@ -118,12 +118,34 @@ const fileInputRef = ref(null)
|
||||
const formatTime = TimestamptolocalTime
|
||||
|
||||
async function loadConversations() {
|
||||
// GoEasy 暂时禁用
|
||||
if (!isGoEasyEnabled()) {
|
||||
ElMessage.warning('消息功能暂时不可用(GoEasy 订阅未续费)')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await goEasyGetConversations()
|
||||
chatList.value = result?.content || []
|
||||
} catch (e) {
|
||||
console.error('加载会话列表失败', e)
|
||||
}
|
||||
}
|
||||
|
||||
async function selectChat(item) {
|
||||
// GoEasy 暂时禁用
|
||||
if (!isGoEasyEnabled()) return
|
||||
|
||||
selectedChat.value = item
|
||||
try {
|
||||
const messages = await goEasyGetMessages({ id: item.userId, timestamp: null })
|
||||
messagesList.value = messages || []
|
||||
await nextTick()
|
||||
scrollToBottom()
|
||||
// 标记消息已读
|
||||
goEasyMessageRead({ id: item.userId }).catch(() => {})
|
||||
item.unread = 0
|
||||
} catch (e) {
|
||||
console.error('加载消息失败', e)
|
||||
}
|
||||
}
|
||||
|
||||
function scrollToBottom() {
|
||||
@@ -133,22 +155,105 @@ function scrollToBottom() {
|
||||
}
|
||||
|
||||
async function sendMessage() {
|
||||
// GoEasy 暂时禁用
|
||||
if (!isGoEasyEnabled()) {
|
||||
ElMessage.warning('消息功能暂时不可用(GoEasy 订阅未续费)')
|
||||
return
|
||||
}
|
||||
|
||||
if (!inputText.value.trim()) return
|
||||
if (!selectedChat.value) return
|
||||
|
||||
try {
|
||||
const msg = await goEasySendMessage({
|
||||
text: inputText.value,
|
||||
id: selectedChat.value.userId,
|
||||
avatar: currentUser.value.headerIcon,
|
||||
nickname: currentUser.value.nickName
|
||||
})
|
||||
messagesList.value.push(msg)
|
||||
inputText.value = ''
|
||||
await nextTick()
|
||||
scrollToBottom()
|
||||
} catch (e) {
|
||||
console.error('发送消息失败', e)
|
||||
ElMessage.error('发送失败')
|
||||
}
|
||||
}
|
||||
|
||||
function handleSendImage() {
|
||||
// GoEasy 暂时禁用
|
||||
if (!isGoEasyEnabled()) {
|
||||
ElMessage.warning('消息功能暂时不可用(GoEasy 订阅未续费)')
|
||||
return
|
||||
}
|
||||
if (!selectedChat.value) {
|
||||
ElMessage.warning('请先选择一个会话')
|
||||
return
|
||||
}
|
||||
fileInputRef.value?.click()
|
||||
}
|
||||
|
||||
async function handleFileSelect(event) {
|
||||
const file = event.target.files?.[0]
|
||||
event.target.value = ''
|
||||
|
||||
if (!file || !isGoEasyEnabled()) return
|
||||
if (!selectedChat.value) return
|
||||
|
||||
try {
|
||||
const msg = await goEasySendImageMessage({
|
||||
imagefile: file,
|
||||
id: selectedChat.value.userId,
|
||||
avatar: currentUser.value.headerIcon,
|
||||
nickname: currentUser.value.nickName
|
||||
})
|
||||
messagesList.value.push(msg)
|
||||
await nextTick()
|
||||
scrollToBottom()
|
||||
} catch (e) {
|
||||
console.error('发送图片失败', e)
|
||||
ElMessage.error('发送图片失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
currentUser.value = getMainUserData() || {}
|
||||
// GoEasy 暂时禁用,不加载会话
|
||||
if (isGoEasyEnabled()) {
|
||||
loadConversations()
|
||||
// 监听新消息
|
||||
const goeasy = getPkGoEasy()
|
||||
if (goeasy) {
|
||||
goeasy.im.on(GoEasy.IM_EVENT.PRIVATE_MESSAGE_RECEIVED, onMessageReceived)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function onMessageReceived(message) {
|
||||
if (!isGoEasyEnabled()) return
|
||||
// 更新会话列表中的未读数
|
||||
const conv = chatList.value.find(c => c.userId === message.senderId)
|
||||
if (conv) {
|
||||
conv.unread = (conv.unread || 0) + 1
|
||||
conv.lastMessage = message
|
||||
}
|
||||
// 如果当前正在查看该会话,添加消息到列表
|
||||
if (selectedChat.value && selectedChat.value.userId === message.senderId) {
|
||||
messagesList.value.push(message)
|
||||
nextTick(() => scrollToBottom())
|
||||
goEasyMessageRead({ id: message.senderId }).catch(() => {})
|
||||
}
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
if (isGoEasyEnabled()) {
|
||||
const goeasy = getPkGoEasy()
|
||||
if (goeasy) {
|
||||
try {
|
||||
goeasy.im.off(GoEasy.IM_EVENT.PRIVATE_MESSAGE_RECEIVED, onMessageReceived)
|
||||
} catch (e) {
|
||||
console.warn('清理 GoEasy 监听器失败', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
<div
|
||||
v-infinite-scroll="loadMore"
|
||||
:infinite-scroll-distance="100"
|
||||
:infinite-scroll-disabled="loading || noMore"
|
||||
class="pk-list"
|
||||
>
|
||||
<div
|
||||
@@ -184,24 +185,63 @@
|
||||
style="display: none"
|
||||
@change="handleFileSelect"
|
||||
/>
|
||||
|
||||
<!-- PK邀请弹窗 -->
|
||||
<el-dialog v-model="inviteDialogVisible" title="选择主播发起PK邀请" width="500" align-center>
|
||||
<div class="invite-dialog-content">
|
||||
<div v-if="myAnchorList.length === 0" class="no-anchor-tip">
|
||||
暂无可用主播,请先在"我的"页面添加主播
|
||||
</div>
|
||||
<div v-else class="anchor-list">
|
||||
<div
|
||||
v-for="anchor in myAnchorList"
|
||||
:key="anchor.id"
|
||||
class="anchor-item"
|
||||
:class="{ selected: selectedAnchor?.id === anchor.id }"
|
||||
@click="selectedAnchor = anchor"
|
||||
>
|
||||
<img class="anchor-avatar" :src="anchor.anchorIcon" alt="" />
|
||||
<div class="anchor-info">
|
||||
<div class="anchor-name">{{ anchor.anchorId }}</div>
|
||||
<div class="anchor-detail">
|
||||
<span class="anchor-gender" :class="anchor.sex === 1 ? 'male' : 'female'">
|
||||
{{ anchor.sex === 1 ? '男' : '女' }}
|
||||
</span>
|
||||
<span class="anchor-coin">{{ anchor.coin }}K</span>
|
||||
</div>
|
||||
<div class="anchor-time">PK时间: {{ formatTime(anchor.pkTime * 1000) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="invite-dialog-footer">
|
||||
<el-button @click="inviteDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :disabled="!selectedAnchor" @click="confirmInvite">
|
||||
发送邀请
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import { getPkList, getUserInfo } from '@/api/pk-mini'
|
||||
import { ref, onMounted, onUnmounted, nextTick } from 'vue'
|
||||
import { getPkList, getUserInfo, getAnchorListById, createPkRecord } from '@/api/pk-mini'
|
||||
import { getCountryNamesArray } from '@/utils/pk-mini/countryUtil'
|
||||
import { TimestamptolocalTime } from '@/utils/pk-mini/timeConversion'
|
||||
import { getMainUserData } from '@/utils/pk-mini/storage'
|
||||
// GoEasy 暂时禁用(订阅未续费)
|
||||
// import {
|
||||
// goEasyGetMessages,
|
||||
// goEasySendMessage,
|
||||
// goEasySendImageMessage,
|
||||
// goEasyMessageRead,
|
||||
// getPkGoEasy
|
||||
// } from '@/utils/pk-mini/goeasy'
|
||||
// import GoEasy from 'goeasy'
|
||||
import { isGoEasyEnabled } from '@/config/pk-mini'
|
||||
import {
|
||||
goEasyGetMessages,
|
||||
goEasySendMessage,
|
||||
goEasySendImageMessage,
|
||||
goEasySendPKMessage,
|
||||
goEasyMessageRead,
|
||||
getPkGoEasy,
|
||||
GoEasy
|
||||
} from '@/utils/pk-mini/goeasy'
|
||||
import PictureMessage from '@/components/pk-mini/chat/PictureMessage.vue'
|
||||
import MiniPKMessage from '@/components/pk-mini/chat/MiniPKMessage.vue'
|
||||
import VoiceMessage from '@/components/pk-mini/chat/VoiceMessage.vue'
|
||||
@@ -235,6 +275,15 @@ const currentUser = ref({})
|
||||
const chatMessagesRef = ref(null)
|
||||
const fileInputRef = ref(null)
|
||||
|
||||
// 邀请相关状态
|
||||
const inviteDialogVisible = ref(false)
|
||||
const myAnchorList = ref([])
|
||||
const selectedAnchor = ref(null)
|
||||
|
||||
// 加载状态
|
||||
const loading = ref(false)
|
||||
const noMore = ref(false)
|
||||
|
||||
const countryOptions = ref([])
|
||||
const genderOptions = [
|
||||
{ value: 1, label: '男' },
|
||||
@@ -257,6 +306,7 @@ function switchMode() {
|
||||
// 搜索
|
||||
function handleSearch() {
|
||||
page.value = 0
|
||||
noMore.value = false
|
||||
if (isHallMode.value) {
|
||||
hallList.value = []
|
||||
} else {
|
||||
@@ -285,6 +335,9 @@ function loadMore() {
|
||||
async function loadPkList() {
|
||||
const userId = getUserId(currentUser.value)
|
||||
if (!userId) return
|
||||
if (loading.value) return
|
||||
|
||||
loading.value = true
|
||||
|
||||
const body = {
|
||||
status: 0,
|
||||
@@ -303,9 +356,11 @@ async function loadPkList() {
|
||||
body.condition.coin = { start: minCoin.value, end: maxCoin.value }
|
||||
} else if (minCoin.value != null && maxCoin.value == null) {
|
||||
ElMessage.error('请输入最大金币数')
|
||||
loading.value = false
|
||||
return
|
||||
} else if (minCoin.value == null && maxCoin.value != null) {
|
||||
ElMessage.error('请输入最小金币数')
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
@@ -327,9 +382,14 @@ async function loadPkList() {
|
||||
pkList.value = todayList.value
|
||||
}
|
||||
page.value++
|
||||
} else {
|
||||
// 没有更多数据了
|
||||
noMore.value = true
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载 PK 列表失败', e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,16 +401,30 @@ async function handleItemClick(item) {
|
||||
const res = await getUserInfo({ id: item.senderId })
|
||||
chatUserInfo.value = res
|
||||
|
||||
// GoEasy 暂时禁用,聊天功能不可用
|
||||
if (isGoEasyEnabled()) {
|
||||
// GoEasy 已启用,加载聊天消息
|
||||
const messages = await goEasyGetMessages({ id: item.senderId, timestamp: null })
|
||||
messagesList.value = messages || []
|
||||
await nextTick()
|
||||
scrollToBottom()
|
||||
// 标记消息已读
|
||||
goEasyMessageRead({ id: item.senderId }).catch(() => {})
|
||||
} else {
|
||||
messagesList.value = []
|
||||
ElMessage.warning('聊天功能暂时不可用(GoEasy 订阅未续费)')
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('获取聊天信息失败', e)
|
||||
}
|
||||
}
|
||||
|
||||
function onMessageReceived(message) {
|
||||
// GoEasy 暂时禁用
|
||||
if (!isGoEasyEnabled()) return
|
||||
// 处理接收到的消息
|
||||
if (message && selectedItem.value && message.senderId === selectedItem.value.senderId) {
|
||||
messagesList.value.push(message)
|
||||
nextTick(() => scrollToBottom())
|
||||
}
|
||||
}
|
||||
|
||||
function scrollToBottom() {
|
||||
@@ -361,24 +435,134 @@ function scrollToBottom() {
|
||||
|
||||
// 发送消息
|
||||
async function sendMessage() {
|
||||
// GoEasy 暂时禁用
|
||||
if (!isGoEasyEnabled()) {
|
||||
ElMessage.warning('聊天功能暂时不可用(GoEasy 订阅未续费)')
|
||||
return
|
||||
}
|
||||
|
||||
if (!inputText.value.trim()) return
|
||||
if (!selectedItem.value) return
|
||||
|
||||
try {
|
||||
const msg = await goEasySendMessage({
|
||||
text: inputText.value,
|
||||
id: selectedItem.value.senderId,
|
||||
avatar: currentUser.value.headerIcon,
|
||||
nickname: currentUser.value.nickName
|
||||
})
|
||||
messagesList.value.push(msg)
|
||||
inputText.value = ''
|
||||
await nextTick()
|
||||
scrollToBottom()
|
||||
} catch (e) {
|
||||
console.error('发送消息失败', e)
|
||||
ElMessage.error('发送失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 发送图片
|
||||
function handleSendImage() {
|
||||
// GoEasy 暂时禁用
|
||||
if (!isGoEasyEnabled()) {
|
||||
ElMessage.warning('聊天功能暂时不可用(GoEasy 订阅未续费)')
|
||||
return
|
||||
}
|
||||
if (!selectedItem.value) {
|
||||
ElMessage.warning('请先选择一个主播')
|
||||
return
|
||||
}
|
||||
fileInputRef.value?.click()
|
||||
}
|
||||
|
||||
async function handleFileSelect(event) {
|
||||
// GoEasy 暂时禁用
|
||||
const file = event.target.files?.[0]
|
||||
event.target.value = ''
|
||||
|
||||
if (!file || !isGoEasyEnabled()) return
|
||||
if (!selectedItem.value) return
|
||||
|
||||
try {
|
||||
const msg = await goEasySendImageMessage({
|
||||
imagefile: file,
|
||||
id: selectedItem.value.senderId,
|
||||
avatar: currentUser.value.headerIcon,
|
||||
nickname: currentUser.value.nickName
|
||||
})
|
||||
messagesList.value.push(msg)
|
||||
await nextTick()
|
||||
scrollToBottom()
|
||||
} catch (e) {
|
||||
console.error('发送图片失败', e)
|
||||
ElMessage.error('发送图片失败')
|
||||
}
|
||||
}
|
||||
|
||||
// PK邀请
|
||||
function handleInvite() {
|
||||
ElMessage.info('PK邀请功能开发中')
|
||||
async function handleInvite() {
|
||||
if (!isGoEasyEnabled()) {
|
||||
ElMessage.warning('邀请功能暂时不可用(GoEasy 订阅未续费)')
|
||||
return
|
||||
}
|
||||
if (!selectedItem.value) {
|
||||
ElMessage.warning('请先选择一个主播')
|
||||
return
|
||||
}
|
||||
|
||||
const userId = getUserId(currentUser.value)
|
||||
if (!userId) {
|
||||
ElMessage.warning('用户信息异常')
|
||||
return
|
||||
}
|
||||
|
||||
// 获取我的主播列表(未邀请过的)
|
||||
try {
|
||||
const res = await getAnchorListById({
|
||||
pkId: selectedItem.value.id,
|
||||
userId: userId
|
||||
})
|
||||
myAnchorList.value = res || []
|
||||
selectedAnchor.value = null
|
||||
inviteDialogVisible.value = true
|
||||
} catch (e) {
|
||||
console.error('获取主播列表失败', e)
|
||||
ElMessage.error('获取主播列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 确认发送邀请
|
||||
async function confirmInvite() {
|
||||
if (!selectedAnchor.value || !selectedItem.value) return
|
||||
|
||||
const userId = getUserId(currentUser.value)
|
||||
if (!userId) return
|
||||
|
||||
try {
|
||||
// 创建 PK 记录
|
||||
const pkRecord = await createPkRecord({
|
||||
pkIdA: selectedItem.value.id,
|
||||
pkIdB: selectedAnchor.value.id,
|
||||
userId: userId
|
||||
})
|
||||
|
||||
// 发送 PK 邀请消息
|
||||
const msg = await goEasySendPKMessage({
|
||||
msgid: pkRecord.id,
|
||||
pkIdA: selectedItem.value.id,
|
||||
pkIdB: selectedAnchor.value.id,
|
||||
id: selectedItem.value.senderId,
|
||||
avatar: currentUser.value.headerIcon,
|
||||
nickname: currentUser.value.nickName
|
||||
})
|
||||
|
||||
messagesList.value.push(msg)
|
||||
await nextTick()
|
||||
scrollToBottom()
|
||||
|
||||
inviteDialogVisible.value = false
|
||||
ElMessage.success('邀请已发送')
|
||||
} catch (e) {
|
||||
console.error('发送邀请失败', e)
|
||||
ElMessage.error('发送邀请失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@@ -420,7 +604,16 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
// GoEasy 暂时禁用
|
||||
if (isGoEasyEnabled()) {
|
||||
const goeasy = getPkGoEasy()
|
||||
if (goeasy) {
|
||||
try {
|
||||
goeasy.im.off(GoEasy.IM_EVENT.PRIVATE_MESSAGE_RECEIVED, onMessageReceived)
|
||||
} catch (e) {
|
||||
console.warn('清理 GoEasy 监听器失败', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -862,4 +1055,100 @@ onUnmounted(() => {
|
||||
visibility: hidden; // 仍然占位,但看不见
|
||||
pointer-events: none; // 不能点击
|
||||
}
|
||||
|
||||
// 邀请弹窗样式
|
||||
.invite-dialog-content {
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.no-anchor-tip {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.anchor-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.anchor-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
border: 2px solid #eee;
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.anchor-item:hover {
|
||||
border-color: #4fcacd;
|
||||
background: #f8ffff;
|
||||
}
|
||||
|
||||
.anchor-item.selected {
|
||||
border-color: #03aba8;
|
||||
background: #e4f9f9;
|
||||
}
|
||||
|
||||
.anchor-avatar {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
.anchor-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.anchor-name {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.anchor-detail {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.anchor-gender {
|
||||
padding: 2px 10px;
|
||||
border-radius: 10px;
|
||||
font-size: 12px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.anchor-gender.male {
|
||||
background: #59d8db;
|
||||
}
|
||||
|
||||
.anchor-gender.female {
|
||||
background: #f3876f;
|
||||
}
|
||||
|
||||
.anchor-coin {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.anchor-time {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.invite-dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user