Changeset 76e46d7 in uz
- Timestamp:
- 2022.10.08 18:53:06 (2 years ago)
- Branches:
- master
- Parents:
- d45005e
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UploadTest.vue
rd45005e r76e46d7 98 98 <br /> 99 99 {{ progress.length }} / {{ current.length }} / {{ queue.length }} 100 <br />101 <button @click='abort()'>abort</button>102 100 <b>errors:</b> <span v-for='error in errors'>{{ error.file.name }}</span> 103 101 <b>progress:</b> <div v-for='item in progress'>{{ item }}</div> -
src/UploadZone.vue
rd45005e r76e46d7 3 3 import { ref, computed, defineProps, withDefaults, defineEmits, getCurrentInstance, defineExpose, watch, nextTick } from 'vue' 4 4 5 import $ from 'jQuery'5 import axios from 'axios' 6 6 7 7 interface Props { … … 56 56 }>() 57 57 58 let abort_controller: any = null 59 58 60 const do_emit = (code: string, ... args: any[]) => { 59 61 // @ts-ignore … … 93 95 for(const file of evt.dataTransfer.files) 94 96 files.push(file) 95 else 97 else // XXX elem click 96 98 for(const file of evt.target.files) 97 99 files.push(file) … … 134 136 if(state.value != State.s_wait) 135 137 return 138 139 try { 140 abort_controller = new AbortController() 141 } 142 catch { 143 } 136 144 137 145 do_emit('upload:start', [files]) … … 205 213 cur_file += 1 206 214 207 $.ajax({ 215 const options = { 216 method: 'post', 208 217 url: props.target, 209 type: 'POST',210 218 data: fd, 211 contentType: false, 212 processData: false, 213 xhr: (): any => { 214 const xhr = new window.XMLHttpRequest() 215 216 xhr.upload.addEventListener('progress', (evt): void => { 217 current.value.forEach((item) => { 218 if(item.file === cur) { 219 item.current = evt.loaded 220 item.total = evt.total 221 } 222 }) 223 do_emit('upload:progress', progress.value, current.value, queue.value) 219 onUploadProgress: (evt: any) => { 220 if(aborted && abort_controller) 221 abort_controller.abort() 222 223 current.value.forEach((item) => { 224 if(item.file === cur) { 225 item.current = evt.loaded 226 item.total = evt.total 227 } 224 228 }) 225 229 226 return xhr230 do_emit('upload:progress', progress.value, current.value, queue.value) 227 231 } 228 }) 229 .then((res: any) => { 232 } as any 233 234 if(abort_controller) 235 options.signal = abort_controller.signal 236 237 axios(options) 238 .then((res) => { 230 239 current.value = current.value.filter((item) => { 231 240 return item.file !== cur … … 234 243 do_emit('upload:progress', progress.value, current.value, queue.value) 235 244 236 progress.value.push(res )237 results.value.push(res )245 progress.value.push(res.data) 246 results.value.push(res.data) 238 247 239 248 cur_jobs -= 1 … … 242 251 if(props.autoReset || props.autoReset === '') { 243 252 state.value = State.s_idle 244 files = [] 253 files = [] // # XXX can drop w/o reset 245 254 do_emit('files:clear', []) 246 255 } … … 255 264 256 265 if(cur_file == files.length && !cur_jobs) { 257 files = [] 266 files = [] // XXX can drop w/o reset 258 267 do_emit('files:clear', []) 259 268 … … 279 288 start_job() 280 289 }) 281 .catch((err: any) => { 290 .catch((err) => { 291 if(aborted && err.name == 'CanceledError') { 292 state.value = State.s_aborted 293 return err 294 } 295 282 296 if(props.keepGoing || props.keepGoing === '') { 283 297 current.value = current.value.filter((item) => { … … 286 300 287 301 errors.value.push({ 288 error: err ,302 error: err.response, 289 303 file: cur 290 304 }) 291 305 292 do_emit('upload:error', err )306 do_emit('upload:error', err.response) 293 307 294 308 cur_jobs -= 1 … … 305 319 else { 306 320 state.value = State.s_error 307 error.value = err 308 do_emit('upload:error', err )321 error.value = err.response 322 do_emit('upload:error', err.response) 309 323 } 310 324 })
Note:
See TracChangeset
for help on using the changeset viewer.