添加系统设置菜单

This commit is contained in:
fangxiang 2021-12-18 16:41:47 +08:00
parent d78f822d64
commit 877a964430
10 changed files with 327 additions and 24 deletions

View File

@ -594,6 +594,43 @@ export default class ClientConnection {
} }
} }
public async setSystemNetwork(
request: Protocol.SetSystemNetworkRequestEntity
) {
try {
return await this.doRpc<Protocol.SetSystemNetworkResponseEntity>(request);
} catch (e) {
console.error(e);
}
}
public async setSystemGraphics(
request: Protocol.SetSystemGraphicsRequestEntity
) {
try {
return await this.doRpc<Protocol.SetSystemGraphicsResponseEntity>(
request
);
} catch (e) {
console.error(e);
}
}
public async setSystemOther(request: Protocol.SetSystemOtherRequestEntity) {
try {
return await this.doRpc<Protocol.SetSystemOtherResponseEntity>(request);
} catch (e) {
console.error(e);
}
}
public async getSupportResolutions() {
try {
return await this.doRpc<Protocol.GetSupportResolutionsResponseEntity>(
new Protocol.GetSupportResolutionsRequestEntity(0)
);
} catch (e) {
console.error(e);
}
}
public restartDevice() { public restartDevice() {
this.ws?.send(JSON.stringify(new Protocol.RestartDeviceRequestEntity())); this.ws?.send(JSON.stringify(new Protocol.RestartDeviceRequestEntity()));
} }

View File

@ -138,6 +138,10 @@ export default class GlobalData {
} }
} }
public getCurrentClientName() {
return this._current_client_name;
}
public setCurrentClientName(name: string) { public setCurrentClientName(name: string) {
this._current_client_name = name; this._current_client_name = name;
} }

View File

