feat: 支持章节通过 mid 进行访问,优化阅读跳转逻辑。新增章节数据结构,包含章节的 mid 信息,提升用户体验。更新 API 以支持通过 mid 查询章节内容,确保兼容性与灵活性。
This commit is contained in:
@@ -22,11 +22,24 @@ Page({
|
||||
async loadOrders() {
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
// 模拟订单数据
|
||||
const purchasedSections = app.globalData.purchasedSections || []
|
||||
let purchasedSections = app.globalData.purchasedSections || []
|
||||
let sectionMidMap = app.globalData.sectionMidMap || {}
|
||||
const userId = app.globalData.userInfo?.id
|
||||
if (userId) {
|
||||
try {
|
||||
const res = await app.request(`/api/miniprogram/user/purchase-status?userId=${encodeURIComponent(userId)}`)
|
||||
if (res?.success && res.data) {
|
||||
purchasedSections = res.data.purchasedSections || []
|
||||
sectionMidMap = res.data.sectionMidMap || {}
|
||||
app.globalData.purchasedSections = purchasedSections
|
||||
app.globalData.sectionMidMap = sectionMidMap
|
||||
}
|
||||
} catch (_) { /* 使用缓存 */ }
|
||||
}
|
||||
const orders = purchasedSections.map((id, index) => ({
|
||||
id: `order_${index}`,
|
||||
sectionId: id,
|
||||
mid: sectionMidMap[id] || 0,
|
||||
title: `章节 ${id}`,
|
||||
amount: 1,
|
||||
status: 'completed',
|
||||
@@ -42,7 +55,9 @@ Page({
|
||||
|
||||
goToRead(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
wx.navigateTo({ url: `/pages/read/read?id=${id}` })
|
||||
const mid = e.currentTarget.dataset.mid
|
||||
const q = mid ? `mid=${mid}` : `id=${id}`
|
||||
wx.navigateTo({ url: `/pages/read/read?${q}` })
|
||||
},
|
||||
|
||||
goBack() { wx.navigateBack() },
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
</view>
|
||||
|
||||
<view class="orders-list" wx:elif="{{orders.length > 0}}">
|
||||
<view class="order-item" wx:for="{{orders}}" wx:key="id" bindtap="goToRead" data-id="{{item.sectionId}}">
|
||||
<view class="order-item" wx:for="{{orders}}" wx:key="id" bindtap="goToRead" data-id="{{item.sectionId}}"
|
||||
data-mid="{{item.mid}}">
|
||||
<view class="order-info">
|
||||
<text class="order-title">{{item.title}}</text>
|
||||
<text class="order-time">{{item.createTime}}</text>
|
||||
|
||||
Reference in New Issue
Block a user