diff --git a/src/pages/Index/Settings/Device.vue b/src/pages/Index/Settings/Device.vue
index c071a3c..163b394 100644
--- a/src/pages/Index/Settings/Device.vue
+++ b/src/pages/Index/Settings/Device.vue
@@ -147,7 +147,7 @@ import {
setLocalIP,
setAutoLogoutTime,
} from '../../../services/Index/settings/settings'
-import { eMessage } from '../utils'
+import { eMessage, isValidIPv4 } from '../utils'
// 系统设置状态
interface Settings {
@@ -240,8 +240,13 @@ const updateSetting = async (key: string, value: any) => {
res = await setDHCP(value)
break
case 'localIP':
+ const addr = value.trim()
+ if (!isValidIPv4(addr)) {
+ eMessage.error('请输入合法的IP地址')
+ return
+ }
hideKeyboard()
- res = await setLocalIP(value)
+ res = await setLocalIP(addr)
break
}
diff --git a/src/pages/Index/Settings/Lis.vue b/src/pages/Index/Settings/Lis.vue
index db01465..02315f2 100644
--- a/src/pages/Index/Settings/Lis.vue
+++ b/src/pages/Index/Settings/Lis.vue
@@ -71,11 +71,11 @@
-
+
(undefined)
+const lisSettings = ref<(LISSettings & { LISNetPortStr: string }) | undefined>(
+ undefined,
+)
const getLisSetting = async () => {
const res = await getLISSetting()
if (res && res.success) {
- lisSettings.value = res.data
+ lisSettings.value = {
+ ...res.data,
+ LISNetPortStr: res.data.LISNetPort.toString(),
+ }
}
}
@@ -211,8 +216,13 @@ const updLisAutoExport = async (auto: boolean) => {
}
const updLisIP = async (ip: string) => {
+ const addr = ip.trim()
+ if (!isValidIPv4(addr)) {
+ eMessage.error('请输入合法的IP地址')
+ return
+ }
hideKeyboard()
- const res = await setLISNetIp(ip)
+ const res = await setLISNetIp(addr)
if (res && res.success) {
getLisSetting()
} else {
@@ -220,9 +230,14 @@ const updLisIP = async (ip: string) => {
}
}
-const updLisPort = async (port: number) => {
+const updLisPort = async (port: string) => {
+ const p = port.toString().trim()
+ if (!/^\d+$/.test(p)) {
+ eMessage.error('请输入合法的端口值')
+ return
+ }
hideKeyboard()
- const res = await setLISNetPort(port)
+ const res = await setLISNetPort(p)
if (res && res.success) {
getLisSetting()
} else {
@@ -245,7 +260,7 @@ const showKeyboard = (field: 'ip' | 'port') => {
currentInputValue.value = lisSettings.value?.LISNetIp || ''
}
if (field === 'port') {
- currentInputValue.value = lisSettings.value?.LISNetPort.toString() || ''
+ currentInputValue.value = lisSettings.value?.LISNetPortStr || ''
}
currentInputField.value = field
keyboardVisible.value = true
@@ -260,7 +275,7 @@ const handleKeyboardInput = (value: string) => {
if (currentInputField.value === 'ip') {
lisSettings.value!.LISNetIp = value
} else {
- lisSettings.value!.LISNetPort = +value
+ lisSettings.value!.LISNetPortStr = value
}
}
diff --git a/src/pages/Index/utils/index.ts b/src/pages/Index/utils/index.ts
index 7aa0225..4551b1b 100644
--- a/src/pages/Index/utils/index.ts
+++ b/src/pages/Index/utils/index.ts
@@ -6,6 +6,11 @@ export function formatRemainTime(seconds: number) {
return min.padStart(2, '0') + ':' + sec.padStart(2, '0')
}
+export function isValidIPv4(ip: string) {
+ const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
+ return ipv4Regex.test(ip);
+}
+
export const eMessage = {
error: (msg: string) => {
ElMessage({