fix: rating

This commit is contained in:
zzc
2026-06-09 23:55:11 +08:00
parent 36dbf05c11
commit d4478cccd8
8 changed files with 101 additions and 58 deletions

View File

@@ -64,6 +64,18 @@ const handleLike = async () => {
try { try {
// 调用点赞接口 (点赞和取消点赞为同一个接口) // 调用点赞接口 (点赞和取消点赞为同一个接口)
await topicItemCommentLike({ commentId: props.comment.id }); await topicItemCommentLike({ commentId: props.comment.id });
// 记录点赞事件
uni.$trackRecord({
eventName: 'like_comment',
eventType: 'like',
elementId: `comment_${props.comment.id}`,
elementContent: `评论项_${props.comment.name}`,
customParams: {
comment: props.comment.content,
page: 'rating_detail'
}
});
uni.showToast({ title: '操作成功', icon: 'success' });
} catch (error) { } catch (error) {
// 接口调用失败,回滚 UI 状态 // 接口调用失败,回滚 UI 状态
isLiked.value = !isLiked.value; isLiked.value = !isLiked.value;

View File

@@ -3,7 +3,7 @@
{ {
"path": "pages/index/index", "path": "pages/index/index",
"style": { "style": {
"navigationBarTitleText": "全民评分", "navigationBarTitleText": "夯拉评分",
"enablePullDownRefresh": true, "enablePullDownRefresh": true,
"navigationStyle": "custom", "navigationStyle": "custom",
"backgroundColor": "#FFFFFF" "backgroundColor": "#FFFFFF"
@@ -67,7 +67,7 @@
{ {
"path": "pages/rating/index", "path": "pages/rating/index",
"style": { "style": {
"navigationBarTitleText": "全民评分", "navigationBarTitleText": "夯拉评分",
"navigationStyle": "custom", "navigationStyle": "custom",
"enablePullDownRefresh": true "enablePullDownRefresh": true
} }

View File

@@ -10,7 +10,7 @@
@tap="handleLogin" @tap="handleLogin"
/> />
<view class="header-texts"> <view class="header-texts">
<text class="title">全民评分</text> <text class="title">夯拉评分</text>
<text class="subtitle">看看全国网友怎么评分</text> <text class="subtitle">看看全国网友怎么评分</text>
</view> </view>
</view> </view>
@@ -136,58 +136,27 @@ const loadTopicList = async (categoryId, page = 1) => {
const switchCategory = (categoryId) => { const switchCategory = (categoryId) => {
if (currentCategoryId.value === categoryId) return; if (currentCategoryId.value === categoryId) return;
currentCategoryId.value = categoryId; currentCategoryId.value = categoryId;
uni.$trackRecord({
// 切换分类时重新加载数据 eventName: 'switch_category',
eventType: 'click',
elementId: `category_${categoryId}`,
elementContent: categories.value.find(c => c.id === categoryId)?.title || '未知分类',
});
// 切换分类时重新加载数据
currentPage.value = 1; currentPage.value = 1;
hasMore.value = true; hasMore.value = true;
loadTopicList(categoryId, currentPage.value); loadTopicList(categoryId, currentPage.value);
}; };
const mockData = [ const topicList = ref([]);
{
id: 1,
title: '你心中的千古一帝',
participants: '23.5万',
heat: '98k',
items: [
{ id: 1, name: '李世民', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=1', score: '9.8' },
{ id: 2, name: '秦始皇', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=2', score: '9.5' },
{ id: 3, name: '康熙', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=3', score: '9.2' },
],
aiSummary: '多数用户认为李世民综合能力最强,兼具文治武功。',
tags: ['历史', '皇帝', '争议']
},
{
id: 2,
title: '国产手机系统谁最强',
participants: '15万',
heat: '76k',
items: [
{ id: 1, name: 'iOS', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=4', score: '8.5' },
{ id: 2, name: 'HyperOS', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=5', score: '8.2' },
{ id: 3, name: 'OriginOS', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=6', score: '8.0' },
],
aiSummary: '系统流畅度与动效是用户关注的核心,底层优化成为评分关键。',
tags: ['数码', '手机', '测评']
},
{
id: 3,
title: '最值得定居的城市',
participants: '12.8万',
heat: '62k',
items: [
{ id: 1, name: '成都', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=7', score: '9.2' },
{ id: 2, name: '杭州', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=8', score: '8.9' },
{ id: 3, name: '厦门', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=9', score: '8.7' },
],
aiSummary: '宜居性与就业机会是主要博弈点,慢节奏生活深受青睐。',
tags: ['城市', '生活', '推荐']
}
];
const topicList = ref([...mockData]);
const goToRating = (topicId, itemId) => { const goToRating = (topicId, itemId) => {
uni.$trackRecord({
eventName: 'jumpto_rating',
eventType: 'jump',
elementId: `topic_${topicId}`,
elementContent: `主题${topicId}`,
});
uni.navigateTo({ uni.navigateTo({
url: `/pages/rating/index?topicId=${topicId}&itemId=${itemId}` url: `/pages/rating/index?topicId=${topicId}&itemId=${itemId}`
}); });
@@ -248,7 +217,7 @@ onShareAppMessage(async () => {
const shareToken = await getShareToken("index"); const shareToken = await getShareToken("index");
getShareReward(); getShareReward();
return { return {
title: "全民评分", title: "夯拉评分",
path: "/pages/index/index?shareToken=" + shareToken, path: "/pages/index/index?shareToken=" + shareToken,
}; };
}); });
@@ -257,7 +226,7 @@ onShareTimeline(async () => {
const shareToken = await getShareToken("index"); const shareToken = await getShareToken("index");
getShareReward(); getShareReward();
return { return {
title: "全民评分", title: "夯拉评分",
query: `shareToken=${shareToken}`, query: `shareToken=${shareToken}`,
}; };
}); });

View File

@@ -5,7 +5,7 @@
<view class="nav-content"> <view class="nav-content">
<view class="nav-left" @tap="goBack"> <view class="nav-left" @tap="goBack">
<text class="back-icon"></text> <text class="back-icon"></text>
<text class="nav-title">全民评分</text> <text class="nav-title">夯拉评分</text>
</view> </view>
<view class="nav-right"> <view class="nav-right">
<text class="search-icon"></text> <text class="search-icon"></text>
@@ -50,7 +50,7 @@
/> />
<!-- 大家都在 PK --> <!-- 大家都在 PK -->
<view class="pk-panel card"> <!-- <view class="pk-panel card">
<view class="pk-header"> <view class="pk-header">
<text class="section-title">大家都在 PK</text> <text class="section-title">大家都在 PK</text>
<view class="go-compare">去对比<text class="arrow-right"></text></view> <view class="go-compare">去对比<text class="arrow-right"></text></view>
@@ -74,7 +74,7 @@
<text class="blue-text">63% 支持</text> <text class="blue-text">63% 支持</text>
<text class="yellow-text">37% 支持</text> <text class="yellow-text">37% 支持</text>
</view> </view>
</view> </view> -->
<!-- 评论区 --> <!-- 评论区 -->
<view class="comments-section card"> <view class="comments-section card">
@@ -165,6 +165,20 @@ const handleActionChange = async (action) => {
if (!isCancel && successPopupRef.value) { if (!isCancel && successPopupRef.value) {
successPopupRef.value.show(action); successPopupRef.value.show(action);
} }
uni.$trackRecord({
eventName: 'rating',
eventType: 'rating',
elementId: `item_${item.id}`,
elementContent: `评分项_${item.name}`,
customParams: {
scoreType: action.scoreType,
action: action.label,
topicId: currentTopicId.value,
topicTitle: topicData.value.title,
score: item.scoreAvg,
page: 'rating_detail'
}
});
} catch (error) { } catch (error) {
detailData.value.userAction = originAction; detailData.value.userAction = originAction;
detailData.value.score = originScore; detailData.value.score = originScore;
@@ -196,6 +210,16 @@ const handleSendComment = async (payload) => {
currentPage.value = 1; currentPage.value = 1;
hasMore.value = true; hasMore.value = true;
comments.value = []; comments.value = [];
uni.$trackRecord({
eventName: 'comment',
eventType: 'comment',
elementId: `item_${item.id}`,
elementContent: `评论项_${item.name}`,
customParams: {
comment: payload.content,
page: 'rating_detail'
}
});
getCommentsData(); getCommentsData();
} catch (error) { } catch (error) {
uni.hideLoading(); uni.hideLoading();

View File

@@ -7,9 +7,9 @@
<text class="back-icon"></text> <text class="back-icon"></text>
</view> </view>
<view class="nav-logo-wrap"> <view class="nav-logo-wrap">
<image class="nav-logo" src="/static/images/default-avatar.png" mode="aspectFill" /> <image class="nav-logo" src="/static/images/logo.jpg" mode="aspectFill" />
</view> </view>
<text class="nav-title">全民评分</text> <text class="nav-title">夯拉评分</text>
</view> </view>
</view> </view>
@@ -273,7 +273,6 @@ const loadItems = async (topicId, page = 1) => {
ratingItems.value = [...ratingItems.value, ...list]; ratingItems.value = [...ratingItems.value, ...list];
hasMore.value = list.length >= 10; // 假设 pageSize 是 10 hasMore.value = list.length >= 10; // 假设 pageSize 是 10
} catch (error) { } catch (error) {
console.error("获取评分项列表失败:", error);
hasMore.value = false; hasMore.value = false;
} finally { } finally {
loading.value = false; loading.value = false;
@@ -330,6 +329,20 @@ const handleAction = async (item, action) => {
if (!isCancel && successPopupRef.value) { if (!isCancel && successPopupRef.value) {
successPopupRef.value.show(action); successPopupRef.value.show(action);
} }
uni.$trackRecord({
eventName: 'rating',
eventType: 'rating',
elementId: `item_${item.id}`,
elementContent: `评分项_${item.name}`,
customParams: {
scoreType: action.scoreType,
action: action.label,
topicId: currentTopicId.value,
topicTitle: topicData.value.title,
score: item.scoreAvg,
page: 'rating'
}
});
} catch (error) { } catch (error) {
item.userAction = originAction; item.userAction = originAction;
item.scoreAvg = originScore; item.scoreAvg = originScore;
@@ -337,6 +350,12 @@ const handleAction = async (item, action) => {
}; };
const goToDetail = (itemId) => { const goToDetail = (itemId) => {
uni.$trackRecord({
eventName: 'jumpto_detail',
eventType: 'jump',
elementId: `item_${itemId}`,
elementContent: `评分项${itemId}`,
});
uni.navigateTo({ uni.navigateTo({
url: `/pages/rating/detail?itemId=${itemId}&topicId=${currentTopicId.value}` url: `/pages/rating/detail?itemId=${itemId}&topicId=${currentTopicId.value}`
}); });
@@ -417,7 +436,6 @@ onReachBottom(() => {
width: 56rpx; width: 56rpx;
height: 56rpx; height: 56rpx;
border-radius: 50%; border-radius: 50%;
background: linear-gradient(135deg, #001f3f, #0088a9);
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;

View File

@@ -151,7 +151,7 @@
</view> </view>
<view class="footer-bar"> <view class="footer-bar">
<button class="submit-btn" @tap="handleSubmit">发布全民评分</button> <button class="submit-btn" @tap="handleSubmit">发布夯拉评分</button>
</view> </view>
</view> </view>
</template> </template>
@@ -321,6 +321,17 @@ const handleSubmit = async () => {
participants: participants.value, participants: participants.value,
}; };
await releaseTopic(payload); await releaseTopic(payload);
// 记录发布事件
uni.$trackRecord({
eventName: 'release_topic',
eventType: 'release',
elementContent: `话题_${payload.title}`,
customParams: {
title: payload.title,
categoryId: payload.categoryId,
}
});
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({

BIN
static/images/logo.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -154,6 +154,15 @@ export const getShareToken = async (scene, targetId = "") => {
return shareTokenRes?.shareToken || ""; return shareTokenRes?.shareToken || "";
}; };
/**
* 记录用户行为事件
* @param {Object} event 事件对象,包含事件名称和参数
* eventName 事件名称,例如 'switchCategory'
* eventType 事件类型,例如 'click',可选
* elementId 事件元素 ID例如 'category_123',可选
* elementContent 事件元素内容,例如 '分类1',可选
* customParams 自定义参数,例如 { categoryId: 123 },可选
*/
export const trackRecord = (event) => { export const trackRecord = (event) => {
const pages = getCurrentPages(); const pages = getCurrentPages();
// 核心修复在小程序刚启动或页面尚未压栈时pages 可能为空数组 // 核心修复在小程序刚启动或页面尚未压栈时pages 可能为空数组