chore: 项目基线(基于 WeKnora 定制版,整理文件忽略规则)
This commit is contained in:
commit
9097ee699d
5769 files changed
+1446466
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { getDeploymentCapabilities } from '@/api/system'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import {
|
||||
isDeploymentCapabilitySupported,
|
||||
type DeploymentCapabilityKey,
|
||||
type DeploymentCapabilityMap,
|
||||
} from '@/config/deploymentCapabilities'
|
||||
|
||||
export const useDeploymentCapabilitiesStore = defineStore('deploymentCapabilities', () => {
|
||||
const edition = ref('')
|
||||
const capabilities = ref<DeploymentCapabilityMap>({})
|
||||
const loaded = ref(false)
|
||||
const loadError = ref('')
|
||||
let loadingPromise: Promise<void> | null = null
|
||||
|
||||
const ensureLoaded = async (force = false): Promise<void> => {
|
||||
if (loaded.value && !force) return
|
||||
if (loadingPromise) return loadingPromise
|
||||
|
||||
loadingPromise = (async () => {
|
||||
try {
|
||||
const response = await getDeploymentCapabilities()
|
||||
edition.value = response.data?.edition || ''
|
||||
capabilities.value = response.data?.capabilities || {}
|
||||
loadError.value = ''
|
||||
} catch (error) {
|
||||
// 能力探测失败时保持 fail-open;权限仍由后端路由最终校验。
|
||||
capabilities.value = {}
|
||||
loadError.value = error instanceof Error ? error.message : String(error)
|
||||
} finally {
|
||||
loaded.value = true
|
||||
loadingPromise = null
|
||||
}
|
||||
})()
|
||||
|
||||
return loadingPromise
|
||||
}
|
||||
|
||||
const isSupported = (key?: DeploymentCapabilityKey) => {
|
||||
const authStore = useAuthStore()
|
||||
return isDeploymentCapabilitySupported(capabilities.value, key, {
|
||||
liteMode: authStore.isLiteMode,
|
||||
edition: edition.value,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
edition,
|
||||
capabilities,
|
||||
loaded,
|
||||
loadError,
|
||||
ensureLoaded,
|
||||
isSupported,
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user