Skip to content

Commit

Permalink
feat: 书源管理筛选器过滤 (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-boide authored Jul 31, 2024
1 parent dd717d1 commit 5ae4d07
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 117 deletions.
2 changes: 1 addition & 1 deletion entry/src/main/ets/componets/import/ImportCommon.ets
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Score from '../common/Score';
import Tag from '../common/Tag';
import BookSourceDao from '../../database/dao/BookSourceDao';
import { BookSource, GroupList, SOURCE_GROUP_MAP } from '../../database/entities/BookSource';
import SourceGroup from '../ui/sourceGroup';
import SourceGroup from '../ui/SourceGroup';

@Component
export default struct ImportCommon {
Expand Down
14 changes: 9 additions & 5 deletions entry/src/main/ets/database/dao/BookSourceDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class BookSourceDao {
getFlowColumn() {
const column: ColumnInfo[] = AppDatabaseUtil.getAssignColumn(this.TABLE_NAME,
['bookSourceUrl', 'bookSourceName', 'bookSourceGroup', 'bookSourceGrade', 'bookSourceScore', 'customOrder',
'enabled', 'enabledExplore', 'lastUpdateTime', 'respondTime', 'weight', 'isTop', 'showRecentIcon', 'showExplore']);
'enabled', 'enabledExplore', 'lastUpdateTime', 'respondTime', 'weight', 'isTop', 'showRecentIcon',
'showExplore']);
column.push(...[
{
name: 'hasLoginUrl',
Expand Down Expand Up @@ -63,6 +64,7 @@ class BookSourceDao {
const bookSourceGrade = searchParams?.bookSourceGrade;
const hasLoginUrl = searchParams?.hasLoginUrl;
const showExplore = searchParams?.showExplore;
const order = searchParams?.order;
try {
let sql = `
SELECT
Expand Down Expand Up @@ -117,10 +119,12 @@ class BookSourceDao {
sql += ` WHERE ${whereClause.join(' AND ')}`;
}

sql += `
ORDER BY
isTop DESC, customOrder ASC
`;
sql += ` ORDER BY`;
if (order !== undefined) {
sql += ` ${order === 0 ? 'bookSourceGroup' : 'lastUpdateTime'} DESC`
} else {
sql += ` isTop DESC, customOrder ASC`;
}
const column: ColumnInfo[] = this.getFlowColumn()
return await DbUtil.querySqlForList<BookSourcePart>(sql, column)
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion entry/src/main/ets/database/types/BookSourceType.ets
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface BookSourceSearchParams {
type?: number,
// 是否启用
enabled?: boolean,
// TODO 排序,还未实现
// 排序 0 按评分排序 1 按时间排序
order?: number,
// 等级
bookSourceGrade?: number,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@Component
export default struct FilterText {
index: number = 0
@Prop title: string
@Prop hasActive: boolean = false
isIcon: boolean = true
onChange: (val: number) => void = (_val) => {}

build() {
Row() {
Text(this.title)
.fontSize(12)
.fontColor(this.hasActive ? '#FF6600' : '#E0000000')

if (this.isIcon) {
Image($r('app.media.down_arrow'))
.width(8)
.margin({ left: 6 })
.fillColor(this.hasActive ? '#FF6600' : '#E0000000')
}
if (this.index === 4 && this.hasActive) {
Image($r('app.media.close'))
.width(8)
.margin({ left: 2 })
.fillColor(this.hasActive ? '#FF6600' : '#E0000000')
}
}
.height(22)
.padding({
top: 2,
bottom: 2,
left: 4,
right: 4
})
.layoutWeight(1)
.backgroundColor(this.hasActive ? 'rgba(255, 102, 0, 0.12)' : Color.White)
.borderRadius(4)
.alignItems(VerticalAlign.Center)
.justifyContent(FlexAlign.Center)
.onClick(() => {
this.onChange(this.index)
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export interface Options {
label: string;
value?: number | string | boolean;
}


@Component
export default struct FiltrateOption {
options: Options[] = []
columns: number = 3
isAgain: boolean = false
@Prop value?: number | string | boolean
onChange: (value?: number | string | boolean) => void = () => {}

build() {
Grid() {
ForEach(this.options, (item: Options) => {
GridItem() {
Text(item.label)
.fontColor(this.value === item.value ? '#FF6600' : '#E0000000')
.fontSize(12)
.height(20)
.lineHeight(20)
}
.border({
radius: 4,
width: 1,
style: BorderStyle.Solid,
color: this.value === item.value ? '#FF6600' : '#0A000000'
})
.padding({ top: 6, bottom: 6 })
.backgroundColor(this.value === item.value ? 'rgba(255, 102, 0, 0.12)' : '#0A000000')
.onClick(() => {
if (this.value !== undefined && this.isAgain && this.value === item.value) {
this.onChange(undefined)
return
}
this.onChange(item.value)
})
})
}
.columnsTemplate(Array(this.columns).fill('1fr').join(' '))
.columnsGap(16)
.rowsGap(16)
.padding({ bottom: 12, top: 12 })
}
}
Loading

0 comments on commit 5ae4d07

Please sign in to comment.