Merge pull request #909 from StarryKira/feature/admin-reset-subscription-quota

Feature/管理员可以重置账号额度
This commit is contained in:
Wesley Liddick
2026-03-12 09:26:47 +08:00
committed by GitHub
8 changed files with 303 additions and 0 deletions

View File

@@ -370,6 +370,15 @@
<Icon name="calendar" size="sm" />
<span class="text-xs">{{ t('admin.subscriptions.adjust') }}</span>
</button>
<button
v-if="row.status === 'active'"
@click="handleResetQuota(row)"
:disabled="resettingQuota && resettingSubscription?.id === row.id"
class="flex flex-col items-center gap-0.5 rounded-lg p-1.5 text-gray-500 transition-colors hover:bg-orange-50 hover:text-orange-600 dark:hover:bg-orange-900/20 dark:hover:text-orange-400 disabled:cursor-not-allowed disabled:opacity-50"
>
<Icon name="refresh" size="sm" />
<span class="text-xs">{{ t('admin.subscriptions.resetQuota') }}</span>
</button>
<button
v-if="row.status === 'active'"
@click="handleRevoke(row)"
@@ -618,6 +627,17 @@
@confirm="confirmRevoke"
@cancel="showRevokeDialog = false"
/>
<!-- Reset Quota Confirmation Dialog -->
<ConfirmDialog
:show="showResetQuotaConfirm"
:title="t('admin.subscriptions.resetQuotaTitle')"
:message="t('admin.subscriptions.resetQuotaConfirm', { user: resettingSubscription?.user?.email })"
:confirm-text="t('admin.subscriptions.resetQuota')"
:cancel-text="t('common.cancel')"
@confirm="confirmResetQuota"
@cancel="showResetQuotaConfirm = false"
/>
</AppLayout>
</template>
@@ -812,7 +832,10 @@ const pagination = reactive({
const showAssignModal = ref(false)
const showExtendModal = ref(false)
const showRevokeDialog = ref(false)
const showResetQuotaConfirm = ref(false)
const submitting = ref(false)
const resettingSubscription = ref<UserSubscription | null>(null)
const resettingQuota = ref(false)
const extendingSubscription = ref<UserSubscription | null>(null)
const revokingSubscription = ref<UserSubscription | null>(null)
@@ -1121,6 +1144,29 @@ const confirmRevoke = async () => {
}
}
const handleResetQuota = (subscription: UserSubscription) => {
resettingSubscription.value = subscription
showResetQuotaConfirm.value = true
}
const confirmResetQuota = async () => {
if (!resettingSubscription.value) return
if (resettingQuota.value) return
resettingQuota.value = true
try {
await adminAPI.subscriptions.resetQuota(resettingSubscription.value.id, { daily: true, weekly: true })
appStore.showSuccess(t('admin.subscriptions.quotaResetSuccess'))
showResetQuotaConfirm.value = false
resettingSubscription.value = null
await loadSubscriptions()
} catch (error: any) {
appStore.showError(error.response?.data?.detail || t('admin.subscriptions.failedToResetQuota'))
console.error('Error resetting quota:', error)
} finally {
resettingQuota.value = false
}
}
// Helper functions
const getDaysRemaining = (expiresAt: string): number | null => {
const now = new Date()