我的患者列表

This commit is contained in:
XiuYun CHEN 2025-08-07 14:13:57 +08:00
parent 69dd55bf27
commit e590efbe68

View File

@ -47,7 +47,10 @@ class PatientDataSource implements IDataSource {
}
registerDataChangeListener(listener: DataChangeListener): void {
this.listeners.push(listener)
// this.listeners.push(listener)
if (this.listeners.indexOf(listener) < 0) {
this.listeners.push(listener);
}
}
unregisterDataChangeListener(listener: DataChangeListener): void {
@ -92,7 +95,10 @@ class PatientItemDataSource implements IDataSource {
}
registerDataChangeListener(listener: DataChangeListener): void {
this.listeners.push(listener)
// this.listeners.push(listener)
if (this.listeners.indexOf(listener) < 0) {
this.listeners.push(listener);
}
}
unregisterDataChangeListener(listener: DataChangeListener): void {
@ -110,7 +116,6 @@ class PatientItemDataSource implements IDataSource {
}
updateData(newData: Array<PatientsData>): void {
this.dataList =[]
this.dataList = [...newData] // 创建新数组以确保引用变化
this.notifyDataChange()
@ -127,6 +132,9 @@ export struct PatientListComp {
private normalIndexValue: string[] = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '#']
// 新增存储每个分组在List中的实际位置
private groupPositions: Map<string, number> = new Map()
private indexUtil = I18n.getInstance(I18n.System.getSystemLocale());
displayClass = display.getDefaultDisplaySync()
@State alphabetSelected: number = 0
@ -175,6 +183,10 @@ export struct PatientListComp {
this.loadPatients()
this.getApplyList()
this.lifecycleOwner?.addObserver(HMLifecycleState.onShown,this.handleCallback)
// 初始化AlphabetIndexer的调试信息
console.info('AlphabetIndexer 初始化 - normalIndexValue:', this.normalIndexValue);
console.info('AlphabetIndexer 初始化 - indexList:', this.indexList);
}
aboutToDisappear(): void {
this.lifecycleOwner?.removeObserver(HMLifecycleState.onShown,this.handleCallback)
@ -214,6 +226,9 @@ export struct PatientListComp {
PatientsData()
{
// 清空现有数据,准备重新加载
this.clearListData();
this.dialog.open()
hdHttp.post<string>(BasicConstant.urlExpert + 'patientListByGBK', {
expertUuid: authStore.getUser().uuid
@ -226,6 +241,7 @@ export struct PatientListComp {
if(json.data!=null&&json.data.length>0)
{
this.total=json.data.length
this.old=preferenceStore.getItemNumber('old_patient_num')
if(this.old<this.total/10)
{
this.needShow=true
@ -249,6 +265,9 @@ export struct PatientListComp {
this.dialog.close()
console.error('解析服务器响应失败:', parseError);
}
}).catch((err: BusinessError) => {
this.dialog.close();
console.error('获取患者数据失败:', err);
})
}
@ -259,6 +278,35 @@ export struct PatientListComp {
console.error('加载患者数据失败:', error);
}
}
// 清空list数据准备重新加载
private clearListData(): void {
console.info('清空list数据准备重新加载');
// 清空数据数组
this.regionInfo = [];
this.regionDataGroupsList = [];
this.indexList = [];
// 清空位置映射
this.groupPositions.clear();
// 重置状态
this.total = 0;
this.alphabetSelected = 0;
this.isEmptyViewVisible = false;
// 更新数据源
this.patientDataSource.updateData([]);
console.info('list数据清空完成');
}
// 公共方法重新加载list数据
// public reloadList(): void {
// console.info('开始重新加载list数据');
// this.PatientsData();
// }
@Builder
itemHead(text: string) {
ListItem() {
@ -501,19 +549,18 @@ export struct PatientListComp {
endMargin: 0
})
.onScrollIndex((start: number, end: number) => {
if(start<3)
{
start=0
}
else
{
start=start-2
}
let target = this.indexList[start]
let indexList = this.normalIndexValue;
let index = this.searchIndex(indexList, target)
this.alphabetSelected = index === -1 ? this.onSlideList(indexList, target) - 1 : index;
console.info('onScrollIndex - start:', start, 'end:', end);
// 计算实际的分组索引位置
let groupIndex = this.calculateGroupIndexFromListPosition(start);
console.info('Calculated groupIndex:', groupIndex);
if (groupIndex >= 0 && groupIndex < this.indexList.length) {
let target = this.indexList[groupIndex];
console.info('Target group:', target);
let index = this.searchIndex(this.normalIndexValue, target);
this.alphabetSelected = index === -1 ? this.onSlideList(this.normalIndexValue, target) - 1 : index;
console.info('Updated alphabetSelected:', this.alphabetSelected);
}
})
.width('100%')
.scrollBar(BarState.Off)
@ -525,20 +572,40 @@ export struct PatientListComp {
.usingPopup(true)
.selected(this.alphabetSelected)
.onSelect((index: number) => {
console.info('AlphabetIndexer onSelect, index:', index);
console.info('Scroller instance:', this.scroller);
console.info('Current alphabetSelected:', this.alphabetSelected);
console.info('Total groups:', this.regionDataGroupsList.length);
if (index === 0) {
console.info('Scrolling to index 0');
this.scroller.scrollToIndex(0);
return;
}
let pos = 0
let useValue = this.normalIndexValue
let currentWord = useValue[index] // 在右侧索引上的位置
pos = this.searchIndex(this.indexList, currentWord)
let currentWord = this.normalIndexValue[index]; // 在右侧索引上的位置
console.info('Current word:', currentWord);
console.info('Available positions:', Array.from(this.groupPositions.entries()));
console.info('IndexList:', this.indexList);
if (pos === -1) {
return;
// 查找该字母在List中的实际位置
let targetPosition = this.groupPositions.get(currentWord);
console.info('Target position:', targetPosition);
if (targetPosition !== undefined) {
console.info('Scrolling to position:', targetPosition);
this.scroller.scrollToIndex(targetPosition);
} else {
// 如果当前字母不存在,查找下一个存在的字母
let nextPosition = this.findNextAvailablePosition(currentWord);
console.info('Next available position:', nextPosition);
if (nextPosition !== -1) {
console.info('Scrolling to next position:', nextPosition);
this.scroller.scrollToIndex(nextPosition);
} else {
console.warn('No available position found for word:', currentWord);
}
}
this.scroller.scrollToIndex(pos+2);
})
.id('id_hwid_region_choose_alphabetIndexer')
.onAreaChange((oldValue: Area, newValue: Area) => {
@ -550,7 +617,8 @@ export struct PatientListComp {
size: '20vp', style: FontStyle.Normal,
weight: FontWeight.Bolder
})
.position({ x: this.displayClass.width / this.displayClass.densityPixels - 25 }) // 侧边栏位置
.position({ x: this.displayClass.width / this.displayClass.densityPixels - 30 })
.zIndex(999) // 确保在最上层
Column()
{
@ -626,6 +694,14 @@ export struct PatientListComp {
return this.normalIndexValue.indexOf(a.title) - this.normalIndexValue.indexOf(b.title);
});
// 排序后重新更新indexList以保持一致性
this.indexList = this.regionDataGroupsList.map(group => group.title);
console.info('排序后的indexList:', this.indexList);
console.info('排序后的分组:', this.regionDataGroupsList.map(g => g.title));
// 计算每个分组在List中的实际位置
this.calculateGroupPositions();
// 更新数据源 - 创建新数组以确保引用变化
// console.info('更新数据源,分组数量:', this.regionDataGroupsList.length)
this.patientDataSource.updateData([...this.regionDataGroupsList])
@ -640,7 +716,6 @@ export struct PatientListComp {
this.dialog.close()
}
private searchIndex(indexList: string[], target: string): number {
return indexList.indexOf(target);
}
@ -653,6 +728,66 @@ export struct PatientListComp {
return 0;
}
// 计算每个分组在List中的实际位置
private calculateGroupPositions(): void {
this.groupPositions.clear();
let currentPosition = 2; // 前两个是固定的ListItem新的患者、患者分组
console.info('开始计算分组位置,分组数量:', this.regionDataGroupsList.length);
this.regionDataGroupsList.forEach((group, index) => {
// 每个ListItemGroup在List中占用一个位置
this.groupPositions.set(group.title, currentPosition);
console.info(`分组 ${group.title} 位置: ${currentPosition}, 患者数量: ${group.regionDataList.length}`);
// 移动到下一个ListItemGroup的位置
currentPosition += 1;
});
console.info('分组位置映射完成:', Array.from(this.groupPositions.entries()));
}
// 从List位置计算对应的分组索引
private calculateGroupIndexFromListPosition(listPosition: number): number {
if (listPosition < 2) {
return 0; // 前两个位置对应第一个分组
}
// 计算ListItemGroup的索引
let groupIndex = listPosition - 2; // 减去前两个固定项
if (groupIndex >= 0 && groupIndex < this.regionDataGroupsList.length) {
return groupIndex;
}
return this.regionDataGroupsList.length - 1; // 默认返回最后一个分组
}
// 查找下一个可用的位置
private findNextAvailablePosition(currentWord: string): number {
let currentIndex = this.normalIndexValue.indexOf(currentWord);
if (currentIndex === -1) return -1;
// 从当前字母开始向后查找
for (let i = currentIndex; i < this.normalIndexValue.length; i++) {
let word = this.normalIndexValue[i];
let position = this.groupPositions.get(word);
if (position !== undefined) {
return position;
}
}
// 如果向后没找到,向前查找
for (let i = currentIndex - 1; i >= 0; i--) {
let word = this.normalIndexValue[i];
let position = this.groupPositions.get(word);
if (position !== undefined) {
return position;
}
}
return -1;
}
// 从本地数据中移除被删除的患者
private removePatientFromLocalData(patientUuid: string): void {
// 从 regionInfo 中移除
@ -669,6 +804,9 @@ export struct PatientListComp {
// 更新索引列表
this.indexList = this.regionDataGroupsList.map(group => group.title)
// 重新计算分组位置
this.calculateGroupPositions();
// 更新总数
this.total = this.regionInfo.length