369 lines
14 KiB
Plaintext
Raw Normal View History

2024-01-05 11:11:15 +08:00
import router from '@ohos.router'
import EndPoPup from './compontents/judge/end-popup'
import LoadingPopup from './compontents/judge/loading-popup'
import {getCurrentTime,formatTime,chunkArr,getCurrentHourTime} from '../common/utils/tools'
import Judge from './judgeSDK/judge'
import {Project,ProjectObj,MarkRule,CDSBInfo} from './judgeSDK/api/judgeSDK.d'
import AccountTable from '../common/database/tables/AccountTable';
import USER from '../common/constants/USER';
import MA_MARKRULE from '../common/constants/MA_MARKRULE';
import MA_SYSTEMPARM from '../common/constants/MA_SYSTEMPARM';
import MA_SYSSET from '../common//constants/MA_SYSSET';
import MA_CDSBINFO from '../common/constants/MA_CDSBINFO'
import FileLog from './judgeSDK/utils/file-log'
import {testAllitems,testUIAllitems,testMarkRules} from './judgeSDK/dataTest/index'
import {
examJudgeEndExam,examJudgeDestroy
} from './judgeSDK/api/index'
import common from '@ohos.app.ability.common';
import { getSyncData } from '../common/service/initable'
interface JudgeData{
xmmcStr:string,
carztStr:string,
kfArr:{xmmcStr:string,desc}[]
}
let LOGTAG = 'LOGTAG'
@Entry
@Component
struct Index {
//页面通用字体大小
@State FONTSIZE:number = 18
@State BIGFONTSIZE:number = 20
//结束考试弹窗
@State endPopupVisible:boolean = false
//等待弹窗(考试及格,考试不及格使用)
@State loadingPopupVisible:boolean = false
@State time:string = ''
//考试用时
@State examTime:number= 0
//开始时间
@State startTime:string = '00:00:00'
@State startFullTime:string =''
@State startHourTime:string = ''
@State xmmcStr:string = ''
@State carztStr:string = ''
@State kfArr:{xmmcStr?:string,score:string,desc:string}[] = []
@State name:string = ''
@State idCard:string = ''
@State totalScore:number = 100
//模拟考试项目
@State projects:Project[] = []
@State projectsObj:ProjectObj = {}
@State projectsCenterObj:ProjectObj = {}
@State markRuleListObj:MarkRule ={}
@State cdsbInfoObj:CDSBInfo ={}
@State timer:number = 0
//流水号
@State lsh:string = ''
@State kszp:string = ''
@State ksdd:string = ''
@State kssycs:string = ''
@State kslx:string = ''
//已考的考试项目
private wantInfos = []
//监管接口序列号
@State serialNumber:number = 0
//TODO 车型待替换
@State carType:string = 'C1'
@State carName:string = '帝豪手动挡'
@State judge:any = {}
scroller: Scroller = new Scroller()
private context = getContext(this) as common.UIAbilityContext;
private img:ImageBitmap = new ImageBitmap("/resources/base/media/1.png")
async aboutToAppear(){
globalThis.windowClass.setWindowSystemBarEnable([''])
const time = await getCurrentTime()
this.startTime = time.split(' ')[1]
this.startFullTime = await getCurrentTime(1);
this.startHourTime = await getCurrentHourTime()
setInterval(async()=>{
this.time = await getCurrentTime();
this.examTime += 1;
},1000);
//初始化考生
await this.initStudent();
await this.initMarkRules();
//初始化项目
await this.initProjectInfo();
//初始化sysset表
await this.initSysset()
// 初始化场地表
await this.initCDSBInfo()
// //初始化评判
const {name,idCard,lsh,kszp} = this;
const fileLog = new FileLog(this.context);
const filePath = await fileLog.initFileLogo({
name,lsh,idCard
});
const judge = await this.initJudge(fileLog);
this.judge = judge
}
//获取考生信息
async initStudent(){
const that = this;
const db = new AccountTable(()=>{},USER);
// that.sfzmhm = 'surenjun';
db.getRdbStore(()=>{
db.query('0', (result) => {
const stuInfo = result[0] || {};
const {xm,sfzmhm,lsh,kszp,ksdd,kssycs,kslx} = stuInfo;
that.name = xm;
that.idCard = sfzmhm;
that.lsh = lsh;
that.kszp = kszp;
that.ksdd = ksdd;
that.kssycs = kssycs;
that.kslx = kslx;
}, true);
});
}
//获取项目信息
async initProjectInfo(){
const that = this;
const systemParamsArr = await getSyncData('MA_SYSTEMPARM')
const itemInfoArr = await getSyncData('MA_ITEMINFO')
//@ts-ignore
const filterProjectsArr = systemParamsArr.filter(item => item.no1 == 6)
// that.projects = testAllitems
testAllitems.map(project => {
//TODO 临时代码
const currentProject = {
name:(project.name),
abbreviation:(project.abbreviation),
projectCode:(project.projectCode),
projectCodeCenter:(project.projectCodeCenter),
sbxh:project.type
// type:project.type
}
that.projectsObj[project.projectCode] = currentProject
that.projectsCenterObj[project.projectCodeCenter] = currentProject
return currentProject
});
//@ts-ignore
//TODO 临时代码待替换
that.projects = testUIAllitems
}
//获取扣分代码信息
async initMarkRules(){
const that = this;
const markRuleParams = await getSyncData('MA_MARKRULE')
//@ts-ignore
markRuleParams.forEach(mark=>{
that.markRuleListObj[`${mark.itemno}_${mark.markserial}`] = {
itemno:mark.itemno*1,
markcatalog:mark.markcatalog,
markshow:decodeURI(mark.markshow),
markreal:mark.markreal*1,
markserial:mark.markserial,
kfxh:mark.kfxh
};
})
const test = this.markRuleListObj;
}
// 获取sysset表信息
async initSysset(){
const that = this;
const db = new AccountTable(()=>{},MA_SYSSET);
const syssetParams = await getSyncData('MA_SYSSET')
//@ts-ignore
const serialNumberArr = syssetParams.filter(sys => sys.v_no === '901');
that.serialNumber = (serialNumberArr[0] && serialNumberArr[0].v_value) || '123456'
console.info('surenjun',that.serialNumber)
}
// 获取场地设备信息
async initCDSBInfo(){
const that = this;
const db = new AccountTable(()=>{},MA_CDSBINFO);
const cdsbParams = await getSyncData('MA_CDSBINFO')
//@ts-ignore
cdsbParams.forEach((cdsb)=>{
const key = decodeURI(cdsb.itemsno);
const newKey = key.split('~').join('_')
that.cdsbInfoObj[newKey] = {
kdid:cdsb.kdid,
sbbh:cdsb.sbbh,
sbbm:cdsb.sbbm,
itemsno:key
}
})
}
// 评判相关初始化
async initJudge(fileLog){
const judge = new Judge(this,fileLog);
await judge.onJudgeFn(async (judgeData)=>{
const {xmmcStr,carztStr,kfArr} = judgeData;
this.xmmcStr = xmmcStr;
this.carztStr = carztStr;
this.kfArr = kfArr;
});
return judge
}
build() {
Column() {
Row() {
Row(){
Image($rawfile('judge/signal_logoS.png')).width(65).height(25)
Text(this.time).fontColor('#CCB48F').fontSize(this.FONTSIZE).padding({left:10,right:5})
Image($rawfile('judge/xh_green.png')).width(25).height(20)
}
Row(){
Text(`当前项目:${this.xmmcStr || '无'} `).fontColor('#E5CCA1').fontSize(this.FONTSIZE)
}
}
.width('100%').height('50').backgroundColor('#001A33').padding({left:15,right:15}).justifyContent(FlexAlign.SpaceBetween).alignItems(VerticalAlign.Center)
Row(){
Row(){
Column(){
Row(){
Column(){
Row(){
Text('考生姓名:').fontColor('#E5CCA1').fontSize(this.FONTSIZE)
Text(this.name).fontColor('#FFF').fontSize(this.FONTSIZE)
}.margin({bottom:10})
Row(){
Text('开始时间:').fontColor('#E5CCA1').fontSize(this.FONTSIZE)
Text(this.startTime).fontColor('#FFF').fontSize(this.FONTSIZE)
}
}.width('45%').alignItems(HorizontalAlign.Start)
Column(){
Row(){
Text('身份证号:').fontColor('#E5CCA1').fontSize(this.FONTSIZE)
Text(this.idCard).fontColor('#FFF').fontSize(this.FONTSIZE)
}.margin({bottom:10})
Row(){
Text('考试用时:').fontColor('#E5CCA1').fontSize(this.FONTSIZE)
Text(formatTime(this.examTime)).fontColor('#FFF').fontSize(this.FONTSIZE)
}
}.alignItems(HorizontalAlign.Start)
}.width('100%')
Column(){
Text(this.carztStr).fontColor('#FFA500').fontSize(this.FONTSIZE)
Row(){
Flex({direction:FlexDirection.Column}){
List({}){
ForEach(this.kfArr,(item)=>{
ListItem(){
Column(){
Row(){
Text(item.xmmcStr).fontSize(this.BIGFONTSIZE).fontColor('#FFF')
Text(`${item.score}分`).fontSize(this.BIGFONTSIZE).fontColor('#FFF')
}.width('100%').backgroundColor('#38260B').justifyContent(FlexAlign.SpaceBetween).padding({top:12,bottom:12,left:8,right:5})
Text(item.desc).fontSize(this.BIGFONTSIZE).fontColor('#E5CBA1').margin({top:10,bottom:8,left:5,right:5})
}.margin({top:10}).alignItems(HorizontalAlign.Start)
}
})
}
}.backgroundImage($rawfile('judge/score_bg.png'),ImageRepeat.NoRepeat).backgroundImageSize({width:'100%',height:'100%'}).width('40%').height('100%').padding({top:18,bottom:15,left:12,right:15})
Flex({wrap:FlexWrap.Wrap,direction:FlexDirection.Row,justifyContent:FlexAlign.SpaceBetween}){
List({}){
ForEach(chunkArr(this.projects,2),(item)=>{
ListItem(){
Row(){
Row(){
//#FF7566 #00FFD5 #E6DECF
// Text(this.projectsObj[item[0].projectCode])
Text(item[0].abbreviation).fontSize(item[0].abbreviation.length > 5?15:22).fontColor(this.getProjectColor(this.projectsObj[item[0].projectCode].type))
}.backgroundImage($rawfile('judge/project_item.png'),ImageRepeat.NoRepeat).backgroundImageSize({width:'100%',height:'100%'}).width('48.5%').height(75).margin({bottom:5}).justifyContent(FlexAlign.Center)
if(item[1]){
Row(){
//#FF7566 #00FFD5 #E6DECF
Text(item[1].abbreviation).fontSize(item[1].abbreviation.length > 5?15:22).fontColor(this.getProjectColor(this.projectsObj[item[1].projectCode].type))
}.backgroundImage($rawfile('judge/project_item.png'),ImageRepeat.NoRepeat).backgroundImageSize({width:'100%',height:'100%'}).width('48.5%').height(75).margin({left:5,bottom:5}).justifyContent(FlexAlign.Center)
}
}
}
});
}
}.backgroundImage($rawfile('judge/project_bg.png'),ImageRepeat.NoRepeat).backgroundImageSize({width:'100%',height:'100%'}).width('57%').height('100%').padding(30).margin({right:10})
}.margin({top:15}).height('80%').justifyContent(FlexAlign.SpaceBetween)
}.width('100%').height('100%').alignItems(HorizontalAlign.Start).margin({top:10})
}.height('100%').alignItems(HorizontalAlign.Start)
}.width('75%').height('100%')
Column(){
Column(){
Row(){
Text(this.totalScore+'').fontColor('#FFEECC').fontSize(30)
Text('分').fontColor('#FFEECC').fontSize(18).padding({top:5})
}.width('85%').height(70).justifyContent(FlexAlign.Center).alignItems(VerticalAlign.Center).border({width:3,color:'#4D4136',radius:15})
Row(){
Image(this.kszp).width('85%').height('85%')
}.width('65%').height(150).backgroundImage($rawfile('judge/photo_bg.png'),ImageRepeat.NoRepeat).backgroundImageSize({width:'100%',height:'100%'}).justifyContent(FlexAlign.Center).alignItems(VerticalAlign.Center).margin({top:30})
}
Row(){ }.width('86%').height(65).backgroundImage($rawfile('judge/anniu_nor.png'),ImageRepeat.NoRepeat).backgroundImageSize({width:'100%',height:'100%'}).onClick(()=>{this.endPopupVisible = true})
}.width('25%').height('100%').justifyContent(FlexAlign.SpaceBetween).alignItems(HorizontalAlign.Center).margin({bottom:20})
}.height('90%').justifyContent(FlexAlign.Start).padding({top:20,left:30,bottom:10,right:30})
//结束考试弹窗
if(this.endPopupVisible){
EndPoPup({
title:'确定结束考试吗?',
cancelFn:()=>{
this.endPopupVisible = false;
},
confirmFn:()=>{
this.endPopupVisible = false;
globalThis.isJudge = false
//调用考试结束,关闭定时器
examJudgeEndExam();
// examJudgeDestroy()
clearInterval(this.timer);
clearInterval(globalThis.judgeTimer)
globalThis.windowClass.setWindowSystemBarEnable(['navigation'])
const judge= this.judge
judge?.endExam();
router.back();
}
})
}
if(this.loadingPopupVisible){
LoadingPopup({
title:'正在生成考试记录,请稍后...',
})
}
}
.height('100%').backgroundColor('#000').justifyContent(FlexAlign.Start)
}
getProjectColor(type:string){
switch (type){
case '1': return '#E6DECF';break;
case '2': return '#FFAD33';break;
case '3': return '#00FFD5';break;
case '4': return '#FF7566';break;
default : return '#E6DECF';break;
}
}
}