fix(前端): 兼容非安全上下文的任务请求键生成
crypto.randomUUID 仅在 HTTPS 或 localhost 下存在,客户内网 以 http://<内网IP> 访问时该 API 为 undefined,而新建任务 对话框在页面挂载即调用,会直接 TypeError 导致整页白屏。 新增 newRequestKey 工具:优先 randomUUID,不可用时降级为 getRandomValues 拼 v4 格式(非安全上下文仍可用)。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
ee801652e3
commit
37eb51513f
2 files changed
+15
-3
No files matched your search
@@ -3,6 +3,7 @@ import { ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import * as api from '@/api/tplus'
|
||||
import { handledError } from '@/utils/error'
|
||||
import { newRequestKey } from '@/utils/uuid'
|
||||
import { entities } from './labels'
|
||||
|
||||
const visible = defineModel<boolean>({ required: true })
|
||||
@@ -11,9 +12,9 @@ const emit = defineEmits<{ created: [batch: api.TPlusDetail] }>()
|
||||
const taskType = ref<api.TaskType>('READ')
|
||||
const selected = ref<api.EntityType[]>(['personnel'])
|
||||
const pending = ref(false)
|
||||
let requestKey = crypto.randomUUID()
|
||||
let requestKey = newRequestKey()
|
||||
// 请求失败后保留键,只有意图改变或成功后才换键。
|
||||
watch([taskType, selected], () => { requestKey = crypto.randomUUID() }, { deep: true, flush: 'sync' })
|
||||
watch([taskType, selected], () => { requestKey = newRequestKey() }, { deep: true, flush: 'sync' })
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
if (pending.value || !props.configured) return
|
||||
@@ -21,7 +22,7 @@ async function submit(): Promise<void> {
|
||||
try {
|
||||
const batch = await api.createTask({ task_type: taskType.value,
|
||||
entity_types: taskType.value === 'AUDIT' ? [] : [...selected.value], request_key: requestKey })
|
||||
requestKey = crypto.randomUUID()
|
||||
requestKey = newRequestKey()
|
||||
visible.value = false
|
||||
ElMessage.success('任务已排队,处理完成后可刷新查看')
|
||||
emit('created', batch)
|
||||
|
||||
Reference in new issue
Block a user