| | |
| | | <el-form-item label="版本号" prop="version"> |
| | | <el-input v-model="uploadForm.version" placeholder="请输入版本号" /> |
| | | </el-form-item> |
| | | <el-form-item label="APK文件" prop="file"> |
| | | <el-upload |
| | | :auto-upload="false" |
| | | :show-file-list="true" |
| | | :limit="1" |
| | | accept=".apk" |
| | | :on-change="handleApkChange" |
| | | :on-remove="handleApkRemove" |
| | | :on-exceed="handleApkExceed" |
| | | :before-upload="beforeApkUpload" |
| | | > |
| | | <el-button type="primary">选择APK文件</el-button> |
| | | <template #tip> |
| | | <div class="el-upload__tip">只能上传 APK 文件,且不超过 200MB</div> |
| | | </template> |
| | | </el-upload> |
| | | <el-form-item label="APK文件" prop="storageBlobDTOList"> |
| | | <FileUpload v-model:file-list="uploadForm.storageBlobDTOList" :limit="1" :file-type="['apk']" |
| | | :file-size="200"/> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | |
| | | </template> |
| | | |
| | | <script setup name="SystemAppVersion"> |
| | | import { listAppVersion, uploadApk } from "@/api/system/appVersion"; |
| | | import {listAppVersion, add} from "@/api/system/appVersion"; |
| | | import FileUpload from "@/components/AttachmentUpload/file/index.vue"; |
| | | |
| | | const { proxy } = getCurrentInstance(); |
| | | |
| | |
| | | const uploadForm = reactive({ |
| | | name: "", |
| | | version: "", |
| | | file: null, |
| | | storageBlobDTOList: null, |
| | | }); |
| | | |
| | | const uploadRules = { |
| | | name: [{ required: true, message: "请输入应用名称", trigger: "blur" }], |
| | | version: [{ required: true, message: "请输入版本号", trigger: "blur" }], |
| | | file: [{ required: true, message: "请上传APK文件", trigger: "change" }], |
| | | storageBlobDTOList: [{required: true, message: "请上传APK文件", trigger: "change"}], |
| | | }; |
| | | |
| | | function normalizeListResp(res) { |
| | |
| | | function resetUploadForm() { |
| | | uploadForm.name = ""; |
| | | uploadForm.version = ""; |
| | | uploadForm.file = null; |
| | | uploadForm.storageBlobDTOList = null; |
| | | proxy.resetForm("uploadRef"); |
| | | } |
| | | |
| | | function beforeApkUpload(file) { |
| | | const isApk = /\.apk$/i.test(file.name); |
| | | if (!isApk) { |
| | | proxy.$modal.msgWarning("只能上传APK文件"); |
| | | return false; |
| | | } |
| | | const isLt200M = file.size / 1024 / 1024 < 200; |
| | | if (!isLt200M) { |
| | | proxy.$modal.msgWarning("APK 文件大小不能超过 200MB"); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | function handleApkChange(file) { |
| | | if (!file || !file.raw) return; |
| | | if (!beforeApkUpload(file.raw)) { |
| | | uploadForm.file = null; |
| | | proxy.$refs.uploadRef?.clearValidate("file"); |
| | | return; |
| | | } |
| | | uploadForm.file = file.raw; |
| | | } |
| | | |
| | | function handleApkRemove() { |
| | | uploadForm.file = null; |
| | | } |
| | | |
| | | function handleApkExceed() { |
| | | proxy.$modal.msgWarning("只能上传一个APK文件"); |
| | | } |
| | | |
| | | function downloadAttachment(row) { |
| | | const filePath = |
| | | (row.commonFileList && |
| | | row.commonFileList.length > 0 && |
| | | row.commonFileList[0].url) || |
| | | row.url; |
| | | if (!filePath) { |
| | | proxy.$modal.msgError("下载链接不存在"); |
| | | return; |
| | | } |
| | | |
| | | const link = document.createElement("a"); |
| | | const rawName = String(row.name || "").trim(); |
| | | const fallbackName = String(filePath).split("/").pop()?.split("?")[0] || "app"; |
| | | const baseName = rawName || fallbackName; |
| | | const downloadName = /\.apk$/i.test(baseName) ? baseName : `${baseName}.apk`; |
| | | console.log(downloadName,filePath,'downloadName,filePath'); |
| | | link.href = filePath; |
| | | link.download = downloadName; |
| | | link.target = "_blank"; |
| | | link.rel = "noopener noreferrer"; |
| | | document.body.appendChild(link); |
| | | link.click(); |
| | | document.body.removeChild(link); |
| | | window.open(row.downloadURL, "_blank"); |
| | | } |
| | | |
| | | function submitUpload() { |
| | | proxy.$refs.uploadRef.validate(valid => { |
| | | if (!valid) return; |
| | | const formData = new FormData(); |
| | | formData.append("name", uploadForm.name); |
| | | formData.append("version", uploadForm.version); |
| | | formData.append("file", uploadForm.file); |
| | | |
| | | uploading.value = true; |
| | | uploadApk(formData) |
| | | add(uploadForm) |
| | | .then(() => { |
| | | proxy.$modal.msgSuccess("上传成功"); |
| | | uploadOpen.value = false; |