mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59:19 +08:00
feat: 新增权限码管理和多处优化
This commit is contained in:
@@ -24,8 +24,8 @@ export async function admin_getAccountPageApi(params: PageQueryDTO<AccountDTO.Ac
|
||||
/**
|
||||
* 更新账户信息
|
||||
*/
|
||||
export async function admin_updateAccountApi(data: AccountDTO.UpdateAccountDTO) {
|
||||
return requestClient.put<AccountVO.AccountInfoVO>(`/company/account/update/${data.id}`, data);
|
||||
export async function admin_updateAccountApi(accountId: number, data: AccountDTO.UpdateAccountDTO) {
|
||||
return requestClient.put<AccountVO.AccountInfoVO>(`/company/account/update/${accountId}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,71 +5,61 @@
|
||||
export namespace AccountDTO {
|
||||
/** 创建账户参数 */
|
||||
export interface CreateAccountDTO {
|
||||
/** 用户名 */
|
||||
username: string;
|
||||
/** 登录账号 */
|
||||
loginCode: string;
|
||||
/** 密码 */
|
||||
password: string;
|
||||
/** 真实姓名 */
|
||||
realName: string;
|
||||
/** 邮箱 */
|
||||
email?: string;
|
||||
/** 手机号 */
|
||||
phone?: string;
|
||||
/** 公司ID */
|
||||
companyId?: number;
|
||||
/** 头像图片ID */
|
||||
avatarImageId?: number;
|
||||
/** 部门ID */
|
||||
departmentId?: number;
|
||||
/** 职位ID */
|
||||
positionId?: number;
|
||||
/** 角色ID */
|
||||
roleId?: number;
|
||||
/** 状态 (0-禁用 1-正常) */
|
||||
status?: number;
|
||||
departmentId: number;
|
||||
/** 岗位ID */
|
||||
positionId: number;
|
||||
/** 备注信息 */
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
/** 更新账户参数 */
|
||||
export interface UpdateAccountDTO {
|
||||
/** 账户ID */
|
||||
id: number;
|
||||
/** 真实姓名 */
|
||||
realName?: string;
|
||||
/** 邮箱 */
|
||||
email?: string;
|
||||
/** 登录账号 */
|
||||
loginCode?: string;
|
||||
/** 手机号 */
|
||||
phone?: string;
|
||||
/** 公司ID */
|
||||
companyId?: number;
|
||||
/** 真实姓名 */
|
||||
realName?: string;
|
||||
/** 头像图片ID */
|
||||
avatarImageId?: number;
|
||||
/** 部门ID */
|
||||
departmentId?: number;
|
||||
/** 职位ID */
|
||||
/** 岗位ID */
|
||||
positionId?: number;
|
||||
/** 角色ID */
|
||||
roleId?: number;
|
||||
/** 状态 (0-禁用 1-正常) */
|
||||
/** 状态(0-正常 1-删除 2-停用 3-冻结) */
|
||||
status?: number;
|
||||
/** 备注信息 */
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
/** 账户过滤条件 */
|
||||
export interface AccountFilterDTO {
|
||||
/** 登录账号(模糊查询) */
|
||||
loginCode?: undefined | string;
|
||||
loginCode?: string;
|
||||
/** 用户姓名(模糊查询) */
|
||||
realName?: undefined | string;
|
||||
realName?: string;
|
||||
/** 手机号码(精确查询) */
|
||||
phone?: undefined | string;
|
||||
phone?: string;
|
||||
/** 公司ID */
|
||||
companyId?: undefined | number;
|
||||
companyId?: number;
|
||||
/** 部门ID */
|
||||
departmentId?: undefined | number;
|
||||
departmentId?: number;
|
||||
/** 岗位ID */
|
||||
positionId?: undefined | number;
|
||||
positionId?: number;
|
||||
/** 角色 */
|
||||
role?: undefined | string;
|
||||
role?: string;
|
||||
/** 状态(0-正常 1-删除 2-停用 3-冻结) */
|
||||
status?: undefined | number;
|
||||
/** 页码 */
|
||||
pageNum?: undefined | number;
|
||||
/** 每页大小 */
|
||||
pageSize?: undefined | number;
|
||||
status?: number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,8 @@
|
||||
export namespace AccountVO {
|
||||
/** 账户信息 */
|
||||
export interface AccountInfoVO {
|
||||
/** 账户ID */
|
||||
/** 用户ID */
|
||||
id: number;
|
||||
/** 用户名 */
|
||||
username: string;
|
||||
/** 真实姓名 */
|
||||
realName: string;
|
||||
/** 邮箱 */
|
||||
email?: string;
|
||||
/** 手机号 */
|
||||
phone?: string;
|
||||
/** 公司ID */
|
||||
companyId?: number;
|
||||
/** 公司名称 */
|
||||
@@ -23,20 +15,49 @@ export namespace AccountVO {
|
||||
departmentId?: number;
|
||||
/** 部门名称 */
|
||||
departmentName?: string;
|
||||
/** 职位ID */
|
||||
/** 岗位ID */
|
||||
positionId?: number;
|
||||
/** 职位名称 */
|
||||
/** 岗位名称 */
|
||||
positionName?: string;
|
||||
/** 角色ID */
|
||||
roleId?: number;
|
||||
/** 登录账号 */
|
||||
loginCode: string;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
/** 用户姓名 */
|
||||
realName: string;
|
||||
/** 头像路径 */
|
||||
avatar?: string;
|
||||
/** 头像图片ID */
|
||||
avatarImageId?: number;
|
||||
/** 角色 */
|
||||
role?: string;
|
||||
/** 角色名称 */
|
||||
roleName?: string;
|
||||
/** 状态 (0-禁用 1-正常) */
|
||||
/** 密码安全级别 */
|
||||
pwdSecurityLevel?: number;
|
||||
/** 密码最后更新时间 */
|
||||
pwdUpdateTime?: string;
|
||||
/** 最后登录IP */
|
||||
lastLoginIp?: string;
|
||||
/** 最后登录时间 */
|
||||
lastLoginDate?: string;
|
||||
/** 冻结时间 */
|
||||
freezeDate?: string;
|
||||
/** 冻结原因 */
|
||||
freezeCause?: string;
|
||||
/** 状态 */
|
||||
status: number;
|
||||
/** 状态名称 */
|
||||
statusName?: string;
|
||||
/** 备注信息 */
|
||||
remark?: string;
|
||||
/** 创建时间 */
|
||||
createTime: string;
|
||||
/** 更新时间 */
|
||||
updateTime: string;
|
||||
/** 创建者 */
|
||||
createByName?: string;
|
||||
/** 更新者 */
|
||||
updateByName?: string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,9 +69,5 @@ export namespace SuperAccountDTO {
|
||||
role?: string;
|
||||
/** 状态(0-正常 1-删除 2-停用 3-冻结) */
|
||||
status?: number;
|
||||
/** 页码 */
|
||||
pageNum?: number;
|
||||
/** 每页大小 */
|
||||
pageSize?: number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,8 @@
|
||||
export namespace SuperAccountVO {
|
||||
/** 账户信息 */
|
||||
export interface AccountInfoVO {
|
||||
/** 账户ID */
|
||||
/** 用户ID */
|
||||
id: number;
|
||||
/** 登录账号 */
|
||||
loginCode: string;
|
||||
/** 用户姓名 */
|
||||
realName: string;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
/** 公司ID */
|
||||
companyId?: number;
|
||||
/** 公司名称 */
|
||||
@@ -25,17 +19,45 @@ export namespace SuperAccountVO {
|
||||
positionId?: number;
|
||||
/** 岗位名称 */
|
||||
positionName?: string;
|
||||
/** 登录账号 */
|
||||
loginCode: string;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
/** 用户姓名 */
|
||||
realName: string;
|
||||
/** 头像路径 */
|
||||
avatar?: string;
|
||||
/** 头像图片ID */
|
||||
avatarImageId?: number;
|
||||
/** 角色 */
|
||||
role?: string;
|
||||
/** 头像 */
|
||||
avatar?: string;
|
||||
/** 状态(0-正常 1-删除 2-停用 3-冻结) */
|
||||
/** 角色名称 */
|
||||
roleName?: string;
|
||||
/** 密码安全级别 */
|
||||
pwdSecurityLevel?: number;
|
||||
/** 密码最后更新时间 */
|
||||
pwdUpdateTime?: string;
|
||||
/** 最后登录IP */
|
||||
lastLoginIp?: string;
|
||||
/** 最后登录时间 */
|
||||
lastLoginDate?: string;
|
||||
/** 冻结时间 */
|
||||
freezeDate?: string;
|
||||
/** 冻结原因 */
|
||||
freezeCause?: string;
|
||||
/** 状态 */
|
||||
status: number;
|
||||
/** 备注 */
|
||||
/** 状态名称 */
|
||||
statusName?: string;
|
||||
/** 备注信息 */
|
||||
remark?: string;
|
||||
/** 创建时间 */
|
||||
createTime: string;
|
||||
/** 更新时间 */
|
||||
updateTime: string;
|
||||
/** 创建者 */
|
||||
createByName?: string;
|
||||
/** 更新者 */
|
||||
updateByName?: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MenuApi {
|
||||
/** 菜单信息 */
|
||||
export interface MenuInfo {
|
||||
id: number;
|
||||
parentId?: number;
|
||||
superMenu?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
component?: string;
|
||||
redirect?: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
type: string;
|
||||
visible?: number;
|
||||
status?: number;
|
||||
keepAlive?: number;
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
children?: MenuInfo[];
|
||||
}
|
||||
|
||||
/** 创建菜单参数 */
|
||||
export interface CreateMenuParams {
|
||||
parentId?: number;
|
||||
superMenu?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
component?: string;
|
||||
redirect?: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
type: string;
|
||||
visible?: number;
|
||||
status?: number;
|
||||
keepAlive?: number;
|
||||
}
|
||||
|
||||
/** 更新菜单参数 */
|
||||
export interface UpdateMenuParams {
|
||||
parentId?: number;
|
||||
superMenu?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
component?: string;
|
||||
redirect?: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
type: string;
|
||||
visible?: number;
|
||||
status?: number;
|
||||
keepAlive?: number;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单树
|
||||
*/
|
||||
export async function getMenuTreeApi() {
|
||||
return requestClient.get<MenuApi.MenuInfo[]>('/menu/tree');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有菜单
|
||||
*/
|
||||
export async function getAllMenusApi() {
|
||||
return requestClient.get<MenuApi.MenuInfo[]>('/menu/list');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单详情
|
||||
*/
|
||||
export async function getMenuDetailApi(id: number) {
|
||||
return requestClient.get<MenuApi.MenuInfo>(`/menu/detail/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建菜单
|
||||
*/
|
||||
export async function createMenuApi(data: MenuApi.CreateMenuParams) {
|
||||
return requestClient.post<MenuApi.MenuInfo>('/menu/create', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
*/
|
||||
export async function updateMenuApi(id: number, data: MenuApi.UpdateMenuParams) {
|
||||
return requestClient.put<MenuApi.MenuInfo>(`/menu/update/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*/
|
||||
export async function deleteMenuApi(id: number) {
|
||||
return requestClient.delete<void>(`/menu/delete/${id}`);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
import type { PermissionDTO, PermissionVO } from './types';
|
||||
|
||||
/**
|
||||
* 权限管理API
|
||||
*/
|
||||
|
||||
/**
|
||||
* 创建权限
|
||||
*/
|
||||
export async function createPermissionApi(data: PermissionDTO.CreatePermissionDTO) {
|
||||
return requestClient.post<PermissionVO.PermissionInfoVO>('/permission/create', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询权限
|
||||
*/
|
||||
export async function getPermissionPageApi(params: PageQueryDTO<PermissionDTO.PermissionFilterDTO>) {
|
||||
return requestClient.post<PageResultVO<PermissionVO.PermissionInfoVO>>('/permission/page', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限信息
|
||||
*/
|
||||
export async function updatePermissionApi(permissionId: number, data: PermissionDTO.UpdatePermissionDTO) {
|
||||
return requestClient.put<PermissionVO.PermissionInfoVO>(`/permission/update/${permissionId}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除权限
|
||||
*/
|
||||
export async function deletePermissionApi(permissionId: number) {
|
||||
return requestClient.delete<void>(`/permission/delete/${permissionId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限详情
|
||||
*/
|
||||
export async function getPermissionDetailApi(permissionId: number) {
|
||||
return requestClient.get<PermissionVO.PermissionInfoVO>(`/permission/detail/${permissionId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有权限
|
||||
*/
|
||||
export async function getAllPermissionsApi() {
|
||||
return requestClient.get<PermissionVO.PermissionInfoVO[]>('/permission/list');
|
||||
}
|
||||
@@ -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 PermissionDTO {
|
||||
/** 创建权限参数 */
|
||||
export interface CreatePermissionDTO {
|
||||
/** 权限码(唯一标识,如 user:add, order:approve) */
|
||||
code: string;
|
||||
/** 权限名称(用于显示,如 用户新增、订单审核) */
|
||||
name: string;
|
||||
/** 权限类型(api-接口权限,button-按钮权限,data-数据权限) */
|
||||
type: string;
|
||||
/** 状态:1-启用 0-禁用 */
|
||||
status?: number;
|
||||
/** 备注 */
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
/** 更新权限参数 */
|
||||
export interface UpdatePermissionDTO {
|
||||
/** 权限码(唯一标识,如 user:add, order:approve) */
|
||||
code: string;
|
||||
/** 权限名称(用于显示,如 用户新增、订单审核) */
|
||||
name: string;
|
||||
/** 权限类型(api-接口权限,button-按钮权限,data-数据权限) */
|
||||
type: string;
|
||||
/** 状态:1-启用 0-禁用 */
|
||||
status?: number;
|
||||
/** 备注 */
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
/** 权限过滤条件 */
|
||||
export interface PermissionFilterDTO {
|
||||
/** 权限码 */
|
||||
code?: string;
|
||||
/** 权限名称 */
|
||||
name?: string;
|
||||
/** 权限类型 */
|
||||
type?: string;
|
||||
/** 状态 */
|
||||
status?: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 权限管理模块VO类型定义
|
||||
*/
|
||||
|
||||
export namespace PermissionVO {
|
||||
/** 权限信息 */
|
||||
export interface PermissionInfoVO {
|
||||
/** 权限ID */
|
||||
id: number;
|
||||
/** 权限码(唯一标识,如 user:add, order:approve) */
|
||||
code: string;
|
||||
/** 权限名称(用于显示,如 用户新增、订单审核) */
|
||||
name: string;
|
||||
/** 权限类型(api-接口权限,button-按钮权限,data-数据权限) */
|
||||
type: string;
|
||||
/** 状态:1-启用 0-禁用 */
|
||||
status: number;
|
||||
/** 备注 */
|
||||
remark?: string;
|
||||
/** 创建时间 */
|
||||
createTime: string;
|
||||
/** 更新时间 */
|
||||
updateTime: string;
|
||||
}
|
||||
}
|
||||
+52
-45
@@ -25,17 +25,16 @@ const isEdit = ref(false);
|
||||
const currentAccountData = ref<AccountVO.AccountInfoVO | null>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<AccountDTO.CreateAccountDTO>({
|
||||
username: '',
|
||||
const formData = ref<AccountDTO.CreateAccountDTO & { status?: number }>({
|
||||
loginCode: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
avatarImageId: undefined,
|
||||
departmentId: 0,
|
||||
positionId: 0,
|
||||
remark: '',
|
||||
status: 0,
|
||||
});
|
||||
|
||||
// 模态框标题
|
||||
@@ -43,23 +42,24 @@ const modalTitle = computed(() => isEdit.value ? '编辑账户' : '添加账户'
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '正常', value: 1 },
|
||||
{ label: '正常', value: 0 },
|
||||
{ label: '删除', value: 1 },
|
||||
{ label: '停用', value: 2 },
|
||||
{ label: '冻结', value: 3 },
|
||||
];
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
username: '',
|
||||
loginCode: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
avatarImageId: undefined,
|
||||
departmentId: 0,
|
||||
positionId: 0,
|
||||
remark: '',
|
||||
status: 0,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
@@ -70,23 +70,22 @@ function handleCancel() {
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(editMode: boolean = false, accountData?: AccountVO.AccountInfoVO | null) {
|
||||
isEdit.value = editMode;
|
||||
function open(accountData?: AccountVO.AccountInfoVO | null) {
|
||||
isEdit.value = !!accountData;
|
||||
currentAccountData.value = accountData || null;
|
||||
|
||||
resetForm();
|
||||
|
||||
if (editMode && accountData) {
|
||||
if (accountData) {
|
||||
formData.value = {
|
||||
username: accountData.username,
|
||||
loginCode: accountData.loginCode,
|
||||
password: '', // 编辑时密码为空
|
||||
realName: accountData.realName,
|
||||
email: accountData.email || '',
|
||||
phone: accountData.phone || '',
|
||||
companyId: accountData.companyId,
|
||||
departmentId: accountData.departmentId,
|
||||
positionId: accountData.positionId,
|
||||
roleId: accountData.roleId,
|
||||
avatarImageId: accountData.avatarImageId,
|
||||
departmentId: accountData.departmentId || 0,
|
||||
positionId: accountData.positionId || 0,
|
||||
remark: accountData.remark || '',
|
||||
status: accountData.status,
|
||||
};
|
||||
}
|
||||
@@ -102,7 +101,7 @@ async function handleSubmit() {
|
||||
|
||||
if (isEdit.value && currentAccountData.value) {
|
||||
const { password, ...updateData } = formData.value;
|
||||
await admin_updateAccountApi({ ...updateData, id: currentAccountData.value.id });
|
||||
await admin_updateAccountApi(currentAccountData.value.id, updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await admin_createAccountApi(formData.value);
|
||||
@@ -111,9 +110,10 @@ async function handleSubmit() {
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('保存账户失败:', error);
|
||||
message.error('保存账户失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '保存账户失败';
|
||||
message.error(errorMessage);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
@@ -147,11 +147,19 @@ defineExpose({
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="用户名" name="username" :rules="[{ required: true, message: '请输入用户名' }]">
|
||||
<Input v-model:value="formData.username" placeholder="请输入用户名" />
|
||||
<Form.Item label="登录账号" name="loginCode" :rules="[
|
||||
{ required: true, message: '请输入登录账号' },
|
||||
{ min: 4, max: 20, message: '登录账号长度为4-20个字符' },
|
||||
{ pattern: /^[a-zA-Z0-9_]+$/, message: '登录账号只能包含字母、数字和下划线' }
|
||||
]">
|
||||
<Input v-model:value="formData.loginCode" placeholder="请输入登录账号" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="!isEdit" label="密码" name="password" :rules="[{ required: true, message: '请输入密码' }]">
|
||||
<Form.Item v-if="!isEdit" label="密码" name="password" :rules="[
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ min: 8, max: 20, message: '密码长度为8-20个字符' },
|
||||
{ pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]{8,}$/, message: '密码必须包含大小写字母、数字,长度至少8位' }
|
||||
]">
|
||||
<Input v-model:value="formData.password" type="password" placeholder="请输入密码" />
|
||||
</Form.Item>
|
||||
|
||||
@@ -159,37 +167,36 @@ defineExpose({
|
||||
<Input v-model:value="formData.realName" placeholder="请输入真实姓名" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="邮箱" name="email">
|
||||
<Input v-model:value="formData.email" placeholder="请输入邮箱" />
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input v-model:value="formData.remark" placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="手机号" name="phone">
|
||||
<Form.Item label="手机号" name="phone" :rules="[
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' }
|
||||
]">
|
||||
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="公司ID" name="companyId">
|
||||
<Input v-model:value="formData.companyId" type="number" placeholder="请输入公司ID" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="部门ID" name="departmentId">
|
||||
<Form.Item label="部门ID" name="departmentId" :rules="[{ required: true, message: '请输入部门ID' }]">
|
||||
<Input v-model:value="formData.departmentId" type="number" placeholder="请输入部门ID" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="职位ID" name="positionId">
|
||||
<Input v-model:value="formData.positionId" type="number" placeholder="请输入职位ID" />
|
||||
<Form.Item label="岗位ID" name="positionId" :rules="[{ required: true, message: '请输入岗位ID' }]">
|
||||
<Input v-model:value="formData.positionId" type="number" placeholder="请输入岗位ID" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="角色ID" name="roleId">
|
||||
<Input v-model:value="formData.roleId" type="number" placeholder="请输入角色ID" />
|
||||
<Form.Item label="头像图片ID" name="avatarImageId">
|
||||
<Input v-model:value="formData.avatarImageId" type="number" placeholder="请输入头像图片ID" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Form.Item v-if="isEdit" label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
+10
-7
@@ -168,9 +168,10 @@ const gridOptions: VxeGridProps<any> = {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('查询数据失败:', error);
|
||||
message.error('查询数据失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '查询数据失败';
|
||||
message.error(errorMessage);
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
@@ -217,9 +218,10 @@ const handleDelete = async (row: AccountVO.AccountInfoVO) => {
|
||||
await admin_deleteAccountApi(row.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('删除失败:', error);
|
||||
message.error('删除失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -236,11 +238,12 @@ const handleBatchDelete = async () => {
|
||||
admin_deleteAccountApi(row.id)
|
||||
);
|
||||
await Promise.all(deletePromises);
|
||||
message.success('批量删除成功');
|
||||
message.success(`成功删除 ${selectedRows.length} 条记录`);
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('批量删除失败:', error);
|
||||
message.error('批量删除失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '批量删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+29
-18
@@ -76,11 +76,11 @@
|
||||
<Input v-model:value="formData.email" placeholder="请输入邮箱" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status" :rules="[{ required: true, message: '请选择状态' }]">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
<Form.Item label="状态" name="status">
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="正常"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
@@ -99,7 +99,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, onUnmounted } from 'vue';
|
||||
import { Form, Input, Modal, Select, DatePicker, Button, message } from 'ant-design-vue';
|
||||
import { Form, Input, Modal, DatePicker, Button, message, Switch } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import dayjs from 'dayjs';
|
||||
import {
|
||||
@@ -131,23 +131,31 @@ const newLogoFile = ref<File | null>(null); // 新选择的logo文件
|
||||
const originalLogoUrl = ref(''); // 原始logo URL
|
||||
const imageLoadError = ref(false); // 图片加载错误状态
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
name: string;
|
||||
address: string;
|
||||
contactPerson: string;
|
||||
contactPhone: string;
|
||||
email: string;
|
||||
logoImageId?: number;
|
||||
status: boolean;
|
||||
expireTime: any;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref({
|
||||
const formData = ref<FormData>({
|
||||
name: '',
|
||||
address: '',
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
logoImageId: undefined as number | undefined,
|
||||
status: 1,
|
||||
expireTime: undefined as any,
|
||||
logoImageId: undefined,
|
||||
status: true,
|
||||
expireTime: undefined,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
];
|
||||
// 开关组件不需要选项数组
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑公司' : '添加公司');
|
||||
@@ -171,7 +179,7 @@ function initFormData() {
|
||||
contactPhone: currentCompanyData.value.contactPhone || '',
|
||||
email: currentCompanyData.value.email || '',
|
||||
logoImageId: undefined,
|
||||
status: currentCompanyData.value.status,
|
||||
status: currentCompanyData.value.status === 1, // 转换为boolean
|
||||
expireTime: currentCompanyData.value.expireTime ? dayjs(currentCompanyData.value.expireTime) : undefined,
|
||||
};
|
||||
|
||||
@@ -186,7 +194,7 @@ function initFormData() {
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
logoImageId: undefined,
|
||||
status: 1,
|
||||
status: true,
|
||||
expireTime: undefined,
|
||||
};
|
||||
originalLogoUrl.value = '';
|
||||
@@ -212,7 +220,10 @@ async function handleSubmit() {
|
||||
loading.value = true;
|
||||
|
||||
// 准备提交数据
|
||||
const submitData = { ...formData.value };
|
||||
const submitData = {
|
||||
...formData.value,
|
||||
status: formData.value.status ? 1 : 0 // 转换boolean为number
|
||||
};
|
||||
|
||||
// 处理日期格式
|
||||
if (submitData.expireTime) {
|
||||
|
||||
+27
-18
@@ -1,12 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
|
||||
import { Form, Input, Modal, Select, message, Switch } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createDepartmentApi,
|
||||
updateDepartmentApi,
|
||||
type DepartmentVO,
|
||||
type DepartmentDTO
|
||||
type DepartmentVO
|
||||
} from '#/api/org/department';
|
||||
|
||||
interface Props {
|
||||
@@ -28,19 +27,23 @@ const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentDepartmentData = ref<DepartmentVO.DepartmentInfoVO | null>(null);
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
name: string;
|
||||
parentId?: number;
|
||||
remark: string;
|
||||
status: boolean;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<DepartmentDTO.CreateDepartmentDTO>({
|
||||
const formData = ref<FormData>({
|
||||
name: '',
|
||||
parentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
status: true,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
// 开关组件不需要选项数组
|
||||
|
||||
// 父部门选项
|
||||
const parentDepartmentOptions = computed(() => {
|
||||
@@ -90,7 +93,7 @@ function resetForm() {
|
||||
name: '',
|
||||
parentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
status: true,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
@@ -106,11 +109,17 @@ async function handleSubmit() {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
// 转换boolean值为number值
|
||||
const submitData = {
|
||||
...formData.value,
|
||||
status: formData.value.status ? 1 : 0
|
||||
};
|
||||
|
||||
if (isEdit.value && currentDepartmentData.value) {
|
||||
await updateDepartmentApi(currentDepartmentData.value.id, formData.value);
|
||||
await updateDepartmentApi(currentDepartmentData.value.id, submitData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createDepartmentApi(formData.value);
|
||||
await createDepartmentApi(submitData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
@@ -136,7 +145,7 @@ function open(editMode: boolean = false, departmentData?: DepartmentVO.Departmen
|
||||
name: departmentData.name,
|
||||
parentId: departmentData.parentId,
|
||||
remark: departmentData.remark || '',
|
||||
status: departmentData.status,
|
||||
status: departmentData.status === 1, // 转换为boolean
|
||||
};
|
||||
}
|
||||
|
||||
@@ -182,10 +191,10 @@ defineExpose({
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
+28
-18
@@ -1,12 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
|
||||
import { Form, Input, Modal, Select, message, Switch } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createPositionApi,
|
||||
updatePositionApi,
|
||||
type PositionVO,
|
||||
type PositionDTO
|
||||
type PositionVO
|
||||
} from '#/api/org/position';
|
||||
|
||||
interface Props {
|
||||
@@ -28,20 +27,25 @@ const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentPositionData = ref<PositionVO.PositionInfoVO | null>(null);
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
name: string;
|
||||
code: string;
|
||||
departmentId?: number;
|
||||
remark: string;
|
||||
status: boolean;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<PositionDTO.CreatePositionDTO>({
|
||||
const formData = ref<FormData>({
|
||||
name: '',
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
status: true,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
// 开关组件不需要选项数组
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑岗位' : '添加岗位');
|
||||
@@ -53,7 +57,7 @@ function resetForm() {
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
status: true,
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
@@ -69,11 +73,17 @@ async function handleSubmit() {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
// 转换boolean值为number值
|
||||
const submitData = {
|
||||
...formData.value,
|
||||
status: formData.value.status ? 1 : 0
|
||||
};
|
||||
|
||||
if (isEdit.value && currentPositionData.value) {
|
||||
await updatePositionApi(currentPositionData.value.id, formData.value);
|
||||
await updatePositionApi(currentPositionData.value.id, submitData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createPositionApi(formData.value);
|
||||
await createPositionApi(submitData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
@@ -100,7 +110,7 @@ function open(editMode: boolean = false, positionData?: PositionVO.PositionInfoV
|
||||
code: positionData.code || '',
|
||||
departmentId: positionData.departmentId,
|
||||
remark: positionData.remark || '',
|
||||
status: positionData.status,
|
||||
status: positionData.status === 1, // 转换为boolean
|
||||
};
|
||||
}
|
||||
|
||||
@@ -150,10 +160,10 @@ defineExpose({
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
+156
-204
@@ -1,153 +1,150 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, watch } from 'vue';
|
||||
import { Modal, Form, FormItem, Input, Select, Button, message } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Form, Input, Modal, Select, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
admin_createAccountApi,
|
||||
admin_updateAccountApi,
|
||||
type AccountVO,
|
||||
type AccountDTO
|
||||
} from '#/api/org/account';
|
||||
super_createAccountApi,
|
||||
super_updateAccountApi,
|
||||
type SuperAccountVO,
|
||||
type SuperAccountDTO
|
||||
} from '#/api/org/superAccount';
|
||||
|
||||
// 创建图标组件
|
||||
const SaveIcon = createIconifyIcon('lucide:save');
|
||||
const CancelIcon = createIconifyIcon('lucide:x');
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
visible?: boolean;
|
||||
accountData?: AccountVO.AccountInfoVO;
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
visible: false,
|
||||
accountData: undefined,
|
||||
});
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
cancel: [];
|
||||
}>();
|
||||
defineOptions({ name: 'SuperAccountFormModal' });
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const formData = ref<any>({
|
||||
username: '',
|
||||
const visible = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentAccountData = ref<SuperAccountVO.AccountInfoVO | null>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<SuperAccountDTO.SuperCreateAccountDTO & { status?: number }>({
|
||||
loginCode: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
companyId: 0,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
role: '',
|
||||
avatarImageId: undefined,
|
||||
remark: '',
|
||||
status: 0,
|
||||
});
|
||||
|
||||
// 计算属性
|
||||
const isEdit = computed(() => !!props.accountData);
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '新增账户');
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => isEdit.value ? '编辑账户' : '添加账户');
|
||||
|
||||
// 角色选项
|
||||
const roleOptions = [
|
||||
{ label: '超级管理员', value: 'super' },
|
||||
{ label: '管理员', value: 'admin' },
|
||||
{ label: '普通用户', value: 'user' },
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '正常', value: 0 },
|
||||
{ label: '删除', value: 1 },
|
||||
{ label: '停用', value: 2 },
|
||||
{ label: '冻结', value: 3 },
|
||||
];
|
||||
|
||||
// 监听props变化
|
||||
watch(() => props.accountData, (newData) => {
|
||||
if (newData) {
|
||||
formData.value = {
|
||||
id: newData.id,
|
||||
username: newData.username,
|
||||
realName: newData.realName,
|
||||
phone: newData.phone,
|
||||
companyId: newData.companyId,
|
||||
departmentId: newData.departmentId,
|
||||
positionId: newData.positionId,
|
||||
roleId: newData.roleId,
|
||||
status: newData.status,
|
||||
};
|
||||
} else {
|
||||
resetForm();
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
// 方法
|
||||
const resetForm = () => {
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
username: '',
|
||||
loginCode: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: undefined,
|
||||
companyId: 0,
|
||||
departmentId: undefined,
|
||||
positionId: undefined,
|
||||
roleId: undefined,
|
||||
status: 1,
|
||||
role: '',
|
||||
avatarImageId: undefined,
|
||||
remark: '',
|
||||
status: 0,
|
||||
};
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
// 处理模态框关闭
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(accountData?: SuperAccountVO.AccountInfoVO | null) {
|
||||
isEdit.value = !!accountData;
|
||||
currentAccountData.value = accountData || null;
|
||||
|
||||
resetForm();
|
||||
|
||||
if (accountData) {
|
||||
formData.value = {
|
||||
loginCode: accountData.loginCode,
|
||||
password: '', // 编辑时密码为空
|
||||
realName: accountData.realName,
|
||||
phone: accountData.phone || '',
|
||||
companyId: accountData.companyId || 0,
|
||||
departmentId: accountData.departmentId,
|
||||
positionId: accountData.positionId,
|
||||
role: accountData.role || '',
|
||||
avatarImageId: accountData.avatarImageId,
|
||||
remark: accountData.remark || '',
|
||||
status: accountData.status,
|
||||
};
|
||||
}
|
||||
|
||||
visible.value = true;
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value) {
|
||||
await admin_updateAccountApi(formData.value as AccountDTO.UpdateAccountDTO);
|
||||
|
||||
if (isEdit.value && currentAccountData.value) {
|
||||
const { password, ...updateData } = formData.value;
|
||||
await super_updateAccountApi(currentAccountData.value.id, updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await admin_createAccountApi(formData.value as AccountDTO.CreateAccountDTO);
|
||||
await super_createAccountApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
|
||||
visible.value = false;
|
||||
emit('success');
|
||||
handleCancel();
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error);
|
||||
message.error('保存失败');
|
||||
} catch (error: any) {
|
||||
console.error('保存账户失败:', error);
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '保存账户失败';
|
||||
message.error(errorMessage);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
resetForm();
|
||||
emit('cancel');
|
||||
};
|
||||
// 监听弹窗关闭
|
||||
watch(visible, (val) => {
|
||||
if (!val) {
|
||||
resetForm();
|
||||
}
|
||||
});
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open: (data?: AccountVO.AccountInfoVO) => {
|
||||
if (data) {
|
||||
formData.value = {
|
||||
id: data.id,
|
||||
username: data.username,
|
||||
realName: data.realName,
|
||||
phone: data.phone,
|
||||
companyId: data.companyId,
|
||||
departmentId: data.departmentId,
|
||||
positionId: data.positionId,
|
||||
roleId: data.roleId,
|
||||
status: data.status,
|
||||
};
|
||||
} else {
|
||||
resetForm();
|
||||
}
|
||||
},
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="props.visible"
|
||||
:open="visible"
|
||||
:title="modalTitle"
|
||||
width="600px"
|
||||
width="500px"
|
||||
:confirm-loading="loading"
|
||||
@ok="handleSave"
|
||||
@ok="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Form
|
||||
@@ -156,116 +153,71 @@ defineExpose({
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<FormItem
|
||||
label="登录账号"
|
||||
name="username"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入登录账号' },
|
||||
{ min: 3, max: 20, message: '登录账号长度必须在3-20个字符之间' },
|
||||
{ pattern: /^[a-zA-Z0-9_]+$/, message: '登录账号只能包含字母、数字和下划线' }
|
||||
]"
|
||||
>
|
||||
<Input v-model:value="formData.username" placeholder="请输入登录账号" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
v-if="!isEdit"
|
||||
label="密码"
|
||||
name="password"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ min: 8, max: 20, message: '密码长度必须在8-20个字符之间' }
|
||||
]"
|
||||
>
|
||||
<Form.Item label="登录账号" name="loginCode" :rules="[
|
||||
{ required: true, message: '请输入登录账号' },
|
||||
{ min: 3, max: 20, message: '登录账号长度为3-20个字符' },
|
||||
{ pattern: /^[a-zA-Z0-9_]+$/, message: '登录账号只能包含字母、数字和下划线' }
|
||||
]">
|
||||
<Input v-model:value="formData.loginCode" placeholder="请输入登录账号" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="!isEdit" label="密码" name="password" :rules="[
|
||||
{ required: true, message: '请输入密码' },
|
||||
{ min: 6, max: 20, message: '密码长度为6-20个字符' }
|
||||
]">
|
||||
<Input v-model:value="formData.password" type="password" placeholder="请输入密码" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="真实姓名"
|
||||
name="realName"
|
||||
:rules="[
|
||||
{ required: true, message: '请输入真实姓名' },
|
||||
{ max: 50, message: '真实姓名长度不能超过50个字符' }
|
||||
]"
|
||||
>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="真实姓名" name="realName" :rules="[{ required: true, message: '请输入真实姓名' }]">
|
||||
<Input v-model:value="formData.realName" placeholder="请输入真实姓名" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="手机号码"
|
||||
name="phone"
|
||||
:rules="[
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '手机号码格式不正确' }
|
||||
]"
|
||||
>
|
||||
<Input v-model:value="formData.phone" placeholder="请输入手机号码" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="公司ID"
|
||||
name="companyId"
|
||||
:rules="[
|
||||
{ required: true, message: '请选择公司' }
|
||||
]"
|
||||
>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input v-model:value="formData.remark" placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="手机号" name="phone" :rules="[
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' }
|
||||
]">
|
||||
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="公司ID" name="companyId" :rules="[{ required: true, message: '请输入公司ID' }]">
|
||||
<Input v-model:value="formData.companyId" type="number" placeholder="请输入公司ID" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="部门ID"
|
||||
name="departmentId"
|
||||
>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="部门ID" name="departmentId">
|
||||
<Input v-model:value="formData.departmentId" type="number" placeholder="请输入部门ID" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="岗位ID"
|
||||
name="positionId"
|
||||
>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="岗位ID" name="positionId">
|
||||
<Input v-model:value="formData.positionId" type="number" placeholder="请输入岗位ID" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="角色"
|
||||
name="roleId"
|
||||
:rules="[
|
||||
{ required: true, message: '请选择角色' }
|
||||
]"
|
||||
>
|
||||
<Select v-model:value="formData.roleId" placeholder="请选择角色">
|
||||
<Select.Option
|
||||
v-for="option in roleOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
label="状态"
|
||||
name="status"
|
||||
:rules="[
|
||||
{ required: true, message: '请选择状态' }
|
||||
]"
|
||||
>
|
||||
<Select v-model:value="formData.status" placeholder="请选择状态">
|
||||
<Select.Option :value="0">禁用</Select.Option>
|
||||
<Select.Option :value="1">正常</Select.Option>
|
||||
</Select>
|
||||
</FormItem>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="角色" name="role" :rules="[{ required: true, message: '请输入角色' }]">
|
||||
<Select
|
||||
v-model:value="formData.role"
|
||||
placeholder="请选择角色"
|
||||
:options="[
|
||||
{ label: '超级管理员', value: 'super' },
|
||||
{ label: '管理员', value: 'admin' },
|
||||
{ label: '普通用户', value: 'user' }
|
||||
]"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="头像图片ID" name="avatarImageId">
|
||||
<Input v-model:value="formData.avatarImageId" type="number" placeholder="请输入头像图片ID" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="isEdit" label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
</Form>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex justify-end space-x-2">
|
||||
<Button @click="handleCancel" :icon="CancelIcon">
|
||||
取消
|
||||
</Button>
|
||||
<Button type="primary" @click="handleSave" :loading="loading" :icon="SaveIcon">
|
||||
保存
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
+33
-30
@@ -8,11 +8,11 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import {
|
||||
admin_deleteAccountApi,
|
||||
admin_getAccountPageApi,
|
||||
type AccountVO,
|
||||
type AccountDTO
|
||||
} from '#/api/org/account';
|
||||
super_deleteAccountApi,
|
||||
super_getAccountPageApi,
|
||||
type SuperAccountVO,
|
||||
type SuperAccountDTO
|
||||
} from '#/api/org/superAccount';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import SuperAccountFormModal from './components/SuperAccountFormModal.vue';
|
||||
|
||||
@@ -27,14 +27,14 @@ const accountFormModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
username: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
companyId: undefined as number | undefined,
|
||||
departmentId: undefined as number | undefined,
|
||||
positionId: undefined as number | undefined,
|
||||
roleId: undefined as number | undefined,
|
||||
status: undefined as number | undefined,
|
||||
loginCode: undefined as undefined | string,
|
||||
realName: undefined as undefined | string,
|
||||
phone: undefined as undefined | string,
|
||||
companyId: undefined as undefined | number,
|
||||
departmentId: undefined as undefined | number,
|
||||
positionId: undefined as undefined | number,
|
||||
role: undefined as undefined | string,
|
||||
status: undefined as undefined | number,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
@@ -49,7 +49,7 @@ const statusOptions = [
|
||||
const formOptions = computed(() => ({
|
||||
schemas: [
|
||||
{
|
||||
fieldName: 'username',
|
||||
fieldName: 'loginCode',
|
||||
label: '登录账号',
|
||||
},
|
||||
{
|
||||
@@ -84,7 +84,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'username',
|
||||
field: 'loginCode',
|
||||
title: '登录账号',
|
||||
minWidth: 120,
|
||||
},
|
||||
@@ -158,19 +158,20 @@ const gridOptions: VxeGridProps<any> = {
|
||||
query: async ({ page }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<AccountDTO.AccountFilterDTO> = {
|
||||
const params: PageQueryDTO<SuperAccountDTO.AccountFilterDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...searchForm.value,
|
||||
};
|
||||
const response = await admin_getAccountPageApi(params);
|
||||
const response = await super_getAccountPageApi(params);
|
||||
return {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('查询数据失败:', error);
|
||||
message.error('查询数据失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '查询数据失败';
|
||||
message.error(errorMessage);
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
@@ -208,18 +209,19 @@ const handleAdd = () => {
|
||||
accountFormModalRef.value?.open();
|
||||
};
|
||||
|
||||
const handleEdit = (row: AccountVO.AccountInfoVO) => {
|
||||
accountFormModalRef.value?.open(true, row);
|
||||
const handleEdit = (row: SuperAccountVO.AccountInfoVO) => {
|
||||
accountFormModalRef.value?.open(row);
|
||||
};
|
||||
|
||||
const handleDelete = async (row: AccountVO.AccountInfoVO) => {
|
||||
const handleDelete = async (row: SuperAccountVO.AccountInfoVO) => {
|
||||
try {
|
||||
await admin_deleteAccountApi(row.id);
|
||||
await super_deleteAccountApi(row.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('删除失败:', error);
|
||||
message.error('删除失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -232,15 +234,16 @@ const handleBatchDelete = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const deletePromises = selectedRows.map((row: AccountVO.AccountInfoVO) =>
|
||||
admin_deleteAccountApi(row.id)
|
||||
const deletePromises = selectedRows.map((row: SuperAccountVO.AccountInfoVO) =>
|
||||
super_deleteAccountApi(row.id)
|
||||
);
|
||||
await Promise.all(deletePromises);
|
||||
message.success('批量删除成功');
|
||||
message.success(`成功删除 ${selectedRows.length} 条记录`);
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('批量删除失败:', error);
|
||||
message.error('批量删除失败');
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '批量删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ import {
|
||||
createProductWithSpecsApi
|
||||
} from '#/api/shop';
|
||||
import type { ProductVO, ProductDTO } from '#/api/shop/types';
|
||||
import { uploadImageApi } from '#/api/media';
|
||||
import { uploadImageApi } from '#/api/media/image';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
|
||||
+76
-74
@@ -1,77 +1,3 @@
|
||||
<template>
|
||||
<Modal
|
||||
:open="visible"
|
||||
:title="modalTitle"
|
||||
width="600px"
|
||||
:confirm-loading="loading"
|
||||
@ok="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="店铺Logo" name="logoImageId">
|
||||
<div style="display: flex; align-items: center; gap: 16px;">
|
||||
|
||||
<!-- Logo预览区域 -->
|
||||
<div style="position: relative; display: inline-block;">
|
||||
<!-- 有图片时显示图片 -->
|
||||
<img
|
||||
v-if="currentLogoUrl && !imageLoadError"
|
||||
:src="currentLogoUrl"
|
||||
alt="店铺Logo"
|
||||
style="width: 80px; height: 80px; object-fit: cover; border-radius: 8px; border: 1px solid #d9d9d9; background-color: #f5f5f5;"
|
||||
@error="handleImageError"
|
||||
/>
|
||||
<!-- 无图片或加载失败时显示空状态 -->
|
||||
<div
|
||||
v-else
|
||||
style="width: 80px; height: 80px; border: 1px dashed #d9d9d9; border-radius: 8px; background-color: #fafafa; display: flex; align-items: center; justify-content: center; color: #999; font-size: 12px; text-align: center; line-height: 1.2;">
|
||||
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px;" />
|
||||
<div>上传Logo</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 点击更换遮罩 -->
|
||||
<div
|
||||
style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); border-radius: 8px; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.3s; cursor: pointer;"
|
||||
@mouseenter="($event.target as HTMLElement).style.opacity = '1'"
|
||||
@mouseleave="($event.target as HTMLElement).style.opacity = '0'"
|
||||
@click="selectLogoFile">
|
||||
<div style="color: white; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px;" />
|
||||
<div style="font-size: 12px;">{{ currentLogoUrl && !imageLoadError ? '更换Logo' : '上传Logo' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 重置按钮 -->
|
||||
<div v-if="newLogoFile">
|
||||
<Button size="small" @click="removeNewLogo">重置</Button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="店铺名称" name="name" :rules="[{ required: true, message: '请输入店铺名称' }]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入店铺名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="平台" name="platform">
|
||||
<Select
|
||||
v-model:value="formData.platform"
|
||||
placeholder="请选择平台"
|
||||
:options="platformOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, onUnmounted } from 'vue';
|
||||
import { Form, Input, Modal, Select, Button, message } from 'ant-design-vue';
|
||||
@@ -302,3 +228,79 @@ onUnmounted(() => {
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
:open="visible"
|
||||
:title="modalTitle"
|
||||
width="600px"
|
||||
:confirm-loading="loading"
|
||||
@ok="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="店铺Logo" name="logoImageId">
|
||||
<div style="display: flex; align-items: center; gap: 16px;">
|
||||
|
||||
<!-- Logo预览区域 -->
|
||||
<div style="position: relative; display: inline-block;">
|
||||
<!-- 有图片时显示图片 -->
|
||||
<img
|
||||
v-if="currentLogoUrl && !imageLoadError"
|
||||
:src="currentLogoUrl"
|
||||
alt="店铺Logo"
|
||||
style="width: 80px; height: 80px; object-fit: cover; border-radius: 8px; border: 1px solid #d9d9d9; background-color: #f5f5f5;"
|
||||
@error="handleImageError"
|
||||
/>
|
||||
<!-- 无图片或加载失败时显示空状态 -->
|
||||
<div
|
||||
v-else
|
||||
style="width: 80px; height: 80px; border: 1px dashed #d9d9d9; border-radius: 8px; background-color: #fafafa; display: flex; align-items: center; justify-content: center; color: #999; font-size: 12px; text-align: center; line-height: 1.2;">
|
||||
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px;" />
|
||||
<div>上传Logo</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 点击更换遮罩 -->
|
||||
<div
|
||||
style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); border-radius: 8px; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.3s; cursor: pointer;"
|
||||
@mouseenter="($event.target as HTMLElement).style.opacity = '1'"
|
||||
@mouseleave="($event.target as HTMLElement).style.opacity = '0'"
|
||||
@click="selectLogoFile">
|
||||
<div style="color: white; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px;" />
|
||||
<div style="font-size: 12px;">{{ currentLogoUrl && !imageLoadError ? '更换Logo' : '上传Logo' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 重置按钮 -->
|
||||
<div v-if="newLogoFile">
|
||||
<Button size="small" @click="removeNewLogo">重置</Button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="店铺名称" name="name" :rules="[{ required: true, message: '请输入店铺名称' }]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入店铺名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="平台" name="platform">
|
||||
<Select
|
||||
v-model:value="formData.platform"
|
||||
placeholder="请选择平台"
|
||||
:options="platformOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
|
||||
|
||||
+258
-251
@@ -1,25 +1,249 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, h } from 'vue'
|
||||
import { Form, Input, InputNumber, Select, Popover, message, Radio, Switch } from 'ant-design-vue'
|
||||
import { createIconifyIcon } from '@vben/icons'
|
||||
import { useVbenModal } from '@vben/common-ui'
|
||||
import IconSelector from './IconSelector.vue'
|
||||
import {
|
||||
createMenuApi,
|
||||
updateMenuApi,
|
||||
getAllMenusApi,
|
||||
type MenuApi as MenuApiType
|
||||
} from '#/api/core/menu'
|
||||
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
cancel: [];
|
||||
}>();
|
||||
|
||||
// 创建Vben Modal实例
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
title: '菜单管理',
|
||||
draggable: true, // 开启拖拽
|
||||
contentClass: 'px-6 py-4', // 使用Tailwind CSS设置内边距
|
||||
onConfirm: handleSubmit,
|
||||
onCancel: close,
|
||||
onOpenChange: (isOpen: boolean) => {
|
||||
if (isOpen) {
|
||||
fetchParentMenuOptions();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const isEdit = ref(false);
|
||||
const currentRecord = ref<MenuApiType.MenuInfo | null>(null);
|
||||
const formRef = ref();
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
parentId?: number;
|
||||
superMenu: boolean;
|
||||
name: string;
|
||||
title: string;
|
||||
path: string;
|
||||
component: string;
|
||||
redirect: string;
|
||||
icon: string;
|
||||
order: number;
|
||||
type: string;
|
||||
visible: boolean;
|
||||
status: boolean;
|
||||
keepAlive: boolean;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<FormData>({
|
||||
parentId: undefined,
|
||||
superMenu: false,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
icon: '',
|
||||
order: 0,
|
||||
type: 'menu',
|
||||
visible: true,
|
||||
status: true,
|
||||
keepAlive: false,
|
||||
})
|
||||
|
||||
// 下拉选项数据
|
||||
const parentMenuOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
// 创建图标组件
|
||||
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
||||
|
||||
// 图标选择器内容
|
||||
const iconSelectorContent = h(IconSelector, {
|
||||
modelValue: formData.value.icon,
|
||||
'onUpdate:modelValue': (value: string) => {
|
||||
formData.value.icon = value;
|
||||
}
|
||||
});
|
||||
|
||||
// 获取父菜单选项
|
||||
async function fetchParentMenuOptions() {
|
||||
try {
|
||||
const data = await getAllMenusApi();
|
||||
const options: Array<{ label: string; value: number }> = [];
|
||||
|
||||
const addMenuOptions = (menus: MenuApiType.MenuInfo[], level = 0) => {
|
||||
menus.forEach(menu => {
|
||||
const prefix = ' '.repeat(level);
|
||||
options.push({
|
||||
label: `${prefix}${menu.title || menu.name}`,
|
||||
value: menu.id,
|
||||
});
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
addMenuOptions(menu.children, level + 1);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
addMenuOptions(data);
|
||||
parentMenuOptions.value = options;
|
||||
} catch (error) {
|
||||
console.error('获取菜单列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function open(edit: boolean, record?: MenuApiType.MenuInfo) {
|
||||
isEdit.value = edit;
|
||||
currentRecord.value = record || null;
|
||||
|
||||
// 更新模态框标题
|
||||
modalApi.setState({
|
||||
title: edit ? '编辑菜单' : '添加菜单'
|
||||
});
|
||||
|
||||
modalApi.open();
|
||||
|
||||
if (edit && record) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
parentId: record.parentId || undefined,
|
||||
superMenu: record.superMenu === 1, // 转换为boolean
|
||||
name: record.name,
|
||||
title: record.title || '',
|
||||
path: record.path || '',
|
||||
component: record.component || '',
|
||||
redirect: record.redirect || '',
|
||||
icon: record.icon || '',
|
||||
order: record.order || 0,
|
||||
type: record.type,
|
||||
visible: record.visible === 1, // 转换为boolean
|
||||
status: record.status === 1, // 转换为boolean
|
||||
keepAlive: record.keepAlive === 1, // 转换为boolean
|
||||
};
|
||||
} else if (!edit && record) {
|
||||
// 添加下级菜单模式,自动选中父菜单
|
||||
formData.value = {
|
||||
parentId: record.id, // 自动设置为当前菜单的ID作为父菜单
|
||||
superMenu: false,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
icon: '',
|
||||
order: 0,
|
||||
type: 'menu',
|
||||
visible: true,
|
||||
status: true,
|
||||
keepAlive: false,
|
||||
};
|
||||
} else {
|
||||
// 新增根菜单模式,重置表单
|
||||
formData.value = {
|
||||
parentId: undefined,
|
||||
superMenu: false,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
icon: '',
|
||||
order: 0,
|
||||
type: 'menu',
|
||||
visible: true,
|
||||
status: true,
|
||||
keepAlive: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function close() {
|
||||
modalApi.close();
|
||||
formRef.value?.resetFields();
|
||||
emit('cancel');
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
|
||||
// 设置模态框为loading状态
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
|
||||
// 转换boolean值为number值
|
||||
const submitData = {
|
||||
...formData.value,
|
||||
superMenu: formData.value.superMenu ? 1 : 0,
|
||||
visible: formData.value.visible ? 1 : 0,
|
||||
status: formData.value.status ? 1 : 0,
|
||||
keepAlive: formData.value.keepAlive ? 1 : 0,
|
||||
};
|
||||
|
||||
if (isEdit.value && currentRecord.value) {
|
||||
// 更新菜单
|
||||
await updateMenuApi(currentRecord.value.id, submitData);
|
||||
message.success('更新菜单成功');
|
||||
} else {
|
||||
// 创建菜单
|
||||
await createMenuApi(submitData);
|
||||
message.success('创建菜单成功');
|
||||
}
|
||||
|
||||
close();
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('提交菜单失败:', error);
|
||||
message.error('提交菜单失败');
|
||||
} finally {
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
open,
|
||||
close,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
:title="isEdit ? '编辑菜单' : '添加菜单'"
|
||||
:confirm-loading="loading"
|
||||
width="600px"
|
||||
@ok="handleSubmit"
|
||||
@cancel="close"
|
||||
>
|
||||
<Modal>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
class="space-y-5"
|
||||
>
|
||||
<Form.Item label="菜单类型" name="type" :rules="[{ required: true, message: '请选择菜单类型' }]">
|
||||
<Radio.Group v-model:value="formData.type" button-style="solid">
|
||||
<Radio.Button value="catalog">目录</Radio.Button>
|
||||
<Radio.Button value="menu">菜单</Radio.Button>
|
||||
<Radio.Button value="button">按钮</Radio.Button>
|
||||
<Radio.Button value="embedded">内联</Radio.Button>
|
||||
<Radio.Button value="link">外链</Radio.Button>
|
||||
<Radio.Group v-model:value="formData.type" button-style="solid" class="w-full">
|
||||
<Radio.Button value="catalog" class="flex-1">目录</Radio.Button>
|
||||
<Radio.Button value="menu" class="flex-1">菜单</Radio.Button>
|
||||
<Radio.Button value="button" class="flex-1">按钮</Radio.Button>
|
||||
<Radio.Button value="embedded" class="flex-1">内联</Radio.Button>
|
||||
<Radio.Button value="link" class="flex-1">外链</Radio.Button>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
|
||||
@@ -33,10 +257,11 @@
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="超级菜单" name="superMenu">
|
||||
<Select
|
||||
v-model:value="formData.superMenu"
|
||||
placeholder="请选择是否为超级菜单"
|
||||
:options="superMenuOptions"
|
||||
<Switch
|
||||
v-model:checked="formData.superMenu"
|
||||
checked-children="是"
|
||||
un-checked-children="否"
|
||||
class="w-12"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
@@ -87,251 +312,33 @@
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="是否显示" name="visible">
|
||||
<Select
|
||||
v-model:value="formData.visible"
|
||||
placeholder="请选择是否显示"
|
||||
:options="visibleOptions"
|
||||
<Switch
|
||||
v-model:checked="formData.visible"
|
||||
checked-children="显示"
|
||||
un-checked-children="隐藏"
|
||||
class="w-12"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
class="w-12"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="是否缓存" name="keepAlive">
|
||||
<Select
|
||||
v-model:value="formData.keepAlive"
|
||||
placeholder="请选择是否缓存"
|
||||
:options="keepAliveOptions"
|
||||
<Switch
|
||||
v-model:checked="formData.keepAlive"
|
||||
checked-children="缓存"
|
||||
un-checked-children="不缓存"
|
||||
class="w-12"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, h } from 'vue'
|
||||
import { Modal, Form, Input, InputNumber, Select, Popover, message, Radio } from 'ant-design-vue'
|
||||
import { createIconifyIcon } from '@vben/icons'
|
||||
import IconSelector from './IconSelector.vue'
|
||||
import {
|
||||
createMenuApi,
|
||||
updateMenuApi,
|
||||
getAllMenusApi,
|
||||
type MenuApi as MenuApiType
|
||||
} from '#/api/core/menu'
|
||||
|
||||
defineProps<{
|
||||
visible?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
cancel: [];
|
||||
}>();
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false);
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentRecord = ref<MenuApiType.MenuInfo | null>(null);
|
||||
const formRef = ref();
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<MenuApiType.CreateMenuParams>({
|
||||
parentId: undefined,
|
||||
superMenu: 0,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
icon: '',
|
||||
order: 0,
|
||||
type: 'menu',
|
||||
visible: 1,
|
||||
status: 1,
|
||||
keepAlive: 0,
|
||||
})
|
||||
|
||||
// 模态框标题(已移到模板中)
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
]
|
||||
|
||||
// 可见性选项
|
||||
const visibleOptions = [
|
||||
{ label: '隐藏', value: 0 },
|
||||
{ label: '显示', value: 1 },
|
||||
]
|
||||
|
||||
// 缓存选项
|
||||
const keepAliveOptions = [
|
||||
{ label: '不缓存', value: 0 },
|
||||
{ label: '缓存', value: 1 },
|
||||
]
|
||||
|
||||
// 超级菜单选项
|
||||
const superMenuOptions = [
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
]
|
||||
|
||||
// 下拉选项数据
|
||||
const parentMenuOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
// 创建图标组件
|
||||
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
||||
|
||||
// 图标选择器内容
|
||||
const iconSelectorContent = h(IconSelector, {
|
||||
modelValue: formData.value.icon,
|
||||
'onUpdate:modelValue': (value: string) => {
|
||||
formData.value.icon = value;
|
||||
}
|
||||
});
|
||||
|
||||
// 获取父菜单选项
|
||||
async function fetchParentMenuOptions() {
|
||||
try {
|
||||
const data = await getAllMenusApi();
|
||||
const options: Array<{ label: string; value: number }> = [];
|
||||
|
||||
const addMenuOptions = (menus: MenuApiType.MenuInfo[], level = 0) => {
|
||||
menus.forEach(menu => {
|
||||
const prefix = ' '.repeat(level);
|
||||
options.push({
|
||||
label: `${prefix}${menu.title || menu.name}`,
|
||||
value: menu.id,
|
||||
});
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
addMenuOptions(menu.children, level + 1);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
addMenuOptions(data);
|
||||
parentMenuOptions.value = options;
|
||||
} catch (error) {
|
||||
console.error('获取菜单列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function open(edit: boolean, record?: MenuApiType.MenuInfo) {
|
||||
isEdit.value = edit;
|
||||
currentRecord.value = record || null;
|
||||
visible.value = true;
|
||||
|
||||
if (edit && record) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
parentId: record.parentId || undefined,
|
||||
superMenu: record.superMenu || 0,
|
||||
name: record.name,
|
||||
title: record.title || '',
|
||||
path: record.path || '',
|
||||
component: record.component || '',
|
||||
redirect: record.redirect || '',
|
||||
icon: record.icon || '',
|
||||
order: record.order || 0,
|
||||
type: record.type,
|
||||
visible: record.visible || 1,
|
||||
status: record.status || 1,
|
||||
keepAlive: record.keepAlive || 0,
|
||||
};
|
||||
} else if (!edit && record) {
|
||||
// 添加下级菜单模式,自动选中父菜单
|
||||
formData.value = {
|
||||
parentId: record.id, // 自动设置为当前菜单的ID作为父菜单
|
||||
superMenu: 0,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
icon: '',
|
||||
order: 0,
|
||||
type: 'menu',
|
||||
visible: 1,
|
||||
status: 1,
|
||||
keepAlive: 0,
|
||||
};
|
||||
} else {
|
||||
// 新增根菜单模式,重置表单
|
||||
formData.value = {
|
||||
parentId: undefined,
|
||||
superMenu: 0,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
icon: '',
|
||||
order: 0,
|
||||
type: 'menu',
|
||||
visible: 1,
|
||||
status: 1,
|
||||
keepAlive: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function close() {
|
||||
visible.value = false;
|
||||
formRef.value?.resetFields();
|
||||
emit('cancel');
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value && currentRecord.value) {
|
||||
// 更新菜单
|
||||
await updateMenuApi(currentRecord.value.id, formData.value);
|
||||
message.success('更新菜单成功');
|
||||
} else {
|
||||
// 创建菜单
|
||||
await createMenuApi(formData.value);
|
||||
message.success('创建菜单成功');
|
||||
}
|
||||
|
||||
close();
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('提交菜单失败:', error);
|
||||
message.error('提交菜单失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 监听visible变化
|
||||
watch(visible, (newVal) => {
|
||||
if (newVal) {
|
||||
fetchParentMenuOptions();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
open,
|
||||
close,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 自定义样式 */
|
||||
</style>
|
||||
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { Form, Input, Select, Switch, message } from 'ant-design-vue';
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
createPermissionApi,
|
||||
updatePermissionApi,
|
||||
type PermissionVO
|
||||
} from '#/api/system/permission';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
defineOptions({ name: 'PermissionFormModal' });
|
||||
|
||||
// 创建Vben Modal实例
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
title: '权限管理',
|
||||
draggable: true, // 开启拖拽
|
||||
contentClass: 'px-6 py-4', // 使用Tailwind CSS设置内边距
|
||||
onConfirm: handleSubmit,
|
||||
onCancel: close,
|
||||
onOpenChange: (isOpen: boolean) => {
|
||||
if (!isOpen) {
|
||||
resetForm();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const isEdit = ref(false);
|
||||
const currentPermissionData = ref<PermissionVO.PermissionInfoVO | null>(null);
|
||||
|
||||
// 内部表单数据类型
|
||||
interface FormData {
|
||||
code: string;
|
||||
name: string;
|
||||
type: string;
|
||||
status: boolean;
|
||||
remark: string;
|
||||
}
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<FormData>({
|
||||
code: '',
|
||||
name: '',
|
||||
type: '',
|
||||
status: true,
|
||||
remark: '',
|
||||
});
|
||||
|
||||
|
||||
// 状态选项(开关组件不需要选项数组)
|
||||
|
||||
// 权限类型选项
|
||||
const typeOptions = [
|
||||
{ label: '接口权限', value: 'api' },
|
||||
{ label: '按钮权限', value: 'button' },
|
||||
{ label: '数据权限', value: 'data' },
|
||||
];
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formData.value = {
|
||||
code: '',
|
||||
name: '',
|
||||
type: '',
|
||||
status: true,
|
||||
remark: '',
|
||||
};
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function close() {
|
||||
modalApi.close();
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(permissionData?: PermissionVO.PermissionInfoVO | null) {
|
||||
isEdit.value = !!permissionData;
|
||||
currentPermissionData.value = permissionData || null;
|
||||
|
||||
// 更新模态框标题
|
||||
modalApi.setState({
|
||||
title: isEdit.value ? '编辑权限' : '添加权限'
|
||||
});
|
||||
|
||||
resetForm();
|
||||
|
||||
if (permissionData) {
|
||||
formData.value = {
|
||||
code: permissionData.code,
|
||||
name: permissionData.name,
|
||||
type: permissionData.type,
|
||||
status: permissionData.status === 1, // 转换为boolean值
|
||||
remark: permissionData.remark || '',
|
||||
};
|
||||
}
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
|
||||
// 设置模态框为loading状态
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
|
||||
// 转换状态值为数字
|
||||
const submitData = {
|
||||
...formData.value,
|
||||
status: formData.value.status ? 1 : 0
|
||||
};
|
||||
|
||||
if (isEdit.value && currentPermissionData.value) {
|
||||
await updatePermissionApi(currentPermissionData.value.id, submitData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createPermissionApi(submitData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
close();
|
||||
emit('success');
|
||||
} catch (error: any) {
|
||||
console.error('保存权限失败:', error);
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '保存权限失败';
|
||||
message.error(errorMessage);
|
||||
} finally {
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
class="space-y-5"
|
||||
>
|
||||
<Form.Item label="权限码" name="code" :rules="[
|
||||
{ required: true, message: '请输入权限码' },
|
||||
{ min: 2, max: 50, message: '权限码长度为2-50个字符' },
|
||||
{ pattern: /^[a-zA-Z0-9:_-]+$/, message: '权限码只能包含字母、数字、冒号、下划线和连字符' }
|
||||
]">
|
||||
<Input v-model:value="formData.code" placeholder="请输入权限码,如 user:add" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="权限名称" name="name" :rules="[
|
||||
{ required: true, message: '请输入权限名称' },
|
||||
{ min: 2, max: 50, message: '权限名称长度为2-50个字符' }
|
||||
]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入权限名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="权限类型" name="type" :rules="[{ required: true, message: '请选择权限类型' }]">
|
||||
<Select
|
||||
v-model:value="formData.type"
|
||||
placeholder="请选择权限类型"
|
||||
:options="typeOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Switch
|
||||
v-model:checked="formData.status"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
class="w-12"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入备注信息"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, message, Space, Tag } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import {
|
||||
deletePermissionApi,
|
||||
getPermissionPageApi,
|
||||
type PermissionVO,
|
||||
type PermissionDTO
|
||||
} from '#/api/system/permission';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import PermissionFormModal from './components/PermissionFormModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
defineOptions({ name: 'PermissionManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const permissionFormModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
code: undefined as undefined | string,
|
||||
name: undefined as undefined | string,
|
||||
type: undefined as undefined | string,
|
||||
status: undefined as undefined | number,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
];
|
||||
|
||||
// 权限类型选项
|
||||
const typeOptions = [
|
||||
{ label: '接口权限', value: 'api' },
|
||||
{ label: '按钮权限', value: 'button' },
|
||||
{ label: '数据权限', value: 'data' },
|
||||
];
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schemas: [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '权限码',
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '权限名称',
|
||||
},
|
||||
{
|
||||
fieldName: 'type',
|
||||
label: '权限类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: typeOptions,
|
||||
placeholder: '请选择权限类型',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: statusOptions,
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
title: '权限码',
|
||||
minWidth: 200,
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '权限名称',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
title: '权限类型',
|
||||
minWidth: 120,
|
||||
slots: { default: 'type' },
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 80,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 120,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
data: [],
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<PermissionDTO.PermissionFilterDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...searchForm.value,
|
||||
};
|
||||
const response = await getPermissionPageApi(params);
|
||||
return {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error('查询数据失败:', error);
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '查询数据失败';
|
||||
message.error(errorMessage);
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 表格实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '权限管理',
|
||||
});
|
||||
|
||||
// 计算属性
|
||||
const hasSelected = computed(() => {
|
||||
const vxeTable = (gridApi as any).grid;
|
||||
return vxeTable?.getCheckboxRecords?.()?.length > 0;
|
||||
});
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
permissionFormModalRef.value?.open();
|
||||
};
|
||||
|
||||
const handleEdit = (row: PermissionVO.PermissionInfoVO) => {
|
||||
permissionFormModalRef.value?.open(row);
|
||||
};
|
||||
|
||||
const handleDelete = async (row: PermissionVO.PermissionInfoVO) => {
|
||||
try {
|
||||
await deletePermissionApi(row.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error: any) {
|
||||
console.error('删除失败:', error);
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBatchDelete = async () => {
|
||||
const vxeTable = (gridApi as any).grid;
|
||||
const selectedRows = vxeTable?.getCheckboxRecords?.();
|
||||
if (!selectedRows?.length) {
|
||||
message.warning('请选择要删除的数据');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const deletePromises = selectedRows.map((row: PermissionVO.PermissionInfoVO) =>
|
||||
deletePermissionApi(row.id)
|
||||
);
|
||||
await Promise.all(deletePromises);
|
||||
message.success(`成功删除 ${selectedRows.length} 条记录`);
|
||||
refreshTable();
|
||||
} catch (error: any) {
|
||||
console.error('批量删除失败:', error);
|
||||
const errorMessage = error?.response?.data?.message || error?.message || '批量删除失败';
|
||||
message.error(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
// 处理模态框成功回调
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 获取权限类型文本
|
||||
const getTypeText = (type: string) => {
|
||||
const typeMap = {
|
||||
api: '接口权限',
|
||||
button: '按钮权限',
|
||||
data: '数据权限',
|
||||
};
|
||||
return typeMap[type as keyof typeof typeMap] || type;
|
||||
};
|
||||
|
||||
// 获取权限类型颜色
|
||||
const getTypeColor = (type: string) => {
|
||||
const colorMap = {
|
||||
api: 'blue',
|
||||
button: 'green',
|
||||
data: 'orange',
|
||||
};
|
||||
return colorMap[type as keyof typeof colorMap] || 'default';
|
||||
};
|
||||
|
||||
// 获取状态文本
|
||||
const getStatusText = (status: number) => {
|
||||
return status === 1 ? '启用' : '禁用';
|
||||
};
|
||||
|
||||
// 获取状态颜色
|
||||
const getStatusColor = (status: number) => {
|
||||
return status === 1 ? 'green' : 'red';
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="权限管理" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理系统权限码,支持权限的增删改查操作
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid
|
||||
:loading="loading"
|
||||
>
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加权限
|
||||
</Button>
|
||||
<Button
|
||||
v-if="hasSelected"
|
||||
danger
|
||||
@click="handleBatchDelete"
|
||||
>
|
||||
批量删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 权限类型列 -->
|
||||
<template #type="{ row }">
|
||||
<Tag :color="getTypeColor(row.type)">
|
||||
{{ getTypeText(row.type) }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }">
|
||||
<Tag :color="getStatusColor(row.status)">
|
||||
{{ getStatusText(row.status) }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)">
|
||||
编辑
|
||||
</Button>
|
||||
<Button size="small" danger @click="handleDelete(row)">
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 权限表单弹窗 -->
|
||||
<PermissionFormModal ref="permissionFormModalRef" @success="handleModalSuccess" />
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user