修改IP、子网掩码的校验逻辑

This commit is contained in:
fangxiang 2023-02-10 16:29:27 +08:00
parent 225fbd4faf
commit 2930add85f
11 changed files with 594 additions and 571 deletions

View File

@ -0,0 +1,59 @@
export default class ValidationUtil {
static isIpAddress(str: string): boolean {
return (
str == "localhost" ||
/^([1-9]|[1-9][0-9]|1\d\d|2[0-2][0-3])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.([1-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-4])$/.test(
str
)
);
}
static isHost(str: string): boolean {
return (
str == "localhost" ||
/^([1-9]|[1-9][0-9]|1\d\d|2[0-2][0-3])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.([1-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-4])$/.test(
str
) ||
/^([1-9]|[1-9][0-9]|1\d\d|2[0-2][0-3])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])\.([1-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-4])\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/.test(
str
)
);
}
static isMacAddress(str: string): boolean {
return /([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}/.test(str);
}
static isMaskAddress(str: string): boolean {
return /^(254|252|248|240|224|192|128|0)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0)$/.test(
str
);
}
static isHexStr(str: string): boolean {
if (str != null && str != undefined && typeof str == "string") {
str = str.trim();
if (str.length == 0) {
return true;
}
for (const item of str.split(" ")) {
if (item.length > 4) {
return false;
}
if (!/^0[xX][A-Fa-f0-9]{1,2}/.test(item)) {
return false;
}
}
return true;
}
return false;
}
static isResolution(str: string): boolean {
return /([0-9]{1,5})[x|X]([0-9]{1,5}@[0-9]{1,3}$)/.test(str);
}
static isEnglishOrNum(str: string): boolean {
return /^[0-9a-zA-Z_\-]+$/.test(str);
}
}

View File

