You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1014 B
47 lines
1014 B
const app = getApp();
|
|
|
|
Page({
|
|
data: {
|
|
totalBooks: 0,
|
|
availableBooks: 0,
|
|
myBorrowCount: 0,
|
|
hotBooks: []
|
|
},
|
|
|
|
onLoad() {
|
|
this.loadData();
|
|
},
|
|
|
|
onShow() {
|
|
this.loadData();
|
|
},
|
|
|
|
loadData() {
|
|
const books = app.globalData.books;
|
|
const borrowRecords = app.globalData.borrowRecords;
|
|
|
|
// 计算统计数据
|
|
const totalBooks = books.reduce((sum, book) => sum + book.total, 0);
|
|
const availableBooks = books.reduce((sum, book) => sum + book.available, 0);
|
|
const myBorrowCount = borrowRecords.filter(record => !record.returnDate).length;
|
|
|
|
// 获取热门图书(按可借数量排序)
|
|
const hotBooks = [...books]
|
|
.sort((a, b) => b.available - a.available)
|
|
.slice(0, 3);
|
|
|
|
this.setData({
|
|
totalBooks,
|
|
availableBooks,
|
|
myBorrowCount,
|
|
hotBooks
|
|
});
|
|
},
|
|
|
|
goToBookDetail(e) {
|
|
const bookId = e.currentTarget.dataset.id;
|
|
wx.navigateTo({
|
|
url: `/pages/books/detail/detail?id=${bookId}`
|
|
});
|
|
}
|
|
}); |