|
@@ -149,7 +149,15 @@
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</scroll-view>
|
|
</scroll-view>
|
|
|
-
|
|
|
|
|
|
|
+ <!-- 新增:消息发送限制提示 -->
|
|
|
|
|
+ <view class="message-limit-tip">
|
|
|
|
|
+ <!-- 同时判断isVip和hasMessageLimit,增强可靠性 -->
|
|
|
|
|
+ <text v-if="isVip || !hasMessageLimit" class="vip-tip">✨ VIP特权:无发送次数限制</text>
|
|
|
|
|
+ <text v-else class="limit-tip">
|
|
|
|
|
+ 今日剩余可发送消息:{{ Math.max(remainingCount, 0) }} 条<text class="vip-link" @click="goToVipPage">(非VIP每日限5条)</text>
|
|
|
|
|
+ </text>
|
|
|
|
|
+ </view>
|
|
|
|
|
+
|
|
|
<!-- 输入框 -->
|
|
<!-- 输入框 -->
|
|
|
<view class="input-bar">
|
|
<view class="input-bar">
|
|
|
<!-- 语音按钮 -->
|
|
<!-- 语音按钮 -->
|
|
@@ -276,8 +284,10 @@ export default {
|
|
|
|
|
|
|
|
emojis: ['😀', '😃', '😄', '😁', '😆', '😅', '😂', '🤣', '😊', '😇', '🙂', '🙃', '😉', '😌', '😍', '🥰', '😘', '😗', '😙', '😚', '😋', '😛', '😝', '😜', '🤪', '🤨', '🧐', '🤓', '😎', '🤩', '🥳'],
|
|
emojis: ['😀', '😃', '😄', '😁', '😆', '😅', '😂', '🤣', '😊', '😇', '🙂', '🙃', '😉', '😌', '😍', '🥰', '😘', '😗', '😙', '😚', '😋', '😛', '😝', '😜', '🤪', '🤨', '🧐', '🤓', '😎', '🤩', '🥳'],
|
|
|
showMoreOptionsModal: false, // 控制更多选项弹窗显示
|
|
showMoreOptionsModal: false, // 控制更多选项弹窗显示
|
|
|
- showBlockConfirmModal: false // 控制拉黑确认弹窗显示
|
|
|
|
|
-
|
|
|
|
|
|
|
+ showBlockConfirmModal: false, // 控制拉黑确认弹窗显示
|
|
|
|
|
+ isVip: false, // 是否VIP用户
|
|
|
|
|
+ remainingCount: 5, // 剩余可发送消息数(非VIP默认5)
|
|
|
|
|
+ hasMessageLimit: true // 是否有发送限制(VIP为false)
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -355,7 +365,8 @@ export default {
|
|
|
|
|
|
|
|
// 初始化 TIM
|
|
// 初始化 TIM
|
|
|
await this.initTIM();
|
|
await this.initTIM();
|
|
|
-
|
|
|
|
|
|
|
+ // 获取用户消息发送限制(VIP状态+剩余次数)
|
|
|
|
|
+ await this.getUserMessageLimit();
|
|
|
// 等待 SDK Ready 后再加载消息
|
|
// 等待 SDK Ready 后再加载消息
|
|
|
await this.waitForSDKReady();
|
|
await this.waitForSDKReady();
|
|
|
// 先检查拉黑状态
|
|
// 先检查拉黑状态
|
|
@@ -410,6 +421,26 @@ export default {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 跳转到VIP页面
|
|
|
|
|
+ */
|
|
|
|
|
+ goToVipPage() {
|
|
|
|
|
+ console.log('点击跳转VIP页面');
|
|
|
|
|
+ // 替换为你的实际VIP页面路径(例如会员开通页面)
|
|
|
|
|
+ uni.navigateTo({
|
|
|
|
|
+ url: '/pages/vip/index', // 请根据项目实际路径修改
|
|
|
|
|
+ success: () => {
|
|
|
|
|
+ console.log('跳转VIP页面成功');
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: (err) => {
|
|
|
|
|
+ console.error('跳转VIP页面失败:', err);
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: 'VIP页面不存在',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
more(userid) {
|
|
more(userid) {
|
|
|
console.log('点击了更多按钮,开始跳转...', userid);
|
|
console.log('点击了更多按钮,开始跳转...', userid);
|
|
|
// 如果目标页面是普通页面,用navigateTo(保留当前页面);如果是tabbar页面,用switchTab
|
|
// 如果目标页面是普通页面,用navigateTo(保留当前页面);如果是tabbar页面,用switchTab
|
|
@@ -725,6 +756,16 @@ export default {
|
|
|
* 发送文本消息
|
|
* 发送文本消息
|
|
|
*/
|
|
*/
|
|
|
async sendTextMessage() {
|
|
async sendTextMessage() {
|
|
|
|
|
+
|
|
|
|
|
+ if (this.hasMessageLimit && this.remainingCount <= 0) {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: '今日消息发送次数已用完,开通VIP无限制',
|
|
|
|
|
+ icon: 'none',
|
|
|
|
|
+ duration: 2000
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (!this.inputText.trim()) {
|
|
if (!this.inputText.trim()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -794,6 +835,9 @@ export default {
|
|
|
|
|
|
|
|
console.log('✅ 消息发送成功');
|
|
console.log('✅ 消息发送成功');
|
|
|
this.syncMessageToMySQL(message);
|
|
this.syncMessageToMySQL(message);
|
|
|
|
|
+ if (!this.isVip) {
|
|
|
|
|
+ await this.updateMessageCount();
|
|
|
|
|
+ }
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('❌ 消息发送失败:', error);
|
|
console.error('❌ 消息发送失败:', error);
|
|
|
|
|
|
|
@@ -1315,7 +1359,69 @@ export default {
|
|
|
closeBlockConfirm() {
|
|
closeBlockConfirm() {
|
|
|
this.showBlockConfirmModal = false;
|
|
this.showBlockConfirmModal = false;
|
|
|
},
|
|
},
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 从后端获取VIP状态和今日剩余发送次数
|
|
|
|
|
+ */
|
|
|
|
|
+ async getUserMessageLimit() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const [err, res] = await uni.request({
|
|
|
|
|
+ url: 'http://localhost:1004/api/chat/getUserMessageLimit',
|
|
|
|
|
+ method: 'GET',
|
|
|
|
|
+ data: {
|
|
|
|
|
+ userId: this.userId ,// 已在onLoad中初始化的当前用户ID
|
|
|
|
|
+ targetUserId: this.targetUserId
|
|
|
|
|
+ },
|
|
|
|
|
+ header: {
|
|
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (err) throw new Error('网络请求失败');
|
|
|
|
|
+ if (res.data.code !== 200) throw new Error(res.data.message || '获取限制信息失败');
|
|
|
|
|
+
|
|
|
|
|
+ const { isVip, remainingCount, hasMessageLimit } = res.data.data;
|
|
|
|
|
+ this.isVip = isVip;
|
|
|
|
|
+ this.remainingCount = remainingCount;
|
|
|
|
|
+ this.hasMessageLimit = hasMessageLimit;
|
|
|
|
|
|
|
|
|
|
+ console.log('✅ 用户消息限制信息:', { isVip, remainingCount, hasMessageLimit });
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('❌ 获取消息限制失败:', error);
|
|
|
|
|
+ // 异常降级:默认非VIP,剩余5次
|
|
|
|
|
+ this.isVip = false;
|
|
|
|
|
+ this.remainingCount = 5;
|
|
|
|
|
+ this.hasMessageLimit = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送成功后,更新后端计数并同步前端剩余次数
|
|
|
|
|
+ */
|
|
|
|
|
+ async updateMessageCount() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const [err, res] = await uni.request({
|
|
|
|
|
+ url: 'http://localhost:8083/api/chat/updateMessageCount',
|
|
|
|
|
+ method: 'get',
|
|
|
|
|
+ data: {
|
|
|
|
|
+ userId: this.userId ,// 已在onLoad中初始化的当前用户ID
|
|
|
|
|
+ targetUserId: this.targetUserId
|
|
|
|
|
+ },
|
|
|
|
|
+ header: {
|
|
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (err) throw new Error('更新计数失败');
|
|
|
|
|
+ if (res.data.code === 200) {
|
|
|
|
|
+ this.remainingCount = res.data.data.remainingCount; // 同步后端返回的剩余次数
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('❌ 更新发送次数失败:', error);
|
|
|
|
|
+ // 前端本地降级:避免影响用户体验,本地暂减1(刷新页面后同步真实数据)
|
|
|
|
|
+ if (this.remainingCount > 0) {
|
|
|
|
|
+ this.remainingCount--;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
/**
|
|
/**
|
|
|
* 确认拉黑好友
|
|
* 确认拉黑好友
|
|
|
*/
|
|
*/
|
|
@@ -1828,6 +1934,33 @@ export default {
|
|
|
.message-action-menu .menu-icon {
|
|
.message-action-menu .menu-icon {
|
|
|
font-size: 36rpx;
|
|
font-size: 36rpx;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+/* 消息发送限制提示 */
|
|
|
|
|
+.message-limit-tip {
|
|
|
|
|
+ padding: 10rpx 20rpx;
|
|
|
|
|
+ font-size: 24rpx;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
|
+ border-bottom: 1px solid #f5f5f5;
|
|
|
|
|
+}
|
|
|
|
|
+.vip-tip {
|
|
|
|
|
+ color: #ff9500; /* VIP橙色提示 */
|
|
|
|
|
+}
|
|
|
|
|
+.limit-tip {
|
|
|
|
|
+ color: #666; /* 普通灰色提示 */
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.vip-link {
|
|
|
|
|
+ color: #2c9fff; /* 蓝色文字 */
|
|
|
|
|
+ text-decoration: underline; /* 下划线 */
|
|
|
|
|
+ cursor: pointer; /* 鼠标悬浮时显示手型 */
|
|
|
|
|
+ margin-left: 5rpx;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* 点击时添加轻微反馈 */
|
|
|
|
|
+.vip-link:active {
|
|
|
|
|
+ opacity: 0.7; /* 点击时透明度降低 */
|
|
|
|
|
+}
|
|
|
</style>
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|