角标,小红点,群发消息

This commit is contained in:
XiuYun CHEN
2025-08-05 17:02:15 +08:00
parent 9355959b36
commit 76b7785d84
15 changed files with 199 additions and 35 deletions
@@ -1,6 +1,6 @@
import { iconsModel } from '../model/HomeModel'
import { patientDbManager, PatientEntity } from '@itcast/basic';
import { promptAction, router } from '@kit.ArkUI';
import { HomeModel, iconsModel } from '../model/HomeModel'
import { BasicConstant, hdHttp, HdResponse, patientDbManager, PatientEntity } from '@itcast/basic';
import { promptAction, router, UIObserver, uiObserver } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';
import { pushService } from '@kit.PushKit';
@@ -9,18 +9,34 @@ import { pushService } from '@kit.PushKit';
// name:string;
// isRed:boolean;
// }
import { ChatKitClient, LocalConversationRepo } from '@nimkit/chatkit';
import { HashMap } from '@kit.ArkTS';
@Component
export struct HomeIconComp {
@Prop iconList: iconsModel[];
@State patientIcon: string = '';
@State patientName: string = '我的患者';
@State patientRed: boolean = false;
@State videoIcon: string = '';
@State videoName: string = '肝胆视频';
@State zixunIcon: string = '';
@State consultation: string = '公益咨询';
@State consultationRed: boolean = false;
@State iconListtmp:iconsModel[]=[];
listener: (info: uiObserver.RouterPageInfo) => void = (info: uiObserver.RouterPageInfo) => {
let routerInfo: uiObserver.RouterPageInfo | undefined = this.queryRouterPageInfo();
if (info.pageId == routerInfo?.pageId) {
if (info.state == uiObserver.RouterPageState.ON_PAGE_SHOW) {
this.getRedCount()
} else if (info.state == uiObserver.RouterPageState.ON_PAGE_HIDE) {
}
}
}
aboutToAppear(): void {
let uiObserver: UIObserver = this.getUIContext().getUIObserver();
uiObserver.on('routerPageUpdate', this.listener);
for (const icons of this.iconList) {
if (icons.name === '我的患者') {
this.patientIcon = icons.img;
@@ -30,19 +46,91 @@ export struct HomeIconComp {
this.zixunIcon = icons.img
}
}
this.initList()
// for (let index = 0; index < this.iconList!.length; index++) {
// const iconModel = this.iconList![index] as iconsModel ;
// if (index == 0) {
// iconModel.isRed = true;
// }
// }
this.getRedCount()
}
for (let index = 0; index < this.iconList!.length; index++) {
const iconModel = this.iconList![index] as iconsModel ;
if (index == 0) {
iconModel.isRed = true;
aboutToDisappear(): void {
let uiObserver: UIObserver = this.getUIContext().getUIObserver();
uiObserver.off('routerPageUpdate', this.listener);
}
async getRedCount()
{
let unreadCount = LocalConversationRepo.getTotalUnreadCount() ?? 0
let consultcount=0
const result = await LocalConversationRepo.getConversationList(0,100)
if(result!=null&&result.conversationList!=null)
{
for (const conversation of result.conversationList) {
const uuid = ChatKitClient.nim.conversationIdUtil.parseConversationTargetId(conversation.conversationId);
// 假设 selectUserStyleWithModel 返回 "1" 表示 type=1
const style = await patientDbManager.getPatientTypeByUuid(uuid);
if (style != 1) {
if(conversation.unreadCount>0)
{
consultcount++
}
}
}
}
unreadCount=unreadCount-consultcount
if(unreadCount>0)
{
this.patientRed=true
}
else
{
this.patientRed=false
}
if(consultcount>0)
{
this.consultationRed=true
}
this.initList()
const hashMap: HashMap<string, string> = new HashMap();
hdHttp.httpReq<string>(BasicConstant.indexV2,hashMap).then(async (res: HdResponse<string>) => {
let json:HomeModel = JSON.parse(res+'') as HomeModel;
if(json.data!=null&&json.data.consult_list!=null&&json.data.consult_list.list!=null)
{
consultcount=consultcount>0?consultcount:json.data.consult_list.list.length
if(consultcount>0)
{
this.consultationRed=true
}
else
{
this.consultationRed=false
}
this.initList()
}
}).catch((err: BusinessError) => {
})
}
initList()
{
this.iconListtmp=[...[{ 'img': this.patientIcon, 'name': this.patientName,'isRed':this.patientRed } as iconsModel,
{ 'img': this.videoIcon, 'name': this.videoName} as iconsModel,
{'img':this.zixunIcon,'name':this.consultation,'isRed':this.consultationRed} as iconsModel]]
}
build() {
Row() {
Grid() {
ForEach([{ 'img': this.patientIcon, 'name': this.patientName },{ 'img': this.videoIcon, 'name': this.videoName},{'img':this.zixunIcon,'name':this.consultation}], (item: iconsModel) => {//this.iconList
ForEach(this.iconListtmp, (item: iconsModel) => {//this.iconList
GridItem(){
Stack() {
Column() {
@@ -76,4 +164,5 @@ export struct HomeIconComp {
}.width('100%').backgroundColor(Color.White)
}
}
}
@@ -170,4 +170,5 @@ export struct HomePage {
.width('100%')
.height('100%')
}
}