启用自动获取IP时,显示当前实际使用的IP。关闭时显示上次设置的手动IP。

This commit is contained in:
fangxiang 2022-05-11 21:03:23 +08:00
parent 20822da33e
commit 16f1ef6e4c
5 changed files with 76 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "media_player_client",
"version": "1.4.4",
"version": "1.4.5",
"description": "A Quasar Framework app",
"productName": "MediaPlayerClient",
"author": "fangxiang <fangxiang@cloudview.work>",

View File

@ -1044,6 +1044,16 @@ export default class ClientConnection {
}
}
public async getSystemNetworkInfo() {
try {
return await this.doRpc<Protocol.GetSystemNetworkInfoResponseEntity>(
new Protocol.GetSystemNetworkInfoRequestEntity()
);
} catch (e) {
console.error(e);
}
}
public destory() {
if (this.ws) {
this.ws.onclose = null;

View File

@ -97,10 +97,11 @@
:options="[$t('enable'), $t('disable')]"
:loading="loading"
:disable="loading"
@update:model-value="autoIpChanged"
/>
</q-item-section>
</q-item>
<q-item v-if="auto_ip != $t('enable')">
<q-item :disable="auto_ip == $t('enable')">
<q-item-section avatar class="width_5_1">{{
$t("ip address") + ":"
}}</q-item-section>
@ -108,7 +109,7 @@
<q-input
v-model="ip_address"
:loading="loading"
:disable="loading"
:disable="auto_ip == $t('enable') || loading"
maxlength="15"
:rules="[
(val) =>
@ -122,14 +123,14 @@
/>
</q-item-section>
</q-item>
<q-item v-if="auto_ip != $t('enable')">
<q-item :disable="auto_ip == $t('enable')">
<q-item-section avatar class="width_5_1">{{
$t("gateway") + ":"
}}</q-item-section>
<q-item-section>
<q-input
:loading="loading"
:disable="loading"
:disable="auto_ip == $t('enable') || loading"
v-model="gateway"
maxlength="15"
:rules="[
@ -144,14 +145,14 @@
/>
</q-item-section>
</q-item>
<q-item v-if="auto_ip != $t('enable')">
<q-item :disable="auto_ip == $t('enable')">
<q-item-section avatar class="width_5_1">{{
$t("netmask") + ":"
}}</q-item-section>
<q-item-section>
<q-input
:loading="loading"
:disable="loading"
:disable="auto_ip == $t('enable') || loading"
v-model="netmask"
maxlength="15"
:rules="[
@ -1664,6 +1665,34 @@ export default defineComponent({
break;
}
},
async autoIpChanged(value: string) {
const enabled = value == $t.t("enable");
let flag = false;
if (enabled) {
try {
const info = await GlobalData.getInstance()
.getCurrentClient()
?.getSystemNetworkInfo();
if (info) {
gateway.value = info.gateway;
netmask.value = info.net_mask;
mac_address.value = info.mac_address;
ip_address.value = info.ip_address;
flag = true;
}
} catch {}
}
if (!flag) {
const config = GlobalData.getInstance()?.applicationConfig;
if (config) {
gateway.value = config.gateway;
netmask.value = config.subnet_mask;
mac_address.value = config.mac_address;
ip_address.value = config.ip_address;
}
}
},
isIpAddress(str: string) {
return (
str == "localhost" ||

View File

@ -1,5 +1,6 @@
export default class ApplicationConfigEntity {
auto_ip_address: string = "";
ip_address: string = "";
gateway: string = "";
mac_address: string = "";
subnet_mask: string = "";

View File

@ -416,6 +416,10 @@ export namespace Protocol {
return Commands.PROTOCOL_PREFIX + "RpcAddTimingTask";
}
public static get kRpcGetSystemNetworkInfo() {
return Commands.PROTOCOL_PREFIX + "RpcGetSystemNetworkInfo";
}
static _all_commands = new Set([
Commands.kUnKnowCommand,
Commands.kSearchDevice,
@ -519,6 +523,7 @@ export namespace Protocol {
Commands.kRpcEditTimingTask,
Commands.kRpcDeleteTimingTask,
Commands.kRpcGetTimingTasks,
Commands.kRpcGetSystemNetworkInfo,
]);
public static get AllCommands() {
return this._all_commands;
@ -2638,4 +2643,28 @@ export namespace Protocol {
success = false;
}
export class GetSystemNetworkInfoRequestEntity extends PacketEntity {
constructor(rpc_id = 0) {
super();
super.command = Commands.kRpcGetSystemNetworkInfo;
super.flag = PacketEntity.FLAG_REQUEST;
super.rpc_id = rpc_id;
this.timestamp = Date.now();
}
timestamp: number;
}
export class GetSystemNetworkInfoResponseEntity extends PacketEntity {
constructor() {
super();
super.flag = PacketEntity.FLAG_RESPONSE;
}
auto_ip = false;
ip_address = "192.168.1.1";
gateway = "192.168.1.1";
net_mask = "192.168.1.1";
mac_address = "AA:BB:CC:DD:EE:FF";
}
}