hookehuyr

fix 图片重复上传问题处理

...@@ -109,7 +109,7 @@ const uuid = () => { ...@@ -109,7 +109,7 @@ const uuid = () => {
109 return uuid; 109 return uuid;
110 }; 110 };
111 111
112 -const uploadQiniu = async (file, token, filename) => { 112 +const uploadQiniu = async (file, token, filename, md5) => {
113 let formData = new FormData(); 113 let formData = new FormData();
114 formData.append("file", file); // 通过append向form对象添加数据 114 formData.append("file", file); // 通过append向form对象添加数据
115 formData.append("token", token); 115 formData.append("token", token);
...@@ -126,8 +126,9 @@ const uploadQiniu = async (file, token, filename) => { ...@@ -126,8 +126,9 @@ const uploadQiniu = async (file, token, filename) => {
126 if (filekey) { 126 if (filekey) {
127 // 保存图片 127 // 保存图片
128 const { data } = await saveFileAPI({ 128 const { data } = await saveFileAPI({
129 + filename,
129 filekey, 130 filekey,
130 - hash, 131 + hash: md5,
131 format: image_info.format, 132 format: image_info.format,
132 height: image_info.height, 133 height: image_info.height,
133 width: image_info.width, 134 width: image_info.width,
...@@ -140,7 +141,6 @@ const uploadQiniu = async (file, token, filename) => { ...@@ -140,7 +141,6 @@ const uploadQiniu = async (file, token, filename) => {
140 const handleUpload = async (files) => { 141 const handleUpload = async (files) => {
141 // 上传图片流程 142 // 上传图片流程
142 loading.value = true; 143 loading.value = true;
143 - // let imgUrl = "";
144 // 获取HASH值 144 // 获取HASH值
145 // const hash = getEtag(files.content); 145 // const hash = getEtag(files.content);
146 return new Promise((resolve, reject) => { 146 return new Promise((resolve, reject) => {
...@@ -156,14 +156,22 @@ const handleUpload = async (files) => { ...@@ -156,14 +156,22 @@ const handleUpload = async (files) => {
156 // 获取七牛token 156 // 获取七牛token
157 const filename = 157 const filename =
158 "uploadForm/" + formCode + "/" + uuid() + "." + files.file.name.split(".")[1]; 158 "uploadForm/" + formCode + "/" + uuid() + "." + files.file.name.split(".")[1];
159 - const { token, key, code } = await qiniuTokenAPI({ 159 + const getToken = await qiniuTokenAPI({
160 name: filename, 160 name: filename,
161 hash: md5, 161 hash: md5,
162 }); 162 });
163 // 文件上传七牛云 163 // 文件上传七牛云
164 - files.status = "uploading"; 164 + let imgUrl = "";
165 - files.message = "上传中..."; 165 + // 第一次上传
166 - const imgUrl = await uploadQiniu(files.file, token, filename); 166 + if (getToken.token) {
167 + files.status = "uploading";
168 + files.message = "上传中...";
169 + imgUrl = await uploadQiniu(files.file, getToken.token, filename, md5);
170 + }
171 + // 重复上传
172 + if (getToken.data) {
173 + imgUrl = getToken.data;
174 + }
167 resolve(imgUrl); 175 resolve(imgUrl);
168 }, 176 },
169 (process) => { 177 (process) => {
......