fix: 更新多个组件中的类型声明和逻辑,提升代码一致性

This commit is contained in:
wangzhongjie 2025-04-09 17:19:49 +08:00
parent 059471385f
commit b98b0ff8c8
7 changed files with 88 additions and 63 deletions

View File

@ -1,13 +1,13 @@
import request from '../utils/Request'; import request from '../utils/Request';
import writeObjectOutNew from './judgeNew'; import writeObjectOutNew from './judgeNew';
import http from '@ohos.net.http'; import http from '@ohos.net.http';
import { MASYSSETTableType, RegulatoryInterfaceParams } from '../model'; import { MASYSSETTableType, RegulatoryInterfaceParams, WuxiExamType } from '../model';
import { GetSyncData } from '../utils/table/Operation'; import { GetSyncData } from '../utils/table/Operation';
import { GetCurrentTime } from '../utils/Common'; import { GetCurrentTime } from '../utils/Common';
import FileUtils from '../utils/FileUtils'; import FileUtils from '../utils/FileUtils';
import common from '@ohos.app.ability.common'; 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, export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath: string,
context: common.UIAbilityContext): Promise<WR> { context: common.UIAbilityContext): Promise<WR> {
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
if (singlePlay) { if (singlePlay) {
return { code: 1 } return { code: 1 }
} }
let JGHOST: string = AppStorage.get<string>("JGHOST") let JGHOST: string = AppStorage.get<string>("JGHOST") || ""
//获取监管接口地址路径 //获取监管接口地址路径
if (!JGHOST) { if (!JGHOST) {
const syssetParams: MASYSSETTableType[] = await GetSyncData<MASYSSETTableType>("MA_SYSSET"); 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 { xtlb, jkxlh, jkid, drvexam } = params;
const isJGNew: boolean = AppStorage.get<boolean>('isJGNew') const isJGNew: boolean = AppStorage.get<boolean>('isJGNew') || false
//新监管调用 //新监管调用
if (isJGNew) { if (isJGNew) {
return await writeObjectOutNew(params, filePath, context) 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) const drvexamArrs = Reflect.ownKeys(params.drvexam)
.filter(dKey => params.drvexam[dKey] != undefined) .filter(dKey => Reflect.get(params.drvexam, dKey) != undefined)
.map((key: string) => ( .map((key: string) => (
`<${key}>${params.drvexam[key]}</${key}>`)); `<${key}>${Reflect.get(params.drvexam, key)}</${key}>`));
if (filePath) { if (filePath) {
const fileUtil = new FileUtils(globalThis.context); const fileUtil = new FileUtils(context);
await fileUtil.initFolder(filePath); await fileUtil.initFolder(filePath);
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify({
let obj: WuxiExamType = {
xtlb: params.xtlb, xtlb: params.xtlb,
jkxlh: params.jkxlh, jkxlh: params.jkxlh,
jkid: params.jkid, jkid: params.jkid,
drvexam: { ...params.drvexam, zp: '' }, drvexam: {
}) + `\n`); zp: "",
},
}
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(obj) + `\n`);
} }
//对象转换成xml //对象转换成xml
@ -108,7 +114,7 @@ export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath
xml: true xml: true
},) },)
if (filePath) { if (filePath) {
const fileUtil = new FileUtils(globalThis.context); const fileUtil = new FileUtils(context);
await fileUtil.initFolder(filePath); await fileUtil.initFolder(filePath);
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`); fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`);
} }
@ -134,7 +140,6 @@ interface UploadExamProgressDataParams {
// 过程文件上传 // 过程文件上传
export async function uploadExamProgressData(params: UploadExamProgressDataParams) { export async function uploadExamProgressData(params: UploadExamProgressDataParams) {
// const singlePlay = globalThis.singlePlay
const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
if (singlePlay) { if (singlePlay) {
return return
@ -257,7 +262,7 @@ export async function uploadExamGrade(params: ESObject) {
function validateIP(path: string) { function validateIP(path: string) {
const reg = new RegExp(`(\w+):\/\/([^/:]+)(:\d*)?`) const reg = new RegExp(`(\w+):\/\/([^/:]+)(:\d*)?`)
const result = path.match(reg); const result = path.match(reg);
return result[0] return result ? result[0] : "";
} }
// 上传运行时常 // 上传运行时常

View File

@ -32,8 +32,8 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams,
context: common.UIAbilityContext): Promise<WR> { context: common.UIAbilityContext): Promise<WR> {
// const context: common.UIAbilityContext = AppStorage.get('context') // const context: common.UIAbilityContext = AppStorage.get('context')
const fileUtil = new FileUtils(context); const fileUtil = new FileUtils(context);
const basic = await getBasicConfig(data.jkid); const basic = await getBasicConfig(data.jkid || "");
const params = await getParams(data.jkid, data.drvexam); const params = await getParams(data.jkid || "", data.drvexam ?? {} as DrvexamType);
if (filePath) { if (filePath) {
let examData: WuxiExamType = { let examData: WuxiExamType = {
@ -44,7 +44,7 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams,
sjbs: basic.sjbs, sjbs: basic.sjbs,
data: params.data, data: params.data,
file: { file: {
sjbs: params.file.sjbs, sjbs: params?.file?.sjbs || "",
// params: [] // params: []
} }
} }
@ -55,7 +55,7 @@ export default async function writeObjectOutNew(data: RegulatoryInterfaceParams,
console.info('surenjun', '调用新监管') console.info('surenjun', '调用新监管')
let temp: WR let temp: WR
try { try {
const JGHOST: string = AppStorage.get<string>('JGHOST') const JGHOST: string = AppStorage.get<string>('JGHOST') || ""
temp = await request<WR>({ temp = await request<WR>({
host: JGHOST, host: JGHOST,
method: http.RequestMethod.POST, 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> { export async function getParams(jkid: string, drvexam: DrvexamType): Promise<GetJudgeParamsType> {
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')! const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
const examSubject: string = carInfo.examSubject; const examSubject: string = carInfo.examSubject || "2";
switch (jkid) { switch (jkid) {
//开始考试 //开始考试
case '17C51': case '17C51':
@ -104,7 +104,7 @@ export async function getParams(jkid: string, drvexam: DrvexamType): Promise<Get
sjbs: gjxlhObj[jkid], sjbs: gjxlhObj[jkid],
param: { param: {
sfzmhm: drvexam.sfzmhm, sfzmhm: drvexam.sfzmhm,
kchp: decodeURI(drvexam.kchp), kchp: decodeURI(drvexam.kchp || ""),
kskm: examSubject.toString(), kskm: examSubject.toString(),
ksxl: examSubject == "3" ? drvexam.ksxl : undefined, ksxl: examSubject == "3" ? drvexam.ksxl : undefined,
kssj: drvexam.kssj kssj: drvexam.kssj
@ -130,7 +130,7 @@ export async function getParams(jkid: string, drvexam: DrvexamType): Promise<Get
sfzmhm: drvexam.sfzmhm, sfzmhm: drvexam.sfzmhm,
kskm: drvexam.kskm, kskm: drvexam.kskm,
ksxl: examSubject == "3" ? drvexam.ksxl : undefined, ksxl: examSubject == "3" ? drvexam.ksxl : undefined,
kchp: decodeURI(drvexam.kchp), kchp: decodeURI(drvexam.kchp || ""),
//TODO 待验证 科目三无 //TODO 待验证 科目三无
sbbh: examSubject == "3" ? undefined : drvexam.sbxh, sbbh: examSubject == "3" ? undefined : drvexam.sbxh,
kssj: drvexam.kssj, kssj: drvexam.kssj,
@ -148,7 +148,7 @@ export async function getParams(jkid: string, drvexam: DrvexamType): Promise<Get
data: { data: {
sjbs: gjxlhObj[jkid], sjbs: gjxlhObj[jkid],
param: { param: {
kffs: drvexam.kffs.toString(), kffs: drvexam?.kffs?.toString(),
kfsj: drvexam.kfsj, kfsj: drvexam.kfsj,
kfxm: drvexam.kfxm, kfxm: drvexam.kfxm,
kfxmmx: drvexam.kfxmmx, kfxmmx: drvexam.kfxmmx,
@ -223,11 +223,13 @@ export async function getParams(jkid: string, drvexam: DrvexamType): Promise<Get
//获取基础信息 //获取基础信息
async function getBasicConfig(jkid: string): Promise<WuxiExamType> { async function getBasicConfig(jkid: string): Promise<WuxiExamType> {
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')! 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'); const syssetParam: MASYSSETTableType[] = await GetSyncData<MASYSSETTableType>('MA_SYSSET');
let syssetObj: Record<string, string> = {}; let syssetObj: Record<string, string> = {};
syssetParam.forEach(sys => { 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 = { let obj: WuxiExamType = {
//外挂类别 //外挂类别

View File

@ -807,13 +807,16 @@ export interface WR {
// 无锡所数据 // 无锡所数据
export interface WuxiExamType { export interface WuxiExamType {
wglb: string wglb?: string
jkxlh: string, jkxlh?: string,
glbm: string, glbm?: string,
jgbh: string, jgbh?: string,
sjbs: string, sjbs?: string,
xtlb?: string
jkid?: string
data?: JudgeData, data?: JudgeData,
file?: JudgeFile file?: JudgeFile
drvexam?: DrvexamType
} }

View File

@ -8,7 +8,7 @@ import { CarInfoType, UDPParamType, VideoConfig } from '../../model';
import { NumberToByteArray } from '../../utils/Common'; import { NumberToByteArray } from '../../utils/Common';
import FileUtils from '../../utils/FileUtils'; import FileUtils from '../../utils/FileUtils';
import { CenterUDPClientInstance } from '../../utils/business/CenterUdpBusiness'; import { CenterUDPClientInstance } from '../../utils/business/CenterUdpBusiness';
import { takePhoto } from '../../utils/Video'; import { takePhoto, takePhotoParam } from '../../utils/Video';
import { voiceService } from '../../utils/Voice'; import { voiceService } from '../../utils/Voice';
interface ParamType { interface ParamType {
@ -189,11 +189,11 @@ export default struct FaceCompare {
async faceComparFn() { async faceComparFn() {
console.log('mmmmm0', 2) console.log('mmmmm0', 2)
this.param.pztd = this.param.rlls 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 || "") this.base64 = this.imageBase64 + (data?.base64 || "")
console.log('mmmmt', this.base64) console.log('mmmmt', this.base64)
faceCompare({ faceCompare({
sfzh: this.sfzh, sfzh: this.sfzh.toString(),
firstImage: this.firstImage.substr(22), firstImage: this.firstImage.substr(22),
secondImage: data?.base64 || "", secondImage: data?.base64 || "",
type: "2", type: "2",

View File

@ -2,12 +2,12 @@ import { takePhoto } from '../../../utils/Video';
import promptAction from '@ohos.promptAction'; import promptAction from '@ohos.promptAction';
import { JudgeConfig } from './judgeConfig'; import { JudgeConfig } from './judgeConfig';
import FileUtils from '../../../utils/FileUtils'; import FileUtils from '../../../utils/FileUtils';
import {VideoConfig} from '../../../model/Common' import { VideoConfig } from '../../../model/Common';
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
export default class FilePhoto { export default class FilePhoto {
private params: VideoConfig private params!: VideoConfig
private context:common.UIAbilityContext private context!: common.UIAbilityContext
public getPhoto = async () => { public getPhoto = async () => {
if (!JudgeConfig.isPhotoOpen) { if (!JudgeConfig.isPhotoOpen) {
return '' return ''
@ -27,9 +27,8 @@ export default class FilePhoto {
} }
} }
} }
private fileUtil: FileUtils
constructor(context:common.UIAbilityContext) { constructor(context: common.UIAbilityContext) {
(async () => { (async () => {
//TODO 309参数 获取拍照摄像头拍照通道 //TODO 309参数 获取拍照摄像头拍照通道
const fileUtil = new FileUtils(context) const fileUtil = new FileUtils(context)
@ -37,15 +36,14 @@ export default class FilePhoto {
await fileUtil.readFile('/mnt/hmdfs/100/account/device_view/local/files/duolun/config/config3.txt'); await fileUtil.readFile('/mnt/hmdfs/100/account/device_view/local/files/duolun/config/config3.txt');
const config: VideoConfig = JSON.parse(strConfig as string) const config: VideoConfig = JSON.parse(strConfig as string)
this.params = { this.params = {
userName:config.userName, userName: config.userName,
pwd:config.pwd, pwd: config.pwd,
ip:config.ip, ip: config.ip,
port:config.port, port: config.port,
rlls:config.rlls, rlls: config.rlls,
pztd:config.pztd, pztd: config.pztd,
} }
this.context = context this.context = context
this.fileUtil = fileUtil
})() })()
} }
} }

View File

@ -3,7 +3,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
import record from '@ohos.rtsprecord'; import record from '@ohos.rtsprecord';
import promptAction from '@ohos.promptAction'; import promptAction from '@ohos.promptAction';
import { GetCurrentTime, IsDaysAgo } from './Common'; import { GetCurrentTime, IsDaysAgo } from './Common';
import { RecordHandleType, TakePhotoCallbackData, VideoConfig } from '../model'; import { RecordHandleType, VideoConfig } from '../model';
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import dayTs from './Date'; import dayTs from './Date';
import { GlobalConfig, VideoTag } from '../config'; import { GlobalConfig, VideoTag } from '../config';
@ -113,7 +113,7 @@ export async function saveStartRecordVideo(path: string, context: common.UIAbili
* @param context * @param context
* @param type=0不获取base64 * @param type=0不获取base64
*/ */
interface takePhotoParam { export interface takePhotoParam {
name?: string, name?: string,
base64?: string, base64?: string,
fileSize?: number, 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, export async function takePhoto(
callback?: (data: TakePhotoCallbackData) => void): Promise<takePhotoParam | void> { 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`; 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 num = Math.floor(Math.random() * 10000);
const fileName = `picture_record${num}.jpg`; const fileName = `picture_record${num}.jpg`;
if (flag == 0) { if (flag === 0) {
return new Promise<void>((resolve, reject) => { return new Promise<takePhotoParam>((resolve, reject) => {
rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err: BusinessError, snapResult: record.RtspResult) => { rtsp_server.detectVideoSnapshotSize(video_uri, fileName, (err: BusinessError, snapResult: record.RtspResult) => {
if (snapResult && snapResult.errorCode === 0) { if (snapResult && snapResult.errorCode === 0) {
if (callback) { const result: takePhotoParam = {
callback({
fileSize: snapResult.fileSize, fileSize: snapResult.fileSize,
errorCode: snapResult.errorCode, errorCode: snapResult.errorCode,
}); };
if (callback) {
callback(result);
} }
resolve(); resolve(result);
} else { } else {
promptAction.showToast({ promptAction.showToast({
message: `拍照失败`, message: `拍照失败`,
duration: 3000, duration: 3000,
}); });
reject(err); reject({
name: fileName,
base64: '',
fileSize: 0,
errorCode: err ? err.code : -1,
});
} }
}); });
}); });
} else { } else {
return new Promise<takePhotoParam>(async (resolve, reject) => { return new Promise<takePhotoParam>((resolve, reject) => {
const time = GetCurrentTime(); const time = GetCurrentTime();
const date = time.split(' ')[0]; const date = time.split(' ')[0];
let dirName = dir ? dir : date; const dirName = dir || date;
rtsp_server.getVideoSnapshot( rtsp_server.getVideoSnapshot(
context, context,
video_uri, video_uri,
fileName, fileName,
dirName, dirName,
true, true,
async (err: BusinessError, snapResult: record.RtspResult) => { (err: BusinessError, snapResult: record.RtspResult) => {
if (snapResult.result && snapResult.errorCode === 0) { if (snapResult && snapResult.errorCode === 0) {
resolve({ resolve({
base64: snapResult.dataString, base64: snapResult.dataString,
name: snapResult.fileName, name: snapResult.fileName,
@ -205,7 +217,12 @@ export async function takePhoto(param: VideoConfig, context: common.UIAbilityCon
message: `拍照失败`, message: `拍照失败`,
duration: 3000, duration: 3000,
}); });
reject(false); reject({
name: fileName,
base64: '',
fileSize: 0,
errorCode: err ? err.code : -1,
});
} }
} }
); );

View File

@ -2,7 +2,7 @@
"meta": { "meta": {
"stableOrder": true "stableOrder": true
}, },
"lockfileVersion": 1, "lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": { "specifiers": {
"@ohos/crypto-js@2.0.3": "@ohos/crypto-js@2.0.3", "@ohos/crypto-js@2.0.3": "@ohos/crypto-js@2.0.3",