fix: add error tip (#137)
This commit is contained in:
@@ -15,7 +15,7 @@ import { onBeforeMount, onMounted, ref, watch } from 'vue'
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
export const useDownload = defineStore('download', (store) => {
|
export const useDownload = defineStore('download', (store) => {
|
||||||
const { toast, confirm } = useToast()
|
const { toast, confirm, wrapperToastError } = useToast()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
const taskList = ref<DownloadTask[]>([])
|
const taskList = ref<DownloadTask[]>([])
|
||||||
@@ -29,20 +29,24 @@ export const useDownload = defineStore('download', (store) => {
|
|||||||
downloadProgress: `${bytesToSize(downloadedSize)} / ${bytesToSize(totalSize)}`,
|
downloadProgress: `${bytesToSize(downloadedSize)} / ${bytesToSize(totalSize)}`,
|
||||||
downloadSpeed: `${bytesToSize(bps)}/s`,
|
downloadSpeed: `${bytesToSize(bps)}/s`,
|
||||||
pauseTask() {
|
pauseTask() {
|
||||||
request(`/download/${item.taskId}`, {
|
wrapperToastError(async () =>
|
||||||
method: 'PUT',
|
request(`/download/${item.taskId}`, {
|
||||||
body: JSON.stringify({
|
method: 'PUT',
|
||||||
status: 'pause',
|
body: JSON.stringify({
|
||||||
|
status: 'pause',
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
})
|
)()
|
||||||
},
|
},
|
||||||
resumeTask: () => {
|
resumeTask: () => {
|
||||||
request(`/download/${item.taskId}`, {
|
wrapperToastError(async () =>
|
||||||
method: 'PUT',
|
request(`/download/${item.taskId}`, {
|
||||||
body: JSON.stringify({
|
method: 'PUT',
|
||||||
status: 'resume',
|
body: JSON.stringify({
|
||||||
|
status: 'resume',
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
})
|
)()
|
||||||
},
|
},
|
||||||
deleteTask: () => {
|
deleteTask: () => {
|
||||||
confirm.require({
|
confirm.require({
|
||||||
@@ -59,9 +63,11 @@ export const useDownload = defineStore('download', (store) => {
|
|||||||
severity: 'danger',
|
severity: 'danger',
|
||||||
},
|
},
|
||||||
accept: () => {
|
accept: () => {
|
||||||
request(`/download/${item.taskId}`, {
|
wrapperToastError(async () =>
|
||||||
method: 'DELETE',
|
request(`/download/${item.taskId}`, {
|
||||||
})
|
method: 'DELETE',
|
||||||
|
}),
|
||||||
|
)()
|
||||||
},
|
},
|
||||||
reject: () => {},
|
reject: () => {},
|
||||||
})
|
})
|
||||||
@@ -71,21 +77,12 @@ export const useDownload = defineStore('download', (store) => {
|
|||||||
return task
|
return task
|
||||||
}
|
}
|
||||||
|
|
||||||
const refresh = async () => {
|
const refresh = wrapperToastError(async () => {
|
||||||
return request('/download/task')
|
return request('/download/task').then((resData: DownloadTaskOptions[]) => {
|
||||||
.then((resData: DownloadTaskOptions[]) => {
|
taskList.value = resData.map((item) => createTaskItem(item))
|
||||||
taskList.value = resData.map((item) => createTaskItem(item))
|
return taskList.value
|
||||||
return taskList.value
|
})
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
|
||||||
toast.add({
|
|
||||||
severity: 'error',
|
|
||||||
summary: 'Error',
|
|
||||||
detail: err.message ?? 'Failed to refresh download task list',
|
|
||||||
life: 15000,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
api.addEventListener('reconnected', () => {
|
api.addEventListener('reconnected', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user