Skip to content

Commit

Permalink
Merge pull request #231 from mgz0227/dev_2008
Browse files Browse the repository at this point in the history
书架分组db操作显示,管理页面跳转分组操作功能实现
  • Loading branch information
MaoXiaoone authored Jul 26, 2024
2 parents 6ae9702 + f023040 commit 1315163
Show file tree
Hide file tree
Showing 23 changed files with 553 additions and 327 deletions.
66 changes: 66 additions & 0 deletions entry/src/main/ets/common/utils/bookGroupUtils.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @author 2008
* @datetime 2024/7/26 10:58
* @className: booksUtils
*/
import BookGroupsDao from '../../database/dao/BookGroupsDao'
import BooksDao from '../../database/dao/BooksDao'
import { BookGroups } from '../../database/entities/BookGroups'

class bookGroupUtils{

async isTopGroup(id: number, isTop?: boolean): Promise<boolean> {
return BookGroupsDao.isUpdateGroupTop(id, isTop)
}

async addGroup(books: BookGroups){
BookGroupsDao.insert(books)
}
//
// async updateBookGroup(id:number|number[], group:number){
// //循环更新
// let booId:number[] = []
// if (typeof id === 'number'){
// booId.push(id)
// } else {
// booId = id
// }
// booId.forEach((item:number)=>{
// BooksDao.updateBookGroup(item,group)
// })
// }

async delGroupById(id:number){
//删除分组
BookGroupsDao.deleteBook(id)
//同时更新书籍分组为未分组
BooksDao.queryBookByGroup(id, 3)
}

async moveBookByGroupId(oldGroup:number|number[], newGroup:number){
//同时更新书籍分组为未分组
let Ids:number[] = []
if (typeof oldGroup === 'number'){
Ids.push(oldGroup)
} else {
Ids = oldGroup
}
Ids.forEach((item:number)=>{
BooksDao.queryBookByGroup(item, newGroup)
})
}

async updateGroupShow(groupId:number|number[]){
let Ids:number[] = []
if (typeof groupId === 'number'){
Ids.push(groupId)
} else {
Ids = groupId
}
Ids.forEach((item:number)=>{
BookGroupsDao.updateGroupShow(item)
})
}
}
let bookGroupUtil = new bookGroupUtils();
export default bookGroupUtil as bookGroupUtils;
21 changes: 10 additions & 11 deletions entry/src/main/ets/componets/bookDetail/BookOverlay.ets
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import CommonConstants from '../../common/constants/CommonConstants'

