wangliang_wd

feat:优化互动消息

1 import { ContentDTO } from 'wdBean/Index'; 1 import { ContentDTO } from 'wdBean/Index';
2 import { ProcessUtils } from 'wdRouter/Index'; 2 import { ProcessUtils } from 'wdRouter/Index';
3 import { InteractMessageModel } from '../../model/InteractMessageModel' 3 import { InteractMessageModel } from '../../model/InteractMessageModel'
4 - 4 +import { DateTimeUtils} from 'wdKit/Index'
5 @Component 5 @Component
6 export struct InteractMComponent { 6 export struct InteractMComponent {
7 messageModel:InteractMessageModel = new InteractMessageModel; 7 messageModel:InteractMessageModel = new InteractMessageModel;
@@ -15,6 +15,7 @@ export struct InteractMComponent { @@ -15,6 +15,7 @@ export struct InteractMComponent {
15 build() { 15 build() {
16 Row(){ 16 Row(){
17 Image(this.messageModel.InteractMsubM.headUrl) 17 Image(this.messageModel.InteractMsubM.headUrl)
  18 + .alt($r('app.media.default_head'))
18 .width(36) 19 .width(36)
19 .height(36) 20 .height(36)
20 .borderRadius(18) 21 .borderRadius(18)
@@ -29,7 +30,7 @@ export struct InteractMComponent { @@ -29,7 +30,7 @@ export struct InteractMComponent {
29 .margin({left:5}) 30 .margin({left:5})
30 }.width('100%') 31 }.width('100%')
31 32
32 - Text(this.messageModel.time) 33 + Text(this.getPublishTime(this.messageModel.time,DateTimeUtils.getDateTimestamp(this.messageModel.time)+""))
33 .margin({top:2}) 34 .margin({top:2})
34 .fontSize('12fp').fontColor('#B0B0B0').margin({top:10,bottom:10}) 35 .fontSize('12fp').fontColor('#B0B0B0').margin({top:10,bottom:10})
35 36
@@ -41,42 +42,44 @@ export struct InteractMComponent { @@ -41,42 +42,44 @@ export struct InteractMComponent {
41 .constraintSize({maxHeight:500}) 42 .constraintSize({maxHeight:500})
42 } 43 }
43 44
44 - Column(){  
45 - if (this.messageModel.contentType === '207' || this.messageModel.contentType === '209'){  
46 - Text('[你的评论]'+this.buildCommentContent()).fontSize('14fp').fontColor('#666666').constraintSize({maxHeight:500})  
47 - .margin({top:15,bottom:10})  
48 - .width('100%') 45 + if(this.messageModel.contentType != '211' && this.messageModel.contentType != '210'){
  46 + Column(){
  47 + if (this.messageModel.contentType === '207' || this.messageModel.contentType === '209'){
  48 + Text('[你的评论]'+this.buildCommentContent()).fontSize('14fp').fontColor('#666666').constraintSize({maxHeight:500})
  49 + .margin({top:15,bottom:10})
  50 + .width('100%')
49 51
50 - Divider()  
51 - .color('#EDEDED')  
52 - .backgroundColor('#EDEDED')  
53 - .width('100%')  
54 - .height(1)  
55 - }  
56 - Row(){  
57 - Image($r('app.media.MessageOriginTextIcon'))  
58 - .width('12')  
59 - .height('12')  
60 - Text(this.messageModel.InteractMsubM.contentTitle)  
61 - .fontSize('12fp')  
62 - .fontColor('#666666')  
63 - .maxLines(1)  
64 - .width('90%')  
65 - .textOverflow({overflow:TextOverflow.Ellipsis}) 52 + Divider()
  53 + .color('#EDEDED')
  54 + .backgroundColor('#EDEDED')
  55 + .width('100%')
  56 + .height(1)
  57 + }
  58 + Row(){
  59 + Image($r('app.media.MessageOriginTextIcon'))
  60 + .width('12')
  61 + .height('12')
  62 + Text(this.messageModel.InteractMsubM.contentTitle)
  63 + .fontSize('12fp')
  64 + .fontColor('#666666')
  65 + .maxLines(1)
  66 + .width('90%')
  67 + .textOverflow({overflow:TextOverflow.Ellipsis})
66 68
67 - Blank() 69 + Blank()
68 70
69 - Image($r('app.media.mine_user_edit'))  
70 - .width('12')  
71 - .height('12')  
72 - }.margin({top:10,bottom:15})  
73 - }.padding({left:10,right:10}).alignItems(HorizontalAlign.Start).backgroundColor('#f5f5f5').borderRadius(5)  
74 - .onClick(()=>{  
75 - let contentDTO :ContentDTO = new ContentDTO();  
76 - contentDTO.objectType = this.messageModel.InteractMsubM.contentType  
77 - contentDTO.objectId = this.messageModel.InteractMsubM.contentId  
78 - ProcessUtils.processPage(contentDTO)  
79 - }) 71 + Image($r('app.media.mine_user_edit'))
  72 + .width('12')
  73 + .height('12')
  74 + }.margin({top:10,bottom:15})
  75 + }.padding({left:10,right:10}).alignItems(HorizontalAlign.Start).backgroundColor('#f5f5f5').borderRadius(5)
  76 + .onClick(()=>{
  77 + let contentDTO :ContentDTO = new ContentDTO();
  78 + contentDTO.objectType = this.messageModel.InteractMsubM.contentType
  79 + contentDTO.objectId = this.messageModel.InteractMsubM.contentId
  80 + ProcessUtils.processPage(contentDTO)
  81 + })
  82 + }
80 }.padding({left:5,right:5}).alignItems(HorizontalAlign.Start).width('90%') 83 }.padding({left:5,right:5}).alignItems(HorizontalAlign.Start).width('90%')
81 }.padding({top:10,left:16,right:16}).width('100%').alignItems(VerticalAlign.Top) 84 }.padding({top:10,left:16,right:16}).width('100%').alignItems(VerticalAlign.Top)
82 } 85 }
@@ -102,4 +105,49 @@ export struct InteractMComponent { @@ -102,4 +105,49 @@ export struct InteractMComponent {
102 let contentString : string = this.messageModel.contentType === '207'?this.messageModel.message:this.messageModel.InteractMsubM.beReply; 105 let contentString : string = this.messageModel.contentType === '207'?this.messageModel.message:this.messageModel.InteractMsubM.beReply;
103 return contentString; 106 return contentString;
104 } 107 }
  108 +
  109 + getPublishTime(data:string,publishTime: string): string {
  110 + const publishTimestamp = parseInt(publishTime)
  111 + const currentTime = Date.now(); // 当前时间戳
  112 +
  113 + // 计算差异
  114 + const timeDifference = currentTime - publishTimestamp;
  115 +
  116 + // 转换为分钟、小时和天
  117 + const minutes = Math.floor(timeDifference / (1000 * 60));
  118 + const hours = Math.floor(timeDifference / (1000 * 60 * 60));
  119 + const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
  120 +
  121 + // 根据时间差返回对应的字符串
  122 + let result: string;
  123 +
  124 + if (minutes < 60) {
  125 + result = `${minutes}分钟前`;
  126 + if (minutes === 0) {
  127 + result = `刚刚`;
  128 + }
  129 + } else if (hours < 24) {
  130 + result = `${hours}小时前`;
  131 + } else {
  132 + result = `${days}天前`;
  133 + if (days > 1) {
  134 + let arr = data.split(" ")
  135 + if (arr.length === 2) {
  136 + let arr2 = arr[0].split("-")
  137 + if (arr2.length === 3) {
  138 + result = `${arr2[1]}-${arr2[2]}`
  139 + }
  140 + } else {
  141 + //原始数据是时间戳 需要转成dateString
  142 + let time = DateTimeUtils.formatDate(Number(publishTime))
  143 + let arr = time.split("-")
  144 + if (arr.length === 3) {
  145 + result = `${arr[1]}-${arr[2]}`
  146 + }
  147 + }
  148 + }
  149 + }
  150 + console.log(result);
  151 + return result
  152 + }
105 } 153 }
@@ -31,21 +31,26 @@ struct InteractMessagePage { @@ -31,21 +31,26 @@ struct InteractMessagePage {
31 if(this.browSingModel.viewType == ViewType.ERROR){ 31 if(this.browSingModel.viewType == ViewType.ERROR){
32 EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NetworkFailed}) 32 EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NetworkFailed})
33 }else if(this.browSingModel.viewType == ViewType.EMPTY){ 33 }else if(this.browSingModel.viewType == ViewType.EMPTY){
34 - EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NoHistory}) 34 + EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NoMessage})
35 }else { 35 }else {
36 CustomPullToRefresh({ 36 CustomPullToRefresh({
37 alldata:this.allDatas, 37 alldata:this.allDatas,
38 scroller:this.scroller, 38 scroller:this.scroller,
  39 + hasMore:this.browSingModel.hasMore,
39 customList:()=>{ 40 customList:()=>{
40 this.ListLayout() 41 this.ListLayout()
41 }, 42 },
42 onRefresh:(resolve)=>{ 43 onRefresh:(resolve)=>{
43 - this.browSingModel.currentPage = 0 44 + this.currentPage = 1
44 this.getData(resolve) 45 this.getData(resolve)
45 }, 46 },
46 onLoadMore:(resolve)=> { 47 onLoadMore:(resolve)=> {
47 - this.browSingModel.currentPage++  
48 - this.getData() 48 + if (this.browSingModel.hasMore === false) {
  49 + if(resolve) resolve('')
  50 + return
  51 + }
  52 + this.currentPage++
  53 + this.getData(resolve)
49 } 54 }
50 }) 55 })
51 } 56 }
@@ -75,6 +80,7 @@ struct InteractMessagePage { @@ -75,6 +80,7 @@ struct InteractMessagePage {
75 } 80 }
76 } 81 }
77 } 82 }
  83 + .scrollBar(BarState.Off)
