|
@@ -1,18 +1,38 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, reactive, onMounted } from "vue";
|
|
|
+import { ref, reactive } from "vue";
|
|
|
import { useMainStore } from "@/stores/main";
|
|
|
import { required } from "@/utils";
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
import type { ImageDownload } from "@/interfaces";
|
|
|
import Dialog from "@/components/Dialog.vue";
|
|
|
+import WS from "@/stores/ws";
|
|
|
|
|
|
const mainStore = useMainStore();
|
|
|
const { t } = useI18n();
|
|
|
const valid = ref(true);
|
|
|
+const dialog = ref(false);
|
|
|
+const title = ref("");
|
|
|
const Form = ref();
|
|
|
let imgFiles = ref();
|
|
|
let imgList: any[] = reactive([]);
|
|
|
|
|
|
+async function upload() {
|
|
|
+ for (let i = 0; i < imgFiles.value.files.length; i++) {
|
|
|
+ const item = imgFiles.value.files[i];
|
|
|
+ imgList.push(item);
|
|
|
+ console.log("element", item.name);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// async function Submit() {
|
|
|
+// setTimeout(() => {
|
|
|
+// dialog.value = true;
|
|
|
+// }, 2000);
|
|
|
+// await (Form as any).value.validate();
|
|
|
+// if (valid.value) {
|
|
|
+// valid.value = false;
|
|
|
+// }
|
|
|
+// }
|
|
|
// props
|
|
|
let dialog = reactive({
|
|
|
msg: "圖片處理需要幾秒鐘的時間,敬請耐心等候",
|
|
@@ -21,6 +41,8 @@ let dialog = reactive({
|
|
|
});
|
|
|
|
|
|
async function Submit() {
|
|
|
+ WS.send("subscribe");
|
|
|
+
|
|
|
setTimeout(() => {
|
|
|
dialog.show = true;
|
|
|
}, 2000);
|
|
@@ -28,27 +50,36 @@ async function Submit() {
|
|
|
(Form as any).value.reset();
|
|
|
for (let i = 0; i < mainStore.images.length; i++) {
|
|
|
const element = mainStore.images[i];
|
|
|
+ imgList = imgList.filter(
|
|
|
+ (e) => e.stored_file_name === element.stored_file_name
|
|
|
+ );
|
|
|
imgList.push(element);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
- if (imgList.length === 0) {
|
|
|
- let images: any | null = localStorage.getItem("imagesList");
|
|
|
- if (images) {
|
|
|
- images = JSON.parse(images);
|
|
|
- for (let i = 0; i < images.length; i++) {
|
|
|
- const item = images[i];
|
|
|
- imgList.push(item);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // 存入 localStorage
|
|
|
+ // if (imgList.length === 0) {
|
|
|
+ // let images: any | null = localStorage.getItem("imagesList");
|
|
|
+ // if (images) {
|
|
|
+ // images = JSON.parse(images);
|
|
|
+ // for (let i = 0; i < images.length; i++) {
|
|
|
+ // const item = images[i];
|
|
|
+ // imgList.push(item);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // webSocket
|
|
|
+ WS.onmessage = function (e) {
|
|
|
+ mainStore.finishImage(e.data);
|
|
|
+ };
|
|
|
});
|
|
|
|
|
|
async function downloadImg(name: string, id: string) {
|
|
|
const data: ImageDownload = {
|
|
|
- file_name: id,
|
|
|
- stored_file_name: name.split(".")[0],
|
|
|
+ file_name: name.split(".")[0],
|
|
|
+ stored_file_name: id,
|
|
|
};
|
|
|
|
|
|
await mainStore.getImage(data);
|
|
@@ -58,18 +89,18 @@ const headers = [
|
|
|
{
|
|
|
title: "檔名",
|
|
|
sortable: true,
|
|
|
- key: "file_name",
|
|
|
+ key: "name",
|
|
|
align: "left",
|
|
|
},
|
|
|
{
|
|
|
title: t("state"),
|
|
|
sortable: true,
|
|
|
- key: "progress_state",
|
|
|
+ key: "state",
|
|
|
align: "left",
|
|
|
},
|
|
|
{
|
|
|
- title: t("download"),
|
|
|
- key: "stored_file_name",
|
|
|
+ title: t("preview"),
|
|
|
+ key: "id",
|
|
|
},
|
|
|
];
|
|
|
</script>
|
|
@@ -81,29 +112,16 @@ const headers = [
|
|
|
<h3 class="card-title mb-3">圖片優化</h3>
|
|
|
</v-card-title>
|
|
|
<v-card-text>
|
|
|
- <!-- <section class="d-flex flex-column form-title">
|
|
|
- <img src="@/assets/img/icon/add-image.png" alt="" class="mb-4" />
|
|
|
- <p>請點擊加入圖片並開始優化</p>
|
|
|
- </section> -->
|
|
|
-
|
|
|
- <v-form v-model="valid" ref="Form">
|
|
|
- <!-- <img src="@/assets/img/icon/add-image.png" alt="" class="mb-4" /> -->
|
|
|
- <!-- <input
|
|
|
+ <v-form v-model="valid" ref="Form" class="img-form">
|
|
|
+ <img src="@/assets/img/icon/add-image.png" alt="" class="mb-4" />
|
|
|
+ <input
|
|
|
@change="upload()"
|
|
|
ref="imgFiles"
|
|
|
type="file"
|
|
|
multiple
|
|
|
class="file-input"
|
|
|
- /> -->
|
|
|
-
|
|
|
- <v-file-input
|
|
|
- v-model="imgFiles"
|
|
|
- multiple
|
|
|
- label="請選擇圖片"
|
|
|
- prepend-icon="add_photo_alternate"
|
|
|
- ></v-file-input>
|
|
|
-
|
|
|
- <!-- <p>請點擊加入圖片並開始優化</p> -->
|
|
|
+ />
|
|
|
+ <p>請點擊加入圖片並開始優化</p>
|
|
|
</v-form>
|
|
|
</v-card-text>
|
|
|
<v-card-actions class="justify-center">
|
|
@@ -113,8 +131,7 @@ const headers = [
|
|
|
color="primary"
|
|
|
class="px-5"
|
|
|
prepend-icon="file_upload"
|
|
|
- @click="Submit()"
|
|
|
- >上傳</v-btn
|
|
|
+ >上傳圖片</v-btn
|
|
|
>
|
|
|
</v-card-actions>
|
|
|
</v-card>
|
|
@@ -124,17 +141,13 @@ const headers = [
|
|
|
<h3 class="card-title mb-3">上傳清單</h3>
|
|
|
</v-card-title>
|
|
|
|
|
|
- <v-data-table :headers="headers" :items="imgList">
|
|
|
- <template v-slot:item.progress_state="{ item }">
|
|
|
- <span v-if="item.raw.progress_state === 'completed'">
|
|
|
+ <v-data-table :headers="headers" :items="mainStore.images">
|
|
|
+ <template v-slot:item.state="{ item }">
|
|
|
+ <span v-if="item.raw.state === 'completed'">
|
|
|
<v-icon icon="check_circle" color="success" />
|
|
|
完成
|
|
|
</span>
|
|
|
- <span v-else-if="item.raw.progress_state === 'waiting'">
|
|
|
- <v-icon icon="pending" color="warning" />
|
|
|
- 等待中
|
|
|
- </span>
|
|
|
- <span v-else-if="item.raw.progress_state === 'processing'">
|
|
|
+ <span v-else>
|
|
|
<v-progress-circular
|
|
|
indeterminate
|
|
|
color="info"
|
|
@@ -142,28 +155,12 @@ const headers = [
|
|
|
></v-progress-circular>
|
|
|
處理中
|
|
|
</span>
|
|
|
- <span v-else>
|
|
|
- <v-icon icon="check_circle" color="success" />
|
|
|
- 完成
|
|
|
- </span>
|
|
|
</template>
|
|
|
- <template v-slot:item.stored_file_name="{ item }">
|
|
|
- <v-btn
|
|
|
- flat
|
|
|
- @click="downloadImg(item.raw.file_name, item.raw.stored_file_name)"
|
|
|
- >
|
|
|
- <v-icon icon="crop_original" />
|
|
|
- </v-btn>
|
|
|
+ <template v-slot:item.id="{ item }">
|
|
|
+ <v-icon icon="crop_original" />
|
|
|
</template>
|
|
|
</v-data-table>
|
|
|
</v-card>
|
|
|
-
|
|
|
- <Dialog
|
|
|
- :msg="dialog.msg"
|
|
|
- :state="dialog.state"
|
|
|
- :dialog="dialog.show"
|
|
|
- @close="dialog.show = false"
|
|
|
- ></Dialog>
|
|
|
</v-container>
|
|
|
</template>
|
|
|
|