@ -85,6 +85,7 @@ export default class Initializer {
global_data.applicationConfig = ( global_data.applicationConfig = (
await global_data.getCurrentClient()?.getApplicationSettins() await global_data.getCurrentClient()?.getApplicationSettins()
)?.config; )?.config;
console.log(global_data.applicationConfig);
const options = this.options; const options = this.options;
let $store = options.$store; let $store = options.$store;

View File

@ -146,7 +146,7 @@
(val) => (val) =>
isMacAddress(val) || isMacAddress(val) ||
$t('Please input vaild mac address') + $t('Please input vaild mac address') +
' (04:XX:XX:XX:XX:XX)', ' (XX:XX:XX:XX:XX:XX)',
]" ]"
lazy-rules lazy-rules
/> />
@ -365,11 +365,12 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref, Ref, watch, computed } from "vue"; import { defineComponent, ref, Ref, watch, computed } from "vue";
import { useStore } from "src/store"; import { useStore } from "src/store";
import { useQuasar } from "quasar"; import { useQuasar, SessionStorage } from "quasar";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import GlobalData from "src/common/GlobalData"; import GlobalData from "src/common/GlobalData";
import { HttpProtocol } from "src/entities/HttpProtocol"; import { HttpProtocol } from "src/entities/HttpProtocol";
import { date } from "quasar"; import { date } from "quasar";
import { Protocol } from "src/entities/WSProtocol";
const _time_zones = [ const _time_zones = [
"UTC-12(Central Pacific)", "UTC-12(Central Pacific)",
@ -429,7 +430,7 @@ export default defineComponent({
let use_ntp = ref($t.t("enable")); let use_ntp = ref($t.t("enable"));
let ntp_server = ref(""); let ntp_server = ref("");
let ntp_sync_delay = ref(""); let ntp_sync_delay = ref(180);
let current_date = ref(""); let current_date = ref("");
let current_time = ref(""); let current_time = ref("");
let time_zone = ref(""); let time_zone = ref("");
@ -445,18 +446,69 @@ export default defineComponent({
const refresh_all = () => { const refresh_all = () => {
const config = GlobalData.getInstance()?.applicationConfig; const config = GlobalData.getInstance()?.applicationConfig;
if (config) { if (config) {
setTimeout(async () => {
const support_resolutions = await GlobalData.getInstance()
.getCurrentClient()
?.getSupportResolutions();
if (support_resolutions) {
output_board_resolution_options.value = [];
for (const item of Object.keys(
support_resolutions.output_board_support_resolutions
).sort()) {
output_board_resolution_options.value.push(
(support_resolutions.output_board_support_resolutions as any)[
item
]
);
}
device_resolution_options.value = [];
for (const item of Object.keys(
support_resolutions.device_support_resolutions
)) {
device_resolution_options.value.push(item);
}
{
const val = output_board_resolution_options.value.find(
(element) =>
element &&
element == support_resolutions.current_output_board_resolution
);
output_board_resolution.value =
val ?? output_board_resolution_options.value[0];
}
{
const val = device_resolution_options.value.find(
(element) =>
element &&
element == support_resolutions.current_device_resolution
);
device_resolution.value =
val ?? device_resolution_options.value[0];
}
}
}, 1);
auto_ip.value = auto_ip.value =
config.auto_ip_address != "0" ? $t.t("enable") : $t.t("disable"); config.auto_ip_address != "0" ? $t.t("enable") : $t.t("disable");
gateway.value = config.gateway; gateway.value = config.gateway;
netmask.value = config.subnet_mask; netmask.value = config.subnet_mask;
mac_address.value = config.mac_address; mac_address.value = config.mac_address;
ip_address.value = $store.state.device_ip_address;
brightness.value = config.graphics_brightness;
contrast.value = config.graphics_contrast;
hue.value = config.graphics_hue;
use_ntp.value = use_ntp.value =
config.use_ntp != "0" ? $t.t("enable") : $t.t("disable"); config.use_ntp != "0" ? $t.t("enable") : $t.t("disable");
ntp_server.value = config.ntp_server; ntp_server.value = config.ntp_server;
ntp_sync_delay.value = config.ntp_sync_delay; ntp_sync_delay.value = parseInt(config.ntp_sync_delay);
if (isNaN(ntp_sync_delay.value)) {
ntp_sync_delay.value = 180;
}
try { try {
time_zone.value = time_zone_options.value[parseInt(config.time_zone)]; time_zone.value = time_zone_options.value[config.time_zone];
} catch (e) { } catch (e) {
time_zone.value = time_zone_options.value[0]; time_zone.value = time_zone_options.value[0];
} }
@ -470,19 +522,109 @@ export default defineComponent({
const applyNetwork = async () => { const applyNetwork = async () => {
const ret = await network_form.value.validate(); const ret = await network_form.value.validate();
if (ret) { if (ret) {
console.log("network"); let request = new Protocol.SetSystemNetworkRequestEntity();
request.auto_ip = auto_ip.value == $t.t("enable");
request.ip_address = ip_address.value;
request.gtateway = gateway.value;
request.net_mask = netmask.value;
request.mac_address = mac_address.value;
let success = false;
try {
GlobalData.getInstance()
.getCurrentClient()
?.setSystemNetwork(request);
success = true;
setTimeout(() => {
if (request.ip_address != $store.state.device_ip_address) {
setTimeout(() => {
SessionStorage.clear();
if (
window.location.hostname.toLowerCase() == "192.168.1.1" ||
window.location.hostname.toLowerCase() == "localhost"
) {
window.location.reload();
} else {
window.location.hostname = request.ip_address;
}
}, 1500);
}
}, 1000 * 10);
} catch {}
$q.notify({
color: success ? "positive" : "negative",
icon: success ? "done" : "warning",
message:
$t.t("set system network") +
(success ? $t.t("success") : $t.t("fail")) +
"!",
position: "top",
timeout: 1000,
});
} }
}; };
const applyGraphics = async () => { const applyGraphics = async () => {
const ret = await graphics_form.value.validate(); const ret = await graphics_form.value.validate();
if (ret) { if (ret) {
console.log("graphics"); let request = new Protocol.SetSystemGraphicsRequestEntity();
request.brightness = brightness.value;
request.contrast = contrast.value;
request.hue = hue.value;
request.output_board_resolution = output_board_resolution.value;
request.device_resolution = device_resolution.value;
let success = false;
try {
await GlobalData.getInstance()
.getCurrentClient()
?.setSystemGraphics(request);
success = true;
} catch {}
$q.notify({
color: success ? "positive" : "negative",
icon: success ? "done" : "warning",
message:
$t.t("set system graphics") +
(success ? $t.t("success") : $t.t("fail")) +
"!",
position: "top",
timeout: 1000,
});
} }
}; };
const applyOther = async () => { const applyOther = async () => {
const ret = await other_form.value.validate(); const ret = await other_form.value.validate();
if (ret) { if (ret) {
console.log("other"); let request = new Protocol.SetSystemOtherRequestEntity();
request.use_ntp = use_ntp.value == $t.t("enable");
request.ntp_sync_delay = ntp_sync_delay.value;
request.ntp_server = ntp_server.value;
request.time_zone = time_zone_options.value.findIndex(
(element) => element && element == time_zone.value
);
if (request.time_zone < 0) {
request.time_zone =
GlobalData.getInstance().applicationConfig?.time_zone ?? 21;
}
request.datetime = current_date.value + " " + current_time.value;
let success = false;
try {
await GlobalData.getInstance()
.getCurrentClient()
?.setSystemOther(request);
success = true;
} catch {}
$q.notify({
color: success ? "positive" : "negative",
icon: success ? "done" : "warning",
message:
$t.t("set system other") +
(success ? $t.t("success") : $t.t("fail")) +
"!",
position: "top",
timeout: 1000,
});
} }
}; };
@ -559,7 +701,7 @@ export default defineComponent({
); );
}, },
isMacAddress(str: string) { isMacAddress(str: string) {
return /(04:)([A-Fa-f0-9]{2}:){4}[A-Fa-f0-9]{2}/.test(str); return /([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}/.test(str);
}, },
}; };
}, },

View File

@ -3,11 +3,10 @@ export default class ApplicationConfigEntity {
gateway: string = ""; gateway: string = "";
mac_address: string = ""; mac_address: string = "";
subnet_mask: string = ""; subnet_mask: string = "";
ip_address: string = "";
use_ntp: string = ""; use_ntp: string = "";
ntp_server: string = ""; ntp_server: string = "";
ntp_sync_delay: string = ""; ntp_sync_delay: string = "";
time_zone: string = ""; time_zone: number = 21;
wall_row: number = 1; wall_row: number = 1;
wall_col: number = 1; wall_col: number = 1;
screen_width: number = 1; screen_width: number = 1;
@ -19,4 +18,7 @@ export default class ApplicationConfigEntity {
root_fs_upload_path: string = ""; root_fs_upload_path: string = "";
media_upload_dir: string = ""; media_upload_dir: string = "";
power_on_plan: string = ""; power_on_plan: string = "";
graphics_brightness: number = 100;
graphics_contrast: number = 100;
graphics_hue: number = 100;
} }

View File

@ -195,6 +195,19 @@ export namespace Protocol {
return Commands.PROTOCOL_PREFIX + "ScreenSizeChanged"; return Commands.PROTOCOL_PREFIX + "ScreenSizeChanged";
} }
public static get kRpcSetSystemNetwork() {
return Commands.PROTOCOL_PREFIX + "RpcSetSystemNetwork";
}
public static get kRpcSetSystemGraphics() {
return Commands.PROTOCOL_PREFIX + "RpcSetSystemGraphics";
}
public static get kRpcSetSystemOther() {
return Commands.PROTOCOL_PREFIX + "RpcSetSystemOther";
}
public static get kRpcGetSupportResolutions() {
return Commands.PROTOCOL_PREFIX + "RpcGetSupportResolutions";
}
static _all_commands = new Set([ static _all_commands = new Set([
Commands.kUnKnowCommand, Commands.kUnKnowCommand,
Commands.kSearchDevice, Commands.kSearchDevice,
@ -238,6 +251,10 @@ export namespace Protocol {
Commands.kRpcSetSubtitle, Commands.kRpcSetSubtitle,
Commands.kRpcGetScreenSize, Commands.kRpcGetScreenSize,
Commands.kScreenSizeChanged, Commands.kScreenSizeChanged,
Commands.kRpcSetSystemNetwork,
Commands.kRpcSetSystemGraphics,
Commands.kRpcSetSystemOther,
Commands.kRpcGetSupportResolutions,
]); ]);
public static get AllCommands() { public static get AllCommands() {
@ -1114,4 +1131,95 @@ export namespace Protocol {
this.command = Commands.kScreenSizeChanged; this.command = Commands.kScreenSizeChanged;
} }
} }
export class SetSystemNetworkRequestEntity extends Protocol.PacketEntity {
auto_ip: boolean = false;
ip_address: string = "192.168.1.68";
gtateway: string = "192.168.1.1";
net_mask: string = "255.255.255.0";
mac_address: string = "04:D9:F5:D3:F4:C5";
constructor(rcp_id?: number) {
super();
this.rpc_id = rcp_id ?? 0;
this.command = Protocol.Commands.kRpcSetSystemNetwork;
}
}
export class SetSystemNetworkResponseEntity extends Protocol.PacketEntity {
timestamp = new Date().getMilliseconds();
constructor() {
super();
this.command = Protocol.Commands.kRpcSetSystemNetwork;
}
}
export class SetSystemGraphicsRequestEntity extends Protocol.PacketEntity {
brightness: number = 100;
contrast: number = 100;
hue: number = 100;
device_resolution: string = "3840x2160@60";
output_board_resolution: string = "1920x1080";
constructor(rcp_id?: number) {
super();
this.rpc_id = rcp_id ?? 0;
this.command = Protocol.Commands.kRpcSetSystemGraphics;
}
}
export class SetSystemGraphicsResponseEntity extends Protocol.PacketEntity {
timestamp = new Date().getMilliseconds();
constructor() {
super();
this.command = Protocol.Commands.kRpcSetSystemGraphics;
}
}
export class SetSystemOtherRequestEntity extends Protocol.PacketEntity {
use_ntp: boolean = false;
ntp_server: string = "ntp.ntsc.ac.cn";
ntp_sync_delay: number = 60;
datetime: string = "1997-01-01 00:00:00";
time_zone: number = 21;
constructor(rcp_id?: number) {
super();
this.rpc_id = rcp_id ?? 0;
this.command = Protocol.Commands.kRpcSetSystemOther;
}
}
export class SetSystemOtherResponseEntity extends Protocol.PacketEntity {
timestamp = new Date().getMilliseconds();
constructor() {
super();
this.command = Protocol.Commands.kRpcSetSystemOther;
}
}
export class GetSupportResolutionsRequestEntity extends Protocol.PacketEntity {
timestamp = new Date().getMilliseconds();
constructor(rcp_id?: number) {
super();
this.rpc_id = rcp_id ?? 0;
this.command = Protocol.Commands.kRpcGetSupportResolutions;
}
}
export class GetSupportResolutionsResponseEntity extends Protocol.PacketEntity {
output_board_support_resolutions: Object = {};
current_output_board_resolution: string = "";
device_support_resolutions: Object = {};
current_device_resolution: string = "";
constructor() {
super();
this.command = Protocol.Commands.kRpcGetSupportResolutions;
}
}
} }

View File

@ -240,4 +240,7 @@ export default {
loop: "循环", loop: "循环",
"unset power on start": "取消开机预案", "unset power on start": "取消开机预案",
"set power on start": "设置为开机预案", "set power on start": "设置为开机预案",
"set system other": "系统参数配置",
"set system network": "系统网络参数配置",
"set system graphics": "系统图像参数配置",
}; };

View File

@ -49,6 +49,11 @@ export default defineComponent({
$q.loading.hide(); $q.loading.hide();
}); });
$store.commit(
"setDeviceIpAddress",
GlobalData.getInstance().getCurrentClientName()
);
return {}; return {};
}, },
}); });

