王士厅

图集替换缺省图为通用组件

1 -import { CommonConstants } from 'wdConstant';  
2 -import { Logger } from 'wdKit';  
3 -  
4 -const TAG = 'EmptyComponent';  
5 -  
6 -/**  
7 - * WDViewDefaultType 缺省页  
8 - */  
9 -export const enum WDViewDefaultType {  
10 - ///无网  
11 - WDViewDefaultType_NoNetwork,  
12 - ///网络失败 请稍后重试-倒计时  
13 - WDViewDefaultType_NetworkFailed,  
14 - ///内容获取失败  
15 - WDViewDefaultType_ContentFailed,  
16 -}  
17 -  
18 -/**  
19 - * 空数据/无数据  
20 - */  
21 -@Preview  
22 -@Component  
23 -export struct MultiPictureDetailEmptyComponent {  
24 - // private emptySize: SizeOptions = {};  
25 - @State emptyWidth: string | number = CommonConstants.FULL_PARENT;  
26 - @State emptyHeight: string | number = CommonConstants.FULL_PARENT;  
27 - @State emptyType: number = WDViewDefaultType.WDViewDefaultType_ContentFailed  
28 - /**  
29 - * The empty image width percentage setting.  
30 - */  
31 - readonly EMPTY_IMAGE_WIDTH: string = '15%';  
32 - /**  
33 - * The empty image height percentage setting.  
34 - */  
35 - readonly EMPTY_IMAGE_HEIGHT: string = '15%';  
36 - /**  
37 - * The empty data text component margin top.  
38 - */  
39 - readonly EMPTY_TIP_TEXT_MARGIN_TOP: string = '10';  
40 - /**  
41 - * The empty data text opacity.  
42 - */  
43 - readonly TEXT_OPACITY: number = 1;  
44 -  
45 - build() {  
46 - this.noProgrammeData();  
47 - }  
48 -  
49 - /**  
50 - * 无数据,空白view组件  
51 - */  
52 - @Builder  
53 - noProgrammeData() {  
54 - Column() {  
55 - Image(this.buildNoDataTipImage())  
56 - .width('this.EMPTY_IMAGE_WIDTH')  
57 - .height(this.EMPTY_IMAGE_HEIGHT)  
58 - .objectFit(ImageFit.Contain)  
59 - // .border({ width: 1, color: Color.Red, radius: 6 })  
60 -  
61 - Text(this.buildNoDataTip())  
62 - .fontSize($r('app.float.font_size_14'))  
63 - .fontColor('#999999')  
64 - .fontWeight(FontWeight.Normal)  
65 - .opacity(this.TEXT_OPACITY)  
66 - .margin({ top: this.EMPTY_TIP_TEXT_MARGIN_TOP })  
67 - .onClick((event: ClickEvent) => {  
68 - Logger.info(TAG, `noProgrammeData onClick event?.source: ${event.source}`);  
69 - })  
70 - Button('点击重试', { type: ButtonType.Normal, stateEffect: true })  
71 - .borderRadius(4)  
72 - .margin(16)  
73 - .height(28)  
74 - .fontSize(12)  
75 - .fontColor('#CCCCCC')  
76 - .fontFamily('PingFang SC-Medium')  
77 - .border({ width: 1, color: '#545454' })  
78 - .backgroundColor(Color.Black)  
79 - }  
80 - .justifyContent(FlexAlign.Center)  
81 - .width(this.emptyWidth)  
82 - .height(this.emptyHeight)  
83 - .backgroundColor(Color.Black)  
84 - }  
85 -  
86 - buildNoDataTip(): string {  
87 - Logger.info(TAG, "buildNoDataTip");  
88 - let contentString: string = '获取内容失败请重试'  
89 - if (this.emptyType === WDViewDefaultType.WDViewDefaultType_NoNetwork) {  
90 - contentString = '网络出小差了,请检查网络后重试'  
91 - } else if (this.emptyType === WDViewDefaultType.WDViewDefaultType_ContentFailed) {  
92 - contentString = '获取内容失败请重试'  
93 - }  
94 -  
95 - return contentString  
96 - }  
97 -  
98 - buildNoDataTipImage(): Resource | string {  
99 - Logger.info(TAG, "buildNoDataTip");  
100 - let imageString: Resource | string = $r('app.media.icon_no_content')  
101 - if (this.emptyType === WDViewDefaultType.WDViewDefaultType_NoNetwork) {  
102 - imageString = $r('app.media.icon_no_net')  
103 - } else if (this.emptyType === WDViewDefaultType.WDViewDefaultType_ContentFailed) {  
104 - imageString = $r('app.media.icon_no_content')  
105 - } else if (this.emptyType === WDViewDefaultType.WDViewDefaultType_NetworkFailed) {  
106 - imageString = $r('app.media.icon_no_net')  
107 - }  
108 - return imageString  
109 - }  
110 -}  
@@ -12,7 +12,7 @@ import display from '@ohos.display'; @@ -12,7 +12,7 @@ import display from '@ohos.display';
12 import font from '@ohos.font'; 12 import font from '@ohos.font';
13 import { OperRowListView } from './view/OperRowListView'; 13 import { OperRowListView } from './view/OperRowListView';
14 import { MultiPictureDetailItemComponent } from './MultiPictureDetailItemComponent'; 14 import { MultiPictureDetailItemComponent } from './MultiPictureDetailItemComponent';
15 -import { MultiPictureDetailEmptyComponent } from './MultiPictureDetailEmptyComponent'; 15 +import { EmptyComponent } from './view/EmptyComponent';
16 import { DateTimeUtils } from 'wdKit/Index'; 16 import { DateTimeUtils } from 'wdKit/Index';
17 import { HttpUrlUtils } from 'wdNetwork/Index'; 17 import { HttpUrlUtils } from 'wdNetwork/Index';
18 import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'; 18 import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
@@ -37,7 +37,7 @@ export struct MultiPictureDetailPageComponent { @@ -37,7 +37,7 @@ export struct MultiPictureDetailPageComponent {
37 @State swiperIndex: number = 0; 37 @State swiperIndex: number = 0;
38 @Provide followStatus: string = '0' // 关注状态 38 @Provide followStatus: string = '0' // 关注状态
39 private scroller: Scroller = new Scroller() 39 private scroller: Scroller = new Scroller()
40 - @State netStatus: number = 0 // 存储网络状态用来展示缺省图 40 + @State netStatus: number | undefined = undefined // 存储网络状态用来展示缺省图
41 41
42 //watch监听页码回调 42 //watch监听页码回调
43 onCurrentPageNumUpdated(): void { 43 onCurrentPageNumUpdated(): void {
@@ -239,8 +239,8 @@ export struct MultiPictureDetailPageComponent { @@ -239,8 +239,8 @@ export struct MultiPictureDetailPageComponent {
239 .height(px2vp(this.titleHeight) + 64) 239 .height(px2vp(this.titleHeight) + 64)
240 240
241 } else { 241 } else {
242 - if (this.netStatus === 1) {  
243 - MultiPictureDetailEmptyComponent({ emptyType: 2}) 242 + if(this.netStatus !== undefined) {
  243 + EmptyComponent({ emptyType: this.netStatus})
244 .id('e_empty_content') 244 .id('e_empty_content')
245 .alignRules({ 245 .alignRules({
246 center: { anchor: "__container__", align: VerticalAlign.Center }, 246 center: { anchor: "__container__", align: VerticalAlign.Center },
@@ -290,6 +290,9 @@ export struct MultiPictureDetailPageComponent { @@ -290,6 +290,9 @@ export struct MultiPictureDetailPageComponent {
290 return 290 return
291 } 291 }
292 this.contentDetailData = resDTO.data?.[0]; 292 this.contentDetailData = resDTO.data?.[0];
  293 + if(this.contentDetailData?.photoList && this.contentDetailData?.photoList?.length === 0) {
  294 + this.netStatus = 0
  295 + }
293 Logger.info(TAG, `contentDetailData:${JSON.stringify(this.contentDetailData)}`) 296 Logger.info(TAG, `contentDetailData:${JSON.stringify(this.contentDetailData)}`)
294 if (HttpUrlUtils.getUserId()) { 297 if (HttpUrlUtils.getUserId()) {
295 this.getInteractBrowsOperate() 298 this.getInteractBrowsOperate()