You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
6.4 KiB
219 lines
6.4 KiB
import { HttpErrorResponse } from "@angular/common/http"; |
|
import { plainToClass } from "class-transformer"; |
|
import { InstitutionData, NormalData } from "../../model/data/institution/institution-data"; |
|
import { InsitutionDataSimple } from "../../model/data/institution/institution-data-simple"; |
|
import { InstitutionCreateWindow } from "../../view/institution/institution-create-window"; |
|
import { InstitutionSelectWindow } from "../../view/institution/institution-select-window"; |
|
import { TopbarWindow } from "../../view/topbar-window/topbar-window"; |
|
|
|
import { DataManager } from "../data-manager"; |
|
import { SceneManager } from "../scene-manager"; |
|
import { ServeManager } from "../serve-manager"; |
|
import { UIManager } from "../ui-manager"; |
|
import { MainStatus } from "./main-status"; |
|
import { StatusBase, StatusManager } from "./status-manager"; |
|
|
|
export class LoginSatus extends StatusBase { |
|
|
|
institutionSelectWindow: InstitutionSelectWindow; |
|
|
|
institutionCreateWindow: InstitutionCreateWindow; |
|
|
|
institutionList: InsitutionDataSimple[];//单位简易信息列表 |
|
|
|
|
|
//#region 前端对接 |
|
|
|
/** |
|
* 新建单位 |
|
* @param insData 新的单位信息 |
|
*/ |
|
createInsitution(key: string, name: string, onSuccess?: (insDataSimple: InsitutionDataSimple) => void) { |
|
|
|
if (key == null) { |
|
console.error("创建单位key为null"); |
|
return; |
|
} |
|
let insData = new InstitutionData(); |
|
insData.normalData = new NormalData(key, name); |
|
|
|
this.saveNewIns(this, insData, key, onSuccess); |
|
} |
|
|
|
//#endregion |
|
|
|
|
|
//#region 外部方法 |
|
|
|
|
|
/** |
|
* 获取单位简易信息列表 |
|
* @param onSuccess 获取成功的回调 |
|
*/ |
|
getInstitutionListFromServe(onSuccess?: (result: InsitutionDataSimple[], data?: any) => void, onFail?: (error: string) => void) { |
|
let debugList: any | InsitutionDataSimple[] = []; |
|
// let testIns1 = new InsitutionDataSimple(); |
|
// testIns1.key = "test"; |
|
// testIns1.name = "测试单位1"; |
|
// debugList.push(testIns1); |
|
ServeManager.instance.getInstitutionData("InsList", (key, data) => { |
|
debugList = plainToClass(InsitutionDataSimple, data); |
|
this.institutionList = debugList; |
|
if (onSuccess) { |
|
onSuccess(debugList, data); |
|
} |
|
}, (key: string, error: any) => { |
|
console.error("获取单位列表失败"); |
|
console.log(error); |
|
if (error instanceof HttpErrorResponse && error.status === 404) { |
|
//数据库没有数据,新建 |
|
this.institutionList = []; |
|
if (onSuccess) { |
|
onSuccess(this.institutionList, this.institutionList); |
|
} |
|
console.log("新建数据列表"); |
|
} |
|
else { |
|
if (onFail) { |
|
onFail(error); |
|
} |
|
} |
|
|
|
return; |
|
}) |
|
} |
|
|
|
|
|
/** |
|
* 选择单位完成,初始化数据(向服务器请求完整数据) |
|
* @param simpleData 选择的单位 |
|
*/ |
|
onSelectInsSuccess(simpleData: InsitutionDataSimple) { |
|
let status: LoginSatus = StatusManager.getStatus<LoginSatus>(LoginSatus); |
|
if (status.institutionSelectWindow != null) { |
|
UIManager.close(status.institutionSelectWindow); |
|
status.institutionSelectWindow = null; |
|
} |
|
|
|
DataManager.init(simpleData, (resultkey) => { |
|
StatusManager.enterStatus<MainStatus>(MainStatus); |
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
//#endregion |
|
|
|
|
|
//#region 生命周期 |
|
//初始化 |
|
onCreate() { |
|
super.onCreate(); |
|
|
|
} |
|
//进入状态 |
|
onEnter() { |
|
super.onEnter(); |
|
|
|
console.log("进入 logins"); |
|
|
|
//UIManager.open<TopbarWindow>(TopbarWindow); |
|
// this.openSelectWindow();//可以开启选择、新建单位 |
|
|
|
|
|
} |
|
//退出状态 |
|
onExit() { |
|
|
|
super.onEnter(); |
|
|
|
} |
|
|
|
//开启选择界面 |
|
openSelectWindow() { |
|
console.log("=======开启选择界面"); |
|
this.institutionSelectWindow = UIManager.open<InstitutionSelectWindow>(InstitutionSelectWindow); |
|
console.log(this.institutionSelectWindow); |
|
let status = this; |
|
this.institutionSelectWindow.getInsList(status.onSelectInsSuccess); |
|
} |
|
|
|
//关闭选择界面 |
|
closeSelectWindow() { |
|
if (this.institutionSelectWindow != null) { |
|
UIManager.close(this.institutionSelectWindow); |
|
this.institutionSelectWindow = null; |
|
} |
|
} |
|
|
|
|
|
//新建完成 |
|
onCreateInsSuccess(insData: InsitutionDataSimple) { |
|
|
|
this.closeCreateWindow(); |
|
|
|
let isOverWrite = false; |
|
for (let i = 0; i < this.institutionList.length; i++) { |
|
if (this.institutionList[i].key == insData.key) { |
|
this.institutionList[i].name = insData.name; |
|
isOverWrite = true; |
|
break; |
|
} |
|
} |
|
|
|
if (!isOverWrite) { |
|
this.institutionList.push(insData); |
|
} |
|
|
|
let status = this; |
|
|
|
ServeManager.instance.saveInstitutionListData(this.institutionList, () => { |
|
//进入新单位 |
|
status.onSelectInsSuccess(insData); |
|
}); |
|
|
|
} |
|
//#endregion |
|
|
|
//#region babylonGUI 新建单位 |
|
//开启新建界面 |
|
onNewIns() { |
|
this.closeSelectWindow(); |
|
|
|
this.institutionCreateWindow = UIManager.open<InstitutionCreateWindow>(InstitutionCreateWindow); |
|
let status = this; |
|
this.institutionCreateWindow.startCreate(); |
|
|
|
} |
|
|
|
//关闭创建界面 |
|
closeCreateWindow() { |
|
if (this.institutionCreateWindow != null) { |
|
UIManager.close(this.institutionCreateWindow); |
|
} |
|
this.institutionCreateWindow = null; |
|
|
|
|
|
} |
|
|
|
|
|
//保存新单位信息至服务器 |
|
saveNewIns(status: LoginSatus, insData: InstitutionData, key: string, onSuccess?: (insDataSimple: InsitutionDataSimple) => void) { |
|
ServeManager.instance.saveInstitutionData(insData, key, (key, result) => { |
|
console.log("在服务器新建单位" + key); |
|
let insDataSimple = new InsitutionDataSimple(); |
|
insDataSimple.key = key; |
|
insDataSimple.name = insData.normalData.name; |
|
status.onCreateInsSuccess(insDataSimple); |
|
if (onSuccess != null) { |
|
onSuccess(insDataSimple); |
|
} |
|
}); |
|
} |
|
|
|
|
|
|
|
//#endregion |
|
|
|
} |