feat(user): 实现用户角色权限管理和登录态完善

- 新增异步任务支持,启用@EnableAsync注解
- 添加用户信息响应VO类FindUserInfoRspVO
- 修改MyBatis逆向生成配置,调整映射的表为user_role_rel
- 全局异常处理新增未登录异常处理方法
- Vue头部组件Header.vue完善登录状态显示,显示用户名或登录按钮
- 新增获取用户信息的前端API接口getUserInfo
- 新增UserController,提供获取当前用户信息接口
- UserDOMapper新增selectById方法及对应XML配置
- 设计角色与用户角色关系数据对象及MyBatis映射文件
- 新增RoleDO和UserRoleRelDO数据对象及对应Mapper接口和XML映射
- 实现UserService及其实现类UserServiceImpl,支持推送角色权限到Redis
- 新增定时任务UserRoleTask,定时同步权限数据到Redis
- 配置SaToken权限拦截器,设置登录校验及排除路径
- 实现StpInterface接口,自定义权限与角色列表获取逻辑
- 响应码枚举中添加未登录状态码NOT_LOGIN
This commit is contained in:
lbw
2025-12-22 19:03:02 +08:00
parent f4498e5676
commit bc4c74f881
22 changed files with 435 additions and 8 deletions

View File

@@ -7,3 +7,7 @@ export function login(data) {
export function getVerificationCode(data) {
return axios.post("/login/sendVerificationCode", data)
}
export function getUserInfo() {
return axios.post("/user/info")
}

View File

@@ -7,10 +7,18 @@
<span class="self-center text-xl font-semibold whitespace-nowrap dark:text-white">Flowbite</span>
</a>
<div class="flex items-center lg:order-2">
<a href="#" @click.prevent="showLogin = true"
class="text-gray-800 dark:text-white hover:bg-gray-50 focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5 mr-2 dark:hover:bg-gray-700 focus:outline-none dark:focus:ring-gray-800">
Login
</a>
<template v-if="userName">
<span
class="text-gray-800 dark:text-white font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5 mr-2">
{{ userName }}
</span>
</template>
<template v-else>
<a href="#" @click.prevent="showLogin = true"
class="text-gray-800 dark:text-white hover:bg-gray-50 focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5 mr-2 dark:hover:bg-gray-700 focus:outline-none dark:focus:ring-gray-800">
Login
</a>
</template>
<a href="#"
class="text-white bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5 mr-2 dark:bg-primary-600 dark:hover:bg-primary-700 focus:outline-none dark:focus:ring-primary-800">
Get started
@@ -61,12 +69,26 @@
</div>
</div>
</nav>
<LoginDialog v-model="showLogin" />
<LoginDialog v-model="showLogin" @success="refreshUser" />
</header>
</template>
<script setup>
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import LoginDialog from '@/layouts/components/LoginDialog.vue'
import { getUserInfo } from '@/api/user'
const showLogin = ref(false)
const userName = ref('')
async function refreshUser() {
try {
const r = await getUserInfo()
const d = r?.data
userName.value = d?.success ? (d?.data?.name || '') : ''
} catch {
userName.value = ''
}
}
onMounted(() => {
refreshUser()
})
</script>