From 0e10e10157b90002b99996914eaf1e5574924ddf Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期一, 12 十月 2026 11:15:50 +0800
Subject: [PATCH] 修改了报销校验
---
src/views/project/documentfiles/index.vue | 104 ++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 85 insertions(+), 19 deletions(-)
diff --git a/src/views/project/documentfiles/index.vue b/src/views/project/documentfiles/index.vue
index 64bf2be..2114751 100644
--- a/src/views/project/documentfiles/index.vue
+++ b/src/views/project/documentfiles/index.vue
@@ -273,8 +273,8 @@
size="small"
style="width: 220px"
v-model="form.uploadtime"
- type="datetime"
- value-format="yyyy-MM-dd HH:mm:ss"
+ type="datetime" format="yyyy-MM-dd HH:mm"
+ value-format="yyyy-MM-dd HH:mm"
>
</el-date-picker>
</el-form-item>
@@ -659,34 +659,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 || "涓嬭浇鏂囦欢";
},
//鏂囦欢涓婁紶鎴愬姛鍥炶皟
--
Gitblit v1.9.3