升级对话框显示服务器版本

This commit is contained in:
miao 2023-02-14 09:45:09 +08:00
parent 8b6949f087
commit febcf00d94
1 changed files with 290 additions and 278 deletions

View File

@ -1,278 +1,290 @@
<template> <template>
<q-dialog <q-dialog
persistent persistent
v-model="show_dialog" v-model="show_dialog"
@before-hide="resetData" @before-hide="resetData"
@keydown=" @keydown="
(evt) => { (evt) => {
if (!loading && evt.keyCode == 27) { if (!loading && evt.keyCode == 27) {
show_dialog = false; show_dialog = false;
} }
} }
" "
> >
<q-card class="overflow-hidden" style="overflow-y: scroll; max-width: 35vw"> <q-card class="overflow-hidden" style="overflow-y: scroll; max-width: 35vw">
<q-form @submit="onSubmit"> <q-form @submit="onSubmit">
<q-card-section class="q-ma-none q-pa-sm"> <q-card-section class="q-ma-none q-pa-sm">
<div class="row"> <div class="row">
<div class="col-auto text-h6"> <div class="col-auto text-h6">
{{ upgrade_type }}{{ $t("upgrade") }} {{ upgrade_type }}{{ $t("upgrade") }}
</div> </div>
<q-space /> <q-space />
<div> <div>
<q-btn <q-btn
:loading="loading" :loading="loading"
flat flat
round round
icon="close" icon="close"
:disable="loading" :disable="loading"
color="red" color="red"
v-close-popup v-close-popup
> >
<q-tooltip> <q-tooltip>
{{ $t("close") }} {{ $t("close") }}
</q-tooltip> </q-tooltip>
</q-btn> </q-btn>
</div> </div>
</div> </div>
</q-card-section> </q-card-section>
<q-separator /> <q-separator />
<q-card-section style="max-height: 50vh; width: 35vw" class="scroll"> <q-card-section style="max-height: 50vh; width: 35vw" class="scroll">
<q-list> <q-list>
<q-item> <q-item>
<q-item-section> <q-item-section>
<q-select <q-select
:label="$t('upgrade type')" :label="$t('upgrade type')"
:hint="$t('please input ') + $t('upgrade type') + ':'" :hint="$t('please input ') + $t('upgrade type') + ':'"
:options="select_options" :options="select_options"
v-model="upgrade_type" v-model="upgrade_type"
@update:model-value="file_count = 0" @update:model-value="file_count = 0"
> >
</q-select> </q-select>
</q-item-section> </q-item-section>
</q-item> </q-item>
<q-item> <q-item>
<q-item-section> <q-item-section>
<q-uploader <q-uploader
v-show="upgrade_type == $t('software')" v-show="upgrade_type == $t('software')"
class="full-width" class="full-width"
ref="uploader_software" ref="uploader_software"
:url="upload_url_software" :url="upload_url_software"
method="post" method="post"
:headers="generatorFileUploadHeaders" :headers="generatorFileUploadHeaders"
:label="$t('select software upgrade file') + ':'" :label="$t('select software upgrade file') + ':'"
accept=".zip,.tar,.tar.gz" accept=".zip,.tar,.tar.gz"
:hide-upload-btn="true" :hide-upload-btn="true"
@uploaded="onUploaded" @uploaded="onUploaded"
@failed="onFailed" @failed="onFailed"
@added="(files) => files && (file_count += files.length)" @added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)" @removed="(files) => files && (file_count -= files.length)"
/> />
<q-uploader <q-uploader
v-show="upgrade_type == $t('rootfs')" v-show="upgrade_type == $t('rootfs')"
class="full-width" class="full-width"
ref="uploader_rootfs" ref="uploader_rootfs"
:url="upload_url_rootfs" :url="upload_url_rootfs"
method="post" method="post"
:headers="generatorFileUploadHeaders" :headers="generatorFileUploadHeaders"
:label="$t('select rootfs upgrade file') + ':'" :label="$t('select rootfs upgrade file') + ':'"
accept=".img" accept=".img"
:hide-upload-btn="true" :hide-upload-btn="true"
@uploaded="onUploaded" @uploaded="onUploaded"
@failed="onFailed" @failed="onFailed"
@added="(files) => files && (file_count += files.length)" @added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)" @removed="(files) => files && (file_count -= files.length)"
/> />
</q-item-section> </q-item-section>
</q-item> </q-item>
</q-list> </q-list>
</q-card-section> </q-card-section>
<q-separator /> <q-separator />
<q-card-actions align="right"> <q-card-actions>
<q-btn <q-item-section>V: {{ server_version }}</q-item-section>
:loading="loading" <q-space />
flat <q-btn
:label="$t('Cancel')" :loading="loading"
no-caps flat
color="primary" :label="$t('Cancel')"
v-close-popup no-caps
/> color="primary"
<q-btn v-close-popup
ref="accept" />
flat <q-btn
:label="$t('Accept')" ref="accept"
:loading="loading" flat
no-caps :label="$t('Accept')"
type="submit" :loading="loading"
color="primary" no-caps
/> type="submit"
</q-card-actions> color="primary"
</q-form> />
</q-card> </q-card-actions>
</q-dialog> </q-form>
</template> </q-card>
</q-dialog>
<style scoped></style> </template>
<script lang="ts"> <style scoped></style>
import { defineComponent, ref, watch, computed } from "vue";
import { useStore } from "src/store"; <script lang="ts">
import { useQuasar } from "quasar"; import { defineComponent, ref, watch, computed } from "vue";
import { useI18n } from "vue-i18n"; import { useStore } from "src/store";
import GlobalData from "src/common/GlobalData"; import { useQuasar } from "quasar";
import { HttpProtocol } from "src/entities/HttpProtocol"; import { useI18n } from "vue-i18n";
import GlobalData from "src/common/GlobalData";
export default defineComponent({ import { HttpProtocol } from "src/entities/HttpProtocol";
name: "ComponentUpgradeDialog",
export default defineComponent({
setup() { name: "ComponentUpgradeDialog",
let $store = useStore();
let $q = useQuasar(); setup() {
let $t = useI18n(); let $store = useStore();
let $q = useQuasar();
let show_dialog = ref(false); let $t = useI18n();
let uploader_software: any = ref(null);
let uploader_rootfs: any = ref(null); let show_dialog = ref(false);
let loading = ref(false); let uploader_software: any = ref(null);
let upload_url_software = ref(""); let uploader_rootfs: any = ref(null);
let upload_url_rootfs = ref(""); let loading = ref(false);
let file_count = ref(0); let upload_url_software = ref("");
let upload_url_rootfs = ref("");
let select_options = [$t.t("software"), $t.t("rootfs")]; let file_count = ref(0);
let upgrade_type = ref($t.t("software"));
let select_options = [$t.t("software"), $t.t("rootfs")];
return { let upgrade_type = ref($t.t("software"));
show_dialog, const server_version = ref("unknow");
loading,
upload_url_software, return {
upload_url_rootfs, show_dialog,
uploader_software, loading,
uploader_rootfs, upload_url_software,
file_count, upload_url_rootfs,
upgrade_type, uploader_software,
select_options, uploader_rootfs,
generatorFileUploadHeaders(files: File[]) { file_count,
if (files.length > 0) { upgrade_type,
return [ select_options,
{ server_version,
name: HttpProtocol.kHeaderXProductName, generatorFileUploadHeaders(files: File[]) {
value: HttpProtocol.getProductName($store), if (files.length > 0) {
}, return [
{ {
name: HttpProtocol.kHeaderXFileLength, name: HttpProtocol.kHeaderXProductName,
value: files[0].size, value: HttpProtocol.getProductName($store),
}, },
]; {
} name: HttpProtocol.kHeaderXFileLength,
return []; value: files[0].size,
}, },
loga(a: any) { ];
console.log(a); }
}, return [];
showDialog() { },
show_dialog.value = true; loga(a: any) {
console.log(a);
let client = GlobalData.getInstance().getCurrentClient(); },
if (client) { showDialog() {
let url = new URL(client.url); show_dialog.value = true;
url.port =
GlobalData.getInstance().applicationConfig?.httpserver_port ?? let client = GlobalData.getInstance().getCurrentClient();
HttpProtocol.DefaultHttpPort.toString(); if (client) {
url.pathname = HttpProtocol.RequestUploadFile; let url = new URL(client.url);
url.protocol = "http:"; url.port =
url.searchParams.append("type", HttpProtocol.UploadTypeRootFS); GlobalData.getInstance().applicationConfig?.httpserver_port ??
upload_url_rootfs.value = url.toString(); HttpProtocol.DefaultHttpPort.toString();
url.pathname = HttpProtocol.RequestUploadFile;
url.searchParams.set("type", HttpProtocol.UploadTypeSoftware); url.protocol = "http:";
upload_url_software.value = url.toString(); url.searchParams.append("type", HttpProtocol.UploadTypeRootFS);
} upload_url_rootfs.value = url.toString();
},
resetData() { url.searchParams.set("type", HttpProtocol.UploadTypeSoftware);
loading.value = false; upload_url_software.value = url.toString();
upload_url_software.value = ""; try {
upload_url_rootfs.value = ""; client?.getBuildInfo()?.then((build_info) => {
file_count.value = 0; if (build_info) {
}, server_version.value = build_info.version;
async onSubmit() { }
if (file_count.value <= 0) { });
$q.notify({ // console.log(build_info);
type: "warning", } catch {}
message: $t.t("please select file first") + "!", }
position: "top", },
timeout: 1500, resetData() {
}); loading.value = false;
return; upload_url_software.value = "";
} upload_url_rootfs.value = "";
loading.value = true; file_count.value = 0;
try { },
let upgrader = async onSubmit() {
upgrade_type.value == $t.t("software") if (file_count.value <= 0) {
? uploader_software.value $q.notify({
: uploader_rootfs.value; type: "warning",
$q.dialog({ message: $t.t("please select file first") + "!",
title: $t.t("Confirm"), position: "top",
message: $t.t("use this file to upgrade") + "?", timeout: 1500,
ok: { });
label: $t.t("ok"), return;
noCaps: true, }
flat: true, loading.value = true;
}, try {
cancel: { let upgrader =
label: $t.t("cancel"), upgrade_type.value == $t.t("software")
noCaps: true, ? uploader_software.value
flat: true, : uploader_rootfs.value;
}, $q.dialog({
persistent: true, title: $t.t("Confirm"),
}) message: $t.t("use this file to upgrade") + "?",
.onOk(() => { ok: {
upgrader.upload(); label: $t.t("ok"),
}) noCaps: true,
.onCancel(() => { flat: true,
loading.value = false; },
loading.value = false; cancel: {
}); label: $t.t("cancel"),
} catch {} noCaps: true,
}, flat: true,
onUploaded() { },
loading.value = false; persistent: true,
let upgrader = })
upgrade_type.value == $t.t("software") .onOk(() => {
? uploader_software.value upgrader.upload();
: uploader_rootfs.value; })
if (upgrader) { .onCancel(() => {
console.log(upgrader); loading.value = false;
upgrader.removeUploadedFiles(); loading.value = false;
} });
$q.notify({ } catch {}
type: "positive", },
icon: "done", onUploaded() {
message: loading.value = false;
$t.t("update file upload") + let upgrader =
$t.t("success") + upgrade_type.value == $t.t("software")
"! \n" + ? uploader_software.value
upgrade_type.value + : uploader_rootfs.value;
$t.t("automatically restarts after the upgrade is complete"), if (upgrader) {
position: "top", console.log(upgrader);
timeout: 1500, upgrader.removeUploadedFiles();
}); }
setTimeout(() => { $q.notify({
window.location.reload(); type: "positive",
}, 2000); icon: "done",
}, message:
onFailed(info: any) { $t.t("update file upload") +
$q.notify({ $t.t("success") +
type: "warning", "! \n" +
message: $t.t("update file upload") + $t.t("fail") + "!", upgrade_type.value +
position: "top", $t.t("automatically restarts after the upgrade is complete"),
timeout: 1500, position: "top",
}); timeout: 1500,
loading.value = false; });
}, setTimeout(() => {
}; window.location.reload();
}, }, 2000);
}); },
</script> onFailed(info: any) {
$q.notify({
type: "warning",
message: $t.t("update file upload") + $t.t("fail") + "!",
position: "top",
timeout: 1500,
});
loading.value = false;
},
};
},
});
</script>