Showing
1 changed file
with
49 additions
and
90 deletions
| @@ -13,8 +13,20 @@ const LOCAL_CHANNEL: string = '地方频道' | @@ -13,8 +13,20 @@ const LOCAL_CHANNEL: string = '地方频道' | ||
| 13 | 13 | ||
| 14 | const TAG: string = 'ChannelSubscriptionLayout' | 14 | const TAG: string = 'ChannelSubscriptionLayout' |
| 15 | 15 | ||
| 16 | -@CustomDialog | ||
| 17 | -struct ChannelDialog { | 16 | +// @Entry |
| 17 | +@Component | ||
| 18 | +struct ChannelSubscriptionLayout { | ||
| 19 | + @State indexSettingArray: string [] = ['推荐', '热点'] | ||
| 20 | + //当前选中的频道 | ||
| 21 | + @Link currentTopNavSelectedIndex: number; | ||
| 22 | + @Prop homeChannelList: TopNavDTO [] | ||
| 23 | + @Prop indexSettingChannelId: number | ||
| 24 | + @Link myChannelList: TopNavDTO [] | ||
| 25 | + @Link moreChannelList: TopNavDTO [] | ||
| 26 | + @Link localChannelList: TopNavDTO [] | ||
| 27 | + @Link channelIds: number [] | ||
| 28 | + @StorageLink('channelIds') storeChannelIds: string = '' | ||
| 29 | + @State isShow: boolean = false | ||
| 18 | @State dragItem: number = -1 | 30 | @State dragItem: number = -1 |
| 19 | private dragRefOffsetX: number = 0 | 31 | private dragRefOffsetX: number = 0 |
| 20 | private dragRefOffsetY: number = 0 | 32 | private dragRefOffsetY: number = 0 |
| @@ -25,26 +37,40 @@ struct ChannelDialog { | @@ -25,26 +37,40 @@ struct ChannelDialog { | ||
| 25 | @State indexSettingTabIndex: number = 0 | 37 | @State indexSettingTabIndex: number = 0 |
| 26 | @State isEditIng: boolean = false | 38 | @State isEditIng: boolean = false |
| 27 | @State currentTopNavSelectedItem: TopNavDTO = {} as TopNavDTO | 39 | @State currentTopNavSelectedItem: TopNavDTO = {} as TopNavDTO |
| 28 | - @Link currentTopNavSelectedIndex: number | ||
| 29 | - @Link myChannelList: TopNavDTO[] | ||
| 30 | - @Link moreChannelList: TopNavDTO[] | ||
| 31 | - @Link localChannelList: TopNavDTO[] | ||
| 32 | - @Link homeChannelList: TopNavDTO[] | ||
| 33 | - @Link indexSettingChannelId: number | ||
| 34 | - controller?: CustomDialogController | ||
| 35 | - confirm: (index: number) => void = () => { | ||
| 36 | - } | ||
| 37 | - changeChannelIndex: (index1: number, index2: number) => void = () => { | ||
| 38 | - } | ||
| 39 | - delChannelItem: (index: number) => void = () => { | ||
| 40 | - } | ||
| 41 | - addChannelItem: (item: TopNavDTO) => void = () => { | 40 | + changeTab: (index: number) => void = () => { |
| 42 | } | 41 | } |
| 43 | 42 | ||
| 44 | aboutToAppear() { | 43 | aboutToAppear() { |
| 45 | this.currentTopNavSelectedItem = this.myChannelList[this.currentTopNavSelectedIndex] | 44 | this.currentTopNavSelectedItem = this.myChannelList[this.currentTopNavSelectedIndex] |
| 46 | } | 45 | } |
| 47 | 46 | ||
| 47 | + //交换我的频道数组中的位置 | ||
| 48 | + changeChannelIndex(index1: number, index2: number) { | ||
| 49 | + let tmp = this.myChannelList.splice(index1, 1) | ||
| 50 | + let channelIdTmp = this.channelIds.splice(index1, 1) | ||
| 51 | + this.myChannelList.splice(index2, 0, tmp[0]) | ||
| 52 | + this.channelIds.splice(index2, 0, channelIdTmp[0]) | ||
| 53 | + this.storeChannelIds = this.channelIds.join(',') | ||
| 54 | + } | ||
| 55 | + //删除频道 | ||
| 56 | + delChannelItem(index: number){ | ||
| 57 | + let item = this.myChannelList.splice(index, 1)[0] | ||
| 58 | + this.channelIds.splice(index, 1) | ||
| 59 | + this.storeChannelIds = this.channelIds.join(',') | ||
| 60 | + if (item.moreChannel === '1') { | ||
| 61 | + this.moreChannelList.unshift(item) | ||
| 62 | + } | ||
| 63 | + if (item.localChannel === '1') { | ||
| 64 | + this.localChannelList.unshift(item) | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + // 添加频道 | ||
| 68 | + addChannelItem(item: TopNavDTO){ | ||
| 69 | + this.channelIds.push(item.channelId) | ||
| 70 | + this.myChannelList.push(item) | ||
| 71 | + this.storeChannelIds = this.channelIds.join(',') | ||
| 72 | + } | ||
| 73 | + | ||
| 48 | itemMove(index: number, newIndex: number): void { | 74 | itemMove(index: number, newIndex: number): void { |
| 49 | let targetItem = this.myChannelList[newIndex] | 75 | let targetItem = this.myChannelList[newIndex] |
| 50 | if (!(targetItem?.headlinesOn === 1 || targetItem?.movePermitted === 0 || targetItem?.homeChannel === '1')) { | 76 | if (!(targetItem?.headlinesOn === 1 || targetItem?.movePermitted === 0 || targetItem?.homeChannel === '1')) { |
| @@ -176,7 +202,8 @@ struct ChannelDialog { | @@ -176,7 +202,8 @@ struct ChannelDialog { | ||
| 176 | } | 202 | } |
| 177 | } | 203 | } |
| 178 | 204 | ||
| 179 | - build() { | 205 | + @Builder |
| 206 | + sheetBuilder() { | ||
| 180 | Column() { | 207 | Column() { |
| 181 | Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { | 208 | Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { |
| 182 | Image($r('app.media.icon_ren_min_ri_bao')) | 209 | Image($r('app.media.icon_ren_min_ri_bao')) |
| @@ -185,7 +212,7 @@ struct ChannelDialog { | @@ -185,7 +212,7 @@ struct ChannelDialog { | ||
| 185 | Image($r('app.media.close_button')) | 212 | Image($r('app.media.close_button')) |
| 186 | .width(24) | 213 | .width(24) |
| 187 | .onClick(() => { | 214 | .onClick(() => { |
| 188 | - this.controller?.close() | 215 | + this.isShow = false |
| 189 | }) | 216 | }) |
| 190 | } | 217 | } |
| 191 | .width('100%') | 218 | .width('100%') |
| @@ -310,8 +337,8 @@ struct ChannelDialog { | @@ -310,8 +337,8 @@ struct ChannelDialog { | ||
| 310 | this.delChannelItem(index) | 337 | this.delChannelItem(index) |
| 311 | } | 338 | } |
| 312 | } else { | 339 | } else { |
| 313 | - this.confirm(index) | ||
| 314 | - this.controller?.close() | 340 | + this.changeTab(index) |
| 341 | + this.isShow = false | ||
| 315 | } | 342 | } |
| 316 | }), | 343 | }), |
| 317 | LongPressGesture({ repeat: true }) | 344 | LongPressGesture({ repeat: true }) |
| @@ -464,73 +491,6 @@ struct ChannelDialog { | @@ -464,73 +491,6 @@ struct ChannelDialog { | ||
| 464 | }) | 491 | }) |
| 465 | .backgroundColor('#ffffff') | 492 | .backgroundColor('#ffffff') |
| 466 | } | 493 | } |
| 467 | -} | ||
| 468 | - | ||
| 469 | -// @Entry | ||
| 470 | -@Component | ||
| 471 | -struct ChannelSubscriptionLayout { | ||
| 472 | - @State indexSettingArray: string [] = ['推荐', '热点'] | ||
| 473 | - //当前选中的频道 | ||
| 474 | - @Link currentTopNavSelectedIndex: number; | ||
| 475 | - @Prop homeChannelList: TopNavDTO [] | ||
| 476 | - @Prop indexSettingChannelId: number | ||
| 477 | - @Link myChannelList: TopNavDTO [] | ||
| 478 | - @Link moreChannelList: TopNavDTO [] | ||
| 479 | - @Link localChannelList: TopNavDTO [] | ||
| 480 | - @Link channelIds: number [] | ||
| 481 | - @StorageLink('channelIds') storeChannelIds: string = '' | ||
| 482 | - changeTab: (index: number) => void = () => { | ||
| 483 | - } | ||
| 484 | - //频道弹窗点击切换频道 | ||
| 485 | - onAccept = (index: number) => { | ||
| 486 | - this.changeTab(index) | ||
| 487 | - } | ||
| 488 | - //交换我的频道数组中的位置 | ||
| 489 | - changeChannelIndex = (index1: number, index2: number) => { | ||
| 490 | - let tmp = this.myChannelList.splice(index1, 1) | ||
| 491 | - let channelIdTmp = this.channelIds.splice(index1, 1) | ||
| 492 | - this.myChannelList.splice(index2, 0, tmp[0]) | ||
| 493 | - this.channelIds.splice(index2, 0, channelIdTmp[0]) | ||
| 494 | - this.storeChannelIds = this.channelIds.join(',') | ||
| 495 | - } | ||
| 496 | - //删除频道 | ||
| 497 | - delChannelItem = (index: number) => { | ||
| 498 | - let item = this.myChannelList.splice(index, 1)[0] | ||
| 499 | - this.channelIds.splice(index, 1) | ||
| 500 | - this.storeChannelIds = this.channelIds.join(',') | ||
| 501 | - if (item.moreChannel === '1') { | ||
| 502 | - this.moreChannelList.unshift(item) | ||
| 503 | - } | ||
| 504 | - if (item.localChannel === '1') { | ||
| 505 | - this.localChannelList.unshift(item) | ||
| 506 | - } | ||
| 507 | - } | ||
| 508 | - // 添加频道 | ||
| 509 | - addChannelItem = (item: TopNavDTO) => { | ||
| 510 | - this.channelIds.push(item.channelId) | ||
| 511 | - this.myChannelList.push(item) | ||
| 512 | - this.storeChannelIds = this.channelIds.join(',') | ||
| 513 | - } | ||
| 514 | - dialogController: CustomDialogController | null = new CustomDialogController({ | ||
| 515 | - builder: ChannelDialog({ | ||
| 516 | - currentTopNavSelectedIndex: $currentTopNavSelectedIndex, | ||
| 517 | - indexSettingChannelId: $indexSettingChannelId, | ||
| 518 | - homeChannelList: $homeChannelList, | ||
| 519 | - myChannelList: $myChannelList, | ||
| 520 | - moreChannelList: $moreChannelList, | ||
| 521 | - localChannelList: $localChannelList, | ||
| 522 | - confirm: this.onAccept, | ||
| 523 | - changeChannelIndex: this.changeChannelIndex, | ||
| 524 | - delChannelItem: this.delChannelItem, | ||
| 525 | - addChannelItem: this.addChannelItem | ||
| 526 | - }), | ||
| 527 | - alignment: DialogAlignment.TopEnd, | ||
| 528 | - customStyle: true, | ||
| 529 | - }) | ||
| 530 | - | ||
| 531 | - aboutToDisappear() { | ||
| 532 | - this.dialogController = null // 将dialogController置空 | ||
| 533 | - } | ||
| 534 | 494 | ||
| 535 | build() { | 495 | build() { |
| 536 | Row() { | 496 | Row() { |
| @@ -542,10 +502,9 @@ struct ChannelSubscriptionLayout { | @@ -542,10 +502,9 @@ struct ChannelSubscriptionLayout { | ||
| 542 | .justifyContent(FlexAlign.Center) | 502 | .justifyContent(FlexAlign.Center) |
| 543 | .backgroundColor(Color.White) | 503 | .backgroundColor(Color.White) |
| 544 | .onClick(() => { | 504 | .onClick(() => { |
| 545 | - if (this.dialogController != null) { | ||
| 546 | - this.dialogController.open() | ||
| 547 | - } | 505 | + this.isShow = true |
| 548 | }) | 506 | }) |
| 507 | + .bindContentCover(this.isShow, this.sheetBuilder()) | ||
| 549 | } | 508 | } |
| 550 | } | 509 | } |
| 551 | 510 |
-
Please register or login to post a comment