@ -88,7 +88,8 @@
(val) => (val) =>
(val && val.length > 0) || $t('Please type something'), (val && val.length > 0) || $t('Please type something'),
(val) => (val) =>
isIpAddress(val) || $t('Please input vaild ip address'), isMaskAddress(val) ||
$t('Please input vaild netmask address'),
]" ]"
lazy-rules lazy-rules
/> />
@ -162,12 +163,12 @@
</style> </style>
<script lang="ts"> <script lang="ts">
import { defineComponent, ref, Ref, reactive } from "vue"; import { defineComponent, ref } from "vue";
import { useStore } from "src/store"; import { useStore } from "src/store";
import { useQuasar, copyToClipboard, uid } from "quasar"; import { useQuasar } from "quasar";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import GlobalData from "src/common/GlobalData";
import { AdvancedIpAddressEntity } from "src/entities/AdvancedIpAddressEntity"; import { AdvancedIpAddressEntity } from "src/entities/AdvancedIpAddressEntity";
import ValidationUtil from "src/common/ValidationUtil";
export default defineComponent({ export default defineComponent({
name: "ComponentSystenSettingAdvancedNetworkDialog", name: "ComponentSystenSettingAdvancedNetworkDialog",
@ -267,12 +268,10 @@ export default defineComponent({
} catch {} } catch {}
}, },
isIpAddress(str: string) { isIpAddress(str: string) {
return ( return ValidationUtil.isIpAddress(str);
str == "localhost" || },
/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test( isMaskAddress(str: string) {
str return ValidationUtil.isMaskAddress(str);
)
);
}, },
checkFilterListIp(str: string) { checkFilterListIp(str: string) {
if (Array.isArray(ip_filter_list)) { if (Array.isArray(ip_filter_list)) {

View File

@ -139,6 +139,7 @@ import { useQuasar, copyToClipboard } from "quasar";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { ExternalControlTableEntity } from "src/entities/ExternalControlTableEntity"; import { ExternalControlTableEntity } from "src/entities/ExternalControlTableEntity";
import ValidationUtil from "src/common/ValidationUtil";
export default defineComponent({ export default defineComponent({
name: "ComponentCenterControlButtonDialog", name: "ComponentCenterControlButtonDialog",
@ -246,22 +247,7 @@ export default defineComponent({
show_dialog.value = false; show_dialog.value = false;
}, },
isHexStr(val: string) { isHexStr(val: string) {
if (val != null && val != undefined && typeof val == "string") { return ValidationUtil.isHexStr(val);
val = val.trim();
if (val.length == 0) {
return true;
}
for (const item of val.split(" ")) {
if (item.length > 4) {
return false;
}
if (!/^0[xX][A-Fa-f0-9]{1,2}/.test(item)) {
return false;
}
}
return true;
}
return false;
}, },
}; };
}, },

View File

@ -406,6 +406,7 @@ import {
SerialPortConfigEntity, SerialPortConfigEntity,
} from "src/entities/SerialPortConfigEntity"; } from "src/entities/SerialPortConfigEntity";
import { Protocol } from "src/entities/WSProtocol"; import { Protocol } from "src/entities/WSProtocol";
import ValidationUtil from "src/common/ValidationUtil";
export default defineComponent({ export default defineComponent({
name: "ComponentCenterControlDialog", name: "ComponentCenterControlDialog",
@ -733,12 +734,7 @@ export default defineComponent({
} }
}, },
isIpAddress(str: string) { isIpAddress(str: string) {
return ( return ValidationUtil.isIpAddress(str);
str == "localhost" ||
/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(
str
)
);
}, },
}; };
}, },

View File

@ -152,6 +152,7 @@ import { api } from "boot/axios";
import { HttpProtocol } from "src/entities/HttpProtocol"; import { HttpProtocol } from "src/entities/HttpProtocol";
import JointActionEquipmentTableEntity from "src/entities/JointActionEquipmentTableEntity"; import JointActionEquipmentTableEntity from "src/entities/JointActionEquipmentTableEntity";
import EventBus, { EventNamesDefine } from "src/common/EventBus"; import EventBus, { EventNamesDefine } from "src/common/EventBus";
import ValidationUtil from "src/common/ValidationUtil";
export default defineComponent({ export default defineComponent({
name: "ComponentEditJointActionEquipmentDialog", name: "ComponentEditJointActionEquipmentDialog",
@ -330,15 +331,7 @@ export default defineComponent({
} }
}, },
isHost(str: string) { isHost(str: string) {
return ( return ValidationUtil.isHost(str);
str == "localhost" ||
/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(
str
) ||
/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/.test(
str
)
);
}, },
}; };
}, },

View File

@ -190,8 +190,8 @@
(val && val.length > 0) || (val && val.length > 0) ||
$t('Please type something'), $t('Please type something'),
(val) => (val) =>
isIpAddress(val) || isMaskAddress(val) ||
$t('Please input vaild ip address'), $t('Please input vaild netmask address'),
]" ]"
lazy-rules lazy-rules
/> />
@ -1454,7 +1454,7 @@ import TimingTaskDialog from "src/components/TimingTaskDialog.vue";
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 ValidationUtil from "src/common/ValidationUtil";
import { date } from "quasar"; import { date } from "quasar";
import { Protocol } from "src/entities/WSProtocol"; import { Protocol } from "src/entities/WSProtocol";
import TimingTaskEntity, { import TimingTaskEntity, {
@ -2512,20 +2512,17 @@ export default defineComponent({
} }
}, },
isIpAddress(str: string) { isIpAddress(str: string) {
return ( return ValidationUtil.isIpAddress(str);
str == "localhost" ||
/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(
str
)
);
}, },
isMacAddress(str: string) { isMacAddress(str: string) {
return /([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}/.test(str); return ValidationUtil.isMacAddress(str);
},
isMaskAddress(str: string) {
return ValidationUtil.isMaskAddress(str);
}, },
checkResolution(str: string) { checkResolution(str: string) {
const reg = /([0-9]{1,5})[x|X]([0-9]{1,5}@[0-9]{1,3}$)/;
return ( return (
reg.test(str) || ValidationUtil.isResolution(str) ||
$t.t("the resolution format is incorrect,") + $t.t("the resolution format is incorrect,") +
$t.t("for example: ") + $t.t("for example: ") +
"1920x1080@60" "1920x1080@60"

View File

@ -294,6 +294,7 @@ import AdvancedIpAddressDialog from "src/components/AdvancedIpAddressDialog.vue"
import { AdvancedIpAddressEntity } from "src/entities/AdvancedIpAddressEntity"; import { AdvancedIpAddressEntity } from "src/entities/AdvancedIpAddressEntity";
import { api } from "src/boot/axios"; import { api } from "src/boot/axios";
import { HttpProtocol } from "src/entities/HttpProtocol"; import { HttpProtocol } from "src/entities/HttpProtocol";
import ValidationUtil from "src/common/ValidationUtil";
export default defineComponent({ export default defineComponent({
name: "ComponentSystenSettingAdvancedNetworkDialog", name: "ComponentSystenSettingAdvancedNetworkDialog",
@ -353,15 +354,6 @@ export default defineComponent({
const advance_ip_rows: Ref<AdvancedIpAddressEntity[]> = ref([]); const advance_ip_rows: Ref<AdvancedIpAddressEntity[]> = ref([]);
const isIpAddress = (str: string) => {
return (
str == "localhost" ||
/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(
str
)
);
};
let _resolove: any = null; let _resolove: any = null;
return { return {
@ -629,7 +621,7 @@ export default defineComponent({
}); });
}, },
isEnglishOrNum(str: string) { isEnglishOrNum(str: string) {
return /^[0-9a-zA-Z_\-]+$/.test(str); return ValidationUtil.isEnglishOrNum(str);
}, },
}; };
}, },

View File

@ -57,7 +57,7 @@ export default {
Accept: "Accept", Accept: "Accept",
"move speed": "Move Speed", "move speed": "Move Speed",
"y offset": "Y Offset", "y offset": "Y Offset",
"the number must be greater than 0":"the number must be greater than 0", "the number must be greater than 0": "the number must be greater than 0",
"pos x": "X Position", "pos x": "X Position",
"pos y": "Y Position", "pos y": "Y Position",
width: "Width", width: "Width",
@ -434,14 +434,14 @@ export default {
"verify key length is 6": "Verify Key Length Is 6", "verify key length is 6": "Verify Key Length Is 6",
server: "Server", server: "Server",
"set cloud server setting": "Set Cloud Server Setting", "set cloud server setting": "Set Cloud Server Setting",
"set magic wall":"Set Magic wall", "set magic wall": "Set Magic wall",
"update magic wall":"Update Magic Wall", "update magic wall": "Update Magic Wall",
"magic wall":"Magic Wall", "magic wall": "Magic Wall",
"angle":"Angle", angle: "Angle",
"topology diagram":"Topology Diagram", "topology diagram": "Topology Diagram",
"physical central location":"Central Location", "physical central location": "Central Location",
"monitors list":"Monitors List", "monitors list": "Monitors List",
"resize":"Resize", resize: "Resize",
"export magic":"Export", "export magic": "Export",
"raster graph":"Raster Graph" "raster graph": "Raster Graph",
}; };

View File

@ -123,6 +123,7 @@ export default {
"local disk": "本地磁盘", "local disk": "本地磁盘",
usb: "U盘", usb: "U盘",
"Please input vaild ip address": "请输入合法的IP地址", "Please input vaild ip address": "请输入合法的IP地址",
"Please input vaild netmask address": "请输入合法的掩码地址",
"Please input vaild mac address": "请输入合法的MAC地址", "Please input vaild mac address": "请输入合法的MAC地址",
"server ip address": "服务器地址", "server ip address": "服务器地址",
"please input server ip address": "请输入服务器地址", "please input server ip address": "请输入服务器地址",
@ -701,14 +702,14 @@ export default {
"verify key length is 6": "校验码长度必须为6", "verify key length is 6": "校验码长度必须为6",
server: "服务", server: "服务",
"set cloud server setting": "设置云服务器", "set cloud server setting": "设置云服务器",
"set magic wall":"设置魔墙", "set magic wall": "设置魔墙",
"update magic wall":"更新魔墙", "update magic wall": "更新魔墙",
"magic wall":"魔墙", "magic wall": "魔墙",
"angle":"角度", angle: "角度",
"topology diagram":"拓扑图", "topology diagram": "拓扑图",
"physical central location":"物理中心位置", "physical central location": "物理中心位置",
"monitors list":"显示器", "monitors list": "显示器",
"resize":"缩放", resize: "缩放",
"export magic":"导出", "export magic": "导出",
"raster graph":"栅格图" "raster graph": "栅格图",
}; };

View File

@ -68,11 +68,7 @@
(val && val.length > 0) || (val && val.length > 0) ||
$t('Please type something'), $t('Please type something'),
(val) => (val) =>
val == 'localhost' || isHost(val) || $t('Please input vaild ip address'),
/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(
val
) ||
$t('Please input vaild ip address'),
]" ]"
@keydown=" @keydown="
(evt) => { (evt) => {
@ -363,6 +359,7 @@ import Initializer from "src/common/Initializer";
import { api } from "src/boot/axios"; import { api } from "src/boot/axios";
import { HttpProtocol } from "src/entities/HttpProtocol"; import { HttpProtocol } from "src/entities/HttpProtocol";
import { Plugins as CapacitorPlugins } from "@capacitor/core"; import { Plugins as CapacitorPlugins } from "@capacitor/core";
import ValidationUtil from "src/common/ValidationUtil";
class _Data { class _Data {
user_name: string | null = null; user_name: string | null = null;
@ -699,6 +696,9 @@ export default defineComponent({
} }
} }
}, },
isHost(str: string) {
return ValidationUtil.isHost(str);
},
}; };
}, },
}); });

