xugenyuan

ref |> 表情符号删除

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

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
1 import { inputMethodEngine } from '@kit.IMEKit' 1 import { inputMethodEngine } from '@kit.IMEKit'
2 import { commentInfo } from 'wdBean/Index' 2 import { commentInfo } from 'wdBean/Index'
3 import { VoiceRecoginizer } from 'wdHwAbility' 3 import { VoiceRecoginizer } from 'wdHwAbility'
4 -import { ToastUtils } from 'wdKit/Index' 4 +import { Logger, ToastUtils } from 'wdKit/Index'
5 import { HttpUtils } from 'wdNetwork/Index' 5 import { HttpUtils } from 'wdNetwork/Index'
6 import { commentItemModel } from '../model/CommentModel' 6 import { commentItemModel } from '../model/CommentModel'
7 import { publishCommentModel } from '../model/PublishCommentModel' 7 import { publishCommentModel } from '../model/PublishCommentModel'
@@ -9,6 +9,8 @@ import commentViewModel from '../viewmodel/CommentViewModel' @@ -9,6 +9,8 @@ import commentViewModel from '../viewmodel/CommentViewModel'
9 import { VoiceInputView } from './VoiceInputView' 9 import { VoiceInputView } from './VoiceInputView'
10 import { common, UIAbility } from '@kit.AbilityKit' 10 import { common, UIAbility } from '@kit.AbilityKit'
11 11
  12 +const TAG = "CommentInputDialog"
  13 +
