合并FileManager

This commit is contained in:
fangxiang 2023-02-15 16:36:51 +08:00
parent c35ff719c6
commit d16df7ada8
12 changed files with 1225 additions and 1346 deletions

View File

@ -1,3 +1,5 @@
window.media_control_client_product = "LED_PLAYER";
// window.media_control_client_product = "SPECIAL_VIDEO";
// window.media_control_client_product = "RK_3568";
window.media_control_client_custom_title = "SmartPlayer";

View File

@ -1519,6 +1519,15 @@ export default class ClientConnection {
console.error(e);
}
}
public async CheckModeIndex(mode_index:number) {
try {
return await this.doRpc<Protocol.RpcCheckModeIndexResponseEntity>(
new Protocol.RpcCheckModeIndexRequestEntity(mode_index)
);
} catch (e) {
console.error(e);
}
}
}
export interface NotifyMessage {

View File

@ -1,256 +1,226 @@
<template>
<q-dialog
persistent
v-model="show_dialog"
@before-hide="resetData"
@keydown="
(evt) => {
if (!loading && evt.keyCode == 27) {
show_dialog = false;
}
}
"
>
<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">
<div class="col-11 text-h6">
{{ $t("background image") }}
</div>
<div class="col-1">
<q-btn
:loading="loading"
flat
round
icon="close"
:disable="loading"
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-uploader
class="full-width"
ref="uploader"
:url="upload_url"
method="post"
:headers="generatorFileUploadHeaders"
:label="$t('select background image') + ':'"
:accept="$store.state.isSpecialVideo() ? '.svdoj' : 'image/*'"
:hide-upload-btn="true"
@uploaded="onUploaded"
@failed="onFailed"
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/>
</q-item-section>
</q-item>
</q-list>
</q-card-section>
<q-separator />
<q-card-actions align="left">
<q-btn
v-if="$store.state.isLedPlayer()"
flat
no-caps
:loading="loading"
color="primary"
@click="showBackgroundImage"
:label="$t('view current background image')"
/>
<q-space />
<q-btn
:loading="loading"
flat
:label="$t('Cancel')"
no-caps
color="primary"
v-close-popup
/>
<q-btn
ref="accept"
flat
:label="$t('Accept')"
no-caps
: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";
import { api as viewerApi } from "v-viewer";
export default defineComponent({
name: "ComponentBackgroundImageDialog",
setup() {
let $store = useStore();
let $q = useQuasar();
let $t = useI18n();
let show_dialog = ref(false);
let uploader: any = ref(null);
let loading = ref(false);
let upload_url = ref("");
let file_count = ref(0);
return {
show_dialog,
loading,
upload_url,
uploader,
file_count,
loga(a: any) {
console.log(a);
},
generatorFileUploadHeaders(files: File[]) {
if (files.length > 0) {
return [
{
name: HttpProtocol.kHeaderXProductName,
value: HttpProtocol.getProductName($store),
},
{
name: HttpProtocol.kHeaderXFileLength,
value: files[0].size,
},
];
}
return [];
},
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.UploadTypeBackgroundImage
);
upload_url.value = url.toString();
}
},
resetData() {
loading.value = false;
upload_url.value = "";
file_count.value = 0;
},
showBackgroundImage() {
const temp_port =
GlobalData.getInstance().applicationConfig?.httpserver_port ??
HttpProtocol.DefaultHttpPort.toString();
try {
const url = new URL(
GlobalData.getInstance().getCurrentClient()?.url ??
"http://127.0.0.1:" + temp_port
);
url.protocol = "http";
url.port = temp_port.toString();
url.pathname = "/static/background_image.png";
viewerApi({
options: {
toolbar: true,
url: "data-source",
initialViewIndex: 0,
},
images: [
{
src: url.toString(),
"data-source": url.toString(),
},
],
});
} catch {}
},
async onSubmit() {
if (file_count.value <= 0) {
$q.notify({
type: "warning",
message: $t.t("please select file first") + "!",
position: "top",
timeout: 1500,
});
return;
}
loading.value = true;
try {
$q.dialog({
title: $t.t("Confirm"),
message: $t.t("use this image to background image") + "?",
ok: {
label: $t.t("ok"),
noCaps: true,
flat: true,
},
cancel: {
label: $t.t("cancel"),
noCaps: true,
flat: true,
},
persistent: true,
})
.onOk(() => {
uploader.value.upload();
})
.onCancel(() => {
loading.value = false;
});
} catch {}
},
onUploaded() {
$q.notify({
type: "positive",
message: $t.t("upload background image") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
loading.value = false;
show_dialog.value = false;
},
onFailed(info: any) {
console.log(info);
$q.notify({
type: "warning",
message: $t.t("upload background image") + $t.t("fail") + "!",
position: "top",
timeout: 1500,
});
loading.value = false;
},
};
},
});
</script>
<template>
<q-dialog
persistent
v-model="show_dialog"
@before-hide="resetData"
@keydown="
(evt) => {
if (!loading && evt.keyCode == 27) {
show_dialog = false;
}
}
"
>
<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">
<div class="col-11 text-h6">
{{ $t("background image") }}
</div>
<div class="col-1">
<q-btn
:loading="loading"
flat
round
icon="close"
:disable="loading"
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-uploader
class="full-width"
ref="uploader"
:url="upload_url"
method="post"
:label="$t('select background image') + ':'"
:accept="$store.state.isSpecialVideo() ? '.svdoj' : 'image/*'"
:hide-upload-btn="true"
@uploaded="onUploaded"
@failed="onFailed"
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/>
<!-- :headers="generatorFileUploadHeaders" -->
</q-item-section>
</q-item>
</q-list>
</q-card-section>
<q-separator />
<q-card-actions align="left">
<q-btn
v-if="$store.state.isLedPlayer()"
flat
no-caps
:loading="loading"
color="primary"
@click="showBackgroundImage()"
:label="$t('view current background image')"
/>
<q-space />
<q-btn
:loading="loading"
flat
:label="$t('Cancel')"
no-caps
color="primary"
v-close-popup
/>
<q-btn
ref="accept"
flat
:label="$t('Accept')"
no-caps
: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";
import { api as viewerApi } from "v-viewer";
export default defineComponent({
name: "ComponentBackgroundImageDialog",
setup() {
let $store = useStore();
let $q = useQuasar();
let $t = useI18n();
let show_dialog = ref(false);
let uploader: any = ref(null);
let loading = ref(false);
let upload_url = ref("");
let file_count = ref(0);
return {
show_dialog,
loading,
upload_url,
uploader,
file_count,
loga(a: any) {
console.log(a);
},
showDialog() {
show_dialog.value = true;
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (url) {
url.pathname = "/upload_background_image_file";
upload_url.value = url.toString();
}
},
resetData() {
loading.value = false;
upload_url.value = "";
file_count.value = 0;
},
showBackgroundImage() {
try {
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (url) {
url.pathname = "/get_background_image_file";
viewerApi({
options: {
toolbar: true,
url: "data-source",
initialViewIndex: 0,
},
images: [
{
src: url.toString(),
"data-source": url.toString(),
},
],
});
}
} catch {}
},
async onSubmit() {
if (file_count.value <= 0) {
$q.notify({
type: "warning",
message: $t.t("please select file first") + "!",
position: "top",
timeout: 1500,
});
return;
}
loading.value = true;
try {
$q.dialog({
title: $t.t("Confirm"),
message: $t.t("use this image to background image") + "?",
ok: {
label: $t.t("ok"),
noCaps: true,
flat: true,
},
cancel: {
label: $t.t("cancel"),
noCaps: true,
flat: true,
},
persistent: true,
})
.onOk(() => {
uploader.value.upload();
})
.onCancel(() => {
loading.value = false;
});
} catch {}
},
onUploaded() {
$q.notify({
type: "positive",
message: $t.t("upload background image") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
loading.value = false;
show_dialog.value = false;
},
onFailed(info: any) {
console.log(info);
$q.notify({
type: "warning",
message: $t.t("upload background image") + $t.t("fail") + "!",
position: "top",
timeout: 1500,
});
loading.value = false;
},
};
},
});
</script>

View File

@ -346,14 +346,12 @@
style="height: 69vh; width: 70%"
:disable="uploader_loading"
:url="getUrl"
method="post"
:headers="generatorFileUploadHeaders"
multiple
method="POST"
:label="$t('select file') + ':'"
:accept="uploader_accept"
@start="onStartUpload"
@uploaded="onUploaded"
@failed="onFailed"
@added="/*onFileAdded*/ null"
@finish="onFailed"
>
</q-uploader>
<q-space />
@ -687,7 +685,6 @@ export default defineComponent({
loading.value = false;
};
const refresh_file_list_async = async () => {
const response = await _request_list_files(path.value);
_show_files(response);
@ -882,21 +879,6 @@ export default defineComponent({
resolve = _resolve;
});
},
generatorFileUploadHeaders(files: File[]) {
if (files.length > 0) {
return [
{
name: HttpProtocol.kHeaderXProductName,
value: HttpProtocol.getProductName($store),
},
{
name: HttpProtocol.kHeaderXFileLength,
value: files[0].size,
},
];
}
return [];
},
resetData() {
loading.value = false;
uploading.value = false;
@ -912,67 +894,135 @@ export default defineComponent({
resolve_value = null;
},
async onCreateNewFolder() {
$q.dialog({
title: $t.t("create folder"),
message: $t.t("input folder name") + ":",
prompt: {
model: "",
isValid: (val: string) => !!val && val.trim().length > 0,
type: "text",
},
ok: {
label: $t.t("ok"),
noCaps: true,
flat: true,
},
cancel: {
label: $t.t("cancel"),
noCaps: true,
flat: true,
},
persistent: true,
}).onOk(async (data: string) => {
const response = await GlobalData.getInstance()
.getCurrentClient()
?.CreateDirectoryFileManager(path.value, data);
if (response && response.success) {
refresh_file_list();
$q.notify({
type: "positive",
message: $t.t("create folder") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
} else {
$q.notify({
type: "warning",
message:
$t.t("create folder") +
$t.t("fail") +
"!" +
(response ? response.error_message : ""),
position: "top",
timeout: 1500,
});
}
});
},
selectFile,
async deleteFile(file: FileEntity) {
let response = null;
try {
response = await GlobalData.getInstance()
.getCurrentClient()
?.DeleteFileManager(path.value, file.name);
} catch (e) {
console.log(e);
}
$q.dialog({
title: $t.t("create folder"),
message: $t.t("input folder name") + ":",
prompt: {
model: "",
isValid: (val: string) =>
!!val && val.trim().length > 0&& val.indexOf(".") != 0 ,
type: "text",
},
ok: {
label: $t.t("ok"),
noCaps: true,
flat: true,
},
cancel: {
label: $t.t("cancel"),
noCaps: true,
flat: true,
},
persistent: true,
}).onOk(async (data: string) => {
const response = await GlobalData.getInstance()
.getCurrentClient()
?.CreateDirectoryFileManager(path.value, data);
console.log(response);
if (response && response.success) {
refresh_file_list();
$q.notify({
type: "positive",
message: $t.t("delete file") + $t.t("success") + "!",
message: $t.t("create folder") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
} else {
// if (
// response?.error_message ==
// "the folder name cannot start with a '.'"
// ) {
// $q.notify({
// type: "warning",
// message:
// $t.t("create folder") +
// $t.t("fail") +
// "!" +
// $t.t("the folder name cannot start with a '.'"),
// position: "top",
// timeout: 1500,
// });
// }
// else {
if (response) {
$q.notify({
type: "warning",
message:
$t.t("create folder") +
$t.t("fail") +
"! " +
$t.t(response.error_message),
position: "top",
timeout: 1500,
});
}
}
});
},
selectFile,
async deleteFile(file: FileEntity) {
let response = null;
try {
response = await GlobalData.getInstance()
.getCurrentClient()
?.DeleteFileManager(path.value, file.name);
} catch (e) {
console.log(e);
}
if (response && response.success) {
refresh_file_list();
$q.notify({
type: "positive",
message: $t.t("delete file") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
} else {
$q.notify({
type: "warning",
message:
$t.t("delete file") +
$t.t("fail") +
"!" +
(response ? response.error_message : ""),
position: "top",
timeout: 1500,
});
}
},
renameFile(file: FileEntity) {
$q.dialog({
title: $t.t("rename"),
message: $t.t("input new file name") + ":",
prompt: {
model: file.name,
isValid: (val: string) => !!val && val.trim().length > 0,
type: "text",
},
ok: {
label: $t.t("ok"),
noCaps: true,
flat: true,
},
cancel: {
label: $t.t("cancel"),
noCaps: true,
flat: true,
},
persistent: true,
}).onOk(async (data: string) => {
if (data == file.name) {
return;
}
let response = await GlobalData.getInstance()
.getCurrentClient()
?.RenameFileManager(path.value, file.name, data);
if (response && response.success) {
refresh_file_list();
$q.notify({
type: "positive",
message: $t.t("file rename") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
@ -980,7 +1030,7 @@ export default defineComponent({
$q.notify({
type: "warning",
message:
$t.t("delete file") +
$t.t("file rename") +
$t.t("fail") +
"!" +
(response ? response.error_message : ""),
@ -988,55 +1038,7 @@ export default defineComponent({
timeout: 1500,
});
}
},
renameFile(file: FileEntity) {
$q.dialog({
title: $t.t("rename"),
message: $t.t("input new file name") + ":",
prompt: {
model: file.name,
isValid: (val: string) => !!val && val.trim().length > 0,
type: "text",
},
ok: {
label: $t.t("ok"),
noCaps: true,
flat: true,
},
cancel: {
label: $t.t("cancel"),
noCaps: true,
flat: true,
},
persistent: true,
}).onOk(async (data: string) => {
if (data == file.name) {
return;
}
let response = await GlobalData.getInstance()
.getCurrentClient()
?.RenameFileManager(path.value, file.name, data);
if (response && response.success) {
refresh_file_list();
$q.notify({
type: "positive",
message: $t.t("file rename") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
} else {
$q.notify({
type: "warning",
message:
$t.t("file rename") +
$t.t("fail") +
"!" +
(response ? response.error_message : ""),
position: "top",
timeout: 1500,
});
}
});
});
},
copyStringToClipboard(value: string) {
copyToClipboard(value);
@ -1068,8 +1070,8 @@ export default defineComponent({
getUrl(file: File[]) {
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (url) {
url.pathname = HttpProtocol.RequestUploadFile;
url.searchParams.append("type", HttpProtocol.HttpUploadTypeNormal);
url.pathname = "/upload_media_file"; //HttpProtocol.RequestUploadFile;
// url.searchParams.append("type", HttpProtocol.HttpUploadTypeNormal);
url.searchParams.append("base_dir", path.value);
return url.toString();
}
@ -1078,99 +1080,20 @@ export default defineComponent({
onStartUpload() {
loading.value = true;
},
async onFileAdded(files: File[] | File) {
setTimeout(async () => {
const onError = async (file: File | null) => {
await nextTick(() => {});
uploader.value.reset();
async onFailed(info: any) {
let file_list: any = await _request_list_files(path.value);
setTimeout(() => {
if (files.value.length != file_list.files.length) {
$q.notify({
color: "negative",
icon: "warning",
message: $t.t("load file error") + "!",
type: "positive",
message: $t.t("file upload") + $t.t("finish") + "!",
position: "top",
timeout: 3000,
timeout: 1500,
});
};
let file: File | null = null;
try {
if (Array.isArray(files)) {
if (files.length > 0) {
file = files[0];
}
} else {
file = files;
}
if (file) {
const file_name = file.name;
const blob = file.slice(0, 1024 * 1024 * 1); // 1 MB
uploader_loading.value = true;
try {
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (url) {
url.pathname = HttpProtocol.RequestPathCheckFileSupport;
// if (FileSuffixHelper.isVideoPath(file_name)) {
// }
const data = new FormData();
data.append(
"file",
new File([blob], file_name, {
lastModified: file.lastModified,
})
);
const response = await api.post(url.toString(), data, {
headers: {
"Content-Type": "multipart/form-data",
},
});
if (response && response.data && response.data.is_support) {
} else {
onError(file);
}
} else {
throw "";
}
} catch (e) {
console.error(e);
onError(file);
}
uploader_loading.value = false;
return;
}
} catch (e) {
console.error(e);
onError(file);
loading.value = false;
uploading.value = false;
}
}, 1);
},
onUploaded() {
uploading.value = false;
uploader.value.reset();
refresh_file_list();
$q.notify({
type: "positive",
message: $t.t("file upload") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
loading.value = false;
},
onFailed(info: any) {
console.log(info);
$q.notify({
type: "warning",
message: $t.t("file upload") + $t.t("fail") + "!",
position: "top",
timeout: 1500,
});
loading.value = false;
loading.value = false;
}, 500);
},
copyFile(file: FileEntity) {
if (file) {

File diff suppressed because it is too large Load Diff

View File

@ -1,247 +1,225 @@
<template>
<q-dialog
persistent
v-model="show_dialog"
@before-hide="resetData"
@keydown="
(evt) => {
if (!loading && evt.keyCode == 27) {
show_dialog = false;
}
}
"
>
<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">
<div class="col-auto text-h6">
{{ $t("database import") }}
</div>
<q-space />
<div>
<q-btn
:loading="loading"
flat
round
icon="close"
:disable="loading"
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-uploader
class="full-width"
ref="uploader"
:url="upload_url"
method="post"
:headers="generatorFileUploadHeaders"
:label="$t('select data(DBP) file') + ':'"
accept=".dbp"
:hide-upload-btn="true"
@uploaded="onUploaded"
@failed="onFailed"
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/>
</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')"
no-caps
color="primary"
v-close-popup
/>
<q-btn
ref="accept"
flat
:label="$t('Accept')"
no-caps
: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";
import { api as viewerApi } from "v-viewer";
export default defineComponent({
name: "ComponentRecoveryDatabaseDialog",
setup() {
let $store = useStore();
let $q = useQuasar();
let $t = useI18n();
let show_dialog = ref(false);
let uploader: any = ref(null);
let loading = ref(false);
let upload_url = ref("");
let file_count = ref(0);
return {
show_dialog,
loading,
upload_url,
uploader,
file_count,
generatorFileUploadHeaders(files: File[]) {
if (files.length > 0) {
return [
{
name: HttpProtocol.kHeaderXProductName,
value: HttpProtocol.getProductName($store),
},
{
name: HttpProtocol.kHeaderXFileLength,
value: files[0].size,
},
];
}
return [];
},
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.UploadTypeDatabase);
upload_url.value = url.toString();
}
},
resetData() {
loading.value = false;
upload_url.value = "";
file_count.value = 0;
},
async onSubmit() {
if (file_count.value <= 0) {
$q.notify({
type: "warning",
message: $t.t("please select file first") + "!",
position: "top",
timeout: 1500,
});
return;
}
loading.value = true;
try {
$q.dialog({
title: $t.t("Confirm"),
message: $t.t("use this file to recovery data") + "?",
ok: {
label: $t.t("ok"),
noCaps: true,
flat: true,
},
cancel: {
label: $t.t("cancel"),
noCaps: true,
flat: true,
},
persistent: true,
})
.onOk(() => {
uploader.value.upload();
})
.onCancel(() => {
loading.value = false;
});
} catch {}
},
onUploaded() {
$q.notify({
type: "positive",
message: $t.t("data import") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
$q.dialog({
title: $t.t("Confirm"),
message:
$t.t("data changes will take effect after the restart") +
"!" +
"<p class='text-red'>" +
$t.t("reboot now") +
"?" +
"</p>",
html: true,
ok: {
label: $t.t("ok"),
noCaps: true,
flat: true,
},
cancel: {
label: $t.t("cancel"),
noCaps: true,
flat: true,
},
persistent: true,
})
.onOk(() => {
GlobalData.getInstance().getCurrentClient()?.restartDevice();
$q.notify({
type: "positive",
message: $t.t("reboot device command sended") + "!",
position: "top",
timeout: 1500,
});
})
.onDismiss(() => {
loading.value = false;
show_dialog.value = false;
});
},
onFailed(info: any) {
console.log(info);
$q.notify({
type: "warning",
message: $t.t("data import") + $t.t("fail") + "!",
position: "top",
timeout: 1500,
});
loading.value = false;
},
};
},
});
</script>
<template>
<q-dialog
persistent
v-model="show_dialog"
@before-hide="resetData"
@keydown="
(evt) => {
if (!loading && evt.keyCode == 27) {
show_dialog = false;
}
}
"
>
<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">
<div class="col-auto text-h6">
{{ $t("database import") }}
</div>
<q-space />
<div>
<q-btn
:loading="loading"
flat
round
icon="close"
:disable="loading"
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-uploader
class="full-width"
ref="uploader"
:url="upload_url"
method="POST"
:label="$t('select data(DBP) file') + ':'"
accept=".dbp"
:hide-upload-btn="true"
@uploaded="onUploaded"
@failed="onFailed"
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/>
</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')"
no-caps
color="primary"
v-close-popup
/>
<q-btn
ref="accept"
flat
:label="$t('Accept')"
no-caps
: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";
import { api as viewerApi } from "v-viewer";
export default defineComponent({
name: "ComponentRecoveryDatabaseDialog",
setup() {
let $store = useStore();
let $q = useQuasar();
let $t = useI18n();
let show_dialog = ref(false);
let uploader: any = ref(null);
let loading = ref(false);
let upload_url = ref("");
let file_count = ref(0);
return {
show_dialog,
loading,
upload_url,
uploader,
file_count,
showDialog() {
show_dialog.value = true;
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (url) {
url.pathname = "/upload_db_file";
upload_url.value = url.toString();
}
},
resetData() {
loading.value = false;
upload_url.value = "";
file_count.value = 0;
},
async onSubmit() {
if (file_count.value <= 0) {
$q.notify({
type: "warning",
message: $t.t("please select file first") + "!",
position: "top",
timeout: 1500,
});
return;
}
loading.value = true;
try {
$q.dialog({
title: $t.t("Confirm"),
message: $t.t("use this file to recovery data") + "?",
ok: {
label: $t.t("ok"),
noCaps: true,
flat: true,
},
cancel: {
label: $t.t("cancel"),
noCaps: true,
flat: true,
},
persistent: true,
})
.onOk(() => {
uploader.value.upload();
})
.onCancel(() => {
loading.value = false;
});
} catch {}
},
onUploaded() {
$q.notify({
type: "positive",
message: $t.t("data import") + $t.t("success") + "!",
position: "top",
timeout: 1500,
});
$q.dialog({
title: $t.t("Confirm"),
message:
$t.t("data changes will take effect after the restart") +
"!" +
"<p class='text-red'>" +
$t.t("reboot now") +
"?" +
"</p>",
html: true,
ok: {
label: $t.t("ok"),
noCaps: true,
flat: true,
},
cancel: {
label: $t.t("cancel"),
noCaps: true,
flat: true,
},
persistent: true,
})
.onOk(() => {
GlobalData.getInstance().getCurrentClient()?.restartDevice();
$q.notify({
type: "positive",
message: $t.t("reboot device command sended") + "!",
position: "top",
timeout: 1500,
});
})
.onDismiss(() => {
loading.value = false;
show_dialog.value = false;
});
},
onFailed(info: any) {
console.log(info);
$q.notify({
type: "warning",
message: $t.t("data import") + $t.t("fail") + "!",
position: "top",
timeout: 1500,
});
loading.value = false;
},
};
},
});
</script>

View File

@ -61,7 +61,6 @@
ref="uploader_software"
:url="upload_url_software"
method="post"
:headers="generatorFileUploadHeaders"
:label="$t('select software upgrade file') + ':'"
accept=".zip,.tar,.tar.gz"
:hide-upload-btn="true"
@ -76,7 +75,6 @@
ref="uploader_rootfs"
:url="upload_url_rootfs"
method="post"
:headers="generatorFileUploadHeaders"
:label="$t('select rootfs upgrade file') + ':'"
accept=".img"
:hide-upload-btn="true"
@ -85,6 +83,7 @@
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/>
<!-- :headers="generatorFileUploadHeaders" -->
</q-item-section>
</q-item>
</q-list>
@ -92,9 +91,7 @@
<q-separator />
<q-card-actions>
<q-item-section>V: {{ server_version }}</q-item-section>
<q-space />
<q-card-actions align="right">
<q-btn
:loading="loading"
flat
@ -146,7 +143,6 @@ export default defineComponent({
let select_options = [$t.t("software"), $t.t("rootfs")];
let upgrade_type = ref($t.t("software"));
const server_version = ref("unknow");
return {
show_dialog,
@ -158,49 +154,18 @@ export default defineComponent({
file_count,