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