Commit 968ba0f0 authored by spc's avatar spc

back

parent 6f2a1424
......@@ -59,7 +59,7 @@
</template>
<script setup>
import { ref, onMounted, computed } from 'vue'
import { ref, onMounted, computed, onUnmounted } from 'vue'
import { xingmaLabDetailConfig, getImageUrl } from './config.js'
import { fetchRecordDetail, fetchFavoriteAdd, fetchFavoriteRemove } from '@/api/xingmaLab.js'
import { useHomeStore } from '@/stores/home.js'
......@@ -100,6 +100,18 @@ const formatTime = (timeStr) => {
return `${year}-${month}-${day} `
}
// 同步收藏状态到上一页
const syncCollectionStatusToPrevPage = () => {
const pages = getCurrentPages()
if (pages.length > 1) {
let prevPage = pages[pages.length - 2]
prevPage.setData({
isFavorite: detailData.value.collection ? 1 : -1
})
console.log('✅ 收藏状态已同步到上一页:', detailData.value.collection ? 1 : -1)
}
}
// 获取详情数据
const fetchDetailData = async (id) => {
try {
......@@ -114,6 +126,9 @@ const fetchDetailData = async (id) => {
detailData.value = result.data
recordId.value = id // 保存记录ID
console.log('✅ 详情数据获取成功:', detailData.value)
// 初始化时同步收藏状态到上一页
syncCollectionStatusToPrevPage()
} else {
throw new Error(result.message || '获取详情失败')
}
......@@ -180,6 +195,8 @@ const handleLikeClick = async () => {
const result = await fetchFavoriteRemove({ relationId: recordId })
if (result.success) {
detailData.value.collection = false
// 更新时同步收藏状态到上一页
syncCollectionStatusToPrevPage()
uni.showToast({
title: '已取消收藏',
icon: 'none'
......@@ -192,6 +209,8 @@ const handleLikeClick = async () => {
const result = await fetchFavoriteAdd({ relationId: recordId })
if (result.success) {
detailData.value.collection = true
// 更新时同步收藏状态到上一页
syncCollectionStatusToPrevPage()
uni.showToast({
title: '收藏成功',
icon: 'none'
......@@ -228,20 +247,15 @@ const handleShareClick = () => {
// })
}
// 返回上一页
const handleGoBack = () => {
// 检查是否有上一页
const pages = getCurrentPages()
console.log('pages', pages)
if (pages.length > 1) {
let prevPage = pages[pages.length - 2]
prevPage.setData({
isFavorite: detailData.value.collection ? 1 : -1
})
// 有上一页,返回上一页
// 有上一页,直接返回上一页(收藏状态已在更新时同步)
uni.navigateBack({
delta: 1
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment