我的患者列表
This commit is contained in:
parent
8cb36953d9
commit
69dd55bf27
@ -1,5 +1,5 @@
|
||||
import { PatientsData } from '@itcast/basic';
|
||||
|
||||
@Observed
|
||||
export class Groups {
|
||||
|
||||
/**
|
||||
|
||||
@ -24,6 +24,99 @@ let collator = new Intl.Collator(I18n.System.getSystemLocale(), {
|
||||
collation: 'pinyin',
|
||||
caseFirst: 'lower'
|
||||
})
|
||||
|
||||
// 数据源类,用于LazyForEach
|
||||
class PatientDataSource implements IDataSource {
|
||||
private dataList: Array<Groups> = []
|
||||
private listeners: DataChangeListener[] = []
|
||||
|
||||
constructor(data: Array<Groups>) {
|
||||
this.dataList = data
|
||||
}
|
||||
|
||||
totalCount(): number {
|
||||
return this.dataList.length
|
||||
}
|
||||
|
||||
getTotalCount(): number {
|
||||
return this.dataList.length
|
||||
}
|
||||
|
||||
getData(index: number): Groups {
|
||||
return this.dataList[index]
|
||||
}
|
||||
|
||||
registerDataChangeListener(listener: DataChangeListener): void {
|
||||
this.listeners.push(listener)
|
||||
}
|
||||
|
||||
unregisterDataChangeListener(listener: DataChangeListener): void {
|
||||
const index = this.listeners.indexOf(listener)
|
||||
if (index > -1) {
|
||||
this.listeners.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
notifyDataChange(): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataReloaded();
|
||||
// listener.onDataChanged(this.getTotalCount())
|
||||
})
|
||||
}
|
||||
|
||||
updateData(newData: Array<Groups>): void {
|
||||
this.dataList = [...newData] // 创建新数组以确保引用变化
|
||||
this.notifyDataChange()
|
||||
}
|
||||
}
|
||||
|
||||
// 患者数据源类,用于内层LazyForEach
|
||||
class PatientItemDataSource implements IDataSource {
|
||||
private dataList: Array<PatientsData> = []
|
||||
private listeners: DataChangeListener[] = []
|
||||
|
||||
constructor(data: Array<PatientsData>) {
|
||||
this.dataList = data
|
||||
}
|
||||
|
||||
totalCount(): number {
|
||||
return this.dataList.length
|
||||
}
|
||||
|
||||
getTotalCount(): number {
|
||||
return this.dataList.length
|
||||
}
|
||||
|
||||
getData(index: number): PatientsData {
|
||||
return this.dataList[index]
|
||||
}
|
||||
|
||||
registerDataChangeListener(listener: DataChangeListener): void {
|
||||
this.listeners.push(listener)
|
||||
}
|
||||
|
||||
unregisterDataChangeListener(listener: DataChangeListener): void {
|
||||
const index = this.listeners.indexOf(listener)
|
||||
if (index > -1) {
|
||||
this.listeners.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
notifyDataChange(): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataReloaded();
|
||||
// listener.onDataChanged(this.getTotalCount())
|
||||
})
|
||||
}
|
||||
|
||||
updateData(newData: Array<PatientsData>): void {
|
||||
this.dataList =[]
|
||||
this.dataList = [...newData] // 创建新数组以确保引用变化
|
||||
this.notifyDataChange()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
export struct PatientListComp {
|
||||
|
||||
@ -51,6 +144,12 @@ export struct PatientListComp {
|
||||
@State delectname:string=''
|
||||
@State positionDelete:number = 0
|
||||
@State isEmptyViewVisible: boolean = false; // 控制显隐的状态变量
|
||||
|
||||
// 数据源实例
|
||||
private patientDataSource: PatientDataSource = new PatientDataSource([])
|
||||
// 缓存患者数据源,避免重复创建
|
||||
// private patientItemDataSourceCache: Map<string, PatientItemDataSource> = new Map()
|
||||
|
||||
dialogDelete = new CustomDialogController({
|
||||
builder: DelectDialog(
|
||||
{
|
||||
@ -68,7 +167,7 @@ export struct PatientListComp {
|
||||
private lifecycleOwner = HMRouterMgr.getCurrentLifecycleOwner()
|
||||
private handleCallback = () => {
|
||||
this.PatientsData()
|
||||
this.loadPatients()
|
||||
// this.loadPatients()
|
||||
this.getApplyList()
|
||||
}
|
||||
aboutToAppear() {
|
||||
@ -79,6 +178,8 @@ export struct PatientListComp {
|
||||
}
|
||||
aboutToDisappear(): void {
|
||||
this.lifecycleOwner?.removeObserver(HMLifecycleState.onShown,this.handleCallback)
|
||||
// 清理数据源缓存
|
||||
// this.patientItemDataSourceCache.clear()
|
||||
}
|
||||
|
||||
getApplyList() {
|
||||
@ -122,17 +223,18 @@ export struct PatientListComp {
|
||||
console.log('服务器返回的患者数据:', json);
|
||||
if(json.data!=null)
|
||||
{
|
||||
if(json.data!=null&&json.data.length>0)
|
||||
if(json.data!=null&&json.data.length>0)
|
||||
{
|
||||
this.total=json.data.length
|
||||
if(this.old<this.total/10)
|
||||
{
|
||||
this.total=json.data.length
|
||||
if(this.old<this.total/10)
|
||||
{
|
||||
this.needShow=true
|
||||
preferenceStore.setItemNumber('old_patient_num',this.total/10)
|
||||
}
|
||||
this.collationData(json.data);
|
||||
this.isEmptyViewVisible=false
|
||||
this.needShow=true
|
||||
preferenceStore.setItemNumber('old_patient_num',this.total/10)
|
||||
}
|
||||
console.info('开始处理患者数据,总数:', this.total)
|
||||
this.collationData(json.data);
|
||||
this.isEmptyViewVisible=false
|
||||
}
|
||||
else
|
||||
{
|
||||
this.isEmptyViewVisible=true
|
||||
@ -300,11 +402,11 @@ export struct PatientListComp {
|
||||
.width('100%')
|
||||
.height('60%')
|
||||
}
|
||||
ForEach(this.regionDataGroupsList, (regionDataGroups: Groups, index) => {
|
||||
LazyForEach(this.patientDataSource, (regionDataGroups: Groups, index) => {
|
||||
|
||||
ListItemGroup({ header: this.itemHead(regionDataGroups.title) }) {
|
||||
|
||||
ForEach(regionDataGroups.regionDataList, (regionData: PatientsData, index: number) => {
|
||||
LazyForEach(new PatientItemDataSource(regionDataGroups.regionDataList), (regionData: PatientsData, index: number) => {
|
||||
ListItem() {
|
||||
Column()
|
||||
{
|
||||
@ -383,7 +485,7 @@ export struct PatientListComp {
|
||||
this.dialogDelete.open()
|
||||
})
|
||||
)
|
||||
})
|
||||
}, (item: PatientsData, index: number) => JSON.stringify(item) )
|
||||
|
||||
}
|
||||
.width('100%')
|
||||
@ -523,6 +625,18 @@ export struct PatientListComp {
|
||||
this.regionDataGroupsList.sort((a, b) => {
|
||||
return this.normalIndexValue.indexOf(a.title) - this.normalIndexValue.indexOf(b.title);
|
||||
});
|
||||
|
||||
// 更新数据源 - 创建新数组以确保引用变化
|
||||
// console.info('更新数据源,分组数量:', this.regionDataGroupsList.length)
|
||||
this.patientDataSource.updateData([...this.regionDataGroupsList])
|
||||
|
||||
// 更新缓存的患者数据源
|
||||
// this.patientItemDataSourceCache.clear()
|
||||
// this.regionDataGroupsList.forEach(group => {
|
||||
// this.patientItemDataSourceCache.set(group.title, new PatientItemDataSource([...group.regionDataList]))
|
||||
// })
|
||||
|
||||
console.info('数据源更新完成')
|
||||
this.dialog.close()
|
||||
}
|
||||
|
||||
@ -539,6 +653,35 @@ export struct PatientListComp {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 从本地数据中移除被删除的患者
|
||||
private removePatientFromLocalData(patientUuid: string): void {
|
||||
// 从 regionInfo 中移除
|
||||
this.regionInfo = this.regionInfo.filter(patient => patient.uuid !== patientUuid)
|
||||
|
||||
// 从分组数据中移除
|
||||
this.regionDataGroupsList.forEach(group => {
|
||||
group.regionDataList = group.regionDataList.filter(patient => patient.uuid !== patientUuid)
|
||||
})
|
||||
|
||||
// 移除空的分组
|
||||
this.regionDataGroupsList = this.regionDataGroupsList.filter(group => group.regionDataList.length > 0)
|
||||
|
||||
// 更新索引列表
|
||||
this.indexList = this.regionDataGroupsList.map(group => group.title)
|
||||
|
||||
// 更新总数
|
||||
this.total = this.regionInfo.length
|
||||
|
||||
// 立即更新数据源
|
||||
this.patientDataSource.updateData([...this.regionDataGroupsList])
|
||||
|
||||
// 更新缓存的患者数据源
|
||||
// this.patientItemDataSourceCache.clear()
|
||||
// this.regionDataGroupsList.forEach(group => {
|
||||
// this.patientItemDataSourceCache.set(group.title, new PatientItemDataSource([...group.regionDataList]))
|
||||
// })
|
||||
}
|
||||
|
||||
deletePatientAction(patientUuid:string) {
|
||||
this.dialog.open()
|
||||
hdHttp.post<string>(BasicConstant.cancelRes, {
|
||||
@ -568,6 +711,7 @@ export struct PatientListComp {
|
||||
} else {
|
||||
console.info('修改失败')
|
||||
}
|
||||
// 重新获取数据以确保同步
|
||||
this.PatientsData()
|
||||
} else {
|
||||
console.error('获取患者信息失败:'+json.message)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user