View File

@ -1,482 +1,482 @@
<template> <template>
<q-layout view="hHh lpR fFf"> <q-layout view="hHh lpR fFf">
<img <img
v-if="landspace" v-if="landspace"
src="login/login_background.png" src="login/login_background.png"
class="fit" class="fit"
style="position: fixed" style="position: fixed"
/> />
<q-page-container> <q-page-container>
<q-page <q-page
class="row items-center" class="row items-center"
style="position: ; /*fixed*/" style="position: ; /*fixed*/"
:class="landspace ? '' : 'justify-evenly'" :class="landspace ? '' : 'justify-evenly'"
:style="landspace ? { left: '50%' } : {}" :style="landspace ? { left: '50%' } : {}"
> >
<q-card :style="{ width: (landspace ? 34 : 70) + 'vw' }"> <q-card :style="{ width: (landspace ? 34 : 70) + 'vw' }">
<q-card-section class="text-center text-h6"> <q-card-section class="text-center text-h6">
{{ $t("login") }} {{ $t("login") }}
</q-card-section> </q-card-section>
<q-separator /> <q-separator />
<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"> <q-list class="fit">
<q-item v-if="$store.state.advanced_debug"> <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"
outlined outlined
:loading="data.loading" :loading="data.loading"
:disable="data.loading" :disable="data.loading"
v-model="data.ip_address" v-model="data.ip_address"
:label="$t('server ip address')" :label="$t('server ip address')"
:hint="$t('please input server ip address')" :hint="$t('please input server ip address')"
lazy-rules lazy-rules
:rules="[ :rules="[
(val) => (val) =>
(val && val.length > 0) || (val && val.length > 0) ||
$t('Please type something'), $t('Please type something'),
(val) => (val) =>
val == 'localhost' || isHost(val) || $t('Please input vaild ip address'),
/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test( ]"
val @keydown="
) || (evt) => {
$t('Please input vaild ip address'), if (evt.keyCode == 13) {
]" $refs?.user_name?.focus();
@keydown=" }
(evt) => { }
if (evt.keyCode == 13) { "
$refs?.user_name?.focus(); >
} <template v-slot:prepend>
} <q-icon name="public" class="background" />
" </template>
> <template v-if="data.ip_address" v-slot:append>
<template v-slot:prepend> <q-icon
<q-icon name="public" class="background" /> name="cancel"
</template> @click.stop="data.ip_address = null"
<template v-if="data.ip_address" v-slot:append> class="cursor-pointer"
<q-icon />
name="cancel" </template>
@click.stop="data.ip_address = null" </q-input>
class="cursor-pointer" </q-item-section>
/> </q-item>
</template>
</q-input> <q-item>
</q-item-section> <q-item-section>
</q-item> <q-input
:autofocus="!data.user_name"
<q-item> outlined
<q-item-section> ref="user_name"
<q-input :loading="data.loading"
:autofocus="!data.user_name" :disable="data.loading"
outlined v-model="data.user_name"
ref="user_name" :label="$t('user name')"
:loading="data.loading" :hint="$t('please input user name')"
:disable="data.loading" lazy-rules
v-model="data.user_name" :rules="[
:label="$t('user name')" (val) =>
:hint="$t('please input user name')" (val && val.length > 0) ||
lazy-rules $t('Please type something'),
:rules="[ ]"
(val) => @keydown="
(val && val.length > 0) || (evt) => {
$t('Please type something'), if (evt.keyCode == 13) {
]" $refs?.password_input?.focus();
@keydown=" }
(evt) => { }
if (evt.keyCode == 13) { "
$refs?.password_input?.focus(); >
} <template v-slot:prepend>
} <q-icon name="account_circle" class="background" />
" </template>
> <template v-if="data.user_name" v-slot:append>
<template v-slot:prepend > <q-icon
<q-icon name="account_circle" class="background" /> name="cancel"
</template> @click.stop="data.user_name = null"
<template v-if="data.user_name" v-slot:append> class="cursor-pointer"
<q-icon />
name="cancel" </template>
@click.stop="data.user_name = null" </q-input>
class="cursor-pointer" </q-item-section>
/> </q-item>
</template>
</q-input> <q-item>
</q-item-section> <q-item-section>
</q-item> <q-input
outlined
<q-item> ref="password_input"
<q-item-section> :loading="data.loading"
<q-input :disable="data.loading"
outlined :type="data.show_password ? '' : 'password'"
ref="password_input" v-model="data.password"
:loading="data.loading" :label="$t('password')"
:disable="data.loading" :hint="$t('please input password')"
:type="data.show_password ? '' : 'password'" lazy-rules
v-model="data.password" :rules="[
:label="$t('password')" (val) =>
:hint="$t('please input password')" (val && val.length > 0) ||
lazy-rules $t('Please type something'),
:rules="[ ]"
(val) => @keydown="
(val && val.length > 0) || (evt) => {
$t('Please type something'), if (evt.keyCode == 13) {
]" $refs?.login_button?.click();
@keydown=" }
(evt) => { }
if (evt.keyCode == 13) { "
$refs?.login_button?.click(); >
} <template v-slot:prepend>
} <q-icon name="key" class="background" />
" </template>
> <template v-if="data.password" v-slot:append>
<template v-slot:prepend > <q-icon
<q-icon name="key" class="background" /> :name="
</template> data.show_password ? 'visibility' : 'visibility_off'
<template v-if="data.password" v-slot:append> "
<q-icon class="cursor-pointer"
:name=" @click="data.show_password = !data.show_password"
data.show_password ? 'visibility' : 'visibility_off' />
" <q-icon
class="cursor-pointer" name="cancel"
@click="data.show_password = !data.show_password" @click.stop="data.password = null"
/> class="cursor-pointer"
<q-icon />
name="cancel" </template>
@click.stop="data.password = null" </q-input>
class="cursor-pointer" </q-item-section>
/> </q-item>
</template> <q-item class="q-mt-md">
</q-input> <q-item-section>
</q-item-section> <q-checkbox
</q-item> :label="$t('remember password')"
<q-item class="q-mt-md"> v-model="remember_password"
<q-item-section> :disable="data.loading"
<q-checkbox />
:label="$t('remember password')" </q-item-section>
v-model="remember_password" <q-item-section>
:disable="data.loading" <q-checkbox
/> :label="$t('auto login')"
</q-item-section> v-model="auto_login"
<q-item-section> @update:model-value="remember_password = true"
<q-checkbox :disable="data.loading"
:label="$t('auto login')" />
v-model="auto_login" </q-item-section>
@update:model-value="remember_password = true" </q-item>
:disable="data.loading" </q-list>
/> </q-form>
</q-item-section> </q-card-section>
</q-item> <q-card-actions class="q-px-lg">
</q-list> <q-btn
</q-form> ref="login_button"
</q-card-section> class="full-width text-h6"
<q-card-actions class="q-px-lg"> :loading="data.loading"
<q-btn :label="$t('login')"
ref="login_button" no-caps
class="full-width text-h6" style="
:loading="data.loading" background: #273de4;
:label="$t('login')" box-shadow: 0 4px 6px 0px rgb(39 60 228 / 40%);
no-caps "
style=" text-color="white"
background: #273de4; @click="$refs?.login_form?.submit()"
box-shadow: 0 4px 6px 0px rgb(39 60 228 / 40%); />
" </q-card-actions>
text-color="white" </q-card>
@click="$refs?.login_form?.submit()" </q-page>
/> </q-page-container>
</q-card-actions> </q-layout>
</q-card> </template>
</q-page>
</q-page-container> <style scoped>
</q-layout> .background {
</template> color: #3f69fd;
}
<style scoped> </style>
.background{
color: #3f69fd; <script lang="ts">
} import { defineComponent, onMounted, reactive, ref, Ref, computed } from "vue";
</style>
import GlobalData from "src/common/GlobalData";
<script lang="ts"> import { Cookies, LocalStorage, SessionStorage, useQuasar } from "quasar";
import { defineComponent, onMounted, reactive, ref, Ref, computed } from "vue"; import ClientConnection from "src/common/ClientConnection";
import PermissionLevel from "src/entities/PermissionLevel";
import GlobalData from "src/common/GlobalData"; import { useI18n } from "vue-i18n";
import { Cookies, LocalStorage, SessionStorage, useQuasar } from "quasar"; import { useRouter } from "vue-router";
import ClientConnection from "src/common/ClientConnection"; import EventBus, { EventNamesDefine } from "src/common/EventBus";
import PermissionLevel from "src/entities/PermissionLevel"; import { useStore } from "src/store";
import { useI18n } from "vue-i18n"; import { Md5 } from "ts-md5";
import { useRouter } from "vue-router"; import Initializer from "src/common/Initializer";
import EventBus, { EventNamesDefine } from "src/common/EventBus"; import { api } from "src/boot/axios";
import { useStore } from "src/store"; import { HttpProtocol } from "src/entities/HttpProtocol";
import { Md5 } from "ts-md5"; import ValidationUtil from "src/common/ValidationUtil";
import Initializer from "src/common/Initializer";
import { api } from "src/boot/axios"; class _Data {
import { HttpProtocol } from "src/entities/HttpProtocol"; user_name: string | null = null;
password: string | null = null;
class _Data { loading = false;
user_name: string | null = null; ip_address = window.location.hostname;
password: string | null = null; show_password = false;
loading = false;
ip_address = window.location.hostname; constructor() {
show_password = false; let temp = LocalStorage.getItem("default_ip_address");
if (temp) {
constructor() { this.ip_address = temp.toString();
let temp = LocalStorage.getItem("default_ip_address"); } else {
if (temp) { this.ip_address = window.location.hostname;
this.ip_address = temp.toString(); }
} else {
this.ip_address = window.location.hostname; temp = LocalStorage.getItem("default_user_name");
} if (temp) {
this.user_name = temp.toString();
temp = LocalStorage.getItem("default_user_name"); }
if (temp) {
this.user_name = temp.toString(); temp = LocalStorage.getItem("default_password");
} if (temp) {
this.password = temp.toString();
temp = LocalStorage.getItem("default_password"); }
if (temp) { }
this.password = temp.toString(); }
}
} export default defineComponent({
} name: "PageLogin",
export default defineComponent({ components: {},
name: "PageLogin",
setup() {
components: {}, const $q = useQuasar();
const $t = useI18n();
setup() { const $route = useRouter();
const $q = useQuasar(); const $store = useStore();
const $t = useI18n(); const data = reactive(new _Data());
const $route = useRouter();
const $store = useStore(); try {
const data = reactive(new _Data()); (window as any).setPcTheme();
} catch {}
try {
(window as any).setPcTheme(); const login_form: Ref<any> = ref(null);
} catch {}
const remember_password = ref(false);
const login_form: Ref<any> = ref(null); const auto_login = ref(false);
let cache_password: string | null = null;
const remember_password = ref(false);
const auto_login = ref(false); let web_socket: ClientConnection | null = null;
let cache_password: string | null = null; let is_pwa = ["fullscreen", "standalone", "minimal-ui"].some(
(displayMode) =>
let web_socket: ClientConnection | null = null; window.matchMedia("(display-mode: " + displayMode + ")").matches
let is_pwa = ["fullscreen", "standalone", "minimal-ui"].some( );
(displayMode) =>
window.matchMedia("(display-mode: " + displayMode + ")").matches const landspace = computed({
); get: () => $store.state.landspace,
set: (val) => null,
const landspace = computed({ });
get: () => $store.state.landspace,
set: (val) => null, EventBus.getInstance().on(EventNamesDefine.WindowResize, () => {
}); landspace.value = window.innerHeight < window.innerWidth;
});
EventBus.getInstance().on(EventNamesDefine.WindowResize, () => {
landspace.value = window.innerHeight < window.innerWidth; onMounted(() => {
}); console.log((<any>window).user_search);
if ((<any>window).user_search?.user && (<any>window).user_search?.pwd) {
onMounted(() => { if ((<any>window).user_search?.host) {
console.log((<any>window).user_search); data.ip_address = (<any>window).user_search?.host;
if ((<any>window).user_search?.user && (<any>window).user_search?.pwd) { }
if ((<any>window).user_search?.host) { data.user_name = (<any>window).user_search?.user;
data.ip_address = (<any>window).user_search?.host; data.password = (<any>window).user_search?.pwd;
} login_form.value.submit();
data.user_name = (<any>window).user_search?.user; } else {
data.password = (<any>window).user_search?.pwd; if (auto_login.value) {
login_form.value.submit(); login_form.value.submit();
} else { }
if (auto_login.value) { }
login_form.value.submit(); });
}
} try {
}); remember_password.value = JSON.parse(
Cookies.get("remember_password")
try { ) as boolean;
remember_password.value = JSON.parse( auto_login.value = JSON.parse(Cookies.get("auto_login")) as boolean;
Cookies.get("remember_password") if (
) as boolean; typeof remember_password.value == "undefined" ||
auto_login.value = JSON.parse(Cookies.get("auto_login")) as boolean; remember_password.value == null
if ( ) {
typeof remember_password.value == "undefined" || remember_password.value = false;
remember_password.value == null }
) {
remember_password.value = false; if (typeof auto_login.value == "undefined" || auto_login.value == null) {
} auto_login.value = false;
}
if (typeof auto_login.value == "undefined" || auto_login.value == null) {
auto_login.value = false; if (remember_password.value) {
} data.user_name = Cookies.get("user_name") ?? data.user_name;
cache_password = Cookies.get("password");
if (remember_password.value) { if (
data.user_name = Cookies.get("user_name") ?? data.user_name; typeof cache_password != "undefined" &&
cache_password = Cookies.get("password"); cache_password != null &&
if ( cache_password.length == 32
typeof cache_password != "undefined" && ) {
cache_password != null && data.password = cache_password;
cache_password.length == 32 } else {
) { cache_password = null;
data.password = cache_password; }
} else { }
cache_password = null; } catch {}
}
} return {
} catch {} login_form,
data,
return { remember_password,
login_form, auto_login,
data, landspace,
remember_password, is_pwa,
auto_login, async onSubmit() {
landspace, data.loading = true;
is_pwa, return new Promise((resolve) => {
async onSubmit() { try {
data.loading = true; let global_data = GlobalData.getInstance();
return new Promise((resolve) => { api
try { .get(HttpProtocol.RequestPathGetWebscoketPort)
let global_data = GlobalData.getInstance(); .then((response) => {
api let final_ws_port = GlobalData.kDefaultWebsocektPort;
.get(HttpProtocol.RequestPathGetWebscoketPort) if (response && typeof response.data != "undefined") {
.then((response) => { if (typeof response.data != "number") {
let final_ws_port = GlobalData.kDefaultWebsocektPort; const temp_port = parseInt(response.data);
if (response && typeof response.data != "undefined") { if (!isNaN(temp_port) && temp_port != Infinity) {
if (typeof response.data != "number") { final_ws_port = temp_port;
const temp_port = parseInt(response.data); }
if (!isNaN(temp_port) && temp_port != Infinity) { } else {
final_ws_port = temp_port; final_ws_port = response.data;
} }
} else { const url =
final_ws_port = response.data; "ws://" +
} data.ip_address +
const url = ":" +
"ws://" + final_ws_port.toString() +
data.ip_address + GlobalData.kWebsocketResource;
":" + web_socket = new ClientConnection(
final_ws_port.toString() + url,
GlobalData.kWebsocketResource; data.user_name,
web_socket = new ClientConnection( data.password == cache_password
url, ? data.password
data.user_name, : Md5.hashStr(data.password ?? "admin")
data.password == cache_password );
? data.password let timer = setTimeout(() => {
: Md5.hashStr(data.password ?? "admin") web_socket?.destory();
); web_socket = null;
let timer = setTimeout(() => { $q.notify({
web_socket?.destory(); color: "negative",
web_socket = null; icon: "warning",
$q.notify({ message:
color: "negative", $t.t("login fail!") +
icon: "warning", $t.t("connect time out!") +
message: $t.t(
$t.t("login fail!") + "please check server state, or check server ip address!"
$t.t("connect time out!") + ),
$t.t( position: "center",
"please check server state, or check server ip address!" timeout: 1500,
), });
position: "center", SessionStorage.set("auth", PermissionLevel.None);
timeout: 1500, resolve(false);
}); data.loading = false;
SessionStorage.set("auth", PermissionLevel.None); }, 5000);
resolve(false); web_socket.login_callback = (is_login) => {
data.loading = false; clearTimeout(timer);
}, 5000); if (is_login && web_socket) {
web_socket.login_callback = (is_login) => { global_data.addClient(data.ip_address, web_socket);
clearTimeout(timer); global_data.setCurrentClientName(data.ip_address);
if (is_login && web_socket) {
global_data.addClient(data.ip_address, web_socket); SessionStorage.set("auth", PermissionLevel.Root);
global_data.setCurrentClientName(data.ip_address); SessionStorage.set("url", url);
SessionStorage.set("name", data.ip_address);
SessionStorage.set("auth", PermissionLevel.Root); SessionStorage.set("user_name", data.user_name);
SessionStorage.set("url", url); SessionStorage.set(
SessionStorage.set("name", data.ip_address); "password",
SessionStorage.set("user_name", data.user_name); data.password == cache_password
SessionStorage.set( ? data.password
"password", : Md5.hashStr(data.password ?? "admin")
data.password == cache_password );
? data.password
: Md5.hashStr(data.password ?? "admin") // TODO add self to setConnects
);
if (remember_password.value) {
// TODO add self to setConnects Cookies.set("remember_password", JSON.stringify(true), {
expires: 15,
if (remember_password.value) { });
Cookies.set("remember_password", JSON.stringify(true), { Cookies.set(
expires: 15, "auto_login",
}); JSON.stringify(auto_login.value),
Cookies.set( {
"auto_login", expires: 15,
JSON.stringify(auto_login.value), }
{ );
expires: 15, Cookies.set("user_name", data.user_name ?? "admin", {
} expires: 15,
); });
Cookies.set("user_name", data.user_name ?? "admin", { Cookies.set(
expires: 15, "password",
}); data.password == cache_password
Cookies.set( ? data.password ?? Md5.hashStr("admin")
"password", : Md5.hashStr(data.password ?? "admin"),
data.password == cache_password {
? data.password ?? Md5.hashStr("admin") expires: 15,
: Md5.hashStr(data.password ?? "admin"), }
{ );
expires: 15, } else {
} Cookies.remove("remember_password");
); Cookies.remove("auto_login");
} else { Cookies.remove("name");
Cookies.remove("remember_password"); Cookies.remove("user_name");
Cookies.remove("auto_login"); Cookies.remove("password");
Cookies.remove("name"); }
Cookies.remove("user_name");
Cookies.remove("password"); $store.commit("setDeviceIpAddress", data.ip_address);
}
setTimeout(() => {
$store.commit("setDeviceIpAddress", data.ip_address); new Initializer({
$t,
setTimeout(() => { $store,
new Initializer({ $q,
$t, })
$store, .initialize()
$q, .then(() => {
}) $store.commit("setInitialized");
.initialize() });
.then(() => { }, 0);
$store.commit("setInitialized");
}); $route.push("/");
}, 0); } else {
$q.notify({
$route.push("/"); color: "negative",
} else { icon: "warning",
$q.notify({ message:
color: "negative", $t.t("login fail!") + $t.t("user or password error!"),
icon: "warning", position: "center",
message: timeout: 1500,
$t.t("login fail!") + $t.t("user or password error!"), });
position: "center", SessionStorage.set("auth", PermissionLevel.None);
timeout: 1500, }
}); resolve(true);
SessionStorage.set("auth", PermissionLevel.None); data.loading = false;
} };
resolve(true); }
data.loading = false; })
}; .catch(() => {
} resolve(true);
}) data.loading = false;
.catch(() => { });
resolve(true); } catch {
data.loading = false; resolve(true);
}); data.loading = false;
} catch { }
resolve(true); });
data.loading = false; },
} onReset() {
}); data.user_name = null;
}, data.password = null;
onReset() { remember_password.value = false;
data.user_name = null; },
data.password = null; isHost(str: string) {
remember_password.value = false; return ValidationUtil.isHost(str);
}, },
}; };
}, },
}); });
</script> </script>