mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-04 00:17:45 +08:00
refactor(users): share access control options
This commit is contained in:
@@ -355,11 +355,10 @@ import {
|
|||||||
import { UserPlus, SquarePen } from 'lucide-vue-next'
|
import { UserPlus, SquarePen } from 'lucide-vue-next'
|
||||||
import { useFormDialog } from '@/composables/useFormDialog'
|
import { useFormDialog } from '@/composables/useFormDialog'
|
||||||
import { MultiSelect } from '@/components/common'
|
import { MultiSelect } from '@/components/common'
|
||||||
import { getProvidersSummary } from '@/api/endpoints/providers'
|
|
||||||
import { getGlobalModels } from '@/api/global-models'
|
|
||||||
import { adminApi } from '@/api/admin'
|
import { adminApi } from '@/api/admin'
|
||||||
import { log } from '@/utils/logger'
|
import { log } from '@/utils/logger'
|
||||||
import { parseNumberInput } from '@/utils/form'
|
import { parseNumberInput } from '@/utils/form'
|
||||||
|
import { useUserAccessControlOptions } from '@/features/users/composables/useUserAccessControlOptions'
|
||||||
import {
|
import {
|
||||||
getPasswordPolicyHint,
|
getPasswordPolicyHint,
|
||||||
getPasswordPolicyPlaceholder,
|
getPasswordPolicyPlaceholder,
|
||||||
@@ -367,10 +366,6 @@ import {
|
|||||||
validatePasswordByPolicy,
|
validatePasswordByPolicy,
|
||||||
type PasswordPolicyLevel,
|
type PasswordPolicyLevel,
|
||||||
} from '@/utils/passwordPolicy'
|
} from '@/utils/passwordPolicy'
|
||||||
import type {
|
|
||||||
ProviderWithEndpointsSummary,
|
|
||||||
GlobalModelResponse,
|
|
||||||
} from '@/api/endpoints/types'
|
|
||||||
|
|
||||||
export interface UserFormData {
|
export interface UserFormData {
|
||||||
id?: string
|
id?: string
|
||||||
@@ -401,29 +396,12 @@ const saving = ref(false)
|
|||||||
const formNonce = ref(createFieldNonce())
|
const formNonce = ref(createFieldNonce())
|
||||||
const passwordPolicyLevel = ref<PasswordPolicyLevel>('weak')
|
const passwordPolicyLevel = ref<PasswordPolicyLevel>('weak')
|
||||||
|
|
||||||
// 选项数据
|
const {
|
||||||
const providers = ref<ProviderWithEndpointsSummary[]>([])
|
providerOptions,
|
||||||
const globalModels = ref<GlobalModelResponse[]>([])
|
apiFormatOptions,
|
||||||
const apiFormats = ref<Array<{ value: string; label: string }>>([])
|
modelOptions,
|
||||||
|
loadAccessControlOptions: loadAccessControlOptionLists,
|
||||||
const providerOptions = computed(() =>
|
} = useUserAccessControlOptions()
|
||||||
providers.value.map((provider) => ({
|
|
||||||
value: provider.id,
|
|
||||||
label: provider.name,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
const apiFormatOptions = computed(() =>
|
|
||||||
apiFormats.value.map((format) => ({
|
|
||||||
value: format.value,
|
|
||||||
label: format.label,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
const modelOptions = computed(() =>
|
|
||||||
globalModels.value.map((model) => ({
|
|
||||||
value: model.name,
|
|
||||||
label: model.name,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
|
|
||||||
// 表单数据
|
// 表单数据
|
||||||
const form = ref({
|
const form = ref({
|
||||||
@@ -547,15 +525,10 @@ const isFormValid = computed(() => {
|
|||||||
// 加载访问控制选项
|
// 加载访问控制选项
|
||||||
async function loadAccessControlOptions(): Promise<void> {
|
async function loadAccessControlOptions(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const [providersResponse, modelsData, formatsData, passwordPolicyResponse] = await Promise.all([
|
const [, passwordPolicyResponse] = await Promise.all([
|
||||||
getProvidersSummary({ page_size: 9999 }),
|
loadAccessControlOptionLists(),
|
||||||
getGlobalModels({ limit: 1000, is_active: true }),
|
|
||||||
adminApi.getApiFormats(),
|
|
||||||
adminApi.getSystemConfig('password_policy_level').catch(() => ({ value: 'weak' })),
|
adminApi.getSystemConfig('password_policy_level').catch(() => ({ value: 'weak' })),
|
||||||
])
|
])
|
||||||
providers.value = providersResponse.items
|
|
||||||
globalModels.value = modelsData.models || []
|
|
||||||
apiFormats.value = formatsData.formats || []
|
|
||||||
passwordPolicyLevel.value = normalizePasswordPolicyLevel(passwordPolicyResponse.value)
|
passwordPolicyLevel.value = normalizePasswordPolicyLevel(passwordPolicyResponse.value)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error('加载访问限制选项失败:', err)
|
log.error('加载访问限制选项失败:', err)
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { getProvidersSummary } from '@/api/endpoints/providers'
|
||||||
|
import { getGlobalModels } from '@/api/global-models'
|
||||||
|
import { adminApi } from '@/api/admin'
|
||||||
|
import type { ProviderWithEndpointsSummary } from '@/api/endpoints/types'
|
||||||
|
import type { GlobalModelResponse } from '@/api/global-models'
|
||||||
|
|
||||||
|
export function useUserAccessControlOptions() {
|
||||||
|
const providers = ref<ProviderWithEndpointsSummary[]>([])
|
||||||
|
const globalModels = ref<GlobalModelResponse[]>([])
|
||||||
|
const apiFormats = ref<Array<{ value: string; label: string }>>([])
|
||||||
|
|
||||||
|
const providerOptions = computed(() =>
|
||||||
|
providers.value.map((provider) => ({
|
||||||
|
value: provider.id,
|
||||||
|
label: provider.name,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
const apiFormatOptions = computed(() =>
|
||||||
|
apiFormats.value.map((format) => ({
|
||||||
|
value: format.value,
|
||||||
|
label: format.label,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
const modelOptions = computed(() =>
|
||||||
|
globalModels.value.map((model) => ({
|
||||||
|
value: model.name,
|
||||||
|
label: model.name,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
async function loadAccessControlOptions(): Promise<void> {
|
||||||
|
const [providersResponse, modelsData, formatsData] = await Promise.all([
|
||||||
|
getProvidersSummary({ page_size: 9999 }),
|
||||||
|
getGlobalModels({ limit: 1000, is_active: true }),
|
||||||
|
adminApi.getApiFormats(),
|
||||||
|
])
|
||||||
|
providers.value = providersResponse.items
|
||||||
|
globalModels.value = modelsData.models || []
|
||||||
|
apiFormats.value = formatsData.formats || []
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
providers,
|
||||||
|
globalModels,
|
||||||
|
apiFormats,
|
||||||
|
providerOptions,
|
||||||
|
apiFormatOptions,
|
||||||
|
modelOptions,
|
||||||
|
loadAccessControlOptions,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user