chenhj
2026-04-24 7916a958c24d69f841d978a5b317a426e94fd3b3
apk文件上传
已修改3个文件
101 ■■■■ 文件已修改
src/api/system/appVersion.js 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/AttachmentUpload/file/index.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/system/appVersion/index.vue 90 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/system/appVersion.js
@@ -10,13 +10,10 @@
}
// 上传 APK
export function uploadApk(data) {
export function add(data) {
  return request({
    url: "/app/uploadApk",
    url: "/app/add",
    method: "post",
    data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data
  });
}
src/components/AttachmentUpload/file/index.vue
@@ -17,7 +17,7 @@
  },
  limit: {
    type: Number,
    default: 20,
    default: 10,
  },
  fileSize: {
    type: Number,
src/views/system/appVersion/index.vue
@@ -44,22 +44,9 @@
        <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>
@@ -73,7 +60,8 @@
</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();
@@ -91,13 +79,13 @@
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) {
@@ -131,78 +119,20 @@
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;