feat: 新增账号状态管理、头像功能与报表工具,完善账号系统
新增账号状态字段与停用校验,支持账号头像上传管理,新增物料收发汇总表合并工具,优化银行卡检查脚本,新增ERP登录复用模块,重构账号数据库迁移与管理接口
This commit is contained in:
@@ -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>刷新
|
||||
|
||||
Reference in New Issue
Block a user