diff --git a/pages/home/home.vue b/pages/home/home.vue index fa81ab6..08f45d8 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -191,8 +191,7 @@ import { FetchOpenId, FetchFindAllReaderBindByOpenId} from '@/api/user'; import { FetchInitScreenBookRecommend } from '@/api/book'; import config from '@/utils/config'; - -const READLIST = 'reader-card-list'; +import { STORAGE_KEYS } from '@/utils/storage'; export default { data() { @@ -283,17 +282,17 @@ export default { // 合并:默认在前,其他在后 this.readerCardList = defaultCard ? [defaultCard, ...otherCards] : res.data; - uni.setStorageSync(READLIST, this.readerCardList); - uni.setStorageSync('currentReaderCard', defaultCard); + uni.setStorageSync(STORAGE_KEYS.READER_CARD_LIST, this.readerCardList); + uni.setStorageSync(STORAGE_KEYS.CURRENT_READER_CARD, defaultCard); } else { this.isBindLibraryCard = false; this.readerCardList = []; - uni.setStorageSync(READLIST, []); + uni.setStorageSync(STORAGE_KEYS.READER_CARD_LIST, []); } } catch (err) { console.error('初始化失败:', err); - const list = uni.getStorageSync(READLIST) || []; + const list = uni.getStorageSync(STORAGE_KEYS.READER_CARD_LIST) || []; // 同样默认排第一 const defaultCard = list.find(item => item.bindDefault === true); const otherCards = list.filter(item => !item.bindDefault); @@ -308,10 +307,12 @@ export default { const res = await FetchInitScreenBookRecommend({ libcode: '1201' }); let books = res.data || []; - // 只遍历前3条,做Base64转换 + // 只处理并展示前3条,避免setData数据过大 const limit = 3; - for (let i = 0; i < books.length && i < limit; i++) { - let item = books[i]; + const displayBooks = books.slice(0, limit); + + for (let i = 0; i < displayBooks.length; i++) { + let item = displayBooks[i]; if (item.imgPath) { const imageUrl = this.baseUrl + '/api/fileRelevant/getImg?imgType=2&imgId=' + item.imgPath; try { @@ -325,12 +326,8 @@ export default { } } - // 第3条之后直接赋空,用默认图 - for (let i = limit; i < books.length; i++) { - books[i].base64Cover = ''; - } - - this.recommendedBooks = books; + // 只将展示所需的前3条数据放入响应式,减少setData传输量 + this.recommendedBooks = displayBooks; this.isLoading = false; } catch (err) { console.error('获取图书推荐失败:', err); diff --git a/pages/lendCar/lendCar.vue b/pages/lendCar/lendCar.vue index 5234649..8f59835 100644 --- a/pages/lendCar/lendCar.vue +++ b/pages/lendCar/lendCar.vue @@ -44,7 +44,8 @@