Skip to content

Commit

Permalink
订阅源->批量管理->实现全选、取消全选、单项选中
Browse files Browse the repository at this point in the history
订阅源->批量管理->实现全选、取消全选、单项选中
  • Loading branch information
MaoXiaoone committed Dec 4, 2024
1 parent 1df5caa commit 418699a
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 36 deletions.
2 changes: 2 additions & 0 deletions entry/src/main/ets/database/dao/RssSourcesHistoryDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 订阅源
*/
import DbUtil from '../../common/utils/DbUtil';
import { showMessage } from '../../componets/common/promptShow';
import AppDatabaseUtil from '../AppDatabaseUtil';
import { rssSourcesHistory } from '../entities/rssSourcesHistory';
import { ColumnInfo } from '../types/ColumnInfo';
Expand Down Expand Up @@ -115,6 +116,7 @@ class RssSourcesHistoryDao {
for (let index = 0; index < rssHistory.length; index++) {
await this.deleteRssSourcesHistory(rssHistory[index].sourceUrl)
}
showMessage('清除最近使用')
return true
} catch (err) {
console.log('TagInfo, Error, ', JSON.stringify(err))
Expand Down
36 changes: 30 additions & 6 deletions entry/src/main/ets/pages/view/Subscription/SubscriptionIndex.ets
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ export default struct SubscriptionIndex {
new IconTitleVo($r('app.media.icon_rule_add'), '新建订阅'),
new IconTitleVo($r('app.media.icon_rule_batch'), '批量管理'),
]
//批量管理选中内容存储
@Provide('batchList') batchList: Record<number, boolean> = {}
@State RecentlyUsed: rssSourcesHistory[] = []
@State loading: boolean = false
@State subscriptionList: rssSources[] = []
@State rssSourcesList: rssSources[] = []
@State groupList: rssGroupList[] = []
@State batchEdit: boolean = false
//全选
@Provide('batchAll') batchAll: boolean = false
// 主题颜色
@StorageProp(ThemeStorageKey.THEME) theme: ThemeItem = {} as ThemeItem
//刷新
Expand Down Expand Up @@ -71,6 +75,12 @@ export default struct SubscriptionIndex {
const rssSources = data ?? []
console.info('TagInfo', JSON.stringify(rssSources.slice(0, 3)))
this.rssSourcesList = rssSources
//将rssSources的id存放进batchList值默认为false
rssSources.forEach((item: rssSources) => {
if (item.id) {
this.batchList[item.id] = false
}
})
this.getGroupList()
}).catch(() => {

Expand Down Expand Up @@ -128,14 +138,26 @@ export default struct SubscriptionIndex {
.height(ImageConstants.IMG_HEIGHT_24)
.bindMenu(this.MenuBuilder)
} else {
Text('全选')
Text(`${this.batchAll?'取消全选':'全选'}`)
.width('33%')
.onClick(()=>{
this.batchAll = !this.batchAll

Object.keys(this.batchList).forEach((key: string) => {
this.batchList[key] = this.batchAll
})
})
Blank(1)
Text(`已选2项`)
//获取选中项数量
Text(`已选${Object.values(this.batchList).filter(value => value === true).length}项`).width('33%')
Blank(1)
Text('完成').onClick(() => {
this.batchEdit = false
getContext(this).eventHub.emit('SubscriptionBatchEdit', true);
})
Text('完成')
.width('33%')
.onClick(() => {
this.batchList = {}
this.batchEdit = false
getContext(this).eventHub.emit('SubscriptionBatchEdit', true);
})
}
}
.width('100%')
Expand All @@ -162,6 +184,7 @@ export default struct SubscriptionIndex {
} else if (!this.groupList.length) {
SubscriptionContent({
subscriptionTitle: '收藏',
batchEdit:this.batchEdit,
showAddDialog: () => {
this.isShowNewSources = true
}
Expand All @@ -173,6 +196,7 @@ export default struct SubscriptionIndex {
SubscriptionContent({
subscriptionTitle: item.title,
contentList: item.list,
batchEdit:this.batchEdit,
refresh: this.refresh
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ import confirmDialogExample from '../../../../componets/common/confirmDialog'
import RssSourceGroup from './RssSourceGroup'
import PreviewEffectImage from './PreviewEffectImage'
import rssSourcesUtils from '../../../../common/utils/rssSourcesUtils'
import { ThemeItem } from '../../../../common/model/Theme'
import { ThemeStorageKey } from '../../../../common/constants/Theme'

@Component
export default struct SubscriptionContent{
@Prop subscriptionTitle: string
@Prop contentList: rssSources[] = []
@State isButtonFunction: boolean = false
@State contentIndex:number = 0
@Prop batchEdit: boolean
@Consume('batchAll') batchAll: boolean
@StorageProp(ThemeStorageKey.THEME) theme: ThemeItem = {} as ThemeItem
@Consume('batchList') batchList: Record<number, boolean>
// controller: web_webview.WebviewController = new web_webview.WebviewController()
refresh: () => void = () => {

Expand Down Expand Up @@ -133,7 +139,7 @@ export default struct SubscriptionContent{
columns:2
}){
ForEach(this.contentList,(item:rssSources,index:number)=>{
if (index < 2){
if (index < 2 && !this.batchEdit){
GridCol({
span:1
}){
Expand Down Expand Up @@ -167,7 +173,7 @@ export default struct SubscriptionContent{
columns: 5
}){
ForEach(this.contentList,(item:rssSources,index:number)=>{
if (index >= 2) {
if (index >= 2 || this.batchEdit) {
GridCol(){
this.contentListBuilder(item)
}
Expand Down Expand Up @@ -497,36 +503,60 @@ export default struct SubscriptionContent{

@Builder
contentListBuilder(item:rssSources){
Column({
space: CommonConstants.SPACE_6
}){
Stack(){
PreviewEffectImage({
sourceIcon:item.sourceIcon,
customizeTitle:item.customizeTitle,
PreviewWidth:ImageConstants.IMG_WIDTH_40,
PreviewHeight:ImageConstants.IMG_HEIGHT_40,
isShowTitle:false,
sourceName:item.sourceName
})
.borderRadius(8)

if (this.isShowRecentIcon(item.lastUpdateTime) && item.showRecentIcon)
Row().width(8).height(8)
Stack(){
Column({
space: CommonConstants.SPACE_6
}){
Stack(){
PreviewEffectImage({
sourceIcon:item.sourceIcon,
customizeTitle:item.customizeTitle,
PreviewWidth:ImageConstants.IMG_WIDTH_40,
PreviewHeight:ImageConstants.IMG_HEIGHT_40,
isShowTitle:false,
sourceName:item.sourceName
})
.borderRadius(8)
.backgroundColor('#EF4444')
.position({
right: -2,
top:-2
Checkbox({
group:'checkBatch',
name:JSON.stringify(item.id)
})
.onChange((val)=>{
if (item.id) {
this.batchList[item.id] = val
}
})
}
.alignContent(Alignment.TopEnd)
.select(item?.id?this.batchList[item.id]??false:false)
.width(15)
.selectedColor(this.theme.mainColor)
.unselectedColor('rgba(0, 0, 0, 0.35)')
.position({
top:-10,
right:-10
})
.visibility(this.batchEdit?Visibility.Visible:Visibility.None)
.zIndex(2)
if (this.isShowRecentIcon(item.lastUpdateTime) && item.showRecentIcon && !this.batchEdit){
Row().width(8).height(8)
.borderRadius(8)
.backgroundColor('#EF4444')
.position({
right: -2,
top:-2
})
}
}
.alignContent(Alignment.TopEnd)

Text(`${item.sourceName}`).fontSize(10)
.fontColor($r('app.string.color_black_88'))
.lineHeight(18)
.fontFamily(CommonConstants.FAMILY_PingFANG)
.fontWeight(FontConstants.FONT_WEIGHT_400)
}.margin({bottom:20})
Text(`${item.sourceName}`)
.minFontSize(8)
.maxFontSize(12)
.fontSize(10)
.fontColor($r('app.string.color_black_88'))
.lineHeight(18)
.fontFamily(CommonConstants.FAMILY_PingFANG)
.fontWeight(FontConstants.FONT_WEIGHT_400)
}.margin({bottom:20})
} .alignContent(Alignment.TopEnd)
}
}
4 changes: 4 additions & 0 deletions entry/src/main/resources/base/element/string.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
{
"name": "export_help",
"value": "导入帮助"
},
{
"name": "clear_recently_used",
"value": "清除最近使用"
}
]
}
4 changes: 4 additions & 0 deletions entry/src/main/resources/en_US/element/string.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
{
"name": "export_help",
"value": "export help"
},
{
"name": "clear_recently_used",
"value": "clear recently used"
}
]
}
4 changes: 4 additions & 0 deletions entry/src/main/resources/zh_CN/element/string.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
{
"name": "export_help",
"value": "导入帮助"
},
{
"name": "clear_recently_used",
"value": "clear recently used"
}
]
}

0 comments on commit 418699a

Please sign in to comment.