From 418699aa15e5d935f93e5ceb9c7cba003175f195 Mon Sep 17 00:00:00 2001 From: 2008 <59199830@qq.com> Date: Wed, 4 Dec 2024 23:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=BA=90->=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E7=AE=A1=E7=90=86->=E5=AE=9E=E7=8E=B0=E5=85=A8=E9=80=89?= =?UTF-8?q?=E3=80=81=E5=8F=96=E6=B6=88=E5=85=A8=E9=80=89=E3=80=81=E5=8D=95?= =?UTF-8?q?=E9=A1=B9=E9=80=89=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 订阅源->批量管理->实现全选、取消全选、单项选中 --- .../ets/database/dao/RssSourcesHistoryDao.ets | 2 + .../view/Subscription/SubscriptionIndex.ets | 36 ++++++-- .../components/SubscriptionContent.ets | 90 ++++++++++++------- .../main/resources/base/element/string.json | 4 + .../main/resources/en_US/element/string.json | 4 + .../main/resources/zh_CN/element/string.json | 4 + 6 files changed, 104 insertions(+), 36 deletions(-) diff --git a/entry/src/main/ets/database/dao/RssSourcesHistoryDao.ets b/entry/src/main/ets/database/dao/RssSourcesHistoryDao.ets index 2183e151..5eb8f814 100644 --- a/entry/src/main/ets/database/dao/RssSourcesHistoryDao.ets +++ b/entry/src/main/ets/database/dao/RssSourcesHistoryDao.ets @@ -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'; @@ -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)) diff --git a/entry/src/main/ets/pages/view/Subscription/SubscriptionIndex.ets b/entry/src/main/ets/pages/view/Subscription/SubscriptionIndex.ets index 2ca87b16..a32371c3 100644 --- a/entry/src/main/ets/pages/view/Subscription/SubscriptionIndex.ets +++ b/entry/src/main/ets/pages/view/Subscription/SubscriptionIndex.ets @@ -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 = {} @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 //刷新 @@ -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(() => { @@ -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%') @@ -162,6 +184,7 @@ export default struct SubscriptionIndex { } else if (!this.groupList.length) { SubscriptionContent({ subscriptionTitle: '收藏', + batchEdit:this.batchEdit, showAddDialog: () => { this.isShowNewSources = true } @@ -173,6 +196,7 @@ export default struct SubscriptionIndex { SubscriptionContent({ subscriptionTitle: item.title, contentList: item.list, + batchEdit:this.batchEdit, refresh: this.refresh }) }) diff --git a/entry/src/main/ets/pages/view/Subscription/components/SubscriptionContent.ets b/entry/src/main/ets/pages/view/Subscription/components/SubscriptionContent.ets index c9e66e86..ba29f35a 100644 --- a/entry/src/main/ets/pages/view/Subscription/components/SubscriptionContent.ets +++ b/entry/src/main/ets/pages/view/Subscription/components/SubscriptionContent.ets @@ -22,6 +22,8 @@ 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{ @@ -29,6 +31,10 @@ export default struct SubscriptionContent{ @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 // controller: web_webview.WebviewController = new web_webview.WebviewController() refresh: () => void = () => { @@ -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 }){ @@ -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) } @@ -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) } } \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 4f0efa37..e4ccbce8 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -87,6 +87,10 @@ { "name": "export_help", "value": "导入帮助" + }, + { + "name": "clear_recently_used", + "value": "清除最近使用" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index f19292a2..2e020dee 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -87,6 +87,10 @@ { "name": "export_help", "value": "export help" + }, + { + "name": "clear_recently_used", + "value": "clear recently used" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 0537a73b..b9eb335b 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -87,6 +87,10 @@ { "name": "export_help", "value": "导入帮助" + }, + { + "name": "clear_recently_used", + "value": "clear recently used" } ] } \ No newline at end of file