xugenyuan

ref |> 表情符号删除

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

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
import { inputMethodEngine } from '@kit.IMEKit'
import { commentInfo } from 'wdBean/Index'
import { VoiceRecoginizer } from 'wdHwAbility'
import { ToastUtils } from 'wdKit/Index'
import { Logger, ToastUtils } from 'wdKit/Index'
import { HttpUtils } from 'wdNetwork/Index'
import { commentItemModel } from '../model/CommentModel'
import { publishCommentModel } from '../model/PublishCommentModel'
... ... @@ -9,6 +9,8 @@ import commentViewModel from '../viewmodel/CommentViewModel'
import { VoiceInputView } from './VoiceInputView'
import { common, UIAbility } from '@kit.AbilityKit'
const TAG = "CommentInputDialog"
export interface CommentDialogInputContent {
comment?: string
imageUrl?: string
... ... @@ -213,15 +215,16 @@ export struct CommentCustomDialog {
struct emojiView {
@ObjectLink publishCommentModel: publishCommentModel
/*没找到获取系统emoji的方案*/
private emojiString = '😀,😁,😂,😃,😄,😅,😆,😇,😈,😉,😊,😋,😌,😍,😎,😏,😐,😑,😒,😓,😔,😕,😖,😗,😘,😙,😚,😛,😜,😝,😞,😟,😠,😡,😢,😣,😤,😥,😦,😧,😨,😩,😪,😫,😬,😭,😮,😯,😰,😱,😲,😳,😴,😵,😶,😷,😸,😹,😺,😻,😼,😽,😾,😿,🙀,🙅,🙆,🙇,🙈,🙉,🙊,🙋,🙌,🙍,🙎,🙏'
private emojiArray = ["😀","😁","😂","😃","😄","😅","😆","😇","😈","😉","😊","😋","😌","😍","😎","😏","😐","😑","😒","😓","😔","😕","😖","😗","😘","😙","😚","😛","😜","😝","😞","😟","😠","😡","😢","😣","😤","😥","😦","😧","😨","😩","😪","😫","😬","😭","😮","😯","😰","😱","😲","😳","😴","😵","😶","😷","😸","😹","😺","😻","😼","😽","😾","😿","🙀","🙅","🙆","🙇","🙈","🙉","🙊","🙋","🙌","🙍","🙎","🙏"]
// private emojiCharCodeArray: number[] = []
private displayArray: string[][] = []
private swiperController: SwiperController = new SwiperController()
aboutToAppear(): void {
this.displayArray = chunk(this.emojiString.split(','), 20)
// this.emojiCharCodeArray = this.emojiArray.map((a) => { return a.charCodeAt(0) })
this.displayArray = chunk(this.emojiArray, 20)
//补上删除按钮以及空白占位
let lastElement = this.displayArray.slice(-1)[0];
... ... @@ -260,10 +263,27 @@ struct emojiView {
// .backgroundColor(Color.Orange)
}.onClick(() => {
if (emoji == '删除') {
this.publishCommentModel.commentContent = this.publishCommentModel.commentContent.substring(0, this.publishCommentModel.commentContent.length -1)
let content = this.publishCommentModel.commentContent
// if (content.length > 3) {
// if (isEmojiCharacter(content.substring(content.length-4))) {
// content = content.substring(0, content.length -4)
// this.publishCommentModel.commentContent = content
// return
// }
// }
if (content.length > 1) {
if (isEmojiCharacter(content.substring(content.length-2))) {
content = content.substring(0, content.length -2)
this.publishCommentModel.commentContent = content
return
}
}
content = content.substring(0, content.length -1)
this.publishCommentModel.commentContent = content
} else if (emoji == '') {
} else {
Logger.debug(TAG, "charCode: " + emoji.charCodeAt(0) + " ==> " + emoji)
this.publishCommentModel.commentContent = this.publishCommentModel.commentContent + emoji
}
... ... @@ -295,6 +315,45 @@ function chunk<T>(array: T[], size: number): T[][] {
return result;
}
// https://blog.csdn.net/liaowenfeng/article/details/120484855
function isEmojiCharacter(substring: string): boolean {
for (let i = 0; i < substring.length; i++) {
let hs = substring.charCodeAt(i);
if (0xd800 <= hs && hs <= 0xdbff) {
if (substring.length > 1) {
let ls = substring.charCodeAt(i + 1);
let uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
if (0x1d000 <= uc && uc <= 0x1f77f) {
return true;
}
if (0x1f900 <= uc && uc <= 0x1f9ff) {
// SupplementalSymBolsAndPictographs 字符串含有表情字符[U+1F900,U+1F90F]
// https://www.fileformat.info/info/unicode/block/supplemental_symbols_and_pictographs/index.htm
// https://www.fileformat.info/info/unicode/char/1f964/index.htm
return true;
}
}
}
else if (substring.length > 1) {
let ls = substring.charCodeAt(i + 1);
if (ls == 0x20e3) {
return true;
}
} else {
if (0x2100 <= hs && hs <= 0x27ff) {
return true;
} else if (0x2B05 <= hs && hs <= 0x2b07) {
return true;
} else if (0x2934 <= hs && hs <= 0x2935) {
return true;
} else if (0x3297 <= hs && hs <= 0x3299) {
return true;
} else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 ||
hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b ||
hs == 0x2b50) {
return true;
}
}
}
return false;
}
... ...