AI分析
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
<image class="room-nav__avatar" :src="targetUser?.avatar || defaultAvatar" mode="aspectFill" />
|
||||
<view class="room-nav__text">
|
||||
<text class="room-nav__name">{{ targetUser?.nickname || '私聊' }}</text>
|
||||
<text class="room-nav__relation">{{ relationshipText }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="room-nav__btn" />
|
||||
@@ -19,17 +18,41 @@
|
||||
<u-loading mode="circle" />
|
||||
</view>
|
||||
|
||||
<view v-if="session && !isMutual" class="relationship-notice">
|
||||
<text>{{ relationshipText }}</text>
|
||||
<view v-if="relationshipNoticeText" class="relationship-notice">
|
||||
<view class="relationship-notice__inner">
|
||||
<text class="relationship-notice__text">{{ relationshipNoticeText }}</text>
|
||||
<text
|
||||
v-if="showAddFriendAction"
|
||||
class="relationship-notice__action"
|
||||
@tap.stop="handleAddFriend"
|
||||
>
|
||||
{{ addingFriend ? '添加中' : addFriendActionText }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-for="item in messages" :id="'msg-' + item.id" :key="item.id" class="message-row"
|
||||
:class="{ 'message-row--self': item.is_self }">
|
||||
<view class="message-bubble" :class="{ 'message-bubble--image': item.message_type === 'image' }">
|
||||
<text v-if="item.message_type === 'text'" class="message-bubble__text">{{ item.content }}</text>
|
||||
<image v-else class="message-bubble__image" :src="item.content" mode="widthFix"
|
||||
@tap="previewImage(item.content)" />
|
||||
<image
|
||||
v-if="!item.is_self"
|
||||
class="message-row__avatar"
|
||||
:src="targetUser?.avatar || defaultAvatar"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<view class="message-row__body">
|
||||
<text v-if="!item.is_self" class="message-row__name">{{ targetUser?.nickname || '对方' }}</text>
|
||||
<view class="message-bubble" :class="{ 'message-bubble--image': item.message_type === 'image' }">
|
||||
<text v-if="item.message_type === 'text'" class="message-bubble__text">{{ item.content }}</text>
|
||||
<image v-else class="message-bubble__image" :src="item.content" mode="widthFix"
|
||||
@tap="previewImage(item.content)" />
|
||||
</view>
|
||||
</view>
|
||||
<image
|
||||
v-if="item.is_self"
|
||||
class="message-row__avatar message-row__avatar--self"
|
||||
:src="myAvatar"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view v-if="!loading && messages.length === 0" class="message-empty">
|
||||
@@ -86,9 +109,14 @@ import {
|
||||
} from '@/api/chat'
|
||||
import { uploadImage } from '@/api/app'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { toggleFollow } from '@/api/community'
|
||||
|
||||
const defaultAvatar = '/static/images/avatar.png'
|
||||
const notMutualText = '对方还未添加你为好友'
|
||||
const notFollowedText = '对方未添加好友'
|
||||
const waitingMutualText = '对方未添加互关'
|
||||
const followedMeText = '对方已关注'
|
||||
const userStore = useUserStore()
|
||||
const statusBarHeight = ref(0)
|
||||
const sessionId = ref(0)
|
||||
const targetUserId = ref(0)
|
||||
@@ -103,6 +131,7 @@ const voiceSupported = ref(false)
|
||||
const recording = ref(false)
|
||||
const transcribing = ref(false)
|
||||
const recordSeconds = ref(0)
|
||||
const addingFriend = ref(false)
|
||||
const scrollIntoView = ref('')
|
||||
let pollTimer: ReturnType<typeof setInterval> | null = null
|
||||
let recordTimer: ReturnType<typeof setInterval> | null = null
|
||||
@@ -111,9 +140,23 @@ let recordCancelled = false
|
||||
let recordStartAt = 0
|
||||
|
||||
const targetUser = computed(() => session.value?.target_user || null)
|
||||
const isMutual = computed(() => !!session.value?.relationship?.is_mutual)
|
||||
const relationshipText = computed(() => {
|
||||
return session.value?.relationship?.relationship_text || (isMutual.value ? '互相关注' : notMutualText)
|
||||
const isMutual = computed(() => {
|
||||
const relation = session.value?.relationship
|
||||
return !!(relation?.is_mutual || (relation?.is_followed_by_me && relation?.is_following_me))
|
||||
})
|
||||
const myAvatar = computed(() => userStore.userInfo?.avatar || defaultAvatar)
|
||||
const relationshipNoticeText = computed(() => {
|
||||
const relation = session.value?.relationship
|
||||
if (!relation || relation.is_mutual) return ''
|
||||
if (relation.is_followed_by_me) return waitingMutualText
|
||||
if (relation.is_following_me) return followedMeText
|
||||
return notFollowedText
|
||||
})
|
||||
const showAddFriendAction = computed(() => {
|
||||
return !!session.value && !isMutual.value && !session.value.relationship?.is_followed_by_me
|
||||
})
|
||||
const addFriendActionText = computed(() => {
|
||||
return session.value?.relationship?.is_following_me ? '添加互关' : '添加好友'
|
||||
})
|
||||
const toolDisabled = computed(() => sending.value || recording.value || transcribing.value || !sessionId.value)
|
||||
const canSend = computed(() => inputText.value.trim().length > 0 && !toolDisabled.value)
|
||||
@@ -144,6 +187,9 @@ onLoad(async (options) => {
|
||||
voiceSupported.value = true
|
||||
initRecorder()
|
||||
// #endif
|
||||
if (getToken() && !userStore.userInfo?.id) {
|
||||
userStore.getUser().catch(() => { })
|
||||
}
|
||||
|
||||
sessionId.value = Number(options?.session_id || 0)
|
||||
targetUserId.value = Number(options?.target_user_id || 0)
|
||||
@@ -237,6 +283,46 @@ const stopPolling = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleAddFriend = async () => {
|
||||
if (addingFriend.value || !showAddFriendAction.value) return
|
||||
const followUserId = Number(targetUser.value?.id || session.value?.target_user_id || targetUserId.value || 0)
|
||||
if (!followUserId) {
|
||||
uni.showToast({ title: '用户信息异常', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
addingFriend.value = true
|
||||
try {
|
||||
const res: any = await toggleFollow({ follow_user_id: followUserId })
|
||||
const followed = !!res?.is_followed
|
||||
if (!followed) {
|
||||
uni.showToast({ title: '添加失败,请重试', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
if (session.value) {
|
||||
const oldRelation = session.value.relationship || {}
|
||||
const isFollowingMe = !!oldRelation.is_following_me
|
||||
const relation = {
|
||||
...oldRelation,
|
||||
is_followed_by_me: true,
|
||||
is_following_me: isFollowingMe,
|
||||
is_mutual: isFollowingMe,
|
||||
relationship_text: isFollowingMe ? '互相关注' : waitingMutualText
|
||||
}
|
||||
session.value = {
|
||||
...session.value,
|
||||
relationship: relation
|
||||
}
|
||||
}
|
||||
uni.showToast({ title: '已添加好友', icon: 'success' })
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '添加失败,请重试', icon: 'none' })
|
||||
} finally {
|
||||
addingFriend.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const sendText = async () => {
|
||||
const content = inputText.value.trim()
|
||||
if (!content || !canSend.value) return
|
||||
@@ -502,12 +588,6 @@ const goBack = () => {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__relation {
|
||||
margin-top: 4rpx;
|
||||
font-size: 22rpx;
|
||||
color: #185dff;
|
||||
line-height: 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
.message-list {
|
||||
@@ -522,25 +602,78 @@ const goBack = () => {
|
||||
justify-content: center;
|
||||
margin: 4rpx 0 28rpx;
|
||||
|
||||
text {
|
||||
height: 42rpx;
|
||||
&__inner {
|
||||
min-height: 42rpx;
|
||||
padding: 0 18rpx;
|
||||
border-radius: 8rpx;
|
||||
background: rgba(17, 24, 39, 0.08);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
&__text {
|
||||
color: #4b5563;
|
||||
font-size: 22rpx;
|
||||
line-height: 42rpx;
|
||||
}
|
||||
|
||||
&__action {
|
||||
color: #185dff;
|
||||
font-size: 22rpx;
|
||||
line-height: 42rpx;
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.message-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: flex-start;
|
||||
margin-bottom: 22rpx;
|
||||
|
||||
&__avatar {
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
margin-right: 14rpx;
|
||||
border-radius: 8rpx;
|
||||
background: #dbe3ee;
|
||||
flex-shrink: 0;
|
||||
|
||||
&--self {
|
||||
margin-right: 0;
|
||||
margin-left: 14rpx;
|
||||
}
|
||||
}
|
||||
|
||||
&__body {
|
||||
max-width: calc(100% - 78rpx);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__name {
|
||||
max-width: 360rpx;
|
||||
margin-bottom: 8rpx;
|
||||
color: #6b7280;
|
||||
font-size: 22rpx;
|
||||
line-height: 1.2;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&--self {
|
||||
justify-content: flex-end;
|
||||
|
||||
.message-row__body {
|
||||
max-width: calc(100% - 78rpx);
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.message-bubble {
|
||||
background: #185dff;
|
||||
border-color: #185dff;
|
||||
@@ -555,7 +688,7 @@ const goBack = () => {
|
||||
}
|
||||
|
||||
.message-bubble {
|
||||
max-width: 78%;
|
||||
max-width: 100%;
|
||||
padding: 18rpx 22rpx;
|
||||
border-radius: 8rpx;
|
||||
background: #fff;
|
||||
|
||||
Reference in New Issue
Block a user