Showing
3 changed files
with
140 additions
and
0 deletions
| 1 | 1 | ||
| 2 | export { PageViewModel } from "./viewmodel/PageViewModel" | 2 | export { PageViewModel } from "./viewmodel/PageViewModel" |
| 3 | 3 | ||
| 4 | +export { DemoPreviewerComponent} from "./components/DemoPreviewerComponent" | ||
| 5 | + | ||
| 4 | export { EmptyComponent } from "./components/EmptyComponent" | 6 | export { EmptyComponent } from "./components/EmptyComponent" |
| 5 | 7 | ||
| 6 | export { ErrorComponent } from "./components/ErrorComponent" | 8 | export { ErrorComponent } from "./components/ErrorComponent" |
| 1 | +import { CompDTO } from '../repository/bean/CompDTO'; | ||
| 2 | +import { ContentDTO } from '../repository/bean/ContentDTO'; | ||
| 3 | + | ||
| 4 | +const FULL_PARENT: string = '100%'; | ||
| 5 | +const COLUMNS_TEMPLATE_ONE: string = '1fr'; | ||
| 6 | +const COLUMNS_TEMPLATE_TWO: string = '1fr 1fr'; | ||
| 7 | +const COLUMNS_TEMPLATE_THREE: string = '1fr 1fr 1fr'; | ||
| 8 | +const COLUMNS_TEMPLATE_FOUR: string = '1fr 1fr 1fr 1fr'; | ||
| 9 | +const COLUMNS_TEMPLATE_SIX: string = '1fr 1fr 1fr 1fr 1fr 1fr'; | ||
| 10 | + | ||
| 11 | +const TAG = 'DemoPreviewerComponent'; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * xxxx 布局及功能说明 | ||
| 15 | + * | ||
| 16 | + * 【查看ArkUI预览效果】在线参考文档: | ||
| 17 | + * https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/previewer-0000001054328973-V3#section146052489820 | ||
| 18 | + */ | ||
| 19 | +@Entry | ||
| 20 | +@Component | ||
| 21 | +export struct DemoPreviewerComponent { | ||
| 22 | + @State compDTO: CompDTO = { | ||
| 23 | + compStyle: 'compStyle3', | ||
| 24 | + operDataList: [ | ||
| 25 | + { | ||
| 26 | + title: 'title0', | ||
| 27 | + description: "description0", | ||
| 28 | + coverUrl: 'https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231208/image/display/d4496925a1264a749975ae9b01a4ef46.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg' | ||
| 29 | + } as ContentDTO, | ||
| 30 | + { | ||
| 31 | + title: 'title1 title1 title1 title1 title1 title1 title1 title1 title1', | ||
| 32 | + description: "description1", | ||
| 33 | + "coverUrl": "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20240104/image/display/c4a9b526e0994d1bbd3ac8450f5cfc6c.jpg?x-oss-process=image/resize,w_550/quality,q_90/format,jpg", | ||
| 34 | + } as ContentDTO, | ||
| 35 | + { | ||
| 36 | + title: 'title2', | ||
| 37 | + description: "description2", | ||
| 38 | + "coverUrl": "https://cdnjdphoto.aikan.pdnews.cn/sjbj-20231206/image/live/bbe6d821e92b48919d90c7dadfd1f05a.jpg?x-oss-process=image/resize,l_850/auto-orient,1/quality,q_95/format,jpg", | ||
| 39 | + } as ContentDTO, | ||
| 40 | + { | ||
| 41 | + title: 'title3', | ||
| 42 | + description: "description3", | ||
| 43 | + coverUrl: 'https://cdnjdphoto.aikan.pdnews.cn/sjbj-20231109/image/live/102e6eb9356b4ef19405b04c1f6ff875.png?x-oss-process=image/resize,l_850/auto-orient,1/quality,q_95/format,jpg' | ||
| 44 | + } as ContentDTO, | ||
| 45 | + { | ||
| 46 | + title: 'title4', | ||
| 47 | + description: "description4", | ||
| 48 | + "coverUrl": "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231218/image/display/62bdbbb35dbd45689e00790c81f04c4b.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg", | ||
| 49 | + } as ContentDTO, | ||
| 50 | + { | ||
| 51 | + title: 'title5', | ||
| 52 | + description: "description5", | ||
| 53 | + "coverUrl": "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231218/image/display/f79bbaa5a33b4bd88176071c4f797ff6.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg", | ||
| 54 | + } as ContentDTO, | ||
| 55 | + { | ||
| 56 | + title: 'title6', | ||
| 57 | + description: "description6", | ||
| 58 | + "coverUrl": "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231218/image/display/2c1d917009584ce2bb4a35cbb3a860a0.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg", | ||
| 59 | + } as ContentDTO, | ||
| 60 | + { | ||
| 61 | + title: 'title7', | ||
| 62 | + description: "description7", | ||
| 63 | + "coverUrl": "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231222/image/display/117dc516ca5c42d5843c0d32050c9fc6.jpeg?x-oss-process=image/resize,w_240/quality,q_90/format,jpg", | ||
| 64 | + } as ContentDTO, | ||
| 65 | + { | ||
| 66 | + title: 'title8', | ||
| 67 | + description: "description8", | ||
| 68 | + "coverUrl": "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231228/image/display/90a2db4077d44a1f887f068fc659d977.jpeg?x-oss-process=image/resize,w_550/quality,q_90/format,jpg", | ||
| 69 | + } as ContentDTO | ||
| 70 | + ] | ||
| 71 | + } as CompDTO | ||
| 72 | + | ||
| 73 | + aboutToAppear() { | ||
| 74 | + // this.compDTO = { | ||
| 75 | + // compStyle: 'compStyle3', | ||
| 76 | + // operDataList: [ | ||
| 77 | + // { | ||
| 78 | + // title: 'title0', | ||
| 79 | + // description: "description0", | ||
| 80 | + // coverUrl: 'https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231208/image/display/d4496925a1264a749975ae9b01a4ef46.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg' | ||
| 81 | + // } as ContentDTO | ||
| 82 | + // ] | ||
| 83 | + // } as CompDTO | ||
| 84 | + | ||
| 85 | + this.compDTO.operDataList[0].title = 'title_first_0' | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + build() { | ||
| 89 | + Grid() { | ||
| 90 | + ForEach(this.compDTO.operDataList, (item: ContentDTO, index: number) => { | ||
| 91 | + GridItem() { | ||
| 92 | + this.gridItemView(item, index) | ||
| 93 | + } | ||
| 94 | + }, (item: ContentDTO, index: number) => JSON.stringify(item)) | ||
| 95 | + } | ||
| 96 | + .height(FULL_PARENT) | ||
| 97 | + .margin({ top: 10, bottom: 10, left: $r('app.float.main_margin'), right: $r('app.float.main_margin') }) | ||
| 98 | + .columnsTemplate(COLUMNS_TEMPLATE_TWO) | ||
| 99 | + .columnsGap(4) | ||
| 100 | + .rowsGap(2) | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * 布局描述 | ||
| 105 | + * | ||
| 106 | + * @param ContentDTO item 组件项 | ||
| 107 | + * @param index | ||
| 108 | + */ | ||
| 109 | + @Builder | ||
| 110 | + gridItemView(item: ContentDTO, index: number) { | ||
| 111 | + Column() { | ||
| 112 | + Image(item.coverUrl) | ||
| 113 | + .width(FULL_PARENT)// .aspectRatio(3 / 4) // 宽/高比:纵向 | ||
| 114 | + // .aspectRatio(1 / 1) // 宽/高比:正方形 | ||
| 115 | + .aspectRatio(16 / 9)// 宽/高比:横向 | ||
| 116 | + .margin({ top: 8 }) | ||
| 117 | + .borderRadius(10) | ||
| 118 | + | ||
| 119 | + Text(item.title) | ||
| 120 | + .width(FULL_PARENT) | ||
| 121 | + .margin({ top: 4, left: 2, right: 2, bottom: 4 }) | ||
| 122 | + .backgroundColor(Color.White) | ||
| 123 | + .fontWeight(FontWeight.Bold)// .textAlign(TextAlign.Center) | ||
| 124 | + .fontSize($r('app.float.font_size_12')) | ||
| 125 | + .fontColor('#808080') | ||
| 126 | + .maxLines(1) | ||
| 127 | + .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 128 | + } | ||
| 129 | + .width(FULL_PARENT) | ||
| 130 | + .backgroundColor(Color.Yellow) | ||
| 131 | + .justifyContent(FlexAlign.Center) | ||
| 132 | + .onClick(() => { | ||
| 133 | + console.info(TAG, `gridItemView onClick, index: ${index}`); | ||
| 134 | + // MGRouterRule.jumpWithAction(item.action) | ||
| 135 | + }) | ||
| 136 | + } | ||
| 137 | +} |
-
Please register or login to post a comment