el-upload 上傳圖片及回顯照片和預覽圖片,文件流和http線上鏈接格式操作

在這里插入圖片描述
在這里插入圖片描述

   <div  v-for="(info, index) in zsjzqwhxqList.helicopterTourInfoList"  :key="info.id" >編輯上傳圖片// oss返回線上地址http鏈接格式:<el-form-itemlabel="巡視結果照片":label-width="formLabelWidth"><el-upload:action="'http://×××××uploadFile'"list-type="picture-card":limit="10":on-exceed="limitError":on-success="(response, file, fileList) =>imgSuccess(response,file, fileList,index ) ":on-error="imgError":on-remove="(file, fileList) =>handleRemove(file,fileList, index) ":file-list="getFileList(info.url)":on-preview="handlePreview"class="horizontal-upload"  ></el-upload></el-form-item>//文件流格式:<el-col :span="24"><el-form-itemlabel="巡視結果照片":label-width="formLabelWidth"><el-upload:action="'×××接口地址/uploadFile' "list-type="picture-card":limit="10":on-exceed="limitError":on-success="(response, file, fileList) =>imgSuccess(response,file,fileList,index) ":on-error="imgError":on-remove="(file, fileList) =>handleRemove(file,fileList,index ) ":on-preview="handlePreview":file-list="getFileList(index)"class="horizontal-upload" ></el-upload></el-form-item></el-col>

然后就是方法了有2種

     //http在線返回:返回的是http形式直接瀏覽器可以打開// async xiaziaT() {//     for (const tourInfo of this.zsjzqwhxqListck//         .helicopterTourInfoList) {//         if (tourInfo.url) {//             const urls = tourInfo.url.split(",");//             for (const url of urls) {//                 try {//                     const data = await getFileUrl({ url });//                     console.log(data);//                     // 更新 tourInfo.imageUrl 以回顯圖片//                     tourInfo.imageUrl = data.data.msg;//                 } catch (error) {//                     console.error(`無法下載文件 ${url}`, error);//                 }//             }//         }//     }// },//文件流:后端接口返回文件流格式async xiaziaTwh() {this.teamPhotoUrls = [];const tempTeamPhotoUrls = [];for (const [tourIndex,tourInfo,] of this.zsjzqwhxqList.helicopterTourInfoList.entries()) {if (tourInfo.url) {console.log(tourInfo.url, "tourInfo.url");const urls = tourInfo.url.split(",");tempTeamPhotoUrls[tourIndex] = [];for (const url of urls) {try {const data = await downloadFile({ url });let blob = new Blob([data], {type: "image/jpg",});console.log(data);const imageUrl = data.data.msg;tempTeamPhotoUrls[tourIndex].push({name: url.split(",").pop(),url: imageUrl,});console.log(this.fileList, "234");} catch (error) {console.error(`無法從下載文件 ${url}`, error);}}}}this.teamPhotoUrls = tempTeamPhotoUrls;},

