增加ip输入校验。
This commit is contained in:
@ -245,7 +245,11 @@ Item {
|
||||
anchors.bottom: parent.bottom
|
||||
columns: 2
|
||||
spacing: 10
|
||||
Text {text: qsTr("开门区域: ")}
|
||||
verticalItemAlignment: Qt.AlignVCenter
|
||||
Text {
|
||||
|
||||
text: qsTr("开门区域: ")
|
||||
}
|
||||
Row {
|
||||
enabled: root.enabled
|
||||
RadioButton {
|
||||
|
34
qml/IpTextField.qml
Normal file
34
qml/IpTextField.qml
Normal file
@ -0,0 +1,34 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
Column {
|
||||
id: root
|
||||
property alias text: input.text
|
||||
property bool valid: false
|
||||
TextField {
|
||||
height: 36
|
||||
width: 350
|
||||
id: input
|
||||
|
||||
onTextChanged: {
|
||||
valid = validateIp(text);
|
||||
if(!valid){
|
||||
hint.text="参数配置无效"
|
||||
} else {
|
||||
hint.text=""
|
||||
}
|
||||
}
|
||||
}
|
||||
Text {
|
||||
id: hint
|
||||
color: "red"
|
||||
font.pixelSize: 12
|
||||
}
|
||||
|
||||
function validateIp(ip) {
|
||||
// Regular expression for validating IP address
|
||||
var regex = /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/;
|
||||
return regex.test(ip);
|
||||
}
|
||||
}
|
17
qml/Main.qml
17
qml/Main.qml
@ -9,27 +9,25 @@ ApplicationWindow {
|
||||
width: 1000
|
||||
height: 640
|
||||
visible: true
|
||||
title: qsTr("Hello World")
|
||||
title: qsTr("T009上位机工具")
|
||||
|
||||
header: ToolBar {
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
Button {
|
||||
ToolButton {
|
||||
text: "搜索设备"
|
||||
onClicked: {
|
||||
deviceList.currentIndex = -1
|
||||
App.startSearchDevice()
|
||||
}
|
||||
}
|
||||
Text {
|
||||
Label {
|
||||
text: `设备总数: ${deviceList.count}`
|
||||
}
|
||||
Text {
|
||||
Label {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
Layout.preferredWidth: 400
|
||||
text: deviceList.currentIndex
|
||||
>= 0 ? `当前设备版本号: ${App.devices.get(
|
||||
deviceList.currentIndex).softwareVersion}` : ""
|
||||
Layout.preferredWidth: 280
|
||||
text: App.currentFirmware.length > 0 ? `当前设备版本号: ${App.currentFirmware}` : ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,7 +95,7 @@ ApplicationWindow {
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: deviceList.right
|
||||
anchors.right: parent.right
|
||||
enabled: deviceList.currentIndex>=0
|
||||
enabled: deviceList.currentIndex >= 0
|
||||
openDoorAreaWay: App.currentOpenDoorAreaWay
|
||||
openDoorAreaPoints: App.currentOpenDoorAreaPoints
|
||||
shieldedAreaEnabled: App.currentShieldedAreaEnabled
|
||||
@ -110,7 +108,6 @@ ApplicationWindow {
|
||||
id: networkPopup
|
||||
visible: false
|
||||
width: 500
|
||||
height: 240
|
||||
}
|
||||
|
||||
OtaPopup {
|
||||
|
@ -72,7 +72,7 @@ Dialog {
|
||||
Button {
|
||||
id: cancelButton
|
||||
width: 72
|
||||
height: 26
|
||||
height: 40
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 15
|
||||
anchors.bottom: parent.bottom
|
||||
|
@ -1,116 +1,141 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import AntiClipSettings
|
||||
|
||||
Popup {
|
||||
id: root
|
||||
parent: Overlay.overlay
|
||||
anchors.centerIn: Overlay.overlay
|
||||
modal: true
|
||||
property int inputHeight: 50
|
||||
background: Rectangle {
|
||||
radius: 8
|
||||
}
|
||||
contentItem: ColumnLayout {
|
||||
anchors.centerIn: parent
|
||||
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
color: "white"
|
||||
border.color: "lightgray"
|
||||
radius: 10
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
Row {
|
||||
spacing: 10
|
||||
padding: 20
|
||||
|
||||
Row {
|
||||
spacing: 10
|
||||
|
||||
Text {
|
||||
text: "模式"
|
||||
font.pointSize: 14
|
||||
width: 100
|
||||
}
|
||||
|
||||
RadioButton {
|
||||
id: dhcpMode
|
||||
text: "DHCP"
|
||||
checked: App.currentNetworkInfomation.dhcp
|
||||
}
|
||||
|
||||
RadioButton {
|
||||
id: staticMode
|
||||
text: "静态IP"
|
||||
checked: !App.currentNetworkInfomation.dhcp
|
||||
}
|
||||
Label {
|
||||
text: "模式"
|
||||
width: 100
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: 5
|
||||
|
||||
Text {
|
||||
text: "设备IP"
|
||||
font.pointSize: 14
|
||||
width: 100
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: ipInput
|
||||
width: 350
|
||||
height: 30
|
||||
text: App.currentNetworkInfomation.ip
|
||||
}
|
||||
RadioButton {
|
||||
id: dhcpMode
|
||||
text: "DHCP"
|
||||
checked: App.currentNetworkInfomation.dhcp
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: 5
|
||||
Text {
|
||||
width: 100
|
||||
text: "子网掩码"
|
||||
font.pointSize: 14
|
||||
}
|
||||
RadioButton {
|
||||
id: staticMode
|
||||
text: "静态IP"
|
||||
checked: true
|
||||
// checked: !App.currentNetworkInfomation.dhcp
|
||||
}
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: netmaskInput
|
||||
width: 350
|
||||
height: 30
|
||||
text: App.currentNetworkInfomation.netmask
|
||||
}
|
||||
Row {
|
||||
spacing: 5
|
||||
visible: staticMode.checked
|
||||
Label {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.verticalCenterOffset: -10
|
||||
text: "设备IP"
|
||||
width: 100
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: 5
|
||||
IpTextField {
|
||||
id: ipInput
|
||||
height: inputHeight
|
||||
width: 350
|
||||
text: App.currentNetworkInfomation.ip
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: 5
|
||||
|
||||
Text {
|
||||
text: "设备网关"
|
||||
font.pointSize: 14
|
||||
width: 100
|
||||
}
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: gatewayInput
|
||||
width: 350
|
||||
height: 30
|
||||
text: App.currentNetworkInfomation.gateway
|
||||
}
|
||||
Row {
|
||||
spacing: 5
|
||||
visible: staticMode.checked
|
||||
Label {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.verticalCenterOffset: -10
|
||||
width: 100
|
||||
text: "子网掩码"
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: 20
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
IpTextField {
|
||||
id: netmaskInput
|
||||
width: 350
|
||||
height: inputHeight
|
||||
text: App.currentNetworkInfomation.netmask
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "保存"
|
||||
onClicked: {
|
||||
App.updateNetworkInfomation(dhcpMode.checked,ipInput.text,netmaskInput.text,gatewayInput.text);
|
||||
Row {
|
||||
spacing: 5
|
||||
visible: staticMode.checked
|
||||
Label {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: "设备网关"
|
||||
anchors.verticalCenterOffset: -10
|
||||
width: 100
|
||||
}
|
||||
|
||||
IpTextField {
|
||||
id: gatewayInput
|
||||
width: 350
|
||||
height: inputHeight
|
||||
text: App.currentNetworkInfomation.gateway
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: 5
|
||||
visible: staticMode.checked
|
||||
Label {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: "DNS服务器"
|
||||
anchors.verticalCenterOffset: -10
|
||||
width: 100
|
||||
}
|
||||
|
||||
IpTextField {
|
||||
id: dnsInput
|
||||
width: 350
|
||||
height: inputHeight
|
||||
text: App.currentNetworkInfomation.gateway
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
Layout.rightMargin: 20
|
||||
Layout.alignment: Qt.AlignRight
|
||||
spacing: 20
|
||||
|
||||
Button {
|
||||
text: "保存"
|
||||
onClicked: {
|
||||
if (dhcpMode.checked || (staticMode.checked && ipInput.valid
|
||||
&& netmaskInput.valid
|
||||
&& gatewayInput.valid
|
||||
&& dnsInput.valid)) {
|
||||
App.updateNetworkInfomation(dhcpMode.checked,
|
||||
ipInput.text,
|
||||
netmaskInput.text,
|
||||
gatewayInput.text)
|
||||
networkPopup.close()
|
||||
} else {
|
||||
showMessageDialog(2, "网络设置", "请输入合法参数地址!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "取消"
|
||||
onClicked: root.close()
|
||||
}
|
||||
Button {
|
||||
text: "取消"
|
||||
onClicked: root.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ Popup {
|
||||
modal: true
|
||||
focus: true
|
||||
closePolicy: Popup.CloseOnEscape
|
||||
property bool otaFinished: true
|
||||
property var onClose
|
||||
|
||||
ColumnLayout {
|
||||
@ -23,9 +24,15 @@ Popup {
|
||||
|
||||
RowLayout {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
Button {
|
||||
text: "关闭"
|
||||
onClicked: root.close()
|
||||
IconButton {
|
||||
source: "../resources/popup_close.svg"
|
||||
onClicked: {
|
||||
if(otaFinished){
|
||||
root.close()
|
||||
}else{
|
||||
showMessageDialog(2,"OTA升级","设备正在升级中,请耐心等待...")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +41,8 @@ Popup {
|
||||
TextField {
|
||||
id: otaFile
|
||||
Layout.fillWidth: true
|
||||
placeholderText: "请选择升级文件或将文件拖入工具中"
|
||||
readOnly: true
|
||||
placeholderText: "请选择升级bin文件"
|
||||
}
|
||||
Button {
|
||||
text: "选择"
|
||||
@ -99,6 +107,7 @@ Popup {
|
||||
Connections {
|
||||
target: App
|
||||
function onCurrentDeviceOtaProgressChanged (status, progress, message) {
|
||||
otaFinished = !status || (progress>=100)
|
||||
progressBar.value = progress
|
||||
progressText.text = `${progress}%`
|
||||
if(progress>=100){
|
||||
@ -107,7 +116,6 @@ Popup {
|
||||
}else {
|
||||
otaMessage.text = message
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user