fix: 优化多个组件中的代码逻辑和类型声明,提升代码一致性
This commit is contained in:
parent
63f4248e9f
commit
a4cb423722
@ -9,6 +9,7 @@ import { BusinessError } from '@ohos.base';
|
||||
import { voiceService } from '../utils/Voice';
|
||||
import dayTs from '../utils/Date';
|
||||
import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
@ -41,27 +42,28 @@ struct Index {
|
||||
@State stopFlag: boolean = false
|
||||
@State fromIndex: boolean = false
|
||||
@State carInfo: CarInfoType = {}
|
||||
private vocObj: voiceService;
|
||||
private vocObj?: voiceService;
|
||||
private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext
|
||||
|
||||
// private AccountTable = new AccountTable(()=>{},CommonConstants);
|
||||
aboutToAppear() {
|
||||
const that = this
|
||||
this.carInfo = AppStorage.get<CarInfoType>('carInfo')
|
||||
this.vocObj = new voiceService(async (status: string, val: string) => {
|
||||
if (!that.breakFlag) {
|
||||
return
|
||||
this.carInfo = AppStorage.get<CarInfoType>('carInfo')!
|
||||
this.vocObj = new voiceService(async (status: string, val?: string) => {
|
||||
if (!that.breakFlag || !val) {
|
||||
return;
|
||||
}
|
||||
if (status == 'idle') {
|
||||
if (val == 'kszj.wav') {
|
||||
console.log('finsh')
|
||||
this.initfackCheck(0)
|
||||
console.log('finsh');
|
||||
this.initfackCheck(0);
|
||||
// this.getCheckList(true)
|
||||
} else {
|
||||
this.subFlag = false
|
||||
this.getNextNode()
|
||||
this.subFlag = false;
|
||||
this.getNextNode();
|
||||
}
|
||||
}
|
||||
});
|
||||
}, this.context);
|
||||
let routParam: RouteParamsType = router.getParams() as RouteParamsType;
|
||||
this.fromIndex = routParam?.fromIndex || false
|
||||
this.carConfigurationInfoFn()
|
||||
@ -107,8 +109,8 @@ struct Index {
|
||||
}
|
||||
|
||||
async xhxs() {
|
||||
this.vocObj.avPlayerStop()
|
||||
this.vocObj.releasePlayer()
|
||||
this.vocObj!.avPlayerStop()
|
||||
this.vocObj!.releasePlayer()
|
||||
router.pushUrl({
|
||||
url: 'pages/SignDisplay',
|
||||
}, router.RouterMode.Single);
|
||||
@ -141,8 +143,8 @@ struct Index {
|
||||
//模拟真实数据
|
||||
const param: CarConfigurationParams = {
|
||||
body: {
|
||||
"carIdString": this.carInfo.carId, //考车ID
|
||||
"deviceNo": baseInfo.deviceNo
|
||||
"carIdString": this.carInfo.carId || "", //考车ID
|
||||
"deviceNo": baseInfo.deviceNo || ""
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,7 +174,7 @@ struct Index {
|
||||
this.warnFlag = JSON.parse(JSON.stringify(WarnFlagData))
|
||||
this.passArray = JSON.parse(JSON.stringify(PassData))
|
||||
this.index = this.checkListCopy[0].key
|
||||
this.vocObj.playAudio({
|
||||
this.vocObj!.playAudio({
|
||||
type: 1,
|
||||
name: 'kszj.wav'
|
||||
})
|
||||
@ -272,7 +274,7 @@ struct Index {
|
||||
flag = true;
|
||||
}
|
||||
});
|
||||
this.vocObj.playAudio({
|
||||
this.vocObj!.playAudio({
|
||||
type: 1,
|
||||
name: flag ? 'zjwtg.wav' : 'zjtg.wav'
|
||||
})
|
||||
@ -325,7 +327,7 @@ struct Index {
|
||||
// if (!flag) {
|
||||
// that.warnFlag[index] = '2';
|
||||
// }
|
||||
const spzd: SpzdType = AppStorage.get('spzd');
|
||||
const spzd: SpzdType = AppStorage.get('spzd')!;
|
||||
const hasTruthyValue = Object.values(spzd).some((value: string) => value);
|
||||
that.warnFlag[index] = hasTruthyValue ? '1' : '2';
|
||||
} else {
|
||||
@ -358,7 +360,7 @@ struct Index {
|
||||
name,
|
||||
})
|
||||
} else {
|
||||
this.vocObj.playAudio({
|
||||
this.vocObj!.playAudio({
|
||||
type: 1,
|
||||
name,
|
||||
})
|
||||
|
||||
@ -312,7 +312,7 @@ export default struct FaceCompare {
|
||||
this.showFaceCompareFlag = !this.showFaceCompareFlag
|
||||
}
|
||||
}
|
||||
});
|
||||
}, this.context);
|
||||
|
||||
const data = await this.fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt');
|
||||
console.log('faceEnterIn,data', data)
|
||||
|
||||
@ -14,8 +14,10 @@ export class voiceService {
|
||||
private endFlag: Boolean = false;
|
||||
private mediaArray: Array<string> = [];
|
||||
private callBack: AVPlayerCallback | null = null;
|
||||
private context: common.UIAbilityContext
|
||||
|
||||
constructor(callBack: AVPlayerCallback) {
|
||||
constructor(callBack: AVPlayerCallback, context: common.UIAbilityContext) {
|
||||
this.context = context
|
||||
// 创建avPlayer实例对象
|
||||
media.createAVPlayer().then(video => {
|
||||
this.avPlayer = video
|
||||
@ -96,11 +98,7 @@ export class voiceService {
|
||||
|
||||
// 以下为使用资源管理接口获取打包在HAP内的媒体资源文件并通过fdSrc属性进行播放示例
|
||||
avPlayerFdSrc(name: string) {
|
||||
const context: common.UIAbilityContext = AppStorage.get('context')
|
||||
if (!context) {
|
||||
console.log(VoiceTag, ' context is null');
|
||||
return
|
||||
}
|
||||
const context = this.context
|
||||
context.resourceManager.getRawFd(name, async (error, value) => {
|
||||
if (error != null) {
|
||||
console.log(VoiceTag, ` callback getRawFd failed error code: ${error.code}, message: ${error.message}.`);
|
||||
@ -141,16 +139,16 @@ export class voiceService {
|
||||
playAudio(param: playParams) {
|
||||
this.endFlag = false
|
||||
this.mediaArray = []
|
||||
this.type = param.type
|
||||
this.type = param.type ?? 1;
|
||||
if (param.type == 1) {
|
||||
this.playerName = param.name
|
||||
this.playerName = param.name || ""
|
||||
// this.nextPlayerName=param.nextName
|
||||
this.avPlayerFdSrc(param.name);
|
||||
this.avPlayerFdSrc(param.name || "");
|
||||
} else if (param.type == 2) {
|
||||
this.avPlayerLive(param.url);
|
||||
this.avPlayerLive(param.url!);
|
||||
} else if (param.type == 3) {
|
||||
if (param.value.length) {
|
||||
this.mediaArray = param.value
|
||||
if (param.value && param.value.length) {
|
||||
this.mediaArray = param.value;
|
||||
this.avPlayerFdSrc(param.value[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,89 +5,12 @@ import UdpClient from '../UdpUtils'
|
||||
// 获取PLC GPS信号
|
||||
class ObtainUdpBusiness {
|
||||
// 三代机UDP
|
||||
private thirdGenerationMachineUdp: UdpClient
|
||||
private thirdGenerationMachineUdp?: UdpClient
|
||||
// 几代机
|
||||
private modelNo: string = "3"
|
||||
|
||||
constructor() {
|
||||
this.modelNo = GlobalConfig.modelNo
|
||||
}
|
||||
|
||||
private initSecondaryBoard() {
|
||||
|
||||
}
|
||||
|
||||
private initFirstGeneration() {
|
||||
|
||||
}
|
||||
|
||||
private initSecondGeneration() {
|
||||
|
||||
}
|
||||
|
||||
private initThirdGeneration() {
|
||||
let config: EnvironmentConfigurationType =
|
||||
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
|
||||
this.thirdGenerationMachineUdp = new UdpClient()
|
||||
this.thirdGenerationMachineUdp.create(config.udplocalIp, config.udplocalIpPort, config.udpOppositeIp,
|
||||
config.udpOppositeIpPort)
|
||||
this.thirdGenerationMachineUdp.setDealMethod(this.dealThirdGenerationMsg)
|
||||
}
|
||||
|
||||
private dealSecondaryBoardMsg() {
|
||||
|
||||
}
|
||||
|
||||
private dealFirstGenerationMsg() {
|
||||
|
||||
}
|
||||
|
||||
private dealSecondGenerationMsg() {
|
||||
|
||||
}
|
||||
|
||||
private dealThirdGenerationMsg(data: ArrayBuffer) {
|
||||
const dataView = new DataView(data);
|
||||
let str = ""
|
||||
for (let i = 0; i < dataView?.byteLength; ++i) {
|
||||
let c = String.fromCharCode(dataView?.getUint8(i))
|
||||
if (c !== "\n") {
|
||||
str += c
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
private onSecondaryBoardMsg(cb: Function) {
|
||||
|
||||
}
|
||||
|
||||
private onFirstGenerationMsg(cb: Function) {
|
||||
|
||||
}
|
||||
|
||||
private onSecondGenerationMsg(cb: Function) {
|
||||
|
||||
}
|
||||
|
||||
private onThirdGenerationMsg(cb: Function) {
|
||||
this.thirdGenerationMachineUdp.onMsg(cb)
|
||||
}
|
||||
|
||||
private sendSecondaryBoardMsg(data: string) {
|
||||
|
||||
}
|
||||
|
||||
private sendFirstGenerationMsg(data: string) {
|
||||
|
||||
}
|
||||
|
||||
private sendSecondGenerationMsg(data: string) {
|
||||
|
||||
}
|
||||
|
||||
private sendThirdGenerationMsg(data: string) {
|
||||
this.thirdGenerationMachineUdp.sendMsg(data)
|
||||
this.modelNo = GlobalConfig.modelNo || ""
|
||||
}
|
||||
|
||||
init() {
|
||||
@ -138,7 +61,7 @@ class ObtainUdpBusiness {
|
||||
case "2":
|
||||
break
|
||||
case "3":
|
||||
this.thirdGenerationMachineUdp.offMsg(cb)
|
||||
this.thirdGenerationMachineUdp!.offMsg(cb)
|
||||
break
|
||||
default:
|
||||
break
|
||||
@ -163,6 +86,83 @@ class ObtainUdpBusiness {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
private initSecondaryBoard() {
|
||||
|
||||
}
|
||||
|
||||
private initFirstGeneration() {
|
||||
|
||||
}
|
||||
|
||||
private initSecondGeneration() {
|
||||
|
||||
}
|
||||
|
||||
private initThirdGeneration() {
|
||||
let config: EnvironmentConfigurationType =
|
||||
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
|
||||
this.thirdGenerationMachineUdp = new UdpClient()
|
||||
this.thirdGenerationMachineUdp.create(config.udplocalIp!, config.udplocalIpPort!, config.udpOppositeIp!,
|
||||
config.udpOppositeIpPort!)
|
||||
this.thirdGenerationMachineUdp.setDealMethod(this.dealThirdGenerationMsg)
|
||||
}
|
||||
|
||||
private dealSecondaryBoardMsg() {
|
||||
|
||||
}
|
||||
|
||||
private dealFirstGenerationMsg() {
|
||||
|
||||
}
|
||||
|
||||
private dealSecondGenerationMsg() {
|
||||
|
||||
}
|
||||
|
||||
private dealThirdGenerationMsg(data: ArrayBuffer) {
|
||||
const dataView = new DataView(data);
|
||||
let str = ""
|
||||
for (let i = 0; i < dataView?.byteLength; ++i) {
|
||||
let c = String.fromCharCode(dataView?.getUint8(i))
|
||||
if (c !== "\n") {
|
||||
str += c
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
private onSecondaryBoardMsg(cb: Function) {
|
||||
|
||||
}
|
||||
|
||||
private onFirstGenerationMsg(cb: Function) {
|
||||
|
||||
}
|
||||
|
||||
private onSecondGenerationMsg(cb: Function) {
|
||||
|
||||
}
|
||||
|
||||
private onThirdGenerationMsg(cb: Function) {
|
||||
this.thirdGenerationMachineUdp!.onMsg(cb)
|
||||
}
|
||||
|
||||
private sendSecondaryBoardMsg(data: string) {
|
||||
|
||||
}
|
||||
|
||||
private sendFirstGenerationMsg(data: string) {
|
||||
|
||||
}
|
||||
|
||||
private sendSecondGenerationMsg(data: string) {
|
||||
|
||||
}
|
||||
|
||||
private sendThirdGenerationMsg(data: string) {
|
||||
this.thirdGenerationMachineUdp!.sendMsg(data)
|
||||
}
|
||||
}
|
||||
|
||||
export const ObtainUdpBusinessInstance = new ObtainUdpBusiness()
|
||||
Loading…
x
Reference in New Issue
Block a user