From 3520060b65b5364040ec2ee7e06f30423b36b1e9 Mon Sep 17 00:00:00 2001 From: Marvin <63292605+yi-boide@users.noreply.github.com> Date: Sun, 21 Jul 2024 22:20:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8B=E6=8B=89=E6=A1=86=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E9=80=89=E4=B8=AD=E7=8A=B6=E6=80=81=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20(#218)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 下拉框选项选中状态修复 * fix: 修改SideBar组件@Prop改为@Link导致的bug * feat: 新增字段showExplore,用于发现页面中筛选的显示和隐藏,不直接使用enabled,寓意冲突 --- .../src/main/ets/componets/common/SideBar.ets | 2 +- .../main/ets/componets/source/SourceView.ets | 14 ++++++++------ .../main/ets/database/AppDatabase/index.ets | 10 +++++++++- .../main/ets/database/dao/BookSourceDao.ets | 11 ++++++++--- .../main/ets/database/entities/BookSource.ets | 6 +++++- .../ets/database/entities/BookSourcePart.ets | 1 + .../main/ets/database/types/BookSourceType.ets | 2 ++ .../view/Find/BookSource/AddSourcePage.ets | 18 +++++++++--------- .../Find/BookSource/components/SourceView.ets | 6 ++++-- .../view/Find/components/ContentRefresh.ets | 3 ++- 10 files changed, 49 insertions(+), 24 deletions(-) diff --git a/entry/src/main/ets/componets/common/SideBar.ets b/entry/src/main/ets/componets/common/SideBar.ets index bebc2ea2..208ed002 100644 --- a/entry/src/main/ets/componets/common/SideBar.ets +++ b/entry/src/main/ets/componets/common/SideBar.ets @@ -9,7 +9,7 @@ import { GroupList, GroupPartList } from '../../database/entities/BookSource' @Component export default struct SideBar { @Link currentIndex: number - @Link sideBarList: GroupList[] | GroupPartList[] | string[] + @Prop sideBarList: GroupList[] | GroupPartList[] | string[] @Prop isBadge: boolean = false @Prop isDrag: boolean = false clickAction: Function = (_index: number) => { diff --git a/entry/src/main/ets/componets/source/SourceView.ets b/entry/src/main/ets/componets/source/SourceView.ets index d88d0bce..65924c6a 100644 --- a/entry/src/main/ets/componets/source/SourceView.ets +++ b/entry/src/main/ets/componets/source/SourceView.ets @@ -46,7 +46,7 @@ export default struct SourceView { BookSourceDao.flowSearch({ type: [0, 2, 1][this.type], searchKey: this.searchValue, - enabled: this.index === 0 + showExplore: this.index === 0 }).then(data => { const bookSource = data ?? [] console.info('TagInfo', JSON.stringify(bookSource.slice(0, 3))) @@ -148,8 +148,10 @@ export default struct SourceView { }, isBadge: !this.isBatch, isDrag: this.isBatch, - onDragChange: async (_list) => { - const bookSourcePartList = this.groupList.reduce((acc: BookSourcePart[], item) => acc.concat(item.list), []) + onDragChange: async (list) => { + this.groupList = list as GroupPartList[] + const bookSourcePartList = + this.groupList.reduce((acc: BookSourcePart[], item) => acc.concat(item.list), []) const sortBookSourcePartList = bookSourcePartList.map((item, index) => { if (index !== 0) { item.customOrder = bookSourcePartList[index - 1].customOrder + 1 @@ -238,7 +240,7 @@ export default struct SourceView { } this.sourceList.forEach((item, i) => { if (this.activeNameMap[item.bookSourceUrl]) { - item.enabled = this.index !== 0 + item.showExplore = this.index !== 0 this.sourceList[i] = item } }) @@ -368,7 +370,7 @@ export default struct SourceView { itemData.title = item.isTop ? '取消置顶' : '置顶' } if (index === 3) { - itemData.title = item.enabled ? '隐藏' : '显示' + itemData.title = item.showExplore ? '隐藏' : '显示' } return itemData }), async (index: number) => { @@ -390,7 +392,7 @@ export default struct SourceView { showMessage(this.Item_Right_Dialog_Data[index].title) break; case 3: - item.enabled = !item.enabled + item.showExplore = !item.showExplore this.showRightDialogMap[item.bookSourceUrl] = false await BookSourceDao.updateFlow(item) this.refreshCount += 1 diff --git a/entry/src/main/ets/database/AppDatabase/index.ets b/entry/src/main/ets/database/AppDatabase/index.ets index e4976a47..7dc1e883 100644 --- a/entry/src/main/ets/database/AppDatabase/index.ets +++ b/entry/src/main/ets/database/AppDatabase/index.ets @@ -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, `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`))", + "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, `showExplore` 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", @@ -513,6 +513,14 @@ export default { "boolean": true, "notNull": true, "defaultValue": "1" + }, + { + "fieldPath": "showExplore", + "columnName": "showExplore", + "affinity": "INTEGER", + "boolean": true, + "notNull": true, + "defaultValue": "1" } ], "primaryKey": { diff --git a/entry/src/main/ets/database/dao/BookSourceDao.ets b/entry/src/main/ets/database/dao/BookSourceDao.ets index 33bd2a65..7e217e0e 100644 --- a/entry/src/main/ets/database/dao/BookSourceDao.ets +++ b/entry/src/main/ets/database/dao/BookSourceDao.ets @@ -27,7 +27,7 @@ class BookSourceDao { getFlowColumn() { const column: ColumnInfo[] = AppDatabaseUtil.getAssignColumn(this.TABLE_NAME, ['bookSourceUrl', 'bookSourceName', 'bookSourceGroup', 'bookSourceGrade', 'bookSourceScore', 'customOrder', - 'enabled', 'enabledExplore', 'lastUpdateTime', 'respondTime', 'weight', 'isTop', 'showRecentIcon']); + 'enabled', 'enabledExplore', 'lastUpdateTime', 'respondTime', 'weight', 'isTop', 'showRecentIcon', 'showExplore']); column.push(...[ { name: 'hasLoginUrl', @@ -46,7 +46,7 @@ class BookSourceDao { async flowAll(): Promise { try { const sql = `select bookSourceUrl, bookSourceName, bookSourceGroup, bookSourceGrade, bookSourceScore, customOrder, enabled, enabledExplore, - trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl, isTop, showRecentIcon + trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl, isTop, showRecentIcon, showExplore from book_sources order by customOrder asc` const column: ColumnInfo[] = this.getFlowColumn() return await DbUtil.querySqlForList(sql, column) @@ -62,6 +62,7 @@ class BookSourceDao { const enabled = searchParams?.enabled; const bookSourceGrade = searchParams?.bookSourceGrade; const hasLoginUrl = searchParams?.hasLoginUrl; + const showExplore = searchParams?.showExplore; try { let sql = ` SELECT @@ -79,7 +80,8 @@ class BookSourceDao { weight, trim(exploreUrl) <> '' AS hasExploreUrl, isTop, - showRecentIcon + showRecentIcon, + showExplore FROM book_sources `; @@ -92,6 +94,9 @@ class BookSourceDao { if (enabled !== undefined) { whereClause.push(`enabled = ${enabled ? 1 : 0}`); } + if (showExplore !== undefined) { + whereClause.push(`showExplore = ${showExplore ? 1 : 0}`); + } if (bookSourceGrade !== undefined) { whereClause.push(`bookSourceGrade = ${bookSourceGrade}`); } diff --git a/entry/src/main/ets/database/entities/BookSource.ets b/entry/src/main/ets/database/entities/BookSource.ets index c71582ff..992a01f8 100644 --- a/entry/src/main/ets/database/entities/BookSource.ets +++ b/entry/src/main/ets/database/entities/BookSource.ets @@ -70,6 +70,7 @@ export class BookSource { isTop: boolean = false //是否新增或则更新点击过 showRecentIcon: boolean = true + showExplore: boolean = true } export interface GroupList { @@ -94,7 +95,7 @@ export const BOOK_SOURCE_TYPE: Record = { 2 : '漫画', 1 : '有声' } - +export const SOURCE_SCORE_ARR = ['5.0分', '4.0分', '3.0分', '2.0分', '1.0分'] export const SOURCE_GROUP_MAP: Record = { 0: ['男频', '女频', '综合', '出版', '下载', '正版', '轻文', '网络', '其他'], 1: ['听书', '音乐', '正版', '其他'], @@ -152,6 +153,7 @@ export const ToBookSource = (bookSourceDb: BookSourceDb) => { searchUrl: bookSourceDb.searchUrl, isTop: bookSourceDb.isTop, showRecentIcon: bookSourceDb.showRecentIcon, + showExplore: bookSourceDb.showExplore, ruleExplore, ruleSearch, ruleBookInfo, @@ -198,6 +200,7 @@ export const ToBookSourceDb = (bookSource: BookSource) => { searchUrl: bookSource.searchUrl, isTop: bookSource.isTop, showRecentIcon: bookSource.showRecentIcon, + showExplore: bookSource.showExplore, ruleExplore, ruleSearch, ruleBookInfo, @@ -223,6 +226,7 @@ export const ToBookSourcePart = (bookSource: BookSource) => { weight: bookSource.weight, isTop: bookSource.isTop, showRecentIcon: bookSource.showRecentIcon, + showExplore: bookSource.showExplore, hasLoginUrl: false, hasExploreUrl: false } diff --git a/entry/src/main/ets/database/entities/BookSourcePart.ets b/entry/src/main/ets/database/entities/BookSourcePart.ets index dc181bb0..5e71bcd6 100644 --- a/entry/src/main/ets/database/entities/BookSourcePart.ets +++ b/entry/src/main/ets/database/entities/BookSourcePart.ets @@ -28,4 +28,5 @@ export class BookSourcePart { isTop: boolean = false //是否新增或则更新点击过 showRecentIcon: boolean = true + showExplore: boolean = true } \ No newline at end of file diff --git a/entry/src/main/ets/database/types/BookSourceType.ets b/entry/src/main/ets/database/types/BookSourceType.ets index 79fcafcd..7e9995ab 100644 --- a/entry/src/main/ets/database/types/BookSourceType.ets +++ b/entry/src/main/ets/database/types/BookSourceType.ets @@ -15,6 +15,8 @@ export interface BookSourceSearchParams { hasLoginUrl?: boolean, // 是否存在发现 hasExploreUrl?: boolean + // 是否显示的发现 + showExplore?: boolean } export interface ExploreQuery { diff --git a/entry/src/main/ets/pages/view/Find/BookSource/AddSourcePage.ets b/entry/src/main/ets/pages/view/Find/BookSource/AddSourcePage.ets index d602e10e..78a3bafb 100644 --- a/entry/src/main/ets/pages/view/Find/BookSource/AddSourcePage.ets +++ b/entry/src/main/ets/pages/view/Find/BookSource/AddSourcePage.ets @@ -8,7 +8,8 @@ import FormItem from '../../../../componets/Form/FormItem'; import SourceDebug from './components/SourceDebug'; import { JSON } from '@kit.ArkTS'; import BookSourceDao from '../../../../database/dao/BookSourceDao'; -import { BookSource, BOOK_SOURCE_TYPE, GRADE_TYPE, SOURCE_GROUP_MAP } from '../../../../database/entities/BookSource'; +import { BookSource, BOOK_SOURCE_TYPE, GRADE_TYPE, SOURCE_GROUP_MAP, + SOURCE_SCORE_ARR } from '../../../../database/entities/BookSource'; interface RouteParams { id: string, @@ -48,7 +49,8 @@ struct AddSourcePage { customOrder: 0, weight: 0, isTop: false, - showRecentIcon: false + showRecentIcon: false, + showExplore: true } async aboutToAppear() { @@ -260,6 +262,7 @@ struct AddSourcePage { { value: '漫画' }, { value: '有声' } ]) + .selected([0, 2, 1][this.formModel.bookSourceType]) .value(BOOK_SOURCE_TYPE[this.formModel.bookSourceType || 0]) .borderRadius(4) .fontColor(this.formModel.bookSourceType !== undefined ? '#E0000000' : '#73000000') @@ -273,6 +276,7 @@ struct AddSourcePage { Select( SOURCE_GROUP_MAP[this.formModel.bookSourceType ?? 0].map(item => ({ value: item } as SelectOption)) ) + .selected(SOURCE_GROUP_MAP[this.formModel.bookSourceType ?? 0].findIndex(item => item === this.formModel.bookSourceGroup)) .value(this.formModel.bookSourceGroup ?? SOURCE_GROUP_MAP[this.formModel.bookSourceType ?? 0][0]) .borderRadius(4) .fontColor(this.formModel.bookSourceGroup ? '#E0000000' : '#73000000') @@ -304,6 +308,7 @@ struct AddSourcePage { { value: '优质' }, { value: '精品' } ]) + .selected(this.formModel.bookSourceGrade) .value(GRADE_TYPE[this.formModel.bookSourceGrade ?? 0]) .borderRadius(4) .fontColor(this.formModel.bookSourceGrade !== undefined ? '#E0000000' : '#73000000') @@ -313,13 +318,8 @@ struct AddSourcePage { .backgroundColor('#f5f5f5') .layoutWeight(1) Row().width(16) - Select([ - { value: '5.0分' }, - { value: '4.0分' }, - { value: '3.0分' }, - { value: '2.0分' }, - { value: '1.0分' }, - ]) + Select(SOURCE_SCORE_ARR.map(item => ({ value: item } as SelectOption))) + .selected(SOURCE_SCORE_ARR.findIndex(item => (item === this.formModel.bookSourceScore ?? '5.0分'))) .value(this.formModel.bookSourceScore ?? '5.0分') .borderRadius(4) .fontColor(this.formModel.bookSourceScore ? '#E0000000' : '#73000000') diff --git a/entry/src/main/ets/pages/view/Find/BookSource/components/SourceView.ets b/entry/src/main/ets/pages/view/Find/BookSource/components/SourceView.ets index 8d0f14f6..c2a617ed 100644 --- a/entry/src/main/ets/pages/view/Find/BookSource/components/SourceView.ets +++ b/entry/src/main/ets/pages/view/Find/BookSource/components/SourceView.ets @@ -230,8 +230,10 @@ export default struct SourceView { }, isBadge: !this.isBatch, isDrag: this.isBatch, - onDragChange: async (_list) => { - const bookSourcePartList = this.groupList.reduce((acc: BookSourcePart[], item) => acc.concat(item.list), []) + onDragChange: async (list) => { + this.groupList = list as GroupPartList[] + const bookSourcePartList = + this.groupList.reduce((acc: BookSourcePart[], item) => acc.concat(item.list), []) const sortBookSourcePartList = bookSourcePartList.map((item, index) => { if (index !== 0) { item.customOrder = bookSourcePartList[index - 1].customOrder + 1 diff --git a/entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets b/entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets index 262a43a4..db838b2c 100644 --- a/entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets +++ b/entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets @@ -24,7 +24,8 @@ export default struct ContentRefresh { respondTime: 0, weight: 0, isTop: false, - showRecentIcon: false + showRecentIcon: false, + showExplore: true } @State isRefreshing: boolean = false @State RefreshingTitle: string = '松开刷新'