From 470724fb572b10045ae1792ddec6c61d1d33bdbd Mon Sep 17 00:00:00 2001 From: fangxiang Date: Fri, 20 Aug 2021 16:46:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BF=A1=E5=8F=B7=E6=BA=90?= =?UTF-8?q?=E6=97=B6=E5=8F=AF=E4=BB=A5=E9=80=89=E6=8B=A9=E8=BF=9C=E7=A8=8B?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/boot/axios.ts | 5 +- src/components/FileManageDialog.vue | 216 +++++++++++++++++++++----- src/components/SignalSourceDialog.vue | 41 ++++- src/i18n/zh-CN/index.ts | 5 +- 4 files changed, 224 insertions(+), 43 deletions(-) diff --git a/src/boot/axios.ts b/src/boot/axios.ts index b350ffe..4c08488 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -13,7 +13,10 @@ declare module "@vue/runtime-core" { // good idea to move this instance creation inside of the // "export default () => {}" function below (which runs individually // for each client) -const api = axios.create({ baseURL: "https://api.example.com" }); +const api = axios.create({ + baseURL: "https://" + window.location.hostname, + timeout: 10000, +}); api.defaults.headers.common["X-Product-Name"] = "RK_3568"; export default boot(({ app }) => { diff --git a/src/components/FileManageDialog.vue b/src/components/FileManageDialog.vue index 7003a27..e72a5a3 100644 --- a/src/components/FileManageDialog.vue +++ b/src/components/FileManageDialog.vue @@ -32,16 +32,17 @@
@@ -50,10 +51,34 @@
+ + + + + + + {{ item.label }} + + + @@ -64,9 +89,7 @@ @@ -78,7 +101,7 @@ flat icon="refresh" @click="refresh_file_list" - :disable="status == 'uploading'" + :disable="uploading" :label="$t('refresh')" > @@ -89,7 +112,7 @@ flat icon="create_new_folder" @click="onCreateNewFolder" - :disable="loading" + :disable="loading || uploading" :label="$t('create folder')" > @@ -98,10 +121,10 @@ {{ $t("upload file") }} @@ -110,9 +133,9 @@ {{ $t("cancel upload file") }} @@ -127,7 +150,7 @@ > {{ - props.value.length > 23 - ? props.value.substr(0, 23) + "..." + props.value.length > 60 + ? props.value.substr(0, 60) + "..." : props.value }} {{ props.value }} @@ -160,30 +183,46 @@ {{ props.value }}
-
- - {{ $t("rename") }} - {{ $t("click") }}{{ $t("rename") }} - -      - - {{ $t("delete") }} - {{ $t("click") }}{{ $t("delete") }} +
+ +
+
+ + {{ $t("select file") }} + + {{ $t("click") }}{{ $t("select file") }} +
-
+
@@ -202,12 +241,12 @@ @click="(evt) => copyStringToClipboard(current_file.name)" > - {{ $t("copy file name") }} + {{ $t("copy name") }} @@ -216,7 +255,7 @@ {{ $t("delete") }} + + + {{ $t("select file") }} +
@@ -296,15 +344,34 @@ export default defineComponent({ let show_dialog = ref(false); let loading = ref(false); + let uploading = ref(false); let files = ref([]); let show_context_menu = ref(false); let target_dom: any = ref(document.body.children[0]); let current_file = ref(new FileEntity()); - let path = ref(""); + let default_path_label = ref($t.t("local disk")); + let default_path = ref("media"); + let path = ref(default_path.value); let prev_path = ref(""); let paths = ref([new _BreadcrumbItem("root", "")]); let status = ref("normal"); let upload_url = ref(""); + let uploader: any = ref(null); + let resolve: any = null; + let resolve_value: any = null; + + const disk_options = ref([ + { + label: $t.t("local disk"), + value: "media", + }, + ]); + for (let i = 1; i < 8; ++i) { + disk_options.value.push({ + label: $t.t("usb") + i.toString(), + value: "/usb" + i.toString(), + }); + } const columns = [ { @@ -409,42 +476,107 @@ export default defineComponent({ refresh_file_list_async(); }; + const selectFile = async (file: FileEntity) => { + resolve_value = { + file, + path: path.value, + }; + show_dialog.value = false; + }; + watch( () => path.value, - (newValue: string) => { + (newValue: string, oldValue: string) => { + if (!newValue) { + path.value = oldValue ?? default_path.value; + return; + } paths.value = []; - let parent_item = new _BreadcrumbItem("root", ""); + let parent_item = null; for (let item of newValue.split("/")) { - let temp = new _BreadcrumbItem(item, parent_item.path + "/" + item); + if (item.trim() == "") { + continue; + } + + let temp: _BreadcrumbItem = new _BreadcrumbItem( + item, + (parent_item + ? parent_item.path + "/" + : newValue.length > 0 + ? newValue[0] == "/" || "\\" + ? "/" + : "" + : "") + item + ); + paths.value.push(temp); parent_item = temp; } if (paths.value.length < 1) { - paths.value.push(new _BreadcrumbItem("root", "")); + paths.value.push(new _BreadcrumbItem("local disk", "media")); } refresh_file_list(); } ); + watch( + () => status.value, + (newValue: string) => { + switch (newValue) { + case "normal": + case "select": + break; + default: + console.log("status error!", status.value); + status.value = "normal"; + } + } + ); + + watch( + () => default_path.value, + (newValue: string) => { + let item = disk_options.value.find((item) => item.value == newValue); + if (item && item.value && item.label) { + default_path_label.value = item.label; + path.value = default_path.value; + } + } + ); + return { show_dialog, loading, + uploading, files, columns, show_context_menu, + default_path, + default_path_label, path, prev_path, paths, target_dom, upload_url, + uploader, + disk_options, current_file, refresh_file_list, refresh_file_list_async, status, - showDialog() { + showDialog(in_status: string) { + status.value = in_status; refresh_file_list(); show_dialog.value = true; }, + showDialogAsync(in_status: string) { + return new Promise((_resolve, _reject) => { + status.value = in_status; + refresh_file_list(); + show_dialog.value = true; + resolve = _resolve; + }); + }, generatorFileUploadHeaders(files: File[]) { if (files.length > 0) { return [ @@ -466,6 +598,10 @@ export default defineComponent({ path.value = ""; status.value = "normal"; upload_url.value = ""; + if (resolve) { + resolve(resolve_value); + } + resolve_value = null; }, async onCreateNewFolder() { let url = GlobalData.getInstance().createCurrentRequestUrl(); @@ -513,6 +649,7 @@ export default defineComponent({ }); } }, + selectFile, async deleteFile(file: FileEntity) { let url = GlobalData.getInstance().createCurrentRequestUrl(); if (url) { @@ -623,6 +760,8 @@ export default defineComponent({ onTableItemDBClick(evt: PointerEvent, row: FileEntity, index: number) { if (row && row.is_directory) { path.value += "/" + row.name; + } else if (status.value == "select" && !row.is_directory) { + selectFile(row); } }, backToParentPath() { @@ -642,7 +781,12 @@ export default defineComponent({ } return "#"; }, + onStartUpload() { + loading.value = true; + }, onUploaded() { + uploading.value = false; + uploader.value.reset(); refresh_file_list(); $q.notify({ @@ -651,6 +795,7 @@ export default defineComponent({ position: "top", timeout: 1500, }); + loading.value = false; }, onFailed(info: any) { console.log(info); @@ -661,6 +806,7 @@ export default defineComponent({ timeout: 1500, }); loading.value = false; + loading.value = false; }, }; }, diff --git a/src/components/SignalSourceDialog.vue b/src/components/SignalSourceDialog.vue index de74d3c..16d92e2 100644 --- a/src/components/SignalSourceDialog.vue +++ b/src/components/SignalSourceDialog.vue @@ -103,7 +103,7 @@ >