yuzhilin

首页频道缓存

@@ -29,7 +29,8 @@ struct ChannelDialog { @@ -29,7 +29,8 @@ struct ChannelDialog {
29 @Link myChannelList: TopNavDTO[] 29 @Link myChannelList: TopNavDTO[]
30 @Link moreChannelList: TopNavDTO[] 30 @Link moreChannelList: TopNavDTO[]
31 @Link localChannelList: TopNavDTO[] 31 @Link localChannelList: TopNavDTO[]
32 - @Link indexSettingArray: string[] 32 + @Link homeChannelList: TopNavDTO[]
  33 + @Link indexSettingChannelId: number
33 controller?: CustomDialogController 34 controller?: CustomDialogController
34 confirm: (index: number) => void = () => { 35 confirm: (index: number) => void = () => {
35 } 36 }
@@ -48,9 +49,6 @@ struct ChannelDialog { @@ -48,9 +49,6 @@ struct ChannelDialog {
48 let targetItem = this.myChannelList[newIndex] 49 let targetItem = this.myChannelList[newIndex]
49 if (!(targetItem?.headlinesOn === 1 || targetItem?.movePermitted === 0 || targetItem?.homeChannel === '1')) { 50 if (!(targetItem?.headlinesOn === 1 || targetItem?.movePermitted === 0 || targetItem?.homeChannel === '1')) {
50 this.changeChannelIndex(index, newIndex) 51 this.changeChannelIndex(index, newIndex)
51 - if (index <= this.currentTopNavSelectedIndex || newIndex <= this.currentTopNavSelectedIndex) {  
52 - // this.currentTopNavSelectedIndex = this.myChannelList.findIndex(ele => ele.channelId === currentTopNavSelectedItem.channelId)  
53 - }  
54 } 52 }
55 } 53 }
56 54
@@ -214,22 +212,22 @@ struct ChannelDialog { @@ -214,22 +212,22 @@ struct ChannelDialog {
214 212
215 ListItem() { 213 ListItem() {
216 Flex({ justifyContent: FlexAlign.SpaceBetween }) { 214 Flex({ justifyContent: FlexAlign.SpaceBetween }) {
217 - ForEach(this.indexSettingArray, (text: string, index: number) => { 215 + ForEach(this.homeChannelList, (item: TopNavDTO, index: number) => {
218 Stack() { 216 Stack() {
219 - Image(this.indexSettingTabIndex === index ? $r('app.media.index_setting_button_active') : $r('app.media.index_setting_button')) 217 + Image(item.channelId === this.indexSettingChannelId ? $r('app.media.index_setting_button_active') : $r('app.media.index_setting_button'))
220 .objectFit(ImageFit.Auto) 218 .objectFit(ImageFit.Auto)
221 .rotate({ 219 .rotate({
222 angle: index === 1 ? 180 : 0 220 angle: index === 1 ? 180 : 0
223 }) 221 })
224 Row() { 222 Row() {
225 if (index === 0) { 223 if (index === 0) {
226 - Image(this.indexSettingTabIndex === index ? $r('app.media.recommend_icon') : $r('app.media.recommend_icon_active')) 224 + Image(item.channelId === this.indexSettingChannelId ? $r('app.media.recommend_icon') : $r('app.media.recommend_icon_active'))
227 .width(20) 225 .width(20)
228 } 226 }
229 - Text(text) 227 + Text(item.name)
230 .textAlign(TextAlign.Center) 228 .textAlign(TextAlign.Center)
231 .fontSize(16) 229 .fontSize(16)
232 - .fontColor(index === this.indexSettingTabIndex ? '#ffffff' : '#ED2800') 230 + .fontColor(item.channelId === this.indexSettingChannelId ? '#ffffff' : '#ED2800')
233 } 231 }
234 .width('100%') 232 .width('100%')
235 .justifyContent(FlexAlign.Center) 233 .justifyContent(FlexAlign.Center)
@@ -237,7 +235,7 @@ struct ChannelDialog { @@ -237,7 +235,7 @@ struct ChannelDialog {
237 .alignContent(Alignment.Start) 235 .alignContent(Alignment.Start)
238 .height(36) 236 .height(36)
239 .onClick(() => { 237 .onClick(() => {
240 - this.indexSettingTabIndex = index 238 + AppStorage.set('indexSettingChannelId',item.channelId)
241 }) 239 })
242 }) 240 })
243 } 241 }
@@ -280,7 +278,7 @@ struct ChannelDialog { @@ -280,7 +278,7 @@ struct ChannelDialog {
280 .fontSize(14) 278 .fontSize(14)
281 .fontColor(this.currentTopNavSelectedItem.channelId === item.channelId ? '#ED2800' : (item.homeChannel === '1' || item.movePermitted === 0 ? '#999999' : '#222222')) 279 .fontColor(this.currentTopNavSelectedItem.channelId === item.channelId ? '#ED2800' : (item.homeChannel === '1' || item.movePermitted === 0 ? '#999999' : '#222222'))
282 280
283 - if (this.isEditIng && item.myChannel !== '1') { 281 + if (this.isEditIng && item.delPermitted === 1) {
284 Image($r('app.media.icon_audio_close')) 282 Image($r('app.media.icon_audio_close'))
285 .width(12) 283 .width(12)
286 .margin({ left: 1 }) 284 .margin({ left: 1 })
@@ -292,7 +290,7 @@ struct ChannelDialog { @@ -292,7 +290,7 @@ struct ChannelDialog {
292 .backgroundColor(item.homeChannel === '1' || item.movePermitted === 0 ? '#F5F5F5' : '#ffffff') 290 .backgroundColor(item.homeChannel === '1' || item.movePermitted === 0 ? '#F5F5F5' : '#ffffff')
293 .onClick(() => { 291 .onClick(() => {
294 if (this.isEditIng) { 292 if (this.isEditIng) {
295 - if (item.myChannel !== '1') { 293 + if (item.delPermitted === 1) {
296 this.delChannelItem(index) 294 this.delChannelItem(index)
297 } 295 }
298 } else { 296 } else {
@@ -445,10 +443,13 @@ struct ChannelSubscriptionLayout { @@ -445,10 +443,13 @@ struct ChannelSubscriptionLayout {
445 @State indexSettingArray: string [] = ['推荐', '热点'] 443 @State indexSettingArray: string [] = ['推荐', '热点']
446 //当前选中的频道 444 //当前选中的频道
447 @Link currentTopNavSelectedIndex: number; 445 @Link currentTopNavSelectedIndex: number;
  446 + @Prop homeChannelList: TopNavDTO []
  447 + @Prop indexSettingChannelId: number
448 @Link myChannelList: TopNavDTO [] 448 @Link myChannelList: TopNavDTO []
449 @Link moreChannelList: TopNavDTO [] 449 @Link moreChannelList: TopNavDTO []
450 @Link localChannelList: TopNavDTO [] 450 @Link localChannelList: TopNavDTO []
451 - @Link @Watch('onChannelIdsUpdate') channelIds: number [] 451 + @Link channelIds: number []
  452 + @StorageLink('channelIds') storeChannelIds: string = ''
452 changeTab: (index: number) => void = () => { 453 changeTab: (index: number) => void = () => {
453 } 454 }
454 //频道弹窗点击切换频道 455 //频道弹窗点击切换频道
@@ -461,11 +462,13 @@ struct ChannelSubscriptionLayout { @@ -461,11 +462,13 @@ struct ChannelSubscriptionLayout {
461 let channelIdTmp = this.channelIds.splice(index1, 1) 462 let channelIdTmp = this.channelIds.splice(index1, 1)
462 this.myChannelList.splice(index2, 0, tmp[0]) 463 this.myChannelList.splice(index2, 0, tmp[0])
463 this.channelIds.splice(index2, 0, channelIdTmp[0]) 464 this.channelIds.splice(index2, 0, channelIdTmp[0])
  465 + this.storeChannelIds = this.channelIds.join(',')
464 } 466 }
465 //删除频道 467 //删除频道
466 delChannelItem = (index: number) => { 468 delChannelItem = (index: number) => {
467 let item = this.myChannelList.splice(index, 1)[0] 469 let item = this.myChannelList.splice(index, 1)[0]
468 this.channelIds.splice(index, 1) 470 this.channelIds.splice(index, 1)
  471 + this.storeChannelIds = this.channelIds.join(',')
469 if (item.moreChannel === '1') { 472 if (item.moreChannel === '1') {
470 this.moreChannelList.unshift(item) 473 this.moreChannelList.unshift(item)
471 } 474 }
@@ -477,6 +480,7 @@ struct ChannelSubscriptionLayout { @@ -477,6 +480,7 @@ struct ChannelSubscriptionLayout {
477 addChannelItem = (item: TopNavDTO) => { 480 addChannelItem = (item: TopNavDTO) => {
478 this.channelIds.push(item.channelId) 481 this.channelIds.push(item.channelId)
479 this.myChannelList.push(item) 482 this.myChannelList.push(item)
  483 + this.storeChannelIds = this.channelIds.join(',')
480 } 484 }
481 // @State currentTopNavSelectedIndex: number = 0 485 // @State currentTopNavSelectedIndex: number = 0
482 // @State topNavList: TopNavDTO [] = [ 486 // @State topNavList: TopNavDTO [] = [
@@ -1987,7 +1991,8 @@ struct ChannelSubscriptionLayout { @@ -1987,7 +1991,8 @@ struct ChannelSubscriptionLayout {
1987 dialogController: CustomDialogController | null = new CustomDialogController({ 1991 dialogController: CustomDialogController | null = new CustomDialogController({
1988 builder: ChannelDialog({ 1992 builder: ChannelDialog({
1989 currentTopNavSelectedIndex: $currentTopNavSelectedIndex, 1993 currentTopNavSelectedIndex: $currentTopNavSelectedIndex,
1990 - indexSettingArray: $indexSettingArray, 1994 + indexSettingChannelId: $indexSettingChannelId,
  1995 + homeChannelList: $homeChannelList,
1991 myChannelList: $myChannelList, 1996 myChannelList: $myChannelList,
1992 moreChannelList: $moreChannelList, 1997 moreChannelList: $moreChannelList,
1993 localChannelList: $localChannelList, 1998 localChannelList: $localChannelList,
@@ -2049,13 +2054,8 @@ struct ChannelSubscriptionLayout { @@ -2049,13 +2054,8 @@ struct ChannelSubscriptionLayout {
2049 // }) 2054 // })
2050 // } 2055 // }
2051 2056
2052 - onChannelIdsUpdate(){  
2053 - AppStorage.SetOrCreate('channelIds', this.channelIds.join(','));  
2054 - console.log(`AppStorage.get('channelIds')${AppStorage.get('channelIds')}`)  
2055 - }  
2056 2057
2057 aboutToAppear() { 2058 aboutToAppear() {
2058 - console.log(`myChannelListzz${this.channelIds}}`)  
2059 // this.topNavListHandle() 2059 // this.topNavListHandle()
2060 } 2060 }
2061 2061
@@ -7,22 +7,26 @@ import { ChannelSubscriptionLayout } from './ChannelSubscriptionLayout' @@ -7,22 +7,26 @@ import { ChannelSubscriptionLayout } from './ChannelSubscriptionLayout'
7 const TAG = 'TopNavigationComponent'; 7 const TAG = 'TopNavigationComponent';
8 8
9 PersistentStorage.persistProp('channelIds', ''); 9 PersistentStorage.persistProp('channelIds', '');
  10 +PersistentStorage.persistProp('indexSettingChannelId', 0);
  11 +
10 /** 12 /**
11 * 顶部页签导航栏/顶导 13 * 顶部页签导航栏/顶导
12 */ 14 */
13 @Component 15 @Component
14 export struct TopNavigationComponent { 16 export struct TopNavigationComponent {
15 private tabsController: TabsController = new TabsController() 17 private tabsController: TabsController = new TabsController()
16 - @Prop _currentNavIndex?: number; 18 + @Prop _currentNavIndex: number;
17 // 顶导当前选中/焦点下标 19 // 顶导当前选中/焦点下标
18 @State currentTopNavSelectedIndex: number = 0; 20 @State currentTopNavSelectedIndex: number = 0;
19 // 顶导数据 21 // 顶导数据
20 @State @Watch('onTopNavigationDataUpdated') topNavList: TopNavDTO[] = [] 22 @State @Watch('onTopNavigationDataUpdated') topNavList: TopNavDTO[] = []
21 @State compList: LazyDataSource<CompDTO> = new LazyDataSource(); 23 @State compList: LazyDataSource<CompDTO> = new LazyDataSource();
  24 + @StorageProp('indexSettingChannelId') indexSettingChannelId: number = 0
22 //我的频道id列表 25 //我的频道id列表
23 - @State @Watch('onChannelIdsUpdate') channelIds: number[] = [] 26 + @State channelIds: number[] = []
24 //本地缓存频道id列表 27 //本地缓存频道id列表
25 @StorageProp('channelIds') storageChannelIds: string = '' 28 @StorageProp('channelIds') storageChannelIds: string = ''
  29 + @State homeChannelList: TopNavDTO[] = []
26 // 我的频道列表 30 // 我的频道列表
27 @State myChannelList: TopNavDTO[] = [] 31 @State myChannelList: TopNavDTO[] = []
28 // 更多频道列表 32 // 更多频道列表
@@ -31,33 +35,48 @@ export struct TopNavigationComponent { @@ -31,33 +35,48 @@ export struct TopNavigationComponent {
31 @State localChannelList: TopNavDTO[] = [] 35 @State localChannelList: TopNavDTO[] = []
32 readonly MAX_LINE: number = 1; 36 readonly MAX_LINE: number = 1;
33 37
34 - //处理接口顶导数据 38 + //处理新闻tab顶导频道数据
35 topNavListHandle() { 39 topNavListHandle() {
36 let _channelIds: number [] = [] 40 let _channelIds: number [] = []
37 - let _myChannelList : TopNavDTO [] = [] 41 + let _myChannelList: TopNavDTO [] = []
  42 + let _storageChannelIds: string [] = [] //list1
38 let defaultMyChannelList: TopNavDTO[] = [] 43 let defaultMyChannelList: TopNavDTO[] = []
39 - let handledTopNavList = [...this.topNavList]  
40 - handledTopNavList.sort((a, b) => { 44 + let defaultList = [...this.topNavList]
  45 + defaultList.sort((a, b) => {
41 return a.num - b.num; 46 return a.num - b.num;
42 }); 47 });
43 - handledTopNavList.forEach(item => { 48 +
  49 + //defaultMyChannelList
  50 + defaultList.forEach(item => {
44 if (item.defaultPermitted === 1 || item.movePermitted === 0 || item.delPermitted === 0 || item.headlinesOn === 1) { 51 if (item.defaultPermitted === 1 || item.movePermitted === 0 || item.delPermitted === 0 || item.headlinesOn === 1) {
45 defaultMyChannelList.push(item); 52 defaultMyChannelList.push(item);
46 } 53 }
  54 + if (item.defaultPermitted === 1) {
  55 + this.homeChannelList.push(item)
  56 + }
47 }) 57 })
48 58
  59 + //有缓存频道id
  60 + if (this.storageChannelIds) {
  61 + _storageChannelIds = this.storageChannelIds.split(',')
  62 + }
  63 +
49 defaultMyChannelList.forEach(item => { 64 defaultMyChannelList.forEach(item => {
50 item.myChannel = '1' 65 item.myChannel = '1'
51 if (item.defaultPermitted === 1) { 66 if (item.defaultPermitted === 1) {
52 item.homeChannel = '1' 67 item.homeChannel = '1'
53 } 68 }
54 - let index = handledTopNavList.findIndex(_item => _item.channelId === item.channelId) 69 + let index = defaultList.findIndex(_item => _item.channelId === item.channelId)
55 if (index !== -1) { 70 if (index !== -1) {
56 - handledTopNavList.splice(index, 1) 71 + defaultList.splice(index, 1)
57 } 72 }
58 }) 73 })
59 - handledTopNavList.unshift(...defaultMyChannelList)  
60 - handledTopNavList.forEach((item, index) => { 74 + defaultList.unshift(...defaultMyChannelList)
  75 +
  76 + defaultList.forEach((item, index) => {
  77 + if (this.storageChannelIds && _storageChannelIds.includes(String(item.channelId))) {
  78 + item.myChannel = '1'
  79 + }
61 if (item.channelType === 2) { 80 if (item.channelType === 2) {
62 item.localChannel = '1' 81 item.localChannel = '1'
63 } 82 }
@@ -75,17 +94,24 @@ export struct TopNavigationComponent { @@ -75,17 +94,24 @@ export struct TopNavigationComponent {
75 if (item.myChannel === '1') { 94 if (item.myChannel === '1') {
76 _myChannelList.push(item) 95 _myChannelList.push(item)
77 _channelIds.push(item.channelId) 96 _channelIds.push(item.channelId)
78 - }  
79 - if (item.moreChannel === '1') { 97 + } else if (item.moreChannel === '1') {
80 this.moreChannelList.push(item) 98 this.moreChannelList.push(item)
81 - }  
82 - if (item.localChannel === '1') { 99 + } else if (item.localChannel === '1') {
83 this.localChannelList.push(item) 100 this.localChannelList.push(item)
84 } 101 }
85 102
86 }) 103 })
  104 +
87 this.channelIds = _channelIds 105 this.channelIds = _channelIds
88 this.myChannelList = _myChannelList 106 this.myChannelList = _myChannelList
  107 +
  108 + //缓存首页频道
  109 + if (!this.indexSettingChannelId) {
  110 + AppStorage.set('indexSettingChannelId', this.homeChannelList[0].channelId)
  111 + } else {
  112 + let index = this.myChannelList.findIndex(_item => _item.channelId === this.indexSettingChannelId)
  113 + this.currentTopNavSelectedIndex = index
  114 + }
89 } 115 }
90 116
91 isBroadcast(item: TopNavDTO) { 117 isBroadcast(item: TopNavDTO) {
@@ -126,7 +152,7 @@ export struct TopNavigationComponent { @@ -126,7 +152,7 @@ export struct TopNavigationComponent {
126 Image($r('app.media.icon_ren_min_ri_bao')) 152 Image($r('app.media.icon_ren_min_ri_bao'))
127 .width(72) 153 .width(72)
128 .height(29) 154 .height(29)
129 - .onClick((event: ClickEvent) => { 155 + .onClick(() => {
130 let taskAction: Action = { 156 let taskAction: Action = {
131 type: 'JUMP_INNER_NEW_PAGE', 157 type: 'JUMP_INNER_NEW_PAGE',
132 params: { 158 params: {
@@ -165,7 +191,7 @@ export struct TopNavigationComponent { @@ -165,7 +191,7 @@ export struct TopNavigationComponent {
165 right: { anchor: "__container__", align: HorizontalAlign.End }, 191 right: { anchor: "__container__", align: HorizontalAlign.End },
166 center: { anchor: "__container__", align: VerticalAlign.Center } 192 center: { anchor: "__container__", align: VerticalAlign.Center }
167 }) 193 })
168 - .onClick((event: ClickEvent) => { 194 + .onClick(() => {
169 195
170 let taskAction: Action = { 196 let taskAction: Action = {
171 type: 'JUMP_INNER_NEW_PAGE', 197 type: 'JUMP_INNER_NEW_PAGE',
@@ -182,8 +208,7 @@ export struct TopNavigationComponent { @@ -182,8 +208,7 @@ export struct TopNavigationComponent {
182 208
183 // 频道分类list 209 // 频道分类list
184 Stack({ alignContent: Alignment.TopEnd }) { 210 Stack({ alignContent: Alignment.TopEnd }) {
185 -  
186 - Tabs({ controller: this.tabsController }) { 211 + Tabs({ index: this.currentTopNavSelectedIndex, controller: this.tabsController }) {
187 ForEach(this._currentNavIndex === 0 ? this.myChannelList : this.topNavList, (navItem: TopNavDTO, index: number) => { 212 ForEach(this._currentNavIndex === 0 ? this.myChannelList : this.topNavList, (navItem: TopNavDTO, index: number) => {
188 TabContent() { 213 TabContent() {
189 if (!this.isBroadcast(navItem)) { 214 if (!this.isBroadcast(navItem)) {
@@ -220,9 +245,11 @@ export struct TopNavigationComponent { @@ -220,9 +245,11 @@ export struct TopNavigationComponent {
220 }) 245 })
221 246
222 // 分类列表最右侧频道设置 247 // 分类列表最右侧频道设置
223 - if(this._currentNavIndex === 0){ 248 + if (this._currentNavIndex === 0) {
224 ChannelSubscriptionLayout({ 249 ChannelSubscriptionLayout({
225 currentTopNavSelectedIndex: $currentTopNavSelectedIndex, 250 currentTopNavSelectedIndex: $currentTopNavSelectedIndex,
  251 + indexSettingChannelId: this.indexSettingChannelId,
  252 + homeChannelList: this.homeChannelList,
226 myChannelList: $myChannelList, 253 myChannelList: $myChannelList,
227 moreChannelList: $moreChannelList, 254 moreChannelList: $moreChannelList,
228 localChannelList: $localChannelList, 255 localChannelList: $localChannelList,
@@ -270,15 +297,14 @@ export struct TopNavigationComponent { @@ -270,15 +297,14 @@ export struct TopNavigationComponent {
270 } 297 }
271 298
272 aboutToAppear() { 299 aboutToAppear() {
273 - if(this._currentNavIndex === 0){ 300 + //处理新闻tab顶导频道数据
  301 + if (this._currentNavIndex === 0) {
274 this.topNavListHandle() 302 this.topNavListHandle()
275 } 303 }
276 } 304 }
277 305
278 - onChannelIdsUpdate() { 306 + aboutToDisappear() {
279 AppStorage.set('channelIds', this.channelIds.join(',')) 307 AppStorage.set('channelIds', this.channelIds.join(','))
280 - console.log(`PersistentStorage channelIds: ${this.channelIds}`)  
281 - console.log(`PersistentStorage aboutToAppear: ${this.storageChannelIds}`)  
282 } 308 }
283 309
284 onTopNavigationDataUpdated() { 310 onTopNavigationDataUpdated() {