添加在线注册逻辑
This commit is contained in:
parent
f2ae4560c8
commit
c14041f82b
|
@ -55,6 +55,7 @@
|
|||
<div>
|
||||
<q-btn
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
flat
|
||||
round
|
||||
icon="close"
|
||||
|
@ -86,6 +87,8 @@
|
|||
val="offline"
|
||||
:label="$t('offline register')"
|
||||
class="offset-md-1 col"
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
/>
|
||||
<q-radio
|
||||
v-model="register_type"
|
||||
|
@ -94,6 +97,8 @@
|
|||
val="online"
|
||||
:label="$t('online register')"
|
||||
class="col"
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
/>
|
||||
</div>
|
||||
</q-item-section>
|
||||
|
@ -121,6 +126,8 @@
|
|||
flat
|
||||
icon="content_copy"
|
||||
color="green"
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
@click="
|
||||
copyToClipboard(register_code).then(() =>
|
||||
$q.notify({
|
||||
|
@ -149,6 +156,8 @@
|
|||
v-model="active_code"
|
||||
lazy-rules
|
||||
autofocus
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
:rules="[
|
||||
(val) =>
|
||||
(val && val.length > 0) || $t('Please type something'),
|
||||
|
@ -160,6 +169,8 @@
|
|||
icon="attach_file"
|
||||
round
|
||||
flat
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
class="rotate-90"
|
||||
color="green"
|
||||
@click="$refs.select_file_dialog.pickFiles($event)"
|
||||
|
@ -185,8 +196,10 @@
|
|||
</q-item-section>
|
||||
<q-item-section>
|
||||
<q-input
|
||||
v-model="active_code"
|
||||
v-model="server_address"
|
||||
autofocus
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
lazy-rules
|
||||
:rules="[
|
||||
(val) =>
|
||||
|
@ -208,6 +221,8 @@
|
|||
val="forever"
|
||||
:label="$t('forever active')"
|
||||
class="offset-md-1 col"
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
/>
|
||||
<q-radio
|
||||
v-model="active_type"
|
||||
|
@ -216,6 +231,8 @@
|
|||
val="limit"
|
||||
:label="$t('time limit active')"
|
||||
class="col"
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
/>
|
||||
</div>
|
||||
</q-item-section>
|
||||
|
@ -229,7 +246,9 @@
|
|||
v-model="active_hour"
|
||||
type="number"
|
||||
min="1"
|
||||
max="65535"
|
||||
max="120"
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
>
|
||||
<template v-slot:append>
|
||||
{{ $t("day") }}
|
||||
|
@ -245,6 +264,7 @@
|
|||
<q-card-actions align="right">
|
||||
<q-btn
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
flat
|
||||
:label="$t('Cancel')"
|
||||
color="primary"
|
||||
|
@ -255,6 +275,7 @@
|
|||
flat
|
||||
:label="$t('register')"
|
||||
:loading="loading"
|
||||
:disable="loading"
|
||||
type="submit"
|
||||
color="primary"
|
||||
/>
|
||||
|
@ -308,6 +329,7 @@ export default defineComponent({
|
|||
const secret_key = ref("");
|
||||
const active_hour = ref(1);
|
||||
const ext_flag = ref(false);
|
||||
const server_address = ref("");
|
||||
|
||||
const trial_days = ref(0);
|
||||
const last_days = ref(0);
|
||||
|
@ -366,6 +388,7 @@ export default defineComponent({
|
|||
register_flag,
|
||||
licence_file,
|
||||
select_file_dialog,
|
||||
server_address,
|
||||
copyToClipboard,
|
||||
isShow() {
|
||||
return show_dialog.value;
|
||||
|
@ -375,7 +398,93 @@ export default defineComponent({
|
|||
|
||||
async onSubmit() {
|
||||
loading.value = true;
|
||||
if (active_hour.value > 30 * 2) {
|
||||
active_hour.value = 30 * 2;
|
||||
}
|
||||
if (active_hour.value < 1) {
|
||||
active_hour.value = 1;
|
||||
}
|
||||
|
||||
try {
|
||||
if (register_type.value == "online") {
|
||||
let licence_str = "";
|
||||
const requested = await new Promise((resolve) => {
|
||||
const timeout_handler = setTimeout(() => {
|
||||
resolve(false);
|
||||
}, 1000 * 5);
|
||||
try {
|
||||
let ws = new WebSocket(
|
||||
"ws://" + server_address.value + ":37631"
|
||||
);
|
||||
ws.onmessage = (data) => {
|
||||
interface IResult {
|
||||
id: 1;
|
||||
action: "license";
|
||||
result: {
|
||||
err?: "";
|
||||
update_key: "";
|
||||
lic: "";
|
||||
};
|
||||
}
|
||||
try {
|
||||
const result = JSON.parse(data.data) as IResult;
|
||||
if (result && !result.result.err) {
|
||||
licence_str = result.result.lic;
|
||||
}
|
||||
console.log(result);
|
||||
clearTimeout(timeout_handler);
|
||||
resolve(true);
|
||||
} catch {
|
||||
clearTimeout(timeout_handler);
|
||||
resolve(false);
|
||||
}
|
||||
};
|
||||
ws.onerror = () => {
|
||||
clearTimeout(timeout_handler);
|
||||
resolve(false);
|
||||
};
|
||||
ws.onclose = ws.onerror;
|
||||
ws.onopen = () => {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
id: 1,
|
||||
action: "license",
|
||||
params: {
|
||||
name: "MSFusion",
|
||||
days:
|
||||
active_type.value == "forever"
|
||||
? 0
|
||||
: parseInt(active_hour.value.toString()),
|
||||
minutes: 0,
|
||||
key: register_code.value,
|
||||
},
|
||||
})
|
||||
);
|
||||
};
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
clearTimeout(timeout_handler);
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
console.log(licence_str);
|
||||
if (requested && licence_str) {
|
||||
active_code.value = licence_str;
|
||||
console.log(licence_str);
|
||||
} else {
|
||||
$q.notify({
|
||||
color: "negative",
|
||||
icon: "warning",
|
||||
message: $t.t("register device") + $t.t("fail") + "!",
|
||||
position: "top",
|
||||
timeout: 1500,
|
||||
});
|
||||
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let success = false;
|
||||
const response = await GlobalData.getInstance()
|
||||
.getCurrentClient()
|
||||
|
|
|
@ -1496,7 +1496,6 @@ export namespace Protocol {
|
|||
) {
|
||||
super();
|
||||
this.rpc_id = rcp_id ?? 0;
|
||||
this.timeout = 1000 * 60 * 5; // 6911写固件比较耗时, 请求超时5分钟
|
||||
this.command = Protocol.Commands.kRpcRegisterDevice;
|
||||
this.timestamp = new Date().getMilliseconds();
|
||||
this.register_code = register_code;
|
||||
|
|
Loading…
Reference in New Issue