fix: 更新多个组件中的类型声明和逻辑,提升代码一致性
This commit is contained in:
parent
059471385f
commit
b98b0ff8c8
@ -1,13 +1,13 @@
|
||||
import request from '../utils/Request';
|
||||
import writeObjectOutNew from './judgeNew';
|
||||
import http from '@ohos.net.http';
|
||||
import { MASYSSETTableType, RegulatoryInterfaceParams } from '../model';
|
||||
import { MASYSSETTableType, RegulatoryInterfaceParams, WuxiExamType } from '../model';
|
||||
import { GetSyncData } from '../utils/table/Operation';
|
||||
import { GetCurrentTime } from '../utils/Common';
|
||||
import FileUtils from '../utils/FileUtils';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
let baseHost: string = AppStorage.get<string>('host');
|
||||
let baseHost: string = AppStorage.get<string>('host')!;
|
||||
|
||||
|
||||
// 下载模型
|
||||
@ -30,11 +30,11 @@ interface WR {
|
||||
export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath: string,
|
||||
context: common.UIAbilityContext): Promise<WR> {
|
||||
|
||||
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay')
|
||||
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
|
||||
if (singlePlay) {
|
||||
return { code: 1 }
|
||||
}
|
||||
let JGHOST: string = AppStorage.get<string>("JGHOST")
|
||||
let JGHOST: string = AppStorage.get<string>("JGHOST") || ""
|
||||
//获取监管接口地址路径
|
||||
if (!JGHOST) {
|
||||
const syssetParams: MASYSSETTableType[] = await GetSyncData<MASYSSETTableType>("MA_SYSSET");
|
||||
@ -52,27 +52,33 @@ export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath
|
||||
})
|
||||
}
|
||||
// const { xtlb, jkxlh, jkid, drvexam } = params;
|
||||
const isJGNew: boolean = AppStorage.get<boolean>('isJGNew')
|
||||
const isJGNew: boolean = AppStorage.get<boolean>('isJGNew') || false
|
||||
//新监管调用
|
||||
if (isJGNew) {
|
||||
return await writeObjectOutNew(params, filePath, context)
|
||||
}
|
||||
params.drvexam.zp = params.drvexam.zp === undefined ? undefined : encodeURIComponent(drvexam.zp)
|
||||
params.drvexam = params.drvexam ?? {};
|
||||
params.drvexam.zp = params.drvexam.zp === undefined ? undefined : encodeURIComponent(params.drvexam.zp);
|
||||
|
||||
const drvexamArrs = Reflect.ownKeys(params.drvexam)
|
||||
.filter(dKey => params.drvexam[dKey] != undefined)
|
||||
.filter(dKey => Reflect.get(params.drvexam, dKey) != undefined)
|
||||
.map((key: string) => (
|
||||
`<${key}>${params.drvexam[key]}</${key}>`));
|
||||
`<${key}>${Reflect.get(params.drvexam, key)}</${key}>`));
|
||||
|
||||
if (filePath) {
|
||||
const fileUtil = new FileUtils(globalThis.context);
|
||||
const fileUtil = new FileUtils(context);
|
||||
await fileUtil.initFolder(filePath);
|
||||
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify({
|
||||
|
||||
let obj: WuxiExamType = {
|
||||
xtlb: params.xtlb,
|
||||
jkxlh: params.jkxlh,
|
||||
jkid: params.jkid,
|
||||
drvexam: { ...params.drvexam, zp: '' },
|
||||
}) + `\n`);
|
||||
drvexam: {
|
||||
zp: "",
|
||||
|
||||
},
|
||||
}
|
||||
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(obj) + `\n`);
|
||||
}
|
||||
|
||||
//对象转换成xml
|
||||
@ -108,7 +114,7 @@ export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath
|
||||
xml: true
|
||||
},)
|
||||
if (filePath) {
|
||||
const fileUtil = new FileUtils(globalThis.context);
|
||||
const fileUtil = new FileUtils(context);
|
||||
await fileUtil.initFolder(filePath);
|
||||
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`);
|
||||
}
|
||||
@ -134,7 +140,6 @@ interface UploadExamProgressDataParams {
|
||||
|
||||
// 过程文件上传
|
||||
export async function uploadExamProgressData(params: UploadExamProgressDataParams) {
|
||||
// const singlePlay = globalThis.singlePlay
|
||||
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
|
||||
if (singlePlay) {
|
||||
return
|
||||
@ -257,7 +262,7 @@ export async function uploadExamGrade(params: ESObject) {
|
||||
function validateIP(path: string) {
|
||||
const reg = new RegExp(`(\w+):\/\/([^/:]+)(:\d*)?`)
|
||||
const result = path.match(reg);
|
||||
return result[0]
|
||||
return result ? result[0] : "";
|
||||
}
|
||||
|
||||
// 上传运行时常
|
||||
|
||||
@ -32,8 +32,8 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams,
|
||||
context: common.UIAbilityContext): Promise<WR> {
|
||||
// const context: common.UIAbilityContext = AppStorage.get('context')
|
||||
const fileUtil = new FileUtils(context);
|
||||
const basic = await getBasicConfig(data.jkid);
|
||||
const params = await getParams(data.jkid, data.drvexam);
|
||||
const basic = await getBasicConfig(data.jkid || "");
|
||||
const params = await getParams(data.jkid || "", data.drvexam ?? {} as DrvexamType);
|
||||
|
||||
if (filePath) {
|
||||
let examData: WuxiExamType = {
|
||||
@ -44,7 +44,7 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams,
|
||||
sjbs: basic.sjbs,
|
||||
data: params.data,
|
||||
file: {
|
||||
sjbs: params.file.sjbs,
|
||||
sjbs: params?.file?.sjbs || "",
|
||||
// params: []
|
||||
}
|
||||
}
|
||||
@ -55,7 +55,7 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams,
|
||||
console.info('surenjun', '调用新监管')
|
||||
let temp: WR
|
||||
try {
|
||||
const JGHOST: string = AppStorage.get<string>('JGHOST')
|
||||
const JGHOST: string = AppStorage.get<string>('JGHOST') || ""
|
||||
temp = await request<WR>({
|
||||
host: JGHOST,
|
||||
method: http.RequestMethod.POST,
|
||||
@ -95,7 +95,7 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams,
|
||||
|
||||
export async function getParams(jkid: string, drvexam: DrvexamType): Promise<GetJudgeParamsType> {
|
||||
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
|
||||
const examSubject: string = carInfo.examSubject;
|
||||
const examSubject: string = carInfo.examSubject || "2";
|
||||
switch (jkid) {
|
||||
//开始考试
|
||||
case '17C51':
|
||||
@ -104,7 +104,7 @@ export async function getParams(jkid: string, drvexam: DrvexamType): Promise<Get
|
||||
sjbs: gjxlhObj[jkid],
|
||||
param: {
|
||||
sfzmhm: drvexam.sfzmhm,
|
||||
kchp: decodeURI(drvexam.kchp),
|
||||
kchp: decodeURI(drvexam.kchp || ""),
|
||||
kskm: examSubject.toString(),
|
||||
ksxl: examSubject == "3" ? drvexam.ksxl : undefined,
|
||||
kssj: drvexam.kssj
|
||||
@ -130,7 +130,7 @@ export async function getParams(jkid: string, drvexam: DrvexamType): Promise<Get
|
||||
sfzmhm: drvexam.sfzmhm,
|
||||
kskm: drvexam.kskm,
|
||||
ksxl: examSubject == "3" ? drvexam.ksxl : undefined,
|
||||
kchp: decodeURI(drvexam.kchp),
|
||||
kchp: decodeURI(drvexam.kchp || ""),
|
||||
//TODO 待验证 科目三无
|
||||
sbbh: examSubject == "3" ? undefined : drvexam.sbxh,
|
||||
kssj: drvexam.kssj,
|
||||
@ -148,7 +148,7 @@ export async function getParams(jkid: string, drvexam: DrvexamType): Promise<Get
|
||||
data: {
|
||||
sjbs: gjxlhObj[jkid],
|
||||
param: {
|
||||
kffs: drvexam.kffs.toString(),
|
||||
kffs: drvexam?.kffs?.toString(),
|
||||
kfsj: drvexam.kfsj,
|
||||
kfxm: drvexam.kfxm,
|
||||
kfxmmx: drvexam.kfxmmx,
|
||||
@ -223,11 +223,13 @@ export async function getParams(jkid: string, drvexam: DrvexamType): Promise<Get
|
||||
//获取基础信息
|
||||
async function getBasicConfig(jkid: string): Promise<WuxiExamType> {
|
||||
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
|
||||
const examSubject: string = carInfo.examSubject;
|
||||
const examSubject: string = carInfo.examSubject || "2";
|
||||
const syssetParam: MASYSSETTableType[] = await GetSyncData<MASYSSETTableType>('MA_SYSSET');
|
||||
let syssetObj: Record<string, string> = {};
|
||||
syssetParam.forEach(sys => {
|
||||
syssetObj[sys.v_no] = decodeURIComponent(sys.v_value)
|
||||
if (sys.v_no) {
|
||||
syssetObj[sys.v_no] = decodeURIComponent(sys.v_value || "")
|
||||
}
|
||||
});
|
||||
let obj: WuxiExamType = {
|
||||
//外挂类别
|
||||
|
||||
@ -807,13 +807,16 @@ export interface WR {
|
||||
|
||||
// 无锡所数据
|
||||
export interface WuxiExamType {
|
||||
wglb: string
|
||||
jkxlh: string,
|
||||
glbm: string,
|
||||
jgbh: string,
|
||||
sjbs: string,
|
||||
wglb?: string
|
||||
jkxlh?: string,
|
||||
glbm?: string,
|
||||
jgbh?: string,
|
||||
sjbs?: string,
|
||||
xtlb?: string
|
||||
jkid?: string
|
||||
data?: JudgeData,
|
||||
file?: JudgeFile
|
||||
drvexam?: DrvexamType
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ import { CarInfoType, UDPParamType, VideoConfig } from '../../model';
|
||||
import { NumberToByteArray } from '../../utils/Common';
|
||||
import FileUtils from '../../utils/FileUtils';
|
||||
import { CenterUDPClientInstance } from '../../utils/business/CenterUdpBusiness';
|
||||
import { takePhoto } from '../../utils/Video';
|
||||
import { takePhoto, takePhotoParam } from '../../utils/Video';
|
||||
import { voiceService } from '../../utils/Voice';
|
||||
|
||||
interface ParamType {
|
||||
@ -189,11 +189,11 @@ export default struct FaceCompare {
|
||||
async faceComparFn() {
|
||||
console.log('mmmmm0', 2)
|
||||
this.param.pztd = this.param.rlls
|
||||
const data = await takePhoto(this.param, this.context, 'jt/', 1,)
|
||||
const data: takePhotoParam = await takePhoto(this.param, this.context, 'jt/', 1,)
|
||||
this.base64 = this.imageBase64 + (data?.base64 || "")
|
||||
console.log('mmmmt', this.base64)
|
||||
faceCompare({
|
||||
sfzh: this.sfzh,
|
||||
sfzh: this.sfzh.toString(),
|
||||
firstImage: this.firstImage.substr(22),
|
||||
secondImage: data?.base64 || "",
|
||||
type: "2",
|
||||
|
||||
@ -2,12 +2,12 @@ import { takePhoto } from '../../../utils/Video';
|
||||
import promptAction from '@ohos.promptAction';
|
||||
import { JudgeConfig } from './judgeConfig';
|
||||
import FileUtils from '../../../utils/FileUtils';
|
||||
import {VideoConfig} from '../../../model/Common'
|
||||
import { VideoConfig } from '../../../model/Common';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
export default class FilePhoto {
|
||||
private params: VideoConfig
|
||||
private context:common.UIAbilityContext
|
||||
private params!: VideoConfig
|
||||
private context!: common.UIAbilityContext
|
||||
public getPhoto = async () => {
|
||||
if (!JudgeConfig.isPhotoOpen) {
|
||||
return ''
|
||||
@ -27,7 +27,6 @@ export default class FilePhoto {
|
||||
}
|
||||
}
|
||||
}
|
||||
private fileUtil: FileUtils
|
||||
|
||||
constructor(context: common.UIAbilityContext) {
|
||||
(async () => {
|
||||
@ -45,7 +44,6 @@ export default class FilePhoto {
|
||||
pztd: config.pztd,
|
||||
}
|
||||
this.context = context
|
||||
this.fileUtil = fileUtil
|
||||
})()
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
|
||||
import record from '@ohos.rtsprecord';
|
||||
import promptAction from '@ohos.promptAction';
|
||||
import { GetCurrentTime, IsDaysAgo } from './Common';
|
||||
import { RecordHandleType, TakePhotoCallbackData, VideoConfig } from '../model';
|
||||
import { RecordHandleType, VideoConfig } from '../model';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import dayTs from './Date';
|
||||
import { GlobalConfig, VideoTag } from '../config';
|
||||
@ -113,7 +113,7 @@ export async function saveStartRecordVideo(path: string, context: common.UIAbili
|
||||
* @param context
|
||||
* @param type=0不获取base64
|
||||
*/
|
||||
interface takePhotoParam {
|
||||
export interface takePhotoParam {
|
||||
name?: string,
|
||||
base64?: string,
|
||||
fileSize?: number,
|
||||
@ -154,46 +154,58 @@ export async function delPic(day: number, type: number, context: common.UIAbilit
|
||||
}
|
||||
}
|
||||
|
||||
export async function takePhoto(param: VideoConfig, context: common.UIAbilityContext, dir: string, flag = 1,
|
||||
callback?: (data: TakePhotoCallbackData) => void): Promise<takePhotoParam | void> {
|
||||
export async function takePhoto(
|
||||
param: VideoConfig,
|
||||
context: common.UIAbilityContext,
|
||||
dir: string,
|
||||
flag = 1,
|
||||
callback?: (data: takePhotoParam) => void
|
||||
): Promise<takePhotoParam> {
|
||||
let video_uri = `rtsp://${param.userName}:${param.pwd}@${param.ip}:${param.port}/h264/ch${param.pztd}/main/av_stream`;
|
||||
|
||||
const num = Math.floor(Math.random() * 10000);
|
||||
const fileName = `picture_record${num}.jpg`;
|
||||
|
||||
if (flag == 0) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
if (flag === 0) {
|
||||
return new Promise<takePhotoParam>((resolve, reject) => {
|
||||
rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err: BusinessError, snapResult: record.RtspResult) => {
|
||||
if (snapResult && snapResult.errorCode === 0) {
|
||||
if (callback) {
|
||||
callback({
|
||||
const result: takePhotoParam = {
|
||||
fileSize: snapResult.fileSize,
|
||||
errorCode: snapResult.errorCode,
|
||||
});
|
||||
};
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve();
|
||||
resolve(result);
|
||||
} else {
|
||||
promptAction.showToast({
|
||||
message: `拍照失败`,
|
||||
duration: 3000,
|
||||
});
|
||||
reject(err);
|
||||
reject({
|
||||
name: fileName,
|
||||
base64: '',
|
||||
fileSize: 0,
|
||||
errorCode: err ? err.code : -1,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return new Promise<takePhotoParam>(async (resolve, reject) => {
|
||||
return new Promise<takePhotoParam>((resolve, reject) => {
|
||||
const time = GetCurrentTime();
|
||||
const date = time.split(' ')[0];
|
||||
let dirName = dir ? dir : date;
|
||||
const dirName = dir || date;
|
||||
|
||||
rtsp_server.getVideoSnapshot(
|
||||
context,
|
||||
video_uri,
|
||||
fileName,
|
||||
dirName,
|
||||
true,
|
||||
async (err: BusinessError, snapResult: record.RtspResult) => {
|
||||
if (snapResult.result && snapResult.errorCode === 0) {
|
||||
(err: BusinessError, snapResult: record.RtspResult) => {
|
||||
if (snapResult && snapResult.errorCode === 0) {
|
||||
resolve({
|
||||
base64: snapResult.dataString,
|
||||
name: snapResult.fileName,
|
||||
@ -205,7 +217,12 @@ export async function takePhoto(param: VideoConfig, context: common.UIAbilityCon
|
||||
message: `拍照失败`,
|
||||
duration: 3000,
|
||||
});
|
||||
reject(false);
|
||||
reject({
|
||||
name: fileName,
|
||||
base64: '',
|
||||
fileSize: 0,
|
||||
errorCode: err ? err.code : -1,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"meta": {
|
||||
"stableOrder": true
|
||||
},
|
||||
"lockfileVersion": 1,
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@ohos/crypto-js@2.0.3": "@ohos/crypto-js@2.0.3",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user