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

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
)
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_LIB_DIR ${FFmpeg_ROOT}/lib)

View File

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

View File

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

View File

@ -6,22 +6,13 @@ Column {
id: root
property alias text: input.text
property bool valid: false
property bool canEmpty: false
TextField {
height: 36
width: 350
id: input
onTextChanged: {
if(text.length<=0){
hint.text = "参数不能为空"
return
}
valid = validateIp(text)
if (!valid) {
hint.text = "参数配置无效"
} else {
hint.text = ""
}
validate()
}
}
Text {
@ -30,12 +21,22 @@ Column {
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() {
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
anchors.centerIn: Overlay.overlay
modal: true
closePolicy: Popup.CloseOnEscap | Popup.NoAutoClose
property int inputHeight: 50
background: Rectangle {
radius: 8
@ -40,11 +41,17 @@ Popup {
Row {
spacing: 5
visible: staticMode.checked
Label {
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: -10
text: "设备IP"
Row {
width: 100
anchors.verticalCenterOffset: -10
anchors.verticalCenter: parent.verticalCenter
Label {
text: "设备IP"
}
Label {
color: "red"
text: "*"
}
}
IpTextField {
@ -58,12 +65,18 @@ Popup {
Row {
spacing: 5
visible: staticMode.checked
Label {
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: -10
Row {
width: 100
anchors.verticalCenterOffset: -10
anchors.verticalCenter: parent.verticalCenter
Label {
text: "子网掩码"
}
Label {
color: "red"
text: "*"
}
}
IpTextField {
id: netmaskInput
@ -88,12 +101,13 @@ Popup {
width: 350
height: inputHeight
text: App.currentNetworkInfomation.gateway
canEmpty: true
}
}
Row {
spacing: 5
visible: staticMode.checked
visible: false // staticMode.checked
Label {
anchors.verticalCenter: parent.verticalCenter
text: "DNS服务器"
@ -106,6 +120,7 @@ Popup {
width: 350
height: inputHeight
text: App.currentNetworkInfomation.dns
canEmpty: true
}
}
@ -117,6 +132,10 @@ Popup {
Button {
text: "保存"
onClicked: {
ipInput.validate()
netmaskInput.validate()
gatewayInput.validate()
dnsInput.validate()
if (dhcpMode.checked || (staticMode.checked && ipInput.valid
&& netmaskInput.valid
&& gatewayInput.valid
@ -124,10 +143,9 @@ Popup {
App.updateNetworkInfomation(dhcpMode.checked,
ipInput.text,
netmaskInput.text,
gatewayInput.text,dnsInput.text)
gatewayInput.text,
dnsInput.text)
networkPopup.close()
} else {
showMessageDialog(2, "网络设置", "请输入合法参数地址!")
}
}
}
@ -139,9 +157,18 @@ Popup {
}
}
onVisibleChanged: {
if (visible) {
ipInput.reset()
netmaskInput.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
}
}
}