144 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			144 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| import { registrationDeviceNo } from '../api/checkCar'
 | |
| import deviceManager from '@ohos.distributedHardware.deviceManager'
 | |
| 
 | |
| import common from '@ohos.app.ability.common'
 | |
| import { ApiResponseType, DeviceParamType } from '../model'
 | |
| import dayTs from '../utils/Date'
 | |
| import FileUtils from '../utils/FileUtils'
 | |
| import Prompt from '@system.prompt'
 | |
| import { dConsole } from '../utils/LogWorker'
 | |
| import HeaderComponent from './compontents/Header'
 | |
| 
 | |
| @Entry
 | |
| @Component
 | |
| struct RegisterPage {
 | |
|   @State ratio: number = 1700 / 960
 | |
|   @State ip: string = ''
 | |
|   @State deviceNo: string = ''
 | |
|   @State deviceName: string = ''
 | |
|   @State checked: string = '0'
 | |
|   @State plateNo: string = ''
 | |
|   @State @Watch('outClick') outFlag: boolean = false;
 | |
|   @State subType: string = '2';
 | |
|   private context = getContext(this) as common.UIAbilityContext;
 | |
| 
 | |
|   onPageShow() {
 | |
|     dConsole.log('createDeviceManagerstart')
 | |
|     try {
 | |
|       deviceManager.createDeviceManager('com.oh.dts', (error: string, value: deviceManager.DeviceManager) => {
 | |
|         if (error) {
 | |
|           dConsole.error('createDeviceManager failed.');
 | |
|           return;
 | |
|         }
 | |
|         this.deviceName = value.getLocalDeviceInfoSync().deviceName
 | |
|         this.deviceNo = value.getLocalDeviceInfoSync().deviceId.substring(0, 10).toUpperCase()
 | |
|         this.ip = 'MAC-' + this.deviceNo
 | |
|         AppStorage.SetOrCreate('deviceNo', 'MAC-' + this.deviceNo)
 | |
|       });
 | |
| 
 | |
|     } catch (error) {
 | |
|       dConsole.log('createDeviceManagererror', error)
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   build() {
 | |
|     Column() {
 | |
|       HeaderComponent({
 | |
|         shortLogo: true,
 | |
|         shouBackArea: true
 | |
|       })
 | |
|       Column() {
 | |
|         Row() {
 | |
|           Row() {
 | |
|             Radio({ value: '0', group: 'radioGroup' }).checked(this.subType == '2' ? true : false)
 | |
|               .height(50)
 | |
|               .width(50).onChange((isChecked: boolean) => {
 | |
|               if (isChecked) {
 | |
|                 this.subType = '2'
 | |
|               }
 | |
|               this.ip = 'MAC-' + this.deviceNo
 | |
|               AppStorage.setOrCreate('deviceNo', this.ip)
 | |
| 
 | |
|             })
 | |
|             Text('网卡').fontSize(34 * this.ratio).fontColor('#FFE0B2').margin({ right: 98.5 * this.ratio })
 | |
|           }
 | |
| 
 | |
|           Row() {
 | |
|             Radio({ value: '1', group: 'radioGroup' }).checked(this.subType == '3' ? true : false)
 | |
|               .height(50)
 | |
|               .width(50).onChange((isChecked: boolean) => {
 | |
|               if (isChecked) {
 | |
|                 this.subType = '3'
 | |
|               }
 | |
|               this.ip = 'DISK-' + this.deviceNo
 | |
|               AppStorage.setOrCreate('deviceNo', this.ip)
 | |
|               // this.ip = ip
 | |
|             })
 | |
|             Text('硬盘').fontSize(34 * this.ratio).fontColor('#FFE0B2').margin({ right: 83 * this.ratio })
 | |
|           }
 | |
|         }.margin({ top: 35 * this.ratio })
 | |
| 
 | |
|         Row() {
 | |
|           Column() {
 | |
|             Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
 | |
|               Text(this.ip).fontColor('#fff')
 | |
|                 .fontSize(33.6 * this.ratio)
 | |
|             }
 | |
|             .width('100%')
 | |
|             .height('100%')
 | |
|             .padding({ left: 30 * this.ratio, right: 30 * this.ratio })
 | |
|           }
 | |
|           .backgroundImage($r('app.media.xk'))
 | |
|           .backgroundImageSize({ width: '100%', height: '100%' })
 | |
|           .width(610 * this.ratio)
 | |
|           .height(108 * this.ratio)
 | |
|           .margin({ left: 22 * this.ratio })
 | |
| 
 | |
|         }.margin({ top: 30 * this.ratio })
 | |
|       }
 | |
|       .width(720 * this.ratio)
 | |
|       .height(310 * this.ratio)
 | |
|       .backgroundColor('#333230')
 | |
|       .margin({ top: 37 * this.ratio })
 | |
|       .borderRadius(19 * this.ratio)
 | |
| 
 | |
|       Image($r('app.media.zhuce_nor'))
 | |
|         .width(320 * this.ratio)
 | |
|         .height(92 * this.ratio)
 | |
|         .margin({ top: 30 * this.ratio })
 | |
|         .onClick(() => {
 | |
|           this.registrationDeviceNoFn()
 | |
|         })
 | |
|     }
 | |
|     .height('100%')
 | |
|     .width('100%')
 | |
|     .backgroundImage($r('app.media.bg'))
 | |
|     .backgroundImageSize({ width: '100%', height: '100%' })
 | |
|   }
 | |
| 
 | |
|   outClick() {
 | |
|   }
 | |
| 
 | |
|   async registrationDeviceNoFn() {
 | |
|     const date = new Date()
 | |
|     const param: DeviceParamType = {
 | |
|       time: dayTs(date).format("YYYY-MM-DD HH:mm:ss"),
 | |
|       deviceName: this.ip,
 | |
|       type: '1'
 | |
|     }
 | |
|     const fileUtil = new FileUtils(this.context)
 | |
|     const folderPath = await fileUtil.initFolder(`/config`);
 | |
|     fileUtil.addFile(`${folderPath}/deviceNo.txt`, JSON.stringify(param))
 | |
|     AppStorage.setOrCreate<string>('deviceNo', this.ip)
 | |
|     registrationDeviceNo(param).then((res: ApiResponseType) => {
 | |
|       if (res.registrationDeviceNoRsp && res.registrationDeviceNoRsp.head &&
 | |
|         res.registrationDeviceNoRsp.head.resultCode == '0') {
 | |
|         Prompt.showToast({
 | |
|           message: decodeURIComponent(res.registrationDeviceNoRsp.head.resultMessage),
 | |
|           duration: 3000
 | |
|         });
 | |
|       }
 | |
|     })
 | |
|   }
 | |
| }
 |