2025-12-18 13:50:39 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<AppLayout>
|
2025-12-27 10:50:25 +08:00
|
|
|
|
<TablePageLayout>
|
|
|
|
|
|
<template #actions>
|
|
|
|
|
|
<div class="flex justify-end gap-3">
|
|
|
|
|
|
<button
|
2025-12-20 10:48:42 +08:00
|
|
|
|
@click="loadCodes"
|
|
|
|
|
|
:disabled="loading"
|
|
|
|
|
|
class="btn btn-secondary"
|
|
|
|
|
|
:title="t('common.refresh')"
|
|
|
|
|
|
>
|
refactor(frontend): 完成所有组件的内联SVG统一替换为Icon组件
- 扩展 Icon.vue 组件,新增 60+ 图标路径
- 导航类: arrowRight, arrowLeft, arrowUp, arrowDown, chevronUp, externalLink
- 状态类: checkCircle, xCircle, exclamationCircle, exclamationTriangle, infoCircle
- 用户类: user, userCircle, userPlus, users
- 文档类: document, clipboard, copy, inbox
- 操作类: download, upload, filter, sort
- 安全类: key, lock, shield
- UI类: menu, calendar, home, terminal, gift, creditCard, mail
- 数据类: chartBar, trendingUp, database, cube
- 其他: bolt, sparkles, cloud, server, sun, moon, book 等
- 重构 56 个 Vue 组件,用 Icon 组件替换内联 SVG
- 净减少约 2200 行代码
- 提升代码可维护性和一致性
- 统一图标样式和尺寸管理
2026-01-05 20:22:48 +08:00
|
|
|
|
<Icon name="refresh" size="md" :class="loading ? 'animate-spin' : ''" />
|
2025-12-20 10:48:42 +08:00
|
|
|
|
</button>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<button @click="showGenerateDialog = true" class="btn btn-primary">
|
2025-12-18 13:50:39 +08:00
|
|
|
|
{{ t('admin.redeem.generateCodes') }}
|
|
|
|
|
|
</button>
|
2025-12-27 10:50:25 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
2025-12-27 10:50:25 +08:00
|
|
|
|
<template #filters>
|
|
|
|
|
|
<div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
|
|
|
|
|
<div class="max-w-md flex-1">
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<input
|
|
|
|
|
|
v-model="searchQuery"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
:placeholder="t('admin.redeem.searchCodes')"
|
|
|
|
|
|
class="input"
|
|
|
|
|
|
@input="handleSearch"
|
|
|
|
|
|
/>
|
2025-12-27 10:50:25 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="flex gap-2">
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<Select
|
|
|
|
|
|
v-model="filters.type"
|
|
|
|
|
|
:options="filterTypeOptions"
|
|
|
|
|
|
class="w-36"
|
|
|
|
|
|
@change="loadCodes"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<Select
|
|
|
|
|
|
v-model="filters.status"
|
|
|
|
|
|
:options="filterStatusOptions"
|
|
|
|
|
|
class="w-36"
|
|
|
|
|
|
@change="loadCodes"
|
|
|
|
|
|
/>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<button @click="handleExportCodes" class="btn btn-secondary">
|
2025-12-18 13:50:39 +08:00
|
|
|
|
{{ t('admin.redeem.exportCsv') }}
|
|
|
|
|
|
</button>
|
2025-12-27 10:50:25 +08:00
|
|
|
|
</div>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</div>
|
2025-12-27 10:50:25 +08:00
|
|
|
|
</template>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
2025-12-27 10:50:25 +08:00
|
|
|
|
<template #table>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<DataTable :columns="columns" :data="codes" :loading="loading">
|
|
|
|
|
|
<template #cell-code="{ value }">
|
|
|
|
|
|
<div class="flex items-center space-x-2">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<code class="font-mono text-sm text-gray-900 dark:text-gray-100">{{ value }}</code>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<button
|
|
|
|
|
|
@click="copyToClipboard(value)"
|
|
|
|
|
|
:class="[
|
|
|
|
|
|
'flex items-center transition-colors',
|
2025-12-25 08:41:36 -08:00
|
|
|
|
copiedCode === value
|
|
|
|
|
|
? 'text-green-500'
|
|
|
|
|
|
: 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
]"
|
|
|
|
|
|
:title="copiedCode === value ? t('admin.redeem.copied') : t('keys.copyToClipboard')"
|
|
|
|
|
|
>
|
refactor(frontend): 完成所有组件的内联SVG统一替换为Icon组件
- 扩展 Icon.vue 组件,新增 60+ 图标路径
- 导航类: arrowRight, arrowLeft, arrowUp, arrowDown, chevronUp, externalLink
- 状态类: checkCircle, xCircle, exclamationCircle, exclamationTriangle, infoCircle
- 用户类: user, userCircle, userPlus, users
- 文档类: document, clipboard, copy, inbox
- 操作类: download, upload, filter, sort
- 安全类: key, lock, shield
- UI类: menu, calendar, home, terminal, gift, creditCard, mail
- 数据类: chartBar, trendingUp, database, cube
- 其他: bolt, sparkles, cloud, server, sun, moon, book 等
- 重构 56 个 Vue 组件,用 Icon 组件替换内联 SVG
- 净减少约 2200 行代码
- 提升代码可维护性和一致性
- 统一图标样式和尺寸管理
2026-01-05 20:22:48 +08:00
|
|
|
|
<Icon v-if="copiedCode !== value" name="copy" size="sm" :stroke-width="2" />
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<svg v-else class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
|
<path
|
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
|
stroke-linejoin="round"
|
|
|
|
|
|
stroke-width="2"
|
|
|
|
|
|
d="M5 13l4 4L19 7"
|
|
|
|
|
|
/>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</svg>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #cell-type="{ value }">
|
|
|
|
|
|
<span
|
|
|
|
|
|
:class="[
|
|
|
|
|
|
'badge',
|
2025-12-25 08:41:36 -08:00
|
|
|
|
value === 'balance'
|
|
|
|
|
|
? 'badge-success'
|
|
|
|
|
|
: value === 'subscription'
|
|
|
|
|
|
? 'badge-warning'
|
|
|
|
|
|
: 'badge-primary'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
]"
|
|
|
|
|
|
>
|
2026-01-04 20:49:34 +08:00
|
|
|
|
{{ t('admin.redeem.types.' + value) }}
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #cell-value="{ value, row }">
|
|
|
|
|
|
<span class="text-sm font-medium text-gray-900 dark:text-white">
|
|
|
|
|
|
<template v-if="row.type === 'balance'">${{ value.toFixed(2) }}</template>
|
|
|
|
|
|
<template v-else-if="row.type === 'subscription'">
|
2026-01-04 20:49:34 +08:00
|
|
|
|
{{ row.validity_days || 30 }} {{ t('admin.redeem.days') }}
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<span v-if="row.group" class="ml-1 text-xs text-gray-500 dark:text-gray-400"
|
|
|
|
|
|
>({{ row.group.name }})</span
|
|
|
|
|
|
>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else>{{ value }}</template>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #cell-status="{ value }">
|
|
|
|
|
|
<span
|
|
|
|
|
|
:class="[
|
|
|
|
|
|
'badge',
|
2025-12-25 08:41:36 -08:00
|
|
|
|
value === 'unused'
|
|
|
|
|
|
? 'badge-success'
|
|
|
|
|
|
: value === 'used'
|
|
|
|
|
|
? 'badge-gray'
|
|
|
|
|
|
: 'badge-danger'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
]"
|
|
|
|
|
|
>
|
2026-01-04 21:00:10 +08:00
|
|
|
|
{{ t('admin.redeem.status.' + value) }}
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #cell-used_by="{ value }">
|
|
|
|
|
|
<span class="text-sm text-gray-500 dark:text-dark-400">
|
|
|
|
|
|
{{ value ? t('admin.redeem.userPrefix', { id: value }) : '-' }}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #cell-used_at="{ value }">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<span class="text-sm text-gray-500 dark:text-dark-400">{{
|
2025-12-27 10:50:25 +08:00
|
|
|
|
value ? formatDateTime(value) : '-'
|
2025-12-25 08:41:36 -08:00
|
|
|
|
}}</span>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #cell-actions="{ row }">
|
|
|
|
|
|
<div class="flex items-center space-x-2">
|
|
|
|
|
|
<button
|
|
|
|
|
|
v-if="row.status === 'unused'"
|
|
|
|
|
|
@click="handleDelete(row)"
|
2025-12-27 16:05:16 +08:00
|
|
|
|
class="flex flex-col items-center gap-0.5 rounded-lg p-1.5 text-gray-500 transition-colors hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20 dark:hover:text-red-400"
|
2025-12-18 13:50:39 +08:00
|
|
|
|
>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
|
<path
|
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
|
stroke-linejoin="round"
|
|
|
|
|
|
stroke-width="2"
|
|
|
|
|
|
d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
|
|
|
|
|
|
/>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</svg>
|
2025-12-27 16:05:16 +08:00
|
|
|
|
<span class="text-xs">{{ t('common.delete') }}</span>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</button>
|
|
|
|
|
|
<span v-else class="text-gray-400 dark:text-dark-500">-</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</DataTable>
|
2025-12-27 10:50:25 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #pagination>
|
|
|
|
|
|
<Pagination
|
|
|
|
|
|
v-if="pagination.total > 0"
|
|
|
|
|
|
:page="pagination.page"
|
|
|
|
|
|
:total="pagination.total"
|
|
|
|
|
|
:page-size="pagination.page_size"
|
|
|
|
|
|
@update:page="handlePageChange"
|
2025-12-28 01:00:06 +08:00
|
|
|
|
@update:pageSize="handlePageSizeChange"
|
2025-12-27 10:50:25 +08:00
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Batch Actions -->
|
|
|
|
|
|
<div v-if="filters.status === 'unused'" class="flex justify-end">
|
|
|
|
|
|
<button @click="showDeleteUnusedDialog = true" class="btn btn-danger">
|
|
|
|
|
|
{{ t('admin.redeem.deleteAllUnused') }}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</TablePageLayout>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- Delete Confirmation Dialog -->
|
|
|
|
|
|
<ConfirmDialog
|
|
|
|
|
|
:show="showDeleteDialog"
|
|
|
|
|
|
:title="t('admin.redeem.deleteCode')"
|
|
|
|
|
|
:message="t('admin.redeem.deleteCodeConfirm')"
|
|
|
|
|
|
:confirm-text="t('common.delete')"
|
|
|
|
|
|
:cancel-text="t('common.cancel')"
|
|
|
|
|
|
danger
|
|
|
|
|
|
@confirm="confirmDelete"
|
|
|
|
|
|
@cancel="showDeleteDialog = false"
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Delete Unused Codes Dialog -->
|
|
|
|
|
|
<ConfirmDialog
|
|
|
|
|
|
:show="showDeleteUnusedDialog"
|
|
|
|
|
|
:title="t('admin.redeem.deleteAllUnused')"
|
|
|
|
|
|
:message="t('admin.redeem.deleteAllUnusedConfirm')"
|
|
|
|
|
|
:confirm-text="t('admin.redeem.deleteAll')"
|
|
|
|
|
|
:cancel-text="t('common.cancel')"
|
|
|
|
|
|
danger
|
|
|
|
|
|
@confirm="confirmDeleteUnused"
|
|
|
|
|
|
@cancel="showDeleteUnusedDialog = false"
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Generate Codes Dialog -->
|
|
|
|
|
|
<Teleport to="body">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<div v-if="showGenerateDialog" class="fixed inset-0 z-50 flex items-center justify-center">
|
|
|
|
|
|
<div class="fixed inset-0 bg-black/50" @click="showGenerateDialog = false"></div>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<div
|
2025-12-25 08:41:36 -08:00
|
|
|
|
class="relative z-10 w-full max-w-md rounded-xl bg-white p-6 shadow-xl dark:bg-dark-800"
|
|
|
|
|
|
>
|
|
|
|
|
|
<h2 class="mb-4 text-lg font-semibold text-gray-900 dark:text-white">
|
|
|
|
|
|
{{ t('admin.redeem.generateCodesTitle') }}
|
|
|
|
|
|
</h2>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<form @submit.prevent="handleGenerateCodes" class="space-y-4">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label class="input-label">{{ t('admin.redeem.codeType') }}</label>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<Select v-model="generateForm.type" :options="typeOptions" />
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<!-- 余额/并发类型:显示数值输入 -->
|
2026-01-29 16:29:59 +08:00
|
|
|
|
<div v-if="generateForm.type !== 'subscription' && generateForm.type !== 'invitation'">
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<label class="input-label">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
{{
|
|
|
|
|
|
generateForm.type === 'balance'
|
|
|
|
|
|
? t('admin.redeem.amount')
|
|
|
|
|
|
: t('admin.redeem.columns.value')
|
|
|
|
|
|
}}
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
v-model.number="generateForm.value"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
:step="generateForm.type === 'balance' ? '0.01' : '1'"
|
|
|
|
|
|
:min="generateForm.type === 'balance' ? '0.01' : '1'"
|
|
|
|
|
|
required
|
|
|
|
|
|
class="input"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2026-01-29 16:29:59 +08:00
|
|
|
|
<!-- 邀请码类型:显示提示信息 -->
|
|
|
|
|
|
<div v-if="generateForm.type === 'invitation'" class="rounded-lg bg-blue-50 p-3 dark:bg-blue-900/20">
|
|
|
|
|
|
<p class="text-sm text-blue-700 dark:text-blue-300">
|
|
|
|
|
|
{{ t('admin.redeem.invitationHint') }}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<!-- 订阅类型:显示分组选择和有效天数 -->
|
|
|
|
|
|
<template v-if="generateForm.type === 'subscription'">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label class="input-label">{{ t('admin.redeem.selectGroup') }}</label>
|
|
|
|
|
|
<Select
|
|
|
|
|
|
v-model="generateForm.group_id"
|
|
|
|
|
|
:options="subscriptionGroupOptions"
|
|
|
|
|
|
:placeholder="t('admin.redeem.selectGroupPlaceholder')"
|
2026-01-20 15:02:48 +08:00
|
|
|
|
>
|
|
|
|
|
|
<template #selected="{ option }">
|
|
|
|
|
|
<GroupBadge
|
|
|
|
|
|
v-if="option"
|
|
|
|
|
|
:name="(option as unknown as GroupOption).label"
|
|
|
|
|
|
:platform="(option as unknown as GroupOption).platform"
|
|
|
|
|
|
:subscription-type="(option as unknown as GroupOption).subscriptionType"
|
|
|
|
|
|
:rate-multiplier="(option as unknown as GroupOption).rate"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<span v-else class="text-gray-400">{{
|
|
|
|
|
|
t('admin.redeem.selectGroupPlaceholder')
|
|
|
|
|
|
}}</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template #option="{ option, selected }">
|
|
|
|
|
|
<GroupOptionItem
|
|
|
|
|
|
:name="(option as unknown as GroupOption).label"
|
|
|
|
|
|
:platform="(option as unknown as GroupOption).platform"
|
|
|
|
|
|
:subscription-type="(option as unknown as GroupOption).subscriptionType"
|
|
|
|
|
|
:rate-multiplier="(option as unknown as GroupOption).rate"
|
|
|
|
|
|
:description="(option as unknown as GroupOption).description"
|
|
|
|
|
|
:selected="selected"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</Select>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label class="input-label">{{ t('admin.redeem.validityDays') }}</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
v-model.number="generateForm.validity_days"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
min="1"
|
|
|
|
|
|
max="365"
|
|
|
|
|
|
required
|
|
|
|
|
|
class="input"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label class="input-label">{{ t('admin.redeem.count') }}</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
v-model.number="generateForm.count"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
min="1"
|
|
|
|
|
|
max="100"
|
|
|
|
|
|
required
|
|
|
|
|
|
class="input"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="flex justify-end gap-3 pt-2">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<button type="button" @click="showGenerateDialog = false" class="btn btn-secondary">
|
2025-12-18 13:50:39 +08:00
|
|
|
|
{{ t('common.cancel') }}
|
|
|
|
|
|
</button>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<button type="submit" :disabled="generating" class="btn btn-primary">
|
2025-12-18 13:50:39 +08:00
|
|
|
|
{{ generating ? t('admin.redeem.generating') : t('admin.redeem.generate') }}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Teleport>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Generated Codes Result Dialog -->
|
|
|
|
|
|
<Teleport to="body">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<div v-if="showResultDialog" class="fixed inset-0 z-50 flex items-center justify-center p-4">
|
|
|
|
|
|
<div class="fixed inset-0 bg-black/50" @click="closeResultDialog"></div>
|
|
|
|
|
|
<div class="relative z-10 w-full max-w-lg rounded-xl bg-white shadow-xl dark:bg-dark-800">
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<!-- Header -->
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<div
|
|
|
|
|
|
class="flex items-center justify-between border-b border-gray-200 px-5 py-4 dark:border-dark-600"
|
|
|
|
|
|
>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<div class="flex items-center gap-3">
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<div
|
|
|
|
|
|
class="flex h-10 w-10 items-center justify-center rounded-full bg-green-100 dark:bg-green-900/30"
|
|
|
|
|
|
>
|
|
|
|
|
|
<svg
|
|
|
|
|
|
class="h-5 w-5 text-green-600 dark:text-green-400"
|
|
|
|
|
|
fill="none"
|
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
|
>
|
|
|
|
|
|
<path
|
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
|
stroke-linejoin="round"
|
|
|
|
|
|
stroke-width="2"
|
|
|
|
|
|
d="M5 13l4 4L19 7"
|
|
|
|
|
|
/>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</svg>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<h2 class="text-base font-semibold text-gray-900 dark:text-white">
|
|
|
|
|
|
{{ t('admin.redeem.generatedSuccessfully') }}
|
|
|
|
|
|
</h2>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<p class="text-sm text-gray-500 dark:text-gray-400">
|
|
|
|
|
|
{{ t('admin.redeem.codesCreated', { count: generatedCodes.length }) }}
|
|
|
|
|
|
</p>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<button
|
|
|
|
|
|
@click="closeResultDialog"
|
2025-12-25 08:41:36 -08:00
|
|
|
|
class="rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-dark-700 dark:hover:text-gray-300"
|
2025-12-18 13:50:39 +08:00
|
|
|
|
>
|
refactor(frontend): 完成所有组件的内联SVG统一替换为Icon组件
- 扩展 Icon.vue 组件,新增 60+ 图标路径
- 导航类: arrowRight, arrowLeft, arrowUp, arrowDown, chevronUp, externalLink
- 状态类: checkCircle, xCircle, exclamationCircle, exclamationTriangle, infoCircle
- 用户类: user, userCircle, userPlus, users
- 文档类: document, clipboard, copy, inbox
- 操作类: download, upload, filter, sort
- 安全类: key, lock, shield
- UI类: menu, calendar, home, terminal, gift, creditCard, mail
- 数据类: chartBar, trendingUp, database, cube
- 其他: bolt, sparkles, cloud, server, sun, moon, book 等
- 重构 56 个 Vue 组件,用 Icon 组件替换内联 SVG
- 净减少约 2200 行代码
- 提升代码可维护性和一致性
- 统一图标样式和尺寸管理
2026-01-05 20:22:48 +08:00
|
|
|
|
<Icon name="x" size="md" :stroke-width="2" />
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<!-- Content -->
|
|
|
|
|
|
<div class="p-5">
|
|
|
|
|
|
<div class="relative">
|
|
|
|
|
|
<textarea
|
|
|
|
|
|
readonly
|
|
|
|
|
|
:value="generatedCodesText"
|
|
|
|
|
|
:style="{ height: textareaHeight }"
|
2025-12-25 08:41:36 -08:00
|
|
|
|
class="w-full resize-none rounded-lg border border-gray-200 bg-gray-50 p-3 font-mono text-sm text-gray-800 focus:outline-none dark:border-dark-600 dark:bg-dark-700 dark:text-gray-200"
|
2025-12-18 13:50:39 +08:00
|
|
|
|
></textarea>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<!-- Footer -->
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<div
|
|
|
|
|
|
class="flex justify-end gap-2 rounded-b-xl border-t border-gray-200 bg-gray-50 px-5 py-4 dark:border-dark-600 dark:bg-dark-700/50"
|
|
|
|
|
|
>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
<button
|
|
|
|
|
|
@click="copyGeneratedCodes"
|
|
|
|
|
|
:class="[
|
|
|
|
|
|
'btn flex items-center gap-2 transition-all',
|
|
|
|
|
|
copiedAll ? 'btn-success' : 'btn-secondary'
|
|
|
|
|
|
]"
|
|
|
|
|
|
>
|
refactor(frontend): 完成所有组件的内联SVG统一替换为Icon组件
- 扩展 Icon.vue 组件,新增 60+ 图标路径
- 导航类: arrowRight, arrowLeft, arrowUp, arrowDown, chevronUp, externalLink
- 状态类: checkCircle, xCircle, exclamationCircle, exclamationTriangle, infoCircle
- 用户类: user, userCircle, userPlus, users
- 文档类: document, clipboard, copy, inbox
- 操作类: download, upload, filter, sort
- 安全类: key, lock, shield
- UI类: menu, calendar, home, terminal, gift, creditCard, mail
- 数据类: chartBar, trendingUp, database, cube
- 其他: bolt, sparkles, cloud, server, sun, moon, book 等
- 重构 56 个 Vue 组件,用 Icon 组件替换内联 SVG
- 净减少约 2200 行代码
- 提升代码可维护性和一致性
- 统一图标样式和尺寸管理
2026-01-05 20:22:48 +08:00
|
|
|
|
<Icon v-if="!copiedAll" name="copy" size="sm" :stroke-width="2" />
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<svg v-else class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
|
<path
|
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
|
stroke-linejoin="round"
|
|
|
|
|
|
stroke-width="2"
|
|
|
|
|
|
d="M5 13l4 4L19 7"
|
|
|
|
|
|
/>
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</svg>
|
|
|
|
|
|
{{ copiedAll ? t('admin.redeem.copied') : t('admin.redeem.copyAll') }}
|
|
|
|
|
|
</button>
|
2025-12-25 08:41:36 -08:00
|
|
|
|
<button @click="downloadGeneratedCodes" class="btn btn-primary flex items-center gap-2">
|
refactor(frontend): 完成所有组件的内联SVG统一替换为Icon组件
- 扩展 Icon.vue 组件,新增 60+ 图标路径
- 导航类: arrowRight, arrowLeft, arrowUp, arrowDown, chevronUp, externalLink
- 状态类: checkCircle, xCircle, exclamationCircle, exclamationTriangle, infoCircle
- 用户类: user, userCircle, userPlus, users
- 文档类: document, clipboard, copy, inbox
- 操作类: download, upload, filter, sort
- 安全类: key, lock, shield
- UI类: menu, calendar, home, terminal, gift, creditCard, mail
- 数据类: chartBar, trendingUp, database, cube
- 其他: bolt, sparkles, cloud, server, sun, moon, book 等
- 重构 56 个 Vue 组件,用 Icon 组件替换内联 SVG
- 净减少约 2200 行代码
- 提升代码可维护性和一致性
- 统一图标样式和尺寸管理
2026-01-05 20:22:48 +08:00
|
|
|
|
<Icon name="download" size="sm" :stroke-width="2" />
|
2025-12-18 13:50:39 +08:00
|
|
|
|
{{ t('admin.redeem.download') }}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Teleport>
|
|
|
|
|
|
</AppLayout>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-01-29 16:29:59 +08:00
|
|
|
|
import { ref, reactive, computed, onMounted, onUnmounted, watch } from 'vue'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
|
import { useAppStore } from '@/stores/app'
|
2025-12-27 15:16:52 +08:00
|
|
|
|
import { useClipboard } from '@/composables/useClipboard'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
import { adminAPI } from '@/api/admin'
|
2025-12-27 10:50:25 +08:00
|
|
|
|
import { formatDateTime } from '@/utils/format'
|
2026-01-20 15:02:48 +08:00
|
|
|
|
import type { RedeemCode, RedeemCodeType, Group, GroupPlatform, SubscriptionType } from '@/types'
|
2025-12-18 14:26:55 +08:00
|
|
|
|
import type { Column } from '@/components/common/types'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
import AppLayout from '@/components/layout/AppLayout.vue'
|
2025-12-27 10:50:25 +08:00
|
|
|
|
import TablePageLayout from '@/components/layout/TablePageLayout.vue'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
import DataTable from '@/components/common/DataTable.vue'
|
|
|
|
|
|
import Pagination from '@/components/common/Pagination.vue'
|
|
|
|
|
|
import ConfirmDialog from '@/components/common/ConfirmDialog.vue'
|
|
|
|
|
|
import Select from '@/components/common/Select.vue'
|
2026-01-20 15:02:48 +08:00
|
|
|
|
import GroupBadge from '@/components/common/GroupBadge.vue'
|
|
|
|
|
|
import GroupOptionItem from '@/components/common/GroupOptionItem.vue'
|
refactor(frontend): 完成所有组件的内联SVG统一替换为Icon组件
- 扩展 Icon.vue 组件,新增 60+ 图标路径
- 导航类: arrowRight, arrowLeft, arrowUp, arrowDown, chevronUp, externalLink
- 状态类: checkCircle, xCircle, exclamationCircle, exclamationTriangle, infoCircle
- 用户类: user, userCircle, userPlus, users
- 文档类: document, clipboard, copy, inbox
- 操作类: download, upload, filter, sort
- 安全类: key, lock, shield
- UI类: menu, calendar, home, terminal, gift, creditCard, mail
- 数据类: chartBar, trendingUp, database, cube
- 其他: bolt, sparkles, cloud, server, sun, moon, book 等
- 重构 56 个 Vue 组件,用 Icon 组件替换内联 SVG
- 净减少约 2200 行代码
- 提升代码可维护性和一致性
- 统一图标样式和尺寸管理
2026-01-05 20:22:48 +08:00
|
|
|
|
import Icon from '@/components/icons/Icon.vue'
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
const appStore = useAppStore()
|
2025-12-27 15:16:52 +08:00
|
|
|
|
const { copyToClipboard: clipboardCopy } = useClipboard()
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
2026-01-20 15:02:48 +08:00
|
|
|
|
interface GroupOption {
|
|
|
|
|
|
value: number
|
|
|
|
|
|
label: string
|
|
|
|
|
|
description: string | null
|
|
|
|
|
|
platform: GroupPlatform
|
|
|
|
|
|
subscriptionType: SubscriptionType
|
|
|
|
|
|
rate: number
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-18 13:50:39 +08:00
|
|
|
|
const showGenerateDialog = ref(false)
|
|
|
|
|
|
const showResultDialog = ref(false)
|
|
|
|
|
|
const generatedCodes = ref<RedeemCode[]>([])
|
|
|
|
|
|
const subscriptionGroups = ref<Group[]>([])
|
|
|
|
|
|
|
|
|
|
|
|
// 订阅类型分组选项
|
|
|
|
|
|
const subscriptionGroupOptions = computed(() => {
|
|
|
|
|
|
return subscriptionGroups.value
|
2025-12-25 08:41:36 -08:00
|
|
|
|
.filter((g) => g.subscription_type === 'subscription')
|
|
|
|
|
|
.map((g) => ({
|
2025-12-18 13:50:39 +08:00
|
|
|
|
value: g.id,
|
2026-01-20 15:02:48 +08:00
|
|
|
|
label: g.name,
|
|
|
|
|
|
description: g.description,
|
|
|
|
|
|
platform: g.platform,
|
|
|
|
|
|
subscriptionType: g.subscription_type,
|
|
|
|
|
|
rate: g.rate_multiplier
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}))
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const generatedCodesText = computed(() => {
|
2025-12-25 08:41:36 -08:00
|
|
|
|
return generatedCodes.value.map((code) => code.code).join('\n')
|
2025-12-18 13:50:39 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const textareaHeight = computed(() => {
|
|
|
|
|
|
const lineCount = generatedCodes.value.length
|
|
|
|
|
|
const lineHeight = 24 // approximate line height in px
|
|
|
|
|
|
const padding = 24 // top + bottom padding
|
|
|
|
|
|
const minHeight = 60
|
|
|
|
|
|
const maxHeight = 240
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const calculatedHeight = Math.min(
|
|
|
|
|
|
Math.max(lineCount * lineHeight + padding, minHeight),
|
|
|
|
|
|
maxHeight
|
|
|
|
|
|
)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
return `${calculatedHeight}px`
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const copiedAll = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
const closeResultDialog = () => {
|
|
|
|
|
|
showResultDialog.value = false
|
|
|
|
|
|
generatedCodes.value = []
|
|
|
|
|
|
copiedAll.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const copyGeneratedCodes = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await navigator.clipboard.writeText(generatedCodesText.value)
|
|
|
|
|
|
copiedAll.value = true
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
copiedAll.value = false
|
|
|
|
|
|
}, 2000)
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
appStore.showError(t('admin.redeem.failedToCopy'))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const downloadGeneratedCodes = () => {
|
|
|
|
|
|
const blob = new Blob([generatedCodesText.value], { type: 'text/plain' })
|
|
|
|
|
|
const url = window.URL.createObjectURL(blob)
|
|
|
|
|
|
const link = document.createElement('a')
|
|
|
|
|
|
link.href = url
|
|
|
|
|
|
link.download = `redeem-codes-${new Date().toISOString().split('T')[0]}.txt`
|
|
|
|
|
|
document.body.appendChild(link)
|
|
|
|
|
|
link.click()
|
|
|
|
|
|
document.body.removeChild(link)
|
|
|
|
|
|
window.URL.revokeObjectURL(url)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const columns = computed<Column[]>(() => [
|
|
|
|
|
|
{ key: 'code', label: t('admin.redeem.columns.code') },
|
|
|
|
|
|
{ key: 'type', label: t('admin.redeem.columns.type'), sortable: true },
|
|
|
|
|
|
{ key: 'value', label: t('admin.redeem.columns.value'), sortable: true },
|
|
|
|
|
|
{ key: 'status', label: t('admin.redeem.columns.status'), sortable: true },
|
|
|
|
|
|
{ key: 'used_by', label: t('admin.redeem.columns.usedBy') },
|
|
|
|
|
|
{ key: 'used_at', label: t('admin.redeem.columns.usedAt'), sortable: true },
|
|
|
|
|
|
{ key: 'actions', label: t('admin.redeem.columns.actions') }
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
const typeOptions = computed(() => [
|
|
|
|
|
|
{ value: 'balance', label: t('admin.redeem.balance') },
|
|
|
|
|
|
{ value: 'concurrency', label: t('admin.redeem.concurrency') },
|
2026-01-29 16:29:59 +08:00
|
|
|
|
{ value: 'subscription', label: t('admin.redeem.subscription') },
|
|
|
|
|
|
{ value: 'invitation', label: t('admin.redeem.invitation') }
|
2025-12-18 13:50:39 +08:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
const filterTypeOptions = computed(() => [
|
|
|
|
|
|
{ value: '', label: t('admin.redeem.allTypes') },
|
|
|
|
|
|
{ value: 'balance', label: t('admin.redeem.balance') },
|
|
|
|
|
|
{ value: 'concurrency', label: t('admin.redeem.concurrency') },
|
2026-01-29 16:29:59 +08:00
|
|
|
|
{ value: 'subscription', label: t('admin.redeem.subscription') },
|
|
|
|
|
|
{ value: 'invitation', label: t('admin.redeem.invitation') }
|
2025-12-18 13:50:39 +08:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
const filterStatusOptions = computed(() => [
|
|
|
|
|
|
{ value: '', label: t('admin.redeem.allStatus') },
|
|
|
|
|
|
{ value: 'unused', label: t('admin.redeem.unused') },
|
2026-01-04 20:51:37 -08:00
|
|
|
|
{ value: 'used', label: t('admin.redeem.used') },
|
|
|
|
|
|
{ value: 'expired', label: t('admin.redeem.status.expired') }
|
2025-12-18 13:50:39 +08:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
const codes = ref<RedeemCode[]>([])
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const generating = ref(false)
|
|
|
|
|
|
const searchQuery = ref('')
|
|
|
|
|
|
const filters = reactive({
|
|
|
|
|
|
type: '',
|
|
|
|
|
|
status: ''
|
|
|
|
|
|
})
|
|
|
|
|
|
const pagination = reactive({
|
|
|
|
|
|
page: 1,
|
|
|
|
|
|
page_size: 20,
|
|
|
|
|
|
total: 0,
|
|
|
|
|
|
pages: 0
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-12-28 01:00:06 +08:00
|
|
|
|
let abortController: AbortController | null = null
|
|
|
|
|
|
|
2025-12-18 13:50:39 +08:00
|
|
|
|
const showDeleteDialog = ref(false)
|
|
|
|
|
|
const showDeleteUnusedDialog = ref(false)
|
|
|
|
|
|
const deletingCode = ref<RedeemCode | null>(null)
|
|
|
|
|
|
const copiedCode = ref<string | null>(null)
|
|
|
|
|
|
|
|
|
|
|
|
const generateForm = reactive({
|
|
|
|
|
|
type: 'balance' as RedeemCodeType,
|
|
|
|
|
|
value: 10,
|
|
|
|
|
|
count: 1,
|
|
|
|
|
|
group_id: null as number | null,
|
|
|
|
|
|
validity_days: 30
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-01-29 16:29:59 +08:00
|
|
|
|
// 监听类型变化,邀请码类型时自动设置 value 为 0
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => generateForm.type,
|
|
|
|
|
|
(newType) => {
|
|
|
|
|
|
if (newType === 'invitation') {
|
|
|
|
|
|
generateForm.value = 0
|
|
|
|
|
|
} else if (generateForm.value === 0) {
|
|
|
|
|
|
generateForm.value = 10
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-12-18 13:50:39 +08:00
|
|
|
|
const loadCodes = async () => {
|
2025-12-28 01:00:06 +08:00
|
|
|
|
if (abortController) {
|
|
|
|
|
|
abortController.abort()
|
|
|
|
|
|
}
|
|
|
|
|
|
const currentController = new AbortController()
|
|
|
|
|
|
abortController = currentController
|
2025-12-18 13:50:39 +08:00
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
2025-12-28 01:00:06 +08:00
|
|
|
|
const response = await adminAPI.redeem.list(
|
|
|
|
|
|
pagination.page,
|
|
|
|
|
|
pagination.page_size,
|
|
|
|
|
|
{
|
|
|
|
|
|
type: filters.type as RedeemCodeType,
|
|
|
|
|
|
status: filters.status as any,
|
|
|
|
|
|
search: searchQuery.value || undefined
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
signal: currentController.signal
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
if (currentController.signal.aborted) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-12-18 13:50:39 +08:00
|
|
|
|
codes.value = response.items
|
|
|
|
|
|
pagination.total = response.total
|
|
|
|
|
|
pagination.pages = response.pages
|
2025-12-28 01:00:06 +08:00
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
if (
|
|
|
|
|
|
currentController.signal.aborted ||
|
|
|
|
|
|
error?.name === 'AbortError' ||
|
|
|
|
|
|
error?.code === 'ERR_CANCELED'
|
|
|
|
|
|
) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-12-18 13:50:39 +08:00
|
|
|
|
appStore.showError(t('admin.redeem.failedToLoad'))
|
|
|
|
|
|
console.error('Error loading redeem codes:', error)
|
|
|
|
|
|
} finally {
|
2025-12-28 01:00:06 +08:00
|
|
|
|
if (abortController === currentController && !currentController.signal.aborted) {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
abortController = null
|
|
|
|
|
|
}
|
2025-12-18 13:50:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let searchTimeout: ReturnType<typeof setTimeout>
|
|
|
|
|
|
const handleSearch = () => {
|
|
|
|
|
|
clearTimeout(searchTimeout)
|
|
|
|
|
|
searchTimeout = setTimeout(() => {
|
|
|
|
|
|
pagination.page = 1
|
|
|
|
|
|
loadCodes()
|
|
|
|
|
|
}, 300)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handlePageChange = (page: number) => {
|
|
|
|
|
|
pagination.page = page
|
|
|
|
|
|
loadCodes()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-28 01:00:06 +08:00
|
|
|
|
const handlePageSizeChange = (pageSize: number) => {
|
|
|
|
|
|
pagination.page_size = pageSize
|
|
|
|
|
|
pagination.page = 1
|
|
|
|
|
|
loadCodes()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-18 13:50:39 +08:00
|
|
|
|
const handleGenerateCodes = async () => {
|
|
|
|
|
|
// 订阅类型必须选择分组
|
|
|
|
|
|
if (generateForm.type === 'subscription' && !generateForm.group_id) {
|
|
|
|
|
|
appStore.showError(t('admin.redeem.groupRequired'))
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
generating.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const result = await adminAPI.redeem.generate(
|
|
|
|
|
|
generateForm.count,
|
|
|
|
|
|
generateForm.type,
|
|
|
|
|
|
generateForm.value,
|
|
|
|
|
|
generateForm.type === 'subscription' ? generateForm.group_id : undefined,
|
|
|
|
|
|
generateForm.type === 'subscription' ? generateForm.validity_days : undefined
|
|
|
|
|
|
)
|
|
|
|
|
|
showGenerateDialog.value = false
|
|
|
|
|
|
generatedCodes.value = result
|
|
|
|
|
|
showResultDialog.value = true
|
|
|
|
|
|
// 重置表单
|
|
|
|
|
|
generateForm.group_id = null
|
|
|
|
|
|
generateForm.validity_days = 30
|
|
|
|
|
|
loadCodes()
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
appStore.showError(error.response?.data?.detail || t('admin.redeem.failedToGenerate'))
|
|
|
|
|
|
console.error('Error generating codes:', error)
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
generating.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const copyToClipboard = async (text: string) => {
|
2025-12-27 15:16:52 +08:00
|
|
|
|
const success = await clipboardCopy(text, t('admin.redeem.copied'))
|
|
|
|
|
|
if (success) {
|
2025-12-18 13:50:39 +08:00
|
|
|
|
copiedCode.value = text
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
copiedCode.value = null
|
|
|
|
|
|
}, 2000)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleExportCodes = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const blob = await adminAPI.redeem.exportCodes({
|
|
|
|
|
|
type: filters.type as RedeemCodeType,
|
|
|
|
|
|
status: filters.status as any
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Create download link
|
|
|
|
|
|
const url = window.URL.createObjectURL(blob)
|
|
|
|
|
|
const link = document.createElement('a')
|
|
|
|
|
|
link.href = url
|
|
|
|
|
|
link.download = `redeem-codes-${new Date().toISOString().split('T')[0]}.csv`
|
|
|
|
|
|
document.body.appendChild(link)
|
|
|
|
|
|
link.click()
|
|
|
|
|
|
document.body.removeChild(link)
|
|
|
|
|
|
window.URL.revokeObjectURL(url)
|
|
|
|
|
|
|
|
|
|
|
|
appStore.showSuccess(t('admin.redeem.codesExported'))
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
appStore.showError(error.response?.data?.detail || t('admin.redeem.failedToExport'))
|
|
|
|
|
|
console.error('Error exporting codes:', error)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleDelete = (code: RedeemCode) => {
|
|
|
|
|
|
deletingCode.value = code
|
|
|
|
|
|
showDeleteDialog.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const confirmDelete = async () => {
|
|
|
|
|
|
if (!deletingCode.value) return
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
await adminAPI.redeem.delete(deletingCode.value.id)
|
|
|
|
|
|
appStore.showSuccess(t('admin.redeem.codeDeleted'))
|
|
|
|
|
|
showDeleteDialog.value = false
|
|
|
|
|
|
deletingCode.value = null
|
|
|
|
|
|
loadCodes()
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
appStore.showError(error.response?.data?.detail || t('admin.redeem.failedToDelete'))
|
|
|
|
|
|
console.error('Error deleting code:', error)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const confirmDeleteUnused = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// Get all unused codes and delete them
|
|
|
|
|
|
const unusedCodesResponse = await adminAPI.redeem.list(1, 1000, { status: 'unused' })
|
2025-12-25 08:41:36 -08:00
|
|
|
|
const unusedCodeIds = unusedCodesResponse.items.map((code) => code.id)
|
2025-12-18 13:50:39 +08:00
|
|
|
|
|
|
|
|
|
|
if (unusedCodeIds.length === 0) {
|
|
|
|
|
|
appStore.showInfo(t('admin.redeem.noUnusedCodes'))
|
|
|
|
|
|
showDeleteUnusedDialog.value = false
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const result = await adminAPI.redeem.batchDelete(unusedCodeIds)
|
|
|
|
|
|
appStore.showSuccess(t('admin.redeem.codesDeleted', { count: result.deleted }))
|
|
|
|
|
|
showDeleteUnusedDialog.value = false
|
|
|
|
|
|
loadCodes()
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
appStore.showError(error.response?.data?.detail || t('admin.redeem.failedToDeleteUnused'))
|
|
|
|
|
|
console.error('Error deleting unused codes:', error)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 加载订阅类型分组
|
|
|
|
|
|
const loadSubscriptionGroups = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const groups = await adminAPI.groups.getAll()
|
|
|
|
|
|
subscriptionGroups.value = groups
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Error loading subscription groups:', error)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
loadCodes()
|
|
|
|
|
|
loadSubscriptionGroups()
|
|
|
|
|
|
})
|
2026-01-09 17:38:45 +08:00
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
clearTimeout(searchTimeout)
|
|
|
|
|
|
abortController?.abort()
|
|
|
|
|
|
})
|
2025-12-18 13:50:39 +08:00
|
|
|
|
</script>
|