Commit 968ba0f0 authored by spc's avatar spc

back

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