公共方法:

 data() {return {fileList: [],fileListCache: {},zsjzqwhxqList: [],zsjzqwhxqListck: [],},
http在線方法:// getUrls(urlString) {//     if (typeof urlString !== "string" || !urlString) {//         return [];//     }//     return urlString.split(",");// },// getFileList(urlString) {//     if (this.fileListCache[urlString]) {//         return this.fileListCache[urlString];//     }//     const urls = this.getUrls(urlString);//     const fileList = urls.map((url, index) => ({//         name: `圖片 ${index + 1}`,//         url: url,//     }));//     this.fileListCache[urlString] = fileList;//     return fileList;// },
//防止上傳和回顯圖片了重復加載,因為是根據url:'里面有幾個url,隔開會請求幾遍文件流地址避免重復渲染'computed: {computedFileList() {return this.teamPhotoUrls.map((photos, index) => {return photos.map((photo) => ({name: photo.name,url: photo.url,status: "done", // 設置文件狀態為已完成}));});},
//上傳功能
limitError(files, fileList) {this.$message.error("最多只能上傳10張圖片");},imgSuccess(response, file, fileList, index) {console.log(file, fileList);// 獲取當前的 URL 列表let currentUrls =this.zsjzqwhxqList.helicopterTourInfoList[index].url || "";// 將新上傳的文件 URL 添加到當前的 URL 列表中const newUrl = file.response.msg;if (currentUrls) {currentUrls += "," + newUrl;} else {currentUrls = newUrl;}// 更新 URL 列表和文件列表this.zsjzqwhxqList.helicopterTourInfoList[index].url = currentUrls;this.zsjzqwhxqList.helicopterTourInfoList[index].fileList = fileList;this.$message.success("文件上傳成功");// this.$nextTick(() => {// this.xiaziaTwh();// });},imgError(err, file, fileList) {this.$message.error("文件上傳失敗");},limitError(files, fileList) {this.$message.error("上傳文件數量超出限制");},// 刪除圖片handleRemove(file, fileList, index) {console.log("Removing file:", file);console.log("Removing fileList:", fileList);console.log("Removing index:", index);const url ="××接口地址:10007/zxjcgjgl/helicopterTourManagement/deleteImage";let imageUrl;if (file.raw) {imageUrl = file.response.msg;console.log("6666");} else {imageUrl = file.name;console.log("7777");} fetch(url, {method: "POST",headers: {"Content-Type": "application/json",},body: JSON.stringify({ url: imageUrl }),}).then((response) => response.json()).then((data) => {console.log("響應數據:", data);let currentUrls = this.zsjzqwhxqList.helicopterTourInfoList[index].url;console.log("刪除前的當前URL:", currentUrls);if (data.code === 200) {if (currentUrls) {let urlArray = currentUrls.split(",");let newUrlArray = urlArray.filter((url) => url !== imageUrl);this.zsjzqwhxqList.helicopterTourInfoList[index ].url = newUrlArray.join(",");}this.zsjzqwhxqList.helicopterTourInfoList[index].fileList = fileList;this.$message.success("圖片刪除成功");} else {console.error("錯誤:", data);this.$message.error("圖片刪除失敗");}}).catch((error) => {console.error("錯誤", error);this.$message.error("圖片刪除失敗");});},
//預覽圖片:handlePreview(file) {this.$alert(`<img src="${file.url}" style="width: 100%;">`,"圖片預覽",{dangerouslyUseHTMLString: true,confirmButtonText: "關閉",});},

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/38314.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/38314.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/38314.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Cyber Weekly #13

賽博新聞 1、谷歌發布最強開源小模型Gemma-2 本周五&#xff08;6月28日&#xff09;凌晨&#xff0c;谷歌發布最強開源小模型Gemma-2&#xff0c;分別為9B&#xff08;90億&#xff09;和27B&#xff08;270億&#xff09;參數規模&#xff0c;其中9B 模型在多項基準測試中均…

潁川韓氏,來自戰國七雄韓國的豪族

潁川是戰國七雄韓國故土&#xff0c;韓國被秦國滅國后&#xff0c;王公貴族們除了堅決反秦的被殺了外&#xff0c;大部分都留存了下來。這些人在楚、漢反秦戰爭中&#xff0c;成為反秦統一戰線的重要力量&#xff0c;其中兩人先后被封為重新恢復的韓國的國王。 一個是橫陽君韓…

Windows系統下,將nginx注冊為本地服【親測可用】

在Windows系統下&#xff0c;將nginx注冊為本地服務并設置為開機自動運行&#xff0c;可以通過以下步驟進行&#xff1a; 下載Windows Service Wrapper&#xff1a; 訪問 WinSW 項目頁面&#xff0c;下載適用于Windows的版本。 準備nginx&#xff1a; 確保你已經下載并解壓了n…

共有5部手機,如果通過服務器讓1號手機執行打開 “閑魚.js“ 腳本

1.手機端Auto.js腳本&#xff1a; 每部手機需要在連接時發送一個唯一的標識符&#xff08;如設備ID&#xff09;&#xff0c;并接收服務器發送的指令以執行指定的腳本。 // Auto.js腳本連接WebSocket服務器并發送設備ID var WebSocket require(ws); var ws new WebSocket(w…

大模型上下文長度擴展中的檢索增強技術簡述

基于Transformer的語言模型在眾多自然語言處理任務上都取得了十分優異的成績&#xff0c;在一些任務上已經達到SOTA的效果。但是&#xff0c;經過預訓練后&#xff0c;模型能夠較好處理的序列長度就固定下來。而當前的眾多場景往往需要處理很長的上下文&#xff08;如&#xff…

CppTest單元測試框架(更新)

目錄 1 背景2 設計3 實現4 使用4.1 主函數4.2 使用方法 1 背景 前面文章單元測試之CppTest測試框架中講述利用宏ADD_SUITE將測試用例自動增加到測試框架中。但在使用中發現一個問題&#xff0c;就是通過宏ADD_SUITE增加多個測試Suite時&#xff0c;每次運行時都是所有測試Suit…

逆向開發環境準備

JDK安裝 AndroidStudio安裝 默認sdk路徑 C:\Users\Administrator\AppData\Local\Android\Sdk 將platform-tools所在的目錄添加到path C:\Users\Administrator\AppData\Local\Android\Sdk\platform-tools 主要目的是使用該目錄下的adb等命令 將tools所在的目錄添加到path C:\Us…

1-5題查詢 - 高頻 SQL 50 題基礎版

目錄 1. 相關知識點2. 例題2.1.可回收且低脂的產品2.2.尋找用戶推薦人2.3.大的國家2.4. 文章瀏覽 I2.5. 無效的推文 1. 相關知識點 sql判斷&#xff0c;不包含null&#xff0c;判斷不出來distinct是通過查詢的結果來去除重復記錄ASC升序計算字符長度 CHAR_LENGTH() 或 LENGTH(…

sqlmap注入詳解

免責聲明:本文僅做分享... 目錄 1.介紹 2.特點 3.下載 4.幫助文檔 5.常見命令 指定目標 請求 HTTP cookie頭 HTTP User-Agent頭 HTTP協議的證書認證 HTTP(S)代理 HTTP請求延遲 設定超時時間 設定重試超時 設定隨機改變的參數值 利用正則過濾目標網址 避免過多的…

Python-爬蟲案例

Python-爬蟲案例 代碼代碼 代碼 import requests import json import threading from queue import Queue import timeclass HeiMaTouTiao:def __init__(self):self.headers {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) ""AppleWebKit/53…

前端筆記-day11

文章目錄 01-空間-平移02-視距03-空間旋轉Z軸04-空間旋轉X軸05-空間旋轉Y軸06-立體呈現07-案例-3D導航08-空間縮放10-動畫實現步驟11-animation復合屬性12-animation拆分寫法13-案例-走馬燈14-案例-精靈動畫15-多組動畫16-全民出游全民出游.htmlindex.css 01-空間-平移 <!D…

基于Spring Boot的在線醫療咨詢平臺的設計與實現【附源碼】

基于Spring Boot的在線醫療咨詢平臺的設計與實現 Design and implementation of the computer hardware mall based on Spring Boot Candidate&#xff1a; Supervisor&#xff1a; April 20th, 2024 學位論文原創性聲明 本人鄭重聲明&#xff1a;所呈交的論文是本人在導師…

初中英語優秀作文分析-006How to Deal with the Exam Stress-如何應對考試壓力

更多資源請關注紐扣編程微信公眾號 記憶樹 1 We students are very busy with schoolwork and in the face of many exams every school day. 翻譯 我們學生忙于功課&#xff0c;每個上學日都面臨許多考試。 簡化記憶 考試 句子結構 We students 主語 我們學生&#xf…

Vite: 高階特性 Pure ESM

概述 ESM 已經逐步得到各大瀏覽器廠商以及 Node.js 的原生支持&#xff0c;正在成為主流前端模塊化方案。 而 Vite 本身就是借助瀏覽器原生的 ESM 解析能力( type“module” )實現了開發階段的 no-bundle &#xff0c;即不用打包也可以構建 Web 應用。不過我們對于原生 ESM 的…

綜合評價類模型——突變級數法

含義 首先&#xff1a;對評價目標進行多層次矛盾分解其次&#xff1a;利用突變理論和模糊數學相結合產生突變模糊隸屬函數再次&#xff1a;由歸一公式進行綜合量化運算最終&#xff1a;歸一為一個參數&#xff0c;即求出總的隸屬函數&#xff0c;從而對評價目標進行排序分析特點…

【linux/shell實戰案例】shell中變量的使用

目錄 一.linux變量聲明及定義 二.linux變量使用方法 三.linux變量使用花括號${name}和雙引號“$name”的區別 四.linux變量使用單引號$name和雙引號“$name”的區別 五.linux變量中使用命令 一.linux變量聲明及定義 #!/bin/bash namezhaodabao 等號兩邊不能有空格變量名…

ES6面試題——箭頭函數和普通函數有什么區別

1. this指向問題 <script> let obj {a: function () {console.log(this); // 打印出&#xff1a;{a: ?, b: ?}},b: () > {console.log(this); // 打印出Window {window: Window, self: Window,...}}, }; obj.a(); obj.b(); </script> 箭頭函數中的this是在箭…

成都市水資源公報(2000-2022年)

數據年限&#xff1a;2000-2022年&#xff0c;無2009年 數據格式&#xff1a;pdf、word、jpg 數據內容&#xff1a;降水量、地表水資源量、地下水資源量、水資源總量、蓄水狀況、平原區淺層地下水動態、水資源情況分析、供水量、用水量、污水處理、洪澇干旱等

類似李跳跳的軟件有什么,強烈推薦所有安卓手機安裝!!!

今天阿星分享一款讓安卓手機更順滑的神器——智慧島。你問我李跳跳&#xff1f;由于大家都知道的原因&#xff0c;那是個曾經讓廣告無處遁形的神兵利器&#xff0c;可惜現在它已經退休了。不過別擔心&#xff0c;智慧島接過了接力棒&#xff0c;繼續為我們的安卓體驗保駕護航。…

Raccon:更好防側信道攻擊的后量子簽名方案

1. 引言 安全社區已經開發出了一些出色的加密算法&#xff0c;這些算法非常安全&#xff0c;但最終&#xff0c;所有的數據都會被存儲在硅和金屬中&#xff0c;而入侵者越來越多地會在那里放置監視器來破解密鑰。 破解加密密鑰通常涉及暴力破解方法或利用實施過程中的缺陷。然…