From a57e03f7cb03c1ba5f2f2b4c5d7a06b0ed1d0ecb Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期四, 09 四月 2026 11:42:26 +0800
Subject: [PATCH] fix: 添加APP版本管理

---
 src/api/system/appVersion.js          |   22 ++++
 src/views/system/appVersion/index.vue |  220 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 242 insertions(+), 0 deletions(-)

diff --git a/src/api/system/appVersion.js b/src/api/system/appVersion.js
new file mode 100644
index 0000000..25aa02b
--- /dev/null
+++ b/src/api/system/appVersion.js
@@ -0,0 +1,22 @@
+import request from "@/utils/request";
+
+// 鏌ヨ APP 鐗堟湰鍒嗛〉鍒楄〃
+export function listAppVersion(params) {
+  return request({
+    url: "/app/getAllVersion",
+    method: "get",
+    params,
+  });
+}
+
+// 涓婁紶 APK
+export function uploadApk(data) {
+  return request({
+    url: "/app/uploadApk",
+    method: "post",
+    data,
+    headers: {
+      "Content-Type": "multipart/form-data",
+    },
+  });
+}
diff --git a/src/views/system/appVersion/index.vue b/src/views/system/appVersion/index.vue
new file mode 100644
index 0000000..6d68c07
--- /dev/null
+++ b/src/views/system/appVersion/index.vue
@@ -0,0 +1,220 @@
+<template>
+  <div class="app-container">
+    <el-row :gutter="10" class="mb8">
+      <el-col :span="1.5">
+        <el-button type="primary" plain icon="Upload" @click="openUploadDialog">涓婁紶APK</el-button>
+      </el-col>
+    </el-row>
+
+    <el-table v-loading="loading" :data="versionList">
+      <el-table-column label="ID" prop="id" align="center" width="80" />
+      <el-table-column label="搴旂敤鍚嶇О" prop="name" align="center" min-width="150" />
+      <el-table-column label="鐗堟湰鍙�" prop="version" align="center" width="120" />
+      <el-table-column label="鍒涘缓鏃堕棿" prop="createTime" align="center" width="170">
+        <template #default="scope">
+          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{i}:{s}") }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column label="鏇存柊鏃堕棿" prop="updateTime" align="center" width="170">
+        <template #default="scope">
+          <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d} {h}:{i}:{s}") }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column label="鍒涘缓浜�" prop="createUser" align="center" width="100" />
+      <el-table-column label="鎿嶄綔" align="center" width="100" class-name="small-padding fixed-width">
+        <template #default="scope">
+          <el-button link type="primary" @click="downloadAttachment(scope.row)">涓嬭浇</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+
+    <pagination
+      v-show="total > 0"
+      :total="total"
+      v-model:page="queryParams.current"
+      v-model:limit="queryParams.size"
+      @pagination="getList"
+    />
+
+    <el-dialog title="涓婁紶APK" v-model="uploadOpen" width="560px" append-to-body @close="resetUploadForm">
+      <el-form ref="uploadRef" :model="uploadForm" :rules="uploadRules" label-width="90px">
+        <el-form-item label="搴旂敤鍚嶇О" prop="name">
+          <el-input v-model="uploadForm.name" placeholder="璇疯緭鍏ュ簲鐢ㄥ悕绉�" />
+        </el-form-item>
+        <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>
+      </el-form>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button type="primary" :loading="uploading" @click="submitUpload">纭� 瀹�</el-button>
+          <el-button @click="uploadOpen = false">鍙� 娑�</el-button>
+        </div>
+      </template>
+    </el-dialog>
+  </div>
+</template>
+
+<script setup name="SystemAppVersion">
+import { listAppVersion, uploadApk } from "@/api/system/appVersion";
+
+const { proxy } = getCurrentInstance();
+
+const loading = ref(false);
+const versionList = ref([]);
+const total = ref(0);
+
+const queryParams = reactive({
+  current: 1,
+  size: 10,
+});
+
+const uploadOpen = ref(false);
+const uploading = ref(false);
+const uploadForm = reactive({
+  name: "",
+  version: "",
+  file: null,
+});
+
+const uploadRules = {
+  name: [{ required: true, message: "璇疯緭鍏ュ簲鐢ㄥ悕绉�", trigger: "blur" }],
+  version: [{ required: true, message: "璇疯緭鍏ョ増鏈彿", trigger: "blur" }],
+  file: [{ required: true, message: "璇蜂笂浼燗PK鏂囦欢", trigger: "change" }],
+};
+
+function normalizeListResp(res) {
+  const data = res?.data || {};
+  const records = data.records || res?.rows || [];
+  const totalNum = Number(data.total ?? res?.total ?? 0);
+  return {
+    records: Array.isArray(records) ? records : [],
+    total: Number.isNaN(totalNum) ? 0 : totalNum,
+  };
+}
+
+function getList() {
+  loading.value = true;
+  listAppVersion(queryParams)
+    .then(res => {
+      const result = normalizeListResp(res);
+      versionList.value = result.records;
+      total.value = result.total;
+    })
+    .finally(() => {
+      loading.value = false;
+    });
+}
+
+function openUploadDialog() {
+  resetUploadForm();
+  uploadOpen.value = true;
+}
+
+function resetUploadForm() {
+  uploadForm.name = "";
+  uploadForm.version = "";
+  uploadForm.file = 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("鍙兘涓婁紶涓�涓狝PK鏂囦欢");
+}
+
+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);
+}
+
+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)
+      .then(() => {
+        proxy.$modal.msgSuccess("涓婁紶鎴愬姛");
+        uploadOpen.value = false;
+        getList();
+      })
+      .finally(() => {
+        uploading.value = false;
+      });
+  });
+}
+
+onMounted(() => {
+  getList();
+});
+</script>

--
Gitblit v1.9.3