goeasy移植
This commit is contained in:
@@ -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 暂时禁用
|
||||
ElMessage.warning('消息功能暂时不可用(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 暂时禁用
|
||||
ElMessage.warning('消息功能暂时不可用(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 暂时禁用
|
||||
ElMessage.warning('消息功能暂时不可用(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 暂时禁用,聊天功能不可用
|
||||
messagesList.value = []
|
||||
ElMessage.warning('聊天功能暂时不可用(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 暂时禁用
|
||||
ElMessage.warning('聊天功能暂时不可用(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 暂时禁用
|
||||
ElMessage.warning('聊天功能暂时不可用(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