添加在线注册逻辑

This commit is contained in:
fangxiang 2022-03-16 16:45:52 +08:00
parent f2ae4560c8
commit c14041f82b
2 changed files with 111 additions and 3 deletions

View File

@ -55,6 +55,7 @@
<div> <div>
<q-btn <q-btn
:loading="loading" :loading="loading"
:disable="loading"
flat flat
round round
icon="close" icon="close"
@ -86,6 +87,8 @@
val="offline" val="offline"
:label="$t('offline register')" :label="$t('offline register')"
class="offset-md-1 col" class="offset-md-1 col"
:loading="loading"
:disable="loading"
/> />
<q-radio <q-radio
v-model="register_type" v-model="register_type"
@ -94,6 +97,8 @@
val="online" val="online"
:label="$t('online register')" :label="$t('online register')"
class="col" class="col"
:loading="loading"
:disable="loading"
/> />
</div> </div>
</q-item-section> </q-item-section>
@ -121,6 +126,8 @@
flat flat
icon="content_copy" icon="content_copy"
color="green" color="green"
:loading="loading"
:disable="loading"
@click=" @click="
copyToClipboard(register_code).then(() => copyToClipboard(register_code).then(() =>
$q.notify({ $q.notify({
@ -149,6 +156,8 @@
v-model="active_code" v-model="active_code"
lazy-rules lazy-rules
autofocus autofocus
:loading="loading"
:disable="loading"
:rules="[ :rules="[
(val) => (val) =>
(val && val.length > 0) || $t('Please type something'), (val && val.length > 0) || $t('Please type something'),
@ -160,6 +169,8 @@
icon="attach_file" icon="attach_file"
round round
flat flat
:loading="loading"
:disable="loading"
class="rotate-90" class="rotate-90"
color="green" color="green"
@click="$refs.select_file_dialog.pickFiles($event)" @click="$refs.select_file_dialog.pickFiles($event)"
@ -185,8 +196,10 @@
</q-item-section> </q-item-section>
<q-item-section> <q-item-section>
<q-input <q-input
v-model="active_code" v-model="server_address"
autofocus autofocus
:loading="loading"
:disable="loading"
lazy-rules lazy-rules
:rules="[ :rules="[
(val) => (val) =>
@ -208,6 +221,8 @@
val="forever" val="forever"
:label="$t('forever active')" :label="$t('forever active')"
class="offset-md-1 col" class="offset-md-1 col"
:loading="loading"
:disable="loading"
/> />
<q-radio <q-radio
v-model="active_type" v-model="active_type"
@ -216,6 +231,8 @@
val="limit" val="limit"
:label="$t('time limit active')" :label="$t('time limit active')"
class="col" class="col"
:loading="loading"
:disable="loading"
/> />
</div> </div>
</q-item-section> </q-item-section>
@ -229,7 +246,9 @@
v-model="active_hour" v-model="active_hour"
type="number" type="number"
min="1" min="1"
max="65535" max="120"
:loading="loading"
:disable="loading"
> >
<template v-slot:append> <template v-slot:append>
{{ $t("day") }} {{ $t("day") }}
@ -245,6 +264,7 @@
<q-card-actions align="right"> <q-card-actions align="right">
<q-btn <q-btn
:loading="loading" :loading="loading"
:disable="loading"
flat flat
:label="$t('Cancel')" :label="$t('Cancel')"
color="primary" color="primary"
@ -255,6 +275,7 @@
flat flat
:label="$t('register')" :label="$t('register')"
:loading="loading" :loading="loading"
:disable="loading"
type="submit" type="submit"
color="primary" color="primary"
/> />
@ -308,6 +329,7 @@ export default defineComponent({
const secret_key = ref(""); const secret_key = ref("");
const active_hour = ref(1); const active_hour = ref(1);
const ext_flag = ref(false); const ext_flag = ref(false);
const server_address = ref("");
const trial_days = ref(0); const trial_days = ref(0);
const last_days = ref(0); const last_days = ref(0);
@ -366,6 +388,7 @@ export default defineComponent({
register_flag, register_flag,
licence_file, licence_file,
select_file_dialog, select_file_dialog,
server_address,
copyToClipboard, copyToClipboard,
isShow() { isShow() {
return show_dialog.value; return show_dialog.value;
@ -375,7 +398,93 @@ export default defineComponent({
async onSubmit() { async onSubmit() {
loading.value = true; loading.value = true;
if (active_hour.value > 30 * 2) {
active_hour.value = 30 * 2;
}
if (active_hour.value < 1) {
active_hour.value = 1;
}
try { 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; let success = false;
const response = await GlobalData.getInstance() const response = await GlobalData.getInstance()
.getCurrentClient() .getCurrentClient()

View File

@ -1496,7 +1496,6 @@ export namespace Protocol {
) { ) {
super(); super();
this.rpc_id = rcp_id ?? 0; this.rpc_id = rcp_id ?? 0;
this.timeout = 1000 * 60 * 5; // 6911写固件比较耗时, 请求超时5分钟
this.command = Protocol.Commands.kRpcRegisterDevice; this.command = Protocol.Commands.kRpcRegisterDevice;
this.timestamp = new Date().getMilliseconds(); this.timestamp = new Date().getMilliseconds();
this.register_code = register_code; this.register_code = register_code;