mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
完善创建公司初始化数据相关
This commit is contained in:
+1
-1
@@ -64,7 +64,7 @@ public class SecurityConfig {
|
||||
AuthenticationException authException) throws IOException {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":401,\"message\":\"Token无效或已过期,请重新登录\",\"data\":null}");
|
||||
response.getWriter().write("{\"code\":401,\"message\":\"登录已过期,请重新登录\",\"data\":null}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
@@ -53,4 +53,25 @@ public interface CompanyService extends IService<CompanyPO> {
|
||||
* @return 更新后的公司信息
|
||||
*/
|
||||
CompanyVO uploadLogo(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 初始化公司菜单
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
*/
|
||||
void initCompanyMenus(Long companyId);
|
||||
|
||||
/**
|
||||
* 初始化公司部门
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
*/
|
||||
void initCompanyDepartments(Long companyId);
|
||||
|
||||
/**
|
||||
* 初始化公司岗位
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
*/
|
||||
void initCompanyPositions(Long companyId);
|
||||
}
|
||||
|
||||
+9
@@ -45,4 +45,13 @@ public interface DepartmentService extends IService<DepartmentPO> {
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<DepartmentVO> getDepartmentPage(PageQueryDTO<DepartmentFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 为指定公司创建部门(用于初始化)
|
||||
*
|
||||
* @param createDepartmentDTO 部门信息
|
||||
* @param companyId 公司ID
|
||||
* @return 部门信息
|
||||
*/
|
||||
DepartmentVO createDepartmentForCompany(CreateDepartmentDTO createDepartmentDTO, Long companyId);
|
||||
}
|
||||
|
||||
+9
@@ -45,4 +45,13 @@ public interface PositionService extends IService<PositionPO> {
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<PositionVO> getPositionPage(PageQueryDTO<PositionFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 为指定公司创建岗位(用于初始化)
|
||||
*
|
||||
* @param createPositionDTO 岗位信息
|
||||
* @param companyId 公司ID
|
||||
* @return 岗位信息
|
||||
*/
|
||||
PositionVO createPositionForCompany(CreatePositionDTO createPositionDTO, Long companyId);
|
||||
}
|
||||
|
||||
+158
-1
@@ -21,11 +21,25 @@ import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.OrderStatusService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.PromotionFeeTypeService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.service.CompanyMenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.service.DepartmentService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.service.PositionService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu.CreateCompanyMenuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.model.dto.department.CreateDepartmentDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.CreatePositionDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.model.po.CompanyMenuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.model.vo.CompanyMenuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.MenuService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -38,15 +52,27 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
private final MediaImageService mediaImageService;
|
||||
private final OrderStatusService orderStatusService;
|
||||
private final PromotionFeeTypeService promotionFeeTypeService;
|
||||
private final CompanyMenuService companyMenuService;
|
||||
private final DepartmentService departmentService;
|
||||
private final PositionService positionService;
|
||||
private final MenuService menuService;
|
||||
|
||||
public CompanyServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService, OrderStatusService orderStatusService, PromotionFeeTypeService promotionFeeTypeService) {
|
||||
public CompanyServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService,
|
||||
OrderStatusService orderStatusService, PromotionFeeTypeService promotionFeeTypeService,
|
||||
CompanyMenuService companyMenuService, DepartmentService departmentService,
|
||||
PositionService positionService, MenuService menuService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.mediaImageService = mediaImageService;
|
||||
this.orderStatusService = orderStatusService;
|
||||
this.promotionFeeTypeService = promotionFeeTypeService;
|
||||
this.companyMenuService = companyMenuService;
|
||||
this.departmentService = departmentService;
|
||||
this.positionService = positionService;
|
||||
this.menuService = menuService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CompanyVO createCompany(CreateCompanyDTO createCompanyDTO) {
|
||||
// 检查公司名称是否重复
|
||||
LambdaQueryWrapper<CompanyPO> wrapper = new LambdaQueryWrapper<>();
|
||||
@@ -85,6 +111,15 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
// 初始化推广费类型数据
|
||||
promotionFeeTypeService.initPromotionFeeTypeForCompany(company.getId());
|
||||
|
||||
// 初始化公司菜单(非超级菜单)
|
||||
initCompanyMenus(company.getId());
|
||||
|
||||
// 初始化公司部门
|
||||
initCompanyDepartments(company.getId());
|
||||
|
||||
// 初始化公司岗位
|
||||
initCompanyPositions(company.getId());
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(company);
|
||||
}
|
||||
@@ -209,6 +244,128 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
return convertToVO(company);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initCompanyMenus(Long companyId) {
|
||||
// 查询所有非超级菜单,按层级顺序排序
|
||||
LambdaQueryWrapper<MenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MenuPO::getSuperMenu, 0) // 非超级菜单
|
||||
.eq(MenuPO::getStatus, 1) // 启用状态
|
||||
.orderByAsc(MenuPO::getOrder) // 按排序字段排序
|
||||
.orderByAsc(MenuPO::getId); // 按ID排序确保一致性
|
||||
|
||||
List<MenuPO> menus = menuService.list(wrapper);
|
||||
|
||||
// 创建菜单ID到公司菜单ID的映射,用于建立父子关系
|
||||
Map<Long, Long> menuIdToCompanyMenuIdMap = new HashMap<>();
|
||||
|
||||
// 按层级递归创建菜单
|
||||
createCompanyMenusRecursively(menus, companyId, null, menuIdToCompanyMenuIdMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归创建公司菜单,保持层级关系
|
||||
*/
|
||||
private void createCompanyMenusRecursively(List<MenuPO> allMenus, Long companyId,
|
||||
Long parentMenuId, Map<Long, Long> menuIdToCompanyMenuIdMap) {
|
||||
// 查找当前层级的菜单
|
||||
List<MenuPO> currentLevelMenus = allMenus.stream()
|
||||
.filter(menu -> Objects.equals(menu.getParentId(), parentMenuId))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (MenuPO menu : currentLevelMenus) {
|
||||
// 检查是否已经存在对应的公司菜单
|
||||
LambdaQueryWrapper<CompanyMenuPO> existingWrapper = new LambdaQueryWrapper<>();
|
||||
existingWrapper.eq(CompanyMenuPO::getCompanyId, companyId)
|
||||
.eq(CompanyMenuPO::getMenuId, menu.getId());
|
||||
CompanyMenuPO existingCompanyMenu = companyMenuService.getOne(existingWrapper);
|
||||
|
||||
Long companyMenuId;
|
||||
if (existingCompanyMenu != null) {
|
||||
// 如果已存在,使用现有的ID
|
||||
companyMenuId = existingCompanyMenu.getId();
|
||||
} else {
|
||||
// 创建新的公司菜单
|
||||
CreateCompanyMenuDTO createCompanyMenuDTO = new CreateCompanyMenuDTO();
|
||||
createCompanyMenuDTO.setCompanyId(companyId);
|
||||
createCompanyMenuDTO.setMenuId(menu.getId());
|
||||
|
||||
// 设置父级ID(如果存在对应的父级公司菜单)
|
||||
if (parentMenuId != null) {
|
||||
Long parentCompanyMenuId = menuIdToCompanyMenuIdMap.get(parentMenuId);
|
||||
createCompanyMenuDTO.setParentId(parentCompanyMenuId);
|
||||
}
|
||||
|
||||
try {
|
||||
CompanyMenuVO companyMenuVO = companyMenuService.createCompanyMenu(createCompanyMenuDTO);
|
||||
companyMenuId = companyMenuVO.getId();
|
||||
} catch (BusinessException e) {
|
||||
// 如果创建失败,跳过
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 记录映射关系
|
||||
menuIdToCompanyMenuIdMap.put(menu.getId(), companyMenuId);
|
||||
|
||||
// 递归创建子菜单
|
||||
createCompanyMenusRecursively(allMenus, companyId, menu.getId(), menuIdToCompanyMenuIdMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initCompanyDepartments(Long companyId) {
|
||||
// 创建默认部门
|
||||
String[] defaultDepartments = {
|
||||
"总经理办公室",
|
||||
"技术部",
|
||||
"市场部",
|
||||
"财务部",
|
||||
"人事部"
|
||||
};
|
||||
|
||||
for (String deptName : defaultDepartments) {
|
||||
CreateDepartmentDTO createDepartmentDTO = new CreateDepartmentDTO();
|
||||
createDepartmentDTO.setName(deptName);
|
||||
createDepartmentDTO.setRemark("系统初始化的默认部门");
|
||||
createDepartmentDTO.setStatus(1);
|
||||
|
||||
try {
|
||||
departmentService.createDepartmentForCompany(createDepartmentDTO, companyId);
|
||||
} catch (BusinessException e) {
|
||||
// 如果已存在,跳过
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initCompanyPositions(Long companyId) {
|
||||
// 创建默认岗位
|
||||
String[][] defaultPositions = {
|
||||
{"总经理", "GM001", "负责公司整体运营管理"},
|
||||
{"技术总监", "CTO001", "负责技术团队管理和技术决策"},
|
||||
{"软件工程师", "SE001", "负责软件开发工作"},
|
||||
{"市场经理", "MM001", "负责市场推广和销售管理"},
|
||||
{"财务经理", "FM001", "负责财务管理和会计核算"},
|
||||
{"人事经理", "HR001", "负责人力资源管理"}
|
||||
};
|
||||
|
||||
for (String[] position : defaultPositions) {
|
||||
CreatePositionDTO createPositionDTO = new CreatePositionDTO();
|
||||
createPositionDTO.setName(position[0]);
|
||||
createPositionDTO.setCode(position[1]);
|
||||
createPositionDTO.setRemark(position[2]);
|
||||
createPositionDTO.setStatus(1);
|
||||
|
||||
try {
|
||||
positionService.createPositionForCompany(createPositionDTO, companyId);
|
||||
} catch (BusinessException e) {
|
||||
// 如果已存在,跳过
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
|
||||
+33
@@ -180,6 +180,39 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public DepartmentVO createDepartmentForCompany(CreateDepartmentDTO createDepartmentDTO, Long companyId) {
|
||||
// 验证部门名称是否重复
|
||||
LambdaQueryWrapper<DepartmentPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DepartmentPO::getName, createDepartmentDTO.getName())
|
||||
.eq(DepartmentPO::getCompanyId, companyId);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("部门名称已存在");
|
||||
}
|
||||
|
||||
// 创建部门
|
||||
DepartmentPO department = new DepartmentPO();
|
||||
BeanUtils.copyProperties(createDepartmentDTO, department);
|
||||
|
||||
// 设置公司ID
|
||||
department.setCompanyId(companyId);
|
||||
|
||||
// 设置默认值
|
||||
if (department.getStatus() == null) {
|
||||
department.setStatus(1);
|
||||
}
|
||||
|
||||
// 设置创建人ID
|
||||
department.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 保存部门
|
||||
this.save(department);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(department);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
|
||||
+33
@@ -170,6 +170,39 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PositionVO createPositionForCompany(CreatePositionDTO createPositionDTO, Long companyId) {
|
||||
// 验证岗位名称是否重复
|
||||
LambdaQueryWrapper<PositionPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PositionPO::getName, createPositionDTO.getName())
|
||||
.eq(PositionPO::getCompanyId, companyId);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("岗位名称已存在");
|
||||
}
|
||||
|
||||
// 创建岗位
|
||||
PositionPO position = new PositionPO();
|
||||
BeanUtils.copyProperties(createPositionDTO, position);
|
||||
|
||||
// 设置公司ID
|
||||
position.setCompanyId(companyId);
|
||||
|
||||
// 设置默认值
|
||||
if (position.getStatus() == null) {
|
||||
position.setStatus(1);
|
||||
}
|
||||
|
||||
// 设置创建人ID
|
||||
position.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 保存岗位
|
||||
this.save(position);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
|
||||
+8
@@ -71,4 +71,12 @@ public class MenuController {
|
||||
MenuVO menuVO = menuService.getMenuDetail(id);
|
||||
return ApiResponse.success(menuVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据角色获取菜单树", description = "根据用户角色获取对应的菜单树")
|
||||
@GetMapping("/tree/role/{userRole}")
|
||||
public ApiResponse<List<MenuVO>> getMenuTreeByRole(
|
||||
@Parameter(description = "用户角色") @PathVariable String userRole) {
|
||||
List<MenuVO> menuTree = menuService.getMenuTreeByRole(userRole);
|
||||
return ApiResponse.success(menuTree);
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -18,6 +18,11 @@ public class CreateMenuDTO {
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 是否超级菜单 (0-否 1-是)
|
||||
*/
|
||||
private Integer superMenu;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
|
||||
+5
@@ -18,6 +18,11 @@ public class UpdateMenuDTO {
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 是否超级菜单 (0-否 1-是)
|
||||
*/
|
||||
private Integer superMenu;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
|
||||
+6
@@ -26,6 +26,12 @@ public class MenuPO {
|
||||
@TableField("parent_id")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 是否超级菜单 (0-否 1-是)
|
||||
*/
|
||||
@TableField("super")
|
||||
private Integer superMenu;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
|
||||
+5
@@ -25,6 +25,11 @@ public class MenuVO {
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 是否超级菜单 (0-否 1-是)
|
||||
*/
|
||||
private Integer superMenu;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
|
||||
+8
@@ -57,4 +57,12 @@ public interface MenuService extends IService<MenuPO> {
|
||||
* @return 菜单详情
|
||||
*/
|
||||
MenuVO getMenuDetail(Long id);
|
||||
|
||||
/**
|
||||
* 根据用户角色获取菜单树
|
||||
*
|
||||
* @param userRole 用户角色
|
||||
* @return 菜单树列表
|
||||
*/
|
||||
List<MenuVO> getMenuTreeByRole(String userRole);
|
||||
}
|
||||
|
||||
+26
@@ -52,6 +52,9 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuPO> implements
|
||||
BeanUtils.copyProperties(createMenuDTO, menu);
|
||||
|
||||
// 设置默认值
|
||||
if (menu.getSuperMenu() == null) {
|
||||
menu.setSuperMenu(0);
|
||||
}
|
||||
if (menu.getVisible() == null) {
|
||||
menu.setVisible(1);
|
||||
}
|
||||
@@ -176,6 +179,29 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuPO> implements
|
||||
return convertToVO(menuPO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuVO> getMenuTreeByRole(String userRole) {
|
||||
// 查询所有菜单
|
||||
LambdaQueryWrapper<MenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByAsc(MenuPO::getOrder);
|
||||
|
||||
// 根据用户角色过滤菜单
|
||||
if (!"super".equals(userRole)) {
|
||||
// 非超级管理员只能看到非超级菜单
|
||||
wrapper.eq(MenuPO::getSuperMenu, 0);
|
||||
}
|
||||
|
||||
List<MenuPO> menuList = this.list(wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<MenuVO> menuVOList = menuList.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建树形结构
|
||||
return buildMenuTree(menuVOList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
*/
|
||||
|
||||
@@ -40,6 +40,7 @@ CREATE TABLE `sys_user` (
|
||||
CREATE TABLE `sys_menu` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '菜单 id',
|
||||
`parent_id` bigint unsigned DEFAULT NULL COMMENT '父菜单 id',
|
||||
`super` tinyint NOT NULL DEFAULT '0' COMMENT '是否超级菜单 (0-否 1-是)',
|
||||
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '菜单名称',
|
||||
`title` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '菜单标题',
|
||||
`path` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '路由路径',
|
||||
|
||||
@@ -5,6 +5,7 @@ export namespace MenuApi {
|
||||
export interface MenuInfo {
|
||||
id: number;
|
||||
parentId?: number;
|
||||
superMenu?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
@@ -24,6 +25,7 @@ export namespace MenuApi {
|
||||
/** 创建菜单参数 */
|
||||
export interface CreateMenuParams {
|
||||
parentId?: number;
|
||||
superMenu?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
@@ -40,6 +42,7 @@ export namespace MenuApi {
|
||||
/** 更新菜单参数 */
|
||||
export interface UpdateMenuParams {
|
||||
parentId?: number;
|
||||
superMenu?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
|
||||
@@ -7,12 +7,12 @@ const routes: RouteRecordRaw[] = [
|
||||
order: 1,
|
||||
title: '数据中台',
|
||||
},
|
||||
name: 'Ecommerce',
|
||||
path: '/ecommerce',
|
||||
name: 'Data',
|
||||
path: '/data',
|
||||
children: [
|
||||
{
|
||||
name: 'DataImport',
|
||||
path: '/data-import',
|
||||
path: '/data/import',
|
||||
component: () => import('#/views/ecommerce/data-import/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:upload',
|
||||
@@ -21,7 +21,7 @@ const routes: RouteRecordRaw[] = [
|
||||
},
|
||||
{
|
||||
name: 'DataAnalysis',
|
||||
path: '/data-analysis',
|
||||
path: '/data/analysis',
|
||||
component: () => import('#/views/ecommerce/data-analysis/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:bar-chart-3',
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref, computed } from 'vue';
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
Select,
|
||||
Table,
|
||||
Upload,
|
||||
message,
|
||||
Tag,
|
||||
@@ -16,6 +12,8 @@ import {
|
||||
Tooltip
|
||||
} from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import FileEditModal from './components/FileEditModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
@@ -67,160 +65,148 @@ const fileFormatOptions = [
|
||||
{ label: '其他', value: 'other' },
|
||||
];
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '文件名',
|
||||
dataIndex: 'filename',
|
||||
key: 'filename',
|
||||
width: 300,
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
return h('div', { style: 'display: flex; align-items: center; gap: 8px;' }, [
|
||||
h('span', { style: 'font-weight: 500;' }, record.filename),
|
||||
h(Tag, { color: 'blue', size: 'small' }, () => record.fileFormat || '未知'),
|
||||
]);
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
title: '文件名',
|
||||
minWidth: 300,
|
||||
slots: { default: 'filename' },
|
||||
},
|
||||
{
|
||||
title: '文件格式',
|
||||
minWidth: 120,
|
||||
slots: { default: 'fileFormat' },
|
||||
},
|
||||
{
|
||||
title: '标签',
|
||||
minWidth: 200,
|
||||
slots: { default: 'tags' },
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
minWidth: 200,
|
||||
slots: { default: 'remark' },
|
||||
},
|
||||
{
|
||||
field: 'uploadTime',
|
||||
title: '上传时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
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<FileDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
filename: searchForm.value.filename || undefined,
|
||||
fileFormat: searchForm.value.fileFormat || undefined,
|
||||
},
|
||||
};
|
||||
const response = await getFilePageApi(params);
|
||||
fileList.value = response.records;
|
||||
total.value = response.total;
|
||||
return {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('加载文件列表失败:', error);
|
||||
message.error('加载文件列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '文件格式',
|
||||
dataIndex: 'fileFormat',
|
||||
key: 'fileFormat',
|
||||
width: 120,
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
return h(Tag, { color: 'blue' }, () => record.fileFormat || '未知');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '标签',
|
||||
dataIndex: 'tags',
|
||||
key: 'tags',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
if (!record.tags) return h('span', { style: 'color: #999;' }, '无标签');
|
||||
const tags = record.tags.split(',').filter(tag => tag.trim());
|
||||
return h('div', { style: 'display: flex; flex-wrap: wrap; gap: 4px;' },
|
||||
tags.map(tag => h(Tag, { color: 'green', size: 'small' }, () => tag.trim()))
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
if (!record.remark) return h('span', { style: 'color: #999;' }, '无描述');
|
||||
return h(Tooltip, { title: record.remark }, {
|
||||
default: () => h('span', {
|
||||
style: 'display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'
|
||||
}, record.remark)
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '上传时间',
|
||||
dataIndex: 'uploadTime',
|
||||
key: 'uploadTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Tooltip, { title: '预览' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handlePreview(record),
|
||||
}, {
|
||||
default: () => h(EyeIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '下载' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handleDownload(record),
|
||||
}, {
|
||||
default: () => h(DownloadIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '编辑' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, {
|
||||
default: () => h(EditIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '删除' }, {
|
||||
default: () => h(Popconfirm, {
|
||||
title: '确定要删除这个文件吗?',
|
||||
onConfirm: () => handleDelete(record.id),
|
||||
}, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
danger: true,
|
||||
}, {
|
||||
default: () => h(DeleteIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
})
|
||||
}),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
// 计算属性 - 由于使用后端分页,不再需要前端过滤
|
||||
const filteredFileList = computed(() => fileList.value);
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入文件名',
|
||||
},
|
||||
fieldName: 'filename',
|
||||
label: '文件名',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择文件格式',
|
||||
options: fileFormatOptions,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'fileFormat',
|
||||
label: '文件格式',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 方法
|
||||
const loadFileList = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<FileDTO.Filters> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
filename: searchForm.value.filename || undefined,
|
||||
fileFormat: searchForm.value.fileFormat || undefined,
|
||||
}
|
||||
};
|
||||
|
||||
const response = await getFilePageApi(params);
|
||||
fileList.value = response.records;
|
||||
total.value = response.total;
|
||||
} catch (error) {
|
||||
message.error('加载文件列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
current.value = 1;
|
||||
loadFileList();
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
filename: '',
|
||||
fileFormat: undefined,
|
||||
};
|
||||
handleSearch();
|
||||
};
|
||||
current.value = 1;
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
const handleUpload = async (file: File) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await uploadFileApi(file);
|
||||
message.success('文件上传成功');
|
||||
loadFileList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
message.error('文件上传失败');
|
||||
} finally {
|
||||
@@ -233,7 +219,7 @@ const handleBatchUpload = async (files: File[]) => {
|
||||
try {
|
||||
await batchUploadFilesApi(files);
|
||||
message.success(`成功上传 ${files.length} 个文件`);
|
||||
loadFileList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
message.error('批量上传失败');
|
||||
} finally {
|
||||
@@ -261,14 +247,14 @@ const handleDelete = async (id: number) => {
|
||||
try {
|
||||
await deleteFileApi(id);
|
||||
message.success('删除成功');
|
||||
loadFileList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleEditSuccess = () => {
|
||||
loadFileList();
|
||||
refreshTable();
|
||||
};
|
||||
|
||||
// 上传配置
|
||||
@@ -293,84 +279,103 @@ const uploadProps = {
|
||||
},
|
||||
};
|
||||
|
||||
// 初始化
|
||||
loadFileList();
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '文件管理',
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<template #title>文件仓库</template>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<div class="mb-4 p-4 bg-white rounded-lg shadow-sm">
|
||||
<Form :model="searchForm" layout="inline">
|
||||
<Form.Item label="文件名">
|
||||
<Input
|
||||
v-model:value="searchForm.filename"
|
||||
placeholder="请输入文件名"
|
||||
style="width: 200px"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="文件格式">
|
||||
<Select
|
||||
v-model:value="searchForm.fileFormat"
|
||||
placeholder="请选择文件格式"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
<Page title="文件仓库" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理文件资源,支持文件上传、预览、下载和编辑
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Upload v-bind="uploadProps">
|
||||
<Button type="primary" :loading="uploadLoading">
|
||||
<UploadIcon />
|
||||
上传文件
|
||||
</Button>
|
||||
</Upload>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 文件名列 -->
|
||||
<template #filename="{ row }: { row: any }">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<span style="font-weight: 500;">{{ row.filename }}</span>
|
||||
<Tag color="blue" size="small">{{ row.fileFormat || '未知' }}</Tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 文件格式列 -->
|
||||
<template #fileFormat="{ row }: { row: any }">
|
||||
<Tag color="blue">{{ row.fileFormat || '未知' }}</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 标签列 -->
|
||||
<template #tags="{ row }: { row: any }">
|
||||
<div v-if="!row.tags" style="color: #999;">无标签</div>
|
||||
<div v-else style="display: flex; flex-wrap: wrap; gap: 4px;">
|
||||
<Tag
|
||||
v-for="tag in row.tags.split(',').filter((t: string) => t.trim())"
|
||||
:key="tag"
|
||||
color="green"
|
||||
size="small"
|
||||
>
|
||||
<Select.Option
|
||||
v-for="option in fileFormatOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
{{ tag.trim() }}
|
||||
</Tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 操作区域 -->
|
||||
<div class="mb-4 flex justify-between items-center">
|
||||
<div class="flex items-center gap-4">
|
||||
<Upload v-bind="uploadProps">
|
||||
<Button type="primary" :loading="uploadLoading">
|
||||
<UploadIcon class="w-4 h-4 mr-2" />
|
||||
上传文件
|
||||
</Button>
|
||||
</Upload>
|
||||
<span class="text-gray-500">支持批量上传,单个文件最大100MB</span>
|
||||
</div>
|
||||
<div class="text-gray-500">
|
||||
共 {{ total }} 个文件
|
||||
</div>
|
||||
</div>
|
||||
<!-- 描述列 -->
|
||||
<template #remark="{ row }: { row: any }">
|
||||
<Tooltip v-if="row.remark" :title="row.remark">
|
||||
<span style="display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
|
||||
{{ row.remark }}
|
||||
</span>
|
||||
</Tooltip>
|
||||
<span v-else style="color: #999;">无描述</span>
|
||||
</template>
|
||||
|
||||
<!-- 文件列表 -->
|
||||
<div class="bg-white rounded-lg shadow-sm">
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="filteredFileList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条,共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
:scroll="{ x: 1200 }"
|
||||
/>
|
||||
</div>
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Tooltip title="预览">
|
||||
<Button type="text" size="small" @click="handlePreview(row)">
|
||||
<EyeIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title="下载">
|
||||
<Button type="text" size="small" @click="handleDownload(row)">
|
||||
<DownloadIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title="编辑">
|
||||
<Button type="text" size="small" @click="handleEdit(row)">
|
||||
<EditIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Popconfirm title="确定要删除这个文件吗?" @confirm="handleDelete(row.id)">
|
||||
<Tooltip title="删除">
|
||||
<Button type="text" size="small" danger>
|
||||
<DeleteIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<FileEditModal
|
||||
|
||||
+263
-290
@@ -1,8 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref } from 'vue';
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Input, Select, Table, message, Tag } from 'ant-design-vue';
|
||||
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 {
|
||||
deleteCompanyApi,
|
||||
@@ -13,14 +16,13 @@ import {
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import CompanyFormModal from './components/CompanyFormModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
defineOptions({ name: 'CompanyManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const companyList = ref<CompanyVO.CompanyInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const companyFormModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
@@ -33,158 +35,203 @@ const searchForm = ref({
|
||||
expired: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 表单数据(已移至CompanyFormModal组件)
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '正常', value: 1 },
|
||||
];
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '公司名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '公司名称',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'address',
|
||||
title: '公司地址',
|
||||
minWidth: 250,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'contactPerson',
|
||||
title: '联系人',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'contactPhone',
|
||||
title: '联系电话',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'email',
|
||||
title: '邮箱',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: 'Logo',
|
||||
minWidth: 100,
|
||||
slots: { default: 'logo' },
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
title: '过期状态',
|
||||
minWidth: 100,
|
||||
slots: { default: 'expired' },
|
||||
},
|
||||
{
|
||||
title: '订阅到期时间',
|
||||
minWidth: 180,
|
||||
slots: { default: 'expireTime' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
{
|
||||
title: '公司地址',
|
||||
dataIndex: 'address',
|
||||
key: 'address',
|
||||
width: 250,
|
||||
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')[],
|
||||
},
|
||||
{
|
||||
title: '联系人',
|
||||
dataIndex: 'contactPerson',
|
||||
key: 'contactPerson',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '联系电话',
|
||||
dataIndex: 'contactPhone',
|
||||
key: 'contactPhone',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '邮箱',
|
||||
dataIndex: 'email',
|
||||
key: 'email',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: 'Logo',
|
||||
dataIndex: 'logo',
|
||||
key: 'logo',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
|
||||
if (record.logo) {
|
||||
return h('img', {
|
||||
src: record.logo,
|
||||
alt: record.name,
|
||||
style: { width: '40px', height: '40px', objectFit: 'cover', borderRadius: '4px' },
|
||||
});
|
||||
}
|
||||
return h('span', { style: { color: '#999' } }, '暂无Logo');
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<CompanyDTO.CompanyFiltersDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
contactPerson: searchForm.value.contactPerson || undefined,
|
||||
contactPhone: searchForm.value.contactPhone || undefined,
|
||||
email: searchForm.value.email || undefined,
|
||||
status: searchForm.value.status,
|
||||
expired: searchForm.value.expired === 'true' ? true : searchForm.value.expired === 'false' ? false : undefined,
|
||||
},
|
||||
};
|
||||
const data = await getCompanyPageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取公司列表失败:', error);
|
||||
message.error('获取公司列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
|
||||
const statusMap = {
|
||||
0: { text: '禁用', color: 'red' },
|
||||
1: { text: '正常', color: 'green' },
|
||||
};
|
||||
const status = statusMap[record.status as keyof typeof statusMap] || { text: '未知', color: 'default' };
|
||||
return h(Tag, { color: status.color }, () => status.text);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '过期状态',
|
||||
dataIndex: 'expired',
|
||||
key: 'expired',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
|
||||
if (record.expired === true) {
|
||||
return h(Tag, { color: 'red' }, () => '已过期');
|
||||
} else if (record.expired === false) {
|
||||
return h(Tag, { color: 'green' }, () => '正常');
|
||||
}
|
||||
return h('span', { style: { color: '#999' } }, '未知');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '订阅到期时间',
|
||||
dataIndex: 'expireTime',
|
||||
key: 'expireTime',
|
||||
width: 180,
|
||||
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
|
||||
if (!record.expireTime) {
|
||||
return h('span', { style: { color: '#999' } }, '未设置');
|
||||
}
|
||||
const isExpired = record.expired;
|
||||
return h('span', {
|
||||
style: { color: isExpired ? '#ff4d4f' : '#52c41a' },
|
||||
}, record.expireTime);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: CompanyVO.CompanyInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入公司名称',
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '公司名称',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人',
|
||||
},
|
||||
fieldName: 'contactPerson',
|
||||
label: '联系人',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系电话',
|
||||
},
|
||||
fieldName: 'contactPhone',
|
||||
label: '联系电话',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入邮箱',
|
||||
},
|
||||
fieldName: 'email',
|
||||
label: '邮箱',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: statusOptions,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择过期状态',
|
||||
options: [
|
||||
{ label: '已过期', value: 'true' },
|
||||
{ label: '正常', value: 'false' }
|
||||
],
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'expired',
|
||||
label: '过期状态',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchCompanyList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
status: undefined,
|
||||
expired: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchCompanyList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchCompanyList();
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加公司
|
||||
@@ -197,174 +244,100 @@ function handleEdit(record: CompanyVO.CompanyInfoVO) {
|
||||
companyFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 组件卸载标志
|
||||
let isUnmounted = false;
|
||||
|
||||
// 获取公司列表
|
||||
async function fetchCompanyList() {
|
||||
if (isUnmounted) return;
|
||||
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<CompanyDTO.CompanyFiltersDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
contactPerson: searchForm.value.contactPerson || undefined,
|
||||
contactPhone: searchForm.value.contactPhone || undefined,
|
||||
email: searchForm.value.email || undefined,
|
||||
status: searchForm.value.status,
|
||||
expired: searchForm.value.expired === 'true' ? true : searchForm.value.expired === 'false' ? false : undefined,
|
||||
},
|
||||
};
|
||||
const data = await getCompanyPageApi(params);
|
||||
|
||||
if (isUnmounted) return;
|
||||
|
||||
companyList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
if (isUnmounted) return;
|
||||
|
||||
console.error('获取公司列表失败:', error);
|
||||
message.error('获取公司列表失败');
|
||||
} finally {
|
||||
if (!isUnmounted) {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理删除公司
|
||||
async function handleDelete(record: CompanyVO.CompanyInfoVO) {
|
||||
try {
|
||||
await deleteCompanyApi(record.id);
|
||||
|
||||
if (isUnmounted) return;
|
||||
|
||||
message.success('删除成功');
|
||||
await fetchCompanyList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
if (isUnmounted) return;
|
||||
|
||||
console.error('删除公司失败:', error);
|
||||
message.error('删除公司失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功回调
|
||||
async function handleModalSuccess() {
|
||||
await fetchCompanyList();
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// Logo相关方法已移至CompanyFormModal组件
|
||||
|
||||
// 初始化
|
||||
fetchCompanyList();
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '公司管理',
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="公司管理">
|
||||
<Page title="公司管理" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理公司信息,包括公司基本信息、联系方式和订阅状态
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加公司
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">公司名称</label>
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入公司名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">联系人</label>
|
||||
<Input
|
||||
v-model:value="searchForm.contactPerson"
|
||||
placeholder="请输入联系人"
|
||||
style="width: 150px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">联系电话</label>
|
||||
<Input
|
||||
v-model:value="searchForm.contactPhone"
|
||||
placeholder="请输入联系电话"
|
||||
style="width: 150px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">邮箱</label>
|
||||
<Input
|
||||
v-model:value="searchForm.email"
|
||||
placeholder="请输入邮箱"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
style="width: 120px;"
|
||||
:options="statusOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">过期状态</label>
|
||||
<Select
|
||||
v-model:value="searchForm.expired"
|
||||
placeholder="请选择过期状态"
|
||||
style="width: 120px;"
|
||||
:options="[
|
||||
{ label: '已过期', value: 'true' },
|
||||
{ label: '正常', value: 'false' }
|
||||
]"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: end;">
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="companyList"
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
>
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加公司
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- Logo列 -->
|
||||
<template #logo="{ row }: { row: any }">
|
||||
<div v-if="row.logo">
|
||||
<img
|
||||
:src="row.logo"
|
||||
:alt="row.name"
|
||||
style="width: 40px; height: 40px; object-fit: cover; border-radius: 4px;"
|
||||
/>
|
||||
</div>
|
||||
<span v-else style="color: #999;">暂无Logo</span>
|
||||
</template>
|
||||
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }: { row: any }">
|
||||
<Tag :color="row.status === 1 ? 'green' : 'red'">
|
||||
{{ row.status === 1 ? '正常' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 过期状态列 -->
|
||||
<template #expired="{ row }: { row: any }">
|
||||
<Tag v-if="row.expired === true" color="red">已过期</Tag>
|
||||
<Tag v-else-if="row.expired === false" color="green">正常</Tag>
|
||||
<span v-else style="color: #999;">未知</span>
|
||||
</template>
|
||||
|
||||
<!-- 订阅到期时间列 -->
|
||||
<template #expireTime="{ row }: { row: any }">
|
||||
<span v-if="!row.expireTime" style="color: #999;">未设置</span>
|
||||
<span v-else :style="{ color: row.expired ? '#ff4d4f' : '#52c41a' }">
|
||||
{{ row.expireTime }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)">
|
||||
编辑
|
||||
</Button>
|
||||
<Button size="small" danger @click="handleDelete(row)">
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 公司表单模态框 -->
|
||||
<CompanyFormModal
|
||||
|
||||
+191
-175
@@ -1,8 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, h, ref } from 'vue';
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Input, Select, Table, message } from 'ant-design-vue';
|
||||
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 {
|
||||
deleteDepartmentApi,
|
||||
@@ -13,15 +16,15 @@ import {
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import DepartmentModal from './components/DepartmentModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
defineOptions({ name: 'DepartmentManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const departmentList = ref<DepartmentVO.DepartmentInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const departmentModalRef = ref();
|
||||
const departmentList = ref<DepartmentVO.DepartmentInfoVO[]>([]);
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
@@ -57,68 +60,100 @@ const parentDepartmentOptions = computed(() => {
|
||||
return options;
|
||||
});
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '部门名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '部门名称',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '父部门',
|
||||
minWidth: 150,
|
||||
slots: { default: 'parentDepartment' },
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '描述',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
{
|
||||
title: '父部门',
|
||||
dataIndex: 'parentId',
|
||||
key: 'parentId',
|
||||
width: 150,
|
||||
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
|
||||
if (!record.parentId) return '根部门';
|
||||
const parent = findParentDepartment(departmentList.value, record.parentId);
|
||||
return parent ? parent.name : '未知';
|
||||
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<DepartmentDTO.DepartmentFiltersDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
parentId: searchForm.value.parentId,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getDepartmentPageApi(params);
|
||||
// 更新部门列表用于父部门选项
|
||||
departmentList.value = data.records;
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取部门列表失败:', error);
|
||||
message.error('获取部门列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
|
||||
return h('span', {
|
||||
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
|
||||
}, record.status === 1 ? '启用' : '禁用');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: DepartmentVO.DepartmentInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
// 查找父部门
|
||||
function findParentDepartment(departments: DepartmentVO.DepartmentInfoVO[], parentId: number): DepartmentVO.DepartmentInfoVO | null {
|
||||
@@ -134,54 +169,50 @@ function findParentDepartment(departments: DepartmentVO.DepartmentInfoVO[], pare
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取部门列表
|
||||
async function fetchDepartmentList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<DepartmentDTO.DepartmentFiltersDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
parentId: searchForm.value.parentId,
|
||||
status: searchForm.value.status,
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入部门名称',
|
||||
},
|
||||
};
|
||||
const data = await getDepartmentPageApi(params);
|
||||
departmentList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取部门列表失败:', error);
|
||||
message.error('获取部门列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
fieldName: 'name',
|
||||
label: '部门名称',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择父部门',
|
||||
options: parentDepartmentOptions.value,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'parentId',
|
||||
label: '父部门',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: statusOptions,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchDepartmentList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
parentId: undefined,
|
||||
status: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchDepartmentList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchDepartmentList();
|
||||
}
|
||||
|
||||
// 处理添加部门
|
||||
function handleAdd() {
|
||||
departmentModalRef.value?.open(false);
|
||||
@@ -197,7 +228,7 @@ async function handleDelete(record: DepartmentVO.DepartmentInfoVO) {
|
||||
try {
|
||||
await deleteDepartmentApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchDepartmentList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除部门失败:', error);
|
||||
message.error('删除部门失败');
|
||||
@@ -205,83 +236,68 @@ async function handleDelete(record: DepartmentVO.DepartmentInfoVO) {
|
||||
}
|
||||
|
||||
// 处理模态框成功回调
|
||||
async function handleModalSuccess() {
|
||||
await fetchDepartmentList();
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
fetchDepartmentList();
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '部门管理',
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="部门管理">
|
||||
<Page title="部门管理" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理部门信息,支持层级结构,可以创建子部门
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加部门
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">部门名称</label>
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入部门名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">父部门</label>
|
||||
<Select
|
||||
v-model:value="searchForm.parentId"
|
||||
placeholder="请选择父部门"
|
||||
style="width: 200px;"
|
||||
:options="parentDepartmentOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
style="width: 120px;"
|
||||
:options="statusOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: end;">
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="departmentList"
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
>
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加部门
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 父部门列 -->
|
||||
<template #parentDepartment="{ row }: { row: any }">
|
||||
<span v-if="!row.parentId">根部门</span>
|
||||
<span v-else>
|
||||
{{ findParentDepartment(departmentList, row.parentId)?.name || '未知' }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }: { row: any }">
|
||||
<Tag :color="row.status === 1 ? 'green' : 'red'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)">
|
||||
编辑
|
||||
</Button>
|
||||
<Button size="small" danger @click="handleDelete(row)">
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 部门模态框组件 -->
|
||||
<DepartmentModal
|
||||
|
||||
+182
-169
@@ -1,8 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref } from 'vue';
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Input, Select, Table, message } from 'ant-design-vue';
|
||||
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 {
|
||||
deletePositionApi,
|
||||
@@ -13,14 +16,13 @@ import {
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import PositionModal from './components/PositionModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
defineOptions({ name: 'PositionManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const positionList = ref<PositionVO.PositionInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const positionModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
@@ -43,121 +45,137 @@ const departmentOptions = ref([
|
||||
{ label: '市场部', value: 4 },
|
||||
]);
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '岗位名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '岗位编码',
|
||||
dataIndex: 'code',
|
||||
key: 'code',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '所属部门',
|
||||
dataIndex: 'departmentId',
|
||||
key: 'departmentId',
|
||||
width: 150,
|
||||
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
|
||||
if (!record.departmentId) return '-';
|
||||
const dept = departmentOptions.value.find(d => d.value === record.departmentId);
|
||||
return dept ? dept.label : '未知部门';
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
|
||||
return h('span', {
|
||||
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
|
||||
}, record.status === 1 ? '启用' : '禁用');
|
||||
{
|
||||
field: 'name',
|
||||
title: '岗位名称',
|
||||
minWidth: 150,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: PositionVO.PositionInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
{
|
||||
field: 'code',
|
||||
title: '岗位编码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
title: '所属部门',
|
||||
minWidth: 150,
|
||||
slots: { default: 'department' },
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '描述',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
];
|
||||
|
||||
// 获取岗位列表
|
||||
async function fetchPositionList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<PositionDTO.PositionFiltersDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
status: searchForm.value.status,
|
||||
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<PositionDTO.PositionFiltersDTO> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getPositionPageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取岗位列表失败:', error);
|
||||
message.error('获取岗位列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
};
|
||||
const data = await getPositionPageApi(params);
|
||||
positionList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取岗位列表失败:', error);
|
||||
message.error('获取岗位列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入岗位名称',
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '岗位名称',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: statusOptions,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchPositionList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
status: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchPositionList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchPositionList();
|
||||
}
|
||||
|
||||
// 处理添加岗位
|
||||
function handleAdd() {
|
||||
positionModalRef.value?.open(false);
|
||||
@@ -173,7 +191,7 @@ async function handleDelete(record: PositionVO.PositionInfoVO) {
|
||||
try {
|
||||
await deletePositionApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchPositionList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除岗位失败:', error);
|
||||
message.error('删除岗位失败');
|
||||
@@ -181,73 +199,68 @@ async function handleDelete(record: PositionVO.PositionInfoVO) {
|
||||
}
|
||||
|
||||
// 处理模态框成功回调
|
||||
async function handleModalSuccess() {
|
||||
await fetchPositionList();
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
fetchPositionList();
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '岗位管理',
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="岗位管理">
|
||||
<Page title="岗位管理" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理岗位信息,包括岗位名称、编码、所属部门和描述
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加岗位
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<div style="display: flex; gap: 16px; align-items: center; flex-wrap: wrap;">
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">岗位名称</label>
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入岗位名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; margin-bottom: 4px; font-weight: 500;">状态</label>
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
style="width: 120px;"
|
||||
:options="statusOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: end;">
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="positionList"
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
>
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加岗位
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 所属部门列 -->
|
||||
<template #department="{ row }: { row: any }">
|
||||
<span v-if="!row.departmentId">-</span>
|
||||
<span v-else>
|
||||
{{ departmentOptions.find(d => d.value === row.departmentId)?.label || '未知部门' }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }: { row: any }">
|
||||
<Tag :color="row.status === 1 ? 'green' : 'red'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)">
|
||||
编辑
|
||||
</Button>
|
||||
<Button size="small" danger @click="handleDelete(row)">
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 岗位模态框组件 -->
|
||||
<PositionModal
|
||||
|
||||
@@ -1,144 +1,182 @@
|
||||
<template>
|
||||
<Page>
|
||||
<template #title>商品管理</template>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<div class="mb-4 p-4 bg-white rounded-lg shadow-sm">
|
||||
<Form :model="searchForm" layout="inline">
|
||||
<Form.Item label="商品名称">
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入商品名称"
|
||||
style="width: 200px"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品编码">
|
||||
<Input
|
||||
v-model:value="searchForm.specCode"
|
||||
placeholder="请输入商品编码"
|
||||
style="width: 150px"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品SKU">
|
||||
<Input
|
||||
v-model:value="searchForm.skuCode"
|
||||
placeholder="请输入商品SKU"
|
||||
style="width: 150px"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="成本价范围">
|
||||
<div class="flex items-center gap-2">
|
||||
<InputNumber
|
||||
v-model:value="searchForm.minCostPrice"
|
||||
placeholder="最小值"
|
||||
style="width: 100px"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
<span class="text-gray-500">-</span>
|
||||
<InputNumber
|
||||
v-model:value="searchForm.maxCostPrice"
|
||||
placeholder="最大值"
|
||||
style="width: 100px"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 操作区域 -->
|
||||
<div class="mb-4 flex justify-between items-center">
|
||||
<div class="flex items-center gap-4">
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="w-4 h-4 mr-2" />
|
||||
添加商品
|
||||
</Button>
|
||||
<span class="text-gray-500">支持商品和规格的一键创建</span>
|
||||
<Page title="商品管理" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理商品信息,支持商品和规格的一键创建,提供网格和列表两种视图模式
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button
|
||||
:type="viewMode === 'grid' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
@click="viewMode = 'grid'"
|
||||
>
|
||||
<GridIcon class="w-4 h-4 mr-2" />
|
||||
网格视图
|
||||
</Button>
|
||||
<Button
|
||||
:type="viewMode === 'table' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
@click="viewMode = 'table'"
|
||||
>
|
||||
<ListIcon class="w-4 h-4 mr-2" />
|
||||
列表视图
|
||||
</Button>
|
||||
<span class="text-gray-500">
|
||||
共 {{ total }} 个商品
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 列表视图 -->
|
||||
<div v-if="viewMode === 'table'" class="bg-white rounded-lg shadow-sm">
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="productList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
</div>
|
||||
<!-- 列表视图 -->
|
||||
<Grid v-if="viewMode === 'table'" :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加商品
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 主图列 -->
|
||||
<template #mainImage="{ row }: { row: any }">
|
||||
<div v-if="row.mainImage">
|
||||
<img
|
||||
:src="row.mainImage"
|
||||
:alt="row.name"
|
||||
style="width: 40px; height: 40px; object-fit: cover; border-radius: 4px;"
|
||||
/>
|
||||
</div>
|
||||
<span v-else style="color: #999;">暂无图片</span>
|
||||
</template>
|
||||
|
||||
<!-- 规格数量列 -->
|
||||
<template #specs="{ row }: { row: any }">
|
||||
<Tag :color="(row.specs?.length || 0) > 0 ? 'blue' : 'default'">
|
||||
{{ row.specs?.length || 0 }} 个规格
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)">
|
||||
编辑
|
||||
</Button>
|
||||
<Button size="small" @click="handleManageSpecs(row)">
|
||||
规格
|
||||
</Button>
|
||||
<Button size="small" danger @click="handleDelete(row)">
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 网格视图 -->
|
||||
<div v-if="viewMode === 'grid'" class="bg-white rounded-lg shadow-sm p-4">
|
||||
<Row :gutter="[16, 16]">
|
||||
<Col
|
||||
v-for="product in productList"
|
||||
:key="product.id"
|
||||
:xs="12"
|
||||
:sm="8"
|
||||
:md="6"
|
||||
:lg="4"
|
||||
:xl="3"
|
||||
>
|
||||
<ProductCard
|
||||
:product="product"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@manage-specs="handleManageSpecs"
|
||||
@view-details="handleViewDetails"
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<div v-if="viewMode === 'grid'">
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-white rounded-lg shadow-sm">
|
||||
<Form :model="searchForm" layout="inline">
|
||||
<Form.Item label="商品名称">
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入商品名称"
|
||||
style="width: 200px"
|
||||
@press-enter="refreshTable"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品编码">
|
||||
<Input
|
||||
v-model:value="searchForm.specCode"
|
||||
placeholder="请输入商品编码"
|
||||
style="width: 150px"
|
||||
@press-enter="refreshTable"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品SKU">
|
||||
<Input
|
||||
v-model:value="searchForm.skuCode"
|
||||
placeholder="请输入商品SKU"
|
||||
style="width: 150px"
|
||||
@press-enter="refreshTable"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="成本价范围">
|
||||
<div class="flex items-center gap-2">
|
||||
<InputNumber
|
||||
v-model:value="searchForm.minCostPrice"
|
||||
placeholder="最小值"
|
||||
style="width: 100px"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
<span class="text-gray-500">-</span>
|
||||
<InputNumber
|
||||
v-model:value="searchForm.maxCostPrice"
|
||||
placeholder="最大值"
|
||||
style="width: 100px"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" @click="refreshTable">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 工具栏 -->
|
||||
<div class="mb-4 flex justify-between items-center">
|
||||
<div class="flex items-center gap-4">
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="w-4 h-4 mr-2" />
|
||||
添加商品
|
||||
</Button>
|
||||
<span class="text-gray-500">支持商品和规格的一键创建</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-gray-500">共 {{ total }} 个商品</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="mt-4 flex justify-center">
|
||||
<Pagination
|
||||
v-model:current="current"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
:show-size-changer="true"
|
||||
:show-quick-jumper="true"
|
||||
:show-total="(total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
<!-- 网格内容 -->
|
||||
<div class="bg-white rounded-lg shadow-sm p-4">
|
||||
<Row :gutter="[16, 16]">
|
||||
<Col
|
||||
v-for="product in productList"
|
||||
:key="product.id"
|
||||
:xs="12"
|
||||
:sm="8"
|
||||
:md="6"
|
||||
:lg="4"
|
||||
:xl="3"
|
||||
>
|
||||
<ProductCard
|
||||
:product="product"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@manage-specs="handleManageSpecs"
|
||||
@view-details="handleViewDetails"
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="mt-4 flex justify-center">
|
||||
<Pagination
|
||||
v-model:current="current"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
:show-size-changer="true"
|
||||
:show-quick-jumper="true"
|
||||
:show-total="(total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -157,11 +195,13 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { h, ref } from 'vue';
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Input, InputNumber, Table, message, Row, Col, Pagination, Form, Space, Tag } from 'ant-design-vue';
|
||||
import { Button, message, Space, Tag, Row, Col, Pagination, Form, Input, InputNumber } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import {
|
||||
deleteProductApi,
|
||||
@@ -200,107 +240,162 @@ const searchForm = ref({
|
||||
maxCostPrice: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '商品名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '主图',
|
||||
dataIndex: 'mainImage',
|
||||
key: 'mainImage',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: ProductVO.Info }) => {
|
||||
if (record.mainImage) {
|
||||
return h('img', {
|
||||
src: record.mainImage,
|
||||
alt: record.name,
|
||||
style: { width: '40px', height: '40px', objectFit: 'cover', borderRadius: '4px' },
|
||||
});
|
||||
}
|
||||
return h('span', { style: { color: '#999' } }, '暂无图片');
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '规格数量',
|
||||
dataIndex: 'specs',
|
||||
key: 'specs',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: ProductVO.Info }) => {
|
||||
const specCount = record.specs?.length || 0;
|
||||
return h(Tag, { color: specCount > 0 ? 'blue' : 'default' }, () => `${specCount} 个规格`);
|
||||
{
|
||||
field: 'name',
|
||||
title: '商品名称',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '更新时间',
|
||||
dataIndex: 'updateTime',
|
||||
key: 'updateTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: ProductVO.Info }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, { default: () => '编辑' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleManageSpecs(record),
|
||||
}, { default: () => '规格' }),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, { default: () => '删除' }),
|
||||
]);
|
||||
{
|
||||
title: '主图',
|
||||
minWidth: 100,
|
||||
slots: { default: 'mainImage' },
|
||||
},
|
||||
{
|
||||
title: '规格数量',
|
||||
minWidth: 100,
|
||||
slots: { default: 'specs' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'updateTime',
|
||||
title: '更新时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
];
|
||||
|
||||
// 获取商品列表
|
||||
async function fetchProductList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<ProductDTO.Filters> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
specCode: searchForm.value.specCode || undefined,
|
||||
skuCode: searchForm.value.skuCode || undefined,
|
||||
minCostPrice: searchForm.value.minCostPrice,
|
||||
maxCostPrice: searchForm.value.maxCostPrice,
|
||||
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<ProductDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
specCode: searchForm.value.specCode || undefined,
|
||||
skuCode: searchForm.value.skuCode || undefined,
|
||||
minCostPrice: searchForm.value.minCostPrice,
|
||||
maxCostPrice: searchForm.value.maxCostPrice,
|
||||
},
|
||||
};
|
||||
const data = await getProductPageApi(params);
|
||||
productList.value = data.records;
|
||||
total.value = data.total;
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取商品列表失败:', error);
|
||||
message.error('获取商品列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
};
|
||||
const data = await getProductPageApi(params);
|
||||
productList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取商品列表失败:', error);
|
||||
message.error('获取商品列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchProductList();
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品名称',
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '商品名称',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品编码',
|
||||
},
|
||||
fieldName: 'specCode',
|
||||
label: '商品编码',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品SKU',
|
||||
},
|
||||
fieldName: 'skuCode',
|
||||
label: '商品SKU',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '最小值',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'minCostPrice',
|
||||
label: '成本价最小值',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '最大值',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'maxCostPrice',
|
||||
label: '成本价最大值',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
@@ -313,20 +408,16 @@ function handleReset() {
|
||||
maxCostPrice: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchProductList();
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchProductList();
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 切换视图模式
|
||||
function toggleViewMode() {
|
||||
viewMode.value = viewMode.value === 'table' ? 'grid' : 'table';
|
||||
}
|
||||
|
||||
// 处理添加商品
|
||||
function handleAdd() {
|
||||
@@ -343,7 +434,7 @@ async function handleDelete(record: ProductVO.Info) {
|
||||
try {
|
||||
await deleteProductApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchProductList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除商品失败:', error);
|
||||
message.error('删除商品失败');
|
||||
@@ -363,18 +454,22 @@ function handleViewDetails() {
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
fetchProductList();
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 处理规格模态框成功
|
||||
function handleSpecModalSuccess() {
|
||||
// 规格管理成功后可能需要刷新商品列表
|
||||
fetchProductList();
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
|
||||
// 初始化
|
||||
fetchProductList();
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '商品管理',
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
+22
-4
@@ -32,6 +32,14 @@
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="超级菜单" name="superMenu">
|
||||
<Select
|
||||
v-model:value="formData.superMenu"
|
||||
placeholder="请选择是否为超级菜单"
|
||||
:options="superMenuOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="菜单名称" name="name" :rules="[{ required: true, message: '请输入菜单名称' }]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入菜单名称" />
|
||||
</Form.Item>
|
||||
@@ -135,7 +143,8 @@ const formRef = ref();
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<MenuApiType.CreateMenuParams>({
|
||||
parentId: 0,
|
||||
parentId: undefined,
|
||||
superMenu: 0,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
@@ -169,6 +178,12 @@ const keepAliveOptions = [
|
||||
{ label: '缓存', value: 1 },
|
||||
]
|
||||
|
||||
// 超级菜单选项
|
||||
const superMenuOptions = [
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
]
|
||||
|
||||
// 下拉选项数据
|
||||
const parentMenuOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
@@ -187,7 +202,7 @@ const iconSelectorContent = h(IconSelector, {
|
||||
async function fetchParentMenuOptions() {
|
||||
try {
|
||||
const data = await getAllMenusApi();
|
||||
const options: Array<{ label: string; value: number }> = [{ label: '根菜单', value: 0 }];
|
||||
const options: Array<{ label: string; value: number }> = [];
|
||||
|
||||
const addMenuOptions = (menus: MenuApiType.MenuInfo[], level = 0) => {
|
||||
menus.forEach(menu => {
|
||||
@@ -218,7 +233,8 @@ function open(edit: boolean, record?: MenuApiType.MenuInfo) {
|
||||
if (edit && record) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
parentId: record.parentId || 0,
|
||||
parentId: record.parentId || undefined,
|
||||
superMenu: record.superMenu || 0,
|
||||
name: record.name,
|
||||
title: record.title || '',
|
||||
path: record.path || '',
|
||||
@@ -235,6 +251,7 @@ function open(edit: boolean, record?: MenuApiType.MenuInfo) {
|
||||
// 添加下级菜单模式,自动选中父菜单
|
||||
formData.value = {
|
||||
parentId: record.id, // 自动设置为当前菜单的ID作为父菜单
|
||||
superMenu: 0,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
@@ -250,7 +267,8 @@ function open(edit: boolean, record?: MenuApiType.MenuInfo) {
|
||||
} else {
|
||||
// 新增根菜单模式,重置表单
|
||||
formData.value = {
|
||||
parentId: 0,
|
||||
parentId: undefined,
|
||||
superMenu: 0,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
|
||||
Reference in New Issue
Block a user