|
@@ -1,23 +1,80 @@
|
|
|
|
|
+import { AppStorageV2 } from "@kit.ArkUI"
|
|
|
|
|
+import { bookListApi } from "../../apis/BookListApi"
|
|
|
|
|
+import { BookListItem } from "../../model/BookModelIndex"
|
|
|
|
|
+import { searchBookListQuery } from "../../model/Query"
|
|
|
|
|
+import { BookCategoriesStorage } from "../../model/Storage"
|
|
|
|
|
|
|
|
@ObservedV2
|
|
@ObservedV2
|
|
|
export class BookListViewModel{
|
|
export class BookListViewModel{
|
|
|
- // 分类列表
|
|
|
|
|
- @Trace categoryList: string[] = ['全部', '精品主题', '名家大师', '国际获奖', '经典系列', '畅销榜TOP', '权威推荐', '月度推荐']
|
|
|
|
|
// 书单列表
|
|
// 书单列表
|
|
|
- @Trace bookList: string[] = ['书单1', '书单2', '书单3', '书单4', '书单5', '书单6', '书单7', '书单8', '书单9', '书单10', '书单11', '书单12', '书单13', '书单14', '书单15', '书单16', '书单17']
|
|
|
|
|
|
|
+ @Trace bookList: BookListItem[] = []
|
|
|
|
|
|
|
|
// 分类索引
|
|
// 分类索引
|
|
|
@Trace categoryIndex: number = 0
|
|
@Trace categoryIndex: number = 0
|
|
|
// 排序方式 0 - 最新 1 - 最热
|
|
// 排序方式 0 - 最新 1 - 最热
|
|
|
@Trace sortType: number = 0
|
|
@Trace sortType: number = 0
|
|
|
|
|
|
|
|
|
|
+ // 分类列表
|
|
|
|
|
+ bookCategories: BookCategoriesStorage = AppStorageV2.connect(BookCategoriesStorage, () => new BookCategoriesStorage())!
|
|
|
|
|
+ // 分类列表控制器
|
|
|
|
|
+ categoryControl: Scroller = new Scroller()
|
|
|
|
|
+ // 书单查询器
|
|
|
|
|
+ query: searchBookListQuery = new searchBookListQuery()
|
|
|
|
|
+
|
|
|
|
|
+ constructor(categories: string) {
|
|
|
|
|
+ if(categories) {
|
|
|
|
|
+ this.init(categories)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.changeCategory(0)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 初始化
|
|
|
|
|
+ async init(categories: string){
|
|
|
|
|
+ if(this.bookCategories.bookList.length == 0) {
|
|
|
|
|
+ await this.bookCategories.init()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ let index = this.bookCategories.bookList.findIndex(item => item.bookListTypeName == categories)
|
|
|
|
|
+ if(index != -1) {
|
|
|
|
|
+ this.changeCategory(index)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 更改选中的分类
|
|
// 更改选中的分类
|
|
|
changeCategory(index: number) {
|
|
changeCategory(index: number) {
|
|
|
this.categoryIndex = index
|
|
this.categoryIndex = index
|
|
|
|
|
+ if(index != 0){
|
|
|
|
|
+ this.query.bookListTypeId = this.bookCategories.bookList[index].id
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.query.bookListTypeId = undefined
|
|
|
|
|
+ }
|
|
|
|
|
+ this.getBookList()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 更改排序方式
|
|
// 更改排序方式
|
|
|
changeSortType(index: number) {
|
|
changeSortType(index: number) {
|
|
|
this.sortType = index
|
|
this.sortType = index
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 获取书单列表
|
|
|
|
|
+ async getBookList(isReload: boolean = true) {
|
|
|
|
|
+ if(isReload) {
|
|
|
|
|
+ this.query.reload()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // if()
|
|
|
|
|
+
|
|
|
|
|
+ this.query.reachEnd()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ let ans = await bookListApi.searchBookList(this.query)
|
|
|
|
|
+
|
|
|
|
|
+ this.bookList = [...ans?.list ?? []]
|
|
|
|
|
+
|
|
|
|
|
+ console.log(`书单列表数据 = ${JSON.stringify(ans)}`)
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|