feat: 支持用户专属分组倍率配置
This commit is contained in:
@@ -18,8 +18,18 @@ export async function getAvailable(): Promise<Group[]> {
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user's custom group rate multipliers
|
||||
* @returns Map of group_id to custom rate_multiplier
|
||||
*/
|
||||
export async function getUserGroupRates(): Promise<Record<number, number>> {
|
||||
const { data } = await apiClient.get<Record<number, number> | null>('/groups/rates')
|
||||
return data || {}
|
||||
}
|
||||
|
||||
export const userGroupsAPI = {
|
||||
getAvailable
|
||||
getAvailable,
|
||||
getUserGroupRates
|
||||
}
|
||||
|
||||
export default userGroupsAPI
|
||||
|
||||
@@ -1,59 +1,328 @@
|
||||
<template>
|
||||
<BaseDialog :show="show" :title="t('admin.users.setAllowedGroups')" width="normal" @close="$emit('close')">
|
||||
<div v-if="user" class="space-y-4">
|
||||
<div class="flex items-center gap-3 rounded-xl bg-gray-50 p-4 dark:bg-dark-700">
|
||||
<div class="flex h-10 w-10 items-center justify-center rounded-full bg-primary-100">
|
||||
<span class="text-lg font-medium text-primary-700">{{ user.email.charAt(0).toUpperCase() }}</span>
|
||||
<BaseDialog :show="show" :title="t('admin.users.groupConfig')" width="wide" @close="$emit('close')">
|
||||
<div v-if="user" class="space-y-6">
|
||||
<!-- 用户信息头部 -->
|
||||
<div class="flex items-center gap-4 rounded-2xl bg-gradient-to-r from-primary-50 to-primary-100 p-5 dark:from-primary-900/30 dark:to-primary-800/20">
|
||||
<div class="flex h-14 w-14 items-center justify-center rounded-full bg-white shadow-sm dark:bg-dark-700">
|
||||
<span class="text-2xl font-semibold text-primary-600 dark:text-primary-400">{{ user.email.charAt(0).toUpperCase() }}</span>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<p class="text-lg font-semibold text-gray-900 dark:text-white">{{ user.email }}</p>
|
||||
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">{{ t('admin.users.groupConfigHint', { email: user.email }) }}</p>
|
||||
</div>
|
||||
<p class="font-medium text-gray-900 dark:text-white">{{ user.email }}</p>
|
||||
</div>
|
||||
<div v-if="loading" class="flex justify-center py-8"><svg class="h-8 w-8 animate-spin text-primary-500" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg></div>
|
||||
<div v-else>
|
||||
<p class="mb-3 text-sm text-gray-600">{{ t('admin.users.allowedGroupsHint') }}</p>
|
||||
<div class="max-h-64 space-y-2 overflow-y-auto">
|
||||
<label v-for="group in groups" :key="group.id" class="flex cursor-pointer items-center gap-3 rounded-lg border border-gray-200 p-3 hover:bg-gray-50" :class="{'border-primary-300 bg-primary-50': selectedIds.includes(group.id)}">
|
||||
<input type="checkbox" :value="group.id" v-model="selectedIds" class="h-4 w-4 rounded border-gray-300 text-primary-600" />
|
||||
<div class="flex-1"><p class="font-medium text-gray-900">{{ group.name }}</p><p v-if="group.description" class="truncate text-sm text-gray-500">{{ group.description }}</p></div>
|
||||
<div class="flex items-center gap-2"><span class="badge badge-gray text-xs">{{ group.platform }}</span><span v-if="group.is_exclusive" class="badge badge-purple text-xs">{{ t('admin.groups.exclusive') }}</span></div>
|
||||
</label>
|
||||
|
||||
<!-- 加载状态 -->
|
||||
<div v-if="loading" class="flex justify-center py-12">
|
||||
<svg class="h-10 w-10 animate-spin text-primary-500" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div v-else class="space-y-6">
|
||||
<!-- 专属分组区域 -->
|
||||
<div v-if="exclusiveGroups.length > 0">
|
||||
<div class="mb-3 flex items-center gap-2">
|
||||
<div class="h-1.5 w-1.5 rounded-full bg-purple-500"></div>
|
||||
<h4 class="text-sm font-semibold text-gray-700 dark:text-gray-300">{{ t('admin.users.exclusiveGroups') }}</h4>
|
||||
<span class="text-xs text-gray-400">({{ exclusiveGroupConfigs.filter(c => c.isSelected).length }}/{{ exclusiveGroupConfigs.length }})</span>
|
||||
</div>
|
||||
<div class="grid gap-3">
|
||||
<div
|
||||
v-for="config in exclusiveGroupConfigs"
|
||||
:key="config.groupId"
|
||||
class="group relative overflow-hidden rounded-xl border-2 p-4 transition-all duration-200"
|
||||
:class="config.isSelected
|
||||
? 'border-primary-400 bg-primary-50/50 shadow-sm dark:border-primary-500 dark:bg-primary-900/20'
|
||||
: 'border-gray-200 bg-white hover:border-gray-300 dark:border-dark-600 dark:bg-dark-800 dark:hover:border-dark-500'"
|
||||
>
|
||||
<div class="flex items-center gap-4">
|
||||
<!-- 复选框 -->
|
||||
<div class="flex-shrink-0">
|
||||
<label class="relative flex h-6 w-6 cursor-pointer items-center justify-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="config.isSelected"
|
||||
@change="toggleExclusiveGroup(config.groupId)"
|
||||
class="peer sr-only"
|
||||
/>
|
||||
<div class="h-5 w-5 rounded-md border-2 border-gray-300 transition-all peer-checked:border-primary-500 peer-checked:bg-primary-500 dark:border-dark-500 peer-checked:dark:border-primary-500">
|
||||
<svg v-if="config.isSelected" class="h-full w-full text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- 分组信息 -->
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-base font-semibold text-gray-900 dark:text-white">{{ config.groupName }}</span>
|
||||
<span class="inline-flex items-center rounded-full bg-purple-100 px-2 py-0.5 text-xs font-medium text-purple-700 dark:bg-purple-900/40 dark:text-purple-300">
|
||||
{{ t('admin.groups.exclusive') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-1.5 flex items-center gap-3 text-sm">
|
||||
<span class="inline-flex items-center gap-1 text-gray-500 dark:text-gray-400">
|
||||
<PlatformIcon :platform="config.platform" size="xs" />
|
||||
<span>{{ config.platform }}</span>
|
||||
</span>
|
||||
<span class="text-gray-300 dark:text-dark-500">•</span>
|
||||
<span class="text-gray-500 dark:text-gray-400">
|
||||
{{ t('admin.users.defaultRate') }}: <span class="font-medium text-gray-700 dark:text-gray-300">{{ config.defaultRate }}x</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 专属倍率输入 -->
|
||||
<div class="flex flex-shrink-0 items-center gap-3">
|
||||
<label class="text-sm font-medium text-gray-600 dark:text-gray-400">{{ t('admin.users.customRate') }}</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.001"
|
||||
min="0"
|
||||
:value="config.customRate ?? ''"
|
||||
@input="updateCustomRate(config.groupId, ($event.target as HTMLInputElement).value)"
|
||||
:placeholder="String(config.defaultRate)"
|
||||
class="hide-spinner w-24 rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm font-medium transition-colors focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-dark-500 dark:bg-dark-700 dark:focus:border-primary-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 border-t border-gray-200 pt-4">
|
||||
<label class="flex cursor-pointer items-center gap-3 rounded-lg border border-gray-200 p-3 hover:bg-gray-50" :class="{'border-green-300 bg-green-50': selectedIds.length === 0}">
|
||||
<input type="radio" :checked="selectedIds.length === 0" @change="selectedIds = []" class="h-4 w-4 border-gray-300 text-green-600" />
|
||||
<div class="flex-1"><p class="font-medium text-gray-900">{{ t('admin.users.allowAllGroups') }}</p><p class="text-sm text-gray-500">{{ t('admin.users.allowAllGroupsHint') }}</p></div>
|
||||
</label>
|
||||
|
||||
<!-- 公开分组区域 -->
|
||||
<div v-if="publicGroups.length > 0">
|
||||
<div class="mb-3 flex items-center gap-2">
|
||||
<div class="h-1.5 w-1.5 rounded-full bg-green-500"></div>
|
||||
<h4 class="text-sm font-semibold text-gray-700 dark:text-gray-300">{{ t('admin.users.publicGroups') }}</h4>
|
||||
<span class="text-xs text-gray-400">({{ publicGroupConfigs.length }})</span>
|
||||
</div>
|
||||
<div class="grid gap-3">
|
||||
<div
|
||||
v-for="config in publicGroupConfigs"
|
||||
:key="config.groupId"
|
||||
class="relative overflow-hidden rounded-xl border-2 border-green-200 bg-green-50/50 p-4 dark:border-green-800/50 dark:bg-green-900/10"
|
||||
>
|
||||
<div class="flex items-center gap-4">
|
||||
<!-- 复选框(禁用状态) -->
|
||||
<div class="flex-shrink-0">
|
||||
<div class="flex h-5 w-5 items-center justify-center rounded-md border-2 border-green-400 bg-green-500 dark:border-green-600 dark:bg-green-600">
|
||||
<svg class="h-full w-full text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 分组信息 -->
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-base font-semibold text-gray-900 dark:text-white">{{ config.groupName }}</span>
|
||||
</div>
|
||||
<div class="mt-1.5 flex items-center gap-3 text-sm">
|
||||
<span class="inline-flex items-center gap-1 text-gray-500 dark:text-gray-400">
|
||||
<PlatformIcon :platform="config.platform" size="xs" />
|
||||
<span>{{ config.platform }}</span>
|
||||
</span>
|
||||
<span class="text-gray-300 dark:text-dark-500">•</span>
|
||||
<span class="text-gray-500 dark:text-gray-400">
|
||||
{{ t('admin.users.defaultRate') }}: <span class="font-medium text-gray-700 dark:text-gray-300">{{ config.defaultRate }}x</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 专属倍率输入 -->
|
||||
<div class="flex flex-shrink-0 items-center gap-3">
|
||||
<label class="text-sm font-medium text-gray-600 dark:text-gray-400">{{ t('admin.users.customRate') }}</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.001"
|
||||
min="0"
|
||||
:value="config.customRate ?? ''"
|
||||
@input="updateCustomRate(config.groupId, ($event.target as HTMLInputElement).value)"
|
||||
:placeholder="String(config.defaultRate)"
|
||||
class="hide-spinner w-24 rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm font-medium transition-colors focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-dark-500 dark:bg-dark-700 dark:focus:border-primary-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 无分组提示 -->
|
||||
<div v-if="groups.length === 0" class="flex flex-col items-center justify-center py-12 text-center">
|
||||
<div class="mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-gray-100 dark:bg-dark-700">
|
||||
<svg class="h-8 w-8 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
|
||||
</svg>
|
||||
</div>
|
||||
<p class="text-gray-500 dark:text-gray-400">{{ t('common.noGroupsAvailable') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex justify-end gap-3">
|
||||
<button @click="$emit('close')" class="btn btn-secondary">{{ t('common.cancel') }}</button>
|
||||
<button @click="handleSave" :disabled="submitting" class="btn btn-primary">{{ submitting ? t('common.saving') : t('common.save') }}</button>
|
||||
<button @click="$emit('close')" class="btn btn-secondary px-5">{{ t('common.cancel') }}</button>
|
||||
<button @click="handleSave" :disabled="submitting" class="btn btn-primary px-6">
|
||||
<svg v-if="submitting" class="-ml-1 mr-2 h-4 w-4 animate-spin" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||
</svg>
|
||||
{{ submitting ? t('common.saving') : t('common.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</BaseDialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { ref, watch, computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import { adminAPI } from '@/api/admin'
|
||||
import type { AdminUser, Group } from '@/types'
|
||||
import type { AdminUser, Group, GroupPlatform } from '@/types'
|
||||
import BaseDialog from '@/components/common/BaseDialog.vue'
|
||||
import PlatformIcon from '@/components/common/PlatformIcon.vue'
|
||||
|
||||
const props = defineProps<{ show: boolean, user: AdminUser | null }>()
|
||||
const emit = defineEmits(['close', 'success']); const { t } = useI18n(); const appStore = useAppStore()
|
||||
interface GroupRateConfig {
|
||||
groupId: number
|
||||
groupName: string
|
||||
platform: GroupPlatform
|
||||
isExclusive: boolean
|
||||
defaultRate: number
|
||||
customRate: number | null
|
||||
isSelected: boolean
|
||||
}
|
||||
|
||||
const groups = ref<Group[]>([]); const selectedIds = ref<number[]>([]); const loading = ref(false); const submitting = ref(false)
|
||||
const props = defineProps<{ show: boolean; user: AdminUser | null }>()
|
||||
const emit = defineEmits(['close', 'success'])
|
||||
const { t } = useI18n()
|
||||
const appStore = useAppStore()
|
||||
|
||||
watch(() => props.show, (v) => { if(v && props.user) { selectedIds.value = props.user.allowed_groups || []; load() } })
|
||||
const load = async () => { loading.value = true; try { const res = await adminAPI.groups.list(1, 1000); groups.value = res.items.filter(g => g.subscription_type === 'standard' && g.status === 'active') } catch (error) { console.error('Failed to load groups:', error) } finally { loading.value = false } }
|
||||
const handleSave = async () => {
|
||||
if (!props.user) return; submitting.value = true
|
||||
const groups = ref<Group[]>([])
|
||||
const groupConfigs = ref<GroupRateConfig[]>([])
|
||||
const originalGroupRates = ref<Record<number, number>>({}) // 记录原始专属倍率,用于检测删除
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
|
||||
// 分离专属分组和公开分组
|
||||
const exclusiveGroups = computed(() => groups.value.filter((g) => g.is_exclusive))
|
||||
const publicGroups = computed(() => groups.value.filter((g) => !g.is_exclusive))
|
||||
|
||||
const exclusiveGroupConfigs = computed(() => groupConfigs.value.filter((c) => c.isExclusive))
|
||||
const publicGroupConfigs = computed(() => groupConfigs.value.filter((c) => !c.isExclusive))
|
||||
|
||||
watch(
|
||||
() => props.show,
|
||||
(v) => {
|
||||
if (v && props.user) {
|
||||
load()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const load = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
await adminAPI.users.update(props.user.id, { allowed_groups: selectedIds.value })
|
||||
appStore.showSuccess(t('admin.users.allowedGroupsUpdated')); emit('success'); emit('close')
|
||||
} catch (error) { console.error('Failed to update allowed groups:', error) } finally { submitting.value = false }
|
||||
const res = await adminAPI.groups.list(1, 1000)
|
||||
// 只显示标准类型且活跃的分组
|
||||
groups.value = res.items.filter((g) => g.subscription_type === 'standard' && g.status === 'active')
|
||||
|
||||
// 初始化配置
|
||||
const userAllowedGroups = props.user?.allowed_groups || []
|
||||
const userGroupRates = props.user?.group_rates || {}
|
||||
|
||||
// 保存原始专属倍率,用于检测删除操作
|
||||
originalGroupRates.value = { ...userGroupRates }
|
||||
|
||||
groupConfigs.value = groups.value.map((g) => ({
|
||||
groupId: g.id,
|
||||
groupName: g.name,
|
||||
platform: g.platform,
|
||||
isExclusive: g.is_exclusive,
|
||||
defaultRate: g.rate_multiplier,
|
||||
customRate: userGroupRates[g.id] ?? null,
|
||||
// 专属分组:检查是否在 allowed_groups 中
|
||||
// 公开分组:始终选中
|
||||
isSelected: g.is_exclusive ? userAllowedGroups.includes(g.id) : true,
|
||||
}))
|
||||
} catch (error) {
|
||||
console.error('Failed to load groups:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const toggleExclusiveGroup = (groupId: number) => {
|
||||
const config = groupConfigs.value.find((c) => c.groupId === groupId)
|
||||
if (config && config.isExclusive) {
|
||||
config.isSelected = !config.isSelected
|
||||
}
|
||||
}
|
||||
|
||||
const updateCustomRate = (groupId: number, value: string) => {
|
||||
const config = groupConfigs.value.find((c) => c.groupId === groupId)
|
||||
if (config) {
|
||||
if (value === '' || value === null || value === undefined) {
|
||||
config.customRate = null
|
||||
} else {
|
||||
const numValue = parseFloat(value)
|
||||
config.customRate = isNaN(numValue) ? null : numValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!props.user) return
|
||||
submitting.value = true
|
||||
|
||||
try {
|
||||
// 构建 allowed_groups(仅包含专属分组中被勾选的)
|
||||
const allowedGroups = groupConfigs.value.filter((c) => c.isExclusive && c.isSelected).map((c) => c.groupId)
|
||||
|
||||
// 构建 group_rates
|
||||
// - 有新专属倍率: 设置为该值
|
||||
// - 原本有专属倍率但现在被清空: 设置为 null(表示删除)
|
||||
const groupRates: Record<number, number | null> = {}
|
||||
for (const c of groupConfigs.value) {
|
||||
const hadOriginalRate = originalGroupRates.value[c.groupId] !== undefined
|
||||
|
||||
if (c.customRate !== null) {
|
||||
// 有专属倍率
|
||||
groupRates[c.groupId] = c.customRate
|
||||
} else if (hadOriginalRate) {
|
||||
// 原本有专属倍率,现在被清空,需要显式删除
|
||||
groupRates[c.groupId] = null
|
||||
}
|
||||
}
|
||||
|
||||
await adminAPI.users.update(props.user.id, {
|
||||
allowed_groups: allowedGroups,
|
||||
group_rates: Object.keys(groupRates).length > 0 ? groupRates : undefined,
|
||||
})
|
||||
|
||||
appStore.showSuccess(t('admin.users.groupConfigUpdated'))
|
||||
emit('success')
|
||||
emit('close')
|
||||
} catch (error) {
|
||||
console.error('Failed to update user group config:', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 隐藏数字输入框的箭头按钮 */
|
||||
.hide-spinner::-webkit-outer-spin-button,
|
||||
.hide-spinner::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
.hide-spinner {
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -11,7 +11,14 @@
|
||||
<span class="truncate">{{ name }}</span>
|
||||
<!-- Right side label -->
|
||||
<span v-if="showLabel" :class="labelClass">
|
||||
{{ labelText }}
|
||||
<template v-if="hasCustomRate">
|
||||
<!-- 原倍率删除线 + 专属倍率高亮 -->
|
||||
<span class="line-through opacity-50 mr-0.5">{{ rateMultiplier }}x</span>
|
||||
<span class="font-bold">{{ userRateMultiplier }}x</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ labelText }}
|
||||
</template>
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
@@ -27,6 +34,7 @@ interface Props {
|
||||
platform?: GroupPlatform
|
||||
subscriptionType?: SubscriptionType
|
||||
rateMultiplier?: number
|
||||
userRateMultiplier?: number | null // 用户专属倍率
|
||||
showRate?: boolean
|
||||
daysRemaining?: number | null // 剩余天数(订阅类型时使用)
|
||||
}
|
||||
@@ -34,20 +42,31 @@ interface Props {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
subscriptionType: 'standard',
|
||||
showRate: true,
|
||||
daysRemaining: null
|
||||
daysRemaining: null,
|
||||
userRateMultiplier: null
|
||||
})
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const isSubscription = computed(() => props.subscriptionType === 'subscription')
|
||||
|
||||
// 是否有专属倍率(且与默认倍率不同)
|
||||
const hasCustomRate = computed(() => {
|
||||
return (
|
||||
props.userRateMultiplier !== null &&
|
||||
props.userRateMultiplier !== undefined &&
|
||||
props.rateMultiplier !== undefined &&
|
||||
props.userRateMultiplier !== props.rateMultiplier
|
||||
)
|
||||
})
|
||||
|
||||
// 是否显示右侧标签
|
||||
const showLabel = computed(() => {
|
||||
if (!props.showRate) return false
|
||||
// 订阅类型:显示天数或"订阅"
|
||||
if (isSubscription.value) return true
|
||||
// 标准类型:显示倍率
|
||||
return props.rateMultiplier !== undefined
|
||||
// 标准类型:显示倍率(包括专属倍率)
|
||||
return props.rateMultiplier !== undefined || hasCustomRate.value
|
||||
})
|
||||
|
||||
// Label text
|
||||
@@ -71,7 +90,7 @@ const labelClass = computed(() => {
|
||||
const base = 'px-1.5 py-0.5 rounded text-[10px] font-semibold'
|
||||
|
||||
if (!isSubscription.value) {
|
||||
// Standard: subtle background
|
||||
// Standard: subtle background (不再为专属倍率使用不同的背景色)
|
||||
return `${base} bg-black/10 dark:bg-white/10`
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
:platform="platform"
|
||||
:subscription-type="subscriptionType"
|
||||
:rate-multiplier="rateMultiplier"
|
||||
:user-rate-multiplier="userRateMultiplier"
|
||||
/>
|
||||
<span
|
||||
v-if="description"
|
||||
@@ -39,6 +40,7 @@ interface Props {
|
||||
platform: GroupPlatform
|
||||
subscriptionType?: SubscriptionType
|
||||
rateMultiplier?: number
|
||||
userRateMultiplier?: number | null
|
||||
description?: string | null
|
||||
selected?: boolean
|
||||
showCheckmark?: boolean
|
||||
@@ -47,6 +49,7 @@ interface Props {
|
||||
withDefaults(defineProps<Props>(), {
|
||||
subscriptionType: 'standard',
|
||||
selected: false,
|
||||
showCheckmark: true
|
||||
showCheckmark: true,
|
||||
userRateMultiplier: null
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -849,6 +849,16 @@ export default {
|
||||
allowedGroupsUpdated: 'Allowed groups updated successfully',
|
||||
failedToLoadGroups: 'Failed to load groups',
|
||||
failedToUpdateAllowedGroups: 'Failed to update allowed groups',
|
||||
// User Group Configuration
|
||||
groupConfig: 'User Group Configuration',
|
||||
groupConfigHint: 'Configure custom rate multipliers for user {email} (overrides group defaults)',
|
||||
exclusiveGroups: 'Exclusive Groups',
|
||||
publicGroups: 'Public Groups (Default Available)',
|
||||
defaultRate: 'Default Rate',
|
||||
customRate: 'Custom Rate',
|
||||
useDefaultRate: 'Use Default',
|
||||
customRatePlaceholder: 'Leave empty for default',
|
||||
groupConfigUpdated: 'Group configuration updated successfully',
|
||||
deposit: 'Deposit',
|
||||
withdraw: 'Withdraw',
|
||||
depositAmount: 'Deposit Amount',
|
||||
|
||||
@@ -910,6 +910,16 @@ export default {
|
||||
allowedGroupsUpdated: '允许分组更新成功',
|
||||
failedToLoadGroups: '加载分组列表失败',
|
||||
failedToUpdateAllowedGroups: '更新允许分组失败',
|
||||
// 用户分组配置
|
||||
groupConfig: '用户分组配置',
|
||||
groupConfigHint: '为用户 {email} 配置专属分组倍率(覆盖分组默认倍率)',
|
||||
exclusiveGroups: '专属分组',
|
||||
publicGroups: '公开分组(默认可用)',
|
||||
defaultRate: '默认倍率',
|
||||
customRate: '专属倍率',
|
||||
useDefaultRate: '使用默认',
|
||||
customRatePlaceholder: '留空使用默认',
|
||||
groupConfigUpdated: '分组配置更新成功',
|
||||
deposit: '充值',
|
||||
withdraw: '退款',
|
||||
depositAmount: '充值金额',
|
||||
|
||||
@@ -41,6 +41,8 @@ export interface User {
|
||||
export interface AdminUser extends User {
|
||||
// 管理员备注(普通用户接口不返回)
|
||||
notes: string
|
||||
// 用户专属分组倍率配置 (group_id -> rate_multiplier)
|
||||
group_rates?: Record<number, number>
|
||||
}
|
||||
|
||||
export interface LoginRequest {
|
||||
@@ -966,6 +968,9 @@ export interface UpdateUserRequest {
|
||||
concurrency?: number
|
||||
status?: 'active' | 'disabled'
|
||||
allowed_groups?: number[] | null
|
||||
// 用户专属分组倍率配置 (group_id -> rate_multiplier | null)
|
||||
// null 表示删除该分组的专属倍率
|
||||
group_rates?: Record<number, number | null>
|
||||
}
|
||||
|
||||
export interface ChangePasswordRequest {
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
:platform="row.group.platform"
|
||||
:subscription-type="row.group.subscription_type"
|
||||
:rate-multiplier="row.group.rate_multiplier"
|
||||
:user-rate-multiplier="userGroupRates[row.group.id]"
|
||||
/>
|
||||
<span v-else class="text-sm text-gray-400 dark:text-dark-500">{{
|
||||
t('keys.noGroup')
|
||||
@@ -272,6 +273,7 @@
|
||||
:platform="(option as unknown as GroupOption).platform"
|
||||
:subscription-type="(option as unknown as GroupOption).subscriptionType"
|
||||
:rate-multiplier="(option as unknown as GroupOption).rate"
|
||||
:user-rate-multiplier="(option as unknown as GroupOption).userRate"
|
||||
/>
|
||||
<span v-else class="text-gray-400">{{ t('keys.selectGroup') }}</span>
|
||||
</template>
|
||||
@@ -281,6 +283,7 @@
|
||||
:platform="(option as unknown as GroupOption).platform"
|
||||
:subscription-type="(option as unknown as GroupOption).subscriptionType"
|
||||
:rate-multiplier="(option as unknown as GroupOption).rate"
|
||||
:user-rate-multiplier="(option as unknown as GroupOption).userRate"
|
||||
:description="(option as unknown as GroupOption).description"
|
||||
:selected="selected"
|
||||
/>
|
||||
@@ -667,6 +670,7 @@
|
||||
:platform="option.platform"
|
||||
:subscription-type="option.subscriptionType"
|
||||
:rate-multiplier="option.rate"
|
||||
:user-rate-multiplier="option.userRate"
|
||||
:description="option.description"
|
||||
:selected="
|
||||
selectedKeyForGroup?.group_id === option.value ||
|
||||
@@ -718,6 +722,7 @@ interface GroupOption {
|
||||
label: string
|
||||
description: string | null
|
||||
rate: number
|
||||
userRate: number | null
|
||||
subscriptionType: SubscriptionType
|
||||
platform: GroupPlatform
|
||||
}
|
||||
@@ -742,6 +747,7 @@ const groups = ref<Group[]>([])
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const usageStats = ref<Record<string, BatchApiKeyUsageStats>>({})
|
||||
const userGroupRates = ref<Record<number, number>>({})
|
||||
|
||||
const pagination = ref({
|
||||
page: 1,
|
||||
@@ -825,6 +831,7 @@ const groupOptions = computed(() =>
|
||||
label: group.name,
|
||||
description: group.description,
|
||||
rate: group.rate_multiplier,
|
||||
userRate: userGroupRates.value[group.id] ?? null,
|
||||
subscriptionType: group.subscription_type,
|
||||
platform: group.platform
|
||||
}))
|
||||
@@ -899,6 +906,14 @@ const loadGroups = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadUserGroupRates = async () => {
|
||||
try {
|
||||
userGroupRates.value = await userGroupsAPI.getUserGroupRates()
|
||||
} catch (error) {
|
||||
console.error('Failed to load user group rates:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadPublicSettings = async () => {
|
||||
try {
|
||||
publicSettings.value = await authAPI.getPublicSettings()
|
||||
@@ -1268,6 +1283,7 @@ const closeCcsClientSelect = () => {
|
||||
onMounted(() => {
|
||||
loadApiKeys()
|
||||
loadGroups()
|
||||
loadUserGroupRates()
|
||||
loadPublicSettings()
|
||||
document.addEventListener('click', closeGroupSelector)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user