Showing
2 changed files
with
29 additions
and
32 deletions
| @@ -23,7 +23,7 @@ struct ChannelSubscriptionLayout { | @@ -23,7 +23,7 @@ struct ChannelSubscriptionLayout { | ||
| 23 | @Link myChannelList: TopNavDTO [] | 23 | @Link myChannelList: TopNavDTO [] |
| 24 | @Link moreChannelList: TopNavDTO [] | 24 | @Link moreChannelList: TopNavDTO [] |
| 25 | @Link localChannelList: TopNavDTO [] | 25 | @Link localChannelList: TopNavDTO [] |
| 26 | - @Link channelIds: number [] | 26 | + @State channelIds: number [] = [] |
| 27 | @State isShow: boolean = false | 27 | @State isShow: boolean = false |
| 28 | @State dragItem: number = -1 | 28 | @State dragItem: number = -1 |
| 29 | private dragRefOffsetX: number = 0 | 29 | private dragRefOffsetX: number = 0 |
| @@ -40,6 +40,9 @@ struct ChannelSubscriptionLayout { | @@ -40,6 +40,9 @@ struct ChannelSubscriptionLayout { | ||
| 40 | 40 | ||
| 41 | aboutToAppear() { | 41 | aboutToAppear() { |
| 42 | this.currentTopNavSelectedItem = this.myChannelList[this.currentTopNavSelectedIndex] | 42 | this.currentTopNavSelectedItem = this.myChannelList[this.currentTopNavSelectedIndex] |
| 43 | + this.myChannelList.forEach(item=>{ | ||
| 44 | + this.channelIds.push(item.channelId) | ||
| 45 | + }) | ||
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | //交换我的频道数组中的位置 | 48 | //交换我的频道数组中的位置 |
| @@ -54,7 +57,8 @@ struct ChannelSubscriptionLayout { | @@ -54,7 +57,8 @@ struct ChannelSubscriptionLayout { | ||
| 54 | delChannelItem(index: number){ | 57 | delChannelItem(index: number){ |
| 55 | let item = this.myChannelList.splice(index, 1)[0] | 58 | let item = this.myChannelList.splice(index, 1)[0] |
| 56 | this.channelIds.splice(index, 1) | 59 | this.channelIds.splice(index, 1) |
| 57 | - AppStorage.setOrCreate('channelIds', this.channelIds.join(',')) | 60 | + AppStorage.setOrCreate('channelIds', JSON.stringify(this.channelIds)) |
| 61 | + console.log('delChannelItem',JSON.stringify(item),AppStorage.get('channelIds')) | ||
| 58 | if (item.moreChannel === '1') { | 62 | if (item.moreChannel === '1') { |
| 59 | this.moreChannelList.unshift(item) | 63 | this.moreChannelList.unshift(item) |
| 60 | } | 64 | } |
| @@ -46,8 +46,6 @@ export struct TopNavigationComponentNew { | @@ -46,8 +46,6 @@ export struct TopNavigationComponentNew { | ||
| 46 | // 顶导数据 | 46 | // 顶导数据 |
| 47 | @State @Watch('onTopNavigationDataUpdated') topNavList: TopNavDTO[] = [] | 47 | @State @Watch('onTopNavigationDataUpdated') topNavList: TopNavDTO[] = [] |
| 48 | @State indexSettingChannelId: number = AppStorage.get<number>('indexSettingChannelId') || 2002 | 48 | @State indexSettingChannelId: number = AppStorage.get<number>('indexSettingChannelId') || 2002 |
| 49 | - //我的频道id列表 | ||
| 50 | - @State channelIds: number[] = [] | ||
| 51 | //本地缓存频道id列表 | 49 | //本地缓存频道id列表 |
| 52 | @State storageChannelIds: string = AppStorage.get<string>('channelIds') || '' | 50 | @State storageChannelIds: string = AppStorage.get<string>('channelIds') || '' |
| 53 | @State homeChannelList: TopNavDTO[] = [] | 51 | @State homeChannelList: TopNavDTO[] = [] |
| @@ -192,7 +190,7 @@ export struct TopNavigationComponentNew { | @@ -192,7 +190,7 @@ export struct TopNavigationComponentNew { | ||
| 192 | myChannelList: $myChannelList, | 190 | myChannelList: $myChannelList, |
| 193 | moreChannelList: $moreChannelList, | 191 | moreChannelList: $moreChannelList, |
| 194 | localChannelList: $localChannelList, | 192 | localChannelList: $localChannelList, |
| 195 | - channelIds: $channelIds, | 193 | + // channelIds: $channelIds, |
| 196 | changeTab: (index) => { | 194 | changeTab: (index) => { |
| 197 | this.changePage(index) | 195 | this.changePage(index) |
| 198 | } | 196 | } |
| @@ -260,7 +258,7 @@ export struct TopNavigationComponentNew { | @@ -260,7 +258,7 @@ export struct TopNavigationComponentNew { | ||
| 260 | .edgeEffect(EdgeEffect.None) | 258 | .edgeEffect(EdgeEffect.None) |
| 261 | .height($r('app.float.top_tab_bar_height_common')) | 259 | .height($r('app.float.top_tab_bar_height_common')) |
| 262 | .backgroundColor(this.barBackgroundColor) | 260 | .backgroundColor(this.barBackgroundColor) |
| 263 | - .margin({top:10}) | 261 | + .margin({ top: 10 }) |
| 264 | .onAreaChange((oldValue: Area, newValue: Area) => { | 262 | .onAreaChange((oldValue: Area, newValue: Area) => { |
| 265 | let width = Number.parseFloat(newValue.width.toString()) | 263 | let width = Number.parseFloat(newValue.width.toString()) |
| 266 | this.tabsWidth = Number.isNaN(width) ? 0 : width | 264 | this.tabsWidth = Number.isNaN(width) ? 0 : width |
| @@ -342,8 +340,6 @@ export struct TopNavigationComponentNew { | @@ -342,8 +340,6 @@ export struct TopNavigationComponentNew { | ||
| 342 | //处理新闻tab顶导频道数据 | 340 | //处理新闻tab顶导频道数据 |
| 343 | topNavListHandle() { | 341 | topNavListHandle() { |
| 344 | let cityName = SPHelper.default.getSync(SpConstants.LOCATION_CITY_NAME, '') as string | 342 | let cityName = SPHelper.default.getSync(SpConstants.LOCATION_CITY_NAME, '') as string |
| 345 | - | ||
| 346 | - let _channelIds: number [] = [] | ||
| 347 | let _myChannelList: TopNavDTO [] = [] | 343 | let _myChannelList: TopNavDTO [] = [] |
| 348 | let _storageChannelIds: string [] = [] //list1 | 344 | let _storageChannelIds: string [] = [] //list1 |
| 349 | let defaultMyChannelList: TopNavDTO[] = [] | 345 | let defaultMyChannelList: TopNavDTO[] = [] |
| @@ -379,11 +375,7 @@ export struct TopNavigationComponentNew { | @@ -379,11 +375,7 @@ export struct TopNavigationComponentNew { | ||
| 379 | } | 375 | } |
| 380 | }) | 376 | }) |
| 381 | defaultList.unshift(...defaultMyChannelList) | 377 | defaultList.unshift(...defaultMyChannelList) |
| 382 | - | ||
| 383 | defaultList.forEach((item, index) => { | 378 | defaultList.forEach((item, index) => { |
| 384 | - if (this.storageChannelIds && _storageChannelIds.includes(String(item.channelId))) { | ||
| 385 | - item.myChannel = '1' | ||
| 386 | - } | ||
| 387 | if (item.channelType === 2) { | 379 | if (item.channelType === 2) { |
| 388 | if (cityName.includes(item.name)) { | 380 | if (cityName.includes(item.name)) { |
| 389 | item.myChannel = '1' | 381 | item.myChannel = '1' |
| @@ -399,32 +391,34 @@ export struct TopNavigationComponentNew { | @@ -399,32 +391,34 @@ export struct TopNavigationComponentNew { | ||
| 399 | item.moreChannel = '1' | 391 | item.moreChannel = '1' |
| 400 | } | 392 | } |
| 401 | } | 393 | } |
| 402 | - | 394 | + if (this.storageChannelIds && _storageChannelIds.includes(String(item.channelId))) { |
| 395 | + item.myChannel = '1' | ||
| 396 | + } | ||
| 403 | //频道分类 | 397 | //频道分类 |
| 404 | if (item.name !== '播报') { //暂时隐藏播报 | 398 | if (item.name !== '播报') { //暂时隐藏播报 |
| 405 | - if (item.myChannel === '1' && !this.storageChannelIds) { | 399 | + if (item.myChannel === '1') { |
| 406 | _myChannelList.push(item) | 400 | _myChannelList.push(item) |
| 407 | - _channelIds.push(item.channelId) | ||
| 408 | } | 401 | } |
| 409 | - if (item.moreChannel === '1') { | 402 | + if (item.moreChannel === '1' && item.myChannel !== '1') { |
| 410 | this.moreChannelList.push(item) | 403 | this.moreChannelList.push(item) |
| 411 | } | 404 | } |
| 412 | if (item.localChannel === '1' && item.myChannel !== '1') { | 405 | if (item.localChannel === '1' && item.myChannel !== '1') { |
| 413 | this.localChannelList.push(item) | 406 | this.localChannelList.push(item) |
| 414 | } | 407 | } |
| 415 | } | 408 | } |
| 416 | - | ||
| 417 | }) | 409 | }) |
| 418 | 410 | ||
| 419 | - if(this.storageChannelIds){ | ||
| 420 | - _storageChannelIds.forEach((_item:string)=>{ | ||
| 421 | - let index = defaultList.findIndex(ele => Number(_item) === ele.channelId) | ||
| 422 | - if(index > -1){ | ||
| 423 | - _myChannelList.push(defaultList[index]) | ||
| 424 | - _channelIds.push(defaultList[index].channelId) | ||
| 425 | - } | ||
| 426 | - }) | 411 | + //根据缓存数组排序 |
| 412 | + if (this.storageChannelIds) { | ||
| 413 | + let sortedyChannelList = _myChannelList.sort((item1, item2) => { | ||
| 414 | + let index1 = this.storageChannelIds.indexOf(String(item1.channelId)); | ||
| 415 | + let index2 = this.storageChannelIds.indexOf(String(item2.channelId)); | ||
| 416 | + return index1 - index2; | ||
| 417 | + }); | ||
| 418 | + _myChannelList = sortedyChannelList | ||
| 427 | } | 419 | } |
| 420 | + | ||
| 421 | + | ||
| 428 | if (cityName) { | 422 | if (cityName) { |
| 429 | let index = _myChannelList.findIndex(ele => cityName.includes(ele.name)) | 423 | let index = _myChannelList.findIndex(ele => cityName.includes(ele.name)) |
| 430 | const localChannelitem = _myChannelList.splice(index, 1)[0]; | 424 | const localChannelitem = _myChannelList.splice(index, 1)[0]; |
| @@ -432,7 +426,6 @@ export struct TopNavigationComponentNew { | @@ -432,7 +426,6 @@ export struct TopNavigationComponentNew { | ||
| 432 | _myChannelList.splice(3, 0, localChannelitem); | 426 | _myChannelList.splice(3, 0, localChannelitem); |
| 433 | } | 427 | } |
| 434 | 428 | ||
| 435 | - this.channelIds = _channelIds | ||
| 436 | this.myChannelList = _myChannelList | 429 | this.myChannelList = _myChannelList |
| 437 | 430 | ||
| 438 | //缓存首页频道 | 431 | //缓存首页频道 |
| @@ -620,22 +613,22 @@ export struct TopNavigationComponentNew { | @@ -620,22 +613,22 @@ export struct TopNavigationComponentNew { | ||
| 620 | }) | 613 | }) |
| 621 | } | 614 | } |
| 622 | 615 | ||
| 623 | - clickMorningEveningPaper(){ | 616 | + clickMorningEveningPaper() { |
| 624 | if (NetworkUtil.isNetConnected()) { | 617 | if (NetworkUtil.isNetConnected()) { |
| 625 | - DailyPaperTopicModel.getDailyPaperTopic().then(dailyPaperTopicBean =>{ | 618 | + DailyPaperTopicModel.getDailyPaperTopic().then(dailyPaperTopicBean => { |
| 626 | if (dailyPaperTopicBean && dailyPaperTopicBean.id > 0) { | 619 | if (dailyPaperTopicBean && dailyPaperTopicBean.id > 0) { |
| 627 | SPHelper.default.saveSync('dailyPaperTopicPageId', dailyPaperTopicBean.id); | 620 | SPHelper.default.saveSync('dailyPaperTopicPageId', dailyPaperTopicBean.id); |
| 628 | ProcessUtils.gotoMorningEveningPaper() | 621 | ProcessUtils.gotoMorningEveningPaper() |
| 629 | - TrackingButton.click('morning_evening_news_click',TrackConstants.SummaryType.MorningAndEveningNews,TrackConstants.SummaryType.MorningAndEveningNews) | ||
| 630 | - }else { | 622 | + TrackingButton.click('morning_evening_news_click', TrackConstants.SummaryType.MorningAndEveningNews, |
| 623 | + TrackConstants.SummaryType.MorningAndEveningNews) | ||
| 624 | + } else { | ||
| 631 | ToastUtils.showToast('暂无早晚报信息', 1000) | 625 | ToastUtils.showToast('暂无早晚报信息', 1000) |
| 632 | } | 626 | } |
| 633 | - }).catch((err:string) =>{ | 627 | + }).catch((err: string) => { |
| 634 | ToastUtils.showToast('暂无早晚报信息', 1000) | 628 | ToastUtils.showToast('暂无早晚报信息', 1000) |
| 635 | }) | 629 | }) |
| 636 | } else { | 630 | } else { |
| 637 | ToastUtils.showToast('网络出小差了,请检查网络后重试', 1000) | 631 | ToastUtils.showToast('网络出小差了,请检查网络后重试', 1000) |
| 638 | } | 632 | } |
| 639 | } | 633 | } |
| 640 | - | ||
| 641 | } | 634 | } |
-
Please register or login to post a comment