Open
fix: 外部参数校验 #5
dangdangallisonAdd on Jul 23
fix: 外部参数校验 #5
Open
Total: 2 files changed+11-1
| @@ -48,8 +48,17 @@ export struct ImageCommentComponent { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | publishComment(): void { | 50 | publishComment(): void { |
| 51 | + const maxLength = 500; | ||
| 52 | + let text = this.textInComment; | ||
| 53 | + let images = this.imageInComment; | ||
| 54 | + if (text.length > maxLength) { | ||
| 55 | + text = text.substring(0, maxLength); | ||
| 56 | + } | ||
| 57 | + if (images.length > maxLength) { | ||
| 58 | + images = images.slice(0, maxLength); | ||
| 59 | + } | ||
| 51 | const comment: Comment = | 60 | const comment: Comment = |
| 52 | - new Comment($r('app.string.name_mine'), this.textInComment, $r('app.media.app_mine_logo'), this.imageInComment, | 61 | + new Comment($r('app.string.name_mine'), text, $r('app.media.app_mine_logo'), images, |
| 53 | this.getCurrentDate()); | 62 | this.getCurrentDate()); |
| 54 | this.commentList.addDataFirst(comment); | 63 | this.commentList.addDataFirst(comment); |
| 55 | } | 64 | } |
| @@ -75,6 +75,7 @@ export struct CommentInputDialog { | |||
| 75 | .onChange((textInComment: string) => { | 75 | .onChange((textInComment: string) => { |
| 76 | this.text = textInComment; | 76 | this.text = textInComment; |
| 77 | }) | 77 | }) |
| 78 | + .maxLength(500) | ||
| 78 | .defaultFocus(true) | 79 | .defaultFocus(true) |
| 79 | .alignRules({ | 80 | .alignRules({ |
| 80 | top: { anchor: '__container__', align: VerticalAlign.Top }, | 81 | top: { anchor: '__container__', align: VerticalAlign.Top }, |