2021-08-16 14:22:43 +08:00
|
|
|
<template>
|
|
|
|
<q-dialog persistent v-model="show_dialog" @before-hide="resetData">
|
|
|
|
<q-card class="overflow-hidden" style="overflow-y: scroll; max-width: 35vw">
|
|
|
|
<q-form @submit="onSubmit">
|
|
|
|
<q-card-section class="q-ma-none q-pa-sm">
|
|
|
|
<div class="row">
|
2021-08-17 17:17:51 +08:00
|
|
|
<div class="col-auto text-h6">
|
2021-12-20 17:39:51 +08:00
|
|
|
{{ upgrade_type }}{{ $t("upgrade") }}
|
2021-08-16 14:22:43 +08:00
|
|
|
</div>
|
2021-08-17 17:17:51 +08:00
|
|
|
<q-space />
|
|
|
|
<div>
|
2021-08-16 14:22:43 +08:00
|
|
|
<q-btn
|
|
|
|
:loading="loading"
|
|
|
|
flat
|
|
|
|
round
|
|
|
|
icon="close"
|
|
|
|
color="red"
|
|
|
|
v-close-popup
|
|
|
|
>
|
|
|
|
<q-tooltip>
|
|
|
|
{{ $t("close") }}
|
|
|
|
</q-tooltip>
|
|
|
|
</q-btn>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</q-card-section>
|
|
|
|
|
|
|
|
<q-separator />
|
|
|
|
|
|
|
|
<q-card-section style="max-height: 50vh; width: 35vw" class="scroll">
|
|
|
|
<q-list>
|
|
|
|
<q-item>
|
|
|
|
<q-item-section>
|
|
|
|
<q-select
|
|
|
|
:label="$t('upgrade type')"
|
|
|
|
:hint="$t('please input') + $t('upgrade type') + ':'"
|
|
|
|
:options="select_options"
|
|
|
|
v-model="upgrade_type"
|
2021-08-16 16:20:35 +08:00
|
|
|
@update:model-value="file_count = 0"
|
2021-08-16 14:22:43 +08:00
|
|
|
>
|
|
|
|
</q-select>
|
|
|
|
</q-item-section>
|
|
|
|
</q-item>
|
|
|
|
<q-item>
|
|
|
|
<q-item-section>
|
|
|
|
<q-uploader
|
2021-12-20 17:39:51 +08:00
|
|
|
v-show="upgrade_type == $t('software')"
|
2021-08-16 14:22:43 +08:00
|
|
|
class="full-width"
|
|
|
|
ref="uploader_software"
|
|
|
|
:url="upload_url_software"
|
|
|
|
method="post"
|
|
|
|
:headers="generatorFileUploadHeaders"
|
|
|
|
:label="$t('select software upgrade file') + ':'"
|
|
|
|
accept=".zip"
|
|
|
|
:hide-upload-btn="true"
|
|
|
|
@uploaded="onUploaded"
|
|
|
|
@failed="onFailed"
|
2021-08-16 16:20:35 +08:00
|
|
|
@added="(files) => files && (file_count += files.length)"
|
|
|
|
@removed="(files) => files && (file_count -= files.length)"
|
2021-08-16 14:22:43 +08:00
|
|
|
/>
|
|
|
|
<q-uploader
|
2021-12-20 17:39:51 +08:00
|
|
|
v-show="upgrade_type == $t('rootfs')"
|
2021-08-16 14:22:43 +08:00
|
|
|
class="full-width"
|
|
|
|
ref="uploader_rootfs"
|
|
|
|
:url="upload_url_rootfs"
|
|
|
|
method="post"
|
|
|
|
:headers="generatorFileUploadHeaders"
|
|
|
|
:label="$t('select rootfs upgrade file') + ':'"
|
|
|
|
accept=".img"
|
|
|
|
:hide-upload-btn="true"
|
|
|
|
@uploaded="onUploaded"
|
|
|
|
@failed="onFailed"
|
2021-08-16 16:20:35 +08:00
|
|
|
@added="(files) => files && (file_count += files.length)"
|
|
|
|
@removed="(files) => files && (file_count -= files.length)"
|
2021-08-16 14:22:43 +08:00
|
|
|
/>
|
|
|
|
</q-item-section>
|
|
|
|
</q-item>
|
|
|
|
</q-list>
|
|
|
|
</q-card-section>
|
|
|
|
|
|
|
|
<q-separator />
|
|
|
|
|
|
|
|
<q-card-actions align="right">
|
|
|
|
<q-btn
|
|
|
|
:loading="loading"
|
|
|
|
flat
|
|
|
|
:label="$t('Cancel')"
|
|
|
|
color="primary"
|
|
|
|
v-close-popup
|
|
|
|
/>
|
|
|
|
<q-btn
|
|
|
|
ref="accept"
|
|
|
|
flat
|
|
|
|
:label="$t('Accept')"
|
|
|
|
:loading="loading"
|
|
|
|
type="submit"
|
|
|
|
color="primary"
|
|
|
|
/>
|
|
|
|
</q-card-actions>
|
|
|
|
</q-form>
|
|
|
|
</q-card>
|
|
|
|
</q-dialog>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped></style>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent, ref, watch, computed } from "vue";
|
|
|
|
import { useStore } from "src/store";
|
|
|
|
import { useQuasar } from "quasar";
|
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
import GlobalData from "src/common/GlobalData";
|
|
|
|
import { HttpProtocol } from "src/entities/HttpProtocol";
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: "ComponentUpgradeDialog",
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
let $store = useStore();
|
|
|
|
let $q = useQuasar();
|
|
|
|
let $t = useI18n();
|
|
|
|
|
|
|
|
let show_dialog = ref(false);
|
|
|
|
let uploader_software: any = ref(null);
|
|
|
|
let uploader_rootfs: any = ref(null);
|
|
|
|
let loading = ref(false);
|
|
|
|
let upload_url_software = ref("");
|
|
|
|
let upload_url_rootfs = ref("");
|
2021-08-16 16:20:35 +08:00
|
|
|
let file_count = ref(0);
|
2021-08-16 14:22:43 +08:00
|
|
|
|
2021-12-20 17:39:51 +08:00
|
|
|
let select_options = [$t.t("software"), $t.t("rootfs")];
|
|
|
|
let upgrade_type = ref($t.t("software"));
|
2021-08-16 14:22:43 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
show_dialog,
|
|
|
|
loading,
|
|
|
|
upload_url_software,
|
|
|
|
upload_url_rootfs,
|
|
|
|
uploader_software,
|
|
|
|
uploader_rootfs,
|
2021-08-16 16:20:35 +08:00
|
|
|
file_count,
|
2021-08-16 14:22:43 +08:00
|
|
|
upgrade_type,
|
|
|
|
select_options,
|
|
|
|
generatorFileUploadHeaders(files: File[]) {
|
|
|
|
if (files.length > 0) {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
name: HttpProtocol.kHeaderXProductName,
|
|
|
|
value: HttpProtocol.kHeaderDefaultValueXProductName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: HttpProtocol.kHeaderXFileLength,
|
|
|
|
value: files[0].size,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
},
|
2021-08-16 16:20:35 +08:00
|
|
|
loga(a: any) {
|
|
|
|
console.log(a);
|
|
|
|
},
|
2021-08-16 14:22:43 +08:00
|
|
|
showDialog() {
|
|
|
|
show_dialog.value = true;
|
|
|
|
|
|
|
|
let client = GlobalData.getInstance().getCurrentClient();
|
|
|
|
if (client) {
|
|
|
|
let url = new URL(client.url);
|
|
|
|
url.port =
|
|
|
|
GlobalData.getInstance().applicationConfig?.httpserver_port ??
|
|
|
|
HttpProtocol.DefaultHttpPort.toString();
|
|
|
|
url.pathname = HttpProtocol.RequestUploadFile;
|
|
|
|
url.protocol = "http:";
|
|
|
|
url.searchParams.append("type", HttpProtocol.UploadTypeRootFS);
|
|
|
|
upload_url_rootfs.value = url.toString();
|
|
|
|
|
|
|
|
url.searchParams.set("type", HttpProtocol.UploadTypeSoftware);
|
|
|
|
upload_url_software.value = url.toString();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resetData() {
|
|
|
|
loading.value = false;
|
|
|
|
upload_url_software.value = "";
|
|
|
|
upload_url_rootfs.value = "";
|
2021-08-16 16:20:35 +08:00
|
|
|
file_count.value = 0;
|
2021-08-16 14:22:43 +08:00
|
|
|
},
|
2021-12-20 17:39:51 +08:00
|
|
|
async onSubmit() {
|
2021-08-16 16:20:35 +08:00
|
|
|
if (file_count.value <= 0) {
|
|
|
|
$q.notify({
|
|
|
|
type: "warning",
|
|
|
|
message: $t.t("please select file first") + "!",
|
|
|
|
position: "top",
|
|
|
|
timeout: 1500,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-08-16 14:22:43 +08:00
|
|
|
loading.value = true;
|
|
|
|
try {
|
2021-08-16 16:20:35 +08:00
|
|
|
let upgrader =
|
2021-12-20 17:39:51 +08:00
|
|
|
upgrade_type.value == $t.t("software")
|
2021-08-16 16:20:35 +08:00
|
|
|
? uploader_software.value
|
|
|
|
: uploader_rootfs.value;
|
2021-08-16 14:22:43 +08:00
|
|
|
$q.dialog({
|
|
|
|
title: "Confirm",
|
|
|
|
message: $t.t("use this file to upgrade") + "?",
|
|
|
|
cancel: true,
|
|
|
|
persistent: true,
|
|
|
|
})
|
|
|
|
.onOk(() => {
|
2021-08-16 16:20:35 +08:00
|
|
|
upgrader.upload();
|
2021-08-16 14:22:43 +08:00
|
|
|
})
|
|
|
|
.onCancel(() => {
|
|
|
|
loading.value = false;
|
2021-12-20 17:39:51 +08:00
|
|
|
loading.value = false;
|
2021-08-16 14:22:43 +08:00
|
|
|
});
|
|
|
|
} catch {}
|
|
|
|
},
|
2021-12-20 17:39:51 +08:00
|
|
|
onUploaded() {},
|
2021-08-16 14:22:43 +08:00
|
|
|
onFailed(info: any) {
|
|
|
|
console.log(info);
|
|
|
|
$q.notify({
|
|
|
|
type: "warning",
|
2021-12-20 17:39:51 +08:00
|
|
|
message: $t.t("update file upload") + $t.t("fail") + "!",
|
2021-08-16 14:22:43 +08:00
|
|
|
position: "top",
|
|
|
|
timeout: 1000,
|
|
|
|
});
|
|
|
|
loading.value = false;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|