Commit 5763f5ce authored by ianshaw's avatar ianshaw
Browse files

style(frontend): 统一 Views 模块代码风格

- 移除语句末尾分号,规范代码格式
- 优化组件结构和类型定义
- 改进视图文档和示例
- 提升代码一致性
parent f79b0f0f
This diff is collapsed.
<template> <template>
<div class="min-h-screen flex items-center justify-center bg-gray-50 dark:bg-dark-950 px-4 relative overflow-hidden"> <div
class="relative flex min-h-screen items-center justify-center overflow-hidden bg-gray-50 px-4 dark:bg-dark-950"
>
<!-- Background Decoration --> <!-- Background Decoration -->
<div class="absolute inset-0 overflow-hidden pointer-events-none"> <div class="pointer-events-none absolute inset-0 overflow-hidden">
<div class="absolute -top-40 -right-40 w-80 h-80 bg-primary-400/10 rounded-full blur-3xl"></div> <div
<div class="absolute -bottom-40 -left-40 w-80 h-80 bg-primary-500/10 rounded-full blur-3xl"></div> class="absolute -right-40 -top-40 h-80 w-80 rounded-full bg-primary-400/10 blur-3xl"
></div>
<div
class="absolute -bottom-40 -left-40 h-80 w-80 rounded-full bg-primary-500/10 blur-3xl"
></div>
</div> </div>
<div class="max-w-md w-full text-center relative z-10"> <div class="relative z-10 w-full max-w-md text-center">
<!-- 404 Display --> <!-- 404 Display -->
<div class="mb-8"> <div class="mb-8">
<div class="relative inline-block"> <div class="relative inline-block">
<span class="text-[12rem] font-bold text-gray-100 dark:text-dark-800 leading-none">404</span> <span class="text-[12rem] font-bold leading-none text-gray-100 dark:text-dark-800"
>404</span
>
<div class="absolute inset-0 flex items-center justify-center"> <div class="absolute inset-0 flex items-center justify-center">
<div class="w-24 h-24 rounded-2xl bg-gradient-to-br from-primary-500 to-primary-600 shadow-lg shadow-primary-500/30 flex items-center justify-center"> <div
<svg class="w-12 h-12 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"> class="flex h-24 w-24 items-center justify-center rounded-2xl bg-gradient-to-br from-primary-500 to-primary-600 shadow-lg shadow-primary-500/30"
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" /> >
<svg
class="h-12 w-12 text-white"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="1.5"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z"
/>
</svg> </svg>
</div> </div>
</div> </div>
...@@ -23,31 +43,43 @@ ...@@ -23,31 +43,43 @@
<!-- Text Content --> <!-- Text Content -->
<div class="mb-8"> <div class="mb-8">
<h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-3"> <h1 class="mb-3 text-2xl font-bold text-gray-900 dark:text-white">Page Not Found</h1>
Page Not Found
</h1>
<p class="text-gray-500 dark:text-dark-400"> <p class="text-gray-500 dark:text-dark-400">
The page you are looking for doesn't exist or has been moved. The page you are looking for doesn't exist or has been moved.
</p> </p>
</div> </div>
<!-- Action Buttons --> <!-- Action Buttons -->
<div class="flex flex-col sm:flex-row gap-3 justify-center"> <div class="flex flex-col justify-center gap-3 sm:flex-row">
<button <button @click="goBack" class="btn btn-secondary">
@click="goBack" <svg
class="btn btn-secondary" class="mr-2 h-5 w-5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="1.5"
> >
<svg class="w-5 h-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"> <path
<path stroke-linecap="round" stroke-linejoin="round" d="M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18" /> stroke-linecap="round"
stroke-linejoin="round"
d="M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"
/>
</svg> </svg>
Go Back Go Back
</button> </button>
<router-link <router-link to="/dashboard" class="btn btn-primary">
to="/dashboard" <svg
class="btn btn-primary" class="mr-2 h-5 w-5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="1.5"
> >
<svg class="w-5 h-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"> <path
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25" /> stroke-linecap="round"
stroke-linejoin="round"
d="M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25"
/>
</svg> </svg>
Go to Dashboard Go to Dashboard
</router-link> </router-link>
...@@ -56,7 +88,10 @@ ...@@ -56,7 +88,10 @@
<!-- Help Link --> <!-- Help Link -->
<p class="mt-8 text-sm text-gray-400 dark:text-dark-500"> <p class="mt-8 text-sm text-gray-400 dark:text-dark-500">
Need help? Need help?
<a href="#" class="text-primary-600 hover:text-primary-500 dark:text-primary-400 dark:hover:text-primary-300 transition-colors"> <a
href="#"
class="text-primary-600 transition-colors hover:text-primary-500 dark:text-primary-400 dark:hover:text-primary-300"
>
Contact support Contact support
</a> </a>
</p> </p>
...@@ -65,11 +100,11 @@ ...@@ -65,11 +100,11 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router'
const router = useRouter(); const router = useRouter()
function goBack(): void { function goBack(): void {
router.back(); router.back()
} }
</script> </script>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -10,23 +10,27 @@ ...@@ -10,23 +10,27 @@
:title="t('common.refresh')" :title="t('common.refresh')"
> >
<svg <svg
:class="['w-5 h-5', loading ? 'animate-spin' : '']" :class="['h-5 w-5', loading ? 'animate-spin' : '']"
fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5" fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="1.5"
> >
<path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99" /> <path
stroke-linecap="round"
stroke-linejoin="round"
d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99"
/>
</svg> </svg>
</button> </button>
<button <button @click="showGenerateDialog = true" class="btn btn-primary">
@click="showGenerateDialog = true"
class="btn btn-primary"
>
{{ t('admin.redeem.generateCodes') }} {{ t('admin.redeem.generateCodes') }}
</button> </button>
</div> </div>
<!-- Filters and Actions --> <!-- Filters and Actions -->
<div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between"> <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
<div class="flex-1 max-w-md"> <div class="max-w-md flex-1">
<input <input
v-model="searchQuery" v-model="searchQuery"
type="text" type="text"
...@@ -48,10 +52,7 @@ ...@@ -48,10 +52,7 @@
class="w-36" class="w-36"
@change="loadCodes" @change="loadCodes"
/> />
<button <button @click="handleExportCodes" class="btn btn-secondary">
@click="handleExportCodes"
class="btn btn-secondary"
>
{{ t('admin.redeem.exportCsv') }} {{ t('admin.redeem.exportCsv') }}
</button> </button>
</div> </div>
...@@ -62,20 +63,38 @@ ...@@ -62,20 +63,38 @@
<DataTable :columns="columns" :data="codes" :loading="loading"> <DataTable :columns="columns" :data="codes" :loading="loading">
<template #cell-code="{ value }"> <template #cell-code="{ value }">
<div class="flex items-center space-x-2"> <div class="flex items-center space-x-2">
<code class="text-sm font-mono text-gray-900 dark:text-gray-100">{{ value }}</code> <code class="font-mono text-sm text-gray-900 dark:text-gray-100">{{ value }}</code>
<button <button
@click="copyToClipboard(value)" @click="copyToClipboard(value)"
:class="[ :class="[
'flex items-center transition-colors', 'flex items-center transition-colors',
copiedCode === value ? 'text-green-500' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300' copiedCode === value
? 'text-green-500'
: 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'
]" ]"
:title="copiedCode === value ? t('admin.redeem.copied') : t('keys.copyToClipboard')" :title="copiedCode === value ? t('admin.redeem.copied') : t('keys.copyToClipboard')"
> >
<svg v-if="copiedCode !== value" class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" /> v-if="copiedCode !== value"
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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
/>
</svg> </svg>
<svg v-else class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <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" /> <path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M5 13l4 4L19 7"
/>
</svg> </svg>
</button> </button>
</div> </div>
...@@ -85,8 +104,11 @@ ...@@ -85,8 +104,11 @@
<span <span
:class="[ :class="[
'badge', 'badge',
value === 'balance' ? 'badge-success' : value === 'balance'
value === 'subscription' ? 'badge-warning' : 'badge-primary' ? 'badge-success'
: value === 'subscription'
? 'badge-warning'
: 'badge-primary'
]" ]"
> >
{{ value }} {{ value }}
...@@ -98,7 +120,9 @@ ...@@ -98,7 +120,9 @@
<template v-if="row.type === 'balance'">${{ value.toFixed(2) }}</template> <template v-if="row.type === 'balance'">${{ value.toFixed(2) }}</template>
<template v-else-if="row.type === 'subscription'"> <template v-else-if="row.type === 'subscription'">
{{ row.validity_days || 30 }}{{ t('admin.redeem.days') }} {{ row.validity_days || 30 }}{{ t('admin.redeem.days') }}
<span v-if="row.group" class="text-gray-500 dark:text-gray-400 text-xs ml-1">({{ row.group.name }})</span> <span v-if="row.group" class="ml-1 text-xs text-gray-500 dark:text-gray-400"
>({{ row.group.name }})</span
>
</template> </template>
<template v-else>{{ value }}</template> <template v-else>{{ value }}</template>
</span> </span>
...@@ -108,9 +132,11 @@ ...@@ -108,9 +132,11 @@
<span <span
:class="[ :class="[
'badge', 'badge',
value === 'unused' ? 'badge-success' : value === 'unused'
value === 'used' ? 'badge-gray' : ? 'badge-success'
'badge-danger' : value === 'used'
? 'badge-gray'
: 'badge-danger'
]" ]"
> >
{{ value }} {{ value }}
...@@ -124,7 +150,9 @@ ...@@ -124,7 +150,9 @@
</template> </template>
<template #cell-used_at="{ value }"> <template #cell-used_at="{ value }">
<span class="text-sm text-gray-500 dark:text-dark-400">{{ value ? formatDate(value) : '-' }}</span> <span class="text-sm text-gray-500 dark:text-dark-400">{{
value ? formatDate(value) : '-'
}}</span>
</template> </template>
<template #cell-actions="{ row }"> <template #cell-actions="{ row }">
...@@ -132,11 +160,16 @@ ...@@ -132,11 +160,16 @@
<button <button
v-if="row.status === 'unused'" v-if="row.status === 'unused'"
@click="handleDelete(row)" @click="handleDelete(row)"
class="p-2 rounded-lg hover:bg-red-50 dark:hover:bg-red-900/20 text-gray-500 hover:text-red-600 dark:hover:text-red-400 transition-colors" class="rounded-lg p-2 text-gray-500 transition-colors hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20 dark:hover:text-red-400"
:title="t('common.delete')" :title="t('common.delete')"
> >
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <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" /> <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"
/>
</svg> </svg>
</button> </button>
<span v-else class="text-gray-400 dark:text-dark-500">-</span> <span v-else class="text-gray-400 dark:text-dark-500">-</span>
...@@ -156,10 +189,7 @@ ...@@ -156,10 +189,7 @@
<!-- Batch Actions --> <!-- Batch Actions -->
<div v-if="filters.status === 'unused'" class="flex justify-end"> <div v-if="filters.status === 'unused'" class="flex justify-end">
<button <button @click="showDeleteUnusedDialog = true" class="btn btn-danger">
@click="showDeleteUnusedDialog = true"
class="btn btn-danger"
>
{{ t('admin.redeem.deleteAllUnused') }} {{ t('admin.redeem.deleteAllUnused') }}
</button> </button>
</div> </div>
...@@ -191,28 +221,27 @@ ...@@ -191,28 +221,27 @@
<!-- Generate Codes Dialog --> <!-- Generate Codes Dialog -->
<Teleport to="body"> <Teleport to="body">
<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>
<div <div
v-if="showGenerateDialog" class="relative z-10 w-full max-w-md rounded-xl bg-white p-6 shadow-xl dark:bg-dark-800"
class="fixed inset-0 z-50 flex items-center justify-center"
> >
<div <h2 class="mb-4 text-lg font-semibold text-gray-900 dark:text-white">
class="fixed inset-0 bg-black/50" {{ t('admin.redeem.generateCodesTitle') }}
@click="showGenerateDialog = false" </h2>
></div>
<div class="relative z-10 w-full max-w-md bg-white dark:bg-dark-800 rounded-xl shadow-xl p-6">
<h2 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">{{ t('admin.redeem.generateCodesTitle') }}</h2>
<form @submit.prevent="handleGenerateCodes" class="space-y-4"> <form @submit.prevent="handleGenerateCodes" class="space-y-4">
<div> <div>
<label class="input-label">{{ t('admin.redeem.codeType') }}</label> <label class="input-label">{{ t('admin.redeem.codeType') }}</label>
<Select <Select v-model="generateForm.type" :options="typeOptions" />
v-model="generateForm.type"
:options="typeOptions"
/>
</div> </div>
<!-- 余额/并发类型显示数值输入 --> <!-- 余额/并发类型显示数值输入 -->
<div v-if="generateForm.type !== 'subscription'"> <div v-if="generateForm.type !== 'subscription'">
<label class="input-label"> <label class="input-label">
{{ generateForm.type === 'balance' ? t('admin.redeem.amount') : t('admin.redeem.columns.value') }} {{
generateForm.type === 'balance'
? t('admin.redeem.amount')
: t('admin.redeem.columns.value')
}}
</label> </label>
<input <input
v-model.number="generateForm.value" v-model.number="generateForm.value"
...@@ -257,18 +286,10 @@ ...@@ -257,18 +286,10 @@
/> />
</div> </div>
<div class="flex justify-end gap-3 pt-2"> <div class="flex justify-end gap-3 pt-2">
<button <button type="button" @click="showGenerateDialog = false" class="btn btn-secondary">
type="button"
@click="showGenerateDialog = false"
class="btn btn-secondary"
>
{{ t('common.cancel') }} {{ t('common.cancel') }}
</button> </button>
<button <button type="submit" :disabled="generating" class="btn btn-primary">
type="submit"
:disabled="generating"
class="btn btn-primary"
>
{{ generating ? t('admin.redeem.generating') : t('admin.redeem.generate') }} {{ generating ? t('admin.redeem.generating') : t('admin.redeem.generate') }}
</button> </button>
</div> </div>
...@@ -279,36 +300,51 @@ ...@@ -279,36 +300,51 @@
<!-- Generated Codes Result Dialog --> <!-- Generated Codes Result Dialog -->
<Teleport to="body"> <Teleport to="body">
<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">
<!-- Header -->
<div <div
v-if="showResultDialog" class="flex items-center justify-between border-b border-gray-200 px-5 py-4 dark:border-dark-600"
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 bg-white dark:bg-dark-800 rounded-xl shadow-xl">
<!-- Header -->
<div class="flex items-center justify-between px-5 py-4 border-b border-gray-200 dark:border-dark-600">
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center"> <div
<svg class="w-5 h-5 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"> class="flex h-10 w-10 items-center justify-center rounded-full bg-green-100 dark:bg-green-900/30"
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" /> >
<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"
/>
</svg> </svg>
</div> </div>
<div> <div>
<h2 class="text-base font-semibold text-gray-900 dark:text-white"> <h2 class="text-base font-semibold text-gray-900 dark:text-white">
{{ t('admin.redeem.generatedSuccessfully') }} {{ t('admin.redeem.generatedSuccessfully') }}
</h2> </h2>
<p class="text-sm text-gray-500 dark:text-gray-400">{{ t('admin.redeem.codesCreated', { count: generatedCodes.length }) }}</p> <p class="text-sm text-gray-500 dark:text-gray-400">
{{ t('admin.redeem.codesCreated', { count: generatedCodes.length }) }}
</p>
</div> </div>
</div> </div>
<button <button
@click="closeResultDialog" @click="closeResultDialog"
class="p-1.5 rounded-lg text-gray-400 hover:text-gray-600 hover:bg-gray-100 dark:hover:text-gray-300 dark:hover:bg-dark-700 transition-colors" 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"
> >
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" /> <path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg> </svg>
</button> </button>
</div> </div>
...@@ -319,12 +355,14 @@ ...@@ -319,12 +355,14 @@
readonly readonly
:value="generatedCodesText" :value="generatedCodesText"
:style="{ height: textareaHeight }" :style="{ height: textareaHeight }"
class="w-full p-3 font-mono text-sm bg-gray-50 dark:bg-dark-700 border border-gray-200 dark:border-dark-600 rounded-lg resize-none focus:outline-none text-gray-800 dark:text-gray-200" 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"
></textarea> ></textarea>
</div> </div>
</div> </div>
<!-- Footer --> <!-- Footer -->
<div class="flex justify-end gap-2 px-5 py-4 border-t border-gray-200 dark:border-dark-600 bg-gray-50 dark:bg-dark-700/50 rounded-b-xl"> <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"
>
<button <button
@click="copyGeneratedCodes" @click="copyGeneratedCodes"
:class="[ :class="[
...@@ -332,20 +370,38 @@ ...@@ -332,20 +370,38 @@
copiedAll ? 'btn-success' : 'btn-secondary' copiedAll ? 'btn-success' : 'btn-secondary'
]" ]"
> >
<svg v-if="!copiedAll" class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" /> v-if="!copiedAll"
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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
/>
</svg> </svg>
<svg v-else class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <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" /> <path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M5 13l4 4L19 7"
/>
</svg> </svg>
{{ copiedAll ? t('admin.redeem.copied') : t('admin.redeem.copyAll') }} {{ copiedAll ? t('admin.redeem.copied') : t('admin.redeem.copyAll') }}
</button> </button>
<button <button @click="downloadGeneratedCodes" class="btn btn-primary flex items-center gap-2">
@click="downloadGeneratedCodes" <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
class="btn btn-primary flex items-center gap-2" <path
> stroke-linecap="round"
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> stroke-linejoin="round"
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" /> stroke-width="2"
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"
/>
</svg> </svg>
{{ t('admin.redeem.download') }} {{ t('admin.redeem.download') }}
</button> </button>
...@@ -380,15 +436,15 @@ const subscriptionGroups = ref<Group[]>([]) ...@@ -380,15 +436,15 @@ const subscriptionGroups = ref<Group[]>([])
// 订阅类型分组选项 // 订阅类型分组选项
const subscriptionGroupOptions = computed(() => { const subscriptionGroupOptions = computed(() => {
return subscriptionGroups.value return subscriptionGroups.value
.filter(g => g.subscription_type === 'subscription') .filter((g) => g.subscription_type === 'subscription')
.map(g => ({ .map((g) => ({
value: g.id, value: g.id,
label: g.name label: g.name
})) }))
}) })
const generatedCodesText = computed(() => { const generatedCodesText = computed(() => {
return generatedCodes.value.map(code => code.code).join('\n') return generatedCodes.value.map((code) => code.code).join('\n')
}) })
const textareaHeight = computed(() => { const textareaHeight = computed(() => {
...@@ -397,7 +453,10 @@ const textareaHeight = computed(() => { ...@@ -397,7 +453,10 @@ const textareaHeight = computed(() => {
const padding = 24 // top + bottom padding const padding = 24 // top + bottom padding
const minHeight = 60 const minHeight = 60
const maxHeight = 240 const maxHeight = 240
const calculatedHeight = Math.min(Math.max(lineCount * lineHeight + padding, minHeight), maxHeight) const calculatedHeight = Math.min(
Math.max(lineCount * lineHeight + padding, minHeight),
maxHeight
)
return `${calculatedHeight}px` return `${calculatedHeight}px`
}) })
...@@ -497,15 +556,11 @@ const formatDate = (dateString: string): string => { ...@@ -497,15 +556,11 @@ const formatDate = (dateString: string): string => {
const loadCodes = async () => { const loadCodes = async () => {
loading.value = true loading.value = true
try { try {
const response = await adminAPI.redeem.list( const response = await adminAPI.redeem.list(pagination.page, pagination.page_size, {
pagination.page,
pagination.page_size,
{
type: filters.type as RedeemCodeType, type: filters.type as RedeemCodeType,
status: filters.status as any, status: filters.status as any,
search: searchQuery.value || undefined search: searchQuery.value || undefined
} })
)
codes.value = response.items codes.value = response.items
pagination.total = response.total pagination.total = response.total
pagination.pages = response.pages pagination.pages = response.pages
...@@ -623,7 +678,7 @@ const confirmDeleteUnused = async () => { ...@@ -623,7 +678,7 @@ const confirmDeleteUnused = async () => {
try { try {
// Get all unused codes and delete them // Get all unused codes and delete them
const unusedCodesResponse = await adminAPI.redeem.list(1, 1000, { status: 'unused' }) const unusedCodesResponse = await adminAPI.redeem.list(1, 1000, { status: 'unused' })
const unusedCodeIds = unusedCodesResponse.items.map(code => code.id) const unusedCodeIds = unusedCodesResponse.items.map((code) => code.id)
if (unusedCodeIds.length === 0) { if (unusedCodeIds.length === 0) {
appStore.showInfo(t('admin.redeem.noUnusedCodes')) appStore.showInfo(t('admin.redeem.noUnusedCodes'))
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -9,6 +9,7 @@ This directory contains Vue 3 authentication views for the Sub2API frontend appl ...@@ -9,6 +9,7 @@ This directory contains Vue 3 authentication views for the Sub2API frontend appl
Login page for existing users to authenticate. Login page for existing users to authenticate.
**Features:** **Features:**
- Username and password inputs with validation - Username and password inputs with validation
- Remember me checkbox for persistent sessions - Remember me checkbox for persistent sessions
- Form validation with real-time error display - Form validation with real-time error display
...@@ -18,26 +19,30 @@ Login page for existing users to authenticate. ...@@ -18,26 +19,30 @@ Login page for existing users to authenticate.
- Link to registration page for new users - Link to registration page for new users
**Usage:** **Usage:**
```vue ```vue
<template> <template>
<LoginView /> <LoginView />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { LoginView } from '@/views/auth'; import { LoginView } from '@/views/auth'
</script> </script>
``` ```
**Route:** **Route:**
- Path: `/login` - Path: `/login`
- Name: `Login` - Name: `Login`
- Meta: `{ requiresAuth: false }` - Meta: `{ requiresAuth: false }`
**Validation Rules:** **Validation Rules:**
- Username: Required, minimum 3 characters - Username: Required, minimum 3 characters
- Password: Required, minimum 6 characters - Password: Required, minimum 6 characters
**Behavior:** **Behavior:**
- Calls `authStore.login()` with credentials - Calls `authStore.login()` with credentials
- Shows success toast on successful login - Shows success toast on successful login
- Shows error toast and inline error message on failure - Shows error toast and inline error message on failure
...@@ -49,6 +54,7 @@ import { LoginView } from '@/views/auth'; ...@@ -49,6 +54,7 @@ import { LoginView } from '@/views/auth';
Registration page for new users to create accounts. Registration page for new users to create accounts.
**Features:** **Features:**
- Username, email, password, and confirm password inputs - Username, email, password, and confirm password inputs
- Comprehensive form validation - Comprehensive form validation
- Password strength requirements (8+ characters, letters + numbers) - Password strength requirements (8+ characters, letters + numbers)
...@@ -60,22 +66,25 @@ Registration page for new users to create accounts. ...@@ -60,22 +66,25 @@ Registration page for new users to create accounts.
- Link to login page for existing users - Link to login page for existing users
**Usage:** **Usage:**
```vue ```vue
<template> <template>
<RegisterView /> <RegisterView />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { RegisterView } from '@/views/auth'; import { RegisterView } from '@/views/auth'
</script> </script>
``` ```
**Route:** **Route:**
- Path: `/register` - Path: `/register`
- Name: `Register` - Name: `Register`
- Meta: `{ requiresAuth: false }` - Meta: `{ requiresAuth: false }`
**Validation Rules:** **Validation Rules:**
- Username: - Username:
- Required - Required
- 3-50 characters - 3-50 characters
...@@ -92,6 +101,7 @@ import { RegisterView } from '@/views/auth'; ...@@ -92,6 +101,7 @@ import { RegisterView } from '@/views/auth';
- Must match password - Must match password
**Behavior:** **Behavior:**
- Calls `authStore.register()` with user data - Calls `authStore.register()` with user data
- Shows success toast on successful registration - Shows success toast on successful registration
- Shows error toast and inline error message on failure - Shows error toast and inline error message on failure
...@@ -131,6 +141,7 @@ Both views follow a consistent structure: ...@@ -131,6 +141,7 @@ Both views follow a consistent structure:
### State Management ### State Management
Both views use: Both views use:
- `useAuthStore()` - For authentication actions (login, register) - `useAuthStore()` - For authentication actions (login, register)
- `useAppStore()` - For toast notifications and UI feedback - `useAppStore()` - For toast notifications and UI feedback
- `useRouter()` - For navigation and redirects - `useRouter()` - For navigation and redirects
...@@ -138,12 +149,14 @@ Both views use: ...@@ -138,12 +149,14 @@ Both views use:
### Validation Strategy ### Validation Strategy
**Client-side Validation:** **Client-side Validation:**
- Real-time validation on form submission - Real-time validation on form submission
- Field-level error messages - Field-level error messages
- Comprehensive validation rules - Comprehensive validation rules
- TypeScript type safety - TypeScript type safety
**Server-side Validation:** **Server-side Validation:**
- Backend API validates all inputs - Backend API validates all inputs
- Error responses handled gracefully - Error responses handled gracefully
- User-friendly error messages displayed - User-friendly error messages displayed
...@@ -151,6 +164,7 @@ Both views use: ...@@ -151,6 +164,7 @@ Both views use:
### Styling ### Styling
**Design System:** **Design System:**
- TailwindCSS utility classes - TailwindCSS utility classes
- Consistent color scheme (indigo primary) - Consistent color scheme (indigo primary)
- Responsive design - Responsive design
...@@ -158,6 +172,7 @@ Both views use: ...@@ -158,6 +172,7 @@ Both views use:
- Loading states with spinner animations - Loading states with spinner animations
**Visual Feedback:** **Visual Feedback:**
- Red border on invalid fields - Red border on invalid fields
- Error messages below inputs - Error messages below inputs
- Global error banner for API errors - Global error banner for API errors
...@@ -167,13 +182,16 @@ Both views use: ...@@ -167,13 +182,16 @@ Both views use:
## Dependencies ## Dependencies
### Components ### Components
- `AuthLayout` - Layout wrapper for auth pages from `@/components/layout` - `AuthLayout` - Layout wrapper for auth pages from `@/components/layout`
### Stores ### Stores
- `authStore` - Authentication state management from `@/stores/auth` - `authStore` - Authentication state management from `@/stores/auth`
- `appStore` - Application state and toasts from `@/stores/app` - `appStore` - Application state and toasts from `@/stores/app`
### Libraries ### Libraries
- Vue 3 Composition API - Vue 3 Composition API
- Vue Router for navigation - Vue Router for navigation
- Pinia for state management - Pinia for state management
...@@ -185,11 +203,11 @@ Both views use: ...@@ -185,11 +203,11 @@ Both views use:
```typescript ```typescript
// User enters credentials // User enters credentials
formData.username = 'john_doe'; formData.username = 'john_doe'
formData.password = 'SecurePass123'; formData.password = 'SecurePass123'
// Submit form // Submit form
await handleLogin(); await handleLogin()
// On success: // On success:
// - authStore.login() called // - authStore.login() called
...@@ -207,13 +225,13 @@ await handleLogin(); ...@@ -207,13 +225,13 @@ await handleLogin();
```typescript ```typescript
// User enters registration data // User enters registration data
formData.username = 'jane_smith'; formData.username = 'jane_smith'
formData.email = 'jane@example.com'; formData.email = 'jane@example.com'
formData.password = 'SecurePass123'; formData.password = 'SecurePass123'
formData.confirmPassword = 'SecurePass123'; formData.confirmPassword = 'SecurePass123'
// Submit form // Submit form
await handleRegister(); await handleRegister()
// On success: // On success:
// - authStore.register() called // - authStore.register() called
...@@ -233,10 +251,10 @@ await handleRegister(); ...@@ -233,10 +251,10 @@ await handleRegister();
```typescript ```typescript
// Validation errors // Validation errors
errors.username = 'Username must be at least 3 characters'; errors.username = 'Username must be at least 3 characters'
errors.email = 'Please enter a valid email address'; errors.email = 'Please enter a valid email address'
errors.password = 'Password must be at least 8 characters with letters and numbers'; errors.password = 'Password must be at least 8 characters with letters and numbers'
errors.confirmPassword = 'Passwords do not match'; errors.confirmPassword = 'Passwords do not match'
``` ```
### Server-side Errors ### Server-side Errors
...@@ -252,8 +270,8 @@ errors.confirmPassword = 'Passwords do not match'; ...@@ -252,8 +270,8 @@ errors.confirmPassword = 'Passwords do not match';
} }
// Displayed as: // Displayed as:
errorMessage.value = 'Username already exists'; errorMessage.value = 'Username already exists'
appStore.showError('Username already exists'); appStore.showError('Username already exists')
``` ```
## Accessibility ## Accessibility
...@@ -269,18 +287,21 @@ appStore.showError('Username already exists'); ...@@ -269,18 +287,21 @@ appStore.showError('Username already exists');
## Testing Considerations ## Testing Considerations
### Unit Tests ### Unit Tests
- Form validation logic - Form validation logic
- Error handling - Error handling
- State management - State management
- Router navigation - Router navigation
### Integration Tests ### Integration Tests
- Full login flow - Full login flow
- Full registration flow - Full registration flow
- Error scenarios - Error scenarios
- Redirect behavior - Redirect behavior
### E2E Tests ### E2E Tests
- Complete user journeys - Complete user journeys
- Form interactions - Form interactions
- API integration - API integration
...@@ -289,6 +310,7 @@ appStore.showError('Username already exists'); ...@@ -289,6 +310,7 @@ appStore.showError('Username already exists');
## Future Enhancements ## Future Enhancements
Potential improvements: Potential improvements:
- OAuth/SSO integration (Google, GitHub) - OAuth/SSO integration (Google, GitHub)
- Two-factor authentication (2FA) - Two-factor authentication (2FA)
- Password strength meter - Password strength meter
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
* Export all authentication-related views * Export all authentication-related views
*/ */
export { default as LoginView } from './LoginView.vue'; export { default as LoginView } from './LoginView.vue'
export { default as RegisterView } from './RegisterView.vue'; export { default as RegisterView } from './RegisterView.vue'
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment