subject-two/entry/src/main/ets/pages/TerminalInfos.ets

198 lines
7.5 KiB
Plaintext
Raw Normal View History

2025-02-11 09:09:34 +08:00
import TopLogo from './compontents/TopLogo';
2024-02-26 15:01:27 +08:00
import ethernet from '@ohos.net.ethernet';
2025-02-11 09:09:34 +08:00
2024-08-10 14:00:18 +08:00
import common from '@ohos.app.ability.common';
2024-08-13 11:50:38 +08:00
import { GlobalConfig } from '../config';
2025-02-11 16:52:41 +08:00
import { NetworkConfigType } from '../model/TerminalInfos';
import Prompt from '@system.prompt';
2025-03-26 13:43:47 +08:00
import FileUtils from '../utils/FileUtils';
2024-07-09 11:11:31 +08:00
2024-02-26 15:01:27 +08:00
@Entry
@Component
struct Index {
2025-02-11 09:09:34 +08:00
@State textList1: string[] =
['差分服务器Ip', '响应端口', '中心服务器IP', '响应端口', '子网掩码', '默认网关', 'dns', '后置机IP ', '响应端口',
'前置机IP', '本地端口']
2024-05-09 13:42:56 +08:00
// @State textList2: string[] = []
2024-05-16 09:53:10 +08:00
@State ratio: number = 1700 / 960
2025-02-11 09:09:34 +08:00
@State inputFontSize: number = 12 //12
2024-02-26 15:01:27 +08:00
//
2024-05-09 13:42:56 +08:00
// @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']
2024-08-07 08:57:40 +08:00
// @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']
2025-02-11 09:09:34 +08:00
@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']
2024-05-09 13:42:56 +08:00
// @State inputTextList2: string[] = []
2024-02-26 15:01:27 +08:00
// 112.80.35.83 11052
2024-05-09 13:42:56 +08:00
// @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']
2025-02-11 09:09:34 +08:00
@State @Watch('outClick') outFlag: boolean = false;
scroller: Scroller = new Scroller()
2024-05-09 13:42:56 +08:00
// @State inputTextList2: string[] = ['192.168.36.139','20022']
2024-08-10 14:00:18 +08:00
private context = getContext(this) as common.UIAbilityContext;
2024-03-12 15:32:48 +08:00
2024-02-26 15:01:27 +08:00
build() {
Column() {
2025-02-11 09:09:34 +08:00
TopLogo({ outFlag: $outFlag })
2024-02-26 15:01:27 +08:00
Column() {
Column() {
2025-02-11 09:09:34 +08:00
Scroll(this.scroller) {
Flex({ 'wrap': FlexWrap.Wrap }) {
ForEach(this.textList1, (item: string, index: number) => {
2024-02-26 15:01:27 +08:00
Row() {
Text(item)
.width('40%')
.height('100%')
.fontColor('#E5CBA1')
2025-02-11 09:09:34 +08:00
.padding({ 'left': '35px' })
.fontSize(this.inputFontSize * this.ratio)
TextInput({ 'text': this.inputTextList1[index] ? this.inputTextList1[index] : '' })
2024-02-26 15:01:27 +08:00
.width('50%')
.height('60%')
.fontColor('#fff')
.borderColor('#E6E0D8')
.borderRadius('10px')
.borderWidth('2px')
2025-02-11 09:09:34 +08:00
.fontSize(this.inputFontSize * this.ratio)
.padding({ top: 0, bottom: 0 })
2024-02-26 15:01:27 +08:00
.linearGradient({
angle: 0,
colors: [[0x403C36, 0.0], [0x4D473D, 0.34], [0x3D3A34, 1.0]]
2025-02-11 09:09:34 +08:00
})
.onChange((value: string) => {
this.inputTextList1[index] = value
2024-02-26 15:01:27 +08:00
2025-02-11 09:09:34 +08:00
})
2024-02-26 15:01:27 +08:00
}
.width('50%')
.height('16.7%')
})
}
}
.width('95%')
.height('90%')
2025-02-11 09:09:34 +08:00
.margin({ 'top': '2%' })
2024-02-26 15:01:27 +08:00
.backgroundColor('#282828')
.borderRadius('15px')
}
.width('100%')
.height('80%')
.borderRadius('25px')
2025-02-11 09:09:34 +08:00
2024-02-26 15:01:27 +08:00
Column() {
2025-02-11 09:09:34 +08:00
Image($r('app.media.terminal_save')).width('20.5%').height('74%').onClick(async () => {
2025-03-26 13:43:47 +08:00
const fileUtil = new FileUtils(this.context)
2024-08-10 14:00:18 +08:00
const folderPath = await fileUtil.initFolder(`/config`);
2025-02-11 16:52:41 +08:00
const param: NetworkConfigType = {
2025-02-11 09:09:34 +08:00
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]
}
fileUtil.addFile(`${folderPath}/ipConfig.txt`, JSON.stringify(param), '')
2024-08-10 14:00:18 +08:00
// upDateTableByArray('IpConfigTable',[])
2024-02-26 15:01:27 +08:00
ethernet.setIfaceConfig("eth0", {
mode: 0,
2025-02-11 09:09:34 +08:00
ipAddr: this.inputTextList1[9],
2024-02-26 15:01:27 +08:00
route: "0.0.0.0",
2025-02-11 09:09:34 +08:00
gateway: this.inputTextList1[5], //value.gateway网关
netMask: this.inputTextList1[4], //value.netMask网络掩码
2024-05-16 09:53:10 +08:00
dnsServers: this.inputTextList1[6],
2024-02-26 15:01:27 +08:00
}, (error) => {
if (error) {
2025-02-11 16:52:41 +08:00
Prompt.showToast({
2025-02-11 09:09:34 +08:00
message: '设置失败' + JSON.stringify(error),
2024-02-26 15:01:27 +08:00
duration: 3000
});
} else {
2025-02-11 16:52:41 +08:00
Prompt.showToast({
2024-02-26 15:01:27 +08:00
message: '设置成功',
duration: 3000
});
}
});
2024-06-04 15:56:50 +08:00
2024-02-26 15:01:27 +08:00
})
}
.backgroundColor('#CCC4B8')
.width('100%')
.height('20%')
2025-02-11 09:09:34 +08:00
.borderRadius({ 'bottomLeft': '25px', 'bottomRight': '25px' })
2024-02-26 15:01:27 +08:00
.justifyContent(FlexAlign.SpaceAround)
}
.width('75%')
.height('69.4%')
.backgroundColor('#E6E3DF')
.borderRadius('25px')
2025-02-11 09:09:34 +08:00
.margin({ 'top': '7%' })
2024-02-26 15:01:27 +08:00
.justifyContent(FlexAlign.SpaceAround)
}
.width('100%')
.height('100%')
2025-02-11 09:09:34 +08:00
.backgroundImagePosition({ x: 0, y: 0 })
2024-02-26 15:01:27 +08:00
.backgroundImage($r('app.media.index_bg'))
.backgroundImageSize({ width: '100%', height: '100%' })
}
2024-06-04 11:28:15 +08:00
2024-08-13 11:50:38 +08:00
async aboutToAppear() {
2025-03-26 13:43:47 +08:00
const fileUtil = new FileUtils(this.context)
2024-08-13 11:50:38 +08:00
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
if (data === '' || data === undefined) {
2025-02-11 09:09:34 +08:00
} else {
2025-02-11 16:52:41 +08:00
// TODO
const result: ESObject = JSON.parse(data)
2025-02-11 09:09:34 +08:00
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
2024-08-13 11:50:38 +08:00
}
2024-02-26 15:01:27 +08:00
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));
}
})
}
2025-02-11 09:09:34 +08:00
2024-02-26 15:01:27 +08:00
onPageShow() {
console.info('Index onPageShow');
}
2025-02-11 09:09:34 +08:00
outClick() {
2024-02-26 15:01:27 +08:00
}
}