xugenyuan

ref |> 发布评论输入框增加发布按钮点击事件回调拦截组件上的接口调用

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
... ... @@ -4,14 +4,25 @@ import { commentItemModel } from '../model/CommentModel'
import { publishCommentModel } from '../model/PublishCommentModel'
import commentViewModel from '../viewmodel/CommentViewModel'
export interface CommentDialogInputContent {
comment?: string
imageUrl?: string
}
/// 评论输入框
@Preview
@CustomDialog
export struct CommentCustomDialog {
@ObjectLink publishCommentModel: publishCommentModel
controller?: CustomDialogController
confirm: (value: Record<string, string>) => void = () => {
}
// 发布按钮点击事件。如果上层传了该值,切返回了true,表示上层已处理,则 confirm 回调不生效
// 可以用这里在上层做埋点
onPublishBtnClick?: (content: CommentDialogInputContent) => boolean
// confirm 表示内部处理调用 内容评论接口 发布了评论并成功,上层只需要 通过 publishCommentModel.lastCommentModel 即可获取最新已提交的评论
confirm?: (value: Record<string, string>) => void
@State private emojiSwitch: boolean = false
textInputController: TextAreaController = new TextAreaController()
@State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 }
... ... @@ -21,6 +32,13 @@ export struct CommentCustomDialog {
}
publishCommentRequest() {
if (this.onPublishBtnClick) {
let content: CommentDialogInputContent = { comment: this.publishCommentModel.commentContent }
if (this.onPublishBtnClick(content)) {
return
}
}
let bean: Record<string, string> = {};
// this.publishCommentModel.commentContent = this.commentText
//TODO 判断类型
... ... @@ -34,7 +52,9 @@ export struct CommentCustomDialog {
if (this.controller != null) {
this.controller.close()
}
this.confirm(bean)
if (this.confirm) {
this.confirm(bean)
}
}).catch(() => {
if (this.controller != null) {
this.controller.close()
... ...