Skip to content

Commit cd4f08b

Browse files
authored
Merge pull request #239 from mgz0227/dev_2008
管理页面支持分组下的书籍添加到书单中
2 parents 3acb103 + 1eb7ddf commit cd4f08b

File tree

10 files changed

+168
-73
lines changed

10 files changed

+168
-73
lines changed

entry/src/main/ets/common/constants/CommonConstants.ets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export default class CommonConstants {
235235
static readonly HAS_EXPLORE_URL:string = 'HAS_EXPLORE_URL'
236236
static readonly BOOK_IS_BOOK_REFRESHING:string = 'BOOK_IS_BOOK_REFRESHING'
237237
static readonly BOOK_IS_BOOK_GROUPS_REFRESHING:string = 'BOOK_IS_BOOK_GROUPS_REFRESHING'
238+
static readonly BOOK_IS_BOOK_WORKS_BOOK_LIST:string = 'BOOK_IS_BOOK_WORKS_BOOK_LIST'
238239
// 订阅源分组数据
239240
//分组是否初始化key
240241
static readonly RSS_SOURCES_GROUP_INIT:string = 'RSS_SOURCES_GROUP_INIT'

entry/src/main/ets/common/utils/bookGroupUtils.ets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ class bookGroupUtils{
9898
updateMoveGroupBookIds(data:Record<number, number>){
9999
BookGroupsDao.updateMoveBookIdsByGroupId(data)
100100
}
101+
//根据分组获取分组下的书籍Id
102+
async queryBookByGroupId(groupId:number|number[]){
103+
let Ids:number[] = toolsUtils.numberArrays(groupId)
104+
return await BookGroupsDao.queryBookByGroup(Ids)
105+
}
101106
}
102107
let bookGroupUtil = new bookGroupUtils();
103108
export default bookGroupUtil as bookGroupUtils;

entry/src/main/ets/database/dao/BookGroupsDao.ets

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,33 @@ class BookGroupsDao{
338338
return false
339339
}
340340
}
341+
/**
342+
* 分组id查询分组下的书籍Id然后去重
343+
* @param ids
344+
*/
345+
async queryBookByGroup(ids:number[]){
346+
try {
347+
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
348+
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
349+
const validIds = ids.filter(id => typeof id === 'number');
350+
predicates.in('groupId', validIds);
351+
const groups = await DbUtil.queryForList<BookGroupDb>(predicates, column);
352+
const bookIds:number[] = []
353+
if (groups.length > 0) {
354+
groups.forEach((item) => {
355+
ToBookGroups(item).bookIds?.forEach((bookId) => {
356+
if (!bookIds.includes(Number(bookId))) {
357+
bookIds.push(Number(bookId))
358+
}
359+
})
360+
})
361+
}
362+
return bookIds
363+
} catch (e){
364+
console.log('queryBookByGroup, Error, ', JSON.stringify(e))
365+
return []
366+
}
367+
}
341368

342369
}
343370

