Skip to content

Commit

Permalink
fix:书架书籍添加排序功能、优化布局
Browse files Browse the repository at this point in the history
1.书架书籍添加排序功能
2.优化布局
  • Loading branch information
MaoXiaoone committed Aug 8, 2024
1 parent ecf53f2 commit 47b11aa
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 72 deletions.
7 changes: 6 additions & 1 deletion entry/src/main/ets/common/utils/booksUtils.ets
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BooksDao from '../../database/dao/BooksDao'
import { Books } from '../../database/entities/Books'
import { Books, BOOK_SEARCH_TYPE } from '../../database/entities/Books'
import bookGroupUtils from './bookGroupUtils'
import toolsUtils from './ToolsUtils'

Expand Down Expand Up @@ -60,6 +60,11 @@ class booksUtils{
let bookId: number[] = toolsUtils.numberArrays(ids)
return await BooksDao.getBookByIds(bookId)
}

//校验类型数据查询数组内容
getOrder(type:string){
return BOOK_SEARCH_TYPE.indexOf(type) ?? 0;
}
}
let booksUtil = new booksUtils();
export default booksUtil as booksUtils;
2 changes: 2 additions & 0 deletions entry/src/main/ets/componets/group/GroupTypeSearch.ets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default struct groupTypeSearch {
@Link groupCoverShow:boolean
@State groupList:BookGroups[] = []
@Link bookTypeNumber:number
@Link searchBookList:number[]
aboutToAppear(): void {
this.getGroupList()
}
Expand All @@ -30,6 +31,7 @@ export default struct groupTypeSearch {
groupCoverShow:this.groupCoverShow,
showGroupList:this.groupList,
currentIndex:this.currentIndex,
searchBookList:this.searchBookList
})
.zIndex(9999)
Rect()
Expand Down
1 change: 0 additions & 1 deletion entry/src/main/ets/componets/group/groupTypePanel.ets
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ export default struct groupTypePanel{
}

@State isShowBookFolderInfoDialog:boolean = false
@Provide searchBookList:number[] = []
@Builder bookFolderInfoDialog(){
Column(){
BookManageDialog({
Expand Down
4 changes: 3 additions & 1 deletion entry/src/main/ets/componets/group/groupTypeSearchPanel.ets
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default struct groupTypeSearchPanel{
@State hideList:BookGroups[] = []
@Prop currentIndex:number = 0
@Prop clickGroup:BookGroups
@Link searchBookList:number[]
aboutToAppear(): void {
this.getGroupList()
}
Expand Down Expand Up @@ -160,7 +161,8 @@ export default struct groupTypeSearchPanel{
bookTypeNumber:this.clickGroup.groupId,
isManage:true,
isManageSearch:true,
searchCheck:()=>{
searchCheck:(val:number[])=>{
this.searchBookList = val
this.isShowBookFolderInfoDialog = false
}
})
Expand Down
83 changes: 54 additions & 29 deletions entry/src/main/ets/componets/head/IndexSearchType.ets
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import CommonConstants from '../../common/constants/CommonConstants'
import FontConstants from '../../common/constants/FontConstants'
import PaddingConstants from '../../common/constants/PaddingConstants'
import { BOOK_SEARCH_TYPE } from '../../database/entities/Books'

@Component
export default struct IndexSearchType {
@Prop title:string
@Link searchValue:string
@State isShown: boolean = false
@State THEME_NAME: string[] = ['最近阅读', '阅读排序', '更新排序', '手动排序']

build() {
if (this.THEME_NAME.includes(this.title)){
if (BOOK_SEARCH_TYPE.includes(this.title)){
Row(
{
space:3
Expand All @@ -24,12 +28,23 @@ export default struct IndexSearchType {
this.searchValue = this.title
this.isShown = !this.isShown
})
.bindMenu(this.isShown, this.MenuBuilder,
{
onDisappear: ()=>{
.bindPopup(this.isShown,{
builder: this.MenuBuilder(),
placement: Placement.Bottom,
enableArrow:true,
radius:12,
onStateChange: (e) => {
if (!e.isVisible) {
this.isShown = false;
}
})
}
})
// .bindMenu(this.isShown, this.MenuBuilder,
// {
// onDisappear: ()=>{
// this.isShown = false;
// }
// })
} else {
Row(
{
Expand All @@ -46,31 +61,41 @@ export default struct IndexSearchType {
}

@Builder MenuBuilder() {
Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
ForEach(this.THEME_NAME, (item:string, index) => {
if (item !== this.searchValue){
Column() {
Row() {
Text(item).fontSize(15)
}
.width('100%')
.height(30)
.justifyContent(FlexAlign.Center)
.align(Alignment.Center)
.onClick(() => {
this.title = item
this.searchValue = item
// this.THEME_NAMES = this.THEME_NAME.filter((value) => {
// return value !== item;
// })
})
if (index != this.THEME_NAME.length - 1) {
Divider().height(10).width('80%').color('#ccc')
}
Column(){
ForEach(BOOK_SEARCH_TYPE, (item:string, index) => {
Column() {
Row() {
Text(item)
.font({
size: FontConstants.FONT_SIZE_14,
weight: FontConstants.FONT_WEIGHT_400,
family: CommonConstants.FAMILY_PingFANG
})
.fontColor(this.searchValue === item ? $r('app.color.theme_color') : $r('app.string.color_black_88'))
Image(item === this.searchValue?$r('app.media.hook'):'').width(20).height(20)
}
.padding({
top: PaddingConstants.PADDING_12,
bottom: PaddingConstants.PADDING_12,
left:PaddingConstants.PADDING_20,
right:PaddingConstants.PADDING_20
})
.width('100%')
.height(40)
.justifyContent(FlexAlign.SpaceBetween)
.align(Alignment.Center)
.onClick(() => {
this.title = item
this.searchValue = item
this.isShown = false
})
if (index != BOOK_SEARCH_TYPE.length - 1) {
Divider().height(10).width('80%').color('#ccc')
}
}

})
}.width(150)
}
.padding(PaddingConstants.PADDING_4)
.width(150)
}
}
27 changes: 23 additions & 4 deletions entry/src/main/ets/database/dao/BooksDao.ets
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import booksUtils from '../../common/utils/booksUtils';
import DbUtil from '../../common/utils/DbUtil';
import toolsUtils from '../../common/utils/ToolsUtils';
import AppDatabaseUtil from '../AppDatabaseUtil';
Expand Down Expand Up @@ -27,6 +28,11 @@ class BooksDao {
let searchKey = param?.searchKey ?? '';
let type = param?.type;
let bookGroup = param?.bookGroup;
let order = param?.order;
let sort = 0
if (order !== undefined){
sort = booksUtils.getOrder(order)
}
try {
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
let sql = `SELECT * FROM ${this.TABLE_NAME}`;
Expand All @@ -50,10 +56,23 @@ class BooksDao {
if (whereClause.length > 0) {
sql += ` WHERE ${whereClause.join(' AND ')}`;
}
sql += `
ORDER BY
isTop DESC, createTime DESC
`;
sql += ` ORDER BY`;
if (order !== undefined) {
switch (sort){
case 0:
sql += ` isTop DESC, durChapterTime DESC`;
break;
case 1:
sql += ` isTop DESC, latestChapterTime DESC`;
break;
case 2:
sql += ` isTop DESC, sort ASC`;
break;
}
} else {
sql += ` isTop DESC, createTime DESC`;
}

const bookDbList = await DbUtil.querySqlForList<Books>(sql, column);
console.log("TagInfo", '书籍:' + bookDbList.length)
return bookDbList
Expand Down
4 changes: 3 additions & 1 deletion entry/src/main/ets/database/entities/Books.ets
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ export class Books {
updateTime?:number = 0
//是否加入书架
isJoin:boolean = false
}
}

export const BOOK_SEARCH_TYPE: string[] = ['最近阅读', '更新排序', '手动排序']
4 changes: 3 additions & 1 deletion entry/src/main/ets/database/types/BooksType.ets
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ export interface BooksTypeSearchParams {
// 源类型 0 小说;1 漫画;2 有声书;
type?: number,
//分组
bookGroup?: number
bookGroup?: number,
//排序方式
order?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default struct dialogNewSources{

@Builder
newSourcesBuilder(){
Flex(){
Column(){
newSources({
isEdit:false,
hideNewSources:()=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default struct SubscriptionContent{

@Builder
newSourcesBuilder(){
Flex(){
Column(){
newSources({
isEdit:true,
hideNewSources:()=>{
Expand Down
1 change: 0 additions & 1 deletion entry/src/main/ets/pages/view/bookShelf/BookFolder.ets
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export default struct BookFolder {
})
}
@Prop clickGroup:BookGroups
@Provide searchBookList:number[] = []
@Builder bookFolderInfoDialog(){
Column(){
BookManageDialog({
Expand Down
3 changes: 0 additions & 3 deletions entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export default struct IndexShelf {
this.bookTypeNumber = 2
}
}
@State searchValue: string = '最近阅读'

@State isShowImport: boolean = false
@State isShowCloudImport: boolean = false
@State isShowImportBookList: boolean = false
Expand Down Expand Up @@ -174,7 +172,6 @@ export default struct IndexShelf {
currentIndex: this.currentIndex,
EXHIBIT: this.EXHIBIT,
GROUP: this.GROUP,
searchValue: this.searchValue,
bookTypeNumber:this.bookTypeNumber
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default struct newAddShelf{
@StorageLink('bottomRectHeight') bottomRectHeight: number = 0
@State @Watch('getBookList')bookTypeNumber:number = 2
@State groupCoverShow: boolean = false
@Provide @Watch('searchBook')searchBookList:number[] = []
@State @Watch('searchBook')searchBookList:number[] = []
//用于分组弹窗添加书籍
searchBook(){
if (this.searchBookList.length === 0 ) return
Expand Down Expand Up @@ -102,7 +102,8 @@ export default struct newAddShelf{
Stack(){
groupTypeSearch({
bookTypeNumber:this.bookTypeNumber,
groupCoverShow:this.groupCoverShow
groupCoverShow:this.groupCoverShow,
searchBookList:this.searchBookList
})
.zIndex(9)
Column(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import newAddShelf from './newAddShelf'

@Component
export default struct newBookShelf{
@StorageLink('topRectHeight') topRectHeight: number = 0
@StorageLink('bottomRectHeight') bottomRectHeight: number = 0
@Prop currentIndex:number
@State TextRecommend:Record<number, string> = {}
@State delCache:boolean = false
Expand Down Expand Up @@ -272,6 +274,10 @@ export default struct newBookShelf{
}
})
}
.padding({
top:this.topRectHeight,
bottom:this.bottomRectHeight
})
}

@Builder newAddBook(){
Expand All @@ -281,7 +287,7 @@ export default struct newBookShelf{
addBookList:(selectBookId:number[])=>{
this.newBookIds = selectBookId
this.isShowAddBook = false;
showMessage('加入书单成功,提交生效!', 1000)
showMessage('加入书单成功,提交生效!')
},
close:() => {
this.isShowAddBook = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export default struct catalogAddShelf{
@Prop showNumber:number = 0
@State worksBook:WorksLists = new WorksLists()
@State worksLists:WorksLists[] =[]
@StorageLink('topRectHeight') topRectHeight: number = 0
@StorageLink('bottomRectHeight') bottomRectHeight: number = 0
@State newBookIds:number[] = []
getWorkLists() {
worksListsDao.search({
Expand Down Expand Up @@ -128,10 +126,6 @@ export default struct catalogAddShelf{
bookIds: this.newBookIds
})
}
.padding({
top:this.topRectHeight,
bottom:this.bottomRectHeight
})
.backgroundColor(Color.White)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export default struct WorksBookLists {
@Prop worksLists:WorksLists[] =[]
@Prop isShowCheck:boolean = false
@State worksBook:WorksLists = new WorksLists()
@StorageLink('topRectHeight') topRectHeight: number = 0
@StorageLink('bottomRectHeight') bottomRectHeight: number = 0
@StorageLink('BOOK_IS_BOOK_WORKS_BOOK_LIST') @Watch('getWorkLists')isWorksBookListRefreshing: number = 0
aboutToAppear(): void {
if (this.worksLists.length === 0) {
Expand Down Expand Up @@ -116,10 +114,6 @@ export default struct WorksBookLists {
lastWorkBookList:this.worksBook
})
}
.padding({
top:this.topRectHeight,
bottom:this.bottomRectHeight
})
.backgroundColor(Color.White)
}
shelfInfoDialog: CustomDialogController | null = new CustomDialogController({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default struct BookBodyContent {
@State GROUP_NAMES: string[] = ['标签', '文件夹']
@Link EXHIBIT: string
@Link GROUP: string
@Link searchValue: string
@State searchValue: string = '最近阅读'
@Link bookTypeNumber:number
@State title: string = '最近阅读'
@State groupCoverShow: boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default struct BookContent {
this.getBookList()
}
@Prop EXHIBIT:string
@Prop searchValue:string
@Prop @Watch('getBookList')searchValue:string
@Prop @Watch('changeBookType')currentIndex: number
@Prop @Watch('changeBookType')bookTypeNumber:number
//更新数据累加刷新数据页面
Expand All @@ -29,7 +29,8 @@ export default struct BookContent {
getBookList(){
booksDao.search({
type:this.currentIndex,
bookGroup:this.bookTypeNumber
bookGroup:this.bookTypeNumber,
order:this.searchValue
}).then((val)=>{
this.bookList = val
})
Expand Down
Loading

0 comments on commit 47b11aa

Please sign in to comment.