i更新
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { prescriptionEsignConfig, type PrescriptionEsignConfig } from '@/api/tcm'
|
||||
|
||||
/** A failed capability lookup must not silently switch a prescription to handwritten signing. */
|
||||
export function usePrescriptionEsignConfig() {
|
||||
const config = ref<PrescriptionEsignConfig | null>(null)
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
let request: Promise<boolean> | null = null
|
||||
|
||||
function load(): Promise<boolean> {
|
||||
if (request) return request
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
request = prescriptionEsignConfig()
|
||||
.then((value) => {
|
||||
if (typeof value?.enabled !== 'boolean' || !['sandbox', 'production'].includes(value.environment)) {
|
||||
throw new Error('Invalid signing configuration')
|
||||
}
|
||||
config.value = value
|
||||
return true
|
||||
})
|
||||
.catch(() => {
|
||||
config.value = null
|
||||
error.value = '签署配置加载失败,请重试后保存处方'
|
||||
return false
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
request = null
|
||||
})
|
||||
return request
|
||||
}
|
||||
|
||||
return {
|
||||
config,
|
||||
enabled: computed(() => config.value?.enabled === true),
|
||||
ready: computed(() => config.value !== null),
|
||||
loading,
|
||||
error,
|
||||
load
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user