Skip to content

Commit

Permalink
feat: 发现 筛选操作,置顶,显示,隐藏 (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-boide authored Jul 20, 2024
1 parent bca8381 commit 4938b66
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 179 deletions.
44 changes: 19 additions & 25 deletions entry/src/main/ets/componets/source/SourceCommon.ets
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ImageConstants from '../../common/constants/ImageConstants'
import PaddingConstants from '../../common/constants/PaddingConstants'
import { IconTitleVo } from '../../componetsmodel/IconTitleVo'
import dialogTitleFuction from '../common/dialogTitleFuction'
import noSourceFind from '../common/noSourceFind'
import { showMessage } from '../common/promptShow'
import { dataItem } from '../dataList/dataItem'
import { sourceTabs } from './sourceTabs'
Expand All @@ -29,6 +28,7 @@ export default struct SourceCommon {
@State showMoreDialog: boolean = false
@State searchValue: string = ''
@State isBatch: boolean = false
@Link refreshCount: number

changeSourceIndex() {
this.sourceController.changeIndex(this.readIndex)
Expand All @@ -49,7 +49,6 @@ export default struct SourceCommon {
.width('90%')
.onChange((value: string) => {
this.searchValue = value
// this.getList()
})

Image($r('app.media.more_vertical'))
Expand Down Expand Up @@ -105,27 +104,22 @@ export default struct SourceCommon {
barPosition: BarPosition.Start,
controller: this.sourceController
}) {
TabContent() {
SourceView({
searchValue: this.searchValue,
isBatch: this.isBatch,
type: this.currentIndex,
index: 0
})
}
.height('100%')
.align(Alignment.Top)

TabContent() {
SourceView({
searchValue: this.searchValue,
isBatch: this.isBatch,
type: this.currentIndex,
index: 1
})
}
.height('100%')
.align(Alignment.Top)
ForEach([0, 1], (item: number) => {
TabContent() {
SourceView({
searchValue: this.searchValue,
isBatch: this.isBatch,
type: this.currentIndex,
index: item,
refreshCount: this.refreshCount,
closeDialog: () => {
this.showDialog = false
}
})
}
.height('100%')
.align(Alignment.Top)
})
}
.barWidth(0)
.barHeight(0)
Expand All @@ -141,10 +135,10 @@ export default struct SourceCommon {
}

More_Right_Dialog_Data: IconTitleVo[] = [
new IconTitleVo($r('app.media.ic_folder'), '按时间排序'),
new IconTitleVo($r('app.media.appointment_time'), '按时间排序'),
new IconTitleVo($r('app.media.icon_no_source_find'), '按评分排序'),
new IconTitleVo($r('app.media.add_book_shelf'), '书源管理'),
new IconTitleVo($r('app.media.icon_rule_batch'), '批量'),
new IconTitleVo($r('app.media.icon_rule_batch'), '批量管理'),
]

@Builder
Expand Down
101 changes: 89 additions & 12 deletions entry/src/main/ets/componets/source/SourceView.ets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { showMessage } from '../common/promptShow'
import Score from '../common/Score'
import SideBar from '../common/SideBar'
import Tag from '../common/Tag'
import { router } from '@kit.ArkUI'
import noFind from '../common/noFind'

@Component
export default struct SourceView {
Expand All @@ -17,7 +19,7 @@ export default struct SourceView {
titleArray: Array<string> = ['小说', '漫画', '有声书']
index: number = 0
type: number = 0
@Link searchValue: string
@Link @Watch('getList') searchValue: string
@State activeNameMap: Record<string, boolean> = {}
@State fullActive: boolean = false
@State groupList: GroupPartList[] = []
Expand All @@ -27,6 +29,10 @@ export default struct SourceView {
@Link isBatch: boolean
@State showRightDialogMap: Record<string, boolean> = {}
@State currentIndex: number = 0
@State topToggle: boolean = false
@Link @Watch('getList') refreshCount: number
closeDialog: () => void = () => {
}
private scroll: Scroller = new Scroller()
private secondScroll = new Scroller()

Expand Down Expand Up @@ -185,22 +191,47 @@ export default struct SourceView {
Row() {
Row() {
Column() {
Text('置顶')
Text(this.topToggle ? '取消置顶' : '置顶')
.fontSize(16)
}
.layoutWeight(1)
.onClick(() => {
showMessage('置顶')
.onClick(async () => {
if (!Object.values(this.activeNameMap).filter(o => o).length) {
showMessage('请至少选择一个')
return
}
this.sourceList.forEach((item, i) => {
if (this.activeNameMap[item.bookSourceUrl]) {
item.isTop = !this.topToggle
this.sourceList[i] = item
}
})
await BookSourceDao.batchUpdateFlow(this.sourceList)
this.activeNameMap = {}
this.refreshCount += 1
this.topToggle = !this.topToggle
})

Row().width(12)
Column() {
Text('隐藏')
Text(this.index === 0 ? '隐藏' : '显示')
.fontSize(16)
}
.layoutWeight(1)
.onClick(async () => {
showMessage('隐藏')
if (!Object.values(this.activeNameMap).filter(o => o).length) {
showMessage('请至少选择一个')
return
}
this.sourceList.forEach((item, i) => {
if (this.activeNameMap[item.bookSourceUrl]) {
item.enabled = this.index !== 0
this.sourceList[i] = item
}
})
await BookSourceDao.batchUpdateFlow(this.sourceList)
this.activeNameMap = {}
this.refreshCount += 1
})
}
.padding({
Expand All @@ -219,6 +250,30 @@ export default struct SourceView {
duration: 500
})
.padding({ bottom: this.bottomRectHeight })

Column() {
if (this.loading) {
LoadingProgress()
.color(0xff6600)
.width('50%')
Text('加载中...')
} else if (this.errorText) {
noFind()
} else if (!this.sourceList.length) {
noFind({
hintIndex: 0
})
}
}
.justifyContent(FlexAlign.Center)
.zIndex(this.loading || (this.errorText && !this.sourceList.length) ? 9 : -1)
.opacity(this.loading || (this.errorText && !this.sourceList.length) ? 1 : 0)
.width('100%')
.height('100%')
.backgroundColor('#f5f5f5')
.animation({
duration: 300
})
}
.alignContent(Alignment.Top)
}
Expand Down Expand Up @@ -295,15 +350,38 @@ export default struct SourceView {
.width(24).fillColor('#73000000')
.bindMenu(
this.showRightDialogMap[item.bookSourceUrl],
this.rightDialogBuilder(this.Item_Right_Dialog_Data, async (index: number) => {
this.rightDialogBuilder(this.Item_Right_Dialog_Data.map((itemData, index) => {
if (index === 1) {
itemData.title = item.isTop ? '取消置顶' : '置顶'
}
if (index === 3) {
itemData.title = item.enabled ? '隐藏' : '显示'
}
return itemData
}), async (index: number) => {
switch (index) {
case 0:
this.closeDialog()
router.pushUrl({
url: 'pages/view/Find/BookSource/AddSourcePage', params: {
id: item.bookSourceUrl
}
})
break;
case 1:
item.isTop = !item.isTop
this.showRightDialogMap[item.bookSourceUrl] = false
await BookSourceDao.updateFlow(item)
this.refreshCount += 1
case 2:
case 3:
case 4:
showMessage(this.Item_Right_Dialog_Data[index].title)
break;
case 3:
item.enabled = !item.enabled
this.showRightDialogMap[item.bookSourceUrl] = false
await BookSourceDao.updateFlow(item)
this.refreshCount += 1
break;
}
}),
{
Expand Down Expand Up @@ -364,10 +442,9 @@ export default struct SourceView {

Item_Right_Dialog_Data: IconTitleVo[] = [
new IconTitleVo($r('app.media.edit'), '编辑'),
new IconTitleVo($r('app.media.icon_no_source_find'), '置顶'),
new IconTitleVo($r('app.media.top'), '置顶'),
new IconTitleVo($r('app.media.search'), '搜索'),
new IconTitleVo($r('app.media.ic_logout'), '登录'),
new IconTitleVo($r('app.media.icon_rule_help'), '取消收藏'),
new IconTitleVo($r('app.media.ic_logout'), '显示'),
]

@Builder
Expand Down
18 changes: 17 additions & 1 deletion entry/src/main/ets/database/AppDatabase/index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export default {
},
{
"tableName": "book_sources",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`bookSourceUrl` TEXT NOT NULL, `bookSourceName` TEXT NOT NULL, `bookSourceGroup` TEXT, `bookSourceType` INTEGER NOT NULL, `bookUrlPattern` TEXT, `bookSourceGrade` INTEGER NOT NULL DEFAULT 2, `bookSourceScore` TEXT NOT NULL DEFAULT `5.0分`, `customOrder` INTEGER NOT NULL DEFAULT 0, `enabled` INTEGER NOT NULL DEFAULT 1, `enabledExplore` INTEGER NOT NULL DEFAULT 1, `jsLib` TEXT, `enabledCookieJar` INTEGER DEFAULT 0, `concurrentRate` TEXT, `header` TEXT, `loginUrl` TEXT, `loginUi` TEXT, `loginCheckJs` TEXT, `coverDecodeJs` TEXT, `bookSourceComment` TEXT, `variableComment` TEXT, `lastUpdateTime` INTEGER NOT NULL, `respondTime` INTEGER NOT NULL, `weight` INTEGER NOT NULL, `exploreUrl` TEXT, `exploreScreen` TEXT, `ruleExplore` TEXT, `searchUrl` TEXT, `ruleSearch` TEXT, `ruleBookInfo` TEXT, `ruleToc` TEXT, `ruleContent` TEXT, `ruleReview` TEXT, PRIMARY KEY(`bookSourceUrl`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`bookSourceUrl` TEXT NOT NULL, `bookSourceName` TEXT NOT NULL, `bookSourceGroup` TEXT, `bookSourceType` INTEGER NOT NULL, `bookUrlPattern` TEXT, `bookSourceGrade` INTEGER NOT NULL DEFAULT 2, `isTop` INTEGER NOT NULL DEFAULT 0, `showRecentIcon` INTEGER NOT NULL DEFAULT 1, `bookSourceScore` TEXT NOT NULL DEFAULT `5.0分`, `customOrder` INTEGER NOT NULL DEFAULT 0, `enabled` INTEGER NOT NULL DEFAULT 1, `enabledExplore` INTEGER NOT NULL DEFAULT 1, `jsLib` TEXT, `enabledCookieJar` INTEGER DEFAULT 0, `concurrentRate` TEXT, `header` TEXT, `loginUrl` TEXT, `loginUi` TEXT, `loginCheckJs` TEXT, `coverDecodeJs` TEXT, `bookSourceComment` TEXT, `variableComment` TEXT, `lastUpdateTime` INTEGER NOT NULL, `respondTime` INTEGER NOT NULL, `weight` INTEGER NOT NULL, `exploreUrl` TEXT, `exploreScreen` TEXT, `ruleExplore` TEXT, `searchUrl` TEXT, `ruleSearch` TEXT, `ruleBookInfo` TEXT, `ruleToc` TEXT, `ruleContent` TEXT, `ruleReview` TEXT, PRIMARY KEY(`bookSourceUrl`))",
"fields": [
{
"fieldPath": "bookSourceUrl",
Expand Down Expand Up @@ -497,6 +497,22 @@ export default {
"columnName": "ruleReview",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "isTop",
"columnName": "isTop",
"affinity": "INTEGER",
"boolean": true,
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "showRecentIcon",
"columnName": "showRecentIcon",
"affinity": "INTEGER",
"boolean": true,
"notNull": true,
"defaultValue": "1"
}
],
"primaryKey": {
Expand Down
Loading

0 comments on commit 4938b66

Please sign in to comment.