Files
sionrui/frontend/app/web-gold/src/views/user/Profile.vue

710 lines
17 KiB
Vue
Raw Normal View History

2026-02-23 02:27:32 +08:00
<script setup>
2026-02-26 18:52:09 +08:00
import { computed, onMounted, ref, reactive } from 'vue'
2026-03-16 23:54:01 +08:00
import { Icon } from '@iconify/vue'
2026-03-17 23:41:49 +08:00
import { toast } from 'vue-sonner'
2026-02-23 02:27:32 +08:00
import { useUserStore } from '@/stores/user'
2026-02-26 18:52:09 +08:00
import { getPointRecordPage } from '@/api/pointRecord'
2026-03-17 23:41:49 +08:00
import { redeemCode as redeemCodeApi } from '@/api/redeemCode'
2026-03-16 23:54:01 +08:00
import { Progress } from '@/components/ui/progress'
import { Button } from '@/components/ui/button'
2026-03-17 23:41:49 +08:00
import { Input } from '@/components/ui/input'
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogFooter,
DialogDescription
} from '@/components/ui/dialog'
2026-02-23 02:27:32 +08:00
const userStore = useUserStore()
2026-03-17 23:41:49 +08:00
// 兑换码相关
const showRedeemDialog = ref(false)
const redeemCodeInput = ref('')
const redeeming = ref(false)
2026-02-26 18:52:09 +08:00
// 积分记录数据
const pointRecords = ref([])
const recordsLoading = ref(false)
const recordsPagination = reactive({
current: 1,
pageSize: 10,
total: 0
})
2026-02-23 02:27:32 +08:00
// 存储空间数据
const GB_TO_MB = 1024
const totalStorage = computed(() => userStore.totalStorage * GB_TO_MB)
const usedStorage = computed(() => userStore.usedStorage * GB_TO_MB)
const storagePercent = computed(() => {
if (totalStorage.value === 0) return 0
return Math.min(100, (usedStorage.value / totalStorage.value) * 100)
})
// 格式化函数
function formatStorage(mb) {
if (mb >= 1024) {
return (mb / 1024).toFixed(1) + ' GB'
}
return Math.round(mb) + ' MB'
}
function formatMoney(amount) {
return amount?.toFixed(2) || '0.00'
}
function formatCredits(credits) {
return credits?.toLocaleString() || '0'
}
// 格式化日期
function formatDate(dateStr) {
if (!dateStr) return '未设置'
const date = new Date(dateStr)
return date.toLocaleDateString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit'
}).replace(/\//g, '-')
}
// 脱敏手机号
function maskMobile(mobile) {
if (!mobile) return '未设置'
return mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
}
// 获取积分记录(只显示已完成的记录)
2026-02-26 18:52:09 +08:00
async function fetchPointRecords() {
recordsLoading.value = true
try {
const res = await getPointRecordPage({
pageNo: recordsPagination.current,
pageSize: recordsPagination.pageSize,
status: 'confirmed'
2026-02-26 18:52:09 +08:00
})
if (res.data) {
pointRecords.value = res.data.list || []
recordsPagination.total = res.data.total || 0
}
} catch (e) {
console.error('获取积分记录失败:', e)
} finally {
recordsLoading.value = false
}
}
// 分页变化
2026-03-16 23:54:01 +08:00
function handlePageChange(page) {
recordsPagination.current = page
2026-02-26 18:52:09 +08:00
fetchPointRecords()
}
2026-03-16 23:54:01 +08:00
// 计算总页数
const totalPages = computed(() => {
return Math.ceil(recordsPagination.total / recordsPagination.pageSize)
})
2026-02-26 18:52:09 +08:00
// 格式化积分记录时间
function formatRecordTime(dateStr) {
if (!dateStr) return ''
const date = new Date(dateStr)
return date.toLocaleString('zh-CN', {
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})
}
// 获取业务类型显示名称
function getBizTypeName(bizType) {
const typeMap = {
'signin': '签到',
'recharge': '充值',
'exchange': '兑换',
'admin': '后台调整',
'gift': '礼包赠送',
'dify_chat': 'AI文案',
'digital_human': '数字人',
'voice_tts': '语音克隆',
'tikhub_fetch': '数据采集',
'forecast_rewrite': '文案改写'
2026-02-26 18:52:09 +08:00
}
return typeMap[bizType] || bizType || '其他'
}
// 获取状态显示
function getStatusInfo(status) {
const statusMap = {
'pending': { text: '处理中', color: 'orange' },
'confirmed': { text: '已完成', color: 'green' },
'canceled': { text: '已取消', color: 'default' }
}
return statusMap[status] || { text: status, color: 'default' }
}
2026-03-17 23:41:49 +08:00
// 兑换码兑换
async function handleRedeem() {
const code = redeemCodeInput.value.trim()
if (!code) {
toast.error('请输入兑换码')
return
}
redeeming.value = true
try {
await redeemCodeApi(code)
toast.success('兑换成功,积分已到账')
showRedeemDialog.value = false
redeemCodeInput.value = ''
// 刷新用户信息和积分记录
await userStore.fetchUserProfile()
await fetchPointRecords()
} catch (e) {
const msg = e?.response?.data?.msg || e?.message || '兑换失败'
toast.error(msg)
} finally {
redeeming.value = false
}
}
2026-02-23 02:27:32 +08:00
onMounted(async () => {
if (userStore.isLoggedIn) {
// 获取用户基本信息和档案信息
if (!userStore.mobile) {
await userStore.fetchUserInfo()
}
if (!userStore.profile) {
await userStore.fetchUserProfile()
}
2026-02-26 18:52:09 +08:00
// 获取积分记录
await fetchPointRecords()
2026-02-23 02:27:32 +08:00
}
})
</script>
<template>
<div class="profile-container">
2026-03-17 00:46:51 +08:00
2026-02-23 02:27:32 +08:00
2026-03-16 23:54:01 +08:00
<div class="grid grid-cols-1 lg:grid-cols-12 gap-6">
2026-02-23 02:27:32 +08:00
<!-- 左侧用户信息卡片 -->
2026-03-16 23:54:01 +08:00
<div class="lg:col-span-4">
<div class="user-card">
2026-02-23 02:27:32 +08:00
<div class="user-info-header">
<div class="avatar-wrapper">
2026-03-16 23:54:01 +08:00
<img
v-if="userStore.displayAvatar"
class="user-avatar"
:src="userStore.displayAvatar"
alt="avatar"
2026-02-23 02:27:32 +08:00
/>
<div v-else class="user-avatar-placeholder">
{{ userStore.displayName?.charAt(0) || 'U' }}
</div>
</div>
<h2 class="user-name">{{ userStore.displayName }}</h2>
<div class="user-role-badge">普通用户</div>
</div>
2026-03-16 23:54:01 +08:00
<div class="divider"></div>
2026-02-23 02:27:32 +08:00
<div class="user-details">
<div class="detail-item">
<span class="detail-label">注册时间</span>
<span class="detail-value">{{ formatDate(userStore.profile?.registerTime || userStore.profile?.createTime) }}</span>
</div>
<div class="detail-item">
<span class="detail-label">绑定手机</span>
<span class="detail-value">{{ maskMobile(userStore.mobile || userStore.profile?.mobile) }}</span>
</div>
</div>
2026-03-16 23:54:01 +08:00
</div>
</div>
2026-02-23 02:27:32 +08:00
<!-- 右侧资源统计与活动 -->
2026-03-16 23:54:01 +08:00
<div class="lg:col-span-8">
2026-02-23 02:27:32 +08:00
<!-- 资源概览卡片 -->
2026-03-17 23:41:49 +08:00
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
2026-03-16 23:54:01 +08:00
<!-- 存储空间 -->
<div class="stat-card">
<div class="stat-icon-wrapper blue">
<Icon icon="lucide:database" class="text-2xl" />
</div>
<div class="stat-content">
<div class="stat-label">存储空间</div>
<div class="stat-value">{{ formatStorage(usedStorage) }} <span class="stat-unit">/ {{ formatStorage(totalStorage) }}</span></div>
<Progress :value="storagePercent" class="stat-progress h-2" />
</div>
</div>
2026-02-23 02:27:32 +08:00
2026-03-16 23:54:01 +08:00
<!-- 剩余积分 -->
<div class="stat-card">
<div class="stat-icon-wrapper purple">
<Icon icon="lucide:wallet" class="text-2xl" />
</div>
<div class="stat-content">
<div class="stat-label">剩余积分</div>
<div class="stat-value">{{ formatCredits(userStore.remainingPoints) }}</div>
<div class="stat-desc">用于生成消耗</div>
</div>
</div>
2026-02-23 02:27:32 +08:00
2026-03-16 23:54:01 +08:00
<!-- 账户余额 -->
<div class="stat-card">
<div class="stat-icon-wrapper orange">
<Icon icon="lucide:coins" class="text-2xl" />
</div>
<div class="stat-content">
<div class="stat-label">账户余额</div>
<div class="stat-value">¥{{ formatMoney(userStore.totalRecharge) }}</div>
<div class="stat-desc">累计充值金额</div>
</div>
</div>
2026-03-17 23:41:49 +08:00
<!-- 兑换码充值 -->
<div class="stat-card">
<div class="stat-icon-wrapper green">
<Icon icon="lucide:gift" class="text-2xl" />
</div>
<div class="stat-content">
<div class="stat-label">兑换码充值</div>
<div class="stat-value" style="font-size: 16px;">
<Button
variant="outline"
size="sm"
@click="showRedeemDialog = true"
>
输入兑换码
</Button>
</div>
<div class="stat-desc">使用兑换码获取积分</div>
</div>
</div>
2026-03-16 23:54:01 +08:00
</div>
2026-02-23 02:27:32 +08:00
2026-02-26 18:52:09 +08:00
<!-- 积分记录 -->
2026-03-16 23:54:01 +08:00
<div class="activity-card mt-6">
<div class="activity-header">
<h3 class="activity-title">积分记录</h3>
2026-02-26 18:52:09 +08:00
<span class="record-count"> {{ recordsPagination.total }} 条记录</span>
2026-03-16 23:54:01 +08:00
</div>
<!-- 加载状态 -->
<div v-if="recordsLoading" class="loading-state">
<span class="custom-spinner"></span>
<span>加载中...</span>
</div>
<!-- 积分记录列表 -->
<div v-else-if="pointRecords.length > 0" class="point-record-list">
<div
v-for="item in pointRecords"
:key="item.id"
class="record-item"
2026-02-26 18:52:09 +08:00
>
2026-03-16 23:54:01 +08:00
<div class="record-left">
<div :class="['record-icon', item.type === 'increase' ? 'increase' : 'decrease']">
<Icon v-if="item.type === 'increase'" icon="lucide:plus" />
<Icon v-else icon="lucide:minus" />
</div>
<div class="record-info">
<div class="record-reason">{{ getBizTypeName(item.bizType) }}</div>
<div class="record-time">{{ formatRecordTime(item.createTime) }}</div>
</div>
</div>
<div :class="['record-amount', item.type === 'increase' ? 'increase' : 'decrease']">
{{ item.type === 'increase' ? '+' : '-' }}{{ Math.abs(item.pointAmount) }}
</div>
</div>
<!-- 分页 -->
<div v-if="recordsPagination.total > recordsPagination.pageSize" class="record-pagination">
<Button
variant="outline"
size="sm"
:disabled="recordsPagination.current === 1"
@click="handlePageChange(recordsPagination.current - 1)"
>
上一页
</Button>
<span class="page-info">
{{ recordsPagination.current }} / {{ totalPages }}
</span>
<Button
variant="outline"
size="sm"
:disabled="recordsPagination.current >= totalPages"
@click="handlePageChange(recordsPagination.current + 1)"
>
下一页
</Button>
2026-02-26 18:52:09 +08:00
</div>
2026-03-16 23:54:01 +08:00
</div>
2026-02-23 02:27:32 +08:00
2026-03-16 23:54:01 +08:00
<!-- 空状态 -->
<div v-else class="empty-state">
<Icon icon="lucide:clock" class="empty-icon" />
<p>暂无积分记录</p>
</div>
</div>
</div>
</div>
2026-03-17 23:41:49 +08:00
<!-- 兑换码弹窗 -->
<Dialog v-model:open="showRedeemDialog">
<DialogContent class="sm:max-w-md">
<DialogHeader>
<DialogTitle>兑换码充值</DialogTitle>
<DialogDescription>
输入您的兑换码积分将立即到账
</DialogDescription>
</DialogHeader>
<div class="py-4">
<Input
v-model="redeemCodeInput"
placeholder="请输入兑换码"
class="w-full"
@keyup.enter="handleRedeem"
/>
</div>
<DialogFooter>
<Button variant="outline" @click="showRedeemDialog = false">
取消
</Button>
<Button @click="handleRedeem" :disabled="redeeming">
{{ redeeming ? '兑换中...' : '立即兑换' }}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
2026-02-23 02:27:32 +08:00
</div>
</template>
<style scoped>
.profile-container {
2026-03-17 00:46:51 +08:00
padding: var(--space-6);
2026-02-23 02:27:32 +08:00
max-width: 1200px;
margin: 0 auto;
}
2026-03-17 00:46:51 +08:00
.profile-content {
2026-02-23 02:27:32 +08:00
text-align: center;
border-radius: 16px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
2026-03-17 00:46:51 +08:00
background: var(--card);
2026-02-23 02:27:32 +08:00
height: 100%;
2026-03-16 23:54:01 +08:00
padding: 24px;
2026-02-23 02:27:32 +08:00
}
.user-info-header {
padding: 24px 0;
display: flex;
flex-direction: column;
align-items: center;
}
.avatar-wrapper {
margin-bottom: 16px;
position: relative;
}
.user-avatar {
width: 100px;
height: 100px;
border-radius: 50%;
object-fit: cover;
border: 4px solid rgba(var(--primary-color-rgb, 24, 144, 255), 0.1);
}
.user-avatar-placeholder {
width: 100px;
height: 100px;
border-radius: 50%;
background: linear-gradient(135deg, #1890ff 0%, #36cfc9 100%);
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 40px;
font-weight: 600;
border: 4px solid rgba(24, 144, 255, 0.1);
}
.user-name {
font-size: 20px;
font-weight: 600;
margin-bottom: 12px;
2026-03-17 00:46:51 +08:00
color: var(--foreground);
2026-02-23 02:27:32 +08:00
}
.user-role-badge {
display: inline-block;
padding: 4px 12px;
background: rgba(24, 144, 255, 0.1);
color: #1890ff;
border-radius: 20px;
font-size: 12px;
font-weight: 500;
}
2026-03-16 23:54:01 +08:00
.divider {
height: 1px;
2026-03-17 00:46:51 +08:00
background: var(--border);
2026-03-16 23:54:01 +08:00
margin: 16px 0;
}
2026-02-23 02:27:32 +08:00
.user-details {
padding: 16px 0;
}
.detail-item {
display: flex;
justify-content: space-between;
padding: 12px 0;
2026-03-17 00:46:51 +08:00
border-bottom: 1px solid var(--border);
2026-02-23 02:27:32 +08:00
}
.detail-item:last-child {
border-bottom: none;
}
.detail-label {
2026-03-17 00:46:51 +08:00
color: var(--muted-foreground);
2026-02-23 02:27:32 +08:00
}
.detail-value {
2026-03-17 00:46:51 +08:00
color: var(--foreground);
2026-02-23 02:27:32 +08:00
font-weight: 500;
}
/* Stat Cards */
.stat-card {
border-radius: 12px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
2026-03-17 00:46:51 +08:00
background: var(--card);
2026-03-16 23:54:01 +08:00
padding: 20px;
transition: transform 0.2s, box-shadow 0.2s;
2026-02-23 02:27:32 +08:00
}
.stat-card:hover {
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}
.stat-icon-wrapper {
width: 48px;
height: 48px;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 16px;
}
.stat-icon-wrapper.blue {
background: rgba(24, 144, 255, 0.1);
color: #1890ff;
}
.stat-icon-wrapper.purple {
background: rgba(114, 46, 209, 0.1);
color: #722ed1;
}
.stat-icon-wrapper.orange {
background: rgba(250, 173, 20, 0.1);
color: #faad14;
}
2026-03-17 23:41:49 +08:00
.stat-icon-wrapper.green {
background: rgba(82, 196, 26, 0.1);
color: #52c41a;
}
2026-02-23 02:27:32 +08:00
.stat-label {
font-size: 14px;
2026-03-17 00:46:51 +08:00
color: var(--muted-foreground);
2026-02-23 02:27:32 +08:00
margin-bottom: 4px;
}
.stat-value {
font-size: 24px;
font-weight: 700;
2026-03-17 00:46:51 +08:00
color: var(--foreground);
2026-02-23 02:27:32 +08:00
margin-bottom: 8px;
}
.stat-unit {
font-size: 14px;
font-weight: 400;
2026-03-17 00:46:51 +08:00
color: var(--muted-foreground);
2026-02-23 02:27:32 +08:00
}
.stat-desc {
font-size: 12px;
2026-03-17 00:46:51 +08:00
color: var(--muted-foreground);
2026-02-23 02:27:32 +08:00
}
.stat-progress {
margin-top: 8px;
}
.mt-6 {
margin-top: 24px;
}
2026-03-16 23:54:01 +08:00
/* Loading State */
.loading-state {
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
padding: 40px 0;
2026-03-17 00:46:51 +08:00
color: var(--muted-foreground);
2026-03-16 23:54:01 +08:00
}
.custom-spinner {
width: 20px;
height: 20px;
border: 2px solid rgba(24, 144, 255, 0.2);
border-top-color: #1890ff;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
2026-02-23 02:27:32 +08:00
/* Empty State */
.empty-state {
text-align: center;
padding: 40px 0;
2026-03-17 00:46:51 +08:00
color: var(--muted-foreground);
2026-02-23 02:27:32 +08:00
}
.empty-icon {
font-size: 48px;
margin-bottom: 16px;
opacity: 0.5;
}
2026-02-26 18:52:09 +08:00
/* Point Record List */
.activity-card {
border-radius: 12px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
2026-03-17 00:46:51 +08:00
background: var(--card);
2026-03-16 23:54:01 +08:00
padding: 20px;
}
.activity-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
}
.activity-title {
font-size: 16px;
font-weight: 600;
2026-03-17 00:46:51 +08:00
color: var(--foreground);
2026-03-16 23:54:01 +08:00
margin: 0;
2026-02-26 18:52:09 +08:00
}
.record-count {
2026-03-17 00:46:51 +08:00
color: var(--muted-foreground);
2026-02-26 18:52:09 +08:00
font-size: 13px;
}
.point-record-list {
max-height: 400px;
overflow-y: auto;
}
2026-03-16 23:54:01 +08:00
.record-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 0;
2026-03-17 00:46:51 +08:00
border-bottom: 1px solid var(--border);
2026-03-16 23:54:01 +08:00
}
.record-item:last-child {
border-bottom: none;
}
.record-left {
display: flex;
align-items: center;
gap: 12px;
}
2026-02-26 18:52:09 +08:00
.record-icon {
width: 36px;
height: 36px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
}
.record-icon.increase {
background: rgba(82, 196, 26, 0.1);
color: #52c41a;
}
.record-icon.decrease {
background: rgba(255, 77, 79, 0.1);
color: #ff4d4f;
}
2026-03-16 23:54:01 +08:00
.record-info {
2026-02-26 18:52:09 +08:00
display: flex;
2026-03-16 23:54:01 +08:00
flex-direction: column;
gap: 2px;
2026-02-26 18:52:09 +08:00
}
.record-reason {
font-weight: 500;
2026-03-17 00:46:51 +08:00
color: var(--foreground);
2026-03-16 23:54:01 +08:00
font-size: 14px;
2026-02-26 18:52:09 +08:00
}
2026-03-16 23:54:01 +08:00
.record-time {
2026-02-26 18:52:09 +08:00
font-size: 12px;
2026-03-17 00:46:51 +08:00
color: var(--muted-foreground);
2026-02-26 18:52:09 +08:00
}
.record-amount {
font-size: 18px;
font-weight: 600;
}
.record-amount.increase {
color: #52c41a;
}
.record-amount.decrease {
color: #ff4d4f;
}
.record-pagination {
2026-03-16 23:54:01 +08:00
display: flex;
align-items: center;
justify-content: center;
gap: 16px;
2026-02-26 18:52:09 +08:00
margin-top: 16px;
2026-03-16 23:54:01 +08:00
padding-top: 16px;
2026-03-17 00:46:51 +08:00
border-top: 1px solid var(--border);
2026-03-16 23:54:01 +08:00
}
.page-info {
font-size: 14px;
2026-03-17 00:46:51 +08:00
color: var(--muted-foreground);
2026-02-26 18:52:09 +08:00
}
2026-02-23 02:27:32 +08:00
</style>