Showing
1 changed file
with
34 additions
and
16 deletions
| ... | @@ -18,7 +18,7 @@ | ... | @@ -18,7 +18,7 @@ |
| 18 | :after-read="afterRead" | 18 | :after-read="afterRead" |
| 19 | :before-delete="beforeDelete" | 19 | :before-delete="beforeDelete" |
| 20 | v-model="fileList" | 20 | v-model="fileList" |
| 21 | - :multiple="item.component_props.multiple" | 21 | + :multiple="true" |
| 22 | /> | 22 | /> |
| 23 | </div> | 23 | </div> |
| 24 | <div class="type-text">上传格式:{{ type_text }}</div> | 24 | <div class="type-text">上传格式:{{ type_text }}</div> |
| ... | @@ -133,20 +133,37 @@ const uploadQiniu = async (file, token, filename) => { | ... | @@ -133,20 +133,37 @@ const uploadQiniu = async (file, token, filename) => { |
| 133 | const handleUpload = async (files) => { | 133 | const handleUpload = async (files) => { |
| 134 | // 上传图片流程 | 134 | // 上传图片流程 |
| 135 | loading.value = true; | 135 | loading.value = true; |
| 136 | + // let imgUrl = ""; | ||
| 136 | // 获取HASH值 | 137 | // 获取HASH值 |
| 137 | - const hash = getEtag(files.content); | 138 | + // const hash = getEtag(files.content); |
| 138 | - // 获取七牛token | 139 | + return new Promise((resolve, reject) => { |
| 139 | - const filename = | 140 | + // 获取MD5值 |
| 140 | - "uploadForm/" + formCode + "/" + uuid() + "." + files.file.name.split(".")[1]; | 141 | + const bmf = new BMF(); |
| 141 | - const { token, key, code } = await qiniuTokenAPI({ | 142 | + bmf.md5( |
| 142 | - name: filename, | 143 | + files.file, |
| 143 | - hash, | 144 | + async (err, md5) => { |
| 145 | + if (err) { | ||
| 146 | + console.log(err); | ||
| 147 | + reject(err); | ||
| 148 | + } | ||
| 149 | + // 获取七牛token | ||
| 150 | + const filename = | ||
| 151 | + "uploadForm/" + formCode + "/" + uuid() + "." + files.file.name.split(".")[1]; | ||
| 152 | + const { token, key, code } = await qiniuTokenAPI({ | ||
| 153 | + name: filename, | ||
| 154 | + hash: md5, | ||
| 155 | + }); | ||
| 156 | + // 文件上传七牛云 | ||
| 157 | + files.status = "uploading"; | ||
| 158 | + files.message = "上传中..."; | ||
| 159 | + const imgUrl = await uploadQiniu(files.file, token, filename); | ||
| 160 | + resolve(imgUrl); | ||
| 161 | + }, | ||
| 162 | + (process) => { | ||
| 163 | + //计算进度 | ||
| 164 | + } | ||
| 165 | + ); | ||
| 144 | }); | 166 | }); |
| 145 | - // 文件上传七牛云 | ||
| 146 | - files.status = "uploading"; | ||
| 147 | - files.message = "上传中..."; | ||
| 148 | - const imgUrl = await uploadQiniu(files.file, token, filename); | ||
| 149 | - return { imgUrl }; | ||
| 150 | }; | 167 | }; |
| 151 | 168 | ||
| 152 | // 多选图片上传遍历 | 169 | // 多选图片上传遍历 |
| ... | @@ -154,7 +171,7 @@ var muliUpload = async (files) => { | ... | @@ -154,7 +171,7 @@ var muliUpload = async (files) => { |
| 154 | for (let item of files) { | 171 | for (let item of files) { |
| 155 | const res = await handleUpload(item); | 172 | const res = await handleUpload(item); |
| 156 | // 上传失败提示 | 173 | // 上传失败提示 |
| 157 | - if (!res.imgUrl.src) { | 174 | + if (!res.src) { |
| 158 | item.status = "failed"; | 175 | item.status = "failed"; |
| 159 | item.message = "上传失败"; | 176 | item.message = "上传失败"; |
| 160 | loading.value = false; | 177 | loading.value = false; |
| ... | @@ -162,7 +179,7 @@ var muliUpload = async (files) => { | ... | @@ -162,7 +179,7 @@ var muliUpload = async (files) => { |
| 162 | item.status = ""; | 179 | item.status = ""; |
| 163 | item.message = ""; | 180 | item.message = ""; |
| 164 | fileList.value.push({ | 181 | fileList.value.push({ |
| 165 | - url: res.imgUrl.src, | 182 | + url: res.src, |
| 166 | isImage: true, | 183 | isImage: true, |
| 167 | }); | 184 | }); |
| 168 | loading.value = false; | 185 | loading.value = false; |
| ... | @@ -175,7 +192,7 @@ const afterRead = async (files) => { | ... | @@ -175,7 +192,7 @@ const afterRead = async (files) => { |
| 175 | // 多张图片上传files是一个数组 | 192 | // 多张图片上传files是一个数组 |
| 176 | muliUpload(files); | 193 | muliUpload(files); |
| 177 | } else { | 194 | } else { |
| 178 | - const { imgUrl } = await handleUpload(files); | 195 | + const imgUrl = await handleUpload(files); |
| 179 | // 上传失败提示 | 196 | // 上传失败提示 |
| 180 | if (!imgUrl.src) { | 197 | if (!imgUrl.src) { |
| 181 | files.status = "failed"; | 198 | files.status = "failed"; |
| ... | @@ -201,6 +218,7 @@ const afterRead = async (files) => { | ... | @@ -201,6 +218,7 @@ const afterRead = async (files) => { |
| 201 | value: fileList.value, | 218 | value: fileList.value, |
| 202 | }; | 219 | }; |
| 203 | emit("active", props.item.value); | 220 | emit("active", props.item.value); |
| 221 | + console.warn(fileList.value); | ||
| 204 | }; | 222 | }; |
| 205 | 223 | ||
| 206 | const beforeDelete = (files) => { | 224 | const beforeDelete = (files) => { | ... | ... |
-
Please register or login to post a comment