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.
55 lines
2.0 KiB
55 lines
2.0 KiB
// 模拟数据存储
|
|
const globalData = {
|
|
userInfo: null,
|
|
books: [
|
|
{ id: 1, title: 'JavaScript高级程序设计', author: '尼古拉斯·泽卡斯', publisher: '人民邮电出版社', isbn: '9787115275790', total: 5, available: 3, cover: '/images/book1.jpg' },
|
|
{ id: 2, title: 'CSS揭秘', author: 'Lea Verou', publisher: '人民邮电出版社', isbn: '9787115434456', total: 3, available: 1, cover: '/images/book2.jpg' },
|
|
{ id: 3, title: '深入浅出Node.js', author: '朴灵', publisher: '人民邮电出版社', isbn: '9787115335500', total: 4, available: 2, cover: '/images/book3.jpg' },
|
|
{ id: 4, title: '算法导论', author: 'Thomas H.Cormen', publisher: '机械工业出版社', isbn: '9787111407010', total: 6, available: 4, cover: '/images/book4.jpg' },
|
|
{ id: 5, title: 'Python编程从入门到实践', author: 'Eric Matthes', publisher: '人民邮电出版社', isbn: '9787115428028', total: 5, available: 5, cover: '/images/book5.jpg' },
|
|
{ id: 6, title: 'React Native开发指南', author: 'Bonnie Eisenman', publisher: '人民邮电出版社', isbn: '9787115453877', total: 3, available: 0, cover: '/images/book6.jpg' }
|
|
],
|
|
borrowRecords: []
|
|
};
|
|
|
|
App({
|
|
onLaunch() {
|
|
// 初始化数据
|
|
this.initData();
|
|
},
|
|
|
|
initData() {
|
|
// 从本地存储加载数据
|
|
try {
|
|
const books = wx.getStorageSync('books');
|
|
const borrowRecords = wx.getStorageSync('borrowRecords');
|
|
|
|
if (books) {
|
|
globalData.books = books;
|
|
}
|
|
if (borrowRecords) {
|
|
globalData.borrowRecords = borrowRecords;
|
|
}
|
|
} catch (e) {
|
|
console.log('初始化数据失败', e);
|
|
}
|
|
},
|
|
|
|
saveBooks() {
|
|
try {
|
|
wx.setStorageSync('books', globalData.books);
|
|
} catch (e) {
|
|
console.log('保存图书数据失败', e);
|
|
}
|
|
},
|
|
|
|
saveBorrowRecords() {
|
|
try {
|
|
wx.setStorageSync('borrowRecords', globalData.borrowRecords);
|
|
} catch (e) {
|
|
console.log('保存借阅记录失败', e);
|
|
}
|
|
},
|
|
|
|
globalData: globalData
|
|
}); |