78 .height(CommonConstants.FULL_PARENT) 84 .height(CommonConstants.FULL_PARENT)
79 .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果 85 .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
80 } 86 }
@@ -120,17 +126,18 @@ struct InteractMessagePage { @@ -120,17 +126,18 @@ struct InteractMessagePage {
120 for (let index = 0; index < InteractMessageMItem.list.length; index++) { 126 for (let index = 0; index < InteractMessageMItem.list.length; index++) {
121 const element = InteractMessageMItem.list[index]; 127 const element = InteractMessageMItem.list[index];
122 element.InteractMsubM = JSON.parse(element.remark) 128 element.InteractMsubM = JSON.parse(element.remark)
  129 + this.allDatas.push(element)
123 } 130 }
124 131
125 - this.allDatas.push(...InteractMessageMItem.list)  
126 - if (InteractMessageMItem.list.length === this.browSingModel.pageSize) {  
127 - this.browSingModel.currentPage++;  
128 - this.browSingModel.hasMore = true;  
129 - } else { 132 + if (InteractMessageMItem.hasNext === 0) {
130 this.browSingModel.hasMore = false; 133 this.browSingModel.hasMore = false;
  134 + } else {
  135 + this.browSingModel.hasMore = true;
131 } 136 }
132 } else { 137 } else {
133 - this.browSingModel.viewType = ViewType.EMPTY; 138 + if (this.currentPage === 1) {
  139 + this.browSingModel.viewType = ViewType.EMPTY;
  140 + }
134 } 141 }
135 }) 142 })
136 } 143 }
@@ -114,6 +114,7 @@ struct MyCollectionListPage { @@ -114,6 +114,7 @@ struct MyCollectionListPage {
114 if (this.browSingModel.hasMore === false) NoMoreLayout() 114 if (this.browSingModel.hasMore === false) NoMoreLayout()
115 } 115 }
116 } 116 }
  117 + .scrollBar(BarState.Off)
117 .height(CommonConstants.FULL_PARENT) 118 .height(CommonConstants.FULL_PARENT)
118 .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果 119 .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
119 } 120 }