feat: 后台管理员独立账号体系,Casdoor 配置改为后台管理

- 新增 admin_users/admin_sessions 表与 adminAuth 工具(scrypt 密码 + 独立会话 Cookie)
- /admin/init 初始化首个管理员,未初始化时服务端/客户端双守卫引导
- 后台鉴权改为管理员会话,前台 Casdoor 用户一律普通用户、与后台解耦
- Casdoor 配置改存 settings 表并由「统一认证」页管理,移除全部 CASDOOR 环境变量
- 侧边栏增加统一认证/管理员入口与登出;LoginModal 感知 SSO 启用状态
- 补充 adminAuth 测试,重写 casdoor 测试,全部 23 项通过
This commit is contained in:
2026-08-09 02:01:14 +08:00
parent 337eb4f05a
commit 541e24c6f4
42 changed files with 1505 additions and 307 deletions
+31 -2
View File
@@ -1,14 +1,22 @@
<script setup lang="ts">
/**
* 后台左侧导航栏:按「内容 / 数据 / 系统」分组,底部返回前台。
* 后台左侧导航栏:按「内容 / 数据 / 系统」分组,底部显示当前管理员可退出。
* 高亮当前路由;点击任意导航项时向父级发出 navigate 事件(移动端关闭侧栏)。
*/
import { useRoute } from '#app'
import { useSiteSettings } from '~/composables/useSiteSettings'
import { useAdminStore } from '~/stores/admin'
const route = useRoute()
const emit = defineEmits<{ navigate: [] }>()
const { settings } = useSiteSettings()
const adminStore = useAdminStore()
const handleLogout = async () => {
await adminStore.logout()
emit('navigate')
navigateTo('/admin/login')
}
interface SidebarItem {
to: string
@@ -42,6 +50,8 @@ const groups: SidebarGroup[] = [
{
label: '系统',
items: [
{ to: '/admin/casdoor', label: '统一认证', icon: 'ph:sign-in' },
{ to: '/admin/admins', label: '管理员', icon: 'ph:shield-check' },
{ to: '/admin/uploads', label: '图片管理', icon: 'ph:image' },
{ to: '/admin/audit', label: '操作日志', icon: 'ph:list-checks' },
{ to: '/admin/settings', label: '站点设置', icon: 'ph:gear-six' },
@@ -93,7 +103,18 @@ const isActive = (to: string) => route.path === to
</div>
</nav>
<div class="p-3 border-t border-white/10 shrink-0">
<div class="p-3 border-t border-white/10 shrink-0 space-y-1">
<div class="flex items-center gap-3 px-3 py-2.5">
<div
class="w-8 h-8 rounded-full bg-white/10 text-white flex items-center justify-center font-bold text-xs flex-shrink-0"
>
{{ (adminStore.admin?.username || 'A').charAt(0).toUpperCase() }}
</div>
<div class="min-w-0 leading-tight">
<p class="text-sm font-semibold text-white truncate">{{ adminStore.admin?.username || '管理员' }}</p>
<p class="text-[11px] text-white/40">后台账号</p>
</div>
</div>
<NuxtLink
to="/"
class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium text-white/70 hover:bg-white/10 hover:text-white transition-colors"
@@ -102,6 +123,14 @@ const isActive = (to: string) => route.path === to
<Icon name="ph:arrow-left" class="w-[18px] h-[18px]" />
返回前台
</NuxtLink>
<button
type="button"
class="w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium text-white/70 hover:bg-white/10 hover:text-white transition-colors"
@click="handleLogout"
>
<Icon name="ph:sign-out" class="w-[18px] h-[18px]" />
退出登录
</button>
</div>
</div>
</template>