64 lines
2.2 KiB
Vue
64 lines
2.2 KiB
Vue
<script setup lang="ts">
|
||
import { NButton, NCheckbox } from 'naive-ui'
|
||
import { ref, watch } from 'vue'
|
||
import { AppDialog } from '../../components/ui'
|
||
|
||
/** 耗费模型额度或覆盖结果的动作必须经过明确确认。 */
|
||
const props = defineProps<{
|
||
label: string
|
||
description: string
|
||
disabled?: boolean
|
||
acknowledgement?: boolean
|
||
primary?: boolean
|
||
}>()
|
||
const emit = defineEmits<{ confirm: [] }>()
|
||
const open = ref(false)
|
||
const acknowledged = ref(false)
|
||
|
||
/** 取消后重新打开,或确认目标改变,都必须重新确认任务与费用。 */
|
||
watch([open, () => props.label, () => props.description], () => {
|
||
acknowledged.value = false
|
||
})
|
||
|
||
/** 发出事件后关闭弹窗,操作状态由项目级锁负责。 */
|
||
function confirm() {
|
||
if (props.disabled || (props.acknowledgement && !acknowledged.value)) return
|
||
emit('confirm')
|
||
open.value = false
|
||
acknowledged.value = false
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<span class="confirm-action">
|
||
<!-- 稳定的根元素承接调用方间距;AppDialog 含多个根节点,不能替按钮接收 class。 -->
|
||
<AppDialog v-model:open="open" :title="label" :description="description">
|
||
<template #trigger
|
||
><NButton :type="primary ? 'primary' : 'default'" :disabled="disabled" @click="open = true">{{
|
||
label
|
||
}}</NButton></template
|
||
>
|
||
<NCheckbox
|
||
v-model:checked="acknowledged"
|
||
v-if="acknowledgement"
|
||
class="mt-5 flex items-start gap-3 text-sm leading-6"
|
||
>我已确认后台任务停止,当前没有同项目的生成或拆解任务在运行。</NCheckbox
|
||
>
|
||
<div class="dialog-footer mt-6">
|
||
<NButton @click="open = false">取消</NButton
|
||
><NButton :disabled="disabled || (acknowledgement && !acknowledged)" @click="confirm" type="primary">
|
||
确认{{ label }}</NButton
|
||
>
|
||
</div>
|
||
</AppDialog>
|
||
</span>
|
||
</template>
|
||
|
||
<style>
|
||
/* 本组件专属布局与 Naive 内部结构覆盖。 */
|
||
@reference "../../styles/styles.css";
|
||
.confirm-action {
|
||
@apply inline-flex items-center max-w-full;
|
||
}
|
||
</style>
|