forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostTaskDialog.vue
More file actions
127 lines (111 loc) · 3.27 KB
/
Copy pathPostTaskDialog.vue
File metadata and controls
127 lines (111 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<script setup lang="ts">
import type { Post } from '@md/shared/types'
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
declare global {
interface Window {
$cose: any
}
}
const props = defineProps<{
post: Post
open: boolean
}>()
const emit = defineEmits([`update:open`])
const dialogVisible = computed({
get: () => props.open,
set: value => emit(`update:open`, value),
})
const taskStatus = ref<any>(null)
const submitting = ref(false)
async function startPost() {
if (!props.post)
return
const taskData = {
post: {
title: props.post.title,
content: props.post.content,
markdown: props.post.markdown,
thumb: props.post.thumb,
desc: props.post.desc,
},
accounts: props.post.accounts.filter(a => a.checked),
}
const onProgress = (newStatus: any) => {
taskStatus.value = newStatus
}
const onComplete = () => {
submitting.value = false
}
try {
window.$cose?.addTask(taskData, onProgress, onComplete)
}
catch (error) {
console.error(`发布失败:`, error)
}
}
watch(() => props.open, (newVal) => {
if (newVal) {
startPost()
}
})
</script>
<template>
<Dialog v-model:open="dialogVisible">
<DialogContent>
<DialogHeader>
<DialogTitle>提交发布任务</DialogTitle>
</DialogHeader>
<div class="mt-4">
<div v-if="!taskStatus" class="py-4 text-center">
等待发布..
</div>
<div v-else class="max-h-[400px] flex flex-col overflow-y-auto">
<div
v-for="account in taskStatus?.accounts"
:key="account.uid + account.displayName"
class="border-b py-4 last:border-b-0"
>
<div class="mb-2 flex items-center gap-2">
<img
v-if="account.icon"
:src="account.icon"
class="object-cover h-5 w-5"
alt=""
>
<span>{{ account.title }} - {{ account.displayName || account.home }}</span>
</div>
<div
class="w-full flex-1 gap-2 overflow-auto pl-7 text-sm" :class="{
'text-yellow-600': account.status === 'uploading',
'text-red-600': account.status === 'failed',
'text-green-600': account.status === 'done',
}"
>
<template v-if="account.status === 'uploading'">
{{ account.msg || '发布中' }}
</template>
<template v-if="account.status === 'failed'">
同步失败, 错误内容:{{ account.error }}
</template>
<template v-if="account.status === 'done' && account.editResp">
同步成功
<a
v-if="account.type !== 'wordpress' && account.editResp"
:href="account.editResp.draftLink"
class="ml-2 text-blue-500 hover:underline"
referrerPolicy="no-referrer"
target="_blank" rel="noopener noreferrer"
>查看草稿</a>
</template>
</div>
</div>
</div>
</div>
</DialogContent>
</Dialog>
</template>
<style scoped>
.account-item {
margin-bottom: 1rem;
}
</style>