Skip to content

Commit

Permalink
Merge pull request #235 from mgz0227/dev_2008
Browse files Browse the repository at this point in the history
书架分组db;书架管理跳转页面数据db操作;书籍长按弹窗功能db操作;
  • Loading branch information
MaoXiaoone authored Jul 29, 2024
2 parents a1134e0 + 037ba9c commit dd717d1
Show file tree
Hide file tree
Showing 36 changed files with 1,395 additions and 1,219 deletions.
31 changes: 31 additions & 0 deletions entry/src/main/ets/common/utils/ToolsUtils.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @author 2008
* @datetime 2024/7/29 12:44
* @className: ToolsUtils
* 工具类方法
*/
export class ToolsUtils {
//数字转换数组
numberArrays(ids:number|number[]){
let Ids:number[] = []
if (typeof ids === 'number'){
Ids.push(ids)
} else {
Ids = ids
}
return Ids
}
//字符串转换数组
stringArrays(ids:string|string[]){
let Ids:string[] = []
if (typeof ids === 'string'){
Ids.push(ids)
} else {
Ids = ids
}
return Ids
}
}

const toolsUtils = new ToolsUtils();
export default toolsUtils as ToolsUtils;
94 changes: 65 additions & 29 deletions entry/src/main/ets/common/utils/bookGroupUtils.ets
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,97 @@
import BookGroupsDao from '../../database/dao/BookGroupsDao'
import BooksDao from '../../database/dao/BooksDao'
import { BookGroups } from '../../database/entities/BookGroups'
import toolsUtils from './ToolsUtils'

