subject-two/entry/src/main/ets/common/service/terminalService.ts

52 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-01-05 11:11:15 +08:00
// @ts-nocheck
2024-07-17 10:19:16 +08:00
import { obtainCarExamInfo } from '../../api/index'
import { dateFormat } from '../utils/tools'
2024-03-12 15:32:48 +08:00
import router from '@ohos.router'
2024-08-10 14:00:18 +08:00
import promptAction from '@ohos.promptAction'
2024-08-14 09:18:33 +08:00
import { getSyncData } from '../../common/service/initable'
2024-07-17 10:19:16 +08:00
import { GlobalConfig } from '../../config/index'
import FileUtil from '../../common/utils/File'
2024-01-05 11:11:15 +08:00
//获取设备信息
2024-07-17 10:19:16 +08:00
export async function getDeviceInfo(context) {
return new Promise(async (resolve, reject) => {
const fileUtil = new FileUtil(context)
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/deviceNo.txt');
if (data === '' || data === undefined) {
2024-08-10 14:00:18 +08:00
promptAction.showToast({
message: `请先进行设备注册`,
duration: 3000
});
2024-08-26 16:00:45 +08:00
globalThis.type='1'
globalThis.title=decodeURIComponent('请先进行设备注册')
globalThis.errorDialog.open()
2024-07-17 10:19:16 +08:00
resolve('')
} else {
2024-08-14 09:18:33 +08:00
const fileData=JSON.parse(data)
2024-07-17 10:19:16 +08:00
globalThis.deviceNo = fileData.deviceName
2024-08-14 14:46:33 +08:00
console.log('globalThis.deviceNo', globalThis.deviceNo)
// getCarInfo()
2024-07-17 10:19:16 +08:00
resolve(fileData.deviceName)
}
})
2024-01-05 11:11:15 +08:00
}
//获取考车信息
export async function getCarInfo() {
2024-07-17 10:19:16 +08:00
let date = new Date();
2024-08-14 14:46:33 +08:00
console.log('globalThis.carInfo2222', globalThis.deviceNo)
2024-07-17 10:19:16 +08:00
let params = { time: dateFormat(date), deviceNo: globalThis.deviceNo };
let res: any = await obtainCarExamInfo(params)
if (!res?.obtainCarExamInfoRsp?.body) {
// router.pushUrl({
// url: 'pages/Register',
// }, router.RouterMode.Single);
} else {
globalThis.carInfo = res.obtainCarExamInfoRsp.body
2024-08-14 14:46:33 +08:00
console.log('globalThis.carInfo2222', JSON.stringify(res));
2024-07-17 10:19:16 +08:00
// globalThis.carInfo.carId=res.obtainCarExamInfoRsp.body.carId
globalThis.carInfo.plateNo = decodeURIComponent(globalThis.carInfo.plateNo)
}
return res
2024-01-05 11:11:15 +08:00
}