feat: 实现剧本创作与拆解前端工作台
This commit is contained in:
1 parent
edc003443f
commit
2ee6f049f6
56 files changed
+7597
-2
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { reactive } from 'vue'
|
||||
import { errorMessage } from '../../lib/http'
|
||||
|
||||
/** 当前浏览器会话中的操作状态;切换路由不会丢失长请求。 */
|
||||
export interface Operation {
|
||||
pending: boolean
|
||||
label: string
|
||||
error: string
|
||||
notice: string
|
||||
}
|
||||
|
||||
/** 按项目而非 graph 上锁,防止改写剧本与拆解同时提交。 */
|
||||
const operations = reactive<Record<string, Operation>>({})
|
||||
|
||||
/** 取得项目操作状态,不向浏览器持久化虚假的后台运行状态。 */
|
||||
export function getOperation(projectId: string): Operation {
|
||||
return (operations[projectId] ??= { pending: false, label: '', error: '', notice: '' })
|
||||
}
|
||||
|
||||
/** 只提交一次;断网不自动重试,后台是否已执行由刷新后的 checkpoint 确认。 */
|
||||
export async function runOperation(projectId: string, label: string, action: () => Promise<unknown>) {
|
||||
const operation = getOperation(projectId)
|
||||
if (operation.pending) return false
|
||||
Object.assign(operation, { pending: true, label, error: '', notice: '' })
|
||||
try {
|
||||
await action()
|
||||
operation.notice = '请求已返回,正在重新读取后端状态;最终结果以下方记录为准。'
|
||||
return true
|
||||
} catch (error) {
|
||||
operation.error = errorMessage(error)
|
||||
return false
|
||||
} finally {
|
||||
operation.pending = false
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user