xugenyuan

fix |> 评论输入框无100字上限限制和提醒,评论输入框无法随着评论内容的输入自适应高度

http://192.168.1.3:8080/zentao/bug-view-20500.html

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
@@ -36,6 +36,8 @@ export struct CommentCustomDialog { @@ -36,6 +36,8 @@ export struct CommentCustomDialog {
36 textInputController: TextAreaController = new TextAreaController() 36 textInputController: TextAreaController = new TextAreaController()
37 @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 } 37 @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 }
38 @State publishButtonOpacity: number = 0.5 38 @State publishButtonOpacity: number = 0.5
  39 + @State inputViewHeight: number = 80
  40 + @Provide maxInputLength: number = 100
39 41
40 aboutToAppear(): void { 42 aboutToAppear(): void {
41 } 43 }
@@ -98,15 +100,32 @@ export struct CommentCustomDialog { @@ -98,15 +100,32 @@ export struct CommentCustomDialog {
98 .width('100%') 100 .width('100%')
99 .backgroundColor($r('app.color.color_transparent')) 101 .backgroundColor($r('app.color.color_transparent'))
100 .caretColor("#ED2800") 102 .caretColor("#ED2800")
  103 + .maxLength(this.maxInputLength)
  104 + .onWillInsert(data => {
  105 + if (this.publishCommentModel.commentContent.length + data.insertValue.length > this.maxInputLength) {
  106 + ToastUtils.showToast("已达到输入上限", 3000)
  107 + return false
  108 + }
  109 + return true
  110 + })
101 .onChange(value => { 111 .onChange(value => {
102 this.publishCommentModel.commentContent = value; 112 this.publishCommentModel.commentContent = value;
103 113
  114 + if ((this.textInputController.getTextContentLineCount() - 3) > 0) {
  115 + this.inputViewHeight = 80 + (this.textInputController.getTextContentLineCount() - 3) * 18
  116 + }
  117 +
104 if (value.length > 0) { 118 if (value.length > 0) {
105 this.publishButtonOpacity = 1.0 119 this.publishButtonOpacity = 1.0
106 } else { 120 } else {
107 this.publishButtonOpacity = 0.5 121 this.publishButtonOpacity = 0.5
108 } 122 }
109 }) 123 })
  124 + .onPaste(value => {
  125 + if (this.publishCommentModel.commentContent.length + value.length > this.maxInputLength) {
  126 + ToastUtils.showToast("已达到输入上限", 3000)
  127 + }
  128 + })
110 .onFocus(() => { 129 .onFocus(() => {
111 if (this.emojiSwitch) { 130 if (this.emojiSwitch) {
112 this.emojiSwitch = false 131 this.emojiSwitch = false
@@ -119,7 +138,7 @@ export struct CommentCustomDialog { @@ -119,7 +138,7 @@ export struct CommentCustomDialog {
119 .backgroundColor('#F9F9F9') 138 .backgroundColor('#F9F9F9')
120 // .width('100%') 139 // .width('100%')
121 .margin({ top: 12, right: 12, left: 12, bottom:10}) 140 .margin({ top: 12, right: 12, left: 12, bottom:10})
122 - .height(80) 141 + .height(this.inputViewHeight)
123 .borderRadius(4) 142 .borderRadius(4)
124 143
125 Row() { 144 Row() {
@@ -198,7 +217,24 @@ export struct CommentCustomDialog { @@ -198,7 +217,24 @@ export struct CommentCustomDialog {
198 } 217 }
199 if (this.voiceSwitch) { 218 if (this.voiceSwitch) {
200 VoiceInputView({voiceRecoginizerResult:(result: string) => { 219 VoiceInputView({voiceRecoginizerResult:(result: string) => {
201 - this.publishCommentModel.commentContent = result; 220 + let beforeStr = ""
  221 + let afterStr = ""
  222 + const offset = this.textInputController.getCaretOffset().index
  223 + if (offset > 0) {
  224 + beforeStr = this.publishCommentModel.commentContent.slice(0, offset)
  225 + }
  226 + if (offset < this.publishCommentModel.commentContent.length) {
  227 + afterStr = this.publishCommentModel.commentContent.slice(offset)
  228 + }
  229 +
  230 + if (this.publishCommentModel.commentContent.length + result.length > this.maxInputLength) {
  231 + let length = this.maxInputLength - this.publishCommentModel.commentContent.length
  232 + if (length < result.length) {
  233 + result.substring(0, length)
  234 + }
  235 + ToastUtils.showToast("已达到输入上限", 3000)
  236 + }
  237 + this.publishCommentModel.commentContent = beforeStr + result + afterStr
202 }}).height(150) 238 }}).height(150)
203 239
204 } 240 }
@@ -213,6 +249,7 @@ export struct CommentCustomDialog { @@ -213,6 +249,7 @@ export struct CommentCustomDialog {
213 249
214 @Component 250 @Component
215 struct emojiView { 251 struct emojiView {
  252 + @Consume maxInputLength: number
216 @ObjectLink publishCommentModel: publishCommentModel 253 @ObjectLink publishCommentModel: publishCommentModel
217 /*没找到获取系统emoji的方案*/ 254 /*没找到获取系统emoji的方案*/
218 private emojiArray = ["😀","😁","😂","😃","😄","😅","😆","😇","😈","😉","😊","😋","😌","😍","😎","😏","😐","😑","😒","😓","😔","😕","😖","😗","😘","😙","😚","😛","😜","😝","😞","😟","😠","😡","😢","😣","😤","😥","😦","😧","😨","😩","😪","😫","😬","😭","😮","😯","😰","😱","😲","😳","😴","😵","😶","😷","😸","😹","😺","😻","😼","😽","😾","😿","🙀","🙅","🙆","🙇","🙈","🙉","🙊","🙋","🙌","🙍","🙎","🙏"] 255 private emojiArray = ["😀","😁","😂","😃","😄","😅","😆","😇","😈","😉","😊","😋","😌","😍","😎","😏","😐","😑","😒","😓","😔","😕","😖","😗","😘","😙","😚","😛","😜","😝","😞","😟","😠","😡","😢","😣","😤","😥","😦","😧","😨","😩","😪","😫","😬","😭","😮","😯","😰","😱","😲","😳","😴","😵","😶","😷","😸","😹","😺","😻","😼","😽","😾","😿","🙀","🙅","🙆","🙇","🙈","🙉","🙊","🙋","🙌","🙍","🙎","🙏"]
@@ -284,6 +321,10 @@ struct emojiView { @@ -284,6 +321,10 @@ struct emojiView {
284 321
285 } else { 322 } else {
286 Logger.debug(TAG, "charCode: " + emoji.charCodeAt(0) + " ==> " + emoji) 323 Logger.debug(TAG, "charCode: " + emoji.charCodeAt(0) + " ==> " + emoji)
  324 + if (this.publishCommentModel.commentContent.length + emoji.length > this.maxInputLength) {
  325 + ToastUtils.showToast("已达到输入上限", 3000)
  326 + return
  327 + }
287 this.publishCommentModel.commentContent = this.publishCommentModel.commentContent + emoji 328 this.publishCommentModel.commentContent = this.publishCommentModel.commentContent + emoji
288 } 329 }
289 330