class bookGroupUtils{
//校验唯一性,同时进行更新
async onlyGroupUpdateName(newName: string, id: number) {
return await BookGroupsDao.onlyGroupUpdateName(id,newName)
}
//置顶分组
async isTopGroup(id: number, isTop?: boolean): Promise<boolean> {
return BookGroupsDao.isUpdateGroupTop(id, isTop)
async isTopGroup(id: number|number[], isTop: boolean) {
let Ids:number[] = []
if (typeof id === 'number'){
Ids.push(id)
} else {
Ids = id
}
Ids.forEach((item:number)=>{
BookGroupsDao.isUpdateGroupTop(item, isTop)
})

}
//添加分组
async addGroup(books: BookGroups){
BookGroupsDao.insert(books)
}
//删除分组
async delGroupById(id:number){
async delGroupById(id:number|number[]){
let Ids = toolsUtils.numberArrays(id)
if (Ids.length === 0) return
//删除分组
BookGroupsDao.deleteBook(id)
BookGroupsDao.deleteBook(Ids)
//同时更新书籍分组为未分组
BooksDao.queryBookByGroup(id, 3)
BooksDao.queryBookByGroup(Ids, 3)
}

//管理页面批量移动分组
async moveBookByGroupId(oldGroup:number|number[], newGroup:number){
//同时更新书籍分组为未分组
let Ids:number[] = []
if (typeof oldGroup === 'number'){
Ids.push(oldGroup)
} else {
Ids = oldGroup
/**
* @author 2008
* @param oldGroup
* @param newGroup
* 分组批量移动
*/
async moveBookByGroupId(oldGroup: number | number[], newGroup: number) {
try {
let Ids: number[] = toolsUtils.numberArrays(oldGroup)
//如果Ids里面有存在newGroup则把Ids移除
if (Ids.includes(newGroup)) {
Ids = Ids.filter(item => item !== newGroup);
}
// 根据旧的分组Id获取书籍Id
const booksInGroup = await BooksDao.queryBooksByGroupId(Ids);

// 更新书籍分组
await BooksDao.updateBookGroup(booksInGroup, newGroup);

//将旧分组书籍id移除
BookGroupsDao.updateMoveGroupBookIds(Ids)

//更新移动的分组下的bookId将GroupBookIds中的值添加到新的分组中
BookGroupsDao.updateAddBookIds(newGroup, booksInGroup.map(val => val.toString()))

} catch (e) {
console.log('moveBookByGroupId, Error, ', JSON.stringify(e));
}
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
}
async updateGroupShow(groupId:number|number[], isShow?:boolean){
let Ids:number[] = toolsUtils.numberArrays(groupId)
Ids.forEach((item:number)=>{
BookGroupsDao.updateGroupShow(item)
BookGroupsDao.updateGroupShow(item,isShow)
})
}

//更新分组的bookIds
async updateAddBookIds(newGroupId:number,bookId:number,data?:Record<number, number[]>){
async updateAddBookIds(newGroupId:number,bookId:number|number[]){
//循环更新
let book:number[] = toolsUtils.numberArrays(bookId)

if(newGroupId && bookId){
BookGroupsDao.updateAddBookIds(newGroupId, bookId)
BookGroupsDao.updateAddBookIds(newGroupId, book.map(val => val.toString()))
}
}

//移除分组下的bookId
async updateMoveBookIdsByGroupId(oldGroupId:number,bookId:number,data?:Record<number, number[]>){
if (oldGroupId && bookId) {
BookGroupsDao.updateMoveBookIdsByGroupId(oldGroupId, bookId)
}
updateMoveBookIdsByGroupId(data:Record<number, number>){
BookGroupsDao.updateMoveBookIdsByGroupId(data)
}

//分组批量移动书籍
updateMoveGroupBookIds(data:Record<number, number>){
BookGroupsDao.updateMoveBookIdsByGroupId(data)
}
}
let bookGroupUtil = new bookGroupUtils();
Expand Down
57 changes: 41 additions & 16 deletions entry/src/main/ets/common/utils/booksUtils.ets
Original file line number Diff line number Diff line change
@@ -1,34 +1,59 @@
/**
* @author 2008
* @datetime 2024/7/23 10:58
* @className: booksUtils
*/
import BooksDao from '../../database/dao/BooksDao'
import { Books } from '../../database/entities/Books'
import bookGroupUtils from './bookGroupUtils'
import toolsUtils from './ToolsUtils'

class booksUtils{
async isTopBook(id: number, isTop?: boolean): Promise<boolean> {
return BooksDao.isUpdateBookTop(id, isTop)
async isTopBook(id: number|number[], isTop: boolean): Promise<boolean>{
let Ids:number[] = toolsUtils.numberArrays(id)
try {
Ids.forEach((item:number)=>{
BooksDao.isUpdateBookTop(item, isTop)
})
return true
} catch (e){
return false
}
}
async addBooks(books: Books){
BooksDao.insert(books)
}

async updateBooks(id:number|number[], group:number,oldGroup?:number){
/**
* @author 2008
* @param id 需要移动的书籍Id
* @param group 移动到的分组Id
* updateBooks 书籍批量移动
*/
async updateBooks(id:number|number[], group:number){
let BookGroupId: Record<number, number> = {}
//循环更新
let booId:number[] = []
if (typeof id === 'number'){
booId.push(id)
let bookId:number[] = toolsUtils.numberArrays(id)
//根据书籍获取旧的分组Id
BookGroupId = await BooksDao.getBookIdsByGroupId(bookId)

if (Object.values(BookGroupId).map(o=>o).length === 0){
await bookGroupUtils.updateAddBookIds(group, bookId)
} else {
booId = id
bookGroupUtils.updateMoveBookIdsByGroupId(BookGroupId)
//同时将新的书籍Id添加到分组中
bookGroupUtils.updateAddBookIds(group, bookId)
}
booId.forEach((item:number)=>{
//再去更新新的书籍的分组
bookId.forEach((item:number)=>{
BooksDao.updateBookGroup(item,group)
})
}

async delBooksById(id:number){
BooksDao.deleteBook(id)
async delBooksById(id:number|number[]){
let BookGroupId: Record<number, number> = {}
let bookId:number[] = toolsUtils.numberArrays(id)
//根据书籍获取分组Id
BookGroupId = await BooksDao.getBookIdsByGroupId(bookId)
if (Object.values(BookGroupId).map(o=>o).length > 0) {
bookGroupUtils.updateMoveBookIdsByGroupId(BookGroupId)
}

BooksDao.deleteBook(bookId)
}
}
let booksUtil = new booksUtils();
Expand Down
4 changes: 2 additions & 2 deletions entry/src/main/ets/componets/bookDetail/BookOverlay.ets
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export default struct BookOverlay {
.alignContent(Alignment.BottomStart)

Row(){
Image($r('app.media.occlusion1'))
Image($r('app.media.occlusion1')).draggable(false)
}
.zIndex(1)
.width(CommonConstants.NOVEL_IMG_WIDTH + 5).height(CommonConstants.NOVEL_IMG_HEIGHT - 5)

Row(){
Image($r('app.media.occlusion2'))
Image($r('app.media.occlusion2')).draggable(false)
}.zIndex(0)
.width(CommonConstants.NOVEL_IMG_WIDTH + 10).height(CommonConstants.NOVEL_IMG_HEIGHT - 10)
}
Expand Down
24 changes: 13 additions & 11 deletions entry/src/main/ets/componets/common/InsideCircleIcon.ets
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
/**
* @author 2008
* @datetime 2024/5/23 22:35
* @className: InsideCircleIcon
*/
import { buttonList } from '../dataList/buttonList'

@Component
export default struct InsideCircleIcon{
@Prop item:buttonList
@Prop icon:Resource
@Prop title:string
build() {
Column({
space:8
}){
Column(){
Image(this.item.icon)
.width(24).height(24).margin(12)
}.borderRadius(50)
Image(this.icon)
.width(24)
.height(24)
.margin(12)
}
.borderRadius(50)
.border({width:0.5,color:'rgba(0, 0, 0, 0.15)'})
Text(this.item.title).fontColor($r('app.string.color_black_65')).fontSize(12).fontWeight(400).lineHeight(20)
Text(this.title)
.fontColor($r('app.string.color_black_65'))
.fontSize(12)
.fontWeight(400)
.lineHeight(20)
}
.alignItems(HorizontalAlign.Center)
.padding({bottom:28})
Expand Down
7 changes: 4 additions & 3 deletions entry/src/main/ets/componets/common/commonInputDialog.ets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* 通用单窗口输入弹窗
* 主要传值为title标题、textValue输入框值、cancel取消方法、confirm确认方法
*/
import PaddingConstants from '../../common/constants/PaddingConstants'
import { showMessage } from './promptShow'

@CustomDialog
Expand All @@ -17,7 +18,7 @@ export default struct commonInputDialog {
@State ValueLength:number = 0
//标题
@Prop title:string = '新增'
@Prop titleWidth:string = '80%'
// @Prop titleWidth:string = '80%'
build() {
Column() {
Text(`${this.title}` ).fontWeight(600).fontSize(20).margin({ top: 20, bottom: 10 })
Expand Down Expand Up @@ -45,10 +46,10 @@ export default struct commonInputDialog {
.padding({left:30,right:30,top:10,bottom:10})
.fontColor(Color.White)
.backgroundColor($r('app.color.theme_color'))
}.padding({top:20,bottom:20})
}.padding({top:PaddingConstants.PADDING_20,bottom:PaddingConstants.PADDING_20})
}
.padding({left:PaddingConstants.PADDING_20,right:PaddingConstants.PADDING_20})
.backgroundColor(Color.White)
.width(this.titleWidth)
}
//输入框提示
@Prop placeholder:string = '请输入内容'
Expand Down
9 changes: 6 additions & 3 deletions entry/src/main/ets/componets/common/hideDialog.ets
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ export default struct hideDialogExample {
confirm: () => void = () => {
}
@Prop title:string
@Prop isHide:boolean = true

build() {
Column() {
Text(`确定隐藏吗?` ).fontWeight(600).maxLines(1).minFontSize(12).maxFontSize(20).margin({ top: 20, bottom: 10 })
Text('隐藏后可点击分组标签栏右侧分组管理入口查看隐藏分组并进入').width('70%').textAlign(TextAlign.Center)
.fontColor('rgba(0, 0, 0, 0.45)').fontSize(14).fontWeight(400).lineHeight(22)
Text(`确定${this.isHide?'隐藏':'显示'}吗?` ).fontWeight(600).maxLines(1).minFontSize(12).maxFontSize(20).margin({ top: 20, bottom: 10 })
if (this.isHide){
Text('隐藏后可点击分组标签栏右侧分组管理入口查看隐藏分组并进入').width('70%').textAlign(TextAlign.Center)
.fontColor('rgba(0, 0, 0, 0.45)').fontSize(14).fontWeight(400).lineHeight(22)
}
Row({space:24}) {
Text('取消')
.onClick(() => {
Expand Down
4 changes: 3 additions & 1 deletion entry/src/main/ets/componets/group/GroupType.ets
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ export default struct groupTypeComponent {
index:item.groupId,
bookTypeNumber:this.bookTypeNumber
}).onClick(() => {
this.bookTypeNumber = item?.groupId||0
if (item.groupName === '分组') {
this.GROUP = '文件夹'
} else {
this.GROUP = '标签'
}
if (item.groupId){
this.bookTypeNumber = item.groupId
}
})
}
})
Expand Down
Loading

0 comments on commit dd717d1

Please sign in to comment.