feat(short-drama-agent-front): 完善主体身份骨架屏与交互反馈

This commit is contained in:
GJ committed 2026-10-11 17:23:14 +08:00
1 parent 5fa1c251a9
commit dd0bd79a35
19 files changed
+1552 -419

No files matched your search

+25 -5
View File
@@ -5,14 +5,24 @@ import { AppDialog } from '../../components/ui'
/** 耗费模型额度或覆盖结果的动作必须经过明确确认。 */
const props = defineProps<{
/** 操作名称。 */
label: string
/** 确认前的操作说明。 */
description: string
/** 前置条件未满足时禁止操作。 */
disabled?: boolean
/** 当前操作请求是否仍在执行。 */
loading?: boolean
/** 是否需要确认后台任务停止。 */
acknowledgement?: boolean
/** 是否使用主要操作样式。 */
primary?: boolean
}>()
/** 用户明确确认操作后通知调用方。 */
const emit = defineEmits<{ confirm: [] }>()
/** 当前确认弹窗的可见状态。 */
const open = ref(false)
/** 用户是否确认任务与费用。 */
const acknowledged = ref(false)
/** 取消后重新打开,或确认目标改变,都必须重新确认任务与费用。 */
@@ -22,7 +32,7 @@ watch([open, () => props.label, () => props.description], () => {
/** 发出事件后关闭弹窗,操作状态由项目级锁负责。 */
function confirm() {
if (props.disabled || (props.acknowledgement && !acknowledged.value)) return
if (props.disabled || props.loading || (props.acknowledgement && !acknowledged.value)) return
emit('confirm')
open.value = false
acknowledged.value = false
@@ -34,9 +44,15 @@ function confirm() {
<!-- 稳定的根元素承接调用方间距;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
><NButton
:type="primary ? 'primary' : 'default'"
:disabled="disabled || loading"
:loading="loading"
:aria-label="label"
:aria-busy="!!loading"
@click="open = true"
>{{ label }}</NButton
></template
>
<NCheckbox
v-model:checked="acknowledged"
@@ -46,7 +62,11 @@ function confirm() {
>
<div class="dialog-footer mt-6">
<NButton @click="open = false">取消</NButton
><NButton :disabled="disabled || (acknowledgement && !acknowledged)" @click="confirm" type="primary">
><NButton
:disabled="disabled || loading || (acknowledgement && !acknowledged)"
@click="confirm"
type="primary"
>
确认{{ label }}</NButton
>
</div>
+35 -5
View File
@@ -4,13 +4,28 @@ import { hasActiveWorkflowExecution } from './execution'
/** 当前浏览器会话中的操作状态;切换路由不会丢失长请求。 */
export interface Operation {
/** 项目请求或后台任务是否仍在执行。 */
pending: boolean
/** 当前操作名称。 */
label: string
/** 请求失败原因。 */
error: string
/** 已确认的操作结果提示。 */
notice: string
/** 结果的实际语义;未指定时由工作区使用默认反馈。 */
noticeType: OperationNotice['type'] | null
/** 可执行的失败恢复入口。 */
recovery: OperationRecovery | null
}
/** 操作结果的临时消息,不将 HTTP 成功直接当作业务校验通过。 */
export interface OperationNotice {
/** 用户可理解的结果描述。 */
content: string
/** 成功、任务提交或业务校验未通过。 */
type: 'success' | 'info' | 'warning'
}
/** 失败后的可执行恢复位置;仅保留当前浏览器会话内的真实上下文。 */
export type OperationRecovery = {
target: 'keyframe'
@@ -42,19 +57,34 @@ export function getOperation(projectId: string): Operation {
label: '',
error: '',
notice: '',
noticeType: null,
recovery: null
}
return operations[projectId]
}
/** 只提交一次;断网不自动重试,后台是否已执行由刷新后的 checkpoint 确认。 */
export async function runOperation(projectId: string, label: string, action: () => Promise<unknown>) {
/**
* 只提交一次,并按真实业务回执生成反馈;断网不自动重试。
* @param projectId 当前项目编号
* @param label 操作名称
* @param action 提交请求并核对响应的操作
* @param feedback 固定反馈或从真实响应中取得的反馈
* @returns 请求及响应核对是否成功,不代表业务校验通过
*/
export async function runOperation<T>(
projectId: string,
label: string,
action: () => Promise<T>,
feedback?: OperationNotice | ((result: T) => OperationNotice)
) {
const operation = getOperation(projectId)
if (operation.pending) return false
Object.assign(operation, { pending: true, label, error: '', notice: '', recovery: null })
Object.assign(operation, { pending: true, label, error: '', notice: '', noticeType: null, recovery: null })
try {
await action()
operation.notice = '请求已返回,正在重新读取后端状态;最终结果以下方记录为准。'
const result = await action()
const notice = typeof feedback === 'function' ? feedback(result) : feedback
operation.noticeType = notice?.type ?? null
operation.notice = notice?.content ?? '请求已返回,正在重新读取后端状态;最终结果以下方记录为准。'
return true
} catch (error) {
operation.error = errorMessage(error)