entry/src/main/ets/pages/view/bookShelf/Manage/BookManagePage.ets

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct BookManagePage {
4242
@StorageLink('topRectHeight') topRectHeight: number = 0
4343
@StorageLink('bottomRectHeight') bottomRectHeight: number = 0
4444
@State isAddShelfShow:boolean = false
45-
tabsController: TabsController = new TabsController();
4645
@State topTitle:string = '置顶'
4746
@State bookList:Books[] = []
4847
@State @Watch('listenCheckList')checkLists: Record<number, boolean> = {}
@@ -122,7 +121,6 @@ struct BookManagePage {
122121
} else if (this.bookTypeNumber === 5){
123122
this.getWorkLists()
124123
this.isMoveStatus = 2
125-
// this.getBookList() //todo 获取书单
126124
} else {
127125
this.getBookList()
128126
this.isMoveStatus = 0
@@ -131,6 +129,7 @@ struct BookManagePage {
131129

132130
@State isCatalogAddShelf:boolean = false
133131
@State showNumber:number = 0
132+
@State bookOrFolder:number = 0
134133
build() {
135134
Column(){
136135
Header({
@@ -144,35 +143,27 @@ struct BookManagePage {
144143
})
145144
.visibility(this.showNumber === 0?Visibility.Visible:Visibility.None)
146145
.opacity(this.showNumber === 0?1:0)
147-
Tabs({
148-
index:this.showNumber,
149-
controller: this.tabsController
150-
}){
151-
TabContent(){
152-
this.bookManage()
153-
}
154-
TabContent(){
155-
newBookShelf({
156-
currentIndex:this.currentIndex,
157-
changeShowNumber:(index:number)=>{
158-
this.showNumber = index
159-
this.refreshData()
160-
},
161-
bookIds:this.checkListNumber
162-
})
163-
}
164-
.padding({
165-
top:this.topRectHeight
166-
})
146+
// Tabs({
147+
// index:this.showNumber,
148+
// controller: this.tabsController
149+
// }){
150+
// TabContent(){
151+
//
152+
// }
153+
// }
154+
// .backgroundColor(Color.White)
155+
// .barWidth(0)
156+
// .barHeight(0)
157+
// .layoutWeight(1)
158+
// .scrollable(false)
159+
// .onChange((index: number) => {
160+
// this.showNumber = index
161+
// })
162+
Column(){
163+
this.bookManage()
167164
}
168-
.backgroundColor(Color.White)
169-
.barWidth(0)
170-
.barHeight(0)
171165
.layoutWeight(1)
172-
.scrollable(false)
173-
.onChange((index: number) => {
174-
this.showNumber = index
175-
})
166+
.backgroundColor(Color.White)
176167
Flex()
177168
.bindSheet($$this.isCatalogAddShelf, this.dialogCatalogAddShelf(), {
178169
height:400,
@@ -182,6 +173,13 @@ struct BookManagePage {
182173
this.isCatalogAddShelf = false
183174
}
184175
})
176+
Flex()
177+
.bindContentCover($$this.isShowEditBook, this.showEditBook(), {
178+
modalTransition: ModalTransition.DEFAULT,
179+
onDisappear: () => {
180+
this.isShowEditBook = false;
181+
}
182+
})
185183
}
186184
.margin({
187185
bottom:this.bottomRectHeight
@@ -241,6 +239,28 @@ struct BookManagePage {
241239
}.backgroundColor(Color.White)
242240
}
243241
}
242+
//新建书单弹出
243+
@State isShowEditBook:boolean = false
244+
@Builder showEditBook(){
245+
Column(){
246+
newBookShelf({
247+
currentIndex:this.currentIndex,
248+
changeShowNumber:(index:number)=>{
249+
this.showNumber = index
250+
this.isShowEditBook = false
251+
this.refreshData()
252+
},
253+
bookIds:this.checkListNumber,
254+
bookOrFolder:this.bookOrFolder
255+
})
256+
}
257+
.padding({
258+
top:this.topRectHeight,
259+
bottom:this.bottomRectHeight
260+
})
261+
.backgroundColor(Color.White)
262+
}
263+
244264
//书单弹窗
245265
@Builder dialogCatalogAddShelf(){
246266
Column(){
@@ -251,7 +271,7 @@ struct BookManagePage {
251271
changeShowNumber:(val:number)=>{
252272
this.showNumber = val
253273
this.isCatalogAddShelf = false
254-
274+
this.isShowEditBook = true
255275
},
256276
currentIndex:this.currentIndex
257277
})
@@ -418,6 +438,11 @@ struct BookManagePage {
418438
this.bookMoveGroup?.open(); break;
419439
case 3 :
420440
this.isCatalogAddShelf = true
441+
if (this.bookTypeNumber === 1) {
442+
this.bookOrFolder = 1
443+
} else {
444+
this.bookOrFolder = 0
445+
}
421446
this.dataCheckList();
422447
break;
423448
case 4 :

entry/src/main/ets/pages/view/bookShelf/Manage/bookManage/newBookShelf.ets

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import CommonConstants from '../../../../../common/constants/CommonConstants'
55
import PaddingConstants from '../../../../../common/constants/PaddingConstants'
6+
import bookGroupUtil from '../../../../../common/utils/bookGroupUtils'
67
import worksListsUtils from '../../../../../common/utils/WorksListsUtils'
78
import confirmDialogExample from '../../../../../componets/common/confirmDialog'
89
import { showMessage } from '../../../../../componets/common/promptShow'
@@ -22,6 +23,8 @@ export default struct newBookShelf{
2223
@Prop bookIds:number[] = []
2324
@State @Watch('changeBookIds')newBookIds:number[] = []
2425
@State isShowAddBook:boolean = false
26+
//默认0为书籍 1为分组
27+
@Prop bookOrFolder:number = 0
2528
changeShowNumber:Function = (_index:number)=>{
2629

2730
}
@@ -31,22 +34,31 @@ export default struct newBookShelf{
3134
changeBookIds(){
3235
this.getBookIds()
3336
}
34-
aboutToAppear(): void {
35-
if (this.workBookListStatus === 0) {
36-
this.newBookIds = this.bookIds
37-
} else {
38-
this.workBookList = this.lastWorkBookList
39-
if (this.workBookList.worksBookList) {
40-
//初始推荐理由
41-
this.workBookList.worksBookList.forEach((item: WorksBookList) => {
42-
if (item.bookId) {
43-
this.TextRecommend[item.bookId] = item.recommend ?? '';
37+
38+
async aboutToAppear(): Promise<void> {
39+
if (this.bookOrFolder === 1){
40+
let bookId = await bookGroupUtil.queryBookByGroupId(this.bookIds)
41+
if (bookId.length) {
42+
this.newBookIds = bookId
43+
}
44+
}
45+
if (this.bookOrFolder === 0) {
46+
if (this.workBookListStatus === 0) {
47+
this.newBookIds = this.bookIds
48+
} else {
49+
this.workBookList = this.lastWorkBookList
50+
if (this.workBookList.worksBookList) {
51+
//初始推荐理由
52+
this.workBookList.worksBookList.forEach((item: WorksBookList) => {
53+
if (item.bookId) {
54+
this.TextRecommend[item.bookId] = item.recommend ?? '';
55+
}
56+
})
57+
//初始书籍
58+
let bookIds = worksListsUtils.getBookIds(this.workBookList.worksBookList).toString()
59+
if (bookIds.length) {
60+
this.newBookIds = bookIds.split(',').map(Number);
4461
}
45-
})
46-
//初始书籍
47-
let bookIds = worksListsUtils.getBookIds(this.workBookList.worksBookList).toString()
48-
if (bookIds.length) {
49-
this.newBookIds = bookIds.split(',').map(Number);
5062
}
5163
}
5264
}

entry/src/main/ets/pages/view/bookShelf/Manage/components/catalogAddShelf.ets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @datetime 2024/7/26 20:35
44
* @className: catalogAddShelf
55
* 加入书单弹窗
6-
* todo 书单功能db暂未实现
76
*/
87
import CommonConstants from '../../../../../common/constants/CommonConstants'
98
import buttonCommon from '../../../../../componets/common/buttonCommon'

entry/src/main/ets/pages/view/bookShelf/Shelf/WorksBookLists.ets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default struct WorksBookLists {
2020
@State worksBook:WorksLists = new WorksLists()
2121
@StorageLink('topRectHeight') topRectHeight: number = 0
2222
@StorageLink('bottomRectHeight') bottomRectHeight: number = 0
23+
@StorageLink('BOOK_IS_BOOK_WORKS_BOOK_LIST') @Watch('getWorkLists')isWorksBookListRefreshing: number = 0
2324
aboutToAppear(): void {
2425
if (this.worksLists.length === 0) {
2526
this.getWorkLists()

entry/src/main/ets/pages/view/bookShelf/components/BookContentRefresh.ets

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default struct BookContentRefresh {
1313
@State @Watch('changeRefreshing')isRefreshing: boolean = false
1414
@StorageLink('BOOK_IS_BOOK_REFRESHING') isBookRefreshing: number = 0
1515
@StorageLink('BOOK_IS_BOOK_GROUPS_REFRESHING') isGroupRefreshing: number = 0
16+
@StorageLink('BOOK_IS_BOOK_WORKS_BOOK_LIST') isWorksBookListRefreshing: number = 0
1617
@State counter: number = 0
1718
@State RefreshingTitle: string = '松开刷新'
1819
@Prop currentIndex: number = 0
@@ -23,8 +24,17 @@ export default struct BookContentRefresh {
2324
@State checkGroup:Record<number, boolean> = {}
2425
changeRefreshing(){
2526
if (this.isRefreshing) {
26-
this.isBookRefreshing++
27-
this.isGroupRefreshing++
27+
switch (this.bookTypeNumber){
28+
case 1:
29+
this.isGroupRefreshing++
30+
break;
31+
case 5:
32+
this.isWorksBookListRefreshing++
33+
break;
34+
default:
35+
this.isBookRefreshing++
36+
break
37+
}
2838
}
2939
}
3040
build() {

0 commit comments

Comments
 (0)