mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 00:29:19 +08:00
Compare commits
3
Commits
abe75f87aa
..
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e183ed7a6 | ||
|
|
2f60efb8ef | ||
|
|
fb05b47d46 |
@@ -17,20 +17,20 @@ async def load_tools_for_turn(
|
|||||||
scene: str = SCENE_GENERAL,
|
scene: str = SCENE_GENERAL,
|
||||||
client_tools: list[Any] | None = None,
|
client_tools: list[Any] | None = None,
|
||||||
) -> list[Any]:
|
) -> list[Any]:
|
||||||
"""general:builtin + memory + 全部 MCP;发布场景:builtin + 目录/拼多多 MCP + 前端 ui_ 工具。"""
|
"""各场景均挂 memory_*;general 全量 MCP,发布场景仅目录/拼多多 + 前端 ui_。"""
|
||||||
from agent.tools.builtin import builtin_tools
|
from agent.tools.builtin import builtin_tools
|
||||||
from agent.tools.memory import memory_tools
|
from agent.tools.memory import memory_tools
|
||||||
from infrastructure.mcp.client import load_mcp_tools
|
from infrastructure.mcp.client import load_mcp_tools
|
||||||
|
|
||||||
scene_value = (scene or SCENE_GENERAL).strip() or SCENE_GENERAL
|
scene_value = (scene or SCENE_GENERAL).strip() or SCENE_GENERAL
|
||||||
tools: list[Any] = [*builtin_tools()]
|
tools: list[Any] = [*builtin_tools(), *memory_tools(memory, actor)]
|
||||||
|
|
||||||
if scene_value == SCENE_ECOM_GOODS_PUBLISH:
|
|
||||||
mcp_tools = await load_mcp_tools(
|
mcp_tools = await load_mcp_tools(
|
||||||
settings,
|
settings,
|
||||||
company_id=actor.company_id,
|
company_id=actor.company_id,
|
||||||
user_id=actor.user_id,
|
user_id=actor.user_id,
|
||||||
)
|
)
|
||||||
|
if scene_value == SCENE_ECOM_GOODS_PUBLISH:
|
||||||
# 发布场景:目录 + 拼多多渠道;不挂经营 BI
|
# 发布场景:目录 + 拼多多渠道;不挂经营 BI
|
||||||
mcp_tools = [
|
mcp_tools = [
|
||||||
t
|
t
|
||||||
@@ -42,15 +42,6 @@ async def load_tools_for_turn(
|
|||||||
tools.extend(client_tools)
|
tools.extend(client_tools)
|
||||||
return tools
|
return tools
|
||||||
|
|
||||||
tools.extend(memory_tools(memory, actor))
|
|
||||||
mcp_tools = await load_mcp_tools(
|
|
||||||
settings, company_id=actor.company_id, user_id=actor.user_id
|
|
||||||
)
|
|
||||||
tools.extend(mcp_tools)
|
|
||||||
if client_tools:
|
|
||||||
tools.extend(client_tools)
|
|
||||||
return tools
|
|
||||||
|
|
||||||
|
|
||||||
def _tool_name(tool: Any) -> str:
|
def _tool_name(tool: Any) -> str:
|
||||||
return str(getattr(tool, "name", None) or "")
|
return str(getattr(tool, "name", None) or "")
|
||||||
|
|||||||
@@ -87,9 +87,7 @@ class ChatService:
|
|||||||
session.llm_response_chain = None
|
session.llm_response_chain = None
|
||||||
await self._session_repo.update(session)
|
await self._session_repo.update(session)
|
||||||
|
|
||||||
just_saved = None
|
# 各 scene 均可按需 memory_*;显式「记住」也会 maybe_capture
|
||||||
memory_count = 0
|
|
||||||
if scene == "general":
|
|
||||||
just_saved = await self._memory.maybe_capture_from_user(
|
just_saved = await self._memory.maybe_capture_from_user(
|
||||||
actor, thread_id=thread_id, text=text
|
actor, thread_id=thread_id, text=text
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -57,9 +57,28 @@ _PUBLISH_SYSTEM = (
|
|||||||
"不要复述工具名、回执原文、字数统计、查了几条、竞品标题全文或改写策略,除非用户问为什么这样改。"
|
"不要复述工具名、回执原文、字数统计、查了几条、竞品标题全文或改写策略,除非用户问为什么这样改。"
|
||||||
"不要主动列 SKU 编码表,不要给没问过的下一版备选,不要让用户刷新、核对,或说「如果还是旧的再告诉我」。"
|
"不要主动列 SKU 编码表,不要给没问过的下一版备选,不要让用户刷新、核对,或说「如果还是旧的再告诉我」。"
|
||||||
"禁止向用户索要或复述数字 ID。"
|
"禁止向用户索要或复述数字 ID。"
|
||||||
|
"【长期记忆】跨会话用户级记忆不自动注入;标题口径、常用规格写法、用户偏好等需要时:"
|
||||||
|
"先 memory_search,必要时 memory_load;用户要求记住用 memory_save。"
|
||||||
|
"改表仍以当前表单与用户本轮指令为准,记忆只作补充,勿用旧记忆覆盖用户刚说的写法。"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _append_memory_status(
|
||||||
|
system: str,
|
||||||
|
*,
|
||||||
|
memory_count: int,
|
||||||
|
memory_just_saved: str | None,
|
||||||
|
) -> str:
|
||||||
|
if memory_count > 0:
|
||||||
|
system += (
|
||||||
|
f"\n\n当前用户约有 {memory_count} 条长期记忆,"
|
||||||
|
"需要时用 memory_search / memory_load。"
|
||||||
|
)
|
||||||
|
if memory_just_saved:
|
||||||
|
system += f"\n\n【本轮已写入长期记忆】{memory_just_saved}"
|
||||||
|
return system
|
||||||
|
|
||||||
|
|
||||||
def build_system_prompt(
|
def build_system_prompt(
|
||||||
*,
|
*,
|
||||||
memory_count: int = 0,
|
memory_count: int = 0,
|
||||||
@@ -73,16 +92,15 @@ def build_system_prompt(
|
|||||||
# 控制体积,避免拖垮上下文
|
# 控制体积,避免拖垮上下文
|
||||||
if len(snap_text) > 12000:
|
if len(snap_text) > 12000:
|
||||||
snap_text = snap_text[:12000] + "…(截断)"
|
snap_text = snap_text[:12000] + "…(截断)"
|
||||||
return (
|
system = f"{_PUBLISH_SYSTEM}\n\n【当前发布表单】\n{snap_text}"
|
||||||
f"{_PUBLISH_SYSTEM}\n\n【当前发布表单】\n{snap_text}"
|
return _append_memory_status(
|
||||||
|
system,
|
||||||
|
memory_count=memory_count,
|
||||||
|
memory_just_saved=memory_just_saved,
|
||||||
)
|
)
|
||||||
|
|
||||||
system = _BASE_SYSTEM
|
return _append_memory_status(
|
||||||
if memory_count > 0:
|
_BASE_SYSTEM,
|
||||||
system += (
|
memory_count=memory_count,
|
||||||
f"\n\n当前用户约有 {memory_count} 条长期记忆,"
|
memory_just_saved=memory_just_saved,
|
||||||
"需要时用 memory_search / memory_load。"
|
|
||||||
)
|
)
|
||||||
if memory_just_saved:
|
|
||||||
system += f"\n\n【本轮已写入长期记忆】{memory_just_saved}"
|
|
||||||
return system
|
|
||||||
|
|||||||
+6
-4
@@ -60,15 +60,17 @@ public class DepartmentController {
|
|||||||
|
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
@RequirePermission(value = "org:department:read", description = "查询全部部门", allowSuper = true)
|
@RequirePermission(value = "org:department:read", description = "查询全部部门", allowSuper = true)
|
||||||
public ApiResponse<List<DepartmentVO>> getAllDepartments() {
|
public ApiResponse<List<DepartmentVO>> getAllDepartments(
|
||||||
List<DepartmentVO> result = departmentService.getAllDepartments();
|
@RequestParam(required = false) Long companyId) {
|
||||||
|
List<DepartmentVO> result = departmentService.getAllDepartments(companyId);
|
||||||
return ApiResponse.success("获取全部部门成功", result);
|
return ApiResponse.success("获取全部部门成功", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/tree")
|
@GetMapping("/tree")
|
||||||
@RequirePermission(value = "org:department:read", description = "查询部门树", allowSuper = true)
|
@RequirePermission(value = "org:department:read", description = "查询部门树", allowSuper = true)
|
||||||
public ApiResponse<List<DepartmentVO>> getDepartmentTree() {
|
public ApiResponse<List<DepartmentVO>> getDepartmentTree(
|
||||||
List<DepartmentVO> result = departmentService.getDepartmentTree();
|
@RequestParam(required = false) Long companyId) {
|
||||||
|
List<DepartmentVO> result = departmentService.getDepartmentTree(companyId);
|
||||||
return ApiResponse.success("获取部门树成功", result);
|
return ApiResponse.success("获取部门树成功", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -22,4 +22,9 @@ public class DepartmentFilterDTO {
|
|||||||
* 状态
|
* 状态
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司ID(仅超管可跨公司查询)
|
||||||
|
*/
|
||||||
|
private Long companyId;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
@@ -55,6 +55,14 @@ public interface DepartmentService extends IService<DepartmentPO> {
|
|||||||
*/
|
*/
|
||||||
List<DepartmentVO> getAllDepartments();
|
List<DepartmentVO> getAllDepartments();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定公司全部部门(companyId 为空则取当前公司;跨公司仅超管)
|
||||||
|
*
|
||||||
|
* @param companyId 公司ID,可空
|
||||||
|
* @return 部门列表
|
||||||
|
*/
|
||||||
|
List<DepartmentVO> getAllDepartments(Long companyId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前公司部门树
|
* 获取当前公司部门树
|
||||||
*
|
*
|
||||||
@@ -62,6 +70,14 @@ public interface DepartmentService extends IService<DepartmentPO> {
|
|||||||
*/
|
*/
|
||||||
List<DepartmentVO> getDepartmentTree();
|
List<DepartmentVO> getDepartmentTree();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定公司部门树(companyId 为空则取当前公司;跨公司仅超管)
|
||||||
|
*
|
||||||
|
* @param companyId 公司ID,可空
|
||||||
|
* @return 部门树
|
||||||
|
*/
|
||||||
|
List<DepartmentVO> getDepartmentTree(Long companyId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为指定公司创建部门(用于初始化)
|
* 为指定公司创建部门(用于初始化)
|
||||||
*
|
*
|
||||||
|
|||||||
+35
-20
@@ -158,6 +158,19 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
this.removeById(id);
|
this.removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析查询用公司ID:超管可传 companyId 跨公司;否则强制当前公司。
|
||||||
|
*/
|
||||||
|
private Long resolveCompanyId(Long requestedCompanyId) {
|
||||||
|
if (requestedCompanyId == null) {
|
||||||
|
return currentUserContext.getCurrentCompanyId();
|
||||||
|
}
|
||||||
|
if (!currentUserContext.isCurrentUserSuper()) {
|
||||||
|
throw new BusinessException("无权跨公司查询部门");
|
||||||
|
}
|
||||||
|
return requestedCompanyId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取部门分页列表
|
* 获取部门分页列表
|
||||||
* @param pageQueryDTO 分页查询DTO
|
* @param pageQueryDTO 分页查询DTO
|
||||||
@@ -165,14 +178,11 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageResultVO<DepartmentVO> getDepartmentPage(PageQueryDTO<DepartmentFilterDTO> pageQueryDTO) {
|
public PageResultVO<DepartmentVO> getDepartmentPage(PageQueryDTO<DepartmentFilterDTO> pageQueryDTO) {
|
||||||
// 从token中获取公司ID
|
DepartmentFilterDTO queryDTO = pageQueryDTO.getFilters();
|
||||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
Long companyId = resolveCompanyId(queryDTO != null ? queryDTO.getCompanyId() : null);
|
||||||
|
|
||||||
// 构建查询条件
|
|
||||||
LambdaQueryWrapper<DepartmentPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<DepartmentPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
// 添加过滤条件
|
|
||||||
DepartmentFilterDTO queryDTO = pageQueryDTO.getFilters();
|
|
||||||
if (queryDTO != null) {
|
if (queryDTO != null) {
|
||||||
if (queryDTO.getName() != null && StringUtils.hasText(queryDTO.getName())) {
|
if (queryDTO.getName() != null && StringUtils.hasText(queryDTO.getName())) {
|
||||||
wrapper.like(DepartmentPO::getName, queryDTO.getName());
|
wrapper.like(DepartmentPO::getName, queryDTO.getName());
|
||||||
@@ -184,37 +194,36 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
wrapper.eq(DepartmentPO::getStatus, queryDTO.getStatus());
|
wrapper.eq(DepartmentPO::getStatus, queryDTO.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 强制添加公司ID过滤条件
|
|
||||||
wrapper.eq(DepartmentPO::getCompanyId, companyId);
|
wrapper.eq(DepartmentPO::getCompanyId, companyId);
|
||||||
|
|
||||||
// 排序
|
|
||||||
wrapper.orderByAsc(DepartmentPO::getCreateTime);
|
wrapper.orderByAsc(DepartmentPO::getCreateTime);
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
Page<DepartmentPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
Page<DepartmentPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||||
IPage<DepartmentPO> pageResult = this.page(page, wrapper);
|
IPage<DepartmentPO> pageResult = this.page(page, wrapper);
|
||||||
|
|
||||||
// 转换为VO
|
|
||||||
List<DepartmentVO> records = pageResult.getRecords().stream()
|
List<DepartmentVO> records = pageResult.getRecords().stream()
|
||||||
.map(this::convertToVO)
|
.map(this::convertToVO)
|
||||||
.toList();
|
.toList();
|
||||||
PageResultVO<DepartmentVO> result = PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(),
|
return PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(),
|
||||||
pageQueryDTO.getPageSize());
|
pageQueryDTO.getPageSize());
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前公司全部部门
|
* 获取当前公司全部部门
|
||||||
*
|
|
||||||
* @return 部门列表
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<DepartmentVO> getAllDepartments() {
|
public List<DepartmentVO> getAllDepartments() {
|
||||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
return getAllDepartments(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定公司全部部门
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<DepartmentVO> getAllDepartments(Long companyId) {
|
||||||
|
Long resolvedCompanyId = resolveCompanyId(companyId);
|
||||||
|
|
||||||
LambdaQueryWrapper<DepartmentPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<DepartmentPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(DepartmentPO::getCompanyId, companyId)
|
wrapper.eq(DepartmentPO::getCompanyId, resolvedCompanyId)
|
||||||
.orderByAsc(DepartmentPO::getCreateTime);
|
.orderByAsc(DepartmentPO::getCreateTime);
|
||||||
|
|
||||||
return this.list(wrapper).stream()
|
return this.list(wrapper).stream()
|
||||||
@@ -224,12 +233,18 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前公司部门树
|
* 获取当前公司部门树
|
||||||
*
|
|
||||||
* @return 部门树
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<DepartmentVO> getDepartmentTree() {
|
public List<DepartmentVO> getDepartmentTree() {
|
||||||
List<DepartmentVO> allDepartments = getAllDepartments();
|
return getDepartmentTree(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定公司部门树
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<DepartmentVO> getDepartmentTree(Long companyId) {
|
||||||
|
List<DepartmentVO> allDepartments = getAllDepartments(companyId);
|
||||||
if (allDepartments.isEmpty()) {
|
if (allDepartments.isEmpty()) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -17,4 +17,9 @@ public class PositionFilterDTO {
|
|||||||
* 状态
|
* 状态
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司ID(仅超管可跨公司查询)
|
||||||
|
*/
|
||||||
|
private Long companyId;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-13
@@ -147,6 +147,19 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
|
|||||||
this.removeById(id);
|
this.removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析查询用公司ID:超管可传 companyId 跨公司;否则强制当前公司。
|
||||||
|
*/
|
||||||
|
private Long resolveCompanyId(Long requestedCompanyId) {
|
||||||
|
if (requestedCompanyId == null) {
|
||||||
|
return currentUserContext.getCurrentCompanyId();
|
||||||
|
}
|
||||||
|
if (!currentUserContext.isCurrentUserSuper()) {
|
||||||
|
throw new BusinessException("无权跨公司查询岗位");
|
||||||
|
}
|
||||||
|
return requestedCompanyId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取岗位分页列表
|
* 获取岗位分页列表
|
||||||
* @param pageQueryDTO 分页查询DTO
|
* @param pageQueryDTO 分页查询DTO
|
||||||
@@ -154,14 +167,11 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageResultVO<PositionVO> getPositionPage(PageQueryDTO<PositionFilterDTO> pageQueryDTO) {
|
public PageResultVO<PositionVO> getPositionPage(PageQueryDTO<PositionFilterDTO> pageQueryDTO) {
|
||||||
// 从token中获取公司ID
|
PositionFilterDTO queryDTO = pageQueryDTO.getFilters();
|
||||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
Long companyId = resolveCompanyId(queryDTO != null ? queryDTO.getCompanyId() : null);
|
||||||
|
|
||||||
// 构建查询条件
|
|
||||||
LambdaQueryWrapper<PositionPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<PositionPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
// 添加过滤条件
|
|
||||||
PositionFilterDTO queryDTO = pageQueryDTO.getFilters();
|
|
||||||
if (queryDTO != null) {
|
if (queryDTO != null) {
|
||||||
if (queryDTO.getName() != null && StringUtils.hasText(queryDTO.getName())) {
|
if (queryDTO.getName() != null && StringUtils.hasText(queryDTO.getName())) {
|
||||||
wrapper.like(PositionPO::getName, queryDTO.getName());
|
wrapper.like(PositionPO::getName, queryDTO.getName());
|
||||||
@@ -170,24 +180,17 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
|
|||||||
wrapper.eq(PositionPO::getStatus, queryDTO.getStatus());
|
wrapper.eq(PositionPO::getStatus, queryDTO.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 强制添加公司ID过滤条件
|
|
||||||
wrapper.eq(PositionPO::getCompanyId, companyId);
|
wrapper.eq(PositionPO::getCompanyId, companyId);
|
||||||
|
|
||||||
// 排序
|
|
||||||
wrapper.orderByAsc(PositionPO::getCreateTime);
|
wrapper.orderByAsc(PositionPO::getCreateTime);
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
Page<PositionPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
Page<PositionPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||||
IPage<PositionPO> pageResult = this.page(page, wrapper);
|
IPage<PositionPO> pageResult = this.page(page, wrapper);
|
||||||
|
|
||||||
// 转换为VO
|
|
||||||
List<PositionVO> records = pageResult.getRecords().stream()
|
List<PositionVO> records = pageResult.getRecords().stream()
|
||||||
.map(this::convertToVO)
|
.map(this::convertToVO)
|
||||||
.toList();
|
.toList();
|
||||||
PageResultVO<PositionVO> result = PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(),
|
return PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(),
|
||||||
pageQueryDTO.getPageSize());
|
pageQueryDTO.getPageSize());
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ public class CreateSysAccountDTO {
|
|||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@NotBlank(message = "密码不能为空")
|
@NotBlank(message = "密码不能为空")
|
||||||
@Size(min = 8, max = 20, message = "密码长度必须在8-20个字符之间")
|
@Size(min = 6, max = 20, message = "密码长度必须在6-20个字符之间")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotBlank(message = "用户姓名不能为空")
|
@NotBlank(message = "用户姓名不能为空")
|
||||||
|
|||||||
@@ -53,15 +53,19 @@ export async function deleteDepartmentApi(id: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部部门
|
* 获取全部部门(超管可传 companyId 跨公司)
|
||||||
*/
|
*/
|
||||||
export async function getAllDepartmentsApi() {
|
export async function getAllDepartmentsApi(companyId?: number) {
|
||||||
return requestClient.get<DepartmentVO.DepartmentInfoVO[]>('/department/all');
|
return requestClient.get<DepartmentVO.DepartmentInfoVO[]>('/department/all', {
|
||||||
|
params: companyId == null ? undefined : { companyId },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取部门树
|
* 获取部门树(超管可传 companyId 跨公司)
|
||||||
*/
|
*/
|
||||||
export async function getDepartmentTreeApi() {
|
export async function getDepartmentTreeApi(companyId?: number) {
|
||||||
return requestClient.get<DepartmentVO.DepartmentInfoVO[]>('/department/tree');
|
return requestClient.get<DepartmentVO.DepartmentInfoVO[]>('/department/tree', {
|
||||||
|
params: companyId == null ? undefined : { companyId },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,5 +35,7 @@ export namespace DepartmentDTO {
|
|||||||
parentId?: number;
|
parentId?: number;
|
||||||
/** 状态 */
|
/** 状态 */
|
||||||
status?: number;
|
status?: number;
|
||||||
|
/** 公司ID(仅超管可跨公司) */
|
||||||
|
companyId?: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,5 +37,7 @@ export namespace PositionDTO {
|
|||||||
name?: string;
|
name?: string;
|
||||||
/** 状态 */
|
/** 状态 */
|
||||||
status?: number;
|
status?: number;
|
||||||
|
/** 公司ID(仅超管可跨公司) */
|
||||||
|
companyId?: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -964,7 +964,8 @@ void loadEnabledModels().then(() => refreshSessions());
|
|||||||
class="mt-24"
|
class="mt-24"
|
||||||
description="开始提问吧(需先在「模型管理」配置 API)"
|
description="开始提问吧(需先在「模型管理」配置 API)"
|
||||||
/>
|
/>
|
||||||
<div class="mx-auto max-w-[760px]">
|
<!-- w-full:避免仅 max-w 时在 flex 列里被内容撑成窄条,短气泡左右贴中间 -->
|
||||||
|
<div class="mx-auto w-full max-w-[760px]">
|
||||||
<ChatItem
|
<ChatItem
|
||||||
v-for="item in bubbleViews"
|
v-for="item in bubbleViews"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
@@ -1086,18 +1087,21 @@ html.dark .agent-session-item--active,
|
|||||||
}
|
}
|
||||||
|
|
||||||
.agent-td-item {
|
.agent-td-item {
|
||||||
/* ChatItem 根节点即 .t-chat__inner,样式打在本类上 */
|
/* ChatItem 根节点即 .t-chat__inner;行必须拉满,短文案才能各贴左右 */
|
||||||
display: flex;
|
display: flex;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
padding-inline: 20px;
|
padding-inline: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 内容区占满行宽,气泡用 align-items 贴边;勿对 content 用 fit-content(会把左右挤到中间) */
|
||||||
.agent-td-item :deep(.t-chat__content) {
|
.agent-td-item :deep(.t-chat__content) {
|
||||||
flex: 0 1 auto !important;
|
flex: 1 1 auto !important;
|
||||||
width: fit-content !important;
|
width: 100% !important;
|
||||||
max-width: min(680px, 100%);
|
max-width: 100%;
|
||||||
|
min-width: 0;
|
||||||
justify-content: flex-start !important;
|
justify-content: flex-start !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1106,30 +1110,31 @@ html.dark .agent-session-item--active,
|
|||||||
}
|
}
|
||||||
|
|
||||||
.agent-td-item--assistant :deep(.t-chat__content) {
|
.agent-td-item--assistant :deep(.t-chat__content) {
|
||||||
align-self: flex-start;
|
|
||||||
align-items: flex-start !important;
|
align-items: flex-start !important;
|
||||||
margin-right: auto;
|
|
||||||
margin-left: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-td-item--user {
|
.agent-td-item--user {
|
||||||
|
/* 无头像时关掉 TDesign row-reverse,避免与左右对齐打架 */
|
||||||
|
flex-direction: row !important;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-td-item--user :deep(.t-chat__content) {
|
.agent-td-item--user :deep(.t-chat__content) {
|
||||||
align-self: flex-end;
|
|
||||||
align-items: flex-end !important;
|
align-items: flex-end !important;
|
||||||
margin-left: auto;
|
|
||||||
margin-right: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.agent-td-item--user :deep(.t-chat__base) {
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 只有气泡随文字收缩;行宽始终 100% */
|
||||||
.agent-td-item :deep(.t-chat__detail) {
|
.agent-td-item :deep(.t-chat__detail) {
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
max-width: 100%;
|
max-width: min(680px, 100%);
|
||||||
margin-inline: 0;
|
margin-inline: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-td-item :deep(.t-chat__text__name) {
|
.agent-td-item :deep(.t-chat__name) {
|
||||||
opacity: 0.55;
|
opacity: 0.55;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
/**
|
||||||
|
* 超管账户表单:公司 / 部门 / 职位走列表接口下拉,不必手填 ID。
|
||||||
|
*/
|
||||||
import type { CompanyVO } from '#/api/company/types';
|
import type { CompanyVO } from '#/api/company/types';
|
||||||
|
import type { DepartmentVO } from '#/api/org/department';
|
||||||
|
import type { PositionVO } from '#/api/org/position';
|
||||||
import type {
|
import type {
|
||||||
SuperAccountDTO,
|
SuperAccountDTO,
|
||||||
SuperAccountVO,
|
SuperAccountVO,
|
||||||
} from '#/api/sys/account';
|
} from '#/api/sys/account';
|
||||||
|
import type { PageQueryDTO } from '#/types/common';
|
||||||
|
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
import { Form, Input, message, Select } from 'ant-design-vue';
|
import { Cascader, Form, Input, message, Select } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { getCompanyPageApi } from '#/api/company';
|
||||||
|
import { getDepartmentTreeApi } from '#/api/org/department';
|
||||||
|
import { getPositionPageApi } from '#/api/org/position';
|
||||||
import {
|
import {
|
||||||
super_createAccountApi,
|
super_createAccountApi,
|
||||||
super_updateAccountApi,
|
super_updateAccountApi,
|
||||||
@@ -20,13 +29,25 @@ interface Emits {
|
|||||||
(e: 'success'): void;
|
(e: 'success'): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DepartmentCascaderOption {
|
||||||
|
children?: DepartmentCascaderOption[];
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PositionSelectOption {
|
||||||
|
departmentId?: number;
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
}
|
||||||
|
|
||||||
defineOptions({ name: 'SysAccountFormModal' });
|
defineOptions({ name: 'SysAccountFormModal' });
|
||||||
|
|
||||||
const emit = defineEmits<Emits>();
|
const emit = defineEmits<Emits>();
|
||||||
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
draggable: true,
|
draggable: true,
|
||||||
class: 'w-[500px]',
|
class: 'w-[560px]',
|
||||||
onCancel() {
|
onCancel() {
|
||||||
handleCancel();
|
handleCancel();
|
||||||
},
|
},
|
||||||
@@ -39,7 +60,16 @@ const formRef = ref();
|
|||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const isEdit = ref(false);
|
const isEdit = ref(false);
|
||||||
const currentAccountData = ref<null | SuperAccountVO.AccountInfoVO>(null);
|
const currentAccountData = ref<null | SuperAccountVO.AccountInfoVO>(null);
|
||||||
const presetCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
|
||||||
|
const companyOptionsLoading = ref(false);
|
||||||
|
const departmentOptionsLoading = ref(false);
|
||||||
|
const positionOptionsLoading = ref(false);
|
||||||
|
const companyOptions = ref<{ label: string; value: number }[]>([]);
|
||||||
|
const departmentTreeOptions = ref<DepartmentCascaderOption[]>([]);
|
||||||
|
const allPositionOptions = ref<PositionSelectOption[]>([]);
|
||||||
|
const departmentPath = ref<number[]>([]);
|
||||||
|
/** 已加载选项的公司,切换公司时重拉部门/职位 */
|
||||||
|
const loadedOrgCompanyId = ref<number | undefined>(undefined);
|
||||||
|
|
||||||
const formData = ref<
|
const formData = ref<
|
||||||
SuperAccountDTO.SuperCreateAccountDTO & { status?: number }
|
SuperAccountDTO.SuperCreateAccountDTO & { status?: number }
|
||||||
@@ -48,7 +78,7 @@ const formData = ref<
|
|||||||
password: '',
|
password: '',
|
||||||
realName: '',
|
realName: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
companyId: 0,
|
companyId: undefined as unknown as number,
|
||||||
departmentId: undefined,
|
departmentId: undefined,
|
||||||
positionId: undefined,
|
positionId: undefined,
|
||||||
isSuper: 0,
|
isSuper: 0,
|
||||||
@@ -64,13 +94,54 @@ const statusOptions = [
|
|||||||
{ label: '停用', value: 0 },
|
{ label: '停用', value: 0 },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const positionOptions = computed(() => {
|
||||||
|
const selectedDepartmentId = formData.value.departmentId;
|
||||||
|
if (!selectedDepartmentId) return allPositionOptions.value;
|
||||||
|
return allPositionOptions.value.filter(
|
||||||
|
(item) => !item.departmentId || item.departmentId === selectedDepartmentId,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
function buildDepartmentTreeOptions(
|
||||||
|
departments: DepartmentVO.DepartmentInfoVO[],
|
||||||
|
): DepartmentCascaderOption[] {
|
||||||
|
return departments.map((item) => ({
|
||||||
|
children:
|
||||||
|
item.children && item.children.length > 0
|
||||||
|
? buildDepartmentTreeOptions(item.children)
|
||||||
|
: undefined,
|
||||||
|
label: item.name,
|
||||||
|
value: item.id,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function findDepartmentPathById(
|
||||||
|
options: DepartmentCascaderOption[],
|
||||||
|
departmentId: number,
|
||||||
|
currentPath: number[] = [],
|
||||||
|
): null | number[] {
|
||||||
|
for (const option of options) {
|
||||||
|
const nextPath = [...currentPath, option.value];
|
||||||
|
if (option.value === departmentId) return nextPath;
|
||||||
|
if (option.children?.length) {
|
||||||
|
const result = findDepartmentPathById(
|
||||||
|
option.children,
|
||||||
|
departmentId,
|
||||||
|
nextPath,
|
||||||
|
);
|
||||||
|
if (result) return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function resetForm() {
|
function resetForm() {
|
||||||
formData.value = {
|
formData.value = {
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
realName: '',
|
realName: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
companyId: presetCompany.value?.id ?? 0,
|
companyId: undefined as unknown as number,
|
||||||
departmentId: undefined,
|
departmentId: undefined,
|
||||||
positionId: undefined,
|
positionId: undefined,
|
||||||
isSuper: 0,
|
isSuper: 0,
|
||||||
@@ -78,6 +149,7 @@ function resetForm() {
|
|||||||
remark: '',
|
remark: '',
|
||||||
status: 1,
|
status: 1,
|
||||||
};
|
};
|
||||||
|
departmentPath.value = [];
|
||||||
formRef.value?.resetFields();
|
formRef.value?.resetFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,15 +157,147 @@ function handleCancel() {
|
|||||||
modalApi.close();
|
modalApi.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
function open(
|
async function loadCompanyOptions() {
|
||||||
|
try {
|
||||||
|
companyOptionsLoading.value = true;
|
||||||
|
const data = await getCompanyPageApi({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 500,
|
||||||
|
filters: {},
|
||||||
|
});
|
||||||
|
companyOptions.value = (data.records || []).map((item) => ({
|
||||||
|
label: item.status === 1 ? item.name : `${item.name}(禁用)`,
|
||||||
|
value: item.id,
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取公司列表失败:', error);
|
||||||
|
message.error('获取公司列表失败');
|
||||||
|
companyOptions.value = [];
|
||||||
|
} finally {
|
||||||
|
companyOptionsLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadDepartmentOptions(companyId: number) {
|
||||||
|
try {
|
||||||
|
departmentOptionsLoading.value = true;
|
||||||
|
const data = await getDepartmentTreeApi(companyId);
|
||||||
|
departmentTreeOptions.value = buildDepartmentTreeOptions(data || []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取部门树失败:', error);
|
||||||
|
message.error('获取部门树失败');
|
||||||
|
departmentTreeOptions.value = [];
|
||||||
|
} finally {
|
||||||
|
departmentOptionsLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadPositionOptions(companyId: number) {
|
||||||
|
try {
|
||||||
|
positionOptionsLoading.value = true;
|
||||||
|
const params: PageQueryDTO = {
|
||||||
|
page: 1,
|
||||||
|
pageSize: 1000,
|
||||||
|
filters: { companyId, status: 1 },
|
||||||
|
};
|
||||||
|
const data = await getPositionPageApi(params);
|
||||||
|
allPositionOptions.value = (data.records || []).map(
|
||||||
|
(item: PositionVO.PositionInfoVO) => ({
|
||||||
|
departmentId: item.departmentId,
|
||||||
|
label: item.name,
|
||||||
|
value: item.id,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取职位列表失败:', error);
|
||||||
|
message.error('获取职位列表失败');
|
||||||
|
allPositionOptions.value = [];
|
||||||
|
} finally {
|
||||||
|
positionOptionsLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadOrgOptionsForCompany(
|
||||||
|
companyId: number,
|
||||||
|
options?: { clearSelection?: boolean },
|
||||||
|
) {
|
||||||
|
if (!companyId) {
|
||||||
|
departmentTreeOptions.value = [];
|
||||||
|
allPositionOptions.value = [];
|
||||||
|
loadedOrgCompanyId.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
loadedOrgCompanyId.value === companyId &&
|
||||||
|
!options?.clearSelection
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await Promise.all([
|
||||||
|
loadDepartmentOptions(companyId),
|
||||||
|
loadPositionOptions(companyId),
|
||||||
|
]);
|
||||||
|
loadedOrgCompanyId.value = companyId;
|
||||||
|
if (options?.clearSelection) {
|
||||||
|
formData.value.departmentId = undefined;
|
||||||
|
formData.value.positionId = undefined;
|
||||||
|
departmentPath.value = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncDepartmentPathByDepartmentId() {
|
||||||
|
if (!formData.value.departmentId) {
|
||||||
|
departmentPath.value = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const path = findDepartmentPathById(
|
||||||
|
departmentTreeOptions.value,
|
||||||
|
formData.value.departmentId,
|
||||||
|
);
|
||||||
|
departmentPath.value = path || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDepartmentChange(value: number[]) {
|
||||||
|
departmentPath.value = value || [];
|
||||||
|
const selectedDepartmentId = departmentPath.value.at(-1);
|
||||||
|
const previousDepartmentId = formData.value.departmentId;
|
||||||
|
formData.value.departmentId = selectedDepartmentId;
|
||||||
|
|
||||||
|
if (
|
||||||
|
previousDepartmentId !== selectedDepartmentId &&
|
||||||
|
formData.value.positionId &&
|
||||||
|
!positionOptions.value.some(
|
||||||
|
(item) => item.value === formData.value.positionId,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
formData.value.positionId = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleCompanyChange(companyId: number | undefined) {
|
||||||
|
formData.value.companyId = companyId as number;
|
||||||
|
if (!companyId) {
|
||||||
|
departmentTreeOptions.value = [];
|
||||||
|
allPositionOptions.value = [];
|
||||||
|
formData.value.departmentId = undefined;
|
||||||
|
formData.value.positionId = undefined;
|
||||||
|
departmentPath.value = [];
|
||||||
|
loadedOrgCompanyId.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await loadOrgOptionsForCompany(companyId, { clearSelection: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function open(
|
||||||
accountData?: null | SuperAccountVO.AccountInfoVO,
|
accountData?: null | SuperAccountVO.AccountInfoVO,
|
||||||
company?: CompanyVO.CompanyInfoVO | null,
|
company?: CompanyVO.CompanyInfoVO | null,
|
||||||
) {
|
) {
|
||||||
isEdit.value = !!accountData;
|
isEdit.value = !!accountData;
|
||||||
currentAccountData.value = accountData || null;
|
currentAccountData.value = accountData || null;
|
||||||
presetCompany.value = company || null;
|
loadedOrgCompanyId.value = undefined;
|
||||||
|
|
||||||
resetForm();
|
resetForm();
|
||||||
|
await loadCompanyOptions();
|
||||||
|
|
||||||
if (accountData) {
|
if (accountData) {
|
||||||
formData.value = {
|
formData.value = {
|
||||||
@@ -101,7 +305,7 @@ function open(
|
|||||||
password: '',
|
password: '',
|
||||||
realName: accountData.realName,
|
realName: accountData.realName,
|
||||||
phone: accountData.phone || '',
|
phone: accountData.phone || '',
|
||||||
companyId: accountData.companyId || presetCompany.value?.id || 0,
|
companyId: accountData.companyId as number,
|
||||||
departmentId: accountData.departmentId,
|
departmentId: accountData.departmentId,
|
||||||
positionId: accountData.positionId,
|
positionId: accountData.positionId,
|
||||||
isSuper: accountData.isSuper ?? 0,
|
isSuper: accountData.isSuper ?? 0,
|
||||||
@@ -109,8 +313,13 @@ function open(
|
|||||||
remark: accountData.remark || '',
|
remark: accountData.remark || '',
|
||||||
status: accountData.status ?? 1,
|
status: accountData.status ?? 1,
|
||||||
};
|
};
|
||||||
} else if (presetCompany.value) {
|
} else if (company?.id) {
|
||||||
formData.value.companyId = presetCompany.value.id;
|
formData.value.companyId = company.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (formData.value.companyId) {
|
||||||
|
await loadOrgOptionsForCompany(formData.value.companyId);
|
||||||
|
syncDepartmentPathByDepartmentId();
|
||||||
}
|
}
|
||||||
|
|
||||||
modalApi.open();
|
modalApi.open();
|
||||||
@@ -126,7 +335,9 @@ async function handleSubmit() {
|
|||||||
await super_updateAccountApi(currentAccountData.value.id, updateData);
|
await super_updateAccountApi(currentAccountData.value.id, updateData);
|
||||||
message.success('更新成功');
|
message.success('更新成功');
|
||||||
} else {
|
} else {
|
||||||
await super_createAccountApi(formData.value);
|
// CreateSysAccountDTO 无 status,创建时剔除
|
||||||
|
const { status: _status, ...createData } = formData.value;
|
||||||
|
await super_createAccountApi(createData);
|
||||||
message.success('创建成功');
|
message.success('创建成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,12 +357,26 @@ watch(
|
|||||||
() => modalApi.useStore()?.value?.isOpen,
|
() => modalApi.useStore()?.value?.isOpen,
|
||||||
(newVal) => {
|
(newVal) => {
|
||||||
if (!newVal) {
|
if (!newVal) {
|
||||||
presetCompany.value = null;
|
loadedOrgCompanyId.value = undefined;
|
||||||
resetForm();
|
resetForm();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => formData.value.departmentId,
|
||||||
|
() => {
|
||||||
|
if (
|
||||||
|
formData.value.positionId &&
|
||||||
|
!positionOptions.value.some(
|
||||||
|
(item) => item.value === formData.value.positionId,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
formData.value.positionId = undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
open,
|
open,
|
||||||
});
|
});
|
||||||
@@ -165,8 +390,22 @@ defineExpose({
|
|||||||
:label-col="{ span: 6 }"
|
:label-col="{ span: 6 }"
|
||||||
:wrapper-col="{ span: 18 }"
|
:wrapper-col="{ span: 18 }"
|
||||||
>
|
>
|
||||||
<Form.Item v-if="presetCompany" label="所属公司">
|
<Form.Item
|
||||||
<Input :value="presetCompany.name" disabled />
|
label="所属公司"
|
||||||
|
name="companyId"
|
||||||
|
:rules="[{ required: true, message: '请选择所属公司' }]"
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
:value="formData.companyId || undefined"
|
||||||
|
:loading="companyOptionsLoading"
|
||||||
|
:options="companyOptions"
|
||||||
|
show-search
|
||||||
|
option-filter-prop="label"
|
||||||
|
placeholder="请选择公司"
|
||||||
|
allow-clear
|
||||||
|
class="w-full"
|
||||||
|
@change="(v) => handleCompanyChange(v as number | undefined)"
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
@@ -211,10 +450,6 @@ defineExpose({
|
|||||||
<Input v-model:value="formData.realName" placeholder="请输入真实姓名" />
|
<Input v-model:value="formData.realName" placeholder="请输入真实姓名" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item label="备注" name="remark">
|
|
||||||
<Input v-model:value="formData.remark" placeholder="请输入备注" />
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="手机号"
|
label="手机号"
|
||||||
name="phone"
|
name="phone"
|
||||||
@@ -226,32 +461,36 @@ defineExpose({
|
|||||||
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
|
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item label="所属部门" name="departmentId">
|
||||||
v-if="!presetCompany"
|
<Cascader
|
||||||
label="公司ID"
|
:value="departmentPath"
|
||||||
name="companyId"
|
:options="departmentTreeOptions"
|
||||||
:rules="[{ required: true, message: '请输入公司ID' }]"
|
:loading="departmentOptionsLoading"
|
||||||
>
|
:disabled="!formData.companyId"
|
||||||
<Input
|
placeholder="请先选择公司"
|
||||||
v-model:value="formData.companyId"
|
:field-names="{
|
||||||
type="number"
|
label: 'label',
|
||||||
placeholder="请输入公司ID"
|
value: 'value',
|
||||||
|
children: 'children',
|
||||||
|
}"
|
||||||
|
change-on-select
|
||||||
|
allow-clear
|
||||||
|
class="w-full"
|
||||||
|
@change="(value) => handleDepartmentChange((value || []) as number[])"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item label="部门ID" name="departmentId">
|
<Form.Item label="职位" name="positionId">
|
||||||
<Input
|
<Select
|
||||||
v-model:value="formData.departmentId"
|
|
||||||
type="number"
|
|
||||||
placeholder="请输入部门ID"
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
|
|
||||||
<Form.Item label="职位ID" name="positionId">
|
|
||||||
<Input
|
|
||||||
v-model:value="formData.positionId"
|
v-model:value="formData.positionId"
|
||||||
type="number"
|
:loading="positionOptionsLoading"
|
||||||
placeholder="请输入职位ID"
|
:options="positionOptions"
|
||||||
|
:disabled="!formData.companyId || positionOptionsLoading"
|
||||||
|
placeholder="请先选择公司"
|
||||||
|
allow-clear
|
||||||
|
show-search
|
||||||
|
option-filter-prop="label"
|
||||||
|
class="w-full"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
@@ -270,12 +509,8 @@ defineExpose({
|
|||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item label="头像图片ID" name="avatarImageId">
|
<Form.Item label="备注" name="remark">
|
||||||
<Input
|
<Input v-model:value="formData.remark" placeholder="请输入备注" />
|
||||||
v-model:value="formData.avatarImageId"
|
|
||||||
type="number"
|
|
||||||
placeholder="请输入头像图片ID"
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item v-if="isEdit" label="状态" name="status">
|
<Form.Item v-if="isEdit" label="状态" name="status">
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
/**
|
||||||
|
* 系统账户:左栏筛公司,右栏用 Vxe 搜索表单 + toolbar 新增(对齐反馈页布局)。
|
||||||
|
*/
|
||||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||||
import type { CompanyVO } from '#/api/company/types';
|
import type { CompanyVO } from '#/api/company/types';
|
||||||
import type {
|
import type {
|
||||||
@@ -14,10 +17,8 @@ import { createIconifyIcon } from '@vben/icons';
|
|||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
Input,
|
|
||||||
message,
|
message,
|
||||||
Popconfirm,
|
Popconfirm,
|
||||||
Select,
|
|
||||||
Space,
|
Space,
|
||||||
Tag,
|
Tag,
|
||||||
} from 'ant-design-vue';
|
} from 'ant-design-vue';
|
||||||
@@ -46,13 +47,6 @@ const accountFormModalRef = ref();
|
|||||||
const selectedCompanyId = ref<number | undefined>(undefined);
|
const selectedCompanyId = ref<number | undefined>(undefined);
|
||||||
const currentCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
const currentCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
||||||
|
|
||||||
const searchForm = ref({
|
|
||||||
username: undefined as string | undefined,
|
|
||||||
realName: undefined as string | undefined,
|
|
||||||
phone: undefined as string | undefined,
|
|
||||||
status: undefined as number | undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
const statusOptions = [
|
const statusOptions = [
|
||||||
{ label: '正常', value: 1 },
|
{ label: '正常', value: 1 },
|
||||||
{ label: '停用', value: 0 },
|
{ label: '停用', value: 0 },
|
||||||
@@ -146,6 +140,52 @@ const accountTableColumns = computed(() =>
|
|||||||
: (accountTableBaseColumns ?? []),
|
: (accountTableBaseColumns ?? []),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const formOptions = computed(() => ({
|
||||||
|
schema: [
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '登录用户名',
|
||||||
|
},
|
||||||
|
fieldName: 'username',
|
||||||
|
label: '用户名',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '真实姓名',
|
||||||
|
},
|
||||||
|
fieldName: 'realName',
|
||||||
|
label: '姓名',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '手机号',
|
||||||
|
},
|
||||||
|
fieldName: 'phone',
|
||||||
|
label: '手机号',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: '全部',
|
||||||
|
options: statusOptions,
|
||||||
|
},
|
||||||
|
fieldName: 'status',
|
||||||
|
label: '状态',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
showDefaultActions: true,
|
||||||
|
collapsed: true,
|
||||||
|
collapsedRows: 1,
|
||||||
|
submitOnChange: true,
|
||||||
|
}));
|
||||||
|
|
||||||
const gridOptions: VxeGridProps<SuperAccountVO.AccountInfoVO> = {
|
const gridOptions: VxeGridProps<SuperAccountVO.AccountInfoVO> = {
|
||||||
columns: accountTableColumns.value,
|
columns: accountTableColumns.value,
|
||||||
height: '100%',
|
height: '100%',
|
||||||
@@ -185,17 +225,17 @@ const gridOptions: VxeGridProps<SuperAccountVO.AccountInfoVO> = {
|
|||||||
},
|
},
|
||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
ajax: {
|
ajax: {
|
||||||
query: async ({ page }) => {
|
query: async ({ page }, formValues: Record<string, any> = {}) => {
|
||||||
try {
|
try {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const params: PageQueryDTO<SuperAccountDTO.AccountFilterDTO> = {
|
const params: PageQueryDTO<SuperAccountDTO.AccountFilterDTO> = {
|
||||||
page: page.currentPage,
|
page: page.currentPage,
|
||||||
pageSize: page.pageSize,
|
pageSize: page.pageSize,
|
||||||
filters: {
|
filters: {
|
||||||
username: searchForm.value.username || undefined,
|
username: formValues.username?.trim() || undefined,
|
||||||
realName: searchForm.value.realName || undefined,
|
realName: formValues.realName?.trim() || undefined,
|
||||||
phone: searchForm.value.phone || undefined,
|
phone: formValues.phone?.trim() || undefined,
|
||||||
status: searchForm.value.status,
|
status: formValues.status,
|
||||||
companyId: currentCompany.value?.id,
|
companyId: currentCompany.value?.id,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -219,7 +259,8 @@ const gridOptions: VxeGridProps<SuperAccountVO.AccountInfoVO> = {
|
|||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
gridOptions,
|
gridOptions,
|
||||||
showSearchForm: false,
|
formOptions: formOptions.value,
|
||||||
|
showSearchForm: true,
|
||||||
tableTitle: '账户列表',
|
tableTitle: '账户列表',
|
||||||
});
|
});
|
||||||
syncVxeGridColumns(gridApi, accountTableColumns);
|
syncVxeGridColumns(gridApi, accountTableColumns);
|
||||||
@@ -233,11 +274,8 @@ function refreshTable() {
|
|||||||
gridApi?.reload();
|
gridApi?.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 新增:不必先选左栏公司,表单内自选;左栏有选中时作默认值 */
|
||||||
function handleAdd() {
|
function handleAdd() {
|
||||||
if (!currentCompany.value) {
|
|
||||||
message.warning('请先选择具体公司,或在公司行点击「添加」');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
accountFormModalRef.value?.open(undefined, currentCompany.value);
|
accountFormModalRef.value?.open(undefined, currentCompany.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,71 +348,32 @@ watch(currentCompany, () => {
|
|||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<template #title>
|
<template #title>
|
||||||
|
<div class="flex min-w-0 items-center gap-2">
|
||||||
<span class="text-base font-semibold">账户列表</span>
|
<span class="text-base font-semibold">账户列表</span>
|
||||||
</template>
|
<span class="text-muted-foreground truncate text-xs font-normal">
|
||||||
<template #extra>
|
|
||||||
<Space wrap size="small" class="max-w-[min(100%,48rem)]">
|
|
||||||
<Input
|
|
||||||
v-model:value="searchForm.username"
|
|
||||||
allow-clear
|
|
||||||
placeholder="登录用户名"
|
|
||||||
class="w-[120px]"
|
|
||||||
@press-enter="refreshTable"
|
|
||||||
/>
|
|
||||||
<Input
|
|
||||||
v-model:value="searchForm.realName"
|
|
||||||
allow-clear
|
|
||||||
placeholder="姓名"
|
|
||||||
class="w-[100px]"
|
|
||||||
@press-enter="refreshTable"
|
|
||||||
/>
|
|
||||||
<Input
|
|
||||||
v-model:value="searchForm.phone"
|
|
||||||
allow-clear
|
|
||||||
placeholder="手机号"
|
|
||||||
class="w-[120px]"
|
|
||||||
@press-enter="refreshTable"
|
|
||||||
/>
|
|
||||||
<Select
|
|
||||||
v-model:value="searchForm.status"
|
|
||||||
allow-clear
|
|
||||||
placeholder="状态"
|
|
||||||
class="min-w-[88px]"
|
|
||||||
:options="statusOptions"
|
|
||||||
@change="refreshTable"
|
|
||||||
/>
|
|
||||||
<Button size="small" @click="refreshTable">查询</Button>
|
|
||||||
<PermissionGate code="sys:account:create">
|
|
||||||
<Button type="primary" size="small" @click="handleAdd">
|
|
||||||
<PlusIcon class="mr-1 h-4 w-4" />
|
|
||||||
新增账户
|
|
||||||
</Button>
|
|
||||||
</PermissionGate>
|
|
||||||
</Space>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<div
|
|
||||||
class="text-muted-foreground shrink-0 border-t border-border px-4 py-2 text-xs"
|
|
||||||
>
|
|
||||||
当前:{{ selectedCompanyLabel }}
|
当前:{{ selectedCompanyLabel }}
|
||||||
<template v-if="currentCompany">
|
</span>
|
||||||
<Tag
|
<Tag
|
||||||
class="ml-2"
|
v-if="currentCompany"
|
||||||
|
class="m-0"
|
||||||
:color="currentCompany.status === 1 ? 'green' : 'red'"
|
:color="currentCompany.status === 1 ? 'green' : 'red'"
|
||||||
>
|
>
|
||||||
{{ currentCompany.status === 1 ? '启用' : '禁用' }}
|
{{ currentCompany.status === 1 ? '启用' : '禁用' }}
|
||||||
</Tag>
|
</Tag>
|
||||||
</template>
|
|
||||||
</div>
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="min-h-0 flex-1 overflow-hidden px-2 pb-2 pt-0 sm:px-3 sm:pb-3"
|
class="min-h-0 flex-1 overflow-hidden px-2 pb-2 pt-0 sm:px-3 sm:pb-3"
|
||||||
>
|
>
|
||||||
<Grid :loading="loading" class="h-full min-h-0">
|
<Grid :loading="loading" class="h-full min-h-0">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<span class="text-muted-foreground text-xs">
|
<PermissionGate code="sys:account:create">
|
||||||
左侧筛选公司;表格在区域内滚动
|
<Button type="primary" @click="handleAdd">
|
||||||
</span>
|
<PlusIcon class="mr-1 h-4 w-4" />
|
||||||
|
新增账户
|
||||||
|
</Button>
|
||||||
|
</PermissionGate>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #status="{ row }">
|
<template #status="{ row }">
|
||||||
|
|||||||
Reference in New Issue
Block a user