新增SMTP邮件通知、仪表盘图表、授权编辑功能、API文档
This commit is contained in:
1 parent
d6d7a1a27e
commit
044e526c80
87 files changed
+1851
-237
No files matched your search
@@ -39,6 +39,13 @@ const authorizationApi = {
|
||||
return request.put(`/authorizations/${id}/revoke`, { reason })
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新授权
|
||||
*/
|
||||
update(id, data) {
|
||||
return request.put(`/authorizations/${id}`, data)
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除授权
|
||||
*/
|
||||
|
||||
@@ -78,9 +78,10 @@
|
||||
<el-table-column prop="status" label="状态" width="100" align="center" sortable="custom" v-if="visibleColumns.status"><template #default="{ row }"><span v-if="row.status==='active' && !row.is_expired" class="status-pill status-active">有效</span><span v-else-if="row.is_expired" class="status-pill status-expired">已过期</span><span v-else-if="row.status==='revoked'" class="status-pill status-revoked">已撤销</span><span v-else class="status-pill status-unknown">{{ row.status }}</span></template></el-table-column>
|
||||
<el-table-column prop="expire_time" label="过期时间" width="180" sortable="custom" v-if="visibleColumns.expire_time"><template #default="{ row }"><span v-if="row.duration_days==0" class="text-success">永久有效</span><span v-else :class="{'text-danger':row.is_expired}">{{ row.expire_time || '-' }}</span></template></el-table-column>
|
||||
<el-table-column prop="authorized_at" label="授权时间" width="180" sortable="custom" v-if="visibleColumns.authorized_at" />
|
||||
<el-table-column label="操作" width="180" fixed="right" align="center">
|
||||
<el-table-column label="操作" width="210" fixed="right" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button size="small" type="primary" link :icon="View" @click="showDetail(row)">详情</el-button>
|
||||
<el-button size="small" type="primary" link :icon="Edit" @click="showEditDialog(row)">编辑</el-button>
|
||||
<el-button v-if="row.status==='active'" size="small" type="danger" link @click="handleRevoke(row)">撤销</el-button>
|
||||
<el-button size="small" type="danger" link plain @click="handleDelete(row.id)">删除</el-button>
|
||||
</template>
|
||||
@@ -120,6 +121,24 @@
|
||||
<template #footer><el-button @click="createDialogVisible = false">取消</el-button><el-button type="primary" :loading="createLoading" @click="submitCreate">确认授权</el-button></template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 编辑授权弹窗 -->
|
||||
<el-dialog v-model="editDialogVisible" title="编辑授权" width="480px" :close-on-click-modal="false" destroy-on-close>
|
||||
<el-form ref="editFormRef" :model="editForm" :rules="editRules" label-width="110px" v-if="editForm.id">
|
||||
<el-form-item label="机器人QQ" prop="bot_qq"><el-input v-model="editForm.bot_qq" placeholder="5-15位数字" maxlength="15" /></el-form-item>
|
||||
<el-form-item label="联系人QQ" prop="contact_qq"><el-input v-model="editForm.contact_qq" placeholder="5-15位数字" maxlength="15" /></el-form-item>
|
||||
<el-form-item label="联系人名称"><el-input v-model="editForm.contact_name" placeholder="联系人称呼" maxlength="50" /></el-form-item>
|
||||
<el-form-item label="有效天数" prop="duration_days">
|
||||
<el-input-number v-model="editForm.duration_days" :min="0" :max="36500" />
|
||||
<span class="form-tip" style="font-size:12px;color:#909399;margin-left:10px">0=永久</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="过期时间">
|
||||
<el-date-picker v-model="editForm.expire_time" type="datetime" placeholder="留空按有效天数计算" value-format="YYYY-MM-DD HH:mm:ss" :disabled-date="disabledDate" style="width:100%" :clearable="false" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注"><el-input v-model="editForm.remark" type="textarea" :rows="2" placeholder="选填" maxlength="255" show-word-limit /></el-form-item>
|
||||
</el-form>
|
||||
<template #footer><el-button @click="editDialogVisible = false">取消</el-button><el-button type="primary" :loading="editLoading" @click="submitEdit">保存修改</el-button></template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 详情弹窗 -->
|
||||
<el-dialog v-model="detailDialogVisible" width="520px" destroy-on-close :show-close="false">
|
||||
<template #header="{ close }">
|
||||
@@ -180,7 +199,7 @@ import { useColumnSettings } from '@/composables/useColumnSettings'
|
||||
import authorizationApi from '@/api/authorization'
|
||||
import request from '@/api'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { Plus, Delete, Download, Search, Refresh, Filter, Setting, View, ArrowDown, Lock, CircleCheck, CircleClose, Timer } from '@element-plus/icons-vue'
|
||||
import { Plus, Delete, Download, Search, Refresh, Filter, Setting, View, Edit, ArrowDown, Lock, CircleCheck, CircleClose, Timer } from '@element-plus/icons-vue'
|
||||
|
||||
const userStore = useUserStore()
|
||||
const user = computed(() => userStore.user)
|
||||
@@ -285,6 +304,45 @@ async function showDetail(row) {
|
||||
} catch {}
|
||||
}
|
||||
|
||||
// 编辑
|
||||
const editDialogVisible = ref(false)
|
||||
const editLoading = ref(false)
|
||||
const editFormRef = ref(null)
|
||||
const editForm = reactive({ id: null, bot_qq: '', contact_qq: '', contact_name: '', duration_days: 30, expire_time: '', remark: '' })
|
||||
const editRules = {
|
||||
bot_qq: [{ required: true, message: '请输入机器人QQ', trigger: 'blur' }, { pattern: /^\d{5,15}$/, message: '请输入5-15位数字', trigger: 'blur' }],
|
||||
contact_qq: [{ required: true, message: '请输入联系人QQ', trigger: 'blur' }, { pattern: /^\d{5,15}$/, message: '请输入5-15位数字', trigger: 'blur' }]
|
||||
}
|
||||
function disabledDate(time) { return time.getTime() < Date.now() - 86400000 }
|
||||
function showEditDialog(row) {
|
||||
editForm.id = row.id
|
||||
editForm.bot_qq = row.bot_qq || ''
|
||||
editForm.contact_qq = row.contact_qq || ''
|
||||
editForm.contact_name = row.contact_name || ''
|
||||
editForm.duration_days = row.duration_days ?? 30
|
||||
editForm.expire_time = row.expire_time || ''
|
||||
editForm.remark = row.remark || ''
|
||||
editDialogVisible.value = true
|
||||
}
|
||||
async function submitEdit() {
|
||||
const valid = await editFormRef.value.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
editLoading.value = true
|
||||
try {
|
||||
await authorizationApi.update(editForm.id, {
|
||||
bot_qq: editForm.bot_qq,
|
||||
contact_qq: editForm.contact_qq,
|
||||
contact_name: editForm.contact_name,
|
||||
duration_days: editForm.duration_days,
|
||||
expire_time: editForm.expire_time,
|
||||
remark: editForm.remark
|
||||
})
|
||||
ElMessage.success('授权更新成功')
|
||||
editDialogVisible.value = false
|
||||
fetchData(); fetchStats()
|
||||
} finally { editLoading.value = false }
|
||||
}
|
||||
|
||||
// 撤销
|
||||
const revokeDialogVisible = ref(false)
|
||||
const revokeLoading = ref(false)
|
||||
|
||||
+179
-209
@@ -14,6 +14,7 @@
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 近7天订单趋势 -->
|
||||
<el-row :gutter="10" style="margin-top:12px" v-if="data && data.order_trend">
|
||||
<el-col :span="24">
|
||||
<el-card shadow="hover" class="chart-card">
|
||||
@@ -27,7 +28,48 @@
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div ref="chartRef" :style="{ height: isMobile ? '200px' : '260px' }"></div>
|
||||
<div ref="chart7Ref" :style="{ height: isMobile ? '200px' : '260px' }"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 近30天收入 + 授权趋势 -->
|
||||
<el-row :gutter="10" style="margin-top:12px" v-if="data">
|
||||
<el-col :xs="24" :md="12">
|
||||
<el-card shadow="hover" class="chart-card" v-if="data.revenue_trend_30">
|
||||
<template #header>
|
||||
<div class="chart-header">
|
||||
<span class="chart-header-title"><el-icon><Money /></el-icon> 近30天收入趋势</span>
|
||||
<span class="chart-header-meta">总收入 <b>¥{{ rev30Total }}</b></span>
|
||||
</div>
|
||||
</template>
|
||||
<div ref="rev30Ref" :style="{ height: isMobile ? '200px' : '240px' }"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :xs="24" :md="12">
|
||||
<el-card shadow="hover" class="chart-card" v-if="data.auth_trend_30">
|
||||
<template #header>
|
||||
<div class="chart-header">
|
||||
<span class="chart-header-title"><el-icon><UserFilled /></el-icon> 近30天新增授权</span>
|
||||
<span class="chart-header-meta">总新增 <b>{{ auth30Total }}</b></span>
|
||||
</div>
|
||||
</template>
|
||||
<div ref="auth30Ref" :style="{ height: isMobile ? '200px' : '240px' }"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 套餐销售占比 -->
|
||||
<el-row :gutter="10" style="margin-top:12px" v-if="data && data.package_distribution && data.package_distribution.length">
|
||||
<el-col :span="24">
|
||||
<el-card shadow="hover" class="chart-card">
|
||||
<template #header>
|
||||
<div class="chart-header">
|
||||
<span class="chart-header-title"><el-icon><PieChart /></el-icon> 套餐销售占比</span>
|
||||
<span class="chart-header-meta">按已支付订单金额</span>
|
||||
</div>
|
||||
</template>
|
||||
<div ref="pieRef" :style="{ height: isMobile ? '220px' : '280px' }"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -35,7 +77,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { ref, computed, onMounted, onUnmounted, nextTick } from 'vue'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import request from '@/api'
|
||||
import * as echarts from 'echarts'
|
||||
@@ -43,26 +85,19 @@ import * as echarts from 'echarts'
|
||||
const userStore = useUserStore()
|
||||
const user = computed(() => userStore.user)
|
||||
const data = ref(null)
|
||||
const chartRef = ref(null)
|
||||
const chart7Ref = ref(null)
|
||||
const rev30Ref = ref(null)
|
||||
const auth30Ref = ref(null)
|
||||
const pieRef = ref(null)
|
||||
|
||||
const isMobile = ref(window.innerWidth < 768)
|
||||
|
||||
function handleResize() {
|
||||
isMobile.value = window.innerWidth < 768
|
||||
}
|
||||
function handleResize() { isMobile.value = window.innerWidth < 768 }
|
||||
|
||||
const iconMap = {
|
||||
'项目总数': 'FolderOpened',
|
||||
'卡密总数': 'Tickets',
|
||||
'总订单': 'Document',
|
||||
'总收入': 'Money',
|
||||
'今日收入': 'Coin',
|
||||
'用户总数': 'UserFilled',
|
||||
'已使用卡密': 'CircleCheck',
|
||||
'代理总数': 'Avatar',
|
||||
'可用额度': 'Wallet',
|
||||
'卡密总数': 'Tickets',
|
||||
'今日生成': 'TrendCharts',
|
||||
'项目总数': 'FolderOpened', '卡密总数': 'Tickets', '总订单': 'Document',
|
||||
'总收入': 'Money', '今日收入': 'Coin', '用户总数': 'UserFilled',
|
||||
'已使用卡密': 'CircleCheck', '代理总数': 'Avatar', '可用额度': 'Wallet',
|
||||
'今日生成': 'TrendCharts', '即将过期': 'WarningFilled',
|
||||
}
|
||||
|
||||
const statCards = computed(() => {
|
||||
@@ -84,6 +119,10 @@ const statCards = computed(() => {
|
||||
{ label: '卡密总数', value: d.total_authorized || 0, color: '#67C23A' },
|
||||
{ label: '今日生成', value: d.today_authorized || 0, color: '#E6A23C' },
|
||||
]
|
||||
// 如果有即将过期数据,插入第一行
|
||||
if (d.expiring_soon !== undefined && d.expiring_soon > 0) {
|
||||
cards.unshift({ label: '即将过期', value: d.expiring_soon + ' 个', color: '#F56C6C' })
|
||||
}
|
||||
return cards.map(c => ({ ...c, icon: iconMap[c.label] || 'Odometer' }))
|
||||
})
|
||||
|
||||
@@ -91,225 +130,156 @@ const trendSummary = computed(() => {
|
||||
const trend = data.value?.order_trend || []
|
||||
const orders = trend.reduce((s, t) => s + (t.count || 0), 0)
|
||||
const amount = trend.reduce((s, t) => s + (parseFloat(t.amount) || 0), 0)
|
||||
return {
|
||||
total_orders: orders,
|
||||
total_amount: amount.toFixed(2)
|
||||
}
|
||||
return { total_orders: orders, total_amount: amount.toFixed(2) }
|
||||
})
|
||||
const rev30Total = computed(() => {
|
||||
const tr = data.value?.revenue_trend_30 || []
|
||||
const total = tr.reduce((s, t) => s + (parseFloat(t.amount) || 0), 0)
|
||||
return '¥' + total.toFixed(2)
|
||||
})
|
||||
const auth30Total = computed(() => {
|
||||
const tr = data.value?.auth_trend_30 || []
|
||||
return tr.reduce((s, t) => s + (t.count || 0), 0)
|
||||
})
|
||||
|
||||
let chart7Instance = null, rev30Instance = null, auth30Instance = null, pieInstance = null
|
||||
|
||||
onMounted(async () => {
|
||||
window.addEventListener('resize', handleResize)
|
||||
try {
|
||||
const res = await request.get('/dashboard')
|
||||
data.value = res.data
|
||||
if (data.value?.order_trend) {
|
||||
renderChart()
|
||||
}
|
||||
await nextTick()
|
||||
if (data.value?.order_trend) render7DayChart()
|
||||
if (data.value?.revenue_trend_30) renderRev30Chart()
|
||||
if (data.value?.auth_trend_30) renderAuth30Chart()
|
||||
if (data.value?.package_distribution) renderPieChart()
|
||||
} catch (e) { /* handled */ }
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', handleResize)
|
||||
chart7Instance?.dispose()
|
||||
rev30Instance?.dispose()
|
||||
auth30Instance?.dispose()
|
||||
pieInstance?.dispose()
|
||||
})
|
||||
|
||||
function renderChart() {
|
||||
if (!chartRef.value) return
|
||||
const chart = echarts.init(chartRef.value)
|
||||
const trend = data.value.order_trend
|
||||
const dates = trend.map(t => t.date)
|
||||
const counts = trend.map(t => t.count || 0)
|
||||
const amounts = trend.map(t => parseFloat(t.amount) || 0)
|
||||
function makeBarLineChart(domRef, dates, counts, amounts, countName, amountName) {
|
||||
const el = domRef.value
|
||||
if (!el) return
|
||||
const chart = echarts.init(el)
|
||||
const hasData = amounts.some(v => v > 0)
|
||||
|
||||
chart.setOption({
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
axisPointer: { type: 'cross', crossStyle: { color: '#999' } },
|
||||
axisPointer: { type: 'cross' },
|
||||
backgroundColor: 'rgba(255,255,255,0.96)',
|
||||
borderColor: '#e2e8f0',
|
||||
borderWidth: 1,
|
||||
borderColor: '#e2e8f0', borderWidth: 1,
|
||||
textStyle: { color: '#333', fontSize: 12 },
|
||||
formatter: (params) => {
|
||||
const bar = params[0], line = params[1]
|
||||
return `
|
||||
<div style="font-weight:600;margin-bottom:4px;font-size:13px">${bar.axisValue}</div>
|
||||
<div style="display:flex;align-items:center;gap:6px;margin:3px 0">
|
||||
<span style="display:inline-block;width:8px;height:8px;border-radius:2px;background:${bar.color};flex-shrink:0"></span>
|
||||
<span>订单数:<b>${bar.value}</b> 单</span>
|
||||
</div>
|
||||
<div style="display:flex;align-items:center;gap:6px;margin:3px 0">
|
||||
<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:${line.color};flex-shrink:0"></span>
|
||||
<span>金额:<b>¥${line.value.toFixed(2)}</b></span>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
data: ['订单数', '金额'],
|
||||
bottom: 0,
|
||||
textStyle: { fontSize: 11, color: '#94a3b8' },
|
||||
itemWidth: 12,
|
||||
itemHeight: 8,
|
||||
itemGap: 20
|
||||
},
|
||||
legend: { data: [countName, amountName], bottom: 0, textStyle: { fontSize: 11, color: '#94a3b8' }, itemWidth: 12, itemHeight: 8, itemGap: 20 },
|
||||
grid: { left: '3%', right: '4%', top: 8, bottom: 30, containLabel: true },
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: dates,
|
||||
axisLine: { lineStyle: { color: '#e2e8f0' } },
|
||||
axisTick: { show: false },
|
||||
axisLabel: { fontSize: 10, color: '#94a3b8' }
|
||||
},
|
||||
xAxis: { type: 'category', data: dates, axisLine: { lineStyle: { color: '#e2e8f0' } }, axisTick: { show: false }, axisLabel: { fontSize: 10, color: '#94a3b8' } },
|
||||
yAxis: [
|
||||
{
|
||||
type: 'value',
|
||||
min: 0,
|
||||
name: '单',
|
||||
nameTextStyle: { fontSize: 10, color: '#94a3b8', padding: [0, 0, 0, 0] },
|
||||
axisLabel: { fontSize: 10, color: '#94a3b8' },
|
||||
splitLine: { lineStyle: { color: '#f1f5f9', type: 'dashed' } },
|
||||
axisLine: { show: false },
|
||||
axisTick: { show: false }
|
||||
},
|
||||
{
|
||||
type: 'value',
|
||||
min: 0,
|
||||
name: '元',
|
||||
nameTextStyle: { fontSize: 10, color: '#94a3b8', padding: [0, 0, 0, 0] },
|
||||
axisLabel: { fontSize: 10, color: '#94a3b8' },
|
||||
splitLine: { show: false },
|
||||
axisLine: { show: false },
|
||||
axisTick: { show: false }
|
||||
}
|
||||
{ type: 'value', min: 0, name: countName, nameTextStyle: { fontSize: 10, color: '#94a3b8' }, axisLabel: { fontSize: 10, color: '#94a3b8' }, splitLine: { lineStyle: { color: '#f1f5f9', type: 'dashed' } }, axisLine: { show: false }, axisTick: { show: false } },
|
||||
{ type: 'value', min: 0, name: amountName, nameTextStyle: { fontSize: 10, color: '#94a3b8' }, axisLabel: { fontSize: 10, color: '#94a3b8' }, splitLine: { show: false }, axisLine: { show: false }, axisTick: { show: false } },
|
||||
],
|
||||
series: [
|
||||
{
|
||||
name: '订单数',
|
||||
type: 'bar',
|
||||
data: counts,
|
||||
barWidth: 16,
|
||||
itemStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||
{ offset: 0, color: '#6366f1' },
|
||||
{ offset: 1, color: '#a5b4fc' }
|
||||
]),
|
||||
borderRadius: [6, 6, 0, 0],
|
||||
borderColor: 'transparent'
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||
{ offset: 0, color: '#4f46e5' },
|
||||
{ offset: 1, color: '#818cf8' }
|
||||
])
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: '金额',
|
||||
type: 'line',
|
||||
yAxisIndex: 1,
|
||||
smooth: hasData,
|
||||
data: amounts,
|
||||
symbol: 'circle',
|
||||
symbolSize: 6,
|
||||
showSymbol: false,
|
||||
itemStyle: { color: '#f59e0b' },
|
||||
lineStyle: { width: 2, color: '#f59e0b' },
|
||||
areaStyle: hasData ? {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||
{ offset: 0, color: 'rgba(245,158,11,0.18)' },
|
||||
{ offset: 1, color: 'rgba(245,158,11,0.01)' }
|
||||
])
|
||||
} : undefined,
|
||||
emphasis: {
|
||||
focus: 'series',
|
||||
itemStyle: { borderWidth: 2, borderColor: '#fff' }
|
||||
}
|
||||
}
|
||||
{ name: countName, type: 'bar', data: counts, barWidth: 16, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#6366f1' }, { offset: 1, color: '#a5b4fc' }]), borderRadius: [6, 6, 0, 0] } },
|
||||
{ name: amountName, type: 'line', yAxisIndex: 1, smooth: hasData, data: amounts, symbol: 'circle', symbolSize: 6, showSymbol: false, itemStyle: { color: '#f59e0b' }, lineStyle: { width: 2, color: '#f59e0b' }, areaStyle: hasData ? { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: 'rgba(245,158,11,0.18)' }, { offset: 1, color: 'rgba(245,158,11,0.01)' }]) } : undefined },
|
||||
]
|
||||
})
|
||||
window.addEventListener('resize', () => chart.resize())
|
||||
return chart
|
||||
}
|
||||
|
||||
function render7DayChart() {
|
||||
chart7Instance?.dispose()
|
||||
const trend = data.value.order_trend
|
||||
chart7Instance = makeBarLineChart(chart7Ref,
|
||||
trend.map(t => t.date),
|
||||
trend.map(t => t.count || 0),
|
||||
trend.map(t => parseFloat(t.amount) || 0),
|
||||
'订单数', '金额'
|
||||
)
|
||||
}
|
||||
|
||||
function renderRev30Chart() {
|
||||
rev30Instance?.dispose()
|
||||
const trend = data.value.revenue_trend_30
|
||||
const dates = trend.map(t => t.date)
|
||||
const amounts = trend.map(t => parseFloat(t.amount) || 0)
|
||||
const el = rev30Ref.value
|
||||
if (!el) return
|
||||
rev30Instance = echarts.init(el)
|
||||
rev30Instance.setOption({
|
||||
tooltip: { trigger: 'axis', backgroundColor: 'rgba(255,255,255,0.96)', borderColor: '#e2e8f0', borderWidth: 1, textStyle: { color: '#333', fontSize: 12 } },
|
||||
grid: { left: '3%', right: '4%', top: 8, bottom: 20, containLabel: true },
|
||||
xAxis: { type: 'category', data: dates, axisLine: { lineStyle: { color: '#e2e8f0' } }, axisTick: { show: false }, axisLabel: { fontSize: 10, color: '#94a3b8', rotate: dates.length > 15 ? 45 : 0 } },
|
||||
yAxis: { type: 'value', min: 0, axisLabel: { fontSize: 10, color: '#94a3b8' }, splitLine: { lineStyle: { color: '#f1f5f9', type: 'dashed' } } },
|
||||
series: [{
|
||||
type: 'bar', data: amounts, barWidth: 12,
|
||||
itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#22c55e' }, { offset: 1, color: '#86efac' }]), borderRadius: [4, 4, 0, 0] }
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
function renderAuth30Chart() {
|
||||
auth30Instance?.dispose()
|
||||
const trend = data.value.auth_trend_30
|
||||
const dates = trend.map(t => t.date)
|
||||
const counts = trend.map(t => t.count || 0)
|
||||
const el = auth30Ref.value
|
||||
if (!el) return
|
||||
auth30Instance = echarts.init(el)
|
||||
auth30Instance.setOption({
|
||||
tooltip: { trigger: 'axis', backgroundColor: 'rgba(255,255,255,0.96)', borderColor: '#e2e8f0', borderWidth: 1, textStyle: { color: '#333', fontSize: 12 } },
|
||||
grid: { left: '3%', right: '4%', top: 8, bottom: 20, containLabel: true },
|
||||
xAxis: { type: 'category', data: dates, axisLine: { lineStyle: { color: '#e2e8f0' } }, axisTick: { show: false }, axisLabel: { fontSize: 10, color: '#94a3b8', rotate: dates.length > 15 ? 45 : 0 } },
|
||||
yAxis: { type: 'value', min: 0, axisLabel: { fontSize: 10, color: '#94a3b8' }, splitLine: { lineStyle: { color: '#f1f5f9', type: 'dashed' } } },
|
||||
series: [{
|
||||
type: 'line', smooth: true, data: counts, symbol: 'circle', symbolSize: 4,
|
||||
itemStyle: { color: '#3b82f6' }, lineStyle: { width: 2, color: '#3b82f6' },
|
||||
areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: 'rgba(59,130,246,0.2)' }, { offset: 1, color: 'rgba(59,130,246,0.01)' }]) }
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
function renderPieChart() {
|
||||
pieInstance?.dispose()
|
||||
const pieData = data.value.package_distribution
|
||||
const el = pieRef.value
|
||||
if (!el) return
|
||||
pieInstance = echarts.init(el)
|
||||
pieInstance.setOption({
|
||||
tooltip: { trigger: 'item', backgroundColor: 'rgba(255,255,255,0.96)', borderColor: '#e2e8f0', borderWidth: 1, textStyle: { color: '#333', fontSize: 12 }, formatter: '{b}: ¥{c} ({d}%)' },
|
||||
legend: { bottom: 0, textStyle: { fontSize: 11, color: '#94a3b8' }, itemWidth: 10, itemHeight: 10 },
|
||||
series: [{
|
||||
type: 'pie', radius: ['50%', '75%'], center: ['50%', '45%'], avoidLabelOverlap: false,
|
||||
itemStyle: { borderRadius: 6, borderColor: '#fff', borderWidth: 3 },
|
||||
label: { show: false },
|
||||
emphasis: { label: { show: true, fontSize: 13, fontWeight: 'bold' } },
|
||||
data: pieData.map(p => ({ name: p.name, value: parseFloat(p.amount) || 0 })),
|
||||
color: ['#3b82f6', '#22c55e', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899', '#06b6d4', '#6366f1']
|
||||
}]
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.stat-card {
|
||||
border-radius: 8px;
|
||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
margin-bottom: 6px;
|
||||
border: 1px solid #f0f0f0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.stat-card :deep(.el-card__body) {
|
||||
padding: 10px 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
.stat-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08) !important;
|
||||
border-color: #e0e0e0;
|
||||
}
|
||||
.stat-icon {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.stat-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.stat-value {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
color: #1e293b;
|
||||
line-height: 1.2;
|
||||
font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
|
||||
}
|
||||
.stat-label {
|
||||
color: #94a3b8;
|
||||
font-size: 11px;
|
||||
margin-top: 1px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.chart-card {
|
||||
border-radius: 8px;
|
||||
}
|
||||
.chart-card :deep(.el-card__body) {
|
||||
padding: 12px 14px;
|
||||
}
|
||||
.chart-card :deep(.el-card__header) {
|
||||
padding: 10px 14px;
|
||||
}
|
||||
.chart-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.chart-header-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.chart-header-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 11px;
|
||||
color: #94a3b8;
|
||||
}
|
||||
.chart-header-meta b {
|
||||
color: #475569;
|
||||
}
|
||||
.chart-meta-divider {
|
||||
color: #e2e8f0;
|
||||
}
|
||||
</style>
|
||||
.stat-card { border-radius:8px; transition:all .25s; margin-bottom:6px; border:1px solid #f0f0f0; overflow:hidden; }
|
||||
.stat-card :deep(.el-card__body) { padding:10px 12px; display:flex; align-items:center; gap:10px; }
|
||||
.stat-card:hover { transform:translateY(-2px); box-shadow:0 4px 16px rgba(0,0,0,.08)!important; border-color:#e0e0e0; }
|
||||
.stat-icon { width:34px; height:34px; border-radius:8px; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
|
||||
.stat-info { flex:1; min-width:0; }
|
||||
.stat-value { font-size:18px; font-weight:700; color:#1e293b; line-height:1.2; }
|
||||
.stat-label { color:#94a3b8; font-size:11px; margin-top:1px; white-space:nowrap; }
|
||||
.chart-card { border-radius:8px; }
|
||||
.chart-card :deep(.el-card__body) { padding:12px 14px; }
|
||||
.chart-card :deep(.el-card__header) { padding:10px 14px; }
|
||||
.chart-header { display:flex; align-items:center; justify-content:space-between; }
|
||||
.chart-header-title { font-size:13px; font-weight:600; display:flex; align-items:center; gap:4px; }
|
||||
.chart-header-meta { display:flex; align-items:center; gap:8px; font-size:11px; color:#94a3b8; }
|
||||
.chart-header-meta b { color:#475569; }
|
||||
.chart-meta-divider { color:#e2e8f0; }
|
||||
</style>
|
||||
@@ -79,6 +79,61 @@
|
||||
</el-form>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- SMTP 邮件配置 -->
|
||||
<el-tab-pane name="smtp" label="SMTP邮件配置">
|
||||
<template #label>
|
||||
<span><el-icon><Message /></el-icon> SMTP邮件配置</span>
|
||||
</template>
|
||||
<el-card shadow="never" class="config-card" v-loading="smtpLoading">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>SMTP 邮件服务器</span>
|
||||
<el-switch v-model="smtpForm.smtp_enabled" active-text="启用" inactive-text="禁用" :active-value="'1'" :inactive-value="'0'" inline-prompt style="--el-switch-on-color:#22c55e" />
|
||||
</div>
|
||||
</template>
|
||||
<el-form ref="smtpFormRef" :model="smtpForm" label-width="140px" label-position="right">
|
||||
<el-form-item label="SMTP 服务器" prop="smtp_host">
|
||||
<el-input v-model="smtpForm.smtp_host" placeholder="如 smtp.qq.com" />
|
||||
</el-form-item>
|
||||
<el-form-item label="端口" prop="smtp_port">
|
||||
<el-input-number v-model="smtpForm.smtp_port" :min="1" :max="65535" />
|
||||
<span class="form-tip">SSL 通常 465,TLS 通常 587</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="加密方式" prop="smtp_encryption">
|
||||
<el-radio-group v-model="smtpForm.smtp_encryption">
|
||||
<el-radio value="ssl">SSL</el-radio>
|
||||
<el-radio value="tls">TLS</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="用户名" prop="smtp_user">
|
||||
<el-input v-model="smtpForm.smtp_user" placeholder="如 123456@qq.com" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="smtp_pass">
|
||||
<el-input v-model="smtpForm.smtp_pass" type="password" show-password placeholder="QQ邮箱需使用授权码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="发件人邮箱" prop="smtp_from_email">
|
||||
<el-input v-model="smtpForm.smtp_from_email" placeholder="留空则使用用户名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="发件人名称" prop="smtp_from_name">
|
||||
<el-input v-model="smtpForm.smtp_from_name" placeholder="CardAuth" maxlength="50" />
|
||||
</el-form-item>
|
||||
<el-form-item label="提前提醒天数" prop="smtp_expire_days">
|
||||
<el-input-number v-model="smtpForm.smtp_expire_days" :min="1" :max="30" />
|
||||
<span class="form-tip">授权到期前 N 天发送邮件到联系人 QQ 邮箱</span>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="smtpSubmitting" @click="handleSaveSmtp" :icon="Check">保存配置</el-button>
|
||||
<el-button @click="fetchSmtpConfig" :icon="RefreshRight">重置</el-button>
|
||||
<el-popconfirm title="将向此地址发送测试邮件" @confirm="handleTestSmtp">
|
||||
<template #reference>
|
||||
<el-button :loading="smtpTesting" :icon="Promotion">发送测试邮件</el-button>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</template>
|
||||
@@ -86,7 +141,7 @@
|
||||
<script setup>
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { OfficeBuilding, User, Check, RefreshRight } from '@element-plus/icons-vue'
|
||||
import { OfficeBuilding, User, Check, RefreshRight, Message, Promotion } from '@element-plus/icons-vue'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import request from '@/api'
|
||||
|
||||
@@ -134,6 +189,7 @@ const roleText = computed(() => {
|
||||
onMounted(() => {
|
||||
fetchSiteConfig()
|
||||
fetchProfile()
|
||||
fetchSmtpConfig()
|
||||
})
|
||||
|
||||
async function fetchSiteConfig() {
|
||||
@@ -214,19 +270,100 @@ async function handleSaveProfile() {
|
||||
finally { profileSubmitting.value = false }
|
||||
})
|
||||
}
|
||||
|
||||
// ========== SMTP 配置 ==========
|
||||
const smtpFormRef = ref(null)
|
||||
const smtpLoading = ref(false)
|
||||
const smtpSubmitting = ref(false)
|
||||
const smtpTesting = ref(false)
|
||||
const smtpForm = ref({
|
||||
smtp_host: '',
|
||||
smtp_port: 465,
|
||||
smtp_user: '',
|
||||
smtp_pass: '',
|
||||
smtp_encryption: 'ssl',
|
||||
smtp_from_email: '',
|
||||
smtp_from_name: 'CardAuth',
|
||||
smtp_enabled: '0',
|
||||
smtp_expire_days: 7,
|
||||
})
|
||||
|
||||
async function fetchSmtpConfig() {
|
||||
smtpLoading.value = true
|
||||
try {
|
||||
const res = await request.get('/system/smtp-config')
|
||||
const data = res.data || {}
|
||||
smtpForm.value.smtp_host = data.smtp_host || ''
|
||||
smtpForm.value.smtp_port = parseInt(data.smtp_port || '465', 10)
|
||||
smtpForm.value.smtp_user = data.smtp_user || ''
|
||||
smtpForm.value.smtp_pass = data.smtp_pass || ''
|
||||
smtpForm.value.smtp_encryption = data.smtp_encryption || 'ssl'
|
||||
smtpForm.value.smtp_from_email = data.smtp_from_email || ''
|
||||
smtpForm.value.smtp_from_name = data.smtp_from_name || 'CardAuth'
|
||||
smtpForm.value.smtp_enabled = data.smtp_enabled || '0'
|
||||
smtpForm.value.smtp_expire_days = parseInt(data.smtp_expire_days || '7', 10)
|
||||
} catch (e) { /* */ }
|
||||
finally { smtpLoading.value = false }
|
||||
}
|
||||
|
||||
async function handleSaveSmtp() {
|
||||
smtpSubmitting.value = true
|
||||
try {
|
||||
await request.post('/system/smtp-config', smtpForm.value)
|
||||
ElMessage.success('SMTP 配置保存成功')
|
||||
} catch (e) { /* */ }
|
||||
finally { smtpSubmitting.value = false }
|
||||
}
|
||||
|
||||
async function handleTestSmtp() {
|
||||
smtpTesting.value = true
|
||||
try {
|
||||
const adminEmail = user.value?.email || smtpForm.value.smtp_user
|
||||
if (!adminEmail) {
|
||||
ElMessage.warning('请先完善当前管理员邮箱,或填写 SMTP 用户名')
|
||||
return
|
||||
}
|
||||
await request.post('/system/test-smtp', { test_email: adminEmail })
|
||||
ElMessage.success('测试邮件发送成功,请检查收件箱')
|
||||
} catch (e) { /* */ }
|
||||
finally { smtpTesting.value = false }
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-container {
|
||||
max-width: 900px;
|
||||
}
|
||||
.system-tabs :deep(.el-tabs__content) {
|
||||
padding: 0;
|
||||
.system-tabs :deep(.el-tabs__content) { padding:0; }
|
||||
|
||||
/* Tab 切换动画 */
|
||||
.system-tabs :deep(.el-tab-pane) {
|
||||
animation: tabFadeIn .35s cubic-bezier(.4,0,.2,1);
|
||||
}
|
||||
@keyframes tabFadeIn {
|
||||
from { opacity:0; transform:translateY(10px); }
|
||||
to { opacity:1; transform:translateY(0); }
|
||||
}
|
||||
|
||||
/* 导航条激活指示器过渡 */
|
||||
.system-tabs :deep(.el-tabs__active-bar) {
|
||||
transition: transform .3s cubic-bezier(.4,0,.2,1), width .3s cubic-bezier(.4,0,.2,1) !important;
|
||||
}
|
||||
/* 标签项 hover 过渡 */
|
||||
.system-tabs :deep(.el-tabs__item) {
|
||||
transition: color .25s ease !important;
|
||||
}
|
||||
.system-tabs :deep(.el-tabs__item:hover) {
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.config-card {
|
||||
border-radius: 8px;
|
||||
margin-top: -1px;
|
||||
}
|
||||
.config-card:deep(.el-card__body) {
|
||||
transition: padding .3s ease;
|
||||
}
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
Reference in new issue
Block a user