xugenyuan

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

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