|
@@ -0,0 +1,162 @@
|
|
|
+<template>
|
|
|
+ <div class="tool-manage package-manage">
|
|
|
+ <el-row :gutter="20" type="flex">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-card class="card-box upload-card" header="包上传">
|
|
|
+ <h3 class="mb-2">图片下载工具:</h3>
|
|
|
+ <el-upload
|
|
|
+ drag
|
|
|
+ action="/api/admin/sys/client/package/upload"
|
|
|
+ accept=".zip"
|
|
|
+ :show-file-list="false"
|
|
|
+ :on-error="handleError"
|
|
|
+ :on-success="handleSuccess"
|
|
|
+ :http-request="upload"
|
|
|
+ :disabled="loading"
|
|
|
+ :on-change="handleFileChange"
|
|
|
+ ref="UploadComp"
|
|
|
+ >
|
|
|
+ <i class="el-icon-upload"></i><br />
|
|
|
+ <em class="el-upload__text">点击或将文件拖拽到这里上传</em>
|
|
|
+ <p
|
|
|
+ slot="tip"
|
|
|
+ :class="[
|
|
|
+ `info-tips`,
|
|
|
+ {
|
|
|
+ 'tips-success': result.success,
|
|
|
+ 'tips-error': !result.success,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ v-if="result.message"
|
|
|
+ >
|
|
|
+ {{ result.message }}
|
|
|
+ </p>
|
|
|
+ </el-upload>
|
|
|
+ <div
|
|
|
+ v-if="curProcess.filename && loading"
|
|
|
+ class="upload-precess box-justify"
|
|
|
+ >
|
|
|
+ <div class="upload-name">
|
|
|
+ <p>{{ curProcess.filename }}</p>
|
|
|
+ <el-progress :percentage="curProcess.progress"></el-progress>
|
|
|
+ </div>
|
|
|
+ <i class="icon icon-close-act" @click="toDelete"></i>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-card class="card-box package-card" header="包信息">
|
|
|
+ <h3>
|
|
|
+ 安装包(更新时间:{{ info.installUploadTime | timestampFilter }})
|
|
|
+ </h3>
|
|
|
+ <p>
|
|
|
+ <span>下载地址:</span>
|
|
|
+ <a v-if="installUrl" :href="installUrl" download>
|
|
|
+ {{ info.fileName }}</a
|
|
|
+ >
|
|
|
+ <span v-else>--</span>
|
|
|
+ </p>
|
|
|
+ </el-card>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { toolInfo, uploadTool } from "../api";
|
|
|
+import { fileMD5 } from "@/plugins/md5";
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: "tool-manage",
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ info: {},
|
|
|
+ result: {
|
|
|
+ message: "",
|
|
|
+ success: true,
|
|
|
+ },
|
|
|
+ curProcess: {
|
|
|
+ filename: "",
|
|
|
+ progress: 0,
|
|
|
+ },
|
|
|
+ loading: false,
|
|
|
+ uploadController: null,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ installUrl() {
|
|
|
+ return this.info.prefix ? `${this.info.prefix}/${this.info.url}` : "";
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ // this.getInfo();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ initData() {
|
|
|
+ this.result = {
|
|
|
+ message: "",
|
|
|
+ success: true,
|
|
|
+ };
|
|
|
+ this.curProcess = {
|
|
|
+ filename: "",
|
|
|
+ progress: 0,
|
|
|
+ };
|
|
|
+ this.loading = false;
|
|
|
+ this.uploadController = null;
|
|
|
+ },
|
|
|
+ async getInfo() {
|
|
|
+ const res = await toolInfo();
|
|
|
+ this.info = res || {};
|
|
|
+ },
|
|
|
+ handleFileChange(file) {
|
|
|
+ if (file.status === "ready") {
|
|
|
+ this.initData();
|
|
|
+ }
|
|
|
+ this.curProcess.filename = file.name;
|
|
|
+ },
|
|
|
+ async upload(options) {
|
|
|
+ this.uploadController = new AbortController();
|
|
|
+ this.loading = true;
|
|
|
+ let formData = new FormData();
|
|
|
+ formData.append("file", options.file);
|
|
|
+ const md5 = await fileMD5(options.file);
|
|
|
+ formData.append("md5", md5);
|
|
|
+
|
|
|
+ return uploadTool(formData, {
|
|
|
+ timeout: 60 * 60 * 1000,
|
|
|
+ signal: this.uploadController.signal,
|
|
|
+ onUploadProgress: ({ loaded, total }) => {
|
|
|
+ this.curProcess.progress = Math.floor((100 * loaded) / total);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
+ handleError(error) {
|
|
|
+ const message = error.message === "canceled" ? "已取消" : error.message;
|
|
|
+
|
|
|
+ this.loading = false;
|
|
|
+ this.result = {
|
|
|
+ success: false,
|
|
|
+ message,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ handleSuccess(responseData) {
|
|
|
+ this.loading = false;
|
|
|
+ this.result = {
|
|
|
+ success: true,
|
|
|
+ message: "导入成功!",
|
|
|
+ };
|
|
|
+ this.initData();
|
|
|
+ this.getInfo();
|
|
|
+ },
|
|
|
+ async toDelete() {
|
|
|
+ const confirm = await this.$confirm(`确定要取消上传吗?`, "提示", {
|
|
|
+ type: "warning",
|
|
|
+ }).catch(() => {});
|
|
|
+ if (confirm !== "confirm") return;
|
|
|
+
|
|
|
+ this.uploadController && this.uploadController.abort();
|
|
|
+ this.initData();
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|