From 9be5670e35e25c77f1d8d0bdf0e84bb78fb313e6 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期五, 23 一月 2026 16:03:35 +0800
Subject: [PATCH] 规章制度附件上传下载
---
src/pages/managementMeetings/rulesRegulationsManagement/index.vue | 6 +++
src/pages/managementMeetings/rulesRegulationsManagement/fileList.vue | 114 ++++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 86 insertions(+), 34 deletions(-)
diff --git a/src/pages/managementMeetings/rulesRegulationsManagement/fileList.vue b/src/pages/managementMeetings/rulesRegulationsManagement/fileList.vue
index c31e39b..90272b5 100644
--- a/src/pages/managementMeetings/rulesRegulationsManagement/fileList.vue
+++ b/src/pages/managementMeetings/rulesRegulationsManagement/fileList.vue
@@ -31,7 +31,7 @@
<u-button size="small"
type="info"
plain
- @click="downloadFile(file)">涓嬭浇</u-button>
+ @click="downloadFile(file)">涓嬭浇骞堕瑙�</u-button>
<u-button size="small"
type="error"
plain
@@ -48,10 +48,10 @@
<text class="empty-text">鏆傛棤闄勪欢</text>
</view>
</view>
- <a rel="nofollow"
+ <!-- <a rel="nofollow"
id="downloadLink"
href="#"
- style="display:none;">涓嬭浇鏂囨湰鏂囦欢</a>
+ style="display:none;">涓嬭浇鏂囨湰鏂囦欢</a> -->
<!-- 涓婁紶鎸夐挳 -->
<view class="upload-button"
@click="chooseFile">
@@ -143,18 +143,19 @@
// 閫夋嫨鏂囦欢
const chooseFile = () => {
- // uni.chooseImage({
- // count: 9,
- // sizeType: ["original", "compressed"],
- // sourceType: ["album", "camera"],
- // success: res => {
- // uploadFiles(res.tempFiles);
- // },
- // fail: err => {
- // console.error("閫夋嫨鍥剧墖澶辫触:", err);
- // showToast("閫夋嫨鏂囦欢澶辫触");
- // },
- // });
+ uni.chooseImage({
+ count: 9,
+ sizeType: ["original", "compressed"],
+ sourceType: ["album", "camera"],
+ success: res => {
+ console.log(res, "閫夋嫨鍥剧墖鎴愬姛");
+ uploadFiles(res.tempFiles);
+ },
+ fail: err => {
+ console.error("閫夋嫨鍥剧墖澶辫触:", err);
+ showToast("閫夋嫨鏂囦欢澶辫触");
+ },
+ });
// uni.chooseFile({
// count: 9,
// extension: [
@@ -174,6 +175,7 @@
// ".rar",
// ],
// success: res => {
+ // console.log(res, "閫夋嫨鏂囦欢鎴愬姛");
// uploadFiles(res.tempFiles);
// },
// fail: err => {
@@ -184,13 +186,14 @@
// 涓婁紶鏂囦欢
const uploadFiles = tempFiles => {
+ console.log(tempFiles, "涓婁紶鏂囦欢1");
tempFiles.forEach((tempFile, index) => {
// 鏄剧ず涓婁紶涓彁绀�
uni.showLoading({
title: "涓婁紶涓�...",
mask: true,
});
- console.log(tempFile, "涓婁紶鏂囦欢");
+ console.log(tempFile, "涓婁紶鏂囦欢2");
// 1. 鐩存帴浣跨敤 uni.uploadFile 涓婁紶鏂囦欢
uni.uploadFile({
url: config.baseUrl + "/file/upload",
@@ -201,12 +204,17 @@
},
success: uploadRes => {
uni.hideLoading();
+ console.log(uploadRes, "涓婁紶鏂囦欢3");
+
try {
const res = JSON.parse(uploadRes.data);
+ console.log(res, "涓婁紶鏂囦欢4");
if (res.code === 200) {
// 2. 鎻愬彇鏂囦欢淇℃伅
- const fileName = tempFile.name;
- const fileType = fileName.split(".").pop();
+ const fileName = tempFile.name
+ ? tempFile.name
+ : tempFile.path.split("/").pop();
+ // const fileType = fileName.split(".").pop();
// 3. 鏋勯�犱繚瀛樻枃浠朵俊鎭殑鍙傛暟
const saveData = {
name: fileName,
@@ -250,7 +258,6 @@
});
});
};
-
// 涓嬭浇鏂囦欢
const downloadFile = file => {
var url =
@@ -267,21 +274,60 @@
header: { Authorization: "Bearer " + getToken() },
})
.then(res => {
- console.log(res, "res");
- const isBlob = blobValidate(res.data);
- console.log(isBlob, "isBlob");
- if (isBlob) {
- const blob = new Blob([res.data], { type: "text/plain" });
- const url = URL.createObjectURL(blob);
- const downloadLink = document.getElementById("downloadLink");
- downloadLink.href = url;
- downloadLink.download = file.name;
- downloadLink.click();
- // downloadLink.style.display = "block";
- showToast("涓嬭浇鎴愬姛");
+ let osType = uni.getStorageSync("deviceInfo").osName;
+ let filePath = res.tempFilePath;
+ if (osType === "ios") {
+ uni.openDocument({
+ filePath: filePath,
+ showMenu: true,
+ success: res => {
+ resolve(res);
+ },
+ fail: err => {
+ console.log("uni.openDocument--fail");
+ reject(err);
+ },
+ });
} else {
- showToast("涓嬭浇澶辫触");
+ uni.saveFile({
+ tempFilePath: filePath,
+ success: fileRes => {
+ uni.showToast({
+ icon: "none",
+ mask: true,
+ title:
+ "鏂囦欢宸蹭繚瀛橈細Android/data/uni.UNI720216F/apps/__UNI__720216F/" +
+ fileRes.savedFilePath, //淇濆瓨璺緞
+ duration: 3000,
+ });
+ setTimeout(() => {
+ //鎵撳紑鏂囨。鏌ョ湅
+ uni.openDocument({
+ filePath: fileRes.savedFilePath,
+ success: function (res) {
+ resolve(fileRes);
+ },
+ });
+ }, 3000);
+ },
+ fail: err => {
+ console.log("uni.save--fail");
+ reject(err);
+ },
+ });
}
+ // const isBlob = blobValidate(res.data);
+ // if (isBlob) {
+ // const blob = new Blob([res.data], { type: "text/plain" });
+ // const url = URL.createObjectURL(blob);
+ // const downloadLink = document.getElementById("downloadLink");
+ // downloadLink.href = url;
+ // downloadLink.download = file.name;
+ // downloadLink.click();
+ // showToast("涓嬭浇鎴愬姛");
+ // } else {
+ // showToast("涓嬭浇澶辫触");
+ // }
})
.catch(err => {
console.error("涓嬭浇澶辫触:", err);
@@ -483,8 +529,8 @@
position: fixed;
bottom: 40rpx;
right: 40rpx;
- width: 80rpx;
- height: 80rpx;
+ width: 130rpx;
+ height: 130rpx;
border-radius: 50%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
diff --git a/src/pages/managementMeetings/rulesRegulationsManagement/index.vue b/src/pages/managementMeetings/rulesRegulationsManagement/index.vue
index e3f223b..431814c 100644
--- a/src/pages/managementMeetings/rulesRegulationsManagement/index.vue
+++ b/src/pages/managementMeetings/rulesRegulationsManagement/index.vue
@@ -115,6 +115,12 @@
@click="viewDetail(item,2)">
缂栬緫
</u-button>
+ <u-button type="primary"
+ size="small"
+ class="action-btn"
+ @click="fileList(item,2)">
+ 闄勪欢
+ </u-button>
</view>
</view>
</view>
--
Gitblit v1.9.3