扩展消息部分代码提交

This commit is contained in:
XiuYun CHEN 2025-07-14 17:37:45 +08:00
parent cf7aa93d6e
commit 1121cc3f20
15 changed files with 200 additions and 73 deletions

View File

@ -75,7 +75,7 @@ import { TextMessageDetailDialog } from '../view/TextMessageDetailDialog';
import { TeachDialog } from '../view/TeachDialog';
import { NewWaDialog } from '../view/NewWaDialog';
import { PerfactInputSheet } from '@itcast/basic/src/main/ets/Views/PerfactInputSheet'
import { hdHttp, HdResponse,BasicConstant, authStore} from '@itcast/basic'
import { hdHttp, HdResponse,BasicConstant, authStore, preferenceStore, ChatParam} from '@itcast/basic'
import { HashMap } from '@kit.ArkTS';
import { customAttachment } from '../view/MessageComponentBuilder'
@ -84,6 +84,8 @@ export struct ChatP2PPage {
pathStack: NavPathStack = new NavPathStack()
sessionId=''//患者的云信id
patientUuid=''//患者uuid
@Local chat_state:string=''
@Local gdxz_sessionType:string= preferenceStore.getItemString('gdxz_sessionType')
@Local statusBarHeight:number=0
@Local havestopout:boolean=false;//是否有出诊公告
@Local chatUserInfo: ChatUserInfo = new ChatUserInfo();
@ -420,6 +422,11 @@ export struct ChatP2PPage {
}
aboutToAppear() {
if(this.chat_state=='3')
{
this.bottomHeight==0
}
NEEmojiManager.instance.setup();
DeviceUtils.rootDirPath = getContext(this).filesDir
this.operationMoreDataList = setupMoreOperationData()
@ -574,8 +581,8 @@ export struct ChatP2PPage {
NavDestination() {
NavigationBackBuilder({
title:this.showName ,
rightButtonIcon: this.showMultiSelect ? undefined : $r('app.media.ic_public_more_dot'),
rightButtonTitle: this.showMultiSelect ? $r('app.string.chat_msg_dialog_cancel') : undefined,
rightButtonIcon: this.gdxz_sessionType==BasicConstant.general ? $r('app.media.more') :undefined,
rightButtonTitle: this.gdxz_sessionType==BasicConstant.consult && this.chat_state!='3'? '关闭会话' : undefined,
top:this.statusBarHeight,
rightButtonAction: () => {
this.goToSettingPage(this.pathStack)
@ -776,7 +783,7 @@ export struct ChatP2PPage {
top: { anchor: "chatPageListView", align: VerticalAlign.Bottom },
})
if (this.hideInput === false && !this.showMultiSelect) {
if (this.hideInput === false && !this.showMultiSelect&&this.chat_state!='3') {
NEChatInputView({
controller: this.controller,
placeHolder: (this.chatUserInfo.conversationName ?? '').length > 15 ?
@ -1087,9 +1094,11 @@ export struct ChatP2PPage {
.hideTitleBar(true)
.onReady((context: NavDestinationContext) => {
this.pathStack = context.pathStack
let param = this.pathStack.getParamByName("ChatP2PPage") as string[];
let param = this.pathStack.getParamByName("ChatP2PPage") as ChatParam[];
if (param.length > 0) {
this.conversationId = param[0];
this.conversationId = param[0].conversationId;
this.showName= param[0].name+'';
this.chat_state=param[0].chat_state
this.loadChatData();
} else {
this.pathStack.removeByName("ChatP2PPage")

View File

@ -36,6 +36,7 @@ import {
V2NIMMessageFileAttachment,
V2NIMMessagePinNotification,
V2NIMMessagePinState,
V2NIMMessagePushConfig,
V2NIMMessageRevokeNotification,
V2NIMMessageSendingState,
V2NIMMessageType,
@ -57,10 +58,10 @@ import { ChatKitConfig } from '../ChatKitConfig';
import { sceneMap } from '@kit.MapKit';
import { clearForwardAtMark, createForwardMessageListFileDetail, sendMessageFailedTips } from '../common/MessageHelper';
import { instanceToPlain } from 'class-transformer';
import { NECommonUtils } from '@nimkit/common';
import { NECommonUtils, UserUtils } from '@nimkit/common';
import { HashMap, JSON } from '@kit.ArkTS';
import { assign } from '@nimsdk/vendor';
import { BasicConstant, ChatExtModel } from '@itcast/basic';
import { BasicConstant, ChatExtModel, preferenceStore } from '@itcast/basic';
@ObservedV2
export class ChatBaseViewModel {
@ -654,13 +655,14 @@ export class ChatBaseViewModel {
}
// 消息发送之前调用,用于配置消息通用参数
beforeSendMessage(msg: V2NIMMessage): V2NIMMessage {
beforeSendMessage(msg: V2NIMMessage){
// if (ChatKitConfig.messageReadState) {
// let msgConfig: V2NIMMessageConfig = {
// readReceiptEnabled: false
// }
// msg.messageConfig = msgConfig
// }
return msg
}
@ -689,12 +691,7 @@ export class ChatBaseViewModel {
// let extension = JSON.stringify(instanceToPlain(extensionMap))
// message.serverExtension = extension
// }
let extension:ChatExtModel= {
gdxz_sessionType: '',
gdxz_consult_uuid: '',
gdxz_nickName: ''
}
message.serverExtension =JSON.stringify(extension)
//设置推送
@ -911,6 +908,19 @@ export class ChatBaseViewModel {
* @param progress 消息发送进度
*/
async sendMessage(msg: V2NIMMessage, params?: V2NIMSendMessageParams, progress?: (percentage: number) => void) {
let extension:ChatExtModel= {
gdxz_sessionType: preferenceStore.getItemString('gdxz_sessionType'),
gdxz_consult_uuid: preferenceStore.getItemString('gdxz_consult_uuid')+'',
gdxz_nickName:await UserUtils.getAvatarName(ChatKitClient.nim.conversationIdUtil.parseConversationTargetId(this.conversationId),'')
}
msg.serverExtension =JSON.stringify(extension)
// Map<String,Integer> p=new HashMap<>();
// p.put("classification",1);
// payload.put("vivoField",p);//vivo推送
// payload.put("apns-collapse-id", "321");//ios需要
// payload.put("apns-from-id", NimUIKit.getAccount());//ios需要
// msg.pushConfig = {} as V2NIMMessagePushConfig
// msg.pushConfig.pushPayload=''
ChatRepo.sendMessage(this.beforeSendMessage(msg), this.conversationId!, params, progress)
.catch((err: BusinessError) => {
console.error("net ease send message error", err.code, err.message);

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

View File

@ -53,8 +53,11 @@ export function NavigationBackBuilder(params?: NavigationBackBuilderParams) {
} else {
Image($r('app.media.top_back'))
.margin({ left: 20 })
.width(24)
.width(65)
.height(24)
.padding({
right:41
})
// .padding({
// left: 8,
// right: 8,
@ -69,9 +72,13 @@ export function NavigationBackBuilder(params?: NavigationBackBuilderParams) {
// .fontWeight(FontWeight.Bold)
.height(18)
.width('100%')
.maxLines(1)
.ellipsisMode(EllipsisMode.END)
.margin({
left: params?.buttonTextWidth ? (params.buttonTextWidth - 32 + 8) : 8,
right: (params?.rightButtonTitle || params?.rightButtonIcon) ? 8 : 60
left:5,
right:5
// left: params?.buttonTextWidth ? (params.buttonTextWidth - 32 + 8) : 8,
// right: (params?.rightButtonTitle || params?.rightButtonIcon) ? 8 : 60
})
.fontColor('#8D2316')
.layoutWeight(1)
@ -81,28 +88,43 @@ export function NavigationBackBuilder(params?: NavigationBackBuilderParams) {
if (params?.rightButtonTitle) {
Text(params?.rightButtonTitle)
.fontSize(16)
.fontColor(params?.rightButtonColor)
.width(params?.buttonTextWidth ?? 32)
.height(18)
.margin({ right: 20 })
.fontSize(14)
.fontColor(params?.rightButtonColor??Color.White)
.width(params?.buttonTextWidth ?? 80)
.height(35)
.textAlign(TextAlign.Center)
// .padding({
// top:10,bottom:10,left:18,right:18
// })
.borderRadius(4)
// .height(18)
.backgroundColor($r('app.color.top_title'))
.margin({ right: 5 })
.onClick(params?.rightButtonAction)
.textAlign(TextAlign.End)
}
if (params?.rightButtonIcon) {
else if (params?.rightButtonIcon) {
Image(params?.rightButtonIcon)
.width(32)
.height(32)
// .width(36)
.width(65)
.height(4)
.objectFit(ImageFit.Contain)
.padding({
left: 3,
right: 3,
top: 3,
bottom: 3
left: 47,
// right: 3,
// top: 3,
// bottom: 3
})
.margin({ right: 20 })
.onClick(params?.rightButtonAction)
}
else
{
Text('')
.width(85)
.height(24)
}
}
.height(55)
.alignSelf(ItemAlign.Start)

View File

@ -87,4 +87,4 @@ export { ChangePhotoGrids } from './src/main/ets/components/ChangePhotoGrids'
export { InputPopWindow } from './src/main/ets/Views/InputPopWindow'
export { ChatExtModel } from './src/main/ets/models/ChatExtModel'
export { ChatExtModel,ChatParam } from './src/main/ets/models/ChatExtModel'

View File

@ -101,5 +101,9 @@ export class BasicConstant {
static readonly CouTeach="[公益咨询]";
static readonly Shopping="[肝胆商城]";
static readonly Hostipal="[互联网医院]";
//聊天类型普通聊天与公益咨询
static readonly general = "general";
static readonly consult = "consult";
}

View File

@ -5,4 +5,12 @@ export interface ChatExtModel{
gdxz_consult_uuid:string,//公益咨询uuid
gdxz_nickName:string//患者备注姓名
}
export interface ChatParam extends ChatExtModel{
name:string,//患者姓名
conversationId:string,//最近会话id
chat_state:string//公益咨询状态
}

View File

@ -1,6 +1,8 @@
import { ConsulList } from '../model/ConsulModel'
import { router } from '@kit.ArkUI'
import { BasicConstant, ChatParam, preferenceStore } from '@itcast/basic';
import { ChatKitClient } from '@nimkit/chatkit';
@Preview
@ -12,55 +14,99 @@ export struct ItemCompPublic {
aboutToAppear(): void {
}
pathStack: NavPathStack = new NavPathStack()
build() {
Column() {
Row()
{
Text(this.item.state==0?$r('app.string.cancellation'):this.item.realName).fontSize(19).fontColor($r('app.color.top_title')).layoutWeight(1)
Text(this.item.createDate?this.item.createDate.length>16?this.item.createDate.substring(1,16):this.item.createDate:'')
.fontSize(15).fontColor($r('app.color.top_title')).padding({left:5})
Text('').width(11).height(11).backgroundColor('#ffff3e3e').borderRadius(20).margin({top:-20})
.visibility(this.isHistory?Visibility.Visible:Visibility.None)
}
Column() {
Row() {
Text(this.item.state == 0 ? $r('app.string.cancellation') : this.item.realName)
.fontSize(19)
.fontColor($r('app.color.top_title'))
.layoutWeight(1)
Text(this.item.createDate ?
this.item.createDate.length > 16 ? this.item.createDate.substring(1, 16) : this.item.createDate : '')
.fontSize(15).fontColor($r('app.color.top_title')).padding({ left: 5 })
Text('')
.width(11)
.height(11)
.backgroundColor('#ffff3e3e')
.borderRadius(20)
.margin({ top: -20 })
.visibility(this.isHistory ? Visibility.Visible : Visibility.None)
}
Text(this.item.content)
.fontSize(14).fontColor($r('app.color.common_gray_03')).padding(9).margin({top:10})
.backgroundColor($r('app.color.f6f6f6')).borderRadius(8)
.fontSize(14)
.fontColor($r('app.color.common_gray_03'))
.padding(9)
.margin({ top: 10 })
.backgroundColor($r('app.color.f6f6f6'))
.borderRadius(8)
.width('100%')
.maxLines(2)
.textOverflow({ overflow: TextOverflow.Ellipsis })
Row()
{
Text('问题详情').fontSize(11).backgroundColor($r('app.color.top_title')).fontColor(Color.White)
.width(63).height(25).borderRadius(17).textAlign(TextAlign.Center)
Row() {
Text('问题详情')
.fontSize(11)
.backgroundColor($r('app.color.top_title'))
.fontColor(Color.White)
.width(63)
.height(25)
.borderRadius(17)
.textAlign(TextAlign.Center)
.onClick(() => {
router.pushUrl({
url: 'pages/Netease/ConsultationDetailPage',
params: { uuid: this.item.uuid,isHistory:this.isHistory+''}
params: { uuid: this.item.uuid, isHistory: this.isHistory + '' }
});
})
Text(this.item.diseaseName.includes("甲、乙、丙、丁")?'肝炎':this.item.diseaseName).fontSize(11).borderColor($r('app.color.top_title')).fontColor($r('app.color.top_title'))
.width(63).height(25).borderRadius(17).borderWidth(1).textAlign(TextAlign.Center).margin({left:10})
Text(this.item.diseaseName.includes("甲、乙、丙、丁") ? '肝炎' : this.item.diseaseName)
.fontSize(11)
.borderColor($r('app.color.top_title'))
.fontColor($r('app.color.top_title'))
.width(63)
.height(25)
.borderRadius(17)
.borderWidth(1)
.textAlign(TextAlign.Center)
.margin({ left: 10 })
}.alignSelf(ItemAlign.Start)
.margin({top:10})
.margin({ top: 10 })
}
.width('100%')
.padding(10)
.onClick(() => {
router.pushUrl({
url: 'pages/Netease/ConsultationDetailPage',
params: { uuid: this.item.uuid,isHistory:this.isHistory+''}
});
if(this.isHistory)
{
preferenceStore.setItemString('gdxz_consult_uuid', this.item.uuid)
preferenceStore.setItemString('gdxz_sessionType', BasicConstant.consult)
this.pathStack.pushPath({
name: "ChatP2PPage",
param: {
conversationId: ChatKitClient.nim.conversationIdUtil.p2pConversationId(this.item.patientUuid.toString()
.toLowerCase()),
name: this.item.realName,
chat_state:this.item.state+''
} as ChatParam
})
}
else
{
router.pushUrl({
url: 'pages/Netease/ConsultationDetailPage',
params: { uuid: this.item.uuid,isHistory:this.isHistory+''}
});
}
})
}
}

View File

@ -9,7 +9,7 @@ import HashMap from '@ohos.util.HashMap';
@Component
export struct ListCompPublic {
pathStack: NavPathStack = new NavPathStack()
@State isEmptyViewVisible: boolean = false; // 控制显隐的状态变量
@Prop
@Watch('onUpdate')
@ -207,7 +207,7 @@ export struct ListCompPublic {
{
ForEach(this.list, (item: ConsulList) => {
ListItem() {
ItemCompPublic({ item,isHistory:this.isHistory })
ItemCompPublic({ item,isHistory:this.isHistory,pathStack: this.pathStack })
}

View File

@ -112,6 +112,7 @@ export struct ConsultationDetailComp {
if(json.code=='1')
{
promptAction.showToast({ message: '抢答成功' })
this.addBonusPoints()
}
else
{
@ -123,6 +124,21 @@ export struct ConsultationDetailComp {
})
}
addBonusPoints() {
const hashMap: HashMap<string, string> = new HashMap();
hashMap.clear();
hashMap.set('score_type','2');
hdHttp.httpReq<string>(BasicConstant.addBonusPoints,hashMap).then(async (res: HdResponse<string>) => {
let json:Record<string,string> = JSON.parse(res+'') as Record<string,string>;
promptAction.showToast({ message: json.message })
}).catch((err: BusinessError) => {
this.dialog.close();
})
}
build() {
Column() {

View File

@ -7,14 +7,14 @@ export struct QuictDoctorComp {
@Watch('onChangeIndex')
activeIndex: number = 0
@State type: number=0
pathStack: NavPathStack = new NavPathStack()
onChangeIndex() {
}
build() {
Column() {
TabBarTopComp({activeIndex:this.activeIndex,type:this.type});
TabBarTopComp({activeIndex:this.activeIndex,type:this.type,pathStack: this.pathStack});

View File

@ -6,7 +6,7 @@ import { ManyForOneComp } from '../view/ManyForOneComp'
@Component
export struct TabBarConsultationComp {
pathStack: NavPathStack = new NavPathStack()
@StorageProp('bottomHeight')
bottomHeight: number = 0
@Link activeIndex: number
@ -42,7 +42,7 @@ export struct TabBarConsultationComp {
TabContent() {
if (index === 0)
{
QuictDoctorComp()
QuictDoctorComp({pathStack: this.pathStack})
}
else if(index === 1)
{

View File

@ -5,7 +5,7 @@ import { ListCompMany } from '../components/ListCompMany'
@Component
export struct TabBarTopComp {
pathStack: NavPathStack = new NavPathStack()
@StorageProp('bottomHeight')
bottomHeight: number = 0
@Link activeIndex: number
@ -46,7 +46,7 @@ export struct TabBarTopComp {
TabContent() {
if (this.type==0)
{
ListCompPublic({isHistory:this.isHistory})
ListCompPublic({isHistory:this.isHistory,pathStack: this.pathStack})
}
else if(this.type==1)

View File

@ -5,6 +5,7 @@
*
*/
import { BasicConstant, ChatParam, preferenceStore } from '@itcast/basic';
import { ChatKitClient, ChatRepo, NEUserWithFriend, PersonSelectParam, TeamRepo } from '@nimkit/chatkit';
import { CommonEmptyResult, CommonLongLoadingProgress, NetworkBrokenBuilder } from '@nimkit/common';
import { V2NIMConversationType, V2NIMLocalConversation } from '@nimsdk/base';
@ -90,7 +91,15 @@ export struct LocalConversationPage {
*/
goToChatPage(conversationInfo: V2NIMLocalConversation) {
if (conversationInfo?.type == V2NIMConversationType.V2NIM_CONVERSATION_TYPE_P2P) {
this.pathStack.pushPath({ name: "ChatP2PPage", param: conversationInfo.conversationId })
preferenceStore.setItemString('gdxz_consult_uuid','')
preferenceStore.setItemString('gdxz_sessionType',BasicConstant.general)
this.pathStack.pushPath({ name: "ChatP2PPage",
param: {
// gdxz_sessionType:BasicConstant.general,
conversationId:conversationInfo.conversationId
} as ChatParam
})
} else if (conversationInfo?.type == V2NIMConversationType.V2NIM_CONVERSATION_TYPE_TEAM) {
this.pathStack.pushPath({ name: "ChatTeamPage", param: conversationInfo.conversationId })
}

View File

@ -2,7 +2,7 @@ import { TabBarConsultationComp } from 'netease';
@Entry
@Component
struct PublicConsultationPage {
pathStack: NavPathStack = new NavPathStack()
@State
@Watch('onChangeIndex')
@ -22,14 +22,17 @@ struct PublicConsultationPage {
this.onChangeIndex()
}
build() {
Navigation(this.pathStack) {
Flex() {
TabBarConsultationComp({ activeIndex: this.activeIndex})
TabBarConsultationComp({ activeIndex: this.activeIndex, pathStack: this.pathStack})
}
.backgroundColor($r('app.color.white'))
// .backgroundColor(Color.Red)
// .height('100%')
// .width('100%')
}
.mode(NavigationMode.Auto)
.hideTitleBar(true)
}
}