@Component
export default struct BookOverlay {
// @Prop bookWidth:number
// @Prop bookHeight:number
@Prop bookImage:Resource
@Prop bookImage:Resource|string
@Prop isTop:boolean
@Prop isShow:boolean = false
build() {
Expand All @@ -18,19 +16,20 @@ export default struct BookOverlay {
.backgroundColor('rgba(0,0,0,0.45)')
.width(CommonConstants.NOVEL_IMG_WIDTH).height(CommonConstants.NOVEL_IMG_HEIGHT)
}
Flex({
alignItems: ItemAlign.End,
}){

Stack(){
if (this.isTop){
Text('置顶').fontColor(Color.White).fontWeight(300).fontSize(8).padding(3).borderRadius(5)
.backgroundColor('rgba(0, 0, 0, 0.45)')
.backgroundColor('rgba(0, 0, 0, 0.45)').zIndex(1)
}
Image(this.bookImage)
.draggable(false)
.alt($r('app.media.icon_book_default_cover_one'))
.width(CommonConstants.NOVEL_IMG_WIDTH)
.height(CommonConstants.NOVEL_IMG_HEIGHT)
}
.align(Alignment.Start)
.width(CommonConstants.NOVEL_IMG_WIDTH).height(CommonConstants.NOVEL_IMG_HEIGHT)
.backgroundImage(this.bookImage)
.backgroundImageSize({width:CommonConstants.NOVEL_IMG_WIDTH,height:CommonConstants.NOVEL_IMG_HEIGHT})
.zIndex(2)
.alignContent(Alignment.BottomStart)

Row(){
Image($r('app.media.occlusion1'))
Expand Down
1 change: 0 additions & 1 deletion entry/src/main/ets/componets/group/GroupType.ets
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default struct groupTypeComponent {
@Link GROUP:string
@State groupList:BookGroups[] = []
@Link bookTypeNumber:number
// initGroup:string[] = ['分组','全部','未分组','本地','书单']
@StorageLink('BOOK_IS_BOOK_GROUPS_REFRESHING') @Watch('changeRefresh')BOOK_IS_BOOK_GROUPS_REFRESHING: number = 0
aboutToAppear(): void {
this.getGroupList()
Expand Down
12 changes: 3 additions & 9 deletions entry/src/main/ets/componets/group/groupTypePanel.ets
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export default struct groupTypePanel{
.onAction((event: GestureEvent) => {
if (event.repeat) {
if (!this.isShow) {
this.dialogGroupData = item
// this.group = item
this.isShow = true
this.changeNumber = 1
Expand Down Expand Up @@ -206,8 +207,6 @@ export default struct groupTypePanel{

@State dragIndex: number = 0
changeIndex(index1: number, index2: number,type:number = 2) { // 交换数组位置
//@State hideGroupType:string[] = ['游戏','玄幻','都市', '历史', '军事', '科幻', '灵异', '二次元', '耽美', '同人']
//hideGroupType数组位置交换
if (!this.isShowIcon) {
showMessage('请在管理状态下拖到改变顺序')
return
Expand Down Expand Up @@ -249,12 +248,12 @@ export default struct groupTypePanel{
}
}

@State @Watch('watchFolder')group:folderList = new folderList(0,'',0,$r('app.media.folder_test'),'')
@State changeNumber:number = 0
@State isShow:boolean = false
@State dialogGroupData:BookGroups = new BookGroups()
groupInfoDialog: CustomDialogController | null = new CustomDialogController({
builder: FolderInfoDialog({
itemData:this.group,
itemData:this.dialogGroupData,
cancel: () => {
this.exitDialog()
}
Expand All @@ -273,11 +272,6 @@ export default struct groupTypePanel{
this.groupInfoDialog?.close()
}

watchFolder(){
if (this.changeNumber === 1) {
updateDateGroup(this.group)
}
}
@State isShowBookFolderInfoDialog:boolean = false
@State folderType:string = ''
@Builder bookFolderInfoDialog(){
Expand Down
20 changes: 18 additions & 2 deletions entry/src/main/ets/database/AppDatabase/index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
"entities": [
{
"tableName": "books",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` ( `id` INTEGER NOT NULL, `bookUrl` TEXT, `toUrl` TEXT, `origin` TEXT, `originName` TEXT, `bookName` TEXT NOT NULL, `author` TEXT, `cover` TEXT, `customTag` TEXT, `coverUrl` TEXT, `customCoverUrl` TEXT, `intro` TEXT, `customIntro` TEXT, `charset` TEXT, `bookGroup` INTEGER NOT NULL DEFAULT 0, `latestChapterTitle` TEXT, `latestChapterTime` INTEGER NOT NULL DEFAULT 0, `lastCheckTime` INTEGER NOT NULL DEFAULT 0, `lastCheckCount` INTEGER NOT NULL DEFAULT 0, `totalChapterNum` INTEGER NOT NULL DEFAULT 0, `durChapterTitle` TEXT, `durChapterIndex` INTEGER NOT NULL DEFAULT 0, `durChapterPos` INTEGER NOT NULL DEFAULT 0, `durChapterTime` INTEGER NOT NULL DEFAULT 0, `wordCount` TEXT, `canUpdate` INTEGER NOT NULL DEFAULT 1, `sort` INTEGER NOT NULL DEFAULT 0, `originOrder` INTEGER NOT NULL DEFAULT 0, `syncTime` INTEGER NOT NULL DEFAULT 0, `bookType` INTEGER NOT NULL DEFAULT 0, `isTop` INTEGER NOT NULL DEFAULT 0, `createTime` INTEGER NOT NULL DEFAULT 0,`updateTime` INTEGER NOT NULL DEFAULT 0,`isJoin` INTEGER NOT NULL DEFAULT 1,PRIMARY KEY ( `id` ))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` ( `id` INTEGER NOT NULL, `bookUrl` TEXT, `toUrl` TEXT, `origin` TEXT, `originName` TEXT, `bookName` TEXT NOT NULL, `author` TEXT, `cover` TEXT, `customTag` TEXT, `coverUrl` TEXT, `customCoverUrl` TEXT, `intro` TEXT, `customIntro` TEXT, `charset` TEXT, `bookGroup` INTEGER NOT NULL DEFAULT 0, `latestChapterTitle` TEXT, `latestChapterTime` INTEGER NOT NULL DEFAULT 0, `lastCheckTime` INTEGER NOT NULL DEFAULT 0, `lastCheckCount` INTEGER NOT NULL DEFAULT 0, `totalChapterNum` INTEGER NOT NULL DEFAULT 0, `durChapterTitle` TEXT, `durChapterIndex` INTEGER NOT NULL DEFAULT 0, `durChapterPos` INTEGER NOT NULL DEFAULT 0, `durChapterTime` INTEGER NOT NULL DEFAULT 0, `wordCount` TEXT, `canUpdate` INTEGER NOT NULL DEFAULT 1, `sort` INTEGER NOT NULL DEFAULT 0, `originOrder` INTEGER NOT NULL DEFAULT 0, `syncTime` INTEGER NOT NULL DEFAULT 0, `bookType` INTEGER NOT NULL DEFAULT 0, `isTop` INTEGER NOT NULL DEFAULT 0, `createTime` INTEGER NOT NULL DEFAULT 0,`updateTime` INTEGER NOT NULL DEFAULT 0,`isJoin` INTEGER NOT NULL DEFAULT 1,isSystem INTEGER NOT NULL DEFAULT 0,PRIMARY KEY ( `id` ))",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -257,7 +257,7 @@ export default {
},
{
"tableName": "book_groups",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`groupId` INTEGER NOT NULL, `groupName` TEXT NOT NULL, `coverUrl` TEXT, `groupDescribe` TEXT, `sort` INTEGER NOT NULL, `enableRefresh` INTEGER NOT NULL DEFAULT 1, `show` INTEGER NOT NULL DEFAULT 1, `groupType` INTEGER NOT NULL DEFAULT 0, `createTime` INTEGER NOT NULL DEFAULT 0, `updateTime` INTEGER NOT NULL DEFAULT 0, `bookSort` INTEGER NOT NULL DEFAULT -1, `canUpdate` INTEGER NOT NULL DEFAULT 0, `coverOnly` INTEGER NOT NULL DEFAULT 0, `coverType` INTEGER NOT NULL DEFAULT 0, `canDelete` INTEGER NOT NULL DEFAULT 1, PRIMARY KEY(`groupId`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`groupId` INTEGER NOT NULL, `groupName` TEXT NOT NULL, `coverUrl` TEXT, `groupDescribe` TEXT, `sort` INTEGER NOT NULL, `enableRefresh` INTEGER NOT NULL DEFAULT 1, `show` INTEGER NOT NULL DEFAULT 1, `groupType` INTEGER NOT NULL DEFAULT 0, `createTime` INTEGER NOT NULL DEFAULT 0, `updateTime` INTEGER NOT NULL DEFAULT 0, `bookSort` INTEGER NOT NULL DEFAULT -1, `canUpdate` INTEGER NOT NULL DEFAULT 0, `coverOnly` INTEGER NOT NULL DEFAULT 0, `coverType` INTEGER NOT NULL DEFAULT 0, `canDelete` INTEGER NOT NULL DEFAULT 1, `isTop` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`groupId`))",
"fields": [
{
"fieldPath": "groupId",
Expand Down Expand Up @@ -362,6 +362,22 @@ export default {
"boolean": true,
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "isTop",
"columnName": "isTop",
"affinity": "INTEGER",
"boolean": true,
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "isSystem",
"columnName": "isSystem",
"affinity": "INTEGER",
"boolean": true,
"notNull": true,
"defaultValue": "0"
}
],
"primaryKey": {
Expand Down
44 changes: 44 additions & 0 deletions entry/src/main/ets/database/dao/BookGroupsDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class BookGroupsDao{

sql += `
ORDER BY
isSystem DESC,
isTop DESC,
sort ASC
`;
const groupDbList = await DbUtil.querySqlForList<BookGroups>(sql, column);
Expand Down Expand Up @@ -172,6 +174,46 @@ class BookGroupsDao{
}
}

//置顶
async isUpdateGroupTop(id: number, isTop?: boolean) {
try {
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
predicates.equalTo('groupId', id)
const count = await DbUtil.queryForList<BookGroups>(predicates, column)
if (column.length > 0) {
count.forEach((item) => {
item.isTop = isTop||!item.isTop
item.updateTime = Date.now()
this.update(item)
})
return true
}
return false
} catch (err) {
console.log('TagInfo, Error, ', JSON.stringify(err))
return false
}
}

//更新分组显示状态
async updateGroupShow(id: number, show?: boolean) {
try {
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
predicates.equalTo('groupId', id)
const count = await DbUtil.queryForList<BookGroups>(predicates, column)
if (column.length > 0)
count.forEach((item) => {
item.show = show||!item.show
item.updateTime = Date.now()
this.update(item)
})
} catch (e){
console.log('TagInfo, Error, ', JSON.stringify(e))
}
}

//系统初始分组数据
async initGroupData() {
let initGroup = ['分组','全部','未分组','本地','书单']
Expand All @@ -187,6 +229,8 @@ class BookGroupsDao{
group.show = true
group.groupType = 123
group.canDelete = false
group.isSystem = true
group.isTop = true
await bookGroupsDao.insert(group)
}
}catch (e){
Expand Down
32 changes: 32 additions & 0 deletions entry/src/main/ets/database/dao/BooksDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,38 @@ class BooksDao {
return false
}
}

//根据分组id统计书籍数量
async countBookByGroup(groupId: number) {
try {
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
predicates.equalTo('bookGroup', groupId)
const count = await DbUtil.queryForCount(predicates, column)
return count
} catch (err) {
console.log('TagInfo, Error, ', JSON.stringify(err))
return 0
}
}

//分组删除情况下根据删除分组id查询书籍更新未分组
async queryBookByGroup(groupId: number,updateGroupId: number) {
try {
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
predicates.equalTo('bookGroup', groupId)
const bookDbList = await DbUtil.queryForList<Books>(predicates, column)
if (bookDbList.length > 0) {
bookDbList.forEach((item) => {
item.bookGroup = updateGroupId
this.update(item)
})
}
} catch (e) {
console.log('TagInfo, Error, ', JSON.stringify(e))
}
}
}


Expand Down
4 changes: 4 additions & 0 deletions entry/src/main/ets/database/entities/BookGroups.ets
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ export class BookGroups {
canUpdate:boolean = false
//是否可删除
canDelete:boolean = true
//是否置顶
isTop:boolean = false
//是否系统参数
isSystem:boolean = false
}
Loading

0 comments on commit 1315163

Please sign in to comment.