修改网络设置校验提示策略。

This commit is contained in:
luocai 2024-08-22 12:28:11 +08:00
parent 7e28896159
commit eeb1fc088c
5 changed files with 63 additions and 34 deletions

View File

@ -16,7 +16,7 @@ add_compile_definitions(
BOOST_USE_WINAPI_VERSION=BOOST_WINAPI_VERSION_WIN10 BOOST_USE_WINAPI_VERSION=BOOST_WINAPI_VERSION_WIN10
) )
set(FFmpeg_ROOT ${Libraries_ROOT}/ffmpeg-7.0.1-full_build-shared) set(FFmpeg_ROOT ${Libraries_ROOT}/ffmpeg-6.1.1-full_build-shared)
set(FFmpeg_INCLUDE_DIR ${FFmpeg_ROOT}/include) set(FFmpeg_INCLUDE_DIR ${FFmpeg_ROOT}/include)
set(FFmpeg_LIB_DIR ${FFmpeg_ROOT}/lib) set(FFmpeg_LIB_DIR ${FFmpeg_ROOT}/lib)

View File

@ -17,7 +17,7 @@ public:
QString ip; QString ip;
QString netmask; QString netmask;
QString gateway; QString gateway;
QString dns; QString dns = "8.8.8.8"; // dns被屏蔽现在默认赋值 8.8.8.8 以通过校验
}; };
Q_DECLARE_METATYPE(NetworkInfomation) Q_DECLARE_METATYPE(NetworkInfomation)

View File

@ -155,6 +155,7 @@ void DeviceListModel::onDeviceReplyReadyRead() {
if (reply.contains("sw_ver")) { if (reply.contains("sw_ver")) {
device.softwareVersion = QString::fromStdString(std::string(reply.at("sw_ver").as_string())); device.softwareVersion = QString::fromStdString(std::string(reply.at("sw_ver").as_string()));
} }
if (!device.softwareVersion.startsWith("RD_T009")) continue; // 其它设备不予显示
device.ip = datagram.senderAddress().toString(); device.ip = datagram.senderAddress().toString();
auto iterator = std::find_if(m_devices.cbegin(), m_devices.cend(), auto iterator = std::find_if(m_devices.cbegin(), m_devices.cend(),

View File

@ -6,22 +6,13 @@ Column {
id: root id: root
property alias text: input.text property alias text: input.text
property bool valid: false property bool valid: false
property bool canEmpty: false
TextField { TextField {
height: 36 height: 36
width: 350 width: 350
id: input id: input
onTextChanged: { onTextChanged: {
if(text.length<=0){ validate()
hint.text = "参数不能为空"
return
}
valid = validateIp(text)
if (!valid) {
hint.text = "参数配置无效"
} else {
hint.text = ""
}
} }
} }
Text { Text {
@ -30,12 +21,22 @@ Column {
font.pixelSize: 12 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)
}
function reset() { function reset() {
hint.text = "" hint.text = ""
} }
function validate() {
if (input.text.length <= 0) {
hint.text = root.canEmpty ? "" : "参数不能为空"
root.valid = root.canEmpty
return root.valid
}
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])$/
root.valid = regex.test(input.text)
if (!root.valid) {
hint.text = "参数配置无效"
} else {
hint.text = ""
}
return root.valid
}
} }

View File

@ -8,6 +8,7 @@ Popup {
parent: Overlay.overlay parent: Overlay.overlay
anchors.centerIn: Overlay.overlay anchors.centerIn: Overlay.overlay
modal: true modal: true
closePolicy: Popup.CloseOnEscap | Popup.NoAutoClose
property int inputHeight: 50 property int inputHeight: 50
background: Rectangle { background: Rectangle {
radius: 8 radius: 8
@ -40,11 +41,17 @@ Popup {
Row { Row {
spacing: 5 spacing: 5
visible: staticMode.checked visible: staticMode.checked
Label { Row {
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: -10
text: "设备IP"
width: 100 width: 100
anchors.verticalCenterOffset: -10
anchors.verticalCenter: parent.verticalCenter
Label {
text: "设备IP"
}
Label {
color: "red"
text: "*"
}
} }
IpTextField { IpTextField {
@ -58,11 +65,17 @@ Popup {
Row { Row {
spacing: 5 spacing: 5
visible: staticMode.checked visible: staticMode.checked
Label { Row {
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: -10
width: 100 width: 100
text: "子网掩码" anchors.verticalCenterOffset: -10
anchors.verticalCenter: parent.verticalCenter
Label {
text: "子网掩码"
}
Label {
color: "red"
text: "*"
}
} }
IpTextField { IpTextField {
@ -88,12 +101,13 @@ Popup {
width: 350 width: 350
height: inputHeight height: inputHeight
text: App.currentNetworkInfomation.gateway text: App.currentNetworkInfomation.gateway
canEmpty: true
} }
} }
Row { Row {
spacing: 5 spacing: 5
visible: staticMode.checked visible: false // staticMode.checked
Label { Label {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: "DNS服务器" text: "DNS服务器"
@ -106,6 +120,7 @@ Popup {
width: 350 width: 350
height: inputHeight height: inputHeight
text: App.currentNetworkInfomation.dns text: App.currentNetworkInfomation.dns
canEmpty: true
} }
} }
@ -117,6 +132,10 @@ Popup {
Button { Button {
text: "保存" text: "保存"
onClicked: { onClicked: {
ipInput.validate()
netmaskInput.validate()
gatewayInput.validate()
dnsInput.validate()
if (dhcpMode.checked || (staticMode.checked && ipInput.valid if (dhcpMode.checked || (staticMode.checked && ipInput.valid
&& netmaskInput.valid && netmaskInput.valid
&& gatewayInput.valid && gatewayInput.valid
@ -124,10 +143,9 @@ Popup {
App.updateNetworkInfomation(dhcpMode.checked, App.updateNetworkInfomation(dhcpMode.checked,
ipInput.text, ipInput.text,
netmaskInput.text, netmaskInput.text,
gatewayInput.text,dnsInput.text) gatewayInput.text,
dnsInput.text)
networkPopup.close() networkPopup.close()
} else {
showMessageDialog(2, "网络设置", "请输入合法参数地址!")
} }
} }
} }
@ -139,9 +157,18 @@ Popup {
} }
} }
onVisibleChanged: { onVisibleChanged: {
ipInput.reset() if (visible) {
netmaskInput.reset() ipInput.reset()
gatewayInput.reset() netmaskInput.reset()
dnsInput.reset() gatewayInput.reset()
dnsInput.reset()
dhcpMode.checked = App.currentNetworkInfomation.dhcp
staticMode.checked = !App.currentNetworkInfomation.dhcp
ipInput.text = App.currentNetworkInfomation.ip
netmaskInput.text = App.currentNetworkInfomation.netmask
gatewayInput.text = App.currentNetworkInfomation.gateway
dnsInput.text = App.currentNetworkInfomation.dns
}
} }
} }