-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:szuprefix/vue-django
- Loading branch information
Showing
8 changed files
with
118 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<div> | ||
<el-timeline :reverse="$attrs.reverse"> | ||
<el-timeline-item | ||
v-for="(m, i) in messages" | ||
:key="i" | ||
:timestamp="m.timestamp"> | ||
{{m.status}} {{m.text}} | ||
</el-timeline-item> | ||
</el-timeline> | ||
</div> | ||
</template> | ||
<script> | ||
import progress from './progress' | ||
import {parseTime} from '../../utils/filters' | ||
export default{ | ||
props: { | ||
task: Object | ||
}, | ||
data () { | ||
return { | ||
messages: [] | ||
} | ||
}, | ||
components: {}, | ||
created () { | ||
progress(this.task, {progress: this.onProgress}).then((rs) => { | ||
this.$emit('done', rs) | ||
}) | ||
}, | ||
methods: { | ||
onProgress(m) { | ||
this.messages.push({...m, timestamp: parseTime(new Date(), '{h}:{i}:{s}')}) | ||
} | ||
}, | ||
computed: {} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Created by denishuang on 2018/3/12. | ||
*/ | ||
export default function (task, context) { | ||
let sm = { | ||
'PENDING': '排队中', | ||
'STARTED': '开始执行', | ||
'RETRY': '重试', | ||
'SUCCESS': '任务成功', | ||
'FAILURE': '任务失败', | ||
...context.status | ||
} | ||
let progress = context.progress || function () {} | ||
let promise = new Promise((resolve, reject) => { | ||
let s = task.status | ||
let ps = s.split(' ') | ||
// progress({status:sm[ps[0]], text: ps[1]}) | ||
let protocal = location.protocol === "https:" ? "wss" : "ws" | ||
let url = `${protocal}://${location.host}/api/common/async_result/${task.id}/` | ||
let ws = new WebSocket(url) | ||
ws.onload = function () { | ||
console.log('websocket conneted.') | ||
} | ||
ws.onmessage = (e) => { | ||
let rs = JSON.parse(e.data) | ||
if (rs.task_id !== task.id) { | ||
console.log(`got other task id , ignore: ${rs.task_id}`) | ||
return | ||
} | ||
ps = rs.status.split(' ') | ||
progress({status:sm[ps[0]] || ps[0], text: ps[1]}) | ||
console.log(rs) | ||
if (['SUCCESS', 'FAILURE'].includes(rs.status)) { | ||
ws.close() | ||
ws = null | ||
if (rs.status === 'SUCCESS') { | ||
resolve(rs) | ||
} else if (rs.status === 'FAILURE') { | ||
reject({code: 500, msg: rs.result, asyncResult: rs}) | ||
} | ||
} | ||
} | ||
|
||
}) | ||
return promise | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters