mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 04:29:20 +08:00
feat: 超管账户切换
This commit is contained in:
@@ -100,3 +100,10 @@ export async function logoutApi() {
|
||||
export async function getAccessCodesApi() {
|
||||
return requestClient.get<string[]>('/auth/codes');
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换账户(超级管理员功能)
|
||||
*/
|
||||
export async function switchAccountApi(userId: number) {
|
||||
return requestClient.post<AuthApi.LoginResult>(`/auth/switch/${userId}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
import type { UserDTO, UserVO } from './types';
|
||||
|
||||
/**
|
||||
* 用户管理API
|
||||
*/
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
export async function getUserInfoApi() {
|
||||
return requestClient.get<UserVO.UserInfoVO>('/user/info');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
*/
|
||||
export async function updateUserInfoApi(data: UserDTO.UpdateUserInfoDTO) {
|
||||
return requestClient.put<UserVO.UserInfoVO>('/user/info', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
export async function changePasswordApi(data: UserDTO.ChangePasswordDTO) {
|
||||
return requestClient.post<void>('/user/change-password', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传用户头像
|
||||
*/
|
||||
export async function uploadAvatarApi(file: File) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return requestClient.post<UserVO.UserInfoVO>('/user/upload-avatar', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户菜单
|
||||
*/
|
||||
export async function getUserMenuApi() {
|
||||
return requestClient.get<UserVO.UserMenuVO[]>('/user/menu');
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
*/
|
||||
export async function getUserPageApi(params: PageQueryDTO<UserDTO.UserFilterDTO>) {
|
||||
return requestClient.post<PageResultVO<UserVO.UserInfoVO>>('/user/page', params);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 用户管理模块API导出
|
||||
*/
|
||||
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 用户管理模块类型定义导出
|
||||
*/
|
||||
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 用户管理模块DTO类型定义
|
||||
*/
|
||||
|
||||
export namespace UserDTO {
|
||||
/** 更新用户信息参数 */
|
||||
export interface UpdateUserInfoDTO {
|
||||
/** 用户名称 */
|
||||
realName?: string;
|
||||
/** 头像图片ID */
|
||||
avatarImageId?: number;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
/** 备注信息 */
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
/** 修改密码参数 */
|
||||
export interface ChangePasswordDTO {
|
||||
/** 旧密码 */
|
||||
oldPassword: string;
|
||||
/** 新密码 */
|
||||
newPassword: string;
|
||||
}
|
||||
|
||||
/** 用户过滤条件 */
|
||||
export interface UserFilterDTO {
|
||||
/** 用户名称(模糊查询) */
|
||||
realName?: string;
|
||||
/** 登录账号(模糊查询) */
|
||||
loginCode?: string;
|
||||
/** 手机号码(精确查询) */
|
||||
phone?: string;
|
||||
/** 用户角色 */
|
||||
role?: string;
|
||||
/** 公司ID */
|
||||
companyId?: number;
|
||||
/** 部门ID */
|
||||
departmentId?: number;
|
||||
/** 岗位ID */
|
||||
positionId?: number;
|
||||
/** 状态查询 */
|
||||
status?: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* 用户管理模块VO类型定义
|
||||
*/
|
||||
|
||||
export namespace UserVO {
|
||||
/** 用户信息 */
|
||||
export interface UserInfoVO {
|
||||
/** 用户编号 */
|
||||
id: number;
|
||||
/** 公司id */
|
||||
companyId?: number;
|
||||
/** 部门id */
|
||||
departmentId?: number;
|
||||
/** 岗位id */
|
||||
positionId?: number;
|
||||
/** 登录账号 */
|
||||
loginCode: string;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
/** 用户名称 */
|
||||
realName: string;
|
||||
/** 头像路径 */
|
||||
avatar?: string;
|
||||
/** 关联角色(user-普通账户 company-公司账户 super-超管账户) */
|
||||
role: string;
|
||||
/** 密码安全级别(0-初始 1-很弱 2-弱 3-安全 4-很安全) */
|
||||
pwdSecurityLevel?: number;
|
||||
/** 密码最后更新时间 */
|
||||
pwdUpdateTime?: string;
|
||||
/** 最后登录ip */
|
||||
lastLoginIp?: string;
|
||||
/** 最后登录时间 */
|
||||
lastLoginDate?: string;
|
||||
/** 冻结时间 */
|
||||
freezeDate?: string;
|
||||
/** 冻结原因 */
|
||||
freezeCause?: string;
|
||||
/** 状态(0-正常 1-删除 2-停用 3-冻结) */
|
||||
status: number;
|
||||
/** 备注信息 */
|
||||
remark?: string;
|
||||
/** 创建时间 */
|
||||
createTime: string;
|
||||
/** 更新时间 */
|
||||
updateTime: string;
|
||||
}
|
||||
|
||||
/** 用户菜单信息 */
|
||||
export interface UserMenuVO {
|
||||
/** 路由名称 (必填,用于 Vue Router 的 name 属性) */
|
||||
name: string;
|
||||
/** 路由路径 */
|
||||
path: string;
|
||||
/** 页面组件路径 (字符串类型,指向组件文件路径) */
|
||||
component: string;
|
||||
/** 重定向地址 */
|
||||
redirect?: string;
|
||||
/** 路由元信息 */
|
||||
meta: RouteMeta;
|
||||
/** 子路由列表 (扁平化处理,不嵌套) */
|
||||
children?: UserMenuVO[];
|
||||
}
|
||||
|
||||
/** 路由元信息 */
|
||||
export interface RouteMeta {
|
||||
/** 路由ID */
|
||||
id: number;
|
||||
/** 父路由ID */
|
||||
parentId?: number;
|
||||
/** 路由标题 */
|
||||
title: string;
|
||||
/** 路由图标 */
|
||||
icon?: string;
|
||||
/** 顺序 */
|
||||
order?: number;
|
||||
/** 路由类型 (catalog-目录,menu-菜单,button-按钮,embedded-内联,link-外链) */
|
||||
type: string;
|
||||
/** 是否显示在菜单中 (0-否 1-是) */
|
||||
visible?: number;
|
||||
/** 状态 (0-禁用 1-启用) */
|
||||
status?: number;
|
||||
/** 是否缓存 */
|
||||
keepAlive?: boolean;
|
||||
/** 是否超级菜单 (0-否 1-是) */
|
||||
superMenu?: number;
|
||||
/** 权限码列表 */
|
||||
access?: string[];
|
||||
/** 是否隐藏菜单 */
|
||||
hideInMenu?: boolean;
|
||||
/** 是否隐藏面包屑 */
|
||||
hideInBreadcrumb?: boolean;
|
||||
/** 是否隐藏标签页 */
|
||||
hideInTabs?: boolean;
|
||||
/** 是否固定标签页 */
|
||||
affixTab?: boolean;
|
||||
/** 是否在菜单中显示子菜单 */
|
||||
showChildrenInMenu?: boolean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { Form, Select, Card, Avatar, message, Spin } from 'ant-design-vue'
|
||||
import { useVbenModal } from '@vben/common-ui'
|
||||
import { useAccessStore } from '@vben/stores'
|
||||
import { switchAccountApi } from '#/api/core/auth'
|
||||
import { getCompanyPageApi } from '#/api/organization/company'
|
||||
import { getUserPageApi } from '#/api/system/user'
|
||||
import type { CompanyVO } from '#/api/organization/company/types'
|
||||
import type { UserVO } from '#/api/system/user/types'
|
||||
import type { PageQueryDTO } from '#/types/common'
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref()
|
||||
const formData = ref({
|
||||
companyId: undefined as number | undefined,
|
||||
userId: undefined as number | undefined,
|
||||
})
|
||||
|
||||
// 公司相关数据
|
||||
const companyList = ref<CompanyVO.CompanyInfoVO[]>([])
|
||||
const companyLoading = ref(false)
|
||||
const companySearchValue = ref('')
|
||||
const companyPage = ref(1)
|
||||
const companyPageSize = ref(20)
|
||||
const companyHasMore = ref(true)
|
||||
|
||||
// 用户相关数据
|
||||
const userList = ref<UserVO.UserInfoVO[]>([])
|
||||
const userLoading = ref(false)
|
||||
const userSearchValue = ref('')
|
||||
const userPage = ref(1)
|
||||
const userPageSize = ref(20)
|
||||
const userHasMore = ref(true)
|
||||
|
||||
// 选中的用户信息
|
||||
const selectedUser = ref<UserVO.UserInfoVO | null>(null)
|
||||
|
||||
// 公司选项
|
||||
const companyOptions = computed(() =>
|
||||
companyList.value.map(company => ({
|
||||
label: company.name,
|
||||
value: company.id,
|
||||
company
|
||||
}))
|
||||
)
|
||||
|
||||
// 用户选项
|
||||
const userOptions = computed(() =>
|
||||
userList.value.map(user => ({
|
||||
label: `${user.realName} (${user.loginCode})`,
|
||||
value: user.id,
|
||||
user
|
||||
}))
|
||||
)
|
||||
|
||||
// 监听公司选择变化
|
||||
watch(() => formData.value.companyId, (newCompanyId) => {
|
||||
if (newCompanyId) {
|
||||
// 重置用户数据
|
||||
formData.value.userId = undefined
|
||||
userList.value = []
|
||||
userPage.value = 1
|
||||
userHasMore.value = true
|
||||
selectedUser.value = null
|
||||
// 加载该公司的用户
|
||||
loadUsers()
|
||||
}
|
||||
})
|
||||
|
||||
// 监听用户选择变化
|
||||
watch(() => formData.value.userId, (newUserId) => {
|
||||
if (newUserId) {
|
||||
const user = userList.value.find(u => u.id === newUserId)
|
||||
selectedUser.value = user || null
|
||||
} else {
|
||||
selectedUser.value = null
|
||||
}
|
||||
})
|
||||
|
||||
// 加载公司列表
|
||||
const loadCompanies = async (reset = false) => {
|
||||
if (companyLoading.value) return
|
||||
|
||||
try {
|
||||
companyLoading.value = true
|
||||
|
||||
if (reset) {
|
||||
companyList.value = []
|
||||
companyPage.value = 1
|
||||
companyHasMore.value = true
|
||||
}
|
||||
|
||||
const params: PageQueryDTO<{ name?: string }> = {
|
||||
page: companyPage.value,
|
||||
pageSize: companyPageSize.value,
|
||||
filters: {
|
||||
name: companySearchValue.value || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
const result = await getCompanyPageApi(params)
|
||||
|
||||
if (reset) {
|
||||
companyList.value = result.records
|
||||
} else {
|
||||
companyList.value.push(...result.records)
|
||||
}
|
||||
|
||||
companyHasMore.value = result.records.length === companyPageSize.value
|
||||
companyPage.value++
|
||||
|
||||
} catch (error) {
|
||||
console.error('加载公司列表失败:', error)
|
||||
message.error('加载公司列表失败')
|
||||
} finally {
|
||||
companyLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 加载用户列表
|
||||
const loadUsers = async (reset = false) => {
|
||||
if (userLoading.value || !formData.value.companyId) return
|
||||
|
||||
try {
|
||||
userLoading.value = true
|
||||
|
||||
if (reset) {
|
||||
userList.value = []
|
||||
userPage.value = 1
|
||||
userHasMore.value = true
|
||||
}
|
||||
|
||||
const params: PageQueryDTO<{ realName?: string; loginCode?: string; companyId?: number }> = {
|
||||
page: userPage.value,
|
||||
pageSize: userPageSize.value,
|
||||
filters: {
|
||||
realName: userSearchValue.value || undefined,
|
||||
loginCode: userSearchValue.value || undefined,
|
||||
companyId: formData.value.companyId,
|
||||
}
|
||||
}
|
||||
|
||||
const result = await getUserPageApi(params)
|
||||
|
||||
if (reset) {
|
||||
userList.value = result.records
|
||||
} else {
|
||||
userList.value.push(...result.records)
|
||||
}
|
||||
|
||||
userHasMore.value = result.records.length === userPageSize.value
|
||||
userPage.value++
|
||||
|
||||
} catch (error) {
|
||||
console.error('加载用户列表失败:', error)
|
||||
message.error('加载用户列表失败')
|
||||
} finally {
|
||||
userLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 公司搜索
|
||||
const handleCompanySearch = (value: string) => {
|
||||
companySearchValue.value = value
|
||||
loadCompanies(true)
|
||||
}
|
||||
|
||||
// 用户搜索
|
||||
const handleUserSearch = (value: string) => {
|
||||
userSearchValue.value = value
|
||||
loadUsers(true)
|
||||
}
|
||||
|
||||
// 公司下拉框滚动加载更多
|
||||
const handleCompanyScroll = (e: any) => {
|
||||
const { target } = e
|
||||
if (target.scrollTop + target.offsetHeight === target.scrollHeight && companyHasMore.value) {
|
||||
loadCompanies()
|
||||
}
|
||||
}
|
||||
|
||||
// 用户下拉框滚动加载更多
|
||||
const handleUserScroll = (e: any) => {
|
||||
const { target } = e
|
||||
if (target.scrollTop + target.offsetHeight === target.scrollHeight && userHasMore.value) {
|
||||
loadUsers()
|
||||
}
|
||||
}
|
||||
|
||||
// 切换账户
|
||||
const handleSwitchAccount = async () => {
|
||||
console.log('🔄 切换账户函数被调用', { userId: formData.value.userId })
|
||||
|
||||
if (!formData.value.userId) {
|
||||
message.warning('请选择要切换的用户')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
modalApi.setState({ loading: true })
|
||||
console.log('📡 开始调用切换账户接口...')
|
||||
|
||||
const result = await switchAccountApi(formData.value.userId)
|
||||
console.log('✅ 切换账户接口调用成功', result)
|
||||
|
||||
// 设置新的token
|
||||
const accessStore = useAccessStore()
|
||||
accessStore.setTokens(
|
||||
result.accessToken,
|
||||
result.refreshToken,
|
||||
result.accessTokenExpiresAt,
|
||||
result.refreshTokenExpiresAt
|
||||
)
|
||||
|
||||
// 重置权限检查状态,让路由守卫重新生成菜单和路由
|
||||
accessStore.setIsAccessChecked(false)
|
||||
|
||||
message.success('切换账户成功')
|
||||
modalApi.close()
|
||||
|
||||
// 刷新页面
|
||||
window.location.reload()
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('切换账户失败:', error)
|
||||
message.error(error?.message || '切换账户失败')
|
||||
} finally {
|
||||
modalApi.setState({ loading: false })
|
||||
}
|
||||
}
|
||||
|
||||
// 创建模态框
|
||||
const [ModalComponent, modalApi] = useVbenModal({
|
||||
onCancel() {
|
||||
console.log('❌ 模态框取消按钮被点击')
|
||||
modalApi.close()
|
||||
},
|
||||
onConfirm: async () => {
|
||||
console.log('🎯 模态框确认按钮被点击')
|
||||
await handleSwitchAccount()
|
||||
},
|
||||
})
|
||||
|
||||
// 打开模态框
|
||||
function openModal() {
|
||||
modalApi.open()
|
||||
// 重置表单数据
|
||||
formData.value = {
|
||||
companyId: undefined,
|
||||
userId: undefined,
|
||||
}
|
||||
selectedUser.value = null
|
||||
// 加载公司列表
|
||||
loadCompanies(true)
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function closeModal() {
|
||||
modalApi.close()
|
||||
}
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
open: openModal,
|
||||
close: closeModal,
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ModalComponent
|
||||
title="切换账户"
|
||||
width="800px"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
layout="vertical"
|
||||
class="mt-4"
|
||||
>
|
||||
<Form.Item label="选择公司" required>
|
||||
<Select
|
||||
v-model:value="formData.companyId"
|
||||
placeholder="请选择公司"
|
||||
show-search
|
||||
:filter-option="false"
|
||||
:loading="companyLoading"
|
||||
@search="handleCompanySearch"
|
||||
@popup-scroll="handleCompanyScroll"
|
||||
>
|
||||
<template #notFoundContent>
|
||||
<div v-if="companyLoading" class="text-center py-4">
|
||||
<Spin size="small" />
|
||||
<div class="mt-2">加载中...</div>
|
||||
</div>
|
||||
<div v-else class="text-center py-4 text-gray-400">
|
||||
暂无数据
|
||||
</div>
|
||||
</template>
|
||||
<Select.Option
|
||||
v-for="option in companyOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="option.label"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="选择用户" required>
|
||||
<Select
|
||||
v-model:value="formData.userId"
|
||||
placeholder="请选择用户"
|
||||
show-search
|
||||
:filter-option="false"
|
||||
:loading="userLoading"
|
||||
:disabled="!formData.companyId"
|
||||
@search="handleUserSearch"
|
||||
@popup-scroll="handleUserScroll"
|
||||
>
|
||||
<template #notFoundContent>
|
||||
<div v-if="userLoading" class="text-center py-4">
|
||||
<Spin size="small" />
|
||||
<div class="mt-2">加载中...</div>
|
||||
</div>
|
||||
<div v-else-if="!formData.companyId" class="text-center py-4 text-gray-400">
|
||||
请先选择公司
|
||||
</div>
|
||||
<div v-else class="text-center py-4 text-gray-400">
|
||||
暂无数据
|
||||
</div>
|
||||
</template>
|
||||
<Select.Option
|
||||
v-for="option in userOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="option.label"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
<!-- 用户信息展示 -->
|
||||
<Card v-if="selectedUser" title="用户信息" class="mt-4">
|
||||
<div class="flex items-center space-x-4">
|
||||
<Avatar :src="selectedUser.avatar" size="large">
|
||||
{{ selectedUser.realName?.charAt(0) }}
|
||||
</Avatar>
|
||||
<div class="flex-1">
|
||||
<div class="font-medium text-lg">{{ selectedUser.realName }}</div>
|
||||
<div class="text-gray-500">登录账号: {{ selectedUser.loginCode }}</div>
|
||||
<div class="text-gray-500">手机号码: {{ selectedUser.phone || '-' }}</div>
|
||||
<div class="text-gray-500">角色: {{ selectedUser.role }}</div>
|
||||
<div class="text-gray-500">状态: {{ selectedUser.status === 1 ? '正常' : '禁用' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</ModalComponent>
|
||||
</template>
|
||||
@@ -20,6 +20,7 @@ import { openWindow } from '@vben/utils';
|
||||
import { $t } from '#/locales';
|
||||
import { useAuthStore } from '#/store';
|
||||
import LoginForm from '#/views/_core/authentication/login.vue';
|
||||
import SwitchAccountModal from '#/components/SwitchAccountModal.vue';
|
||||
|
||||
const notifications = ref<NotificationItem[]>([
|
||||
{
|
||||
@@ -60,35 +61,55 @@ const showDot = computed(() =>
|
||||
notifications.value.some((item) => !item.isRead),
|
||||
);
|
||||
|
||||
const menus = computed(() => [
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(VBEN_DOC_URL, {
|
||||
target: '_blank',
|
||||
});
|
||||
// 切换账户模态框引用
|
||||
const switchAccountModalRef = ref();
|
||||
|
||||
const menus = computed(() => {
|
||||
const menuItems = [];
|
||||
|
||||
// 只有超级管理员才显示切换账户功能
|
||||
if (accessStore.userRole === 'super') {
|
||||
menuItems.push({
|
||||
handler: () => {
|
||||
switchAccountModalRef.value?.open();
|
||||
},
|
||||
icon: MdiGithub, // 临时使用现有图标
|
||||
text: '切换账户',
|
||||
});
|
||||
}
|
||||
|
||||
menuItems.push(
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(VBEN_DOC_URL, {
|
||||
target: '_blank',
|
||||
});
|
||||
},
|
||||
icon: BookOpenText,
|
||||
text: $t('ui.widgets.document'),
|
||||
},
|
||||
icon: BookOpenText,
|
||||
text: $t('ui.widgets.document'),
|
||||
},
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(VBEN_GITHUB_URL, {
|
||||
target: '_blank',
|
||||
});
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(VBEN_GITHUB_URL, {
|
||||
target: '_blank',
|
||||
});
|
||||
},
|
||||
icon: MdiGithub,
|
||||
text: 'GitHub',
|
||||
},
|
||||
icon: MdiGithub,
|
||||
text: 'GitHub',
|
||||
},
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(`${VBEN_GITHUB_URL}/issues`, {
|
||||
target: '_blank',
|
||||
});
|
||||
},
|
||||
icon: CircleHelp,
|
||||
text: $t('ui.widgets.qa'),
|
||||
},
|
||||
]);
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(`${VBEN_GITHUB_URL}/issues`, {
|
||||
target: '_blank',
|
||||
});
|
||||
},
|
||||
icon: CircleHelp,
|
||||
text: $t('ui.widgets.qa'),
|
||||
}
|
||||
);
|
||||
|
||||
return menuItems;
|
||||
});
|
||||
|
||||
const avatar = computed(() => {
|
||||
return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar;
|
||||
@@ -154,4 +175,7 @@ watch(
|
||||
<LockScreen :avatar @to-login="handleLogout" />
|
||||
</template>
|
||||
</BasicLayout>
|
||||
|
||||
<!-- 切换账户模态框 -->
|
||||
<SwitchAccountModal ref="switchAccountModalRef" />
|
||||
</template>
|
||||
|
||||
@@ -25,14 +25,12 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) {
|
||||
return await generateAccessible(preferences.app.accessMode, {
|
||||
...options,
|
||||
fetchMenuListAsync: async () => {
|
||||
console.log('🚀 开始获取用户菜单路由...');
|
||||
message.loading({
|
||||
content: `${$t('common.loadingMenu')}...`,
|
||||
duration: 1.5,
|
||||
});
|
||||
try {
|
||||
const routes = await getUserMenuApi();
|
||||
console.log('✅ 获取用户菜单路由成功:', routes);
|
||||
return routes;
|
||||
} catch (error) {
|
||||
console.error('❌ 获取用户菜单路由失败:', error);
|
||||
|
||||
@@ -87,21 +87,14 @@ function setupAccessGuard(router: Router) {
|
||||
|
||||
// 是否已经生成过动态路由
|
||||
if (accessStore.isAccessChecked) {
|
||||
console.log('✅ 动态路由已生成,跳过');
|
||||
return true;
|
||||
}
|
||||
|
||||
console.log('🚀 开始生成动态路由...');
|
||||
console.log('📊 当前访问模式:', preferences.app.accessMode);
|
||||
|
||||
// 生成路由表
|
||||
// 当前登录用户拥有的角色标识列表
|
||||
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
|
||||
const userRoles = userInfo.roles ?? [];
|
||||
|
||||
console.log('👤 用户信息:', userInfo);
|
||||
console.log('🎭 用户角色:', userRoles);
|
||||
|
||||
// 生成菜单和路由
|
||||
const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
||||
roles: userRoles,
|
||||
@@ -110,9 +103,6 @@ function setupAccessGuard(router: Router) {
|
||||
routes: accessRoutes,
|
||||
});
|
||||
|
||||
console.log('📋 可访问菜单:', accessibleMenus);
|
||||
console.log('🛣️ 可访问路由:', accessibleRoutes);
|
||||
|
||||
// 保存菜单信息和路由信息
|
||||
accessStore.setAccessMenus(accessibleMenus);
|
||||
accessStore.setAccessRoutes(accessibleRoutes);
|
||||
|
||||
@@ -13,7 +13,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'FileRepository',
|
||||
path: '/media/file-repository',
|
||||
component: () => import('#/views/media/file-repository/index.vue'),
|
||||
component: () => import('#/views/media/file/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:folder',
|
||||
title: '文件仓库',
|
||||
@@ -22,7 +22,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'ImageRepository',
|
||||
path: '/media/image-repository',
|
||||
component: () => import('#/views/media/image-repository/index.vue'),
|
||||
component: () => import('#/views/media/image/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:image',
|
||||
title: '图片仓库',
|
||||
|
||||
@@ -13,7 +13,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'CompanyManagement',
|
||||
path: '/organization/company-management',
|
||||
component: () => import('#/views/organization/company-management/index.vue'),
|
||||
component: () => import('#/views/organization/company/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:building',
|
||||
title: '公司管理',
|
||||
@@ -22,7 +22,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'DepartmentManagement',
|
||||
path: '/organization/department-management',
|
||||
component: () => import('#/views/organization/department-management/index.vue'),
|
||||
component: () => import('#/views/organization/department/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:users',
|
||||
title: '部门管理',
|
||||
@@ -31,7 +31,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'PositionManagement',
|
||||
path: '/organization/position-management',
|
||||
component: () => import('#/views/organization/position-management/index.vue'),
|
||||
component: () => import('#/views/organization/position/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:briefcase',
|
||||
title: '岗位管理',
|
||||
|
||||
@@ -13,7 +13,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'ShopManagement',
|
||||
path: '/shop/shop-management',
|
||||
component: () => import('#/views/shop/shop-management/index.vue'),
|
||||
component: () => import('#/views/shop/shop/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:store',
|
||||
title: '店铺管理',
|
||||
@@ -22,7 +22,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'ProductManagement',
|
||||
path: '/shop/product-management',
|
||||
component: () => import('#/views/shop/product-management/index.vue'),
|
||||
component: () => import('#/views/shop/product/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:package',
|
||||
title: '商品管理',
|
||||
@@ -31,7 +31,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'OrderManagement',
|
||||
path: '/shop/order-management',
|
||||
component: () => import('#/views/shop/order-management/index.vue'),
|
||||
component: () => import('#/views/shop/order/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:shopping-cart',
|
||||
title: '订单管理',
|
||||
@@ -40,7 +40,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'PromotionFeeManagement',
|
||||
path: '/shop/promotion-fee-management',
|
||||
component: () => import('#/views/shop/promotion-fee-management/index.vue'),
|
||||
component: () => import('#/views/shop/promotion-fee/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:credit-card',
|
||||
title: '推广费管理',
|
||||
@@ -57,7 +57,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'OrderStatusConfig',
|
||||
path: '/shop/config-management/order-status',
|
||||
component: () => import('#/views/shop/config-management/order-status-config/index.vue'),
|
||||
component: () => import('#/views/shop/config/order-status-config/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:list-checks',
|
||||
title: '订单状态类型',
|
||||
@@ -66,7 +66,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'PromotionFeeTypeConfig',
|
||||
path: '/shop/config-management/promotion-fee-type',
|
||||
component: () => import('#/views/shop/config-management/promotion-fee-type-config/index.vue'),
|
||||
component: () => import('#/views/shop/config/promotion-fee-type-config/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:percent',
|
||||
title: '推广费用类型',
|
||||
|
||||
@@ -13,7 +13,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'MenuManagement',
|
||||
path: '/system/menu-management',
|
||||
component: () => import('#/views/system/menu-management/index.vue'),
|
||||
component: () => import('#/views/system/menu/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:menu',
|
||||
title: '菜单管理',
|
||||
|
||||
+3
-3
@@ -112,9 +112,9 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { Modal, Button, message } from 'ant-design-vue';
|
||||
import ShopFormModal from '#/views/shop/shop-management/components/ShopFormModal.vue';
|
||||
import ProductFormModal from '#/views/shop/product-management/components/ProductFormModal.vue';
|
||||
import ProductSpecModal from '#/views/shop/product-management/components/ProductSpecModal.vue';
|
||||
import ShopFormModal from '#/views/shop/shop/components/ShopFormModal.vue';
|
||||
import ProductFormModal from '#/views/shop/product/components/ProductFormModal.vue';
|
||||
import ProductSpecModal from '#/views/shop/product/components/ProductSpecModal.vue';
|
||||
|
||||
interface Props {
|
||||
visible: boolean;
|
||||
|
||||
Reference in New Issue
Block a user