删除不再使用的文件和配置,优化项目结构以提升可维护性;新增环境变量配置示例,更新 Docker 和部署相关文件以支持灵活的端口设置;重构数据库连接逻辑,增强错误处理和配置管理,确保更好的兼容性和稳定性。

This commit is contained in:
乘风
2026-02-02 18:16:15 +08:00
parent 6dcc6a4709
commit 8eec1ab78c
126 changed files with 12536 additions and 20384 deletions

View File

@@ -1,45 +1,105 @@
/**
* Soul创业实验 - 订单页
*/
const app = getApp()
function flattenSections(bookData) {
if (!bookData || !Array.isArray(bookData)) return []
const out = []
bookData.forEach(part => {
if (!part.chapters || !Array.isArray(part.chapters)) return
part.chapters.forEach(ch => {
if (!ch.sections || !Array.isArray(ch.sections)) return
ch.sections.forEach(sec => {
out.push({ id: sec.id, title: sec.title || sec.id })
})
})
})
return out
}
Page({
data: {
statusBarHeight: 44,
orders: [],
navBarHeight: 88,
isLoggedIn: false,
user: null,
hasFullBook: false,
purchasedSections: [],
purchasedSectionList: [],
purchasedCount: 0,
totalSections: 62,
sectionList: [],
loading: true
},
onLoad() {
this.setData({ statusBarHeight: app.globalData.statusBarHeight })
this.loadOrders()
const statusBarHeight = app.globalData.statusBarHeight || 44
const navBarHeight = app.globalData.navBarHeight || (statusBarHeight + 44)
this.setData({ statusBarHeight, navBarHeight })
this.syncUser()
this.loadBookData()
},
async loadOrders() {
this.setData({ loading: true })
try {
// 模拟订单数据
const purchasedSections = app.globalData.purchasedSections || []
const orders = purchasedSections.map((id, index) => ({
id: `order_${index}`,
sectionId: id,
title: `章节 ${id}`,
amount: 1,
status: 'completed',
createTime: new Date(Date.now() - index * 86400000).toLocaleDateString()
}))
this.setData({ orders })
} catch (e) {
console.error('加载订单失败:', e)
} finally {
this.setData({ loading: false })
onShow() {
this.syncUser()
},
syncUser() {
const isLoggedIn = !!app.globalData.isLoggedIn
const user = app.globalData.userInfo || null
const hasFullBook = !!app.globalData.hasFullBook
const purchasedSections = app.globalData.purchasedSections || []
const total = this.data.totalSections || 62
const purchasedCount = hasFullBook ? total : purchasedSections.length
const sectionList = this.data.sectionList || []
const purchasedSectionList = sectionList.filter(s => purchasedSections.indexOf(s.id) >= 0)
this.setData({
isLoggedIn,
user,
hasFullBook,
purchasedSections,
purchasedCount,
purchasedSectionList
})
},
loadBookData() {
const bookData = app.globalData.bookData
if (bookData && Array.isArray(bookData)) {
const sectionList = flattenSections(bookData)
const totalSections = sectionList.length || 62
this.setData({ sectionList, totalSections, loading: false })
this.syncUser()
return
}
app.request('/api/book/all-chapters').then(res => {
const raw = (res && res.data) ? res.data : (res && res.chapters) ? res.chapters : []
const totalSections = res.totalSections || res.total || raw.length || 62
let sectionList = []
if (Array.isArray(raw)) {
raw.forEach(s => {
sectionList.push({
id: s.id,
title: s.sectionTitle || s.title || s.section_title || s.id
})
})
}
if (sectionList.length === 0 && raw.length > 0) {
sectionList = raw.map(s => ({ id: s.id, title: s.sectionTitle || s.title || s.id }))
}
this.setData({ sectionList, totalSections, loading: false })
this.syncUser()
}).catch(() => this.setData({ loading: false }))
},
goBack() {
wx.navigateBack({ fail: () => wx.switchTab({ url: '/pages/my/my' }) })
},
goChapters() {
wx.switchTab({ url: '/pages/chapters/chapters' })
},
goToRead(e) {
const id = e.currentTarget.dataset.id
wx.navigateTo({ url: `/pages/read/read?id=${id}` })
},
goBack() { wx.navigateBack() }
if (id) wx.navigateTo({ url: '/pages/read/read?id=' + encodeURIComponent(id) })
}
})