Skip to content

Commit ef8f0ed

Browse files
committed
support fileStatusText function to control response
1 parent d3a91e8 commit ef8f0ed

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/components/file.vue

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
},
7171
data () {
7272
return {
73+
response: null,
7374
paused: false,
7475
error: false,
7576
averageSpeed: 0,
@@ -139,7 +140,14 @@
139140
},
140141
statusText () {
141142
const status = this.status
142-
return this.file.uploader.fileStatusText[status] || status
143+
const fileStatusText = this.file.uploader.fileStatusText
144+
let txt = status
145+
if (typeof fileStatusText === 'function') {
146+
txt = fileStatusText(status, this.response)
147+
} else {
148+
txt = fileStatusText[status]
149+
}
150+
return txt || status
143151
},
144152
formatedTimeRemaining () {
145153
const timeRemaining = this.timeRemaining
@@ -189,12 +197,20 @@
189197
this.file.retry()
190198
this._actionCheck()
191199
},
200+
processResponse (message) {
201+
let res = message
202+
try {
203+
res = JSON.parse(message)
204+
} catch (e) {}
205+
this.response = res
206+
},
192207
fileEventsHandler (event, args) {
193208
const rootFile = args[0]
194209
const file = args[1]
195210
const target = this.list ? rootFile : file
196211
if (this.file === target) {
197212
if (this.list && event === 'fileSuccess') {
213+
this.processResponse(args[2])
198214
return
199215
}
200216
this[`_${event}`].apply(this, args)
@@ -208,7 +224,10 @@
208224
this.uploadedSize = this.file.sizeUploaded()
209225
this._actionCheck()
210226
},
211-
_fileSuccess () {
227+
_fileSuccess (rootFile, file, message) {
228+
if (rootFile) {
229+
this.processResponse(message)
230+
}
212231
this._fileProgress()
213232
this.error = false
214233
this.isComplete = true

src/components/uploader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
default: true
4747
},
4848
fileStatusText: {
49-
type: Object,
49+
type: [Object, Function],
5050
default () {
5151
return {
5252
success: 'success',

0 commit comments

Comments
 (0)