42 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
		
		
			
		
	
	
			42 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| 
								 | 
							
								import common from "@ohos.app.ability.common";
							 | 
						||
| 
								 | 
							
								import FileUtil from "../../common/utils/File";
							 | 
						||
| 
								 | 
							
								import { GlobalConfig } from "../../config";
							 | 
						||
| 
								 | 
							
								import Prompt from "@system.prompt";
							 | 
						||
| 
								 | 
							
								import { CarConfigurationParamsType, ObtainCarExamInfoParams } from "../../model";
							 | 
						||
| 
								 | 
							
								import dayTs from "../../utils/Date";
							 | 
						||
| 
								 | 
							
								import { obtainCarExamInfo } from "../../api";
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//获取设备信息
							 | 
						||
| 
								 | 
							
								export async function GetDeviceInfo(context: common.UIAbilityContext): Promise<string> {
							 | 
						||
| 
								 | 
							
								  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) {
							 | 
						||
| 
								 | 
							
								      Prompt.showToast({
							 | 
						||
| 
								 | 
							
								        message: "请先进行设备注册!",
							 | 
						||
| 
								 | 
							
								        duration: 3000
							 | 
						||
| 
								 | 
							
								      })
							 | 
						||
| 
								 | 
							
								      AppStorage.setOrCreate('type', 1)
							 | 
						||
| 
								 | 
							
								      AppStorage.setOrCreate('title', '请先进行设备注册')
							 | 
						||
| 
								 | 
							
								      resolve("")
							 | 
						||
| 
								 | 
							
								    } else {
							 | 
						||
| 
								 | 
							
								      const fileData: CarConfigurationParamsType = JSON.parse(data)
							 | 
						||
| 
								 | 
							
								      AppStorage.setOrCreate('deviceNo', fileData.deviceName)
							 | 
						||
| 
								 | 
							
								      resolve(fileData.deviceName)
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  })
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								export async function GetCarInfo() {
							 | 
						||
| 
								 | 
							
								  let date = new Date();
							 | 
						||
| 
								 | 
							
								  let params: ObtainCarExamInfoParams = {
							 | 
						||
| 
								 | 
							
								    time: dayTs(date).format("YYYY-MM-DD HH:mm:ss"),
							 | 
						||
| 
								 | 
							
								    deviceNo: AppStorage.get('deviceNo')
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								  let res: ESObject = await obtainCarExamInfo(params)
							 | 
						||
| 
								 | 
							
								  if (res.obtainCarExamInfoRsp.body) {
							 | 
						||
| 
								 | 
							
								    const carInfo: ESObject = res?.obtainCarExamInfoRsp?.body
							 | 
						||
| 
								 | 
							
								    carInfo.plateNo = decodeURIComponent(carInfo.plateNo)
							 | 
						||
| 
								 | 
							
								    AppStorage.setOrCreate('carInfo', carInfo)
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 |