From fb16e99d60035949b870d0bed7f38b452458000a Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期四, 15 十月 2026 15:10:00 +0800
Subject: [PATCH] 修改了专家费校验和附件名字校验
---
src/views/project/documentfiles/index.vue | 117 ++++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 92 insertions(+), 25 deletions(-)
diff --git a/src/views/project/documentfiles/index.vue b/src/views/project/documentfiles/index.vue
index d5d6185..a916524 100644
--- a/src/views/project/documentfiles/index.vue
+++ b/src/views/project/documentfiles/index.vue
@@ -273,7 +273,7 @@
size="small"
style="width: 220px"
v-model="form.uploadtime"
- type="datetime"
+ type="datetime" format="yyyy-MM-dd HH:mm"
value-format="yyyy-MM-dd HH:mm:ss"
>
</el-date-picker>
@@ -331,7 +331,6 @@
<el-input v-model="form.fileurl" placeholder="璇疯緭鍏ユ枃浠跺湴鍧�" />
</el-form-item> -->
<el-form-item label="鏂囦欢涓婁紶" align="left" prop="fileurl">
- <!-- <file-upload ref="fileUpload" :fileType=fileType :limit="1" :on-success="handleUploadSuccess"></file-upload> -->
<el-upload
size="mini"
class="upload-demo"
@@ -460,7 +459,6 @@
fileurl: null,
status: null,
},
- fileType: ["png", "jpg", "jpeg", "doc", "xls", "ppt", "txt", "pdf"],
// 琛ㄥ崟鍙傛暟
form: {},
// 琛ㄥ崟鏍¢獙
@@ -469,8 +467,9 @@
//鏂囦欢鍒楄〃
fileList: [],
baseUrl: process.env.VUE_APP_BASE_API,
- // 涓婁紶鐨勫浘鐗囨湇鍔″櫒鍦板潃
- uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload",
+ // 鏀跨瓥鏂囦欢涓婁紶鎺ュ彛锛�2026-10-09锛氭敼鐢ㄦā鍧椾笓灞炴帴鍙o紝鍏佽浠绘剰鏂囦欢绫诲瀷锛�
+ // 閫氱敤 /common/upload 浠嶆寜鎵╁睍鍚嶇櫧鍚嶅崟鏍¢獙锛屼笉閫傜敤浜庢湰妯″潡锛�
+ uploadFileUrl: process.env.VUE_APP_BASE_API + "/project/documentfiles/upload",
//涓婁紶闄勪欢璇锋眰澶�
headers: {
Authorization: "Bearer " + getToken(),
@@ -659,34 +658,100 @@
download() {
let list = this.fileList;
if (list.length > 0) {
- let downUrl = list[0].url;
- const link = document.createElement("a");
- link.href = this.baseUrl + downUrl;
- link.setAttribute("download", this.getFileName(list[0].name));
- document.body.appendChild(link);
- link.click();
+ this.saveFile(list[0].url, this.getFileName(list[0].name, list[0].url));
} else {
this.$modal.msgWarning("鏈幏鍙栧埌鏂囦欢鍦板潃锛岃纭");
}
},
handleDownload(row) {
if (row.fileurl != "" && row.fileurl != null) {
- const link = document.createElement("a");
- link.href = this.baseUrl + row.fileurl;
- link.setAttribute("download", this.getFileName(row.fileurl));
- document.body.appendChild(link);
- link.click();
+ this.saveFile(
+ row.fileurl,
+ this.getFileName(row.filename, row.fileurl, row.filename)
+ );
} else {
this.$modal.msgWarning("鏈幏鍙栧埌鏂囦欢鍦板潃锛岃纭");
}
},
- // 鑾峰彇鏂囦欢鍚嶇О
- getFileName(name) {
- if (name.lastIndexOf("/") > -1) {
- return name.slice(name.lastIndexOf("/") + 1).toLowerCase();
- } else {
- return "";
+
+ /**
+ * 涓嬭浇鏂囦欢锛堝繀椤诲甫閴存潈锛夈��
+ *
+ * 鑳屾櫙锛�/profile/** 闈欐�佽祫婧愭湭鍦� SecurityConfig 涓斁琛岋紙anyRequest().authenticated()锛夛紝
+ * 鑰屽悗绔� TokenService 鍙粠璇锋眰澶� Authorization 鍙� token銆�
+ * 鍥犳鐢� <a href> 鐩存帴璺宠浆涓嬭浇涓嶄細鎼哄甫 token锛屾湇鍔$杩斿洖 401锛岃〃鐜颁负鈥滅偣涓嬭浇娌″弽搴�/涓嬩笉鍒版枃浠垛�濄��
+ * 杩欓噷鏀逛负 fetch 甯� Authorization 澶村彇鍥炴枃浠舵祦锛屽啀鐢� blob 鏈湴鍙﹀瓨銆�
+ *
+ * @param {string} fileUrl 鏂囦欢鍦板潃锛堝簱涓瓨鐨勬槸 /profile/upload/... 鐩稿璺緞锛�
+ * @param {string} fileName 鍙﹀瓨涓虹殑鏂囦欢鍚�
+ */
+ saveFile(fileUrl, fileName) {
+ if (!fileUrl) {
+ this.$modal.msgWarning("鏈幏鍙栧埌鏂囦欢鍦板潃锛岃纭");
+ return;
}
+ // 鍏煎鍘嗗彶鏁版嵁涓凡鏄粷瀵瑰湴鍧�鐨勬儏鍐碉紝閬垮厤閲嶅鎷兼帴
+ const isAbsolute = /^https?:\/\//i.test(fileUrl);
+ const url = isAbsolute ? fileUrl : this.baseUrl + fileUrl;
+
+ this.$modal.loading("姝e湪涓嬭浇鏂囦欢锛岃鑰愬績绛夊緟锛�");
+ fetch(url, {
+ method: "get",
+ headers: { Authorization: "Bearer " + getToken() },
+ })
+ .then((response) => {
+ if (!response.ok) {
+ // 401/403/404 蹇呴』鏄惧紡鎻愮ず锛屽惁鍒欎細涓嬪埌涓�涓唴瀹逛负閿欒椤电殑鏂囦欢
+ throw new Error("HTTP " + response.status);
+ }
+ return response.blob();
+ })
+ .then((blob) => {
+ const blobUrl = window.URL.createObjectURL(blob);
+ const link = document.createElement("a");
+ link.href = blobUrl;
+ link.setAttribute("download", fileName || "涓嬭浇鏂囦欢");
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ window.URL.revokeObjectURL(blobUrl);
+ })
+ .catch((err) => {
+ console.error("鏂囦欢涓嬭浇澶辫触锛�" + url, err);
+ this.$modal.msgError("鏂囦欢涓嬭浇澶辫触锛岃纭鏂囦欢鏄惁瀛樺湪鎴栫櫥褰曟槸鍚﹁繃鏈�");
+ })
+ .finally(() => {
+ this.$modal.closeLoading();
+ });
+ },
+
+ /**
+ * 鑾峰彇鍙﹀瓨涓虹殑鏂囦欢鍚嶃��
+ *
+ * 浼樺厛绾э細甯︽墿灞曞悕鐨勫師濮嬫枃浠跺悕 > 鏂囦欢鍦板潃鏈 > 鏂囨。鏍囬銆�
+ * 涔嬫墍浠ヤ笉鐩存帴鐢� form.filename锛氳瀛楁鍦ㄨ〃鍗曚腑鍙墜宸ョ紪杈戯紙濡傗�滀汉浣撳櫒瀹樼Щ妞嶆潯渚嬧�濓級锛�
+ * 涓嶅甫鎵╁睍鍚嶏紝鐩存帴鐢ㄤ綔鍙﹀瓨鍚嶄細瀵艰嚧绯荤粺鏃犳硶璇嗗埆鎵撳紑鏂瑰紡銆�
+ *
+ * @param {string} storedName 鍘熷鏂囦欢鍚嶏紙濡� form.filename 涓瓨鐨� xxx.docx锛�
+ * @param {string} fileUrl 鏂囦欢鍦板潃
+ * @param {string} title 澶囩敤鍚嶇О锛堟枃妗f爣棰橈級
+ */
+ getFileName(storedName, fileUrl, title) {
+ const hasExt = (name) => !!name && name.lastIndexOf(".") > -1;
+
+ if (hasExt(storedName)) {
+ return storedName;
+ }
+
+ const source = fileUrl || "";
+ if (source.lastIndexOf("/") > -1) {
+ const fromUrl = source.slice(source.lastIndexOf("/") + 1);
+ if (fromUrl) {
+ return fromUrl;
+ }
+ }
+
+ return title || storedName || "涓嬭浇鏂囦欢";
},
//鏂囦欢涓婁紶鎴愬姛鍥炶皟
@@ -698,7 +763,8 @@
this.$modal.msgSuccess(response.msg);
this.fileList.push({ name: response.fileName, url: response.fileName });
} else {
- this.$modal.msgError(response.msg);
+ // 2026-10-09锛氫笂浼犲け璐ュ繀椤绘彁绀恒�傚師鏉ュ彧 console.log锛岀敤鎴风湅涓嶅埌澶辫触鍘熷洜锛堣〃鐜颁负"鐐逛簡娌″弽搴�"锛�
+ this.$modal.msgError(response.msg || "涓婁紶澶辫触锛岃閲嶈瘯");
}
//console.log("涓婁紶鏂囦欢鍚庯細" + JSON.stringify(this.fileList));
},
@@ -716,9 +782,10 @@
handleExceed() {
this.$message.error(`涓婁紶鏂囦欢鏁伴噺宸茶秴杩�!`);
},
- // 涓婁紶澶辫触
+ // 涓婁紶澶辫触锛圚TTP 灞傞敊璇紝濡傜櫥褰曡繃鏈熴�佺綉缁滃紓甯革級
handleUploadError(err) {
- this.$message.error("涓婁紶澶辫触, 璇烽噸璇�" + JSON.stringify(err));
+ const msg = (err && (err.msg || err.message)) || "";
+ this.$modal.msgError("涓婁紶澶辫触锛岃閲嶈瘯" + (msg ? "锛�" + msg : ""));
},
},
};
--
Gitblit v1.9.3