fix: not login
This commit is contained in:
@@ -24,9 +24,10 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import ActionBadge from "@/components/ActionBadge/ActionBadge.vue";
|
||||
import { topicItemCommentLike } from "@/api/topicItem";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
|
||||
const props = defineProps({
|
||||
comment: {
|
||||
@@ -36,6 +37,10 @@ const props = defineProps({
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['need-login']);
|
||||
const userStore = useUserStore();
|
||||
const isLoggedIn = computed(() => !!userStore.token || !!userStore.userInfo?.nickName);
|
||||
|
||||
const isLiked = ref(props.comment.isLiked || false);
|
||||
const currentLikes = ref(props.comment.likes || 0);
|
||||
let isLiking = false; // 防抖标志
|
||||
@@ -49,6 +54,11 @@ watch(() => props.comment.isLiked, (newVal) => {
|
||||
});
|
||||
|
||||
const handleLike = async () => {
|
||||
if (!isLoggedIn.value) {
|
||||
emit('need-login');
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLiking) return;
|
||||
isLiking = true;
|
||||
|
||||
@@ -206,4 +216,4 @@ const handleLike = async () => {
|
||||
line-height: 1.65;
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -52,7 +52,10 @@
|
||||
|
||||
<view class="action-buttons">
|
||||
<button class="btn-primary" @tap="navTo('profile')">编辑资料</button>
|
||||
<button class="btn-secondary" open-type="share">
|
||||
<button v-if="isLoggedIn" class="btn-secondary" open-type="share">
|
||||
<text class="share-icon-btn"></text> 分享主页
|
||||
</button>
|
||||
<button v-else class="btn-secondary" @tap="openLoginPopup('请先登录后再分享主页')">
|
||||
<text class="share-icon-btn"></text> 分享主页
|
||||
</button>
|
||||
</view>
|
||||
@@ -175,7 +178,7 @@ onShareTimeline(async () => {
|
||||
|
||||
const handleUserClick = () => {
|
||||
if (!isLoggedIn.value) {
|
||||
loginPopupRef.value.open();
|
||||
openLoginPopup("请先登录");
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: "/pages/mine/profile",
|
||||
@@ -187,10 +190,16 @@ const handleLogind = async () => {
|
||||
loadUserStats();
|
||||
};
|
||||
|
||||
const openLoginPopup = (message = "请先登录") => {
|
||||
loginPopupRef.value.open();
|
||||
if (message) {
|
||||
uni.showToast({ title: message, icon: "none" });
|
||||
}
|
||||
};
|
||||
|
||||
const navTo = (page) => {
|
||||
if (!isLoggedIn.value) {
|
||||
loginPopupRef.value.open();
|
||||
uni.showToast({ title: "请先登录", icon: "none" });
|
||||
openLoginPopup("请先登录");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@
|
||||
v-for="(comment, index) in comments"
|
||||
:key="comment.id"
|
||||
:comment="comment"
|
||||
@need-login="openLoginPopup"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -103,37 +104,49 @@
|
||||
|
||||
<!-- 评分成功特效弹窗 -->
|
||||
<SuccessPopup ref="successPopupRef" />
|
||||
<LoginPopup ref="loginPopupRef" @logind="handleLoginSuccess" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import { getStatusBarHeight } from "@/utils/system";
|
||||
import { onLoad, onPullDownRefresh, onReachBottom, onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
|
||||
import AttitudePanel from "@/components/AttitudePanel/AttitudePanel.vue";
|
||||
import SuccessPopup from "@/components/SuccessPopup/SuccessPopup.vue";
|
||||
import ActionBadge from "@/components/ActionBadge/ActionBadge.vue";
|
||||
import CommentItem from "@/components/CommentItem/CommentItem.vue";
|
||||
import LoginPopup from "@/components/LoginPopup/LoginPopup.vue";
|
||||
import { FILE_BASE_URL } from "@/utils/constants";
|
||||
import { fetchTopicRatingItems, topicItemScore, topicItemComment, topicItemCommentList } from "@/api/topicItem";
|
||||
import { formatDate } from "@/utils/date";
|
||||
import { getShareToken } from "@/utils/common";
|
||||
import { getShareReward } from "@/api/system";
|
||||
|
||||
|
||||
|
||||
import { useUserStore } from "@/stores/user";
|
||||
const userStore = useUserStore();
|
||||
const statusBarHeight = ref(getStatusBarHeight() || 44);
|
||||
const loading = ref(false);
|
||||
const hasMore = ref(true);
|
||||
const currentPage = ref(1);
|
||||
const currentAction = ref('');
|
||||
const successPopupRef = ref(null);
|
||||
const loginPopupRef = ref(null);
|
||||
const currentTab = ref('hot'); // 'hot' 或 'new'
|
||||
const isLoggedIn = computed(() => !!userStore.token || !!userStore.userInfo?.nickName);
|
||||
|
||||
const goBack = () => {
|
||||
uni.navigateBack();
|
||||
};
|
||||
|
||||
const openLoginPopup = (message = '请先登录后再操作') => {
|
||||
loginPopupRef.value?.open();
|
||||
if (message) {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const detailData = ref({
|
||||
id: '',
|
||||
name: '',
|
||||
@@ -148,6 +161,11 @@ const comments = ref([]);
|
||||
const itemId = ref('');
|
||||
|
||||
const handleActionChange = async (action) => {
|
||||
if (!isLoggedIn.value) {
|
||||
openLoginPopup();
|
||||
return;
|
||||
}
|
||||
|
||||
const originAction = detailData.value.userAction;
|
||||
const originScore = detailData.value.score;
|
||||
const isCancel = detailData.value.userAction === action.label;
|
||||
@@ -170,14 +188,14 @@ const handleActionChange = async (action) => {
|
||||
uni.$trackRecord({
|
||||
eventName: 'rating',
|
||||
eventType: 'rating',
|
||||
elementId: `item_${item.id}`,
|
||||
elementContent: `评分项_${item.name}`,
|
||||
elementId: `item_${itemId.value}`,
|
||||
elementContent: `评分项_${detailData.value.name}`,
|
||||
customParams: {
|
||||
scoreType: action.scoreType,
|
||||
action: action.label,
|
||||
topicId: currentTopicId.value,
|
||||
topicTitle: topicData.value.title,
|
||||
score: item.scoreAvg,
|
||||
topicId: detailData.value.topicId,
|
||||
topicTitle: detailData.value.name,
|
||||
score: detailData.value.score,
|
||||
page: 'rating_detail'
|
||||
}
|
||||
});
|
||||
@@ -189,6 +207,11 @@ const handleActionChange = async (action) => {
|
||||
};
|
||||
|
||||
const handleSendComment = async (payload) => {
|
||||
if (!isLoggedIn.value) {
|
||||
openLoginPopup();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!detailData.value.topicId || !itemId.value) return;
|
||||
|
||||
try {
|
||||
@@ -215,8 +238,8 @@ const handleSendComment = async (payload) => {
|
||||
uni.$trackRecord({
|
||||
eventName: 'comment',
|
||||
eventType: 'comment',
|
||||
elementId: `item_${item.id}`,
|
||||
elementContent: `评论项_${item.name}`,
|
||||
elementId: `item_${itemId.value}`,
|
||||
elementContent: `评论项_${detailData.value.name}`,
|
||||
customParams: {
|
||||
comment: payload.content,
|
||||
page: 'rating_detail'
|
||||
@@ -339,6 +362,13 @@ onLoad((options) => {
|
||||
}
|
||||
});
|
||||
|
||||
const handleLoginSuccess = () => {
|
||||
currentPage.value = 1;
|
||||
hasMore.value = true;
|
||||
comments.value = [];
|
||||
getDetailData();
|
||||
};
|
||||
|
||||
onShareAppMessage(async () => {
|
||||
const shareToken = await getShareToken("rating_item");
|
||||
getShareReward({ scene: "rating_item" });
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 右下角悬浮添加按钮 -->
|
||||
<view class="fab-btn" @tap="showAddPopup = true">
|
||||
<view class="fab-btn" @tap="handleAddClick">
|
||||
<text class="plus-icon">+</text>
|
||||
</view>
|
||||
|
||||
@@ -150,22 +150,26 @@
|
||||
|
||||
<!-- 评分成功特效弹窗 -->
|
||||
<SuccessPopup ref="successPopupRef" />
|
||||
<LoginPopup ref="loginPopupRef" @logind="handleLoginSuccess" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import { getStatusBarHeight } from "@/utils/system";
|
||||
import { onPullDownRefresh, onReachBottom, onLoad, onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
|
||||
import { fetchTopicDetail, fetchTopicRatingItems } from "@/api/topic";
|
||||
import { FILE_BASE_URL } from "@/utils/constants";
|
||||
import RatingCard from "@/components/RatingCard/RatingCard.vue";
|
||||
import SuccessPopup from "@/components/SuccessPopup/SuccessPopup.vue";
|
||||
import LoginPopup from "@/components/LoginPopup/LoginPopup.vue";
|
||||
import { topicItemScore, topicItemAdd } from "@/api/topicItem";
|
||||
import { uploadImage } from "@/utils/common";
|
||||
import { getShareToken } from "@/utils/common";
|
||||
import { getShareReward } from "@/api/system";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
// 状态栏高度处理
|
||||
const userStore = useUserStore();
|
||||
const statusBarHeight = ref(getStatusBarHeight() || 44);
|
||||
|
||||
const loading = ref(false);
|
||||
@@ -173,6 +177,8 @@ const hasMore = ref(true);
|
||||
const currentPage = ref(1);
|
||||
const currentTopicId = ref(null);
|
||||
const successPopupRef = ref(null);
|
||||
const loginPopupRef = ref(null);
|
||||
const isLoggedIn = computed(() => !!userStore.token || !!userStore.userInfo?.nickName);
|
||||
|
||||
const goBack = () => {
|
||||
uni.navigateBack({
|
||||
@@ -180,6 +186,13 @@ const goBack = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const openLoginPopup = (message = '请先登录后再操作') => {
|
||||
loginPopupRef.value?.open();
|
||||
if (message) {
|
||||
uni.showToast({ title: message, icon: 'none' });
|
||||
}
|
||||
};
|
||||
|
||||
const topicData = ref({
|
||||
title: '',
|
||||
heat: '0',
|
||||
@@ -211,6 +224,11 @@ const newItem = ref({
|
||||
});
|
||||
|
||||
const chooseAvatar = () => {
|
||||
if (!isLoggedIn.value) {
|
||||
openLoginPopup();
|
||||
return;
|
||||
}
|
||||
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
success: (res) => {
|
||||
@@ -220,6 +238,11 @@ const chooseAvatar = () => {
|
||||
};
|
||||
|
||||
const confirmAddItem = async () => {
|
||||
if (!isLoggedIn.value) {
|
||||
openLoginPopup();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!newItem.value.name.trim()) {
|
||||
uni.showToast({ title: '请输入名称', icon: 'none' });
|
||||
return;
|
||||
@@ -314,6 +337,11 @@ const mockComments = [
|
||||
const comments = ref([...mockComments]);
|
||||
|
||||
const handleAction = async (item, action) => {
|
||||
if (!isLoggedIn.value) {
|
||||
openLoginPopup();
|
||||
return;
|
||||
}
|
||||
|
||||
const originAction = item.userAction;
|
||||
const originScore = item.scoreAvg;
|
||||
const isCancel = item.userAction === action.label;
|
||||
@@ -363,6 +391,24 @@ const goToDetail = (itemId) => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleAddClick = () => {
|
||||
if (!isLoggedIn.value) {
|
||||
openLoginPopup();
|
||||
return;
|
||||
}
|
||||
showAddPopup.value = true;
|
||||
};
|
||||
|
||||
const handleLoginSuccess = async () => {
|
||||
if (!currentTopicId.value) return;
|
||||
currentPage.value = 1;
|
||||
hasMore.value = true;
|
||||
await Promise.all([
|
||||
loadDetail(currentTopicId.value),
|
||||
loadItems(currentTopicId.value, 1)
|
||||
]);
|
||||
};
|
||||
|
||||
onShareAppMessage(async () => {
|
||||
const shareToken = await getShareToken("rating_topic");
|
||||
getShareReward({ scene: "rating_topic" });
|
||||
|
||||
Reference in New Issue
Block a user