972 lines
33 KiB
Plaintext
972 lines
33 KiB
Plaintext
/*
|
||
* Copyright (c) 2022 NetEase, Inc. All rights reserved.
|
||
* Use of this source code is governed by a MIT license that can be
|
||
* found in the LICENSE file.
|
||
*
|
||
*/
|
||
|
||
import { NEEmojiParseResult } from '../manager/NEEmojiManager'
|
||
import { V2NIMMessageFileAttachment, V2NIMMessageLocationAttachment, V2NIMMessageType,V2NIMMessageAttachment } from '@nimsdk/base'
|
||
import {
|
||
getAitNodes,
|
||
getCallMessageIcon,
|
||
getCallMessageText,
|
||
getFileMessageIcon,
|
||
getFileMessageName,
|
||
getFileMessageSize,
|
||
getImageHeight,
|
||
getImageWidth,
|
||
getReplyMessageText,
|
||
getVideoMessageThumbnail,
|
||
getVideoMessageUrl,
|
||
parseMessageText,
|
||
parseReplyMessageUserInfo,
|
||
parseText,
|
||
sliceMessageText
|
||
} from '../common/MessageHelper'
|
||
import { NIMMessageInfo } from '../model/NIMMessageInfo'
|
||
import { MessageItemClick } from './MessageItemClick'
|
||
import { MessageAudioItemView } from '../view/MessageAudioItemView'
|
||
import { image } from '@kit.ImageKit'
|
||
import { staticMap } from '@kit.MapKit'
|
||
import { BusinessError } from '@kit.BasicServicesKit'
|
||
import { ChatAitNode } from '../model/ChatAitNode'
|
||
import { MergedMessageAttachment } from '@nimkit/chatkit'
|
||
import { ChatInfo } from '../model/ChatInfo'
|
||
import { Markdown } from '@nimkit/markdown'
|
||
import { BasicConstant,DataWebModel } from '@itcast/basic'
|
||
import { router } from '@kit.ArkUI'
|
||
@ComponentV2
|
||
export struct messageContent {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
@BuilderParam
|
||
chatInfo: ChatInfo | undefined
|
||
|
||
build() {
|
||
if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_TEXT) {
|
||
if (this.message.isAiStreamMessage() == false) {
|
||
textBuilder({
|
||
message: this.message,
|
||
onMessageClick: this.onMessageClick,
|
||
chatInfo: this.chatInfo
|
||
});
|
||
} else {
|
||
richTextBuilder({
|
||
message: this.message,
|
||
onMessageClick: this.onMessageClick,
|
||
chatInfo: this.chatInfo
|
||
});
|
||
}
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_LOCATION) {
|
||
locationBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_IMAGE) {
|
||
imageBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_VIDEO) {
|
||
videoBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_FILE) {
|
||
fileBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_AUDIO) {
|
||
MessageAudioItemView({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_CALL) {
|
||
callBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_CUSTOM) {
|
||
if (this.message.isMergeMsg) {
|
||
mergedMessageBuilder({ message: this.message, onMessageClick: this.onMessageClick })
|
||
} else {
|
||
|
||
customBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
}
|
||
} else {
|
||
unknownBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
@ComponentV2
|
||
export struct pinMessageContent {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick?: MessageItemClick
|
||
|
||
build() {
|
||
if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_TEXT) {
|
||
pinTextBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_LOCATION) {
|
||
pinLocationBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_IMAGE) {
|
||
imageBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_VIDEO) {
|
||
videoBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_FILE) {
|
||
fileBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_AUDIO) {
|
||
MessageAudioItemView({ message: this.message, onMessageClick: this.onMessageClick, isReceiveStyle: true });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_CALL) {
|
||
callBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
} else if (this.message.getMessageType() == V2NIMMessageType.V2NIM_MESSAGE_TYPE_CUSTOM) {
|
||
if (this.message.isMergeMsg) {
|
||
mergedMessageBuilder({ message: this.message, onMessageClick: this.onMessageClick }).width('80%')
|
||
} else {
|
||
unknownBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
}
|
||
} else {
|
||
unknownBuilder({ message: this.message, onMessageClick: this.onMessageClick });
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
@ComponentV2
|
||
export struct richTextBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
@BuilderParam
|
||
chatInfo: ChatInfo | undefined
|
||
|
||
private onItemClick(event: ClickEvent) {
|
||
this.onMessageClick?.onReplyClick?.(event, this.message.replyMsg)
|
||
}
|
||
|
||
private onRevokeEditClick(event: ClickEvent) {
|
||
this.onMessageClick?.onRevokeEditClick?.(event, this.message)
|
||
|
||
}
|
||
|
||
build() {
|
||
Column() {
|
||
if (!this.message.isRevokeMsg && this.message.isReplyMsg) {
|
||
if (this.message.replyMsg) {
|
||
Text() {
|
||
if (this.chatInfo) {
|
||
Span(' | ' + parseReplyMessageUserInfo(this.message.replyMsg, this.chatInfo))
|
||
.fontSize($r('app.float.chat_desc_text_font_size'))
|
||
.textCase(TextCase.Normal)
|
||
.fontColor($r('app.color.color_chat_desc'))
|
||
}
|
||
ForEach(sliceMessageText(parseMessageText(getReplyMessageText(this.message.replyMsg)), 30),
|
||
(item: NEEmojiParseResult) => {
|
||
if (item.text) {
|
||
Span(item.text)
|
||
.fontSize($r('app.float.chat_desc_text_font_size'))
|
||
.textCase(TextCase.Normal)
|
||
.fontColor($r('app.color.color_chat_desc'))
|
||
} else if (item.emoji) {
|
||
ImageSpan($rawfile(`emoji/${item.emoji.file}`)).width('16')
|
||
.height('16')
|
||
.objectFit(ImageFit.Fill)
|
||
.verticalAlign(ImageSpanAlignment.CENTER)
|
||
}
|
||
})
|
||
}
|
||
.fontColor($r('app.color.color_chat_desc'))
|
||
.fontSize($r('app.float.chat_desc_text_font_size'))
|
||
.height(20)
|
||
.maxLines(1)
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.ellipsisMode(EllipsisMode.END)
|
||
.margin({ bottom: 4 })
|
||
.onClick((event) => this.onItemClick(event))
|
||
} else {
|
||
// Text(getContext().resourceManager.getStringSync($r('app.string.chat_reply_not_exist').id))
|
||
// .fontColor($r('app.color.color_chat_desc'))
|
||
// .fontSize($r('app.float.chat_desc_text_font_size'))
|
||
// .height(20)
|
||
// .maxLines(1)
|
||
// .ellipsisMode(EllipsisMode.END)
|
||
// .margin({ bottom: 4 })
|
||
}
|
||
|
||
}
|
||
Column() {
|
||
if (this.message.isRevokeMsg) {
|
||
Span(this.message.message.text)
|
||
if (this.message.revokeEditMsg) {
|
||
Text($r('app.string.chat_msg_undo_edit_tips'))
|
||
.fontColor($r('app.color.color_chat_send'))
|
||
.onClick((event) => {
|
||
this.onRevokeEditClick(event)
|
||
})
|
||
}
|
||
} else {
|
||
ForEach(parseMessageText(this.message.message.text?.trimStart()?.trimEnd()), (item: NEEmojiParseResult) => {
|
||
if (item.text) {
|
||
ForEach(getAitNodes(item.startIndex, item.text, this.message.message.serverExtension),
|
||
(node: ChatAitNode) => {
|
||
if (node.segment) {
|
||
Span(node.text)
|
||
.fontSize($r('app.float.chat_message_text_font_size'))
|
||
.textCase(TextCase.Normal)
|
||
.fontColor('#337EFF')
|
||
} else {
|
||
Markdown({
|
||
content: node.text,
|
||
lineSpace: 0,
|
||
textLineSpace: 6,
|
||
fontStyle: {
|
||
fontColor: $r('app.color.color_chat_title'),
|
||
fontSize: $r('app.float.chat_message_text_font_size')
|
||
},
|
||
})
|
||
}
|
||
})
|
||
|
||
} else if (item.emoji) {
|
||
ImageSpan($rawfile(`emoji/${item.emoji.file}`))
|
||
.width(18)
|
||
.height(18)
|
||
.objectFit(ImageFit.Fill)
|
||
.verticalAlign(ImageSpanAlignment.CENTER)
|
||
}
|
||
})
|
||
}
|
||
}
|
||
}.alignItems(HorizontalAlign.Start)
|
||
.padding({
|
||
left: 12,
|
||
top: 12,
|
||
bottom: 12,
|
||
right: 12
|
||
})
|
||
}
|
||
}
|
||
|
||
|
||
@ComponentV2
|
||
export struct textBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
@BuilderParam
|
||
chatInfo: ChatInfo | undefined
|
||
|
||
private onItemClick(event: ClickEvent) {
|
||
this.onMessageClick?.onReplyClick?.(event, this.message.replyMsg)
|
||
}
|
||
|
||
private onRevokeEditClick(event: ClickEvent) {
|
||
this.onMessageClick?.onRevokeEditClick?.(event, this.message)
|
||
|
||
}
|
||
|
||
build() {
|
||
Column() {
|
||
if (!this.message.isRevokeMsg && this.message.isReplyMsg) {
|
||
if (this.message.replyMsg) {
|
||
Text() {
|
||
if (this.chatInfo) {
|
||
Span(' | ' + parseReplyMessageUserInfo(this.message.replyMsg, this.chatInfo))
|
||
.fontSize($r('app.float.chat_desc_text_font_size'))
|
||
.textCase(TextCase.Normal)
|
||
.fontColor($r('app.color.color_chat_desc'))
|
||
}
|
||
ForEach(sliceMessageText(parseMessageText(getReplyMessageText(this.message.replyMsg)), 30),
|
||
(item: NEEmojiParseResult) => {
|
||
if (item.text) {
|
||
Span(item.text)
|
||
.fontSize($r('app.float.chat_desc_text_font_size'))
|
||
.textCase(TextCase.Normal)
|
||
.fontColor($r('app.color.color_chat_desc'))
|
||
} else if (item.emoji) {
|
||
ImageSpan($rawfile(`emoji/${item.emoji.file}`)).width('16')
|
||
.height('16')
|
||
.objectFit(ImageFit.Fill)
|
||
.verticalAlign(ImageSpanAlignment.CENTER)
|
||
}
|
||
})
|
||
}
|
||
.fontColor($r('app.color.color_chat_desc'))
|
||
.fontSize($r('app.float.chat_desc_text_font_size'))
|
||
.height(20)
|
||
.maxLines(1)
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.ellipsisMode(EllipsisMode.END)
|
||
.margin({ bottom: 4 })
|
||
.onClick((event) => this.onItemClick(event))
|
||
} else {
|
||
// Text(getContext().resourceManager.getStringSync($r('app.string.chat_reply_not_exist').id))
|
||
// .fontColor($r('app.color.color_chat_desc'))
|
||
// .fontSize($r('app.float.chat_desc_text_font_size'))
|
||
// .height(20)
|
||
// .maxLines(1)
|
||
// .ellipsisMode(EllipsisMode.END)
|
||
// .margin({ bottom: 4 })
|
||
//去掉消息已撤回
|
||
}
|
||
|
||
}
|
||
Text() {
|
||
if (this.message.isRevokeMsg) {
|
||
Span(this.message.message.text)
|
||
if (this.message.revokeEditMsg) {
|
||
Span($r('app.string.chat_msg_undo_edit_tips'))
|
||
.fontColor($r('app.color.color_chat_send'))
|
||
.onClick((event) => {
|
||
this.onRevokeEditClick(event)
|
||
})
|
||
}
|
||
} else {
|
||
ForEach(parseMessageText(this.message.message.text?.trimStart()?.trimEnd()), (item: NEEmojiParseResult) => {
|
||
if (item.text) {
|
||
ForEach(getAitNodes(item.startIndex, item.text, this.message.message.serverExtension),
|
||
(node: ChatAitNode) => {
|
||
if (node.segment) {
|
||
Span(node.text)
|
||
.fontSize($r('app.float.chat_message_text_font_size'))
|
||
.textCase(TextCase.Normal)
|
||
.fontColor('#337EFF')
|
||
} else {
|
||
Span(node.text)
|
||
.fontSize($r('app.float.chat_message_text_font_size'))
|
||
.textCase(TextCase.Normal)
|
||
.fontColor($r('app.color.color_chat_title'))
|
||
}
|
||
})
|
||
|
||
} else if (item.emoji) {
|
||
ImageSpan($rawfile(`emoji/${item.emoji.file}`))
|
||
.width(18)
|
||
.height(18)
|
||
.objectFit(ImageFit.Fill)
|
||
.verticalAlign(ImageSpanAlignment.CENTER)
|
||
}
|
||
})
|
||
}
|
||
}
|
||
.lineHeight(20)
|
||
.fontSize($r('app.float.chat_subtitle_text_font_size'))
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.ellipsisMode(EllipsisMode.END)
|
||
}.alignItems(HorizontalAlign.Start)
|
||
.padding({
|
||
left: 12,
|
||
top: 12,
|
||
bottom: 12,
|
||
right: 12
|
||
})
|
||
}
|
||
}
|
||
|
||
|
||
@ComponentV2
|
||
export struct pinTextBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
|
||
build() {
|
||
Column() {
|
||
Text() {
|
||
ForEach(parseMessageText(this.message.message.text?.trimStart()?.trimEnd()), (item: NEEmojiParseResult) => {
|
||
if (item.text) {
|
||
Span(item.text)
|
||
.fontSize($r('app.float.chat_message_text_font_size'))
|
||
.textCase(TextCase.Normal)
|
||
.fontColor($r('app.color.color_chat_title'))
|
||
} else if (item.emoji) {
|
||
ImageSpan($rawfile(`emoji/${item.emoji.file}`)).width('18')
|
||
.height('18')
|
||
.objectFit(ImageFit.Fill)
|
||
.verticalAlign(ImageSpanAlignment.CENTER)
|
||
}
|
||
})
|
||
}
|
||
.fontColor($r('app.color.color_chat_title'))
|
||
.lineHeight(20)
|
||
.fontSize($r('app.float.chat_subtitle_text_font_size'))
|
||
.maxLines(3)
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.ellipsisMode(EllipsisMode.END)
|
||
}
|
||
}
|
||
}
|
||
|
||
@ComponentV2
|
||
export struct imageBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
@Local thumbUrl?: string
|
||
@Local url?: string
|
||
|
||
build() {
|
||
Column() {
|
||
Image(this.thumbUrl ?? this.url)
|
||
.objectFit(ImageFit.Cover)
|
||
.width(getImageWidth(this.message))
|
||
.height(getImageHeight(this.message))
|
||
.borderRadius(8)
|
||
.gesture(LongPressGesture().onAction((event: GestureEvent) => {
|
||
this.onMessageClick?.onItemLongClick?.(event, this.message)
|
||
}), GestureMask.IgnoreInternal)
|
||
}
|
||
}
|
||
|
||
aboutToAppear(): void {
|
||
this.url = this.message.getImageUrl()
|
||
this.message.getImageThumbUrl().then((thumbUrl) => {
|
||
this.thumbUrl = thumbUrl
|
||
})
|
||
}
|
||
}
|
||
|
||
@ComponentV2
|
||
export struct videoBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
@Local videoMessageThumbnail?: image.PixelMap
|
||
|
||
showLoading() {
|
||
if ((this.message.message.attachment as V2NIMMessageFileAttachment).path === undefined) {
|
||
if (this.message.downloadProgress > 0) {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|
||
|
||
async aboutToAppear(): Promise<void> {
|
||
this.videoMessageThumbnail = await getVideoMessageThumbnail(this.message)
|
||
}
|
||
|
||
build() {
|
||
Stack() {
|
||
Image(this.videoMessageThumbnail ?? getVideoMessageUrl(this.message)).objectFit(ImageFit.Auto)
|
||
.width(getImageWidth(this.message)).height(getImageHeight(this.message))
|
||
.borderRadius(8)
|
||
Image($r('app.media.ic_chat_message_video')).objectFit(ImageFit.Auto)
|
||
.width(60).height(60)
|
||
.visibility(!this.showLoading() ? Visibility.Visible : Visibility.Hidden)
|
||
|
||
Row() {
|
||
Column()
|
||
.width(3)
|
||
.height(18)
|
||
.backgroundColor(Color.White)
|
||
.borderRadius(3)
|
||
Column()
|
||
.width(3)
|
||
.height(18)
|
||
.backgroundColor(Color.White)
|
||
.borderRadius(3)
|
||
.margin({
|
||
left: 6
|
||
})
|
||
}
|
||
.width(12)
|
||
.height(18)
|
||
.backgroundColor(Color.Transparent)
|
||
.visibility(this.showLoading() ? Visibility.Visible : Visibility.Hidden)
|
||
|
||
Progress({ value: 0, total: 100, type: ProgressType.Ring })
|
||
.width(42)
|
||
.height(42)
|
||
.value(this.message.downloadProgress)
|
||
.color(Color.White)// 进度条前景色为灰色
|
||
.style({ strokeWidth: 3 })// 设置strokeWidth进度条宽度为15.0vp
|
||
.visibility(this.showLoading() ? Visibility.Visible : Visibility.Hidden)
|
||
}.gesture(LongPressGesture().onAction((event: GestureEvent) => {
|
||
this.onMessageClick?.onItemLongClick?.(event, this.message)
|
||
}), GestureMask.IgnoreInternal)
|
||
}
|
||
}
|
||
|
||
@ComponentV2
|
||
export struct callBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
|
||
build() {
|
||
Row() {
|
||
if (this.message.isReceiveMsg) {
|
||
Image(getCallMessageIcon(this.message)).width(24).height(24).align(Alignment.Start)
|
||
Text(getCallMessageText(this.message)).lineHeight(20).margin({ left: 6 })
|
||
} else {
|
||
Text(getCallMessageText(this.message)).lineHeight(20)
|
||
.fontSize($r('app.float.chat_subtitle_text_font_size'))
|
||
.fontColor($r('app.color.color_chat_title'))
|
||
Image(getCallMessageIcon(this.message)).width(24).height(24).align(Alignment.Start).margin({ left: 6 })
|
||
}
|
||
}
|
||
.padding({
|
||
left: 12,
|
||
top: 12,
|
||
bottom: 12,
|
||
right: 12
|
||
})
|
||
}
|
||
}
|
||
|
||
|
||
@ComponentV2
|
||
export struct fileBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
|
||
build() {
|
||
Row() {
|
||
Stack({}) {
|
||
Image(getFileMessageIcon(this.message))
|
||
.objectFit(ImageFit.Auto)
|
||
.width(35)
|
||
.height(35)
|
||
.margin({ left: 12, top: 12, bottom: 12 })
|
||
Column()
|
||
.width(35)
|
||
.height(35)
|
||
.margin({ left: 12, top: 12, bottom: 12 })
|
||
.backgroundColor($r('app.color.color_chat_converse_bg'))
|
||
.opacity(0.8)
|
||
.borderRadius(6)
|
||
.visibility(this.message.downloadProgress >= 0 ? Visibility.Visible : Visibility.Hidden)
|
||
Progress({ value: 0, total: 100, type: ProgressType.Ring })
|
||
.width(20)
|
||
.height(20)
|
||
.value(this.message.downloadProgress)
|
||
.margin({ left: 16, top: 16, bottom: 12 })
|
||
.color(Color.White)// 进度条前景色为灰色
|
||
.style({ strokeWidth: 3 })// 设置strokeWidth进度条宽度为15.0vp
|
||
.visibility(this.message.downloadProgress >= 0 ? Visibility.Visible : Visibility.Hidden)
|
||
}
|
||
|
||
Column() {
|
||
Text(getFileMessageName(this.message))
|
||
.fontColor($r('app.color.color_chat_title'))
|
||
.fontSize($r('app.float.chat_desc_text_font_size'))
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.textAlign(TextAlign.Start)
|
||
.width('100%')
|
||
.height(20)
|
||
.maxLines(1)
|
||
.ellipsisMode(EllipsisMode.END)
|
||
Text(getFileMessageSize(this.message))
|
||
.fontColor('#666666')
|
||
.fontSize(10)
|
||
.width('100%')
|
||
.textAlign(TextAlign.Start)
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.maxLines(1)
|
||
.margin({ top: 2 })
|
||
}.padding({ left: 12, right: 12 }).width('70%').align(Alignment.Start)
|
||
}
|
||
}
|
||
}
|
||
|
||
@ComponentV2
|
||
export struct locationBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
@Local imagePex: image.PixelMap | undefined
|
||
|
||
aboutToAppear(): void {
|
||
if (this.message) {
|
||
|
||
let attachment = this.message.message.attachment as V2NIMMessageLocationAttachment;
|
||
let staticMapMarker: staticMap.StaticMapMarker = {
|
||
location: {
|
||
latitude: attachment.latitude,
|
||
longitude: attachment.longitude
|
||
},
|
||
defaultIconSize: staticMap.IconSize.SMALL
|
||
};
|
||
let staticMapOptions: staticMap.StaticMapOptions = {
|
||
location: {
|
||
latitude: attachment.latitude,
|
||
longitude: attachment.longitude
|
||
},
|
||
zoom: 15,
|
||
imageWidth: 300,
|
||
imageHeight: 100,
|
||
markers: [staticMapMarker],
|
||
};
|
||
|
||
// 获取静态图
|
||
staticMap.getMapImage(staticMapOptions).then((value) => {
|
||
this.imagePex = value;
|
||
console.info("netease location Succeeded in getting image.");
|
||
}).catch((error: BusinessError) => {
|
||
console.info("netease location fail in getting image.", error.code, error.message);
|
||
});
|
||
}
|
||
}
|
||
|
||
build() {
|
||
Column() {
|
||
Text(this.message?.message.text)
|
||
.fontColor($r('app.color.color_chat_title'))
|
||
.fontSize($r('app.float.chat_title_text_font_size'))
|
||
.textAlign(TextAlign.Start)
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.padding({ left: 12, top: 12, right: 12 })
|
||
Text((this.message?.message.attachment as V2NIMMessageLocationAttachment).address)
|
||
.fontColor($r('app.color.color_chat_desc'))
|
||
.fontSize($r('app.float.chat_desc_text_font_size'))
|
||
.textAlign(TextAlign.Start)
|
||
.maxLines(1)
|
||
.margin({ top: 6 })
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.padding({ left: 12, right: 12 })
|
||
if (this.imagePex) {
|
||
Image(this.imagePex).width('100%').height(88).margin({ top: 8 })
|
||
} else {
|
||
Image($r('app.media.ic_chat_location_default')).width('100%').height(88).margin({ top: 8 })
|
||
}
|
||
}.alignItems(HorizontalAlign.Start)
|
||
}
|
||
}
|
||
|
||
|
||
@ComponentV2
|
||
export struct pinLocationBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
@Local imagePex: image.PixelMap | undefined
|
||
|
||
aboutToAppear(): void {
|
||
if (this.message) {
|
||
|
||
let attachment = this.message.message.attachment as V2NIMMessageLocationAttachment;
|
||
let staticMapMarker: staticMap.StaticMapMarker = {
|
||
location: {
|
||
latitude: attachment.latitude,
|
||
longitude: attachment.longitude
|
||
},
|
||
defaultIconSize: staticMap.IconSize.SMALL
|
||
};
|
||
let staticMapOptions: staticMap.StaticMapOptions = {
|
||
location: {
|
||
latitude: attachment.latitude,
|
||
longitude: attachment.longitude
|
||
},
|
||
zoom: 15,
|
||
imageWidth: 300,
|
||
imageHeight: 100,
|
||
markers: [staticMapMarker],
|
||
};
|
||
|
||
// 获取静态图
|
||
staticMap.getMapImage(staticMapOptions).then((value) => {
|
||
this.imagePex = value;
|
||
console.info("netease location Succeeded in getting image.");
|
||
}).catch((error: BusinessError) => {
|
||
console.info("netease location fail in getting image.", error.code, error.message);
|
||
});
|
||
}
|
||
}
|
||
|
||
build() {
|
||
Column() {
|
||
Text(this.message?.message.text)
|
||
.fontColor($r('app.color.color_chat_title'))
|
||
.fontSize($r('app.float.chat_title_text_font_size'))
|
||
.textAlign(TextAlign.Start)
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.padding({ left: 12, top: 12, right: 12 })
|
||
Text((this.message?.message.attachment as V2NIMMessageLocationAttachment).address)
|
||
.fontColor($r('app.color.color_chat_desc'))
|
||
.fontSize($r('app.float.chat_desc_text_font_size'))
|
||
.textAlign(TextAlign.Start)
|
||
.maxLines(1)
|
||
.margin({ top: 6 })
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.padding({ left: 12, right: 12 })
|
||
if (this.imagePex) {
|
||
Image(this.imagePex).width('100%').height(88).margin({ top: 8 })
|
||
} else {
|
||
Image($r('app.media.ic_chat_location_default')).width('100%').height(88).margin({ top: 8 })
|
||
}
|
||
}.alignItems(HorizontalAlign.Start)
|
||
.width('80%')
|
||
}
|
||
}
|
||
|
||
@ComponentV2
|
||
export struct unknownBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
|
||
build() {
|
||
Column() {
|
||
Text($r('app.string.chat_msg_unknown_type'))
|
||
.fontColor($r('app.color.color_chat_title'))
|
||
.lineHeight(20)
|
||
.fontSize($r('app.float.chat_subtitle_text_font_size'))
|
||
}
|
||
.padding({
|
||
left: 12,
|
||
top: 12,
|
||
bottom: 12,
|
||
right: 12
|
||
})
|
||
}
|
||
}
|
||
|
||
@ComponentV2
|
||
export struct mergedMessageBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
mergedAttachment: MergedMessageAttachment | undefined
|
||
|
||
aboutToAppear(): void {
|
||
if (this.message) {
|
||
this.mergedAttachment = this.message.customAttachment as MergedMessageAttachment
|
||
}
|
||
}
|
||
|
||
build() {
|
||
Column() {
|
||
if (this.mergedAttachment) {
|
||
Text($r('app.string.chat_merged_message_title', this.mergedAttachment.sessionName))
|
||
.fontColor($r('app.color.color_chat_title'))
|
||
.fontSize($r('app.float.chat_title_text_font_size'))
|
||
.height(18)
|
||
.margin({ top: 6, bottom: 4 })
|
||
.maxLines(1)
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.ellipsisMode(EllipsisMode.CENTER)
|
||
Text() {
|
||
ForEach(parseText(this.message.mergedContent), (item: NEEmojiParseResult) => {
|
||
if (item.text) {
|
||
Span(item.text)
|
||
.fontSize($r('app.float.chat_message_text_font_size'))
|
||
.textCase(TextCase.Normal)
|
||
.fontColor($r('app.color.color_chat_desc'))
|
||
|
||
} else if (item.emoji) {
|
||
ImageSpan($rawfile(`emoji/${item.emoji.file}`)).width('18')
|
||
.height('18')
|
||
.objectFit(ImageFit.Fill)
|
||
.verticalAlign(ImageSpanAlignment.CENTER)
|
||
}
|
||
})
|
||
}
|
||
.fontSize($r('app.float.chat_subtitle_text_font_size'))
|
||
.maxLines(3)
|
||
.lineHeight(20)
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.ellipsisMode(EllipsisMode.END)
|
||
.margin({ bottom: 6 })
|
||
|
||
Line().width('100%').height(1).backgroundColor($r('app.color.color_chat_divider_line'))
|
||
Text($r('app.string.chat_merged_message_desc'))
|
||
.fontColor($r('app.color.color_chat_desc'))
|
||
.fontSize($r('app.float.chat_subtitle_text_font_size'))
|
||
.height(18).margin({ top: 6, bottom: 6 })
|
||
}
|
||
}
|
||
.margin({
|
||
left: 4,
|
||
top: 4,
|
||
bottom: 4,
|
||
right: 4
|
||
})
|
||
.padding({ left: 12, right: 6 })
|
||
.backgroundColor($r('app.color.color_chat_page_bg'))
|
||
.borderRadius(12)
|
||
.alignItems(HorizontalAlign.Start)
|
||
}
|
||
|
||
}
|
||
|
||
|
||
@ComponentV2
|
||
export struct customBuilder {
|
||
@BuilderParam
|
||
message: NIMMessageInfo
|
||
@BuilderParam
|
||
onMessageClick: MessageItemClick | undefined
|
||
@Local photoUrl:ResourceStr=$r('app.media.mine_logo')
|
||
@Local title:string=''
|
||
@Local content:string=''
|
||
@Local customType:string=''
|
||
@Local customUrl:string=''
|
||
aboutToAppear(): void {
|
||
if (this.message) {
|
||
//
|
||
let attachment = this.message.message.attachment as V2NIMMessageAttachment ;
|
||
|
||
let custom=JSON.parse(attachment.raw+'') as customAttachment
|
||
this.title=custom.gdxz_title
|
||
this.customType=custom.gdxz_type
|
||
this.customUrl=custom.gdxz_url
|
||
if(BasicConstant.CouTeach==custom.gdxz_type)
|
||
{
|
||
this.content='点击查看问题详情'
|
||
this.photoUrl=$r('app.media.icon_chatting_file')
|
||
}
|
||
else if(BasicConstant.VisitTeach==custom.gdxz_type)
|
||
{
|
||
this.content='肝胆相照®肝胆病在线公共服务平台'
|
||
this.photoUrl=$r('app.media.mine_logo')
|
||
}
|
||
else {
|
||
if(custom.gdxz_content==null||custom.gdxz_content.trim()=='')
|
||
{
|
||
this.content='肝胆相照®肝胆病在线公共服务平台'
|
||
}
|
||
else
|
||
{
|
||
this.content=custom.gdxz_content
|
||
}
|
||
if(custom.gdxz_title!=null&&custom.gdxz_title.includes("互联网医院"))
|
||
{
|
||
this.photoUrl=custom.gdxz_img
|
||
|
||
}
|
||
else
|
||
{
|
||
this.photoUrl=$r('app.media.mine_logo')
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
build() {
|
||
Column() {
|
||
Text(this.title)
|
||
.fontColor($r('app.color.color_chat_title'))
|
||
.fontSize($r('app.float.chat_message_text_font_size'))
|
||
.textAlign(TextAlign.Start)
|
||
.maxLines(2)
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.padding({ left: 12, top: 12, right: 12 })
|
||
Row()
|
||
{
|
||
Text(this.content)
|
||
.fontColor($r('app.color.color_chat_sub_title'))
|
||
.fontSize($r('app.float.chat_desc_text_font_size'))
|
||
.textAlign(TextAlign.Start)
|
||
.maxLines(2)
|
||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
.padding({ left: 12, top: 12, right: 12 })
|
||
.layoutWeight(1)
|
||
|
||
Image(this.photoUrl).width(57)
|
||
.height(57)
|
||
.margin({ bottom: 12, top: 12, right: 12 })
|
||
}
|
||
.alignItems(VerticalAlign.Top)
|
||
// Text((this.message?.message.attachment as V2NIMMessageLocationAttachment).address)
|
||
// .fontColor($r('app.color.color_chat_desc'))
|
||
// .fontSize($r('app.float.chat_desc_text_font_size'))
|
||
// .textAlign(TextAlign.Start)
|
||
// .maxLines(1)
|
||
// .margin({ top: 6 })
|
||
// .textOverflow({ overflow: TextOverflow.Ellipsis })
|
||
// .padding({ left: 12, right: 12 })
|
||
// if (this.imagePex) {
|
||
// Image(this.imagePex).width('100%').height(88).margin({ top: 8 })
|
||
// } else {
|
||
// Image($r('app.media.ic_chat_location_default')).width('100%').height(88).margin({ top: 8 })
|
||
// }
|
||
}.alignItems(HorizontalAlign.Start)
|
||
.onClick(()=>{
|
||
if(BasicConstant.CouTeach==this.customType)
|
||
{
|
||
// Intent intent = new Intent(UIUtils.getContext(), PublicServiceDetailsActivity.class);
|
||
// intent.putExtra("consultUuid", teachAttachment.getMessigeid());
|
||
// intent.putExtra("isCloseAnswer", true);
|
||
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
|
||
// UIUtils.getContext().startActivity(intent);
|
||
}
|
||
else if(this.title!=null&&this.title.includes("互联网医院"))
|
||
{
|
||
// IWXAPI api = WXAPIFactory.createWXAPI(getActivity(), Constant.WeId);
|
||
// WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
|
||
// req.userName = "gh_9cd2fd72eb57"; // 填小程序原始id
|
||
// req.path = "/Pages/yishi/index/index"; //拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。
|
||
// // req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_PREVIEW;// 可选打开 开发版,体验版和正式版
|
||
// api.sendReq(req);
|
||
}
|
||
else if (this.customUrl!=null)
|
||
{
|
||
|
||
if (this.customUrl.includes("video")){
|
||
// intent = new Intent(UIUtils.getContext(), VideoDetilActivity.class);
|
||
// intent.putExtra("uuid", teachAttachment.getMessigeid());
|
||
|
||
}else {
|
||
// intent = new Intent(UIUtils.getContext(), NewsDetailActivity.class);
|
||
|
||
}
|
||
|
||
if (this.customUrl.includes("outpatient_details")
|
||
||this.customUrl.includes("wxPatient/index.htm#/outPatient")){
|
||
// intent.putExtra("title", "门诊详情");
|
||
ToWeb(this.customUrl,'门诊详情')
|
||
}else if(this.customUrl.includes(BasicConstant.getNewWa))
|
||
{
|
||
ToWeb(this.customUrl,'纽娃复合营养素固体饮料')
|
||
// intent.putExtra("title", UIUtils.getContext().getResources().getStringArray(R.array.chat_menu_shop)[0]);
|
||
// intent.putExtra("flag", 1);
|
||
}
|
||
else
|
||
{
|
||
// intent.putExtra("newsTitle", teachAttachment.getTitle()+"");
|
||
// intent.putExtra("kepuuuid", teachAttachment.getMessigeid());
|
||
// intent.putExtra("title", "患教详情");
|
||
// intent.putExtra("need_inside_share", "no");
|
||
}
|
||
if(this.customUrl.includes("dcsvip1imapp.cloopen.net:8888"))
|
||
{
|
||
// intent.putExtra("url",
|
||
// ((TeachAttachment) message.getAttachment()).getUrl().split("http://dcsvip1imapp.cloopen.net:8888")[1]);
|
||
}
|
||
else
|
||
{
|
||
// intent.putExtra("url", teachAttachment.getUrl());
|
||
}
|
||
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
|
||
// UIUtils.getContext().startActivity(intent);
|
||
}
|
||
})
|
||
.width('80%')
|
||
}
|
||
}
|
||
function ToWeb(u:string,t:string)
|
||
{
|
||
let paramsInfo: DataWebModel = {
|
||
url:u ,
|
||
title:t
|
||
|
||
};
|
||
router.pushUrl({
|
||
url: 'pages/WebView/WebPage', // 目标url
|
||
params: paramsInfo // 添加params属性,传递自定义参数
|
||
})
|
||
}
|
||
|
||
export interface customAttachment
|
||
{
|
||
|
||
gdxz_title:string;//标题
|
||
gdxz_url:string;//内容url
|
||
gdxz_content:string;//内容
|
||
gdxz_id:string;//id
|
||
gdxz_img:string;//照片
|
||
gdxz_type:string;//类型
|
||
gdxz_ext_data:string;//备用字段,json字符串
|
||
} |