build(desktop): 升级 electron-shell 版本至 1.6.3 并调整插件执行超时配置
- 插件执行超时默认延长至 6 小时,支持插件单独配置超时时间 - 新增插件根目录迁移逻辑,解决旧版权限问题 - 新增多个服务端实体、DTO、配置模块等基础代码 - 新增插件 UI 模板及相关静态资源
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 业务视图占位骨架(37du 控制台)
|
||||
* 每个业务页面独立实现后替换本组件;参数 title 用于识别当前视图
|
||||
*/
|
||||
defineProps<{ title?: string }>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header>
|
||||
<span class="font-semibold text-base">{{ title || '业务视图' }}</span>
|
||||
</template>
|
||||
<el-empty description="视图建设中(37du 控制台)" />
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,203 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 账号管理(37du 控制台)
|
||||
* 列表/搜索/新建/编辑/重置密码/删除,对接 /api/admin/accounts*
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
fetchAccounts, createAccount, updateAccount, resetAccountPwd, deleteAccount
|
||||
} from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
const total = ref(0)
|
||||
const query = reactive({ page: 1, page_size: 10, q: '' })
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetchAccounts(query)
|
||||
list.value = r.items || []
|
||||
total.value = r.total || 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
query.page = 1
|
||||
load()
|
||||
}
|
||||
|
||||
// ---- 新建/编辑 ----
|
||||
const dialogOpen = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const saving = ref(false)
|
||||
const form = reactive({ account: '', password: '', dept: '', nickname: '', is_admin: false, status: 1 })
|
||||
|
||||
function openCreate() {
|
||||
isEdit.value = false
|
||||
Object.assign(form, { account: '', password: '', dept: '', nickname: '', is_admin: false, status: 1 })
|
||||
dialogOpen.value = true
|
||||
}
|
||||
function openEdit(row: any) {
|
||||
isEdit.value = true
|
||||
Object.assign(form, {
|
||||
account: row.account, password: '', dept: row.dept || '', nickname: row.nickname || '',
|
||||
is_admin: !!row.is_admin, status: row.status
|
||||
})
|
||||
dialogOpen.value = true
|
||||
}
|
||||
async function submit() {
|
||||
if (!form.account) return ElMessage.warning('account 必填')
|
||||
if (!isEdit.value && (!form.password || form.password.length < 8)) {
|
||||
return ElMessage.warning('密码至少 8 位')
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
if (isEdit.value) {
|
||||
await updateAccount({ account: form.account, dept: form.dept, nickname: form.nickname, is_admin: form.is_admin, status: form.status })
|
||||
} else {
|
||||
await createAccount(form)
|
||||
}
|
||||
ElMessage.success('保存成功')
|
||||
dialogOpen.value = false
|
||||
load()
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 重置密码 ----
|
||||
const pwdOpen = ref(false)
|
||||
const pwdForm = reactive({ account: '', new_password: '' })
|
||||
function openReset(row: any) {
|
||||
Object.assign(pwdForm, { account: row.account, new_password: '' })
|
||||
pwdOpen.value = true
|
||||
}
|
||||
async function submitReset() {
|
||||
if (!pwdForm.new_password || pwdForm.new_password.length < 8) {
|
||||
return ElMessage.warning('新密码至少 8 位')
|
||||
}
|
||||
await resetAccountPwd({ account: pwdForm.account, new_password: pwdForm.new_password })
|
||||
ElMessage.success('密码已重置')
|
||||
pwdOpen.value = false
|
||||
}
|
||||
|
||||
// ---- 删除 ----
|
||||
async function remove(row: any) {
|
||||
await ElMessageBox.confirm(`确认删除账号「${row.account}」?`, '删除确认', { type: 'warning' })
|
||||
await deleteAccount(row.account)
|
||||
ElMessage.success('已删除')
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">账号管理</h2>
|
||||
<el-button type="primary" @click="openCreate">新建账号</el-button>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-form inline @submit.prevent="search">
|
||||
<el-form-item label="关键字">
|
||||
<el-input v-model="query.q" placeholder="账号 / 昵称 / 部门" clearable style="width: 240px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="Object.assign(query, { q: '' }); search()">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe>
|
||||
<el-table-column prop="account" label="账号" min-width="120" />
|
||||
<el-table-column prop="nickname" label="昵称" min-width="120" />
|
||||
<el-table-column prop="dept" label="部门" width="120" />
|
||||
<el-table-column label="管理员" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.is_admin" size="small" type="primary">管理员</el-tag>
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'danger'" size="small">
|
||||
{{ row.status === 1 ? '启用' : '停用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="插件授权" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.plugins?.length" size="small" type="info">{{ row.plugins.length }} 个</el-tag>
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="170" />
|
||||
<el-table-column label="操作" width="220" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="warning" @click="openReset(row)">重置密码</el-button>
|
||||
<el-button link type="danger" @click="remove(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<el-pagination
|
||||
v-model:current-page="query.page"
|
||||
v-model:page-size="query.page_size"
|
||||
:total="total"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="load"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 新建/编辑弹窗 -->
|
||||
<el-dialog v-model="dialogOpen" :title="isEdit ? '编辑账号' : '新建账号'" width="480px">
|
||||
<el-form label-width="90px">
|
||||
<el-form-item label="账号" required>
|
||||
<el-input v-model="form.account" :disabled="isEdit" placeholder="工号" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!isEdit" label="初始密码" required>
|
||||
<el-input v-model="form.password" type="password" show-password placeholder="至少 8 位" />
|
||||
</el-form-item>
|
||||
<el-form-item label="昵称">
|
||||
<el-input v-model="form.nickname" />
|
||||
</el-form-item>
|
||||
<el-form-item label="部门">
|
||||
<el-input v-model="form.dept" />
|
||||
</el-form-item>
|
||||
<el-form-item label="管理员">
|
||||
<el-switch v-model="form.is_admin" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="isEdit" label="状态">
|
||||
<el-switch v-model="form.status" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="停用" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogOpen = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 重置密码弹窗 -->
|
||||
<el-dialog v-model="pwdOpen" title="重置密码" width="420px">
|
||||
<el-form label-width="90px">
|
||||
<el-form-item label="账号">{{ pwdForm.account }}</el-form-item>
|
||||
<el-form-item label="新密码" required>
|
||||
<el-input v-model="pwdForm.new_password" type="password" show-password placeholder="至少 8 位" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="pwdOpen = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitReset">重置</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 审计报表(37du 控制台)
|
||||
* 分页 + 动作筛选 + 关键字(对接 /api/admin/audit)
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { fetchAudit } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
const total = ref(0)
|
||||
const today = ref(0)
|
||||
const query = reactive({ page: 1, page_size: 20, action: '', q: '' })
|
||||
|
||||
const actionOptions = ['account-create', 'account-update', 'account-reset-pwd', 'account-delete',
|
||||
'grant', 'revoke-grant', 'grant-platform', 'revoke-platform', 'plugin-publish', 'plugin-delete',
|
||||
'plugin-patch', 'shell-release', 'file-source-upsert', 'file-source-patch', 'file-source-delete',
|
||||
'creds-seed', 'notify-create', 'notify-toggle', 'notify-delete', 'download-ticket']
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetchAudit(query)
|
||||
list.value = r.items || []
|
||||
total.value = r.total || 0
|
||||
today.value = r.today || 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
query.page = 1
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">审计报表</h2>
|
||||
<el-tag type="info">今日 {{ today }} 条</el-tag>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-form inline @submit.prevent="search">
|
||||
<el-form-item label="动作">
|
||||
<el-select v-model="query.action" clearable placeholder="全部" style="width: 200px" @change="search">
|
||||
<el-option v-for="a in actionOptions" :key="a" :label="a" :value="a" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="关键字">
|
||||
<el-input v-model="query.q" placeholder="账号 / 对象 / 详情" clearable style="width: 220px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="Object.assign(query, { q: '', action: '' }); search()">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column label="操作者" width="120">
|
||||
<template #default="{ row }">{{ row.nickname || row.account || '系统' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="action" label="动作" min-width="150" />
|
||||
<el-table-column prop="target" label="对象" min-width="150" />
|
||||
<el-table-column prop="detail" label="详情" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="at" label="时间" width="170" />
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<el-pagination
|
||||
v-model:current-page="query.page"
|
||||
v-model:page-size="query.page_size"
|
||||
:total="total"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="load"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,62 @@
|
||||
<template>
|
||||
<div class="flex w-full h-screen">
|
||||
<LoginLeftView />
|
||||
|
||||
<div class="relative flex-1">
|
||||
<AuthTopBar />
|
||||
|
||||
<div class="auth-right-wrap">
|
||||
<div class="form">
|
||||
<h3 class="title">{{ $t('forgetPassword.title') }}</h3>
|
||||
<p class="sub-title">{{ $t('forgetPassword.subTitle') }}</p>
|
||||
<div class="mt-5">
|
||||
<span class="input-label" v-if="showInputLabel">账号</span>
|
||||
<ElInput
|
||||
class="custom-height"
|
||||
:placeholder="$t('forgetPassword.placeholder')"
|
||||
v-model.trim="username"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 15px">
|
||||
<ElButton
|
||||
class="w-full custom-height"
|
||||
type="primary"
|
||||
@click="register"
|
||||
:loading="loading"
|
||||
v-ripple
|
||||
>
|
||||
{{ $t('forgetPassword.submitBtnText') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 15px">
|
||||
<ElButton class="w-full custom-height" plain @click="toLogin">
|
||||
{{ $t('forgetPassword.backBtnText') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineOptions({ name: 'ForgetPassword' })
|
||||
|
||||
const router = useRouter()
|
||||
const showInputLabel = ref(false)
|
||||
|
||||
const username = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
const register = async () => {}
|
||||
|
||||
const toLogin = () => {
|
||||
router.push({ name: 'Login' })
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@import '../login/style.css';
|
||||
</style>
|
||||
@@ -0,0 +1,183 @@
|
||||
<!-- 登录页面(37du 重构版:统一账户 + 密码 → cool-admin /api/admin/auth) -->
|
||||
<template>
|
||||
<div class="flex w-full h-screen">
|
||||
<LoginLeftView />
|
||||
|
||||
<div class="relative flex-1">
|
||||
<AuthTopBar />
|
||||
|
||||
<div class="auth-right-wrap">
|
||||
<div class="form">
|
||||
<h3 class="title">{{ $t('login.title') }}</h3>
|
||||
<p class="sub-title">{{ $t('login.subTitle') }}</p>
|
||||
<ElForm
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
:key="formKey"
|
||||
@keyup.enter="handleSubmit"
|
||||
style="margin-top: 25px"
|
||||
>
|
||||
<ElFormItem prop="account">
|
||||
<ElInput
|
||||
class="custom-height"
|
||||
:placeholder="'工号 / 账号'"
|
||||
v-model.trim="formData.account"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem prop="password">
|
||||
<ElInput
|
||||
class="custom-height"
|
||||
:placeholder="$t('login.placeholder.password')"
|
||||
v-model.trim="formData.password"
|
||||
type="password"
|
||||
autocomplete="off"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
|
||||
<!-- 拖拽验证 -->
|
||||
<div class="relative pb-5 mt-6">
|
||||
<div
|
||||
class="relative z-[2] overflow-hidden select-none rounded-lg border border-transparent tad-300"
|
||||
:class="{ '!border-[#FF4E4F]': !isPassing && isClickPass }"
|
||||
>
|
||||
<ArtDragVerify
|
||||
ref="dragVerify"
|
||||
v-model:value="isPassing"
|
||||
:text="$t('login.sliderText')"
|
||||
textColor="var(--art-gray-700)"
|
||||
:successText="$t('login.sliderSuccessText')"
|
||||
progressBarBg="var(--main-color)"
|
||||
:background="isDark ? '#26272F' : '#F1F1F4'"
|
||||
handlerBg="var(--default-box-color)"
|
||||
/>
|
||||
</div>
|
||||
<p
|
||||
class="absolute top-0 z-[1] px-px mt-2 text-xs text-[#f56c6c] tad-300"
|
||||
:class="{ 'translate-y-10': !isPassing && isClickPass }"
|
||||
>
|
||||
{{ $t('login.placeholder.slider') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 30px">
|
||||
<ElButton
|
||||
class="w-full custom-height"
|
||||
type="primary"
|
||||
@click="handleSubmit"
|
||||
:loading="loading"
|
||||
v-ripple
|
||||
>
|
||||
{{ $t('login.btnText') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
</ElForm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { HttpError } from '@/utils/http/error'
|
||||
import { fetchLogin, fetchGetUserInfo, fetchUserMenus } from '@/api/auth'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { useSettingStore } from '@/store/modules/setting'
|
||||
|
||||
defineOptions({ name: 'Login' })
|
||||
|
||||
const settingStore = useSettingStore()
|
||||
const { isDark } = storeToRefs(settingStore)
|
||||
const { t, locale } = useI18n()
|
||||
const formKey = ref(0)
|
||||
|
||||
watch(locale, () => {
|
||||
formKey.value++
|
||||
})
|
||||
|
||||
const dragVerify = ref()
|
||||
const userStore = useUserStore()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const isPassing = ref(false)
|
||||
const isClickPass = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const formData = reactive({
|
||||
account: '',
|
||||
password: ''
|
||||
})
|
||||
|
||||
const rules = computed<FormRules>(() => ({
|
||||
account: [{ required: true, message: '请输入工号/账号', trigger: 'blur' }],
|
||||
password: [{ required: true, message: t('login.placeholder.password'), trigger: 'blur' }]
|
||||
}))
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
// 登录
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
if (!isPassing.value) {
|
||||
isClickPass.value = true
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
|
||||
const login = await fetchLogin({ account: formData.account, password: formData.password })
|
||||
if (!login.token) throw new Error('Login failed - no token received')
|
||||
|
||||
// 写入登录态(token + 用户信息)
|
||||
userStore.setLoginResult(login)
|
||||
userStore.checkAndClearWorktabs()
|
||||
|
||||
// 拉取用户信息 + 业务菜单/权限
|
||||
try {
|
||||
const [me, menus] = await Promise.all([fetchGetUserInfo(), fetchUserMenus()])
|
||||
userStore.setUserPerms(me, menus?.perms || [])
|
||||
} catch (e) {
|
||||
// 菜单拉取失败不阻断登录(刷新后重试)
|
||||
console.error('[Login] fetch me/menus failed:', e)
|
||||
}
|
||||
|
||||
// 初始密码强制改密提示
|
||||
if (login.must_change_pwd) {
|
||||
ElMessage.warning('首次登录请尽快修改初始密码')
|
||||
}
|
||||
|
||||
const redirect = route.query.redirect as string
|
||||
router.push(redirect || '/')
|
||||
} catch (error) {
|
||||
// 展示具体错误(如"账号或密码错误"),而非笼统提示
|
||||
if (error instanceof HttpError) {
|
||||
ElMessage.error(error.message)
|
||||
} else {
|
||||
console.error('[Login] Unexpected error:', error)
|
||||
ElMessage.error('登录失败,请稍后重试')
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
resetDragVerify()
|
||||
}
|
||||
}
|
||||
|
||||
const resetDragVerify = () => {
|
||||
dragVerify.value?.reset()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@import './style.css';
|
||||
</style>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-input__wrapper) {
|
||||
height: 40px !important;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,38 @@
|
||||
@reference '@styles/core/tailwind.css';
|
||||
|
||||
/* 授权页右侧区域 */
|
||||
.auth-right-wrap {
|
||||
@apply absolute inset-0 w-[440px] h-[650px] py-[5px] m-auto overflow-hidden
|
||||
max-sm:px-7 max-sm:w-full
|
||||
animate-[slideInRight_0.6s_cubic-bezier(0.25,0.46,0.45,0.94)_forwards]
|
||||
max-md:animate-none;
|
||||
|
||||
.form {
|
||||
@apply h-full py-[40px];
|
||||
}
|
||||
|
||||
.title {
|
||||
@apply text-g-900 text-4xl font-semibold max-md:text-3xl max-sm:pt-10;
|
||||
}
|
||||
|
||||
.sub-title {
|
||||
@apply mt-[10px] text-g-600 text-sm;
|
||||
}
|
||||
|
||||
.custom-height {
|
||||
@apply !h-[40px];
|
||||
}
|
||||
}
|
||||
|
||||
/* 滑入动画 */
|
||||
@keyframes slideInRight {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(30px);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
<!-- 注册页面 -->
|
||||
<template>
|
||||
<div class="flex w-full h-screen">
|
||||
<LoginLeftView />
|
||||
|
||||
<div class="relative flex-1">
|
||||
<AuthTopBar />
|
||||
|
||||
<div class="auth-right-wrap">
|
||||
<div class="form">
|
||||
<h3 class="title">{{ $t('register.title') }}</h3>
|
||||
<p class="sub-title">{{ $t('register.subTitle') }}</p>
|
||||
<ElForm
|
||||
class="mt-7.5"
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
label-position="top"
|
||||
:key="formKey"
|
||||
>
|
||||
<ElFormItem prop="username">
|
||||
<ElInput
|
||||
class="custom-height"
|
||||
v-model.trim="formData.username"
|
||||
:placeholder="$t('register.placeholder.username')"
|
||||
/>
|
||||
</ElFormItem>
|
||||
|
||||
<ElFormItem prop="password">
|
||||
<ElInput
|
||||
class="custom-height"
|
||||
v-model.trim="formData.password"
|
||||
:placeholder="$t('register.placeholder.password')"
|
||||
type="password"
|
||||
autocomplete="off"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
|
||||
<ElFormItem prop="confirmPassword">
|
||||
<ElInput
|
||||
class="custom-height"
|
||||
v-model.trim="formData.confirmPassword"
|
||||
:placeholder="$t('register.placeholder.confirmPassword')"
|
||||
type="password"
|
||||
autocomplete="off"
|
||||
@keyup.enter="register"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
|
||||
<ElFormItem prop="agreement">
|
||||
<ElCheckbox v-model="formData.agreement">
|
||||
{{ $t('register.agreeText') }}
|
||||
<RouterLink
|
||||
style="color: var(--theme-color); text-decoration: none"
|
||||
to="/privacy-policy"
|
||||
>{{ $t('register.privacyPolicy') }}</RouterLink
|
||||
>
|
||||
</ElCheckbox>
|
||||
</ElFormItem>
|
||||
|
||||
<div style="margin-top: 15px">
|
||||
<ElButton
|
||||
class="w-full custom-height"
|
||||
type="primary"
|
||||
@click="register"
|
||||
:loading="loading"
|
||||
v-ripple
|
||||
>
|
||||
{{ $t('register.submitBtnText') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 text-sm text-g-600">
|
||||
<span>{{ $t('register.hasAccount') }}</span>
|
||||
<RouterLink class="text-theme" :to="{ name: 'Login' }">{{
|
||||
$t('register.toLogin')
|
||||
}}</RouterLink>
|
||||
</div>
|
||||
</ElForm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
defineOptions({ name: 'Register' })
|
||||
|
||||
interface RegisterForm {
|
||||
username: string
|
||||
password: string
|
||||
confirmPassword: string
|
||||
agreement: boolean
|
||||
}
|
||||
|
||||
const USERNAME_MIN_LENGTH = 3
|
||||
const USERNAME_MAX_LENGTH = 20
|
||||
const PASSWORD_MIN_LENGTH = 6
|
||||
const REDIRECT_DELAY = 1000
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const loading = ref(false)
|
||||
const formKey = ref(0)
|
||||
|
||||
// 监听语言切换,重置表单
|
||||
watch(locale, () => {
|
||||
formKey.value++
|
||||
})
|
||||
|
||||
const formData = reactive<RegisterForm>({
|
||||
username: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
agreement: false
|
||||
})
|
||||
|
||||
/**
|
||||
* 验证密码
|
||||
* 当密码输入后,如果确认密码已填写,则触发确认密码的验证
|
||||
*/
|
||||
const validatePassword = (_rule: any, value: string, callback: (error?: Error) => void) => {
|
||||
if (!value) {
|
||||
callback(new Error(t('register.placeholder.password')))
|
||||
return
|
||||
}
|
||||
|
||||
if (formData.confirmPassword) {
|
||||
formRef.value?.validateField('confirmPassword')
|
||||
}
|
||||
|
||||
callback()
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证确认密码
|
||||
* 检查确认密码是否与密码一致
|
||||
*/
|
||||
const validateConfirmPassword = (
|
||||
_rule: any,
|
||||
value: string,
|
||||
callback: (error?: Error) => void
|
||||
) => {
|
||||
if (!value) {
|
||||
callback(new Error(t('register.rule.confirmPasswordRequired')))
|
||||
return
|
||||
}
|
||||
|
||||
if (value !== formData.password) {
|
||||
callback(new Error(t('register.rule.passwordMismatch')))
|
||||
return
|
||||
}
|
||||
|
||||
callback()
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证用户协议
|
||||
* 确保用户已勾选同意协议
|
||||
*/
|
||||
const validateAgreement = (_rule: any, value: boolean, callback: (error?: Error) => void) => {
|
||||
if (!value) {
|
||||
callback(new Error(t('register.rule.agreementRequired')))
|
||||
return
|
||||
}
|
||||
callback()
|
||||
}
|
||||
|
||||
const rules = computed<FormRules<RegisterForm>>(() => ({
|
||||
username: [
|
||||
{ required: true, message: t('register.placeholder.username'), trigger: 'blur' },
|
||||
{
|
||||
min: USERNAME_MIN_LENGTH,
|
||||
max: USERNAME_MAX_LENGTH,
|
||||
message: t('register.rule.usernameLength'),
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
password: [
|
||||
{ required: true, validator: validatePassword, trigger: 'blur' },
|
||||
{ min: PASSWORD_MIN_LENGTH, message: t('register.rule.passwordLength'), trigger: 'blur' }
|
||||
],
|
||||
confirmPassword: [{ required: true, validator: validateConfirmPassword, trigger: 'blur' }],
|
||||
agreement: [{ validator: validateAgreement, trigger: 'change' }]
|
||||
}))
|
||||
|
||||
/**
|
||||
* 注册用户
|
||||
* 验证表单后提交注册请求
|
||||
*/
|
||||
const register = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
loading.value = true
|
||||
|
||||
// TODO: 替换为真实 API 调用
|
||||
// const params = {
|
||||
// username: formData.username,
|
||||
// password: formData.password
|
||||
// }
|
||||
// const res = await AuthService.register(params)
|
||||
// if (res.code === ApiStatus.success) {
|
||||
// ElMessage.success('注册成功')
|
||||
// toLogin()
|
||||
// }
|
||||
|
||||
// 模拟注册请求
|
||||
setTimeout(() => {
|
||||
loading.value = false
|
||||
ElMessage.success('注册成功')
|
||||
toLogin()
|
||||
}, REDIRECT_DELAY)
|
||||
} catch (error) {
|
||||
console.error('表单验证失败:', error)
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到登录页面
|
||||
*/
|
||||
const toLogin = () => {
|
||||
setTimeout(() => {
|
||||
router.push({ name: 'Login' })
|
||||
}, REDIRECT_DELAY)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@import '../login/style.css';
|
||||
</style>
|
||||
@@ -0,0 +1,104 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 敏感凭证(37du 控制台)
|
||||
* 已登记账号列表 + 明文源录入(对接 /api/admin/creds/manage、creds/seed)
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { fetchCredsManage, seedCreds } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
const total = ref(0)
|
||||
const query = reactive({ page: 1, page_size: 20 })
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetchCredsManage(query)
|
||||
list.value = r.items || []
|
||||
total.value = r.total || 0
|
||||
allowedKeys.value = r.allowed_keys || []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const allowedKeys = ref<string[]>([])
|
||||
|
||||
// ---- 录入明文源 ----
|
||||
const seedOpen = ref(false)
|
||||
const saving = ref(false)
|
||||
const seedForm = reactive<{ account: string; values: Record<string, string> }>({ account: '', values: {} })
|
||||
|
||||
function openSeed(row: any) {
|
||||
seedForm.account = row.account
|
||||
seedForm.values = {}
|
||||
for (const k of allowedKeys.value) seedForm.values[k] = row.creds?.[k] || ''
|
||||
seedOpen.value = true
|
||||
}
|
||||
async function submitSeed() {
|
||||
if (!seedForm.account) return ElMessage.warning('account 不能为空')
|
||||
saving.value = true
|
||||
try {
|
||||
await seedCreds({ account: seedForm.account, values: seedForm.values })
|
||||
ElMessage.success('明文源已保存')
|
||||
seedOpen.value = false
|
||||
load()
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">敏感凭证</h2>
|
||||
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe>
|
||||
<el-table-column prop="account" label="账号" min-width="140" />
|
||||
<el-table-column prop="nickname" label="昵称" min-width="120" />
|
||||
<el-table-column label="已上报公钥" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.has_pubkey ? 'success' : 'info'" size="small">{{ row.has_pubkey ? '是' : '否' }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="已配置键" width="140">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-for="k in Object.keys(row.creds || {})" :key="k" size="small" class="mr-1">{{ k }}</el-tag>
|
||||
<span v-if="!Object.keys(row.creds || {}).length" class="text-gray-400">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="updated_at" label="更新时间" width="170" />
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="openSeed(row)">录入明文</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<el-pagination v-model:current-page="query.page" v-model:page-size="query.page_size" :total="total"
|
||||
layout="total, prev, pager, next" @current-change="load" />
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-dialog v-model="seedOpen" title="录入敏感凭证明文源" width="520px">
|
||||
<el-form label-width="120px">
|
||||
<el-form-item label="账号">{{ seedForm.account }}</el-form-item>
|
||||
<el-form-item v-for="k in allowedKeys" :key="k" :label="k">
|
||||
<el-input v-model="seedForm.values[k]" type="password" show-password placeholder="留空则清除" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="seedOpen = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="submitSeed">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,41 @@
|
||||
<!-- 工作台页面 -->
|
||||
<template>
|
||||
<div>
|
||||
<CardList></CardList>
|
||||
|
||||
<ElRow :gutter="20">
|
||||
<ElCol :sm="24" :md="12" :lg="10">
|
||||
<ActiveUser />
|
||||
</ElCol>
|
||||
<ElCol :sm="24" :md="12" :lg="14">
|
||||
<SalesOverview />
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
|
||||
<ElRow :gutter="20">
|
||||
<ElCol :sm="24" :md="24" :lg="12">
|
||||
<NewUser />
|
||||
</ElCol>
|
||||
<ElCol :sm="24" :md="12" :lg="6">
|
||||
<Dynamic />
|
||||
</ElCol>
|
||||
<ElCol :sm="24" :md="12" :lg="6">
|
||||
<TodoList />
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
|
||||
<AboutProject />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import CardList from './modules/card-list.vue'
|
||||
import ActiveUser from './modules/active-user.vue'
|
||||
import SalesOverview from './modules/sales-overview.vue'
|
||||
import NewUser from './modules/new-user.vue'
|
||||
import Dynamic from './modules/dynamic-stats.vue'
|
||||
import TodoList from './modules/todo-list.vue'
|
||||
import AboutProject from './modules/about-project.vue'
|
||||
|
||||
defineOptions({ name: 'Console' })
|
||||
</script>
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<template>
|
||||
<div class="art-card p-5 flex-b mb-5 max-sm:mb-4">
|
||||
<div>
|
||||
<h2 class="text-2xl font-medium">关于项目</h2>
|
||||
<p class="text-g-700 mt-1">{{ systemName }} 是一款兼具设计美学与高效开发的后台系统</p>
|
||||
<p class="text-g-700 mt-1">使用了 Vue3、TypeScript、Vite、Element Plus 等前沿技术</p>
|
||||
|
||||
<div class="flex flex-wrap gap-3.5 max-w-150 mt-9">
|
||||
<div
|
||||
class="w-60 flex-cb h-12.5 px-3.5 border border-g-300 c-p rounded-lg text-sm bg-g-100 duration-300 hover:-translate-y-1 max-sm:w-full"
|
||||
v-for="link in linkList"
|
||||
:key="link.label"
|
||||
@click="goPage(link.url)"
|
||||
>
|
||||
<span class="text-g-700">{{ link.label }}</span>
|
||||
<ArtSvgIcon icon="ri:arrow-right-s-line" class="text-lg text-g-600" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<img class="w-75 max-md:!hidden" src="@imgs/draw/draw1.png" alt="draw1" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import AppConfig from '@/config'
|
||||
import { WEB_LINKS } from '@/utils/constants'
|
||||
|
||||
const systemName = AppConfig.systemInfo.name
|
||||
|
||||
const linkList = [
|
||||
{ label: '项目官网', url: WEB_LINKS.DOCS },
|
||||
{ label: '文档', url: WEB_LINKS.INTRODUCE },
|
||||
{ label: 'Github', url: WEB_LINKS.GITHUB_HOME },
|
||||
{ label: '哔哩哔哩', url: WEB_LINKS.BILIBILI }
|
||||
]
|
||||
|
||||
/**
|
||||
* 在新标签页中打开指定 URL
|
||||
* @param url 要打开的网页地址
|
||||
*/
|
||||
const goPage = (url: string): void => {
|
||||
window.open(url, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
</script>
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<template>
|
||||
<div class="art-card h-105 p-4 box-border mb-5 max-sm:mb-4">
|
||||
<ArtBarChart
|
||||
class="box-border p-2"
|
||||
barWidth="50%"
|
||||
height="13.7rem"
|
||||
:showAxisLine="false"
|
||||
:data="chartData"
|
||||
:xAxisData="xAxisLabels"
|
||||
/>
|
||||
<div class="ml-1">
|
||||
<h3 class="mt-5 text-lg font-medium">用户概述</h3>
|
||||
<p class="mt-1 text-sm">比上周 <span class="text-success font-medium">+23%</span></p>
|
||||
<p class="mt-1 text-sm">我们为您创建了多个选项,可将它们组合在一起并定制为像素完美的页面</p>
|
||||
</div>
|
||||
<div class="flex-b mt-2">
|
||||
<div class="flex-1" v-for="(item, index) in list" :key="index">
|
||||
<p class="text-2xl text-g-900">{{ item.num }}</p>
|
||||
<p class="text-xs text-g-500">{{ item.name }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface UserStatItem {
|
||||
name: string
|
||||
num: string
|
||||
}
|
||||
|
||||
// 最近9个月
|
||||
const xAxisLabels = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月']
|
||||
|
||||
// 每月活跃用户数
|
||||
const chartData = [160, 100, 150, 80, 190, 100, 175, 120, 160]
|
||||
|
||||
/**
|
||||
* 用户统计数据列表
|
||||
* 包含总用户量、总访问量、日访问量和周同比等关键指标
|
||||
*/
|
||||
const list: UserStatItem[] = [
|
||||
{ name: '总用户量', num: '32k' },
|
||||
{ name: '总访问量', num: '128k' },
|
||||
{ name: '日访问量', num: '1.2k' },
|
||||
{ name: '周同比', num: '+5%' }
|
||||
]
|
||||
</script>
|
||||
@@ -0,0 +1,74 @@
|
||||
<template>
|
||||
<ElRow :gutter="20" class="flex">
|
||||
<ElCol v-for="(item, index) in dataList" :key="index" :sm="12" :md="6" :lg="6">
|
||||
<div class="art-card relative flex flex-col justify-center h-35 px-5 mb-5 max-sm:mb-4">
|
||||
<span class="text-g-700 text-sm">{{ item.des }}</span>
|
||||
<ArtCountTo class="text-[26px] font-medium mt-2" :target="item.num" :duration="1300" />
|
||||
<div class="flex-c mt-1">
|
||||
<span class="text-xs text-g-600">较上周</span>
|
||||
<span
|
||||
class="ml-1 text-xs font-semibold"
|
||||
:class="[item.change.indexOf('+') === -1 ? 'text-danger' : 'text-success']"
|
||||
>
|
||||
{{ item.change }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="absolute top-0 bottom-0 right-5 m-auto size-12.5 rounded-xl flex-cc bg-theme/10"
|
||||
>
|
||||
<ArtSvgIcon :icon="item.icon" class="text-xl text-theme" />
|
||||
</div>
|
||||
</div>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface CardDataItem {
|
||||
des: string
|
||||
icon: string
|
||||
startVal: number
|
||||
duration: number
|
||||
num: number
|
||||
change: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 卡片统计数据列表
|
||||
* 展示总访问次数、在线访客数、点击量和新用户等核心数据指标
|
||||
*/
|
||||
const dataList = reactive<CardDataItem[]>([
|
||||
{
|
||||
des: '总访问次数',
|
||||
icon: 'ri:pie-chart-line',
|
||||
startVal: 0,
|
||||
duration: 1000,
|
||||
num: 9120,
|
||||
change: '+20%'
|
||||
},
|
||||
{
|
||||
des: '在线访客数',
|
||||
icon: 'ri:group-line',
|
||||
startVal: 0,
|
||||
duration: 1000,
|
||||
num: 182,
|
||||
change: '+10%'
|
||||
},
|
||||
{
|
||||
des: '点击量',
|
||||
icon: 'ri:fire-line',
|
||||
startVal: 0,
|
||||
duration: 1000,
|
||||
num: 9520,
|
||||
change: '-12%'
|
||||
},
|
||||
{
|
||||
des: '新用户',
|
||||
icon: 'ri:progress-2-line',
|
||||
startVal: 0,
|
||||
duration: 1000,
|
||||
num: 156,
|
||||
change: '+30%'
|
||||
}
|
||||
])
|
||||
</script>
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<template>
|
||||
<div class="art-card h-128 p-5 mb-5 max-sm:mb-4">
|
||||
<div class="art-card-header">
|
||||
<div class="title">
|
||||
<h4>动态</h4>
|
||||
<p>新增<span class="text-success">+6</span></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="h-9/10 mt-2 overflow-hidden">
|
||||
<ElScrollbar>
|
||||
<div
|
||||
class="h-17.5 leading-17.5 border-b border-g-300 text-sm overflow-hidden last:border-b-0"
|
||||
v-for="(item, index) in list"
|
||||
:key="index"
|
||||
>
|
||||
<span class="text-g-800 font-medium">{{ item.username }}</span>
|
||||
<span class="mx-2 text-g-600">{{ item.type }}</span>
|
||||
<span class="text-theme">{{ item.target }}</span>
|
||||
</div>
|
||||
</ElScrollbar>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface DynamicItem {
|
||||
username: string
|
||||
type: string
|
||||
target: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户动态列表
|
||||
* 记录用户的关注、发文、提问、兑换等各类活动
|
||||
*/
|
||||
const list = reactive<DynamicItem[]>([
|
||||
{
|
||||
username: '中小鱼',
|
||||
type: '关注了',
|
||||
target: '誶誶淰'
|
||||
},
|
||||
{
|
||||
username: '何小荷',
|
||||
type: '发表文章',
|
||||
target: 'Vue3 + Typescript + Vite 项目实战笔记'
|
||||
},
|
||||
{
|
||||
username: '中小鱼',
|
||||
type: '关注了',
|
||||
target: '誶誶淰'
|
||||
},
|
||||
{
|
||||
username: '何小荷',
|
||||
type: '发表文章',
|
||||
target: 'Vue3 + Typescript + Vite 项目实战笔记'
|
||||
},
|
||||
{
|
||||
username: '誶誶淰',
|
||||
type: '提出问题',
|
||||
target: '主题可以配置吗'
|
||||
},
|
||||
{
|
||||
username: '发呆草',
|
||||
type: '兑换了物品',
|
||||
target: '《奇特的一生》'
|
||||
},
|
||||
{
|
||||
username: '甜筒',
|
||||
type: '关闭了问题',
|
||||
target: '发呆草'
|
||||
},
|
||||
{
|
||||
username: '冷月呆呆',
|
||||
type: '兑换了物品',
|
||||
target: '《高效人士的七个习惯》'
|
||||
}
|
||||
])
|
||||
</script>
|
||||
@@ -0,0 +1,169 @@
|
||||
<template>
|
||||
<div class="art-card p-5 h-128 overflow-hidden mb-5 max-sm:mb-4">
|
||||
<div class="art-card-header">
|
||||
<div class="title">
|
||||
<h4>新用户</h4>
|
||||
<p>这个月增长<span class="text-success">+20%</span></p>
|
||||
</div>
|
||||
<ElRadioGroup v-model="radio2">
|
||||
<ElRadioButton value="本月" label="本月"></ElRadioButton>
|
||||
<ElRadioButton value="上月" label="上月"></ElRadioButton>
|
||||
<ElRadioButton value="今年" label="今年"></ElRadioButton>
|
||||
</ElRadioGroup>
|
||||
</div>
|
||||
<ArtTable
|
||||
class="w-full"
|
||||
:data="tableData"
|
||||
style="width: 100%"
|
||||
size="large"
|
||||
:border="false"
|
||||
:stripe="false"
|
||||
:header-cell-style="{ background: 'transparent' }"
|
||||
>
|
||||
<template #default>
|
||||
<ElTableColumn label="头像" prop="avatar" width="150px">
|
||||
<template #default="scope">
|
||||
<div style="display: flex; align-items: center">
|
||||
<img class="size-9 rounded-lg" :src="scope.row.avatar" alt="avatar" />
|
||||
<span class="ml-2">{{ scope.row.username }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="地区" prop="province" />
|
||||
<ElTableColumn label="性别" prop="avatar">
|
||||
<template #default="scope">
|
||||
<div style="display: flex; align-items: center">
|
||||
<span style="margin-left: 10px">{{ scope.row.sex === 1 ? '男' : '女' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="进度" width="240">
|
||||
<template #default="scope">
|
||||
<ElProgress
|
||||
:percentage="scope.row.pro"
|
||||
:color="scope.row.color"
|
||||
:stroke-width="4"
|
||||
:aria-label="`${scope.row.username}的完成进度: ${scope.row.pro}%`"
|
||||
/>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</template>
|
||||
</ArtTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import avatar1 from '@/assets/images/avatar/avatar1.webp'
|
||||
import avatar2 from '@/assets/images/avatar/avatar2.webp'
|
||||
import avatar3 from '@/assets/images/avatar/avatar3.webp'
|
||||
import avatar4 from '@/assets/images/avatar/avatar4.webp'
|
||||
import avatar5 from '@/assets/images/avatar/avatar5.webp'
|
||||
import avatar6 from '@/assets/images/avatar/avatar6.webp'
|
||||
|
||||
interface UserTableItem {
|
||||
username: string
|
||||
province: string
|
||||
sex: 0 | 1
|
||||
age: number
|
||||
percentage: number
|
||||
pro: number
|
||||
color: string
|
||||
avatar: string
|
||||
}
|
||||
|
||||
const ANIMATION_DELAY = 100
|
||||
|
||||
const radio2 = ref('本月')
|
||||
|
||||
/**
|
||||
* 新用户表格数据
|
||||
* 包含用户基本信息和完成进度
|
||||
*/
|
||||
const tableData = reactive<UserTableItem[]>([
|
||||
{
|
||||
username: '中小鱼',
|
||||
province: '北京',
|
||||
sex: 0,
|
||||
age: 22,
|
||||
percentage: 60,
|
||||
pro: 0,
|
||||
color: 'var(--art-primary)',
|
||||
avatar: avatar1
|
||||
},
|
||||
{
|
||||
username: '何小荷',
|
||||
province: '深圳',
|
||||
sex: 1,
|
||||
age: 21,
|
||||
percentage: 20,
|
||||
pro: 0,
|
||||
color: 'var(--art-secondary)',
|
||||
avatar: avatar2
|
||||
},
|
||||
{
|
||||
username: '誶誶淰',
|
||||
province: '上海',
|
||||
sex: 1,
|
||||
age: 23,
|
||||
percentage: 60,
|
||||
pro: 0,
|
||||
color: 'var(--art-warning)',
|
||||
avatar: avatar3
|
||||
},
|
||||
{
|
||||
username: '发呆草',
|
||||
province: '长沙',
|
||||
sex: 0,
|
||||
age: 28,
|
||||
percentage: 50,
|
||||
pro: 0,
|
||||
color: 'var(--art-info)',
|
||||
avatar: avatar4
|
||||
},
|
||||
{
|
||||
username: '甜筒',
|
||||
province: '浙江',
|
||||
sex: 1,
|
||||
age: 26,
|
||||
percentage: 70,
|
||||
pro: 0,
|
||||
color: 'var(--art-error)',
|
||||
avatar: avatar5
|
||||
},
|
||||
{
|
||||
username: '冷月呆呆',
|
||||
province: '湖北',
|
||||
sex: 1,
|
||||
age: 25,
|
||||
percentage: 90,
|
||||
pro: 0,
|
||||
color: 'var(--art-success)',
|
||||
avatar: avatar6
|
||||
}
|
||||
])
|
||||
|
||||
/**
|
||||
* 添加进度条动画效果
|
||||
* 延迟后将进度值从 0 更新到目标百分比,触发动画
|
||||
*/
|
||||
const addAnimation = (): void => {
|
||||
setTimeout(() => {
|
||||
tableData.forEach((item) => {
|
||||
item.pro = item.percentage
|
||||
})
|
||||
}, ANIMATION_DELAY)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
addAnimation()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.art-card {
|
||||
:deep(.el-radio-button__original-radio:checked + .el-radio-button__inner) {
|
||||
color: var(--el-color-primary) !important;
|
||||
background: transparent !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<div class="art-card h-105 p-5 mb-5 max-sm:mb-4">
|
||||
<div class="art-card-header">
|
||||
<div class="title">
|
||||
<h4>访问量</h4>
|
||||
<p>今年增长<span class="text-success">+15%</span></p>
|
||||
</div>
|
||||
</div>
|
||||
<ArtLineChart
|
||||
height="calc(100% - 56px)"
|
||||
:data="data"
|
||||
:xAxisData="xAxisData"
|
||||
:showAreaColor="true"
|
||||
:showAxisLine="false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 全年访问量数据
|
||||
* 记录每月的访问量统计
|
||||
*/
|
||||
const data = [50, 25, 40, 20, 70, 35, 65, 30, 35, 20, 40, 44]
|
||||
|
||||
/**
|
||||
* X 轴月份标签
|
||||
*/
|
||||
const xAxisData = [
|
||||
'1月',
|
||||
'2月',
|
||||
'3月',
|
||||
'4月',
|
||||
'5月',
|
||||
'6月',
|
||||
'7月',
|
||||
'8月',
|
||||
'9月',
|
||||
'10月',
|
||||
'11月',
|
||||
'12月'
|
||||
]
|
||||
</script>
|
||||
@@ -0,0 +1,71 @@
|
||||
<template>
|
||||
<div class="art-card h-128 p-5 mb-5 max-sm:mb-4">
|
||||
<div class="art-card-header">
|
||||
<div class="title">
|
||||
<h4>代办事项</h4>
|
||||
<p>待处理<span class="text-danger">3</span></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="h-[calc(100%-40px)] overflow-auto">
|
||||
<ElScrollbar>
|
||||
<div
|
||||
class="flex-cb h-17.5 border-b border-g-300 text-sm last:border-b-0"
|
||||
v-for="(item, index) in list"
|
||||
:key="index"
|
||||
>
|
||||
<div>
|
||||
<p class="text-sm">{{ item.username }}</p>
|
||||
<p class="text-g-500 mt-1">{{ item.date }}</p>
|
||||
</div>
|
||||
<ElCheckbox v-model="item.complate" />
|
||||
</div>
|
||||
</ElScrollbar>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface TodoItem {
|
||||
username: string
|
||||
date: string
|
||||
complate: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* 待办事项列表
|
||||
* 记录每日工作任务及完成状态
|
||||
*/
|
||||
const list = reactive<TodoItem[]>([
|
||||
{
|
||||
username: '查看今天工作内容',
|
||||
date: '上午 09:30',
|
||||
complate: true
|
||||
},
|
||||
{
|
||||
username: '回复邮件',
|
||||
date: '上午 10:30',
|
||||
complate: true
|
||||
},
|
||||
{
|
||||
username: '工作汇报整理',
|
||||
date: '上午 11:00',
|
||||
complate: true
|
||||
},
|
||||
{
|
||||
username: '产品需求会议',
|
||||
date: '下午 02:00',
|
||||
complate: false
|
||||
},
|
||||
{
|
||||
username: '整理会议内容',
|
||||
date: '下午 03:30',
|
||||
complate: false
|
||||
},
|
||||
{
|
||||
username: '明天工作计划',
|
||||
date: '下午 06:30',
|
||||
complate: false
|
||||
}
|
||||
])
|
||||
</script>
|
||||
@@ -0,0 +1,71 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 执行机设备(37du 控制台)
|
||||
* 分页列表:环境信息 + Chrome 检测(对接 /api/admin/devices)
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { fetchDevices } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
const total = ref(0)
|
||||
const query = reactive({ page: 1, page_size: 20 })
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetchDevices(query)
|
||||
list.value = r.items || []
|
||||
total.value = r.total || 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">执行机设备</h2>
|
||||
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe>
|
||||
<el-table-column prop="device_id" label="设备ID" min-width="150" />
|
||||
<el-table-column label="账号" width="110">
|
||||
<template #default="{ row }">{{ row.account || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="hostname" label="主机名" min-width="120" />
|
||||
<el-table-column prop="os" label="系统" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="ip" label="IP" width="130" />
|
||||
<el-table-column label="Chrome" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.chrome_ok ? 'success' : 'danger'" size="small">
|
||||
{{ row.chrome_ok ? '就绪' : '异常' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="在线" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'info'" size="small">
|
||||
{{ row.status === 1 ? '在线' : '离线' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="last_seen" label="最后在线" width="170" />
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<el-pagination
|
||||
v-model:current-page="query.page"
|
||||
v-model:page-size="query.page_size"
|
||||
:total="total"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="load"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
<!-- 403页面 -->
|
||||
<template>
|
||||
<ArtException
|
||||
:data="{
|
||||
title: '403',
|
||||
desc: $t('exceptionPage.403'),
|
||||
btnText: $t('exceptionPage.gohome'),
|
||||
imgUrl
|
||||
}"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import imgUrl from '@imgs/svg/403.svg'
|
||||
defineOptions({ name: 'Exception403' })
|
||||
</script>
|
||||
@@ -0,0 +1,16 @@
|
||||
<!-- 404页面 -->
|
||||
<template>
|
||||
<ArtException
|
||||
:data="{
|
||||
title: '404',
|
||||
desc: $t('exceptionPage.404'),
|
||||
btnText: $t('exceptionPage.gohome'),
|
||||
imgUrl
|
||||
}"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import imgUrl from '@imgs/svg/404.svg'
|
||||
defineOptions({ name: 'Exception404' })
|
||||
</script>
|
||||
@@ -0,0 +1,16 @@
|
||||
<!-- 500页面 -->
|
||||
<template>
|
||||
<ArtException
|
||||
:data="{
|
||||
title: '500',
|
||||
desc: $t('exceptionPage.500'),
|
||||
btnText: $t('exceptionPage.gohome'),
|
||||
imgUrl
|
||||
}"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import imgUrl from '@imgs/svg/500.svg'
|
||||
defineOptions({ name: 'Exception500' })
|
||||
</script>
|
||||
@@ -0,0 +1,128 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 大文件源(37du 控制台)
|
||||
* 列表 + 登记/启停/删除(对接 /api/admin/file-sources*)
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { fetchFileSources, upsertFileSource, patchFileSource, deleteFileSource } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
const total = ref(0)
|
||||
const query = reactive({ page: 1, page_size: 20, category: '' })
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetchFileSources(query)
|
||||
list.value = r.items || []
|
||||
total.value = r.total || 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
query.page = 1
|
||||
load()
|
||||
}
|
||||
|
||||
// ---- 登记/覆盖 ----
|
||||
const dialogOpen = ref(false)
|
||||
const saving = ref(false)
|
||||
const form = reactive({ category: '', version: '', filename: '', url: '', sha256: '', notes: '', enabled: true })
|
||||
|
||||
function openCreate() {
|
||||
Object.assign(form, { category: '', version: '', filename: '', url: '', sha256: '', notes: '', enabled: true })
|
||||
dialogOpen.value = true
|
||||
}
|
||||
async function submit() {
|
||||
if (!form.category || !form.url) return ElMessage.warning('category 与 url 必填')
|
||||
saving.value = true
|
||||
try {
|
||||
await upsertFileSource(form)
|
||||
ElMessage.success('登记成功')
|
||||
dialogOpen.value = false
|
||||
load()
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggle(row: any) {
|
||||
await patchFileSource(row.id, { enabled: row.enabled !== 1 })
|
||||
load()
|
||||
}
|
||||
async function remove(row: any) {
|
||||
await ElMessageBox.confirm(`确认删除文件源 #${row.id}?`, '删除确认', { type: 'warning' })
|
||||
await deleteFileSource(row.id)
|
||||
ElMessage.success('已删除')
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">大文件源</h2>
|
||||
<el-button type="primary" @click="openCreate">登记文件源</el-button>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-form inline @submit.prevent="search">
|
||||
<el-form-item label="分类">
|
||||
<el-select v-model="query.category" clearable placeholder="全部" style="width: 160px" @change="search">
|
||||
<el-option label="shell" value="shell" /><el-option label="chrome" value="chrome" /><el-option label="python-env" value="python-env" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe>
|
||||
<el-table-column prop="id" label="ID" width="70" />
|
||||
<el-table-column prop="category" label="分类" width="110" />
|
||||
<el-table-column prop="version" label="版本" width="100" />
|
||||
<el-table-column prop="filename" label="文件名" min-width="180" show-overflow-tooltip />
|
||||
<el-table-column prop="url" label="URL" min-width="220" show-overflow-tooltip />
|
||||
<el-table-column label="启用" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.enabled ? 'success' : 'info'" size="small">{{ row.enabled ? '是' : '否' }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="updated_at" label="更新时间" width="170" />
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="toggle(row)">{{ row.enabled ? '停用' : '启用' }}</el-button>
|
||||
<el-button link type="danger" @click="remove(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<el-pagination v-model:current-page="query.page" v-model:page-size="query.page_size" :total="total"
|
||||
layout="total, prev, pager, next" @current-change="load" />
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-dialog v-model="dialogOpen" title="登记文件源" width="520px">
|
||||
<el-form label-width="90px">
|
||||
<el-form-item label="分类" required><el-input v-model="form.category" placeholder="shell / chrome / python-env" /></el-form-item>
|
||||
<el-form-item label="版本"><el-input v-model="form.version" /></el-form-item>
|
||||
<el-form-item label="文件名"><el-input v-model="form.filename" /></el-form-item>
|
||||
<el-form-item label="URL" required><el-input v-model="form.url" placeholder="内网文件服务器直链" /></el-form-item>
|
||||
<el-form-item label="SHA256"><el-input v-model="form.sha256" /></el-form-item>
|
||||
<el-form-item label="说明"><el-input v-model="form.notes" /></el-form-item>
|
||||
<el-form-item label="启用"><el-switch v-model="form.enabled" /></el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogOpen = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,107 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 权限授权(37du 控制台)
|
||||
* 账号 × 插件授权(can_download / can_run)+ 平台白名单(对接 /api/admin/grant_data、account_grants、account_plugins、account_platforms)
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { fetchGrantData, fetchAccountGrants, grantPlugin, grantPlatform } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const plugins = ref<any[]>([])
|
||||
const accounts = ref<any[]>([])
|
||||
const account = ref('')
|
||||
const grants = reactive<Record<string, { canRun: boolean; canDownload: boolean }>>({})
|
||||
const platforms = ref<string[]>([])
|
||||
const platformOptions = ['hr', 'oa']
|
||||
|
||||
async function loadData() {
|
||||
loading.value = true
|
||||
try {
|
||||
const d = await fetchGrantData()
|
||||
plugins.value = d.plugins || []
|
||||
accounts.value = d.accounts || []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function selectAccount(acc: string) {
|
||||
account.value = acc
|
||||
if (!acc) return
|
||||
const g = await fetchAccountGrants(acc)
|
||||
const map: Record<string, { canRun: boolean; canDownload: boolean }> = {}
|
||||
for (const p of g.plugins || []) {
|
||||
map[p.plugin_id] = { canRun: !!p.canRun, canDownload: !!p.canDownload }
|
||||
}
|
||||
for (const p of plugins.value) {
|
||||
if (!map[p.id]) map[p.id] = { canRun: false, canDownload: false }
|
||||
}
|
||||
Object.assign(grants, map)
|
||||
platforms.value = g.platforms || []
|
||||
}
|
||||
|
||||
async function toggleGrant(pid: string, field: 'canRun' | 'canDownload', val: boolean) {
|
||||
if (!account.value) return
|
||||
await grantPlugin({
|
||||
account: account.value, plugin_id: pid, granted: true,
|
||||
can_download: field === 'canDownload' ? val : grants[pid]?.canDownload,
|
||||
can_run: field === 'canRun' ? val : grants[pid]?.canRun
|
||||
})
|
||||
ElMessage.success('已保存')
|
||||
}
|
||||
|
||||
async function togglePlatform(pid: string, val: boolean) {
|
||||
if (!account.value) return
|
||||
await grantPlatform({ account: account.value, platform_id: pid, granted: val })
|
||||
ElMessage.success(val ? '已授权平台' : '已撤销平台')
|
||||
}
|
||||
|
||||
onMounted(loadData)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">权限授权</h2>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-form inline>
|
||||
<el-form-item label="选择账号">
|
||||
<el-select v-model="account" filterable placeholder="选择账号" style="width: 240px" @change="selectAccount">
|
||||
<el-option v-for="a in accounts" :key="a.account" :label="`${a.nickname || a.account} (${a.account})`" :value="a.account" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-table v-if="account" :data="plugins" border stripe>
|
||||
<el-table-column prop="id" label="插件ID" min-width="140" />
|
||||
<el-table-column prop="name" label="名称" min-width="150" />
|
||||
<el-table-column label="允许运行" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-switch :model-value="grants[row.id]?.canRun" @change="(v: any) => toggleGrant(row.id, 'canRun', !!v)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="允许下载" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-switch :model-value="grants[row.id]?.canDownload" @change="(v: any) => toggleGrant(row.id, 'canDownload', !!v)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-empty v-else description="请先选择账号" :image-size="80" />
|
||||
|
||||
<template v-if="account">
|
||||
<div class="mt-4 font-semibold text-sm mb-2">平台白名单</div>
|
||||
<div class="flex gap-4">
|
||||
<el-checkbox
|
||||
v-for="p in platformOptions"
|
||||
:key="p"
|
||||
:model-value="platforms.includes(p)"
|
||||
@change="(v: any) => togglePlatform(p, !!v)"
|
||||
>{{ p.toUpperCase() }}</el-checkbox>
|
||||
</div>
|
||||
</template>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,29 @@
|
||||
<!-- 布局容器 -->
|
||||
<template>
|
||||
<div class="app-layout">
|
||||
<aside id="app-sidebar">
|
||||
<ArtSidebarMenu />
|
||||
</aside>
|
||||
|
||||
<main id="app-main">
|
||||
<div id="app-header">
|
||||
<ArtHeaderBar />
|
||||
</div>
|
||||
<div id="app-content">
|
||||
<ArtPageContent />
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<div id="app-global">
|
||||
<ArtGlobalComponent />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineOptions({ name: 'AppLayout' })
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@use './style';
|
||||
</style>
|
||||
@@ -0,0 +1,93 @@
|
||||
.app-layout {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
min-height: 100vh;
|
||||
background: var(--default-bg-color);
|
||||
|
||||
#app-sidebar {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
#app-main {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
height: 100vh;
|
||||
overflow: auto;
|
||||
|
||||
#app-header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 50;
|
||||
flex-shrink: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#app-content {
|
||||
flex: 1;
|
||||
|
||||
:deep(.layout-content) {
|
||||
box-sizing: border-box;
|
||||
width: calc(100% - 40px);
|
||||
margin: auto;
|
||||
|
||||
// 子页面默认 style
|
||||
.page-content {
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
padding: 20px;
|
||||
overflow: hidden;
|
||||
background: var(--default-box-color);
|
||||
border-radius: calc(var(--custom-radius) / 2 + 2px) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (width <= 1180px) {
|
||||
.app-layout {
|
||||
#app-main {
|
||||
height: 100dvh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (width <= 800px) {
|
||||
.app-layout {
|
||||
position: relative;
|
||||
|
||||
#app-sidebar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 300;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
#app-main {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
overflow: visible;
|
||||
|
||||
#app-content {
|
||||
:deep(.layout-content) {
|
||||
width: calc(100% - 40px);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (width <= 640px) {
|
||||
.app-layout {
|
||||
#app-main {
|
||||
#app-content {
|
||||
:deep(.layout-content) {
|
||||
width: calc(100% - 30px);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 通知推送(37du 控制台)
|
||||
* 列表 + 新建/启停/删除(对接 /api/admin/notifications*)
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { fetchNotifications, createNotification, toggleNotification, deleteNotification } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
const total = ref(0)
|
||||
const query = reactive({ page: 1, page_size: 20, q: '' })
|
||||
|
||||
const levelMap: Record<string, { label: string; type: any }> = {
|
||||
info: { label: '普通', type: 'info' },
|
||||
warning: { label: '警告', type: 'warning' },
|
||||
important: { label: '重要', type: 'danger' }
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetchNotifications(query)
|
||||
list.value = r.items || []
|
||||
total.value = r.total || 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
query.page = 1
|
||||
load()
|
||||
}
|
||||
|
||||
// ---- 新建 ----
|
||||
const dialogOpen = ref(false)
|
||||
const saving = ref(false)
|
||||
const form = reactive({ title: '', content: '', level: 'info', target: 'all', account: '', expires_at: '' })
|
||||
|
||||
function openCreate() {
|
||||
Object.assign(form, { title: '', content: '', level: 'info', target: 'all', account: '', expires_at: '' })
|
||||
dialogOpen.value = true
|
||||
}
|
||||
async function submit() {
|
||||
if (!form.title) return ElMessage.warning('标题不能为空')
|
||||
saving.value = true
|
||||
try {
|
||||
await createNotification(form)
|
||||
ElMessage.success('通知已下发')
|
||||
dialogOpen.value = false
|
||||
load()
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggle(row: any) {
|
||||
await toggleNotification(row.id, row.active !== 1)
|
||||
load()
|
||||
}
|
||||
async function remove(row: any) {
|
||||
await ElMessageBox.confirm(`确认删除通知「${row.title}」?`, '删除确认', { type: 'warning' })
|
||||
await deleteNotification(row.id)
|
||||
ElMessage.success('已删除')
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">通知推送</h2>
|
||||
<el-button type="primary" @click="openCreate">新建通知</el-button>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-form inline @submit.prevent="search">
|
||||
<el-form-item label="关键字">
|
||||
<el-input v-model="query.q" placeholder="标题 / 内容 / 账号" clearable style="width: 240px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="Object.assign(query, { q: '' }); search()">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe>
|
||||
<el-table-column prop="title" label="标题" min-width="160" />
|
||||
<el-table-column prop="content" label="内容" min-width="220" show-overflow-tooltip />
|
||||
<el-table-column label="级别" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="levelMap[row.level]?.type || 'info'" size="small">{{ levelMap[row.level]?.label || row.level }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="范围" width="100">
|
||||
<template #default="{ row }">{{ row.target === 'all' ? '全部' : row.account }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.active === 1 ? 'success' : 'info'" size="small">{{ row.active === 1 ? '启用' : '停用' }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="170" />
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="toggle(row)">{{ row.active === 1 ? '停用' : '启用' }}</el-button>
|
||||
<el-button link type="danger" @click="remove(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<el-pagination v-model:current-page="query.page" v-model:page-size="query.page_size" :total="total"
|
||||
layout="total, prev, pager, next" @current-change="load" />
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-dialog v-model="dialogOpen" title="新建通知" width="520px">
|
||||
<el-form label-width="90px">
|
||||
<el-form-item label="标题" required><el-input v-model="form.title" /></el-form-item>
|
||||
<el-form-item label="内容"><el-input v-model="form.content" type="textarea" :rows="3" /></el-form-item>
|
||||
<el-form-item label="级别">
|
||||
<el-select v-model="form.level">
|
||||
<el-option label="普通" value="info" /><el-option label="警告" value="warning" /><el-option label="重要" value="important" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="范围">
|
||||
<el-radio-group v-model="form.target">
|
||||
<el-radio value="all">全部账号</el-radio>
|
||||
<el-radio value="account">指定账号</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.target === 'account'" label="账号" required>
|
||||
<el-input v-model="form.account" placeholder="工号" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogOpen = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="submit">下发</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,42 @@
|
||||
<template>
|
||||
<div class="box-border w-full h-full" v-loading="isLoading">
|
||||
<iframe
|
||||
ref="iframeRef"
|
||||
:src="iframeUrl"
|
||||
frameborder="0"
|
||||
class="w-full h-full min-h-[calc(100vh-120px)] border-none"
|
||||
@load="handleIframeLoad"
|
||||
></iframe>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { IframeRouteManager } from '@/router/core'
|
||||
|
||||
defineOptions({ name: 'IframeView' })
|
||||
|
||||
const route = useRoute()
|
||||
const isLoading = ref(true)
|
||||
const iframeUrl = ref('')
|
||||
const iframeRef = ref<HTMLIFrameElement | null>(null)
|
||||
|
||||
/**
|
||||
* 初始化 iframe URL
|
||||
* 从路由配置中获取对应的外部链接地址
|
||||
*/
|
||||
onMounted(() => {
|
||||
const iframeRoute = IframeRouteManager.getInstance().findByPath(route.path)
|
||||
|
||||
if (iframeRoute?.meta) {
|
||||
iframeUrl.value = iframeRoute.meta.link || ''
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 处理 iframe 加载完成事件
|
||||
* 隐藏加载状态
|
||||
*/
|
||||
const handleIframeLoad = (): void => {
|
||||
isLoading.value = false
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,120 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 概览(37du 控制台)
|
||||
* 统计卡片来自 /api/admin/overview + /api/admin/stats
|
||||
*/
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { fetchOverview, fetchStats } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const overview = ref<any>({})
|
||||
const stats = ref<any>({})
|
||||
|
||||
const statCards = ref([
|
||||
{ key: 'plugins', label: '插件总数', value: 0, icon: 'ri:box-3-line', color: '#377dff' },
|
||||
{ key: 'accounts', label: '账号总数', value: 0, icon: 'ri:user-3-line', color: '#00b42a' },
|
||||
{ key: 'admins', label: '管理员', value: 0, icon: 'ri:shield-user-line', color: '#ff7d00' },
|
||||
{ key: 'authorized', label: '已授权账号', value: 0, icon: 'ri:key-2-line', color: '#f5319d' }
|
||||
])
|
||||
|
||||
const runCards = ref([
|
||||
{ key: 'total', label: '运行总次数', value: 0, icon: 'ri:play-circle-line', color: '#377dff' },
|
||||
{ key: 'success', label: '成功', value: 0, icon: 'ri:checkbox-circle-line', color: '#00b42a' },
|
||||
{ key: 'failed', label: '失败', value: 0, icon: 'ri:close-circle-line', color: '#f53f3f' },
|
||||
{ key: 'activeUsers', label: '活跃用户', value: 0, icon: 'ri:user-heart-line', color: '#ff7d00' }
|
||||
])
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const [ov, st] = await Promise.all([fetchOverview(), fetchStats()])
|
||||
overview.value = ov
|
||||
stats.value = st
|
||||
statCards.value = statCards.value.map((c) => {
|
||||
if (c.key === 'plugins') return { ...c, value: ov.plugins?.length || 0 }
|
||||
if (c.key === 'accounts') return { ...c, value: ov.accounts?.length || 0 }
|
||||
if (c.key === 'admins') return { ...c, value: ov.admins?.length || 0 }
|
||||
if (c.key === 'authorized') return { ...c, value: st.users?.authorized || 0 }
|
||||
return c
|
||||
})
|
||||
runCards.value = runCards.value.map((c) => ({
|
||||
...c,
|
||||
value: st.runs?.[c.key] ?? 0
|
||||
}))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">概览</h2>
|
||||
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||
</div>
|
||||
|
||||
<el-row :gutter="16">
|
||||
<el-col v-for="c in statCards" :key="c.key" :span="6">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-11 h-11 rounded-lg grid place-items-center text-white text-xl" :style="{ background: c.color }">
|
||||
<i :class="c.icon" />
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-2xl font-bold leading-none">{{ c.value }}</div>
|
||||
<div class="text-xs text-gray-500 mt-1">{{ c.label }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="16">
|
||||
<el-col v-for="c in runCards" :key="c.key" :span="6">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-11 h-11 rounded-lg grid place-items-center text-white text-xl" :style="{ background: c.color }">
|
||||
<i :class="c.icon" />
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-2xl font-bold leading-none">{{ c.value }}</div>
|
||||
<div class="text-xs text-gray-500 mt-1">{{ c.label }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header><span class="font-semibold">运行统计</span></template>
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="运行总时长">{{ stats.runs?.durationSec || 0 }} 秒</el-descriptions-item>
|
||||
<el-descriptions-item label="活跃插件">{{ stats.runs?.activePlugins || 0 }}</el-descriptions-item>
|
||||
<el-descriptions-item label="今日">{{ stats.today || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="插件发布状态">
|
||||
{{ stats.plugins?.published || 0 }} 发布 / {{ stats.plugins?.disabled || 0 }} 禁用
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header><span class="font-semibold">账号概览</span></template>
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="管理员">
|
||||
<el-tag size="small" type="primary">{{ overview.admins?.length || 0 }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="普通账号">
|
||||
{{ (overview.accounts?.length || 0) - (overview.admins?.length || 0) }}
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,183 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 插件管理(37du 控制台)
|
||||
* 列表/搜索/上传发布/状态切换/删除,对接 /api/admin/plugins、/pkg、/plugin/patch、/plugin/delete
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { fetchPlugins, uploadPlugin, patchPlugin, deletePlugin } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
const total = ref(0)
|
||||
const query = reactive({ page: 1, page_size: 10, q: '' })
|
||||
|
||||
const statusMap: Record<string, { label: string; type: any }> = {
|
||||
published: { label: '已发布', type: 'success' },
|
||||
disabled: { label: '已禁用', type: 'warning' },
|
||||
revoked: { label: '已下架', type: 'danger' }
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetchPlugins(query)
|
||||
list.value = r.items || []
|
||||
total.value = r.total || 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function search() {
|
||||
query.page = 1
|
||||
load()
|
||||
}
|
||||
|
||||
// ---- 上传发布 ----
|
||||
const uploadOpen = ref(false)
|
||||
const uploading = ref(false)
|
||||
const uploadForm = reactive({ plugin_id: '', name: '', version: '', file: null as File | null })
|
||||
|
||||
function openUpload() {
|
||||
Object.assign(uploadForm, { plugin_id: '', name: '', version: '', file: null })
|
||||
uploadOpen.value = true
|
||||
}
|
||||
|
||||
async function submitUpload() {
|
||||
if (!uploadForm.file || !uploadForm.plugin_id || !uploadForm.version) {
|
||||
ElMessage.warning('请填写 plugin_id / version 并选择安装包')
|
||||
return
|
||||
}
|
||||
uploading.value = true
|
||||
try {
|
||||
await uploadPlugin(uploadForm.file, {
|
||||
plugin_id: uploadForm.plugin_id,
|
||||
name: uploadForm.name,
|
||||
version: uploadForm.version
|
||||
})
|
||||
ElMessage.success('上传发布成功')
|
||||
uploadOpen.value = false
|
||||
load()
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 状态切换 ----
|
||||
async function setStatus(row: any, status: string) {
|
||||
await patchPlugin(row.id, { status })
|
||||
ElMessage.success(`已${statusMap[status]?.label || status}`)
|
||||
load()
|
||||
}
|
||||
|
||||
// ---- 删除 ----
|
||||
async function remove(row: any) {
|
||||
await ElMessageBox.confirm(`确认删除插件「${row.id}」?将连带删除版本与授权。`, '删除确认', {
|
||||
type: 'warning'
|
||||
})
|
||||
await deletePlugin(row.id)
|
||||
ElMessage.success('已删除')
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">插件管理</h2>
|
||||
<el-button type="primary" @click="openUpload">上传发布</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 搜索 -->
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-form inline @submit.prevent="search">
|
||||
<el-form-item label="关键字">
|
||||
<el-input v-model="query.q" placeholder="ID / 名称" clearable style="width: 240px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="Object.assign(query, { q: '' }); search()">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<!-- 表格 -->
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe>
|
||||
<el-table-column prop="id" label="插件ID" min-width="140" />
|
||||
<el-table-column prop="name" label="名称" min-width="160" />
|
||||
<el-table-column prop="latest_version" label="最新版本" width="110" />
|
||||
<el-table-column prop="category" label="分类" width="110" />
|
||||
<el-table-column label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="statusMap[row.status]?.type || 'info'" size="small">
|
||||
{{ statusMap[row.status]?.label || row.status }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="版本历史" width="220">
|
||||
<template #default="{ row }">
|
||||
<el-tooltip v-if="row.versions?.length" :content="row.versions.map((v: any) => v.version).join(', ')">
|
||||
<el-tag size="small" type="info">{{ row.versions.length }} 个版本</el-tag>
|
||||
</el-tooltip>
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="220" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-if="row.status === 'disabled'"
|
||||
link type="success"
|
||||
@click="setStatus(row, 'published')"
|
||||
>启用</el-button>
|
||||
<el-button
|
||||
v-if="row.status === 'published'"
|
||||
link type="warning"
|
||||
@click="setStatus(row, 'disabled')"
|
||||
>禁用</el-button>
|
||||
<el-button
|
||||
v-if="row.status !== 'revoked'"
|
||||
link type="danger"
|
||||
@click="setStatus(row, 'revoked')"
|
||||
>下架</el-button>
|
||||
<el-button link type="danger" @click="remove(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<el-pagination
|
||||
v-model:current-page="query.page"
|
||||
v-model:page-size="query.page_size"
|
||||
:total="total"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="load"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 上传发布弹窗 -->
|
||||
<el-dialog v-model="uploadOpen" title="上传发布插件" width="480px">
|
||||
<el-form label-width="90px">
|
||||
<el-form-item label="插件ID" required>
|
||||
<el-input v-model="uploadForm.plugin_id" placeholder="如 seal_check(与 plugin.json 内 id 一致)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="版本号" required>
|
||||
<el-input v-model="uploadForm.version" placeholder="如 1.2.0" />
|
||||
</el-form-item>
|
||||
<el-form-item label="名称">
|
||||
<el-input v-model="uploadForm.name" placeholder="留空则取 plugin.json name" />
|
||||
</el-form-item>
|
||||
<el-form-item label="安装包" required>
|
||||
<input type="file" accept=".zip" @change="(e: any) => (uploadForm.file = e.target.files[0] || null)" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="uploadOpen = false">取消</el-button>
|
||||
<el-button type="primary" :loading="uploading" @click="submitUpload">发布</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,101 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 运行记录(37du 控制台)
|
||||
* 分页 + 状态筛选 + 关键字(对接 /api/admin/reports)
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { fetchReports } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
const total = ref(0)
|
||||
const today = ref(0)
|
||||
const failed = ref(0)
|
||||
const query = reactive({ page: 1, page_size: 20, status: '', q: '' })
|
||||
|
||||
const statusMap: Record<string, { label: string; type: any }> = {
|
||||
start: { label: '启动', type: 'info' },
|
||||
done: { label: '完成', type: 'success' },
|
||||
success: { label: '成功', type: 'success' },
|
||||
error: { label: '错误', type: 'danger' },
|
||||
failed: { label: '失败', type: 'danger' }
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetchReports(query)
|
||||
list.value = r.items || []
|
||||
total.value = r.total || 0
|
||||
today.value = r.today || 0
|
||||
failed.value = r.failed || 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
query.page = 1
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">运行记录</h2>
|
||||
<div>
|
||||
<el-tag type="info" class="mr-2">今日 {{ today }} 条</el-tag>
|
||||
<el-tag type="danger">失败 {{ failed }} 条</el-tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-form inline @submit.prevent="search">
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" clearable placeholder="全部" style="width: 160px" @change="search">
|
||||
<el-option v-for="(v, k) in statusMap" :key="k" :label="v.label" :value="k" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="关键字">
|
||||
<el-input v-model="query.q" placeholder="账号 / 设备 / 插件 / 消息" clearable style="width: 220px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="Object.assign(query, { q: '', status: '' }); search()">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column label="账号" width="110">
|
||||
<template #default="{ row }">{{ row.nickname || row.account || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="pluginId" label="插件" min-width="120" />
|
||||
<el-table-column prop="version" label="版本" width="90" />
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="statusMap[row.status]?.type || 'info'" size="small">
|
||||
{{ statusMap[row.status]?.label || row.status }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="durationSec" label="时长(秒)" width="90" />
|
||||
<el-table-column prop="msg" label="消息" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="at" label="时间" width="170" />
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<el-pagination
|
||||
v-model:current-page="query.page"
|
||||
v-model:page-size="query.page_size"
|
||||
:total="total"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="load"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,28 @@
|
||||
<template>
|
||||
<ArtResultPage
|
||||
type="fail"
|
||||
title="提交失败"
|
||||
message="请核对并修改以下信息后,再重新提交。"
|
||||
iconCode="ri:close-fill"
|
||||
>
|
||||
<template #content>
|
||||
<p>您提交的内容有如下错误:</p>
|
||||
<p>
|
||||
<ArtSvgIcon icon="ri:close-circle-line" class="text-red-500 mr-1" />
|
||||
<span>您的账户已被冻结</span>
|
||||
</p>
|
||||
<p>
|
||||
<ArtSvgIcon icon="ri:close-circle-line" class="text-red-500 mr-1" />
|
||||
<span>您的账户还不具备申请资格</span>
|
||||
</p>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<ElButton type="primary" v-ripple>返回修改</ElButton>
|
||||
<ElButton v-ripple>查看</ElButton>
|
||||
</template>
|
||||
</ArtResultPage>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineOptions({ name: 'ResultFail' })
|
||||
</script>
|
||||
@@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<ArtResultPage
|
||||
type="success"
|
||||
title="提交成功"
|
||||
message="提交结果页用于反馈一系列操作任务的处理结果,如果仅是简单操作,使用 Message 全局提示反馈即可。灰色区域可以显示一些补充的信息。"
|
||||
iconCode="ri:check-fill"
|
||||
>
|
||||
<template #content>
|
||||
<p>已提交申请,等待部门审核。</p>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<ElButton type="primary" v-ripple>返回修改</ElButton>
|
||||
<ElButton v-ripple>查看</ElButton>
|
||||
<ElButton v-ripple>打印</ElButton>
|
||||
</template>
|
||||
</ArtResultPage>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineOptions({ name: 'ResultSuccess' })
|
||||
</script>
|
||||
@@ -0,0 +1,92 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 数据看板(37du 控制台)
|
||||
* 运行统计 + 插件排行 + 活跃用户 + 近14天趋势(对接 /api/admin/stats)
|
||||
*/
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { fetchStats } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const data = ref<any>({})
|
||||
|
||||
const runCards = [
|
||||
{ key: 'total', label: '运行总次数', color: '#377dff' },
|
||||
{ key: 'success', label: '成功', color: '#00b42a' },
|
||||
{ key: 'failed', label: '失败', color: '#f53f3f' },
|
||||
{ key: 'activeUsers', label: '活跃用户', color: '#ff7d00' },
|
||||
{ key: 'activePlugins', label: '活跃插件', color: '#f5319d' }
|
||||
]
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
data.value = await fetchStats()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">数据看板</h2>
|
||||
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||
</div>
|
||||
|
||||
<el-row :gutter="16">
|
||||
<el-col v-for="c in runCards" :key="c.key" :span="4">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<div class="text-2xl font-bold" :style="{ color: c.color }">{{ data.runs?.[c.key] || 0 }}</div>
|
||||
<div class="text-xs text-gray-500 mt-1">{{ c.label }}</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<div class="text-2xl font-bold">{{ data.runs?.durationSec || 0 }}s</div>
|
||||
<div class="text-xs text-gray-500 mt-1">总时长</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header><span class="font-semibold">插件排行(Top 8)</span></template>
|
||||
<el-table :data="data.topPlugins || []" size="small" border>
|
||||
<el-table-column prop="pluginId" label="插件" min-width="120" />
|
||||
<el-table-column prop="name" label="名称" min-width="140" />
|
||||
<el-table-column prop="runs" label="触发次数" width="90" />
|
||||
<el-table-column prop="success" label="成功" width="70" />
|
||||
<el-table-column prop="failed" label="失败" width="70" />
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header><span class="font-semibold">活跃用户(Top 8)</span></template>
|
||||
<el-table :data="data.topUsers || []" size="small" border>
|
||||
<el-table-column prop="account" label="账号" min-width="120" />
|
||||
<el-table-column prop="nickname" label="昵称" min-width="120" />
|
||||
<el-table-column prop="runs" label="运行次数" width="100" />
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header><span class="font-semibold">近 14 天运行趋势</span></template>
|
||||
<div v-if="data.trend?.length" class="flex items-end gap-1" style="height: 120px">
|
||||
<div v-for="t in data.trend" :key="t.day" class="flex-1 flex flex-col items-center gap-1">
|
||||
<div class="text-[10px] text-gray-500">{{ t.runs }}</div>
|
||||
<div class="w-full rounded-sm" :title="`${t.day} 运行 ${t.runs} 次`"
|
||||
:style="{ height: `${Math.max(2, Math.round((t.runs / Math.max(1, ...data.trend.map((x: any) => x.runs))) * 100))}px`, background: '#377dff' }" />
|
||||
<div class="text-[10px] text-gray-400">{{ t.day }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else description="暂无趋势数据" :image-size="60" />
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,96 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 系统管理-部门(37du 重构版,走 /api/admin/sys/departments,后端构建树)
|
||||
* 数据范围"本部门及以下"的载体;支持新增 / 编辑 / 删除(有子级或在用用户拒绝)
|
||||
*/
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { sysDeptDel, sysDepartments } from '@/api/sys'
|
||||
import DepartmentDialog from './modules/department-dialog.vue'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await sysDepartments()
|
||||
list.value = r.items || []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const dialogType = ref<'add' | 'edit'>('add')
|
||||
const currentDept = ref<any>(null)
|
||||
const presetParentId = ref<number | null>(null)
|
||||
|
||||
function openAdd(parent?: any) {
|
||||
dialogType.value = 'add'
|
||||
currentDept.value = null
|
||||
presetParentId.value = parent ? Number(parent.id) : null
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(row: any) {
|
||||
dialogType.value = 'edit'
|
||||
currentDept.value = row
|
||||
presetParentId.value = null
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleDel(row: any) {
|
||||
await ElMessageBox.confirm(`确认删除部门「${row.name}」?`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消'
|
||||
})
|
||||
await sysDeptDel(row.id)
|
||||
ElMessage.success('删除成功')
|
||||
load()
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
dialogVisible.value = false
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">部门管理</h2>
|
||||
<div class="flex gap-2">
|
||||
<el-button type="primary" @click="openAdd()">新增部门</el-button>
|
||||
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe row-key="id" default-expand-all>
|
||||
<el-table-column prop="name" label="部门名称" min-width="220" />
|
||||
<el-table-column prop="orderNum" label="排序" width="80" />
|
||||
<el-table-column prop="createTime" label="创建时间" min-width="170" />
|
||||
<el-table-column label="操作" width="170" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="openAdd(row)">添加子级</el-button>
|
||||
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<DepartmentDialog
|
||||
v-model:visible="dialogVisible"
|
||||
:type="dialogType"
|
||||
:dept-data="currentDept"
|
||||
:preset-parent-id="presetParentId"
|
||||
:tree="list"
|
||||
@submit="handleSubmit"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 部门新增/编辑对话框(37du:base_sys_department)
|
||||
* 上级选择防环由后端校验兜底;有子级/在用用户的部门删除由后端拒绝
|
||||
*/
|
||||
import { computed, nextTick, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { sysDeptAdd, sysDeptEdit } from '@/api/sys'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
type: 'add' | 'edit'
|
||||
deptData?: any
|
||||
presetParentId?: number | null
|
||||
tree?: any[]
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:visible', value: boolean): void
|
||||
(e: 'submit'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
deptData: undefined,
|
||||
presetParentId: null,
|
||||
tree: () => []
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const dialogVisible = computed({
|
||||
get: () => props.visible,
|
||||
set: (value) => emit('update:visible', value)
|
||||
})
|
||||
const isEdit = computed(() => props.type === 'edit')
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const submitting = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
id: 0,
|
||||
parentId: null as number | null,
|
||||
name: '',
|
||||
orderNum: 0
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: '请输入部门名称', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const treeSelectData = computed(() => {
|
||||
const build = (nodes: any[]): any[] =>
|
||||
(nodes || []).map((n) => ({
|
||||
value: Number(n.id),
|
||||
label: n.name,
|
||||
children: n.children?.length ? build(n.children) : undefined
|
||||
}))
|
||||
return build(props.tree)
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
async (visible) => {
|
||||
if (!visible) return
|
||||
await nextTick()
|
||||
formRef.value?.clearValidate()
|
||||
if (props.type === 'edit' && props.deptData) {
|
||||
Object.assign(form, {
|
||||
id: props.deptData.id,
|
||||
parentId: props.deptData.parentId ? Number(props.deptData.parentId) : null,
|
||||
name: props.deptData.name || '',
|
||||
orderNum: Number(props.deptData.orderNum ?? 0)
|
||||
})
|
||||
} else {
|
||||
Object.assign(form, {
|
||||
id: 0,
|
||||
parentId: props.presetParentId,
|
||||
name: '',
|
||||
orderNum: 0
|
||||
})
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate()
|
||||
submitting.value = true
|
||||
try {
|
||||
if (isEdit.value) {
|
||||
await sysDeptEdit({ id: form.id, parentId: form.parentId, name: form.name, orderNum: form.orderNum })
|
||||
ElMessage.success('修改成功')
|
||||
} else {
|
||||
await sysDeptAdd({ parentId: form.parentId, name: form.name, orderNum: form.orderNum })
|
||||
ElMessage.success('新增成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
emit('submit')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑部门' : '新增部门'"
|
||||
width="460px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="上级部门" prop="parentId">
|
||||
<el-tree-select
|
||||
v-model="form.parentId"
|
||||
:data="treeSelectData"
|
||||
node-key="value"
|
||||
check-strictly
|
||||
clearable
|
||||
placeholder="不选则为顶级"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="部门名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="部门名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="orderNum">
|
||||
<el-input-number v-model="form.orderNum" :min="0" :max="9999" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
@@ -0,0 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
const router = useRouter()
|
||||
onMounted(() => { router.replace({ name: 'SysUser' }) })
|
||||
</script>
|
||||
<template><div /></template>
|
||||
@@ -0,0 +1,107 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 系统管理-菜单(37du 重构版,走 /api/admin/sys/menus,后端构建树)
|
||||
* 支持:新增 / 编辑 / 删除(有子级拒绝);type: 0目录 1菜单 2按钮
|
||||
*/
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { sysMenuDel, sysMenus } from '@/api/sys'
|
||||
import MenuDialog from './modules/menu-dialog.vue'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
|
||||
const typeName = (t: number) => (Number(t) === 0 ? '目录' : Number(t) === 1 ? '菜单' : '按钮')
|
||||
const typeTag = (t: number) => (Number(t) === 0 ? 'info' : Number(t) === 1 ? 'success' : 'warning')
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await sysMenus()
|
||||
list.value = r.items || []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 新增/编辑对话框 ----
|
||||
const dialogVisible = ref(false)
|
||||
const dialogType = ref<'add' | 'edit'>('add')
|
||||
const currentMenu = ref<any>(null)
|
||||
const presetParentId = ref<number | null>(null)
|
||||
|
||||
function openAdd(parent?: any) {
|
||||
dialogType.value = 'add'
|
||||
currentMenu.value = null
|
||||
presetParentId.value = parent ? Number(parent.id) : null
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(row: any) {
|
||||
dialogType.value = 'edit'
|
||||
currentMenu.value = row
|
||||
presetParentId.value = null
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleDel(row: any) {
|
||||
await ElMessageBox.confirm(`确认删除菜单「${row.name}」?`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消'
|
||||
})
|
||||
await sysMenuDel(row.id)
|
||||
ElMessage.success('删除成功')
|
||||
load()
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
dialogVisible.value = false
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">菜单管理</h2>
|
||||
<div class="flex gap-2">
|
||||
<el-button type="primary" @click="openAdd()">新增菜单</el-button>
|
||||
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe row-key="id" default-expand-all>
|
||||
<el-table-column prop="name" label="名称" min-width="180" />
|
||||
<el-table-column label="类型" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" :type="typeTag(row.type)">{{ typeName(row.type) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="router" label="路由" min-width="150" show-overflow-tooltip />
|
||||
<el-table-column prop="perms" label="权限标识" min-width="210" show-overflow-tooltip />
|
||||
<el-table-column prop="icon" label="图标" width="130" show-overflow-tooltip />
|
||||
<el-table-column prop="orderNum" label="排序" width="70" />
|
||||
<el-table-column label="操作" width="170" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button v-if="Number(row.type) !== 2" link type="primary" size="small" @click="openAdd(row)">添加子级</el-button>
|
||||
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<MenuDialog
|
||||
v-model:visible="dialogVisible"
|
||||
:type="dialogType"
|
||||
:menu-data="currentMenu"
|
||||
:preset-parent-id="presetParentId"
|
||||
:tree="list"
|
||||
@submit="handleSubmit"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,199 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 菜单新增/编辑对话框(37du:base_sys_menu)
|
||||
* type: 0目录 1菜单 2按钮;目录/菜单必填路由,按钮填权限标识;上级选择防环由后端校验兜底
|
||||
*/
|
||||
import { computed, nextTick, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { sysMenuAdd, sysMenuEdit } from '@/api/sys'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
type: 'add' | 'edit'
|
||||
menuData?: any
|
||||
presetParentId?: number | null
|
||||
tree?: any[]
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:visible', value: boolean): void
|
||||
(e: 'submit'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
menuData: undefined,
|
||||
presetParentId: null,
|
||||
tree: () => []
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const dialogVisible = computed({
|
||||
get: () => props.visible,
|
||||
set: (value) => emit('update:visible', value)
|
||||
})
|
||||
const isEdit = computed(() => props.type === 'edit')
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const submitting = ref(false)
|
||||
|
||||
const typeOptions = [
|
||||
{ value: 0, label: '目录' },
|
||||
{ value: 1, label: '菜单' },
|
||||
{ value: 2, label: '按钮' }
|
||||
]
|
||||
|
||||
const form = reactive({
|
||||
id: 0,
|
||||
parentId: null as number | null,
|
||||
name: '',
|
||||
router: '',
|
||||
perms: '',
|
||||
icon: '',
|
||||
type: 1,
|
||||
orderNum: 0
|
||||
})
|
||||
|
||||
const treeSelectData = computed(() => {
|
||||
const build = (nodes: any[]): any[] =>
|
||||
(nodes || []).map((n) => ({
|
||||
value: Number(n.id),
|
||||
label: n.name,
|
||||
children: n.children?.length ? build(n.children) : undefined
|
||||
}))
|
||||
return build(props.tree)
|
||||
})
|
||||
|
||||
const rules = computed<FormRules>(() => ({
|
||||
name: [{ required: true, message: '请输入菜单名称', trigger: 'blur' }],
|
||||
router: [
|
||||
{
|
||||
validator: (_r, value, callback) => {
|
||||
if (form.type !== 2 && !String(value || '').trim()) {
|
||||
callback(new Error('目录/菜单类型必须填写路由'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
}))
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
async (visible) => {
|
||||
if (!visible) return
|
||||
await nextTick()
|
||||
formRef.value?.clearValidate()
|
||||
if (props.type === 'edit' && props.menuData) {
|
||||
Object.assign(form, {
|
||||
id: props.menuData.id,
|
||||
parentId: props.menuData.parentId ? Number(props.menuData.parentId) : null,
|
||||
name: props.menuData.name || '',
|
||||
router: props.menuData.router || '',
|
||||
perms: props.menuData.perms || '',
|
||||
icon: props.menuData.icon || '',
|
||||
type: Number(props.menuData.type ?? 1),
|
||||
orderNum: Number(props.menuData.orderNum ?? 0)
|
||||
})
|
||||
} else {
|
||||
Object.assign(form, {
|
||||
id: 0,
|
||||
parentId: props.presetParentId,
|
||||
name: '',
|
||||
router: '',
|
||||
perms: '',
|
||||
icon: '',
|
||||
type: 1,
|
||||
orderNum: 0
|
||||
})
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate()
|
||||
submitting.value = true
|
||||
try {
|
||||
if (isEdit.value) {
|
||||
await sysMenuEdit({
|
||||
id: form.id,
|
||||
parentId: form.parentId,
|
||||
name: form.name,
|
||||
router: form.router,
|
||||
perms: form.perms,
|
||||
icon: form.icon,
|
||||
type: form.type,
|
||||
orderNum: form.orderNum
|
||||
})
|
||||
ElMessage.success('修改成功')
|
||||
} else {
|
||||
await sysMenuAdd({
|
||||
parentId: form.parentId,
|
||||
name: form.name,
|
||||
router: form.router,
|
||||
perms: form.perms,
|
||||
icon: form.icon,
|
||||
type: form.type,
|
||||
orderNum: form.orderNum
|
||||
})
|
||||
ElMessage.success('新增成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
emit('submit')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑菜单' : '新增菜单'"
|
||||
width="520px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="上级菜单" prop="parentId">
|
||||
<el-tree-select
|
||||
v-model="form.parentId"
|
||||
:data="treeSelectData"
|
||||
node-key="value"
|
||||
check-strictly
|
||||
clearable
|
||||
placeholder="不选则为顶级"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="类型" prop="type">
|
||||
<el-radio-group v-model="form.type">
|
||||
<el-radio v-for="t in typeOptions" :key="t.value" :value="t.value">{{ t.label }}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="菜单/按钮名称" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.type !== 2" label="路由" prop="router">
|
||||
<el-input v-model="form.router" placeholder="如 /system/user" />
|
||||
</el-form-item>
|
||||
<el-form-item label="权限标识" prop="perms">
|
||||
<el-input v-model="form.perms" placeholder="如 center:sys:user:list(按钮必填)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="图标" prop="icon">
|
||||
<el-input v-model="form.icon" placeholder="图标标识(可选,如 ri:settings-3-line)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="orderNum">
|
||||
<el-input-number v-model="form.orderNum" :min="0" :max="9999" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
@@ -0,0 +1,141 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 系统管理-角色(37du 重构版,走 /api/admin/sys/roles)
|
||||
* 支持:搜索 / 新增 / 编辑 / 授权(菜单+部门树)/ 删除;内置超管角色(id=1 或 label=admin)受保护
|
||||
*/
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { sysRoleDel, sysRoles } from '@/api/sys'
|
||||
import RoleSearch from './modules/role-search.vue'
|
||||
import RoleEditDialog from './modules/role-edit-dialog.vue'
|
||||
import RolePermissionDialog from './modules/role-permission-dialog.vue'
|
||||
|
||||
const loading = ref(false)
|
||||
const all = ref<any[]>([])
|
||||
|
||||
const keyword = ref('')
|
||||
|
||||
const filteredList = computed(() => {
|
||||
const kw = keyword.value.trim().toLowerCase()
|
||||
if (!kw) return all.value
|
||||
return all.value.filter(
|
||||
(r) =>
|
||||
String(r.name || '').toLowerCase().includes(kw) ||
|
||||
String(r.label || '').toLowerCase().includes(kw) ||
|
||||
String(r.remark || '').toLowerCase().includes(kw)
|
||||
)
|
||||
})
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await sysRoles()
|
||||
all.value = r.items || []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch(params: { keyword: string }) {
|
||||
keyword.value = params.keyword
|
||||
}
|
||||
|
||||
// ---- 编辑对话框 ----
|
||||
const editVisible = ref(false)
|
||||
const editType = ref<'add' | 'edit'>('add')
|
||||
const currentRole = ref<any>(null)
|
||||
|
||||
function openAdd() {
|
||||
editType.value = 'add'
|
||||
currentRole.value = null
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(row: any) {
|
||||
editType.value = 'edit'
|
||||
currentRole.value = row
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
// ---- 权限对话框 ----
|
||||
const permVisible = ref(false)
|
||||
const permRole = ref<any>(null)
|
||||
|
||||
function openPerm(row: any) {
|
||||
permRole.value = row
|
||||
permVisible.value = true
|
||||
}
|
||||
|
||||
async function handleDel(row: any) {
|
||||
if (row.protected) {
|
||||
ElMessage.warning('内置超管角色不允许删除')
|
||||
return
|
||||
}
|
||||
await ElMessageBox.confirm(`确认删除角色「${row.name}」?将一并解除该角色的用户绑定与授权关系`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消'
|
||||
})
|
||||
await sysRoleDel(row.id)
|
||||
ElMessage.success('删除成功')
|
||||
load()
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
editVisible.value = false
|
||||
load()
|
||||
}
|
||||
|
||||
function handlePermSaved() {
|
||||
permVisible.value = false
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">角色管理</h2>
|
||||
<div class="flex gap-2">
|
||||
<el-button type="primary" @click="openAdd">新增角色</el-button>
|
||||
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<RoleSearch @search="handleSearch" />
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="filteredList" border stripe>
|
||||
<el-table-column prop="id" label="ID" width="70" />
|
||||
<el-table-column prop="name" label="角色名" min-width="140">
|
||||
<template #default="{ row }">
|
||||
<span>{{ row.name }}</span>
|
||||
<el-tag v-if="row.protected" size="small" type="warning" class="ml-1">内置</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="label" label="标识" min-width="110" />
|
||||
<el-table-column prop="remark" label="备注" min-width="170" show-overflow-tooltip />
|
||||
<el-table-column label="数据权限关联上下级" width="150">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.relevance ? 'primary' : 'info'" size="small">{{ row.relevance ? '是' : '否' }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="180" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<template v-if="!row.protected">
|
||||
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="primary" size="small" @click="openPerm(row)">授权</el-button>
|
||||
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
|
||||
</template>
|
||||
<span v-else class="text-xs text-gray-400">全部权限</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<RoleEditDialog v-model:visible="editVisible" :type="editType" :role-data="currentRole" @submit="handleSubmit" />
|
||||
<RolePermissionDialog v-model:visible="permVisible" :role-data="permRole" @success="handlePermSaved" />
|
||||
</div>
|
||||
</template>
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 角色新增/编辑对话框(37du:base_sys_role)
|
||||
* name 必填;label 全局唯一标识(内置 admin 不可用);relevance=数据权限是否关联上下级
|
||||
*/
|
||||
import { computed, nextTick, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { sysRoleAdd, sysRoleEdit } from '@/api/sys'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
type: 'add' | 'edit'
|
||||
roleData?: any
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:visible', value: boolean): void
|
||||
(e: 'submit'): void
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const dialogVisible = computed({
|
||||
get: () => props.visible,
|
||||
set: (value) => emit('update:visible', value)
|
||||
})
|
||||
const isEdit = computed(() => props.type === 'edit')
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const submitting = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
id: 0,
|
||||
name: '',
|
||||
label: '',
|
||||
remark: '',
|
||||
relevance: false
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: '请输入角色名称', trigger: 'blur' }],
|
||||
label: [
|
||||
{
|
||||
validator: (_rule, value, callback) => {
|
||||
const v = String(value || '').trim()
|
||||
if (v.toLowerCase() === 'admin') {
|
||||
callback(new Error('admin 为内置超管标识,不可使用'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
async (visible) => {
|
||||
if (!visible) return
|
||||
await nextTick()
|
||||
formRef.value?.clearValidate()
|
||||
if (props.type === 'edit' && props.roleData) {
|
||||
Object.assign(form, {
|
||||
id: props.roleData.id,
|
||||
name: props.roleData.name || '',
|
||||
label: props.roleData.label || '',
|
||||
remark: props.roleData.remark || '',
|
||||
relevance: !!props.roleData.relevance
|
||||
})
|
||||
} else {
|
||||
Object.assign(form, { id: 0, name: '', label: '', remark: '', relevance: false })
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate()
|
||||
submitting.value = true
|
||||
try {
|
||||
if (isEdit.value) {
|
||||
await sysRoleEdit({
|
||||
id: form.id,
|
||||
name: form.name,
|
||||
label: form.label,
|
||||
remark: form.remark,
|
||||
relevance: form.relevance
|
||||
})
|
||||
ElMessage.success('修改成功')
|
||||
} else {
|
||||
await sysRoleAdd({
|
||||
name: form.name,
|
||||
label: form.label,
|
||||
remark: form.remark,
|
||||
relevance: form.relevance
|
||||
})
|
||||
ElMessage.success('新增成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
emit('submit')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑角色' : '新增角色'"
|
||||
width="480px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="130px">
|
||||
<el-form-item label="角色名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="如:部门管理员" />
|
||||
</el-form-item>
|
||||
<el-form-item label="角色标识" prop="label">
|
||||
<el-input v-model="form.label" placeholder="英文标识(唯一,如 dept-admin)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="关联上下级" prop="relevance">
|
||||
<el-switch v-model="form.relevance" />
|
||||
<span class="ml-2 text-xs text-gray-400">数据权限:授权部门时自动包含其下级部门</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="备注(可选)" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 角色授权对话框(37du):菜单权限(base_sys_menu 树)+ 部门权限(base_sys_department 树)
|
||||
* - 打开时 GET /api/admin/sys/role/info 回显 menuIdList/departmentIdList
|
||||
* - 保存 POST /api/admin/sys/role/edit(checked + halfChecked 合并提交,后端原子重建授权关系)
|
||||
*/
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { sysDepartments, sysMenus, sysRoleEdit, sysRoleInfo } from '@/api/sys'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
roleData?: any
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:visible', value: boolean): void
|
||||
(e: 'success'): void
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.visible,
|
||||
set: (value) => emit('update:visible', value)
|
||||
})
|
||||
|
||||
const activeTab = ref<'menu' | 'dept'>('menu')
|
||||
const menuTreeRef = ref()
|
||||
const deptTreeRef = ref()
|
||||
const menuTree = ref<any[]>([])
|
||||
const deptTree = ref<any[]>([])
|
||||
const saving = ref(false)
|
||||
|
||||
const treeProps = { children: 'children', label: 'name' }
|
||||
|
||||
const typeName = (t: number) => (Number(t) === 0 ? '目录' : Number(t) === 1 ? '菜单' : '按钮')
|
||||
|
||||
async function loadTrees() {
|
||||
try {
|
||||
const [m, d] = await Promise.all([sysMenus(), sysDepartments()])
|
||||
menuTree.value = m.items || []
|
||||
deptTree.value = d.items || []
|
||||
} catch (e) {
|
||||
/* 树加载失败不阻断 */
|
||||
}
|
||||
}
|
||||
|
||||
/** 找出树中无子级的节点 id(el-tree 级联勾选下仅勾叶子,父级自动半选) */
|
||||
function collectLeafIds(nodes: any[], idSet: Set<number>, out: number[]) {
|
||||
for (const n of nodes) {
|
||||
const id = Number(n.id)
|
||||
if (idSet.has(id)) {
|
||||
if (!n.children?.length) {
|
||||
out.push(id)
|
||||
} else {
|
||||
// 非叶节点:若其全部子级都在集合中,勾它本身即可(级联覆盖)
|
||||
const childIds = collectAllChildIds(n)
|
||||
const allIn = childIds.every((cid) => idSet.has(cid))
|
||||
if (allIn) out.push(id)
|
||||
else collectLeafIds(n.children, idSet, out)
|
||||
}
|
||||
} else if (n.children?.length) {
|
||||
collectLeafIds(n.children, idSet, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function collectAllChildIds(node: any): number[] {
|
||||
const out: number[] = []
|
||||
const walk = (n: any) => {
|
||||
for (const c of n.children || []) {
|
||||
out.push(Number(c.id))
|
||||
walk(c)
|
||||
}
|
||||
}
|
||||
walk(node)
|
||||
return out
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
async (visible) => {
|
||||
if (!visible || !props.roleData) return
|
||||
activeTab.value = 'menu'
|
||||
await loadTrees()
|
||||
await nextTick()
|
||||
try {
|
||||
const info = await sysRoleInfo(props.roleData.id)
|
||||
const menuIds = new Set<number>((info?.menuIdList || []).map(Number))
|
||||
const deptIds = new Set<number>((info?.departmentIdList || []).map(Number))
|
||||
const menuChecked: number[] = []
|
||||
const deptChecked: number[] = []
|
||||
collectLeafIds(menuTree.value, menuIds, menuChecked)
|
||||
collectLeafIds(deptTree.value, deptIds, deptChecked)
|
||||
menuTreeRef.value?.setCheckedKeys(menuChecked)
|
||||
deptTreeRef.value?.setCheckedKeys(deptChecked)
|
||||
} catch (e) {
|
||||
menuTreeRef.value?.setCheckedKeys([])
|
||||
deptTreeRef.value?.setCheckedKeys([])
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
async function handleSave() {
|
||||
if (!props.roleData) return
|
||||
saving.value = true
|
||||
try {
|
||||
const menuChecked: number[] = menuTreeRef.value?.getCheckedKeys() || []
|
||||
const menuHalf: number[] = menuTreeRef.value?.getHalfCheckedKeys() || []
|
||||
const deptChecked: number[] = deptTreeRef.value?.getCheckedKeys() || []
|
||||
const deptHalf: number[] = deptTreeRef.value?.getHalfCheckedKeys() || []
|
||||
const menuIdList = [...new Set([...menuChecked, ...menuHalf])].map(Number)
|
||||
const departmentIdList = [...new Set([...deptChecked, ...deptHalf])].map(Number)
|
||||
await sysRoleEdit({
|
||||
id: props.roleData.id,
|
||||
menuIdList,
|
||||
departmentIdList
|
||||
})
|
||||
ElMessage.success('授权保存成功')
|
||||
emit('success')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="`角色授权 — ${props.roleData?.name || ''}`"
|
||||
width="520px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-tabs v-model="activeTab">
|
||||
<el-tab-pane label="菜单权限" name="menu">
|
||||
<el-scrollbar height="52vh">
|
||||
<el-tree
|
||||
ref="menuTreeRef"
|
||||
:data="menuTree"
|
||||
show-checkbox
|
||||
node-key="id"
|
||||
default-expand-all
|
||||
:props="treeProps"
|
||||
>
|
||||
<template #default="{ data }">
|
||||
<div class="flex items-center gap-2">
|
||||
<el-tag size="small" :type="Number(data.type) === 2 ? 'warning' : 'info'">{{ typeName(data.type) }}</el-tag>
|
||||
<span>{{ data.name }}</span>
|
||||
<span v-if="data.perms" class="text-xs text-gray-400">{{ data.perms }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</el-tree>
|
||||
</el-scrollbar>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="部门权限(数据范围)" name="dept">
|
||||
<el-scrollbar height="52vh">
|
||||
<el-tree
|
||||
ref="deptTreeRef"
|
||||
:data="deptTree"
|
||||
show-checkbox
|
||||
node-key="id"
|
||||
default-expand-all
|
||||
:props="treeProps"
|
||||
/>
|
||||
</el-scrollbar>
|
||||
<div class="mt-2 text-xs text-gray-400">勾选部门即授权该部门数据范围;角色开启"关联上下级"时查询自动包含下级部门</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<template #footer>
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="handleSave">保存授权</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 角色搜索栏:关键字(角色名/标识/备注)过滤(客户端,emit search)
|
||||
*/
|
||||
import { reactive } from 'vue'
|
||||
|
||||
interface Emits {
|
||||
(e: 'search', params: { keyword: string }): void
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const keyword = ref('')
|
||||
|
||||
function handleSearch() {
|
||||
emit('search', { keyword: keyword.value })
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
keyword.value = ''
|
||||
emit('search', { keyword: '' })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<el-input
|
||||
v-model="keyword"
|
||||
placeholder="角色名 / 标识 / 备注"
|
||||
clearable
|
||||
style="width: 240px"
|
||||
@keyup.enter="handleSearch"
|
||||
@clear="handleSearch"
|
||||
/>
|
||||
<el-button type="primary" @click="handleSearch">查询</el-button>
|
||||
<el-button @click="handleReset">重置</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
</template>
|
||||
@@ -0,0 +1,247 @@
|
||||
<!-- 个人中心页面 -->
|
||||
<template>
|
||||
<div class="w-full h-full p-0 bg-transparent border-none shadow-none">
|
||||
<div class="relative flex-b mt-2.5 max-md:block max-md:mt-1">
|
||||
<div class="w-112 mr-5 max-md:w-full max-md:mr-0">
|
||||
<div class="art-card-sm relative p-9 pb-6 overflow-hidden text-center">
|
||||
<img class="absolute top-0 left-0 w-full h-50 object-cover" src="@imgs/user/bg.webp" />
|
||||
<img
|
||||
class="relative z-10 w-20 h-20 mt-30 mx-auto object-cover border-2 border-white rounded-full"
|
||||
src="@imgs/user/avatar.webp"
|
||||
/>
|
||||
<h2 class="mt-5 text-xl font-normal">{{ userInfo.userName }}</h2>
|
||||
<p class="mt-5 text-sm">专注于用户体验跟视觉设计</p>
|
||||
|
||||
<div class="w-75 mx-auto mt-7.5 text-left">
|
||||
<div class="mt-2.5">
|
||||
<ArtSvgIcon icon="ri:mail-line" class="text-g-700" />
|
||||
<span class="ml-2 text-sm">jdkjjfnndf@mall.com</span>
|
||||
</div>
|
||||
<div class="mt-2.5">
|
||||
<ArtSvgIcon icon="ri:user-3-line" class="text-g-700" />
|
||||
<span class="ml-2 text-sm">交互专家</span>
|
||||
</div>
|
||||
<div class="mt-2.5">
|
||||
<ArtSvgIcon icon="ri:map-pin-line" class="text-g-700" />
|
||||
<span class="ml-2 text-sm">广东省深圳市</span>
|
||||
</div>
|
||||
<div class="mt-2.5">
|
||||
<ArtSvgIcon icon="ri:dribbble-fill" class="text-g-700" />
|
||||
<span class="ml-2 text-sm">字节跳动-某某平台部-UED</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-10">
|
||||
<h3 class="text-sm font-medium">标签</h3>
|
||||
<div class="flex flex-wrap justify-center mt-3.5">
|
||||
<div
|
||||
v-for="item in lableList"
|
||||
:key="item"
|
||||
class="py-1 px-1.5 mr-2.5 mb-2.5 text-xs border border-g-300 rounded"
|
||||
>
|
||||
{{ item }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-1 overflow-hidden max-md:w-full max-md:mt-3.5">
|
||||
<div class="art-card-sm">
|
||||
<h1 class="p-4 text-xl font-normal border-b border-g-300">基本设置</h1>
|
||||
|
||||
<ElForm
|
||||
:model="form"
|
||||
class="box-border p-5 [&>.el-row_.el-form-item]:w-[calc(50%-10px)] [&>.el-row_.el-input]:w-full [&>.el-row_.el-select]:w-full"
|
||||
ref="ruleFormRef"
|
||||
:rules="rules"
|
||||
label-width="86px"
|
||||
label-position="top"
|
||||
>
|
||||
<ElRow>
|
||||
<ElFormItem label="姓名" prop="realName">
|
||||
<ElInput v-model="form.realName" :disabled="!isEdit" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="性别" prop="sex" class="ml-5">
|
||||
<ElSelect v-model="form.sex" placeholder="Select" :disabled="!isEdit">
|
||||
<ElOption
|
||||
v-for="item in options"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElRow>
|
||||
|
||||
<ElRow>
|
||||
<ElFormItem label="昵称" prop="nikeName">
|
||||
<ElInput v-model="form.nikeName" :disabled="!isEdit" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="邮箱" prop="email" class="ml-5">
|
||||
<ElInput v-model="form.email" :disabled="!isEdit" />
|
||||
</ElFormItem>
|
||||
</ElRow>
|
||||
|
||||
<ElRow>
|
||||
<ElFormItem label="手机" prop="mobile">
|
||||
<ElInput v-model="form.mobile" :disabled="!isEdit" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="地址" prop="address" class="ml-5">
|
||||
<ElInput v-model="form.address" :disabled="!isEdit" />
|
||||
</ElFormItem>
|
||||
</ElRow>
|
||||
|
||||
<ElFormItem label="个人介绍" prop="des" class="h-32">
|
||||
<ElInput type="textarea" :rows="4" v-model="form.des" :disabled="!isEdit" />
|
||||
</ElFormItem>
|
||||
|
||||
<div class="flex-c justify-end [&_.el-button]:!w-27.5">
|
||||
<ElButton type="primary" class="w-22.5" v-ripple @click="edit">
|
||||
{{ isEdit ? '保存' : '编辑' }}
|
||||
</ElButton>
|
||||
</div>
|
||||
</ElForm>
|
||||
</div>
|
||||
|
||||
<div class="art-card-sm my-5">
|
||||
<h1 class="p-4 text-xl font-normal border-b border-g-300">更改密码</h1>
|
||||
|
||||
<ElForm :model="pwdForm" class="box-border p-5" label-width="86px" label-position="top">
|
||||
<ElFormItem label="当前密码" prop="password">
|
||||
<ElInput
|
||||
v-model="pwdForm.password"
|
||||
type="password"
|
||||
:disabled="!isEditPwd"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
|
||||
<ElFormItem label="新密码" prop="newPassword">
|
||||
<ElInput
|
||||
v-model="pwdForm.newPassword"
|
||||
type="password"
|
||||
:disabled="!isEditPwd"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
|
||||
<ElFormItem label="确认新密码" prop="confirmPassword">
|
||||
<ElInput
|
||||
v-model="pwdForm.confirmPassword"
|
||||
type="password"
|
||||
:disabled="!isEditPwd"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
|
||||
<div class="flex-c justify-end [&_.el-button]:!w-27.5">
|
||||
<ElButton type="primary" class="w-22.5" v-ripple @click="editPwd">
|
||||
{{ isEditPwd ? '保存' : '编辑' }}
|
||||
</ElButton>
|
||||
</div>
|
||||
</ElForm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
defineOptions({ name: 'UserCenter' })
|
||||
|
||||
const userStore = useUserStore()
|
||||
const userInfo = computed(() => userStore.getUserInfo)
|
||||
|
||||
const isEdit = ref(false)
|
||||
const isEditPwd = ref(false)
|
||||
const date = ref('')
|
||||
const ruleFormRef = ref<FormInstance>()
|
||||
|
||||
/**
|
||||
* 用户信息表单
|
||||
*/
|
||||
const form = reactive({
|
||||
realName: 'John Snow',
|
||||
nikeName: '皮卡丘',
|
||||
email: '59301283@mall.com',
|
||||
mobile: '18888888888',
|
||||
address: '广东省深圳市宝安区西乡街道101栋201',
|
||||
sex: '2',
|
||||
des: 'Art Design Pro 是一款兼具设计美学与高效开发的后台系统.'
|
||||
})
|
||||
|
||||
/**
|
||||
* 密码修改表单
|
||||
*/
|
||||
const pwdForm = reactive({
|
||||
password: '123456',
|
||||
newPassword: '123456',
|
||||
confirmPassword: '123456'
|
||||
})
|
||||
|
||||
/**
|
||||
* 表单验证规则
|
||||
*/
|
||||
const rules = reactive<FormRules>({
|
||||
realName: [
|
||||
{ required: true, message: '请输入姓名', trigger: 'blur' },
|
||||
{ min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
|
||||
],
|
||||
nikeName: [
|
||||
{ required: true, message: '请输入昵称', trigger: 'blur' },
|
||||
{ min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
|
||||
],
|
||||
email: [{ required: true, message: '请输入邮箱', trigger: 'blur' }],
|
||||
mobile: [{ required: true, message: '请输入手机号码', trigger: 'blur' }],
|
||||
address: [{ required: true, message: '请输入地址', trigger: 'blur' }],
|
||||
sex: [{ required: true, message: '请选择性别', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
/**
|
||||
* 性别选项
|
||||
*/
|
||||
const options = [
|
||||
{ value: '1', label: '男' },
|
||||
{ value: '2', label: '女' }
|
||||
]
|
||||
|
||||
/**
|
||||
* 用户标签列表
|
||||
*/
|
||||
const lableList: Array<string> = ['专注设计', '很有想法', '辣~', '大长腿', '川妹子', '海纳百川']
|
||||
|
||||
onMounted(() => {
|
||||
getDate()
|
||||
})
|
||||
|
||||
/**
|
||||
* 根据当前时间获取问候语
|
||||
*/
|
||||
const getDate = () => {
|
||||
const h = new Date().getHours()
|
||||
|
||||
if (h >= 6 && h < 9) date.value = '早上好'
|
||||
else if (h >= 9 && h < 11) date.value = '上午好'
|
||||
else if (h >= 11 && h < 13) date.value = '中午好'
|
||||
else if (h >= 13 && h < 18) date.value = '下午好'
|
||||
else if (h >= 18 && h < 24) date.value = '晚上好'
|
||||
else date.value = '很晚了,早点睡'
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换用户信息编辑状态
|
||||
*/
|
||||
const edit = () => {
|
||||
isEdit.value = !isEdit.value
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换密码编辑状态
|
||||
*/
|
||||
const editPwd = () => {
|
||||
isEditPwd.value = !isEditPwd.value
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,136 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 系统管理-用户(37du 重构版,走 /api/admin/sys/users)
|
||||
* 说明:此为控制台登录账号(base_sys_user)管理;业务账号管理在"账号管理"页
|
||||
* 支持:搜索 / 新增 / 编辑(改密/部门/角色)/ 删除;内置 admin 行受保护
|
||||
*/
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { sysUserDel, sysUsers } from '@/api/sys'
|
||||
import UserSearch from './modules/user-search.vue'
|
||||
import UserDialog from './modules/user-dialog.vue'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
const all = ref<any[]>([])
|
||||
|
||||
// 搜索条件(客户端过滤)
|
||||
const keyword = ref('')
|
||||
const status = ref<number | null>(null)
|
||||
|
||||
const filteredList = computed(() => {
|
||||
return all.value.filter((u) => {
|
||||
const kw = keyword.value.trim().toLowerCase()
|
||||
const kwOk =
|
||||
!kw ||
|
||||
String(u.username || '').toLowerCase().includes(kw) ||
|
||||
String(u.nickName || '').toLowerCase().includes(kw) ||
|
||||
String(u.roleName || '').toLowerCase().includes(kw)
|
||||
const stOk = status.value === null || status.value === undefined || Number(u.status) === status.value
|
||||
return kwOk && stOk
|
||||
})
|
||||
})
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await sysUsers()
|
||||
all.value = r.items || []
|
||||
list.value = all.value
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch(params: { keyword: string; status: number | null }) {
|
||||
keyword.value = params.keyword
|
||||
status.value = params.status
|
||||
}
|
||||
|
||||
// ---- 新增/编辑对话框 ----
|
||||
const dialogVisible = ref(false)
|
||||
const dialogType = ref<'add' | 'edit'>('add')
|
||||
const currentUser = ref<any>(null)
|
||||
|
||||
function openAdd() {
|
||||
dialogType.value = 'add'
|
||||
currentUser.value = null
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(row: any) {
|
||||
dialogType.value = 'edit'
|
||||
currentUser.value = row
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleDel(row: any) {
|
||||
if (row.usernameProtected) {
|
||||
ElMessage.warning('内置管理员不允许删除')
|
||||
return
|
||||
}
|
||||
await ElMessageBox.confirm(`确认删除用户「${row.username}」?删除后该控制台账号无法登录`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消'
|
||||
})
|
||||
await sysUserDel(row.id)
|
||||
ElMessage.success('删除成功')
|
||||
load()
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
dialogVisible.value = false
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">用户管理(控制台)</h2>
|
||||
<div class="flex gap-2">
|
||||
<el-button type="primary" @click="openAdd">新增用户</el-button>
|
||||
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<UserSearch @search="handleSearch" />
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="filteredList" border stripe>
|
||||
<el-table-column prop="id" label="ID" width="70" />
|
||||
<el-table-column prop="username" label="用户名" min-width="120">
|
||||
<template #default="{ row }">
|
||||
<span>{{ row.username }}</span>
|
||||
<el-tag v-if="row.usernameProtected" size="small" type="warning" class="ml-1">内置</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="nickName" label="昵称" min-width="110" />
|
||||
<el-table-column prop="departmentName" label="部门" min-width="110" />
|
||||
<el-table-column prop="roleName" label="角色" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'danger'" size="small">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间" min-width="165" />
|
||||
<el-table-column label="操作" width="140" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<template v-if="!row.usernameProtected">
|
||||
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
|
||||
</template>
|
||||
<span v-else class="text-xs text-gray-400">受保护</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<UserDialog v-model:visible="dialogVisible" :type="dialogType" :user-data="currentUser" @submit="handleSubmit" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,227 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 用户新增/编辑对话框(37du:base_sys_user + 角色绑定)
|
||||
* - 新增:用户名+密码必填;编辑:用户名不可改、密码留空不改
|
||||
* - 部门下拉取 /api/admin/sys/departments;角色多选取 /api/admin/sys/roles
|
||||
*/
|
||||
import { computed, nextTick, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { sysDepartments, sysRoles, sysUserAdd, sysUserEdit, sysUserInfo } from '@/api/sys'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
type: 'add' | 'edit'
|
||||
userData?: any
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:visible', value: boolean): void
|
||||
(e: 'submit'): void
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const dialogVisible = computed({
|
||||
get: () => props.visible,
|
||||
set: (value) => emit('update:visible', value)
|
||||
})
|
||||
const isEdit = computed(() => props.type === 'edit')
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const submitting = ref(false)
|
||||
|
||||
// 部门/角色数据源
|
||||
const deptTree = ref<any[]>([])
|
||||
const deptTreeSelectData = ref<any[]>([])
|
||||
const roleOptions = ref<any[]>([])
|
||||
|
||||
async function loadOptions() {
|
||||
try {
|
||||
const [deptRes, roleRes] = await Promise.all([sysDepartments(), sysRoles()])
|
||||
deptTree.value = deptRes.items || []
|
||||
deptTreeSelectData.value = buildTreeSelectData(deptTree.value)
|
||||
// 内置超管角色(label=admin)不在可分配列表
|
||||
roleOptions.value = (roleRes.items || []).filter((r) => r.label !== 'admin')
|
||||
} catch (e) {
|
||||
/* 数据源加载失败不阻断弹窗打开 */
|
||||
}
|
||||
}
|
||||
|
||||
/** 部门树 → el-tree-select 数据(label/children) */
|
||||
function buildTreeSelectData(nodes: any[]): any[] {
|
||||
return (nodes || []).map((n) => ({
|
||||
value: Number(n.id),
|
||||
label: n.name,
|
||||
children: n.children?.length ? buildTreeSelectData(n.children) : undefined
|
||||
}))
|
||||
}
|
||||
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
username: '',
|
||||
password: '',
|
||||
nickName: '',
|
||||
name: '',
|
||||
phone: '',
|
||||
departmentId: null as number | null,
|
||||
status: 1,
|
||||
roleIdList: [] as number[],
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const rules = computed<FormRules>(() => ({
|
||||
username: [
|
||||
{ required: !isEdit.value, message: '请输入用户名', trigger: 'blur' },
|
||||
{ min: 2, max: 30, message: '长度 2-30 个字符', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: !isEdit.value, message: '请输入初始密码', trigger: 'blur' },
|
||||
{ min: 6, max: 32, message: '长度 6-32 位', trigger: 'blur' }
|
||||
]
|
||||
}))
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
async (visible) => {
|
||||
if (!visible) return
|
||||
loadOptions()
|
||||
await nextTick()
|
||||
formRef.value?.clearValidate()
|
||||
if (props.type === 'edit' && props.userData) {
|
||||
// 详情接口拿 roleIdList(列表行的 roleIds 也可用,详情更准)
|
||||
let detail: any = props.userData
|
||||
try {
|
||||
detail = await sysUserInfo(props.userData.id)
|
||||
} catch (e) {
|
||||
/* 退回列表行数据 */
|
||||
}
|
||||
Object.assign(formData, {
|
||||
id: detail.id,
|
||||
username: detail.username,
|
||||
password: '',
|
||||
nickName: detail.nickName || '',
|
||||
name: detail.name || '',
|
||||
phone: detail.phone || '',
|
||||
departmentId: detail.departmentId ? Number(detail.departmentId) : null,
|
||||
status: Number(detail.status ?? 1),
|
||||
roleIdList: Array.isArray(detail.roleIdList) ? detail.roleIdList.map(Number) : [],
|
||||
remark: detail.remark || ''
|
||||
})
|
||||
} else {
|
||||
Object.assign(formData, {
|
||||
id: 0,
|
||||
username: '',
|
||||
password: '',
|
||||
nickName: '',
|
||||
name: '',
|
||||
phone: '',
|
||||
departmentId: null,
|
||||
status: 1,
|
||||
roleIdList: [],
|
||||
remark: ''
|
||||
})
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate()
|
||||
submitting.value = true
|
||||
try {
|
||||
if (isEdit.value) {
|
||||
const body: any = {
|
||||
id: formData.id,
|
||||
nickName: formData.nickName,
|
||||
name: formData.name,
|
||||
phone: formData.phone,
|
||||
departmentId: formData.departmentId,
|
||||
status: formData.status,
|
||||
roleIdList: formData.roleIdList,
|
||||
remark: formData.remark
|
||||
}
|
||||
if (formData.password) body.password = formData.password
|
||||
await sysUserEdit(body)
|
||||
ElMessage.success('修改成功')
|
||||
} else {
|
||||
await sysUserAdd({
|
||||
username: formData.username,
|
||||
password: formData.password,
|
||||
nickName: formData.nickName,
|
||||
name: formData.name,
|
||||
phone: formData.phone,
|
||||
departmentId: formData.departmentId,
|
||||
status: formData.status,
|
||||
roleIdList: formData.roleIdList,
|
||||
remark: formData.remark
|
||||
})
|
||||
ElMessage.success('新增成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
emit('submit')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑用户' : '新增用户'"
|
||||
width="520px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="90px">
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input v-model="formData.username" :disabled="isEdit" placeholder="登录用户名(唯一)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input
|
||||
v-model="formData.password"
|
||||
type="password"
|
||||
show-password
|
||||
:placeholder="isEdit ? '留空则不修改密码' : '初始密码(至少 6 位)'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="昵称" prop="nickName">
|
||||
<el-input v-model="formData.nickName" placeholder="显示昵称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="姓名" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="真实姓名(可选)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号" prop="phone">
|
||||
<el-input v-model="formData.phone" placeholder="手机号(可选)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="部门" prop="departmentId">
|
||||
<el-tree-select
|
||||
v-model="formData.departmentId"
|
||||
:data="deptTreeSelectData"
|
||||
node-key="value"
|
||||
check-strictly
|
||||
clearable
|
||||
placeholder="选择部门"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="角色" prop="roleIdList">
|
||||
<el-select v-model="formData.roleIdList" multiple placeholder="分配角色(可多选)" style="width: 100%">
|
||||
<el-option v-for="r in roleOptions" :key="r.id" :value="Number(r.id)" :label="`${r.name}(${r.label || '-'})`" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-switch v-model="formData.status" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="禁用" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="formData.remark" type="textarea" :rows="2" placeholder="备注(可选)" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 用户搜索栏:关键字(用户名/昵称/角色)+ 状态过滤(客户端过滤,emit search)
|
||||
*/
|
||||
import { reactive } from 'vue'
|
||||
|
||||
interface Emits {
|
||||
(e: 'search', params: { keyword: string; status: number | null }): void
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const form = reactive<{ keyword: string; status: number | null }>({
|
||||
keyword: '',
|
||||
status: null
|
||||
})
|
||||
|
||||
function handleSearch() {
|
||||
emit('search', { keyword: form.keyword, status: form.status })
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
form.keyword = ''
|
||||
form.status = null
|
||||
emit('search', { keyword: '', status: null })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<el-input
|
||||
v-model="form.keyword"
|
||||
placeholder="用户名 / 昵称 / 角色"
|
||||
clearable
|
||||
style="width: 220px"
|
||||
@keyup.enter="handleSearch"
|
||||
@clear="handleSearch"
|
||||
/>
|
||||
<el-select v-model="form.status" placeholder="状态" clearable style="width: 120px" @change="handleSearch">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
<el-button type="primary" @click="handleSearch">查询</el-button>
|
||||
<el-button @click="handleReset">重置</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
</template>
|
||||
@@ -0,0 +1,46 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 升级进度(37du 控制台)
|
||||
* 按账号展示执行机数量与最后在线(对接 /api/admin/devices/summary)
|
||||
*/
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { fetchDevicesSummary } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const data = ref<any>({})
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
data.value = await fetchDevicesSummary()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">升级进度</h2>
|
||||
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header>
|
||||
<span class="font-semibold">执行机汇总(共 {{ data.total || 0 }} 台)</span>
|
||||
</template>
|
||||
<el-table :data="data.by_account || []" border stripe>
|
||||
<el-table-column label="账号" min-width="120">
|
||||
<template #default="{ row }">{{ row.nickname || row.account }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="account" label="工号" width="120" />
|
||||
<el-table-column prop="dept" label="部门" width="120" />
|
||||
<el-table-column prop="device_count" label="设备数" width="90" />
|
||||
<el-table-column prop="last_seen" label="最后在线" min-width="170" />
|
||||
</el-table>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user