feat: 新增账号状态管理、头像功能与报表工具,完善账号系统

新增账号状态字段与停用校验,支持账号头像上传管理,新增物料收发汇总表合并工具,优化银行卡检查脚本,新增ERP登录复用模块,重构账号数据库迁移与管理接口
This commit is contained in:
2026-09-16 00:25:13 +08:00
parent 0ab43d0ed8
commit 813bee743b
27 changed files with 2533 additions and 268 deletions
+3 -3
View File
@@ -14,7 +14,7 @@
<n-dropdown trigger="click" :options="acctOptions" @select="onCommand">
<div class="acct">
<span class="avatar">{{ initial }}</span>
<span class="acct-name">{{ store.current }}</span>
<span class="acct-name">{{ store.nickname || store.current }}</span>
<n-tag v-if="store.isAdmin" size="small" round :bordered="false" type="primary" class="admin-tag">管理员</n-tag>
<n-icon class="caret" :size="13"><ArrowDown /></n-icon>
</div>
@@ -99,7 +99,7 @@ function onMenu(key) {
route.value = h
}
const initial = computed(() => (store.current || '')[0]?.toUpperCase() || '?')
const initial = computed(() => (store.nickname || store.current || '')[0]?.toUpperCase() || '?')
const pwdOpen = ref(false)
function onCommand(cmd) {
@@ -121,7 +121,7 @@ onMounted(async () => {
try {
const me = await adminMe()
if (!me.account || !me.is_admin) clearSession()
else store.isAdmin = true
else { store.isAdmin = true; store.nickname = me.nickname || '' }
} catch (_) { /* 后端 down:保持本地态 */ }
})
</script>
+6
View File
@@ -84,6 +84,12 @@ export async function adminAccountDelete(body) {
body: JSON.stringify(body)
})
}
export async function adminAvatarUpload(account, file) {
const fd = new FormData()
fd.append('file', file)
const qs = new URLSearchParams({ account })
return req('/api/admin/avatar?' + qs.toString(), { method: 'POST', headers: adminHeaders(), body: fd })
}
export async function adminPluginDelete(body) {
return req('/api/admin/plugin/delete', {
method: 'POST',
@@ -70,8 +70,9 @@ async function doLogin() {
store.current = acct
store.token = r.token || ''
store.isAdmin = true
store.nickname = r.nickname || ''
try { localStorage.setItem('cp_account', acct); localStorage.setItem('cp_token', store.token) } catch (_) {}
message.success(`欢迎,${acct}`)
message.success(`欢迎,${store.nickname || acct}`)
emit('ok', r)
} catch (e) {
message.error(e.message || String(e))
@@ -6,6 +6,7 @@ export const store = reactive({
isAdmin: false,
current: _get('cp_account'),
token: _get('cp_token'),
nickname: '',
})
// 概览数据缓存:各管理页共用一份 adminOverview 结果,避免切页重复拉取
@@ -35,6 +36,7 @@ export function clearSession() {
store.current = ''
store.token = ''
store.isAdmin = false
store.nickname = ''
resetOverview()
try { localStorage.removeItem('cp_account'); localStorage.removeItem('cp_token') } catch (_) {}
}
@@ -73,7 +73,7 @@ import { computed, h, onMounted, reactive, ref } from 'vue'
import { NButton, NInput, NSwitch, NTag } from 'naive-ui'
import { Refresh, Plus } from '@element-plus/icons-vue'
import { store, overview, overviewBusy, loadOverview } from '../store'
import { adminAccountCreate, adminAccountUpdate, adminAccountReset, adminAccountDelete } from '../api'
import { adminAccountCreate, adminAccountUpdate, adminAccountReset, adminAccountDelete, adminAvatarUpload } from '../api'
import { message, dialog } from '../naive'
const current = computed(() => store.current || '')
@@ -118,6 +118,45 @@ async function toggleAdmin(row) {
try { await adminAccountUpdate({ account: row.account, is_admin: !row.is_admin }); await refresh() }
catch (e) { message.error(e.message || e) }
}
async function toggleStatus(row, v) {
if (row.account === current.value && !v) { message.warning('不能停用当前登录的账号'); return }
try { await adminAccountUpdate({ account: row.account, status: v }); await refresh() }
catch (e) { message.error(e.message || e) }
}
// ---------- 头像(显示 + 上传) ----------
const _fileInput = (() => {
const el = document.createElement('input')
el.type = 'file'
el.accept = 'image/*'
return el
})()
function pickAvatar(row) {
_fileInput.onchange = async () => {
const f = _fileInput.files && _fileInput.files[0]
_fileInput.value = ''
if (!f) return
try {
await adminAvatarUpload(row.account, f)
message.success(`已更新 ${row.account} 的头像`)
await refresh()
} catch (e) { message.error(e.message || e) }
}
_fileInput.click()
}
function avatarCell(row) {
const img = row.avatar
? h('img', {
src: `/api/avatar/${row.account}?v=${encodeURIComponent(row.avatar)}`,
class: 'cell-avatar',
onError: (e) => { e.target.style.display = 'none' },
})
: h('span', { class: 'dim' }, '—')
return h('div', { class: 'cell-avatar-wrap' }, [
img,
h(NButton, { text: true, size: 'tiny', type: 'primary', onClick: () => pickAvatar(row) }, { default: () => '上传' }),
])
}
function renderTags(list, kind) {
if (!list || !list.length) return h('span', { class: 'dim' }, '—')
@@ -128,22 +167,30 @@ function renderTags(list, kind) {
}
const columns = computed(() => [
{ title: '账号', key: 'account', width: 140, render: r => h('b', { class: 'cell-strong' }, r.account) },
{ title: '昵称', key: 'nickname', width: 150, render: r => inlineInput(r, 'nickname') },
{ title: 'ID', key: 'id', width: 64, render: r => h('span', { class: 'dim' }, r.id ?? '—') },
{ title: '用户名(工号)', key: 'account', width: 130, render: r => h('b', { class: 'cell-strong' }, r.account) },
{ title: '昵称(姓名)', key: 'nickname', width: 130, render: r => inlineInput(r, 'nickname') },
{ title: '部门', key: 'dept', width: 130, render: (row) => inlineInput(row, 'dept') },
{ title: '头像', key: 'avatar', width: 120, render: r => avatarCell(r) },
{
title: '部门', key: 'dept', width: 160,
render: (row) => inlineInput(row, 'dept'),
title: '状态', key: 'status', width: 90,
render: (row) => h(NSwitch, {
value: !!row.status,
disabled: row.account === current.value,
onUpdateValue: (v) => toggleStatus(row, v),
}),
},
{ title: '创建时间', key: 'created_at', width: 150, render: r => h('span', { class: 'dim' }, r.created_at || '—') },
{
title: '管理员', key: 'is_admin', width: 100,
title: '管理员', key: 'is_admin', width: 90,
render: (row) => h(NSwitch, {
value: !!row.is_admin,
disabled: row.account === current.value,
onUpdateValue: () => toggleAdmin(row),
}),
},
{ title: '已授权插件', key: 'plugins', minWidth: 180, render: r => renderTags(r.plugins, 'plugin') },
{ title: '已授权平台', key: 'platforms', minWidth: 140, render: r => renderTags(r.platforms, 'platform') },
{ title: '已授权插件', key: 'plugins', minWidth: 160, render: r => renderTags(r.plugins, 'plugin') },
{ title: '已授权平台', key: 'platforms', minWidth: 130, render: r => renderTags(r.platforms, 'platform') },
{
title: '操作', key: 'actions', width: 170,
render: (row) => h('div', { class: 'ops' }, [
@@ -237,4 +284,6 @@ onMounted(refresh)
<style>
.ops { display: flex; align-items: center; gap: 16px; }
.ops .n-button { padding: 0 4px; }
.cell-avatar-wrap { display: flex; align-items: center; gap: 8px; }
.cell-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #f2f3f7; flex: none; }
</style>
@@ -3,7 +3,7 @@
<div class="page-head cp-rise">
<div>
<h3>概览 <span class="badge">Dashboard</span></h3>
<p>中心机 · 插件分发与账号权限 · 当前账号 <b class="who">{{ store.current }}</b></p>
<p>中心机 · 插件分发与账号权限 · 当前账号 <b class="who">{{ store.nickname || store.current }}</b></p>
</div>
<n-button :loading="overviewBusy" @click="refresh">
<template #icon><n-icon><Refresh /></n-icon></template>刷新