feat(admin): art-design-pro integration with local session auth

P1b Task 9: apps/admin based on art-design-pro v3.0.2 (tag, commit
d224dd4; source recorded in apps/admin/SOURCE.md), trimmed to
layout/login/i18n/request/table-form core. Login wired to real
POST /v1/auth/password (single-token session), Bearer header on all
requests, 401 interceptor logout+redirect, request-driven sliding
renewal (refresh at ~80% TTL, single-flight), best-effort
POST /v1/auth/logout on user-menu logout. One protected stub page
(相册管理). Dev port 5176 strictPort + /v1 proxy to 8080. Admin keeps
its own eslint9 flat config; root eslint ignores apps/admin/**.
vitest unit tests for renewal pacing + Playwright e2e (guard redirect,
localized wrong-password error, login lands on stub, token persists
across reload, logout clears session).

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-18 11:47:32 +08:00
parent 90fe64f637
commit a6cc190751
273 changed files with 32565 additions and 48 deletions
@@ -0,0 +1,15 @@
<!-- 相册管理(P1b Task 9 占位 stub:登录后落地的受保护页面,后续任务填充列表/详情) -->
<template>
<div class="p-5">
<ElCard>
<template #header>
<span>{{ $t('menus.albums.manage') }}</span>
</template>
<ElEmpty :description="$t('albumsManage.placeholder')" />
</ElCard>
</div>
</template>
<script setup lang="ts">
defineOptions({ name: 'AlbumsManage' })
</script>
+157
View File
@@ -0,0 +1,157 @@
<!-- 登录页面(@photo/admin:账号+密码对接 POST /v1/auth/password) -->
<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="$t('login.placeholder.account')"
v-model.trim="formData.account"
autocomplete="username"
/>
</ElFormItem>
<ElFormItem prop="password">
<ElInput
class="custom-height"
:placeholder="$t('login.placeholder.password')"
v-model.trim="formData.password"
type="password"
autocomplete="current-password"
show-password
/>
</ElFormItem>
<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 AppConfig from '@/config'
import { useUserStore } from '@/store/modules/user'
import { useI18n } from 'vue-i18n'
import { HttpError } from '@/utils/http/error'
import { fetchLogin } from '@/api/auth'
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
defineOptions({ name: 'Login' })
const { t, locale } = useI18n()
const formKey = ref(0)
// 监听语言切换,重置表单
watch(locale, () => {
formKey.value++
})
const userStore = useUserStore()
const router = useRouter()
const route = useRoute()
const systemName = AppConfig.systemInfo.name
const formRef = ref<FormInstance>()
const formData = reactive({
account: '',
password: ''
})
const rules = computed<FormRules>(() => ({
account: [{ required: true, message: t('login.placeholder.account'), 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
loading.value = true
const { account, password } = formData
const { sessionToken, expiresAt } = await fetchLogin({ account, password })
if (!sessionToken) {
throw new Error('Login failed - no token received')
}
// 存储会话令牌与登录状态(账号名暂存,供本地拼装用户信息)
userStore.setToken(sessionToken, expiresAt)
userStore.setUserInfo({
userId: 0,
userName: account,
email: '',
buttons: [],
roles: ['R_ADMIN']
})
userStore.setLoginStatus(true)
showLoginSuccessNotice()
// 获取 redirect 参数,如果存在则跳转到指定页面,否则跳转到首页
const redirect = route.query.redirect as string
router.push(redirect || '/')
} catch (error) {
// HttpError 已带本地化文案(如 AUTH_INVALID_CREDENTIALS → 账号或密码错误)
if (error instanceof HttpError) {
ElMessage.error(error.message)
} else {
console.error('[Login] Unexpected error:', error)
}
} finally {
loading.value = false
}
}
// 登录成功提示
const showLoginSuccessNotice = () => {
setTimeout(() => {
ElNotification({
title: t('login.success.title'),
type: 'success',
duration: 2500,
zIndex: 10000,
message: `${t('login.success.message')}, ${systemName}!`
})
}, 1000)
}
</script>
<style scoped>
@import './style.css';
</style>
+38
View File
@@ -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,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>
+29
View File
@@ -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>
+93
View File
@@ -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);
}
}
}
}
}
+42
View File
@@ -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>