12 export interface CommentDialogInputContent { 14 export interface CommentDialogInputContent {
13 comment?: string 15 comment?: string
14 imageUrl?: string 16 imageUrl?: string
@@ -213,15 +215,16 @@ export struct CommentCustomDialog { @@ -213,15 +215,16 @@ export struct CommentCustomDialog {
213 struct emojiView { 215 struct emojiView {
214 @ObjectLink publishCommentModel: publishCommentModel 216 @ObjectLink publishCommentModel: publishCommentModel
215 /*没找到获取系统emoji的方案*/ 217 /*没找到获取系统emoji的方案*/
216 - private emojiString = '😀,😁,😂,😃,😄,😅,😆,😇,😈,😉,😊,😋,😌,😍,😎,😏,😐,😑,😒,😓,😔,😕,😖,😗,😘,😙,😚,😛,😜,😝,😞,😟,😠,😡,😢,😣,😤,😥,😦,😧,😨,😩,😪,😫,😬,😭,😮,😯,😰,😱,😲,😳,😴,😵,😶,😷,😸,😹,😺,😻,😼,😽,😾,😿,🙀,🙅,🙆,🙇,🙈,🙉,🙊,🙋,🙌,🙍,🙎,🙏'  
217 - private displayArray: string[][] = [] 218 + private emojiArray = ["😀","😁","😂","😃","😄","😅","😆","😇","😈","😉","😊","😋","😌","😍","😎","😏","😐","😑","😒","😓","😔","😕","😖","😗","😘","😙","😚","😛","😜","😝","😞","😟","😠","😡","😢","😣","😤","😥","😦","😧","😨","😩","😪","😫","😬","😭","😮","😯","😰","😱","😲","😳","😴","😵","😶","😷","😸","😹","😺","😻","😼","😽","😾","😿","🙀","🙅","🙆","🙇","🙈","🙉","🙊","🙋","🙌","🙍","🙎","🙏"]
  219 + // private emojiCharCodeArray: number[] = []
  220 + private displayArray: string[][] = []
218 private swiperController: SwiperController = new SwiperController() 221 private swiperController: SwiperController = new SwiperController()
219 222
220 aboutToAppear(): void { 223 aboutToAppear(): void {
221 224
222 225
223 -  
224 - this.displayArray = chunk(this.emojiString.split(','), 20) 226 + // this.emojiCharCodeArray = this.emojiArray.map((a) => { return a.charCodeAt(0) })
  227 + this.displayArray = chunk(this.emojiArray, 20)
225 228
226 //补上删除按钮以及空白占位 229 //补上删除按钮以及空白占位
227 let lastElement = this.displayArray.slice(-1)[0]; 230 let lastElement = this.displayArray.slice(-1)[0];
@@ -260,10 +263,27 @@ struct emojiView { @@ -260,10 +263,27 @@ struct emojiView {
260 // .backgroundColor(Color.Orange) 263 // .backgroundColor(Color.Orange)
261 }.onClick(() => { 264 }.onClick(() => {
262 if (emoji == '删除') { 265 if (emoji == '删除') {
263 - this.publishCommentModel.commentContent = this.publishCommentModel.commentContent.substring(0, this.publishCommentModel.commentContent.length -1) 266 + let content = this.publishCommentModel.commentContent
  267 + // if (content.length > 3) {
  268 + // if (isEmojiCharacter(content.substring(content.length-4))) {
  269 + // content = content.substring(0, content.length -4)
  270 + // this.publishCommentModel.commentContent = content
  271 + // return
  272 + // }
  273 + // }
  274 + if (content.length > 1) {
  275 + if (isEmojiCharacter(content.substring(content.length-2))) {
  276 + content = content.substring(0, content.length -2)
  277 + this.publishCommentModel.commentContent = content
  278 + return
  279 + }
  280 + }
  281 + content = content.substring(0, content.length -1)
  282 + this.publishCommentModel.commentContent = content
264 } else if (emoji == '') { 283 } else if (emoji == '') {
265 284
266 } else { 285 } else {
  286 + Logger.debug(TAG, "charCode: " + emoji.charCodeAt(0) + " ==> " + emoji)
267 this.publishCommentModel.commentContent = this.publishCommentModel.commentContent + emoji 287 this.publishCommentModel.commentContent = this.publishCommentModel.commentContent + emoji
268 } 288 }
269 289
@@ -295,6 +315,45 @@ function chunk<T>(array: T[], size: number): T[][] { @@ -295,6 +315,45 @@ function chunk<T>(array: T[], size: number): T[][] {
295 return result; 315 return result;
296 } 316 }
297 317
298 -  
299 -  
300 - 318 +// https://blog.csdn.net/liaowenfeng/article/details/120484855
  319 +function isEmojiCharacter(substring: string): boolean {
  320 + for (let i = 0; i < substring.length; i++) {
  321 + let hs = substring.charCodeAt(i);
  322 + if (0xd800 <= hs && hs <= 0xdbff) {
  323 + if (substring.length > 1) {
  324 + let ls = substring.charCodeAt(i + 1);
  325 + let uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
  326 + if (0x1d000 <= uc && uc <= 0x1f77f) {
  327 + return true;
  328 + }
  329 + if (0x1f900 <= uc && uc <= 0x1f9ff) {
  330 + // SupplementalSymBolsAndPictographs 字符串含有表情字符[U+1F900,U+1F90F]
  331 + // https://www.fileformat.info/info/unicode/block/supplemental_symbols_and_pictographs/index.htm
  332 + // https://www.fileformat.info/info/unicode/char/1f964/index.htm
  333 + return true;
  334 + }
  335 + }
  336 + }
  337 + else if (substring.length > 1) {
  338 + let ls = substring.charCodeAt(i + 1);
  339 + if (ls == 0x20e3) {
  340 + return true;
  341 + }
  342 + } else {
  343 + if (0x2100 <= hs && hs <= 0x27ff) {
  344 + return true;
  345 + } else if (0x2B05 <= hs && hs <= 0x2b07) {
  346 + return true;
  347 + } else if (0x2934 <= hs && hs <= 0x2935) {
  348 + return true;
  349 + } else if (0x3297 <= hs && hs <= 0x3299) {
  350 + return true;
  351 + } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 ||
  352 + hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b ||
  353 + hs == 0x2b50) {
  354 + return true;
  355 + }
  356 + }
  357 + }
  358 + return false;
  359 +}