Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

书架持久化实时更新 #159

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions entry/src/main/ets/storage/bookListData.ets
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const addShelfBook = (shelfTye:number, bookData:BookList)=>{

bookList.push(bookData)

shortUpdateDateList(bookList)
shortUpdateDateList(bookList,shelfTye)
}

export const delBookListByBookId = (shelfTye:number,bookId:string)=>{
Expand All @@ -32,7 +32,7 @@ export const delBookListByBookId = (shelfTye:number,bookId:string)=>{
bookListData = bookListData.filter(book => book.bookId !== bookId);

//重新存放
shortUpdateDateList(bookListData)
shortUpdateDateList(bookListData,shelfTye)
}

export const delBookListAll = (shelfTye:number)=>{
Expand All @@ -41,7 +41,7 @@ export const delBookListAll = (shelfTye:number)=>{

bookListData = [];
//重新存放
shortUpdateDateList(bookListData)
shortUpdateDateList(bookListData,shelfTye)
}


Expand All @@ -60,7 +60,7 @@ export const updateBookListData = (shelfTye:number,list:BookList[])=>{
}
}
}
shortUpdateDateList(bookListData)
shortUpdateDateList(bookListData,shelfTye)
}

export const updateDateListById = (index:number, isJoin:boolean, bookId:string)=>{
Expand All @@ -72,10 +72,10 @@ export const updateDateListById = (index:number, isJoin:boolean, bookId:string)=
break
}
}
shortUpdateDateList(bookListData)
shortUpdateDateList(bookListData,index)
}

export const shortUpdateDateList = (showBookList:BookList[])=> {
export const shortUpdateDateList = (showBookList:BookList[],KeyNumber:number)=> {
//防止topUpdateTime出现string类型
showBookList.forEach(book => {
if (typeof book.topUpdateTime === 'string') {
Expand All @@ -94,7 +94,7 @@ export const shortUpdateDateList = (showBookList:BookList[])=> {
return bTime - aTime;
}
});

shelfBookType(KeyNumber)
AppStorage.set(KEY,showBookList)
bookDataPreferences.shared.set(KEY,showBookList);
}
Expand Down Expand Up @@ -132,4 +132,14 @@ export const shortDateList = (showBookList:BookList[])=> {
});

return showBookList
}
}

function shelfBookType(shelfTye:number){
if (shelfTye === 0) {
KEY = CommonConstants.KEY_NOVEL_BOOK_DATA
} else if (shelfTye === 1) {
KEY = CommonConstants.KEY_CARTOON_BOOK_DATA
} else if (shelfTye === 2) {
KEY = CommonConstants.KEY_SOUND_BOOK_DATA
}
}
Loading