Showing
1 changed file
with
63 additions
and
7 deletions
| 1 | import { TopNavDTO } from 'wdBean'; | 1 | import { TopNavDTO } from 'wdBean'; |
| 2 | 2 | ||
| 3 | - | ||
| 4 | const INDEX_SETTING_TITLE: string = '首页设置' | 3 | const INDEX_SETTING_TITLE: string = '首页设置' |
| 5 | const INDEX_SETTING_SUBTITLE: string = '将指定频道设置为首页' | 4 | const INDEX_SETTING_SUBTITLE: string = '将指定频道设置为首页' |
| 6 | const MY_CHANNEL: string = '我的频道' | 5 | const MY_CHANNEL: string = '我的频道' |
| @@ -19,7 +18,9 @@ struct ChannelDialog { | @@ -19,7 +18,9 @@ struct ChannelDialog { | ||
| 19 | @Link localChannelList: TopNavDTO[] | 18 | @Link localChannelList: TopNavDTO[] |
| 20 | @Link indexSettingArray: string[] | 19 | @Link indexSettingArray: string[] |
| 21 | controller?: CustomDialogController | 20 | controller?: CustomDialogController |
| 22 | - confirm: (index: number) => void = () => {} | 21 | + confirm: (index: number) => void = () => { |
| 22 | + } | ||
| 23 | + changeChannelIndex : (index1:number, index2:number) => void = ()=>{} | ||
| 23 | myChannelItemEditHandle = (index: number): void => { | 24 | myChannelItemEditHandle = (index: number): void => { |
| 24 | let item = this.myChannelList.splice(index, 1)[0] | 25 | let item = this.myChannelList.splice(index, 1)[0] |
| 25 | if (item.moreChannel === '1') { | 26 | if (item.moreChannel === '1') { |
| @@ -30,6 +31,34 @@ struct ChannelDialog { | @@ -30,6 +31,34 @@ struct ChannelDialog { | ||
| 30 | } | 31 | } |
| 31 | } | 32 | } |
| 32 | 33 | ||
| 34 | + @Builder | ||
| 35 | + pixelMapBuilder(item: TopNavDTO, index: number) { //拖拽过程样式 | ||
| 36 | + Row() { | ||
| 37 | + Row() { | ||
| 38 | + Text(item.name) | ||
| 39 | + .fontSize(14) | ||
| 40 | + .fontColor(this.currentTopNavSelectedIndex === index ? '#ED2800' : (item.homeChannel === '1' || item.movePermitted === 0 ? '#999999' : '#222222')) | ||
| 41 | + | ||
| 42 | + if (this.isEditIng && item.myChannel !== '1') { | ||
| 43 | + Image($r('app.media.icon_audio_close')) | ||
| 44 | + .width(12) | ||
| 45 | + .margin({ left: 1 }) | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + .width('100%') | ||
| 49 | + .height('100%') | ||
| 50 | + .justifyContent(FlexAlign.Center) | ||
| 51 | + .backgroundColor(item.homeChannel === '1' || item.movePermitted === 0 ? '#F5F5F5' : '#ffffff') | ||
| 52 | + } | ||
| 53 | + .width('23%') | ||
| 54 | + .height(40) | ||
| 55 | + .border({ | ||
| 56 | + width: item.homeChannel === '1' ? 0 : 1, | ||
| 57 | + color: '#EDEDED', | ||
| 58 | + radius: 3 | ||
| 59 | + }) | ||
| 60 | + } | ||
| 61 | + | ||
| 33 | build() { | 62 | build() { |
| 34 | Column() { | 63 | Column() { |
| 35 | 64 | ||
| @@ -157,8 +186,25 @@ struct ChannelDialog { | @@ -157,8 +186,25 @@ struct ChannelDialog { | ||
| 157 | } | 186 | } |
| 158 | .width('100%') | 187 | .width('100%') |
| 159 | .margin({ bottom: 24 }) | 188 | .margin({ bottom: 24 }) |
| 189 | + .columnsTemplate('1fr 1fr 1fr 1fr') | ||
| 160 | .columnsGap(8) | 190 | .columnsGap(8) |
| 161 | .rowsGap(8) | 191 | .rowsGap(8) |
| 192 | + .height(Math.ceil(this.myChannelList.length / 4 ) * 48) | ||
| 193 | + .editMode(this.isEditIng) | ||
| 194 | + .supportAnimation(true) //设置Grid是否开启拖拽补位动画 | ||
| 195 | + .onItemDragStart((event: ItemDragInfo, itemIndex: number) => { | ||
| 196 | + if(this.myChannelList[itemIndex].headlinesOn===1 || this.myChannelList[itemIndex].movePermitted===0){ | ||
| 197 | + return | ||
| 198 | + }else{ | ||
| 199 | + return this.pixelMapBuilder(this.myChannelList[itemIndex], itemIndex) //设置拖拽过程中显示的元素。 | ||
| 200 | + } | ||
| 201 | + }) | ||
| 202 | + .onItemDrop((event: ItemDragInfo, itemIndex: number, insertIndex: number, isSuccess: boolean) => { //绑定此事件的组件可作为拖拽释放目标,当在本组件范围内停止拖拽行为时,触发回调。 | ||
| 203 | + if (!isSuccess || insertIndex >= this.myChannelList.length || this.myChannelList[insertIndex].headlinesOn===1 || this.myChannelList[insertIndex].movePermitted===0) { | ||
| 204 | + return | ||
| 205 | + } | ||
| 206 | + this.changeChannelIndex(itemIndex,insertIndex) | ||
| 207 | + }) | ||
| 162 | } | 208 | } |
| 163 | 209 | ||
| 164 | //更多频道列表 | 210 | //更多频道列表 |
| @@ -259,19 +305,18 @@ struct ChannelDialog { | @@ -259,19 +305,18 @@ struct ChannelDialog { | ||
| 259 | // @Entry | 305 | // @Entry |
| 260 | @Component | 306 | @Component |
| 261 | struct ChannelSubscriptionLayout { | 307 | struct ChannelSubscriptionLayout { |
| 262 | - changeTab: (index: number) => void = ()=>{} | 308 | + changeTab: (index: number) => void = () => { |
| 309 | + } | ||
| 263 | @State indexSettingArray: string [] = ['推荐', '热点'] | 310 | @State indexSettingArray: string [] = ['推荐', '热点'] |
| 264 | //当前选中的频道 | 311 | //当前选中的频道 |
| 265 | @Link currentTopNavSelectedIndex: number; | 312 | @Link currentTopNavSelectedIndex: number; |
| 266 | @Link myChannelList: TopNavDTO [] | 313 | @Link myChannelList: TopNavDTO [] |
| 267 | @Link moreChannelList: TopNavDTO [] | 314 | @Link moreChannelList: TopNavDTO [] |
| 268 | @Link localChannelList: TopNavDTO [] | 315 | @Link localChannelList: TopNavDTO [] |
| 269 | - | ||
| 270 | - onAccept = (index: number)=> { | 316 | + onAccept = (index: number) => { |
| 271 | console.log(`onAccept${index}`) | 317 | console.log(`onAccept${index}`) |
| 272 | this.changeTab(index) | 318 | this.changeTab(index) |
| 273 | } | 319 | } |
| 274 | - | ||
| 275 | // @State currentTopNavSelectedIndex: number = 0 | 320 | // @State currentTopNavSelectedIndex: number = 0 |
| 276 | // @State topNavList: TopNavDTO [] = [ | 321 | // @State topNavList: TopNavDTO [] = [ |
| 277 | // { | 322 | // { |
| @@ -1785,12 +1830,23 @@ struct ChannelSubscriptionLayout { | @@ -1785,12 +1830,23 @@ struct ChannelSubscriptionLayout { | ||
| 1785 | myChannelList: $myChannelList, | 1830 | myChannelList: $myChannelList, |
| 1786 | moreChannelList: $moreChannelList, | 1831 | moreChannelList: $moreChannelList, |
| 1787 | localChannelList: $localChannelList, | 1832 | localChannelList: $localChannelList, |
| 1788 | - confirm: this.onAccept | 1833 | + confirm: this.onAccept, |
| 1834 | + changeChannelIndex: this.changeChannelIndex | ||
| 1789 | }), | 1835 | }), |
| 1790 | alignment: DialogAlignment.TopEnd, | 1836 | alignment: DialogAlignment.TopEnd, |
| 1791 | customStyle: true, | 1837 | customStyle: true, |
| 1792 | }) | 1838 | }) |
| 1793 | 1839 | ||
| 1840 | + changeChannelIndex(index1:number, index2:number) { //交换数组中的位置 | ||
| 1841 | + const temp = this.myChannelList[index1]; | ||
| 1842 | + if (index1 > index2) { | ||
| 1843 | + this.myChannelList.splice(index2, 0, temp); | ||
| 1844 | + this.myChannelList.splice(index1 + 1, 1); | ||
| 1845 | + } else { | ||
| 1846 | + this.myChannelList.splice(index2 + 1, 0, temp); | ||
| 1847 | + this.myChannelList.splice(index1, 1); | ||
| 1848 | + } | ||
| 1849 | + } | ||
| 1794 | // topNavListHandle() { | 1850 | // topNavListHandle() { |
| 1795 | // let defaultMyChannelList: TopNavDTO[] = [] | 1851 | // let defaultMyChannelList: TopNavDTO[] = [] |
| 1796 | // let handledTopNavList = [...this.topNavList] | 1852 | // let handledTopNavList = [...this.topNavList] |
-
Please register or login to post a comment