Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
yangsunyue_wd
2024-04-26 17:37:52 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8c6709dbe626e6d1d913b1b9a39f17843800d731
8c6709db
1 parent
0c9cce45
desc:评论相关
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
177 additions
and
80 deletions
sight_harmony/commons/wdKit/src/main/ets/utils/EmitterEventId.ts
sight_harmony/commons/wdKit/src/main/ets/utils/LazyDataSource.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/model/PublishCommentModel.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentCustomDialog.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentTabComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/QualityCommentsComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/viewmodel/CommentViewModel.ets
sight_harmony/features/wdComponent/src/main/resources/base/media/comment_icon_number.png → sight_harmony/features/wdComponent/src/main/resources/base/media/comment_icon_number_bg.png
sight_harmony/commons/wdKit/src/main/ets/utils/EmitterEventId.ts
View file @
8c6709d
...
...
@@ -11,6 +11,8 @@ export enum EmitterEventId {
// 跳转首页指定频道,事件id
JUMP_HOME_CHANNEL
=
4
,
LOCATION
=
5
LOCATION
=
5
,
/*发布评论*/
COMMENT_PUBLISH
=
6
,
}
...
...
sight_harmony/commons/wdKit/src/main/ets/utils/LazyDataSource.ets
View file @
8c6709d
...
...
@@ -289,4 +289,8 @@ export class LazyDataSource<T> extends BasicDataSource<T> {
this.dataArray.splice(start, this.dataArray.length, ...data);
this.notifyDataReload()
}
public reloadData(): void {
this.notifyDataReload();
}
}
\ No newline at end of file
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/model/PublishCommentModel.ets
View file @
8c6709d
import { commentItemModel } from './CommentModel'
@Observed
export class publishCommentModel {
...
...
@@ -25,7 +27,7 @@ export class publishCommentModel {
/*评论内容*/
commentContent: string = ""
/*1.文字 2.文字+表情 3.定制表情(客户端写死) 4.图片*/
commentType: string = '
1
'
commentType: string = '
2
'
/*根评论id,如果是一级评论,传-1;否则,传当前评论所属的根评论id*/
rootCommentId: string = "-1"
/*父评论id,如果是其它评论的回复,该字段必填*/
...
...
@@ -35,6 +37,10 @@ export class publishCommentModel {
//可选
placeHolderText: string = "优质评论会获得最佳评论人的称号"
//最新发布的评论
lastCommentModel: commentItemModel = new commentItemModel()
}
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentComponent.ets
View file @
8c6709d
import ArrayList from '@ohos.util.ArrayList'
import { ViewType } from 'wdConstant/Index';
import { DateTimeUtils, LazyDataSource } from 'wdKit/Index';
import { DateTimeUtils,
EmitterEventId, EmitterUtils,
LazyDataSource } from 'wdKit/Index';
import PageModel from '../../../viewmodel/PageModel';
import { commentItemModel, commentListModel, WDPublicUserType } from '../model/CommentModel';
import commentViewModel from '../viewmodel/CommentViewModel'
...
...
@@ -9,6 +9,7 @@ import measure from '@ohos.measure'
import { CommentCustomDialog } from './CommentCustomDialog'
import { publishCommentModel } from '../model/PublishCommentModel';
import { ifaa } from '@kit.OnlineAuthenticationKit';
import { HttpUrlUtils } from 'wdNetwork/Index';
const TAG = 'CommentComponent';
...
...
@@ -18,18 +19,13 @@ const testString = '因为读书的人\n是低着头向上看的人\n身处一
@Preview
@Component
export struct CommentComponent {
// @State private browSingModel: commentListModel = new commentListModel()
/*必传*/
@ObjectLink publishCommentModel: publishCommentModel
isloading: boolean = false
@State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
@State dialogController: CustomDialogController | null = null;
// 在自定义组件即将析构销毁时将dialogControlle置空
aboutToDisappear() {
this.dialogController = null // 将dialogController置空
...
...
@@ -37,12 +33,23 @@ export struct CommentComponent {
aboutToAppear() {
//注册通知,来自别的组件的评论成功通知
EmitterUtils.receiveEvent(EmitterEventId.COMMENT_PUBLISH, (targetId?: string) => {
if (targetId) {
if (targetId == this.publishCommentModel.targetId) {
//新增评论
this.addCommentLocal()
}
}
})
this.dialogController = new CustomDialogController({
builder: CommentCustomDialog({
confirm: (value: Record<string, string>) => {
this.addCommentLocal()
},
publishCommentModel:this.publishCommentModel
publishCommentModel:
this.publishCommentModel
}),
autoCancel: true,
alignment: DialogAlignment.Bottom,
...
...
@@ -57,6 +64,24 @@ export struct CommentComponent {
}
//
addCommentLocal() {
let model = commentViewModel.deepCopyCommentItemModel(this.publishCommentModel.lastCommentModel)
/*一级评论*/
if (this.publishCommentModel.lastCommentModel.parentId == '-1') {
this.allDatas.addFirstItem(model)
//TODO 跳转顶部
}else{
//二级评论
this.allDatas.getDataArray().forEach(element => {
if (element.id == this.publishCommentModel.lastCommentModel.rootCommentId) {
element.childCommentsLazyDataSource.addFirstItem(model)
}
});
}
}
/*标题:全部评论*/
@Builder
titleHeader() {
...
...
@@ -73,6 +98,11 @@ export struct CommentComponent {
}
.margin({ left: 16 })
.onClick(()=>{
// this.allDatas.push(new commentItemModel())
// this.allDatas.addFirstItem(new commentItemModel())
// this.allDatas.reloadData();
})
}.height(44)
.width('100%')
...
...
@@ -92,7 +122,11 @@ export struct CommentComponent {
/*查看更多和收起*/
@Builder
GroupFooterView(item: commentItemModel, index: number) {
footerExpandedView({ item: item, contentId: this.publishCommentModel.targetId, contentType: this.publishCommentModel.targetType })
footerExpandedView({
item: item,
contentId: this.publishCommentModel.targetId,
contentType: this.publishCommentModel.targetType
})
}
build() {
...
...
@@ -114,7 +148,7 @@ export struct CommentComponent {
.onClick(() => {
console.log(TAG)
})
})
}
,(childItem: commentItemModel, subIndex: number) => JSON.stringify(childItem) + subIndex.toString()
)
}
} else {
ListItemGroup({ header: this.CommentHeaderItem(item, index) }) {
...
...
@@ -129,29 +163,31 @@ export struct CommentComponent {
.onClick(() => {
console.log(TAG)
})
})
}
,(childItem: commentItemModel, subIndex: number) => JSON.stringify(childItem) + subIndex.toString()
)
}
}
})
}
,(item: commentItemModel, index: number) => JSON.stringify(item) + index.toString()
)
}.layoutWeight(1)
}
}
//获取数据
async getData() {
commentViewModel.fetchContentCommentList('1', this.publishCommentModel.targetId, this.publishCommentModel.targetType).then(commentListModel => {
if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
commentListModel.list.forEach(element => {
element.hasMore = Number.parseInt(element.childCommentNum) ? true : false
let newModel = commentViewModel.deepCopyCommentItemModel(element)
// newModel.targetId = this.publishCommentModel.targetId
// newModel.targetType = this.publishCommentModel.targetType
this.allDatas.push(newModel)
});
commentViewModel.fetchContentCommentList('1', this.publishCommentModel.targetId, this.publishCommentModel.targetType)
.then(commentListModel => {
if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
commentListModel.list.forEach(element => {
element.hasMore = Number.parseInt(element.childCommentNum) ? true : false
let newModel = commentViewModel.deepCopyCommentItemModel(element)
// 点赞用
newModel.targetId = this.publishCommentModel.targetId
newModel.targetType = this.publishCommentModel.targetType
this.allDatas.push(newModel)
});
}
})
}
})
}
}
...
...
@@ -243,6 +279,8 @@ struct ChildCommentItem {
})
.margin({ left: 95, right: 16, top: -5 })
.onClick(() => {
this.publishCommentModel.rootCommentId = this.item.rootCommentId
this.publishCommentModel.parentId = this.item.id
this.publishCommentModel.placeHolderText = '回复' + this.item.fromUserName + ':'
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentCustomDialog.ets
View file @
8c6709d
import { inputMethodEngine } from '@kit.IMEKit'
import { commentInfo } from 'wdBean/Index'
import { commentItemModel } from '../model/CommentModel'
import { publishCommentModel } from '../model/PublishCommentModel'
import commentViewModel from '../viewmodel/CommentViewModel'
...
...
@@ -22,9 +24,10 @@ export struct CommentCustomDialog {
let bean: Record<string, string> = {};
// this.publishCommentModel.commentContent = this.commentText
//TODO 判断类型
this.publishCommentModel.commentType = '1'
commentViewModel.publishComment(this.publishCommentModel).then(() => {
this.publishCommentModel.commentType = '2'
commentViewModel.publishComment(this.publishCommentModel).then((model:commentItemModel) => {
this.publishCommentModel.commentContent = ''
this.publishCommentModel.lastCommentModel = model
// this.commentText = ''
if (this.controller != null) {
this.controller.close()
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentTabComponent.ets
View file @
8c6709d
import { EmitterEventId, EmitterUtils } from 'wdKit/Index'
import { publishCommentModel } from '../model/PublishCommentModel'
import { CommentCustomDialog } from './CommentCustomDialog'
@Preview
@Component
...
...
@@ -8,6 +11,34 @@ export struct CommentTabComponent {
@State type:number = 1
@State placeHolder: string = '说两句...'
@State dialogController: CustomDialogController | null = null;
/*回调方法*/
dialogControllerConfirm: () => void = () => {}
aboutToAppear() {
this.dialogController = new CustomDialogController({
builder: CommentCustomDialog({
confirm: (value: Record<string, string>) => {
this.dialogControllerConfirm();
EmitterUtils.sendEvent(EmitterEventId.COMMENT_PUBLISH,this.publishCommentModel.targetId)
},
publishCommentModel:this.publishCommentModel
}),
autoCancel: true,
alignment: DialogAlignment.Bottom,
customStyle: true,
offset: {
dx: 0,
dy: -20
},
})
}
build() {
Row(){
Stack({alignContent:Alignment.Start}){
...
...
@@ -15,6 +46,10 @@ export struct CommentTabComponent {
Text(this.placeHolder).fontSize(12).fontColor('#999999').margin({left:10})
}
}.width(151).height(30)
.onClick(()=>{
this.publishCommentModel.parentId = '-1';
this.dialogController?.open();
})
}
}
...
...
@@ -25,25 +60,52 @@ export struct CommentIconComponent {
/*展示类型*/
@State type:number = 1
/*回调方法*/
onClickItem: () => void = () => {}
build() {
Row(){
Stack({alignContent:Alignment.TopEnd}){
Image($r('app.media.comment_icon')).width(24).height(24)
// Stack({alignContent:Alignment.Start}) {
// Image($r('app.media.comment_icon_number')).objectFit(ImageFit.Fill).width(12).height(12)
Text(this.publishCommentModel.totalCommentNumer + '12345' +' ')
.fontSize(8)
.fontColor('#ffffff')
// .backgroundColor('#ED2800')
.height(12)
.margin({ left: 6 })
.backgroundImage($r('app.media.comment_icon_number'))
// }.width(25)
RelativeContainer() {
Image($r('app.media.comment_icon_number_bg'))
.objectFit(ImageFit.Fill)
.resizable({ slice: {top:1, left: 20 , right:1, bottom:1} })
.alignRules({
top: {anchor: "Text", align: VerticalAlign.Top},
left: {anchor: "Text", align: HorizontalAlign.Start},
right: {anchor: "Text", align: HorizontalAlign.End},
bottom : {anchor: "Text", align: VerticalAlign.Bottom},
})
// .offset({
// x:-6
// })
.id("Image")
Text('123213123123123')
.fontSize(8)
.fontColor('#ffffff')// .backgroundColor('#ED2800')
.height(12)
.alignRules({
top: {anchor: "__container__", align: VerticalAlign.Top},
left: {anchor: "__container__", align: HorizontalAlign.Start}
})
// .margin({left: 4,right:4
// })
/*动态计算文字宽度*/
.width(50)
// .backgroundColor(Color.Green)
.id("Text")
}
// }
.offset({
x:12
})
}
}.width(24).height(24)
// .backgroundColor(Color.Blue)
}
}
\ No newline at end of file
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/QualityCommentsComponent.ets
View file @
8c6709d
...
...
@@ -185,37 +185,14 @@ export struct QualityCommentsComponent {
Column() {
Stack() {
this.titleHeader()
this.listLayout()
// if(this.viewType == ViewType.ERROR){
// ErrorComponent()
// }else if(this.viewType == ViewType.EMPTY){
// EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NoComment})
// }else {
// CustomPullToRefresh({
// alldata:[],
// scroller:this.scroller,
// customList:()=>{
// this.listLayout()
// // this.testLayout()
// },
// onRefresh:(resolve)=>{
// this.currentPage = 1
// this.getData(resolve)
// },
// onLoadMore:(resolve)=> {
// if (this.hasMore === false) {
// if(resolve) resolve('')
// return
// }
// this.currentPage++
// this.getData(resolve)
// }
// })
// }
if(this.viewType == ViewType.ERROR){
ErrorComponent()
}else if(this.viewType == ViewType.EMPTY){
EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NoComment})
}else {
this.listLayout()
}
}.alignContent(Alignment.Top)
}.backgroundColor(this.currentWindowColor).width('100%')
...
...
@@ -251,12 +228,15 @@ export struct QualityCommentsComponent {
ListItem() {
}.height(this.bottomSafeHeight)
}
}.onReachEnd(()=>{
this.currentPage++
this.getData()
})
.margin({ top: 196 })
.height("100%")
.width("100%")
.edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
// .edgeEffect(EdgeEffect.Spring)
// .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
.edgeEffect(EdgeEffect.Spring)
.nestedScroll({
scrollForward: NestedScrollMode.PARENT_FIRST,
scrollBackward: NestedScrollMode.SELF_FIRST
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/viewmodel/CommentViewModel.ets
View file @
8c6709d
...
...
@@ -148,7 +148,7 @@ class CommentViewModel {
bean['userName'] = UserDataLocal.getUserId();
bean['userHeaderUrl'] = UserDataLocal.getUserHeaderUrl();
Http
Request
.post<ResponseDTO<commentStatusModel[]>>(url, bean, headers).then((data: ResponseDTO<commentStatusModel[]>) => {
Http
BizUtil
.post<ResponseDTO<commentStatusModel[]>>(url, bean, headers).then((data: ResponseDTO<commentStatusModel[]>) => {
if (data.code != 0) {
fail()
return
...
...
@@ -164,7 +164,7 @@ class CommentViewModel {
/*发布评论*/
publishComment(model: publishCommentModel) {
return new Promise<
void
>((success, fail) => {
return new Promise<
commentItemModel
>((success, fail) => {
let url = HttpUrlUtils.getPublishCommentUrl()
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
let bean: Record<string, string> = {};
...
...
@@ -182,14 +182,15 @@ class CommentViewModel {
bean['targetType'] = model.targetType
bean['parentId'] = model.parentId
HttpRequest.post<ResponseDTO<comment
StatusModel[]>>(url, bean, headers).then((data: ResponseDTO<commentStatusModel[]
>) => {
HttpRequest.post<ResponseDTO<comment
ItemModel>>(url, bean, headers).then((data: ResponseDTO<commentItemModel
>) => {
if (data.code != 0) {
ToastUtils.showToast(data.message, 1000);
fail()
return
}
ToastUtils.showToast(data.message, 1000);
success()
let model = data.data as commentItemModel
success(model)
}, (error: Error) => {
ToastUtils.showToast('评论失败', 1000);
fail()
...
...
@@ -240,7 +241,7 @@ class CommentViewModel {
let promiseArray: Promise<commentStatusListModel | void>[] = [];
//未登录不用批查
if (HttpUrlUtils.getUserId()){
if (HttpUrlUtils.getUserId())
{
if (commentIDs.length > 0) {
let promise1 = new Promise<void>((success) => {
// HttpRequest HttpBizUtil
...
...
@@ -285,7 +286,7 @@ class CommentViewModel {
})
promiseArray.push(promise1);
}
}
}
if (fromUserIDs.length > 0) {
let promise2 = new Promise<void>((success) => {
let url = HttpUrlUtils.getBatchUserUrl();
...
...
@@ -386,8 +387,6 @@ class CommentViewModel {
}
deepCopyCommentItemModel(model: commentItemModel) {
let newModel = new commentItemModel()
...
...
@@ -411,10 +410,13 @@ class CommentViewModel {
newModel.fromUserHeader = model.fromUserHeader
newModel.fromUserId = model.fromUserId
newModel.fromUserName = model.fromUserName
newModel.fromUserType = model.fromUserType
if (model.toUserType != null) {
newModel.fromUserType = model.fromUserType
}
newModel.id = model.id
newModel.likeNum = model.likeNum.toString()
if (model.likeNum) {
newModel.likeNum = model.likeNum.toString()
}
if (Number.parseInt(newModel.likeNum) <= 0) {
newModel.likeNum = ''
}
...
...
sight_harmony/features/wdComponent/src/main/resources/base/media/comment_icon_number.png → sight_harmony/features/wdComponent/src/main/resources/base/media/comment_icon_number
_bg
.png
View file @
8c6709d
934 Bytes
Please
register
or
login
to post a comment