修复点击登录按钮后不会立即进入loading模式的BUG

PAD隐藏
This commit is contained in:
fangxiang 2022-07-22 14:50:12 +08:00
parent da9f6928b8
commit f9316f01e7
3 changed files with 134 additions and 122 deletions

View File

@ -318,4 +318,6 @@ export default {
http: "Http", http: "Http",
control: "Control", control: "Control",
"restart now": "Restart Now", "restart now": "Restart Now",
_SOFT_PAD_LOGIN_TITLE_: "LEDPLAYER",
welcome: "Welcome",
}; };

View File

@ -11,7 +11,7 @@
class="full-height text-h4 text-white text-center text-weight-bold" class="full-height text-h4 text-white text-center text-weight-bold"
style="position: fixed; writing-mode: vertical-lr; left: 56.5%" style="position: fixed; writing-mode: vertical-lr; left: 56.5%"
> >
<span> {{ $t("welcome") }}{{ $t("login") }} </span> <span> {{ $t("welcome") }}{{ $t(" ") }}{{ $t("login") }} </span>
</div> </div>
<div <div
v-if="landspace" v-if="landspace"
@ -46,7 +46,7 @@
<q-card-section class="fit"> <q-card-section class="fit">
<q-form ref="login_form" @submit="onSubmit" @reset="onReset"> <q-form ref="login_form" @submit="onSubmit" @reset="onReset">
<q-list class="fit text-h6"> <q-list class="fit text-h6">
<q-item> <q-item v-if="$store.state.advanced_debug">
<q-item-section> <q-item-section>
<q-input <q-input
:autofocus="!data.ip_address" :autofocus="!data.ip_address"
@ -256,6 +256,7 @@ import EventBus, { EventNamesDefine } from "src/common/EventBus";
import { useStore } from "src/store"; import { useStore } from "src/store";
import { Md5 } from "ts-md5/dist/md5"; import { Md5 } from "ts-md5/dist/md5";
import Initializer from "src/common/Initializer"; import Initializer from "src/common/Initializer";
import { api } from "src/boot/axios";
class _Data { class _Data {
user_name: string | null = null; user_name: string | null = null;
@ -349,7 +350,6 @@ export default defineComponent({
} }
if (remember_password.value) { if (remember_password.value) {
data.ip_address = Cookies.get("name") ?? data.ip_address;
data.user_name = Cookies.get("user_name") ?? data.user_name; data.user_name = Cookies.get("user_name") ?? data.user_name;
cache_password = Cookies.get("password"); cache_password = Cookies.get("password");
if ( if (
@ -383,126 +383,140 @@ export default defineComponent({
show_show_password, show_show_password,
full_screen, full_screen,
async onSubmit() { async onSubmit() {
data.loading = true;
return new Promise((resolve) => { return new Promise((resolve) => {
data.loading = true;
try { try {
let global_data = GlobalData.getInstance(); let global_data = GlobalData.getInstance();
const url = api
"ws://" + .get("/get_websocket_port")
data.ip_address + .then((response) => {
":" + let final_ws_port = GlobalData.kDefaultWebsocektPort;
GlobalData.kDefaultWebsocektPort.toString() + if (response && typeof response.data != "undefined") {
GlobalData.kWebsocketResource; if (typeof response.data != "number") {
web_socket = new ClientConnection( const temp_port = parseInt(response.data);
url, if (!isNaN(temp_port) && temp_port != Infinity) {
data.user_name, final_ws_port = temp_port;
data.password == cache_password }
? data.password } else {
: Md5.hashStr(data.password ?? "admin") final_ws_port = response.data;
);
let timer = setTimeout(() => {
web_socket?.destory();
web_socket = null;
$q.notify({
color: "negative",
icon: "warning",
message:
$t.t("login fail!") +
$t.t("connect time out!") +
$t.t(
"please check server state, or check server ip address!"
),
position: "center",
timeout: 1500,
});
SessionStorage.set("auth", PermissionLevel.None);
resolve(false);
data.loading = false;
}, 5000);
web_socket.login_callback = (is_login) => {
clearTimeout(timer);
if (is_login && web_socket) {
global_data.addClient(data.ip_address, web_socket);
global_data.setCurrentClientName(data.ip_address);
SessionStorage.set("auth", PermissionLevel.Root);
SessionStorage.set("url", url);
SessionStorage.set("name", data.ip_address);
SessionStorage.set("user_name", data.user_name);
SessionStorage.set(
"password",
data.password == cache_password
? data.password
: Md5.hashStr(data.password ?? "admin")
);
// TODO add self to setConnects
if (remember_password.value) {
{
Cookies.set("remember_password", JSON.stringify(true), {
expires: 15,
});
Cookies.set(
"auto_login",
JSON.stringify(auto_login.value),
{
expires: 15,
}
);
Cookies.set("name", data.ip_address, {
expires: 15,
});
Cookies.set("user_name", data.user_name ?? "admin", {
expires: 15,
});
Cookies.set(
"password",
data.password == cache_password
? data.password ?? Md5.hashStr("admin")
: Md5.hashStr(data.password ?? "admin"),
{
expires: 15,
}
);
} }
} else { const url =
Cookies.remove("remember_password"); "ws://" +
Cookies.remove("auto_login"); data.ip_address +
Cookies.remove("name"); ":" +
Cookies.remove("user_name"); final_ws_port.toString() +
Cookies.remove("password"); GlobalData.kWebsocketResource;
} web_socket = new ClientConnection(
url,
$store.commit("setDeviceIpAddress", data.ip_address); data.user_name,
data.password == cache_password
setTimeout(() => { ? data.password
new Initializer({ : Md5.hashStr(data.password ?? "admin")
$t, );
$store, let timer = setTimeout(() => {
$q, web_socket?.destory();
}) web_socket = null;
.initialize() $q.notify({
.then(() => { color: "negative",
$store.commit("setInitialized"); icon: "warning",
message:
$t.t("login fail!") +
$t.t("connect time out!") +
$t.t(
"please check server state, or check server ip address!"
),
position: "center",
timeout: 1500,
}); });
}, 0); SessionStorage.set("auth", PermissionLevel.None);
resolve(false);
data.loading = false;
}, 5000);
web_socket.login_callback = (is_login) => {
clearTimeout(timer);
if (is_login && web_socket) {
global_data.addClient(data.ip_address, web_socket);
global_data.setCurrentClientName(data.ip_address);
$route.push("/"); SessionStorage.set("auth", PermissionLevel.Root);
} else { SessionStorage.set("url", url);
$q.notify({ SessionStorage.set("name", data.ip_address);
color: "negative", SessionStorage.set("user_name", data.user_name);
icon: "warning", SessionStorage.set(
message: "password",
$t.t("login fail!") + $t.t("user or password error!"), data.password == cache_password
position: "center", ? data.password
timeout: 1500, : Md5.hashStr(data.password ?? "admin")
}); );
SessionStorage.set("auth", PermissionLevel.None);
} // TODO add self to setConnects
resolve(true);
data.loading = false; if (remember_password.value) {
}; Cookies.set("remember_password", JSON.stringify(true), {
expires: 15,
});
Cookies.set(
"auto_login",
JSON.stringify(auto_login.value),
{
expires: 15,
}
);
Cookies.set("user_name", data.user_name ?? "admin", {
expires: 15,
});
Cookies.set(
"password",
data.password == cache_password
? data.password ?? Md5.hashStr("admin")
: Md5.hashStr(data.password ?? "admin"),
{
expires: 15,
}
);
} else {
Cookies.remove("remember_password");
Cookies.remove("auto_login");
Cookies.remove("name");
Cookies.remove("user_name");
Cookies.remove("password");
}
$store.commit("setDeviceIpAddress", data.ip_address);
setTimeout(() => {
new Initializer({
$t,
$store,
$q,
})
.initialize()
.then(() => {
$store.commit("setInitialized");
});
}, 0);
$route.push("/");
} else {
$q.notify({
color: "negative",
icon: "warning",
message:
$t.t("login fail!") + $t.t("user or password error!"),
position: "center",
timeout: 1500,
});
SessionStorage.set("auth", PermissionLevel.None);
}
resolve(true);
data.loading = false;
};
}
})
.catch(() => {
resolve(true);
data.loading = false;
});
} catch { } catch {
resolve(true); resolve(true);
data.loading = false; data.loading = false;

View File

@ -314,8 +314,8 @@ export default defineComponent({
landspace, landspace,
is_pwa, is_pwa,
async onSubmit() { async onSubmit() {
data.loading = true;
return new Promise((resolve) => { return new Promise((resolve) => {
data.loading = true;
try { try {
let global_data = GlobalData.getInstance(); let global_data = GlobalData.getInstance();
api api
@ -447,10 +447,6 @@ export default defineComponent({
.catch(() => { .catch(() => {
resolve(true); resolve(true);
data.loading = false; data.loading = false;
})
.finally(() => {
resolve(true);
data.loading = false;
}); });
} catch { } catch {
resolve(true); resolve(true);