View File

@ -220,17 +220,17 @@ export default defineComponent({
}, },
stopPlan() { stopPlan() {
GlobalData.getInstance().getCurrentClient()?.stopCurrentRunningPlan(); GlobalData.getInstance().getCurrentClient()?.stopCurrentRunningPlan();
$q.notify({ // $q.notify({
color: "positive", // color: "positive",
icon: "done", // icon: "done",
message: // message:
$t.t("send") + // $t.t("send") +
$t.t("stop plan") + // $t.t("stop plan") +
$t.t("directives") + // $t.t("directives") +
$t.t("success"), // $t.t("success"),
position: "top", // position: "top",
timeout: 1000, // timeout: 1000,
}); // });
}, },
logout() { logout() {
SessionStorage.clear(); SessionStorage.clear();

View File

@ -627,9 +627,10 @@ export default store(function (/* { ssrContext } */) {
); );
}, },
setDeviceIpAddress(state: StateInterface, playload?: any) { setDeviceIpAddress(state: StateInterface, playload?: any) {
state.device_ip_address = playload; if (playload) state.device_ip_address = playload;
}, },
setPowerOnPlan(state: StateInterface, playload?: any) { setPowerOnPlan(state: StateInterface, playload?: any) {
if (playload != null && playload != undefined)
state.power_on_plan = playload; state.power_on_plan = playload;
}, },
}, },