收藏牌位1.0

This commit is contained in:
minimaxagent1 2025-08-12 11:10:38 +08:00
parent f478fc00a7
commit ad30e079bc
2 changed files with 120 additions and 7 deletions

View File

@ -24,4 +24,33 @@ export function searchDeceased(params) {
method: 'get',
params
})
}
}
// 收藏牌位 (使用 x-www-form-urlencoded 格式)
export function collectMemorial(data) {
// 将数据转换为 x-www-form-urlencoded 格式
return request({
url: '/app/collect',
method: 'post',
data,
header: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
}
// // 收藏牌位 (使用 form-data 格式,可选)
// export function collectMemorialFormData(data) {
// return request({
// url: '/app/collect',
// method: 'post',
// data,
// header: {
// 'Content-Type': 'multipart/form-data'
// }
// })
// }

View File

@ -21,7 +21,12 @@
<!-- 顶部信息 -->
<view class="memorial-header">
<view class="location">{{ memorialDetail ? memorialDetail.name : '加载中...' }}</view>
<view class="collection-btn">收藏牌位</view>
<view
:class="['collection-btn', { 'collected': isCollected }]"
@click="handleCollect"
>
{{ isCollected ? '已收藏' : '收藏牌位' }}
</view>
</view>
<!-- 刻铭标题 -->
@ -131,7 +136,7 @@
<script>
import {CommonEnum} from '@/enum/common.js'
import { getDeceasedList, getMemorialDetail } from '@/api/memorial/index.js'
import { getEnshrinedList } from '@/api/memorial/memorial.js'
import { getEnshrinedList, collectMemorial } from '@/api/memorial/memorial.js'
import SearchBox from "../../components/search-box/search-box.vue"
import StatusDisplay from "../../components/status-display/status-display.vue"
import EnshrinedList from "./compositons/enshrinedList.vue"
@ -167,7 +172,9 @@ export default {
//
scrollTop: 0,
//
showOfferingModal: false
showOfferingModal: false,
//
isCollected: false
}
},
onLoad(options) {
@ -242,9 +249,9 @@ export default {
}
//
if (this.searchName) {
params.keyword = this.searchName
}
// if (this.searchName) {
// params.keyword = this.searchName
// }
const response = await getDeceasedList(params)//api
@ -267,6 +274,56 @@ export default {
}
},
//
async handleCollect() {
if (!this.selectedUnitId) {
uni.showToast({
title: '无法获取牌位信息',
icon: 'none'
})
return
}
//
if (this.isCollected) {
uni.showToast({
title: '已经收藏过了',
icon: 'none'
})
return
}
try {
uni.showLoading({
title: '收藏中...'
})
const data = {
messageId: this.selectedUnitId.toString()
}
const response = await collectMemorial(data)
if (response.code === 200) {
this.isCollected = true
uni.showToast({
title: '收藏成功',
icon: 'success'
})
} else {
throw new Error(response.msg || '收藏失败')
}
} catch (error) {
console.error('收藏失败:', error)
uni.showToast({
title: error.message || '收藏失败',
icon: 'none'
})
} finally {
uni.hideLoading()
}
},
//
async handleSearch(value) {
console.log('搜索内容:', value)
@ -411,6 +468,33 @@ export default {
height: 56rpx;
background: #A24242;
border-radius: 8rpx 8rpx 8rpx 8rpx;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
justify-content: center;
align-items: center;
&:active {
background: #8B3A3A;
transform: scale(0.95);
}
&:hover {
background: #B85A5A;
}
//
&.collected {
background: #4CAF50;
&:hover {
background: #45A049;
}
&:active {
background: #3D8B40;
}
}
}
}
.title {