Skip to content

Commit

Permalink
feat: 下拉框选项选中状态修复 (#218)
Browse files Browse the repository at this point in the history
* feat: 下拉框选项选中状态修复

* fix: 修改SideBar组件@prop改为@link导致的bug

* feat: 新增字段showExplore,用于发现页面中筛选的显示和隐藏,不直接使用enabled,寓意冲突
  • Loading branch information
yi-boide authored Jul 21, 2024
1 parent 49aa6e6 commit 3520060
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 24 deletions.
2 changes: 1 addition & 1 deletion entry/src/main/ets/componets/common/SideBar.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
14 changes: 8 additions & 6 deletions entry/src/main/ets/componets/source/SourceView.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
})
Expand Down Expand Up @@ -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) => {
Expand All @@ -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
Expand Down
10 changes: 9 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, `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",
Expand Down Expand Up @@ -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": {
Expand Down
11 changes: 8 additions & 3 deletions entry/src/main/ets/database/dao/BookSourceDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -46,7 +46,7 @@ class BookSourceDao {
async flowAll(): Promise<BookSourcePart[]> {
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<BookSourcePart>(sql, column)
Expand All @@ -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
Expand All @@ -79,7 +80,8 @@ class BookSourceDao {
weight,
trim(exploreUrl) <> '' AS hasExploreUrl,
isTop,
showRecentIcon
showRecentIcon,
showExplore
FROM
book_sources
`;
Expand All @@ -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}`);
}
Expand Down
6 changes: 5 additions & 1 deletion entry/src/main/ets/database/entities/BookSource.ets
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class BookSource {
isTop: boolean = false
//是否新增或则更新点击过
showRecentIcon: boolean = true
showExplore: boolean = true
}

export interface GroupList {
Expand All @@ -94,7 +95,7 @@ export const BOOK_SOURCE_TYPE: Record<number, string> = {
2 : '漫画',
1 : '有声'
}

export const SOURCE_SCORE_ARR = ['5.0分', '4.0分', '3.0分', '2.0分', '1.0分']
export const SOURCE_GROUP_MAP: Record<number, string[]> = {
0: ['男频', '女频', '综合', '出版', '下载', '正版', '轻文', '网络', '其他'],
1: ['听书', '音乐', '正版', '其他'],
Expand Down Expand Up @@ -152,6 +153,7 @@ export const ToBookSource = (bookSourceDb: BookSourceDb) => {
searchUrl: bookSourceDb.searchUrl,
isTop: bookSourceDb.isTop,
showRecentIcon: bookSourceDb.showRecentIcon,
showExplore: bookSourceDb.showExplore,
ruleExplore,
ruleSearch,
ruleBookInfo,
Expand Down Expand Up @@ -198,6 +200,7 @@ export const ToBookSourceDb = (bookSource: BookSource) => {
searchUrl: bookSource.searchUrl,
isTop: bookSource.isTop,
showRecentIcon: bookSource.showRecentIcon,
showExplore: bookSource.showExplore,
ruleExplore,
ruleSearch,
ruleBookInfo,
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions entry/src/main/ets/database/entities/BookSourcePart.ets
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export class BookSourcePart {
isTop: boolean = false
//是否新增或则更新点击过
showRecentIcon: boolean = true
showExplore: boolean = true
}
2 changes: 2 additions & 0 deletions entry/src/main/ets/database/types/BookSourceType.ets
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface BookSourceSearchParams {
hasLoginUrl?: boolean,
// 是否存在发现
hasExploreUrl?: boolean
// 是否显示的发现
showExplore?: boolean
}

export interface ExploreQuery {
Expand Down
18 changes: 9 additions & 9 deletions entry/src/main/ets/pages/view/Find/BookSource/AddSourcePage.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,7 +49,8 @@ struct AddSourcePage {
customOrder: 0,
weight: 0,
isTop: false,
showRecentIcon: false
showRecentIcon: false,
showExplore: true
}

async aboutToAppear() {
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '松开刷新'
Expand Down

0 comments on commit 3520060

Please sign in to comment.