import TopLogo from './compontents/TopLogo'; import Prompt from '@system.prompt'; import FileUtil from '../common/utils/File'; import common from '@ohos.app.ability.common'; import { GlobalConfig } from '../config'; import ethernet from '@ohos.net.ethernet' @Entry @Component struct Index { @State textList1: string[] = ['差分服务器Ip', '响应端口', '中心服务器IP', '响应端口', '子网掩码', '默认网关', 'dns', '后置机IP ', '响应端口', '前置机IP', '本地端口'] // @State textList2: string[] = [] @State ratio: number = 1700 / 960 @State inputFontSize: number = 12 //12 // // @State inputTextList1: string[] = ['192.168.7.170','8084','192.168.7.170','20122','255.255.255.0','192.168.7.1','','','114.114.114.114','112.80.35.83','11055' + // '',] // @State inputTextList2: string[] = ['192.168.7.124','20022'] // @State inputTextList1: string[] = ['172.37.55.191','18782','192.168.7.1','8082','255.255.255.0','192.168.7.170','114.114.114.114','192.168.7.124','20022','172.37.55.59','20122'] @State inputTextList1: string[] = ['172.37.55.191', '18782', '172.37.55.191', '8082', '255.255.255.0', '192.168.7.1', '114.114.114.114', '192.168.7.124', '20022', '192.168.7.170', '20122'] @State terTextList: string[] = ['一型机', '二型机', '三型机', '一体机'] @State cardTextList: string[] = ['北云', '天宝MB2'] @State netTextList: string[] = ['否', '是'] @State deviceTypeSelect: string[] = ['正常', '安全员','新科目三'] @State selectedTerType: number = 0 @State selectedCardType: number = 0 //是否启用网络差分 @State netOpen: number = 0 //设备应用类型 @State deviceType: number = 0 @State deviceIpArr: string[] = ['192.168.7.173', '192.168.7.173'] @State devicePortArr: string[] = ['8052', '8053'] // @State inputTextList2: string[] = [] // 112.80.35.83 11052 // @State inputTextList1: string[] = ['192.168.36.2','8084','192.168.36.200','20122','255.255.255.0','192.168.36.1','','','114.114.114.114','192.168.36.139','8000'] @State @Watch('outClick') outFlag: boolean = false; scroller: Scroller = new Scroller() // @State inputTextList2: string[] = ['192.168.36.139','20022'] private fileUtil: FileUtil private context = getContext(this) as common.UIAbilityContext; private vocObj = null; build() { Column() { TopLogo({ outFlag: $outFlag }) Column() { Column() { Scroll(this.scroller) { Flex({ 'wrap': FlexWrap.Wrap }) { ForEach(this.textList1, (item: string, index: number) => { Row() { Text(item) .width('40%') .height('100%') .fontColor('#E5CBA1') .padding({ 'left': '35px' }) .fontSize(this.inputFontSize * this.ratio) TextInput({ 'text': this.inputTextList1[index] ? this.inputTextList1[index] : '' }) .width('50%') .height('50%') .fontColor('#fff') .borderColor('#E6E0D8') .borderRadius('10px') .borderWidth('2px') .fontSize(this.inputFontSize * this.ratio) .padding({ top: 0, bottom: 0 }) .linearGradient({ angle: 0, colors: [[0x403C36, 0.0], [0x4D473D, 0.34], [0x3D3A34, 1.0]] }) .onChange((value: string) => { this.inputTextList1[index] = value }) }.width('50%').height('14%') }) Row() {}.width('50%').height('14%') Row() { Text('后置机类型') .width('40%') .height('100%') .fontColor('#E5CBA1') .padding({ 'left': '35px' }) .fontSize(this.inputFontSize * this.ratio) ForEach(this.terTextList, (terText, index) => { Radio({ value: terText, group: 'terRadioGroup' }) .borderColor('#E5CBA1') .checked(index === this.selectedTerType) .onChange((value: boolean) => { if(value){ this.selectedTerType = index } }) Text(terText).fontSize(20).fontColor('#FFF') }) }.width('50%').height('14%') Row() { Text('是否启用网络差分') .width('40%') .height('100%') .fontColor('#E5CBA1') .padding({ 'left': '35px' }) .fontSize(this.inputFontSize * this.ratio) ForEach(this.netTextList, (netText, index) => { Radio({ value: netText, group: 'netRadioGroup' }) .borderColor('#E5CBA1') .checked(index === this.netOpen) .onChange((value: boolean) => { if(value){ this.netOpen = index } }) Text(netText).fontSize(20).fontColor('#FFF') }) }.width('51%').height('14%') Row(){ Text('板卡类型') .width('40%') .height('100%') .fontColor('#E5CBA1') .padding({ 'left': '35px' }) .fontSize(this.inputFontSize * this.ratio) ForEach(this.cardTextList, (cardText, index) => { Radio({ value: cardText, group: 'cardRadioGroup' }) .borderColor('#E5CBA1') .checked(index === this.selectedCardType) .onChange((value: boolean) => { if(value){ this.selectedCardType = index } }) Text(cardText).fontSize(20).fontColor('#FFF') }) }.width('49%').height('14%') Row() { Text('设备应用场景') .width('40%') .height('100%') .fontColor('#E5CBA1') .padding({ 'left': '35px' }) .fontSize(this.inputFontSize * this.ratio) ForEach(this.deviceTypeSelect, (netText, index) => { Radio({ value: netText, group: 'deviceRadioGroup' }) .borderColor('#E5CBA1') .checked(index === this.deviceType) .onChange((value: boolean) => { if(value){ this.deviceType = index } }) Text(netText).fontSize(20).fontColor('#FFF') }) }.width('52%').height('14%') // 新科目三设备 if(this.deviceType == 1 || this.deviceType == 2){ Row() { Text('雷达设备IP') .width('40%') .height('100%') .fontColor('#E5CBA1') .padding({ 'left': '35px' }) .fontSize(this.inputFontSize * this.ratio) TextInput({ 'text':this.deviceIpArr[0] }) .width('50%') .height('50%') .fontColor('#fff') .borderColor('#E6E0D8') .borderRadius('10px') .borderWidth('2px') .fontSize(this.inputFontSize * this.ratio) .padding({ top: 0, bottom: 0 }) .linearGradient({angle: 0,colors: [[0x403C36, 0.0], [0x4D473D, 0.34], [0x3D3A34, 1.0]] }) .onChange((value: string) => { this.deviceIpArr[0] = value }) }.width('50%').height('14%') Row() { Text('响应端口') .width('40%') .height('100%') .fontColor('#E5CBA1') .padding({ 'left': '35px' }) .fontSize(this.inputFontSize * this.ratio) TextInput({ 'text':this.devicePortArr[0] }) .width('50%') .height('50%') .fontColor('#fff') .borderColor('#E6E0D8') .borderRadius('10px') .borderWidth('2px') .fontSize(this.inputFontSize * this.ratio) .padding({ top: 0, bottom: 0 }) .linearGradient({ angle: 0, colors: [[0x403C36, 0.0], [0x4D473D, 0.34], [0x3D3A34, 1.0]] }) .onChange((value: string) => { this.devicePortArr[0] = value }) }.width('50%').height('14%') } // 安全员设备 if(this.deviceType == 2){ Row() { Text('视觉设备IP') .width('40%') .height('100%') .fontColor('#E5CBA1') .padding({ 'left': '35px' }) .fontSize(this.inputFontSize * this.ratio) TextInput({ 'text': this.deviceIpArr[1] }) .width('50%') .height('50%') .fontColor('#fff') .borderColor('#E6E0D8') .borderRadius('10px') .borderWidth('2px') .fontSize(this.inputFontSize * this.ratio) .padding({ top: 0, bottom: 0 }) .linearGradient({ angle: 0, colors: [[0x403C36, 0.0], [0x4D473D, 0.34], [0x3D3A34, 1.0]] }) .onChange((value: string) => { this.deviceIpArr[1] = value }) }.width('50%').height('14%') Row() { Text('响应端口') .width('40%') .height('100%') .fontColor('#E5CBA1') .padding({ 'left': '35px' }) .fontSize(this.inputFontSize * this.ratio) TextInput({ 'text': this.devicePortArr[1] }) .width('50%') .height('50%') .fontColor('#fff') .borderColor('#E6E0D8') .borderRadius('10px') .borderWidth('2px') .fontSize(this.inputFontSize * this.ratio) .padding({ top: 0, bottom: 0 }) .linearGradient({ angle: 0, colors: [[0x403C36, 0.0], [0x4D473D, 0.34], [0x3D3A34, 1.0]] }) .onChange((value: string) => { this.devicePortArr[1] = value; }) }.width('50%').height('14%') } } } .width('95%') .height('95%') .margin({ 'top': '1%' }) .backgroundColor('#282828') .borderRadius('15px') } .width('100%') .height('85%') .borderRadius('25px') Column() { Image($r('app.media.terminal_save')).width('18%').onClick(async () => { const fileUtil = new FileUtil(this.context) const folderPath = await fileUtil.initFolder(`/config`); const param = { udplocalIp: this.inputTextList1[9], udplocalIpPort: this.inputTextList1[10], udpOppositeIp: this.inputTextList1[7], udpOppositeIpPort: this.inputTextList1[8], tcplocalIp: this.inputTextList1[9], tcplocalIpPort: '8088', tcpOppositeIp: this.inputTextList1[0], tcpOppositePort: this.inputTextList1[1], netMask: this.inputTextList1[4], gateway: this.inputTextList1[5], dnsServers: this.inputTextList1[6], centerIp: this.inputTextList1[2], centerPort: this.inputTextList1[3], terType: this.selectedTerType, cardType: this.selectedCardType, netOpen: this.netOpen, deviceType: this.deviceType, deviceIpArr: this.deviceIpArr, devicePortArr: this.devicePortArr, } fileUtil.addFile(`${folderPath}/ipConfig.txt`, JSON.stringify(param), '') // upDateTableByArray('IpConfigTable',[]) // @ts-ignore ethernet.setIfaceConfig("eth0", { mode: 0, ipAddr: this.inputTextList1[9], route: "0.0.0.0", gateway: this.inputTextList1[5], //value.gateway网关 netMask: this.inputTextList1[4], //value.netMask网络掩码 dnsServers: this.inputTextList1[6], // @ts-ignore domain: "" }, (error) => { if (error) { Prompt.showToast({ message: '设置失败' + JSON.stringify(error), duration: 3000 }); } else { Prompt.showToast({ message: '设置成功', duration: 3000 }); } }); }) } .backgroundColor('#CCC4B8') .width('100%') .height('15%') .borderRadius({ 'bottomLeft': '25px', 'bottomRight': '25px' }) .justifyContent(FlexAlign.SpaceAround) } .width('75%') .height('80%') .backgroundColor('#E6E3DF') .borderRadius('25px') .margin({ 'top': '2%' }) .justifyContent(FlexAlign.SpaceAround) } .width('100%') .height('100%') .backgroundImagePosition({ x: 0, y: 0 }) .backgroundImage($r('app.media.index_bg')) .backgroundImageSize({ width: '100%', height: '100%' }) } async aboutToAppear() { const fileUtil = new FileUtil(this.context) const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt'); if (data === '' || data === undefined) { } else { const result = JSON.parse(data) console.log('tagtag', JSON.stringify(result)) this.inputTextList1[9] = result.udplocalIp this.inputTextList1[10] = result.udplocalIpPort this.inputTextList1[7] = result.udpOppositeIp this.inputTextList1[8] = result.udpOppositeIpPort // this.inputTextList1[0]=result[0].tcplocalIp // this.inputTextList1[13]=result[0].tcplocalIpPort this.inputTextList1[0] = result.tcpOppositeIp this.inputTextList1[1] = result.tcpOppositePort this.inputTextList1[5] = result.gateway this.inputTextList1[4] = result.netMask this.inputTextList1[6] = result.dnsServers this.inputTextList1[2] = result.centerIp this.inputTextList1[3] = result.centerPort this.selectedTerType = result.terType this.selectedCardType = result.cardType this.netOpen= result.netOpen this.deviceType= result.deviceType || 0 this.deviceIpArr= result.deviceIpArr || ['',''] this.devicePortArr= result.devicePortArr || ['',''] console.log('surenjun', this.selectedTerType + ''); } //@ts-ignore ethernet.getIfaceConfig("eth0", (error, value) => { if (error) { // that.errorMsg='error' console.log("boot_up getIp_new callback error = " + JSON.stringify(error)); } else { console.log("boot_up getIp_new callback ipAddr = " + JSON.stringify(value.ipAddr)); // console.log(" boot_up getIp_new callback mode = " + JSON.stringify(value.mode)); console.log("boot_up getIp_new callback route = " + JSON.stringify(value.route)); console.log("boot_up getIp_new callback gateway = " + JSON.stringify(value.gateway)); console.log("boot_up getIp_new callback netMask = " + JSON.stringify(value.netMask)); console.log("boot_up getIp_new callback dnsServers = " + JSON.stringify(value.dnsServers)); } }) } onPageShow() { console.info('Index onPageShow'); } outClick() { } }