feat: 删除弹窗预检活动后台任务
This commit is contained in:
1 parent
2bc67e971a
commit
66bbae3630
1 file changed
+20
-5
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, watch } from 'vue'
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { NAlert, NButton, NInput } from 'naive-ui'
|
||||
import { AppDialog } from '../../../components/ui'
|
||||
import { errorMessage } from '../../../lib/http'
|
||||
@@ -11,19 +11,30 @@ const props = defineProps<{ project: Project | null }>()
|
||||
const open = defineModel<boolean>('open', { default: false })
|
||||
const emit = defineEmits<{ deleted: [id: string] }>()
|
||||
const state = reactive({ confirm: '', pending: false, error: '' })
|
||||
const readiness = ref<Awaited<ReturnType<typeof projectsApi.deleteReadiness>> | null>(null)
|
||||
const readinessPending = ref(false)
|
||||
const expected = computed(() => props.project?.title || props.project?.topic || '')
|
||||
const confirmed = computed(() => !!props.project && state.confirm.trim() === expected.value)
|
||||
watch(
|
||||
() => [open.value, props.project?.id],
|
||||
() => {
|
||||
if (!open.value) return
|
||||
async () => {
|
||||
if (!open.value || !props.project) return
|
||||
state.confirm = ''
|
||||
state.error = ''
|
||||
readiness.value = null
|
||||
readinessPending.value = true
|
||||
try {
|
||||
readiness.value = await projectsApi.deleteReadiness(props.project.id)
|
||||
} catch (cause) {
|
||||
state.error = errorMessage(cause)
|
||||
} finally {
|
||||
readinessPending.value = false
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
async function remove() {
|
||||
if (!props.project || state.pending || !confirmed.value) return
|
||||
if (!props.project || state.pending || !confirmed.value || !readiness.value?.canDelete) return
|
||||
const id = props.project.id
|
||||
state.pending = true
|
||||
state.error = ''
|
||||
@@ -44,12 +55,16 @@ async function remove() {
|
||||
<NAlert type="error" :show-icon="false" class="mt-4">
|
||||
会永久删除剧本、主体、身份、形态、分镜、首帧、视频、工作流记录,以及本地 Storage 中属于该项目的图片、视频和上传素材。
|
||||
</NAlert>
|
||||
<NAlert v-if="readinessPending" type="info" :show-icon="false" class="mt-3">正在检查项目后台任务…</NAlert>
|
||||
<NAlert v-else-if="readiness && !readiness.canDelete" type="warning" :show-icon="false" class="mt-3">
|
||||
当前有 {{ readiness.totalActiveTasks }} 个后台任务正在执行,暂不能删除。请等待图片、首帧、视频或工作流任务结束后再试。
|
||||
</NAlert>
|
||||
<NAlert v-if="state.error" type="error" :show-icon="false" class="mt-3">{{ state.error }}</NAlert>
|
||||
<p class="mt-5 text-xs">请输入 <strong>{{ expected }}</strong> 确认删除:</p>
|
||||
<NInput v-model:value="state.confirm" class="mt-2" placeholder="输入项目名称" />
|
||||
<div class="dialog-footer mt-6">
|
||||
<NButton @click="open = false">取消</NButton>
|
||||
<NButton type="error" :loading="state.pending" :disabled="!confirmed" @click="remove">永久删除项目</NButton>
|
||||
<NButton type="error" :loading="state.pending" :disabled="!confirmed || readinessPending || !readiness?.canDelete" @click="remove">永久删除项目</NButton>
|
||||
</div>
|
||||
</AppDialog>
|
||||
</template>
|
||||
Reference in new issue
Block a user