feat: 设置主机分组内元素.
This commit is contained in:
@@ -31,4 +31,12 @@ public interface FieldConst {
|
||||
|
||||
String REL_ID = "relId";
|
||||
|
||||
String BEFORE = "before";
|
||||
|
||||
String AFTER = "after";
|
||||
|
||||
String SOURCE = "source";
|
||||
|
||||
String TARGET = "target";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.orion.ops.framework.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 移动位置
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/11/13 17:26
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum MovePosition {
|
||||
|
||||
// 拖拽到目标元素上
|
||||
TOP(-1),
|
||||
|
||||
// 拖拽到目标元素中
|
||||
IN(0),
|
||||
|
||||
// 拖拽到目标元素下
|
||||
BOTTOM(1),
|
||||
|
||||
;
|
||||
|
||||
private final Integer position;
|
||||
|
||||
public static MovePosition of(Integer position) {
|
||||
if (position == null) {
|
||||
return null;
|
||||
}
|
||||
for (MovePosition value : values()) {
|
||||
if (value.position.equals(position)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,4 +19,6 @@ public interface OperatorLogKeys extends FieldConst {
|
||||
|
||||
String KEY_NAME = "keyName";
|
||||
|
||||
String POSITION_NAME = "positionName";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
### 创建主机分组
|
||||
POST {{baseUrl}}/asset/host-group/create
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"parentId": -1,
|
||||
"name": ""
|
||||
}
|
||||
|
||||
|
||||
### 查询主机分组
|
||||
GET {{baseUrl}}/asset/host-group/tree
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 修改名称
|
||||
PUT {{baseUrl}}/asset/host-group/rename
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": "",
|
||||
"name": ""
|
||||
}
|
||||
|
||||
|
||||
### 移动位置
|
||||
PUT {{baseUrl}}/asset/host-group/move
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": "",
|
||||
"targetId": "",
|
||||
"position": ""
|
||||
}
|
||||
|
||||
|
||||
### 删除主机分组
|
||||
DELETE {{baseUrl}}/asset/host-group/delete?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package com.orion.ops.module.asset.controller;
|
||||
|
||||
import com.orion.lang.define.wrapper.HttpWrapper;
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.asset.define.operator.HostOperatorType;
|
||||
import com.orion.ops.module.asset.service.HostService;
|
||||
import com.orion.ops.module.asset.convert.HostGroupConvert;
|
||||
import com.orion.ops.module.asset.define.operator.HostGroupOperatorType;
|
||||
import com.orion.ops.module.asset.entity.vo.HostGroupTreeVO;
|
||||
import com.orion.ops.module.infra.api.DataGroupApi;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupUpdateDTO;
|
||||
import com.orion.ops.module.infra.api.DataGroupRelApi;
|
||||
import com.orion.ops.module.infra.entity.dto.data.*;
|
||||
import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 主机分组 api
|
||||
@@ -37,43 +40,46 @@ import java.util.List;
|
||||
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||
public class HostGroupController {
|
||||
|
||||
@Resource
|
||||
private HostService hostService;
|
||||
|
||||
@Resource
|
||||
private DataGroupApi dataGroupApi;
|
||||
|
||||
// TODO 配置权限
|
||||
// TODO 配置操作日志类型
|
||||
// TODO 拖拽
|
||||
// TODO http
|
||||
// TODO 聚合查询关联
|
||||
@Resource
|
||||
private DataGroupRelApi dataGroupRelApi;
|
||||
|
||||
@OperatorLog(HostOperatorType.CREATE)
|
||||
@OperatorLog(HostGroupOperatorType.CREATE)
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建主机分组")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:create')")
|
||||
public Long createHostGroup(@Validated @RequestBody DataGroupCreateDTO request) {
|
||||
public Long updateGroupHost(@Validated @RequestBody DataGroupCreateDTO request) {
|
||||
return dataGroupApi.createDataGroup(DataGroupTypeEnum.HOST, request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/tree")
|
||||
@Operation(summary = "创建主机分组")
|
||||
@Operation(summary = "查询主机分组")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:query')")
|
||||
public List<DataGroupDTO> queryHostGroup() {
|
||||
return dataGroupApi.getDataGroupTree(DataGroupTypeEnum.HOST);
|
||||
public List<HostGroupTreeVO> queryHostGroup() {
|
||||
List<DataGroupDTO> rows = dataGroupApi.getDataGroupTree(DataGroupTypeEnum.HOST);
|
||||
return HostGroupConvert.MAPPER.toList(rows);
|
||||
}
|
||||
|
||||
@OperatorLog(HostOperatorType.UPDATE)
|
||||
@OperatorLog(HostGroupOperatorType.RENAME)
|
||||
@PutMapping("/rename")
|
||||
@Operation(summary = "修改名称")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:update')")
|
||||
public Integer updateHostGroupName(@Validated @RequestBody DataGroupUpdateDTO request) {
|
||||
public Integer updateHostGroupName(@Validated @RequestBody DataGroupRenameDTO request) {
|
||||
return dataGroupApi.renameDataGroup(request);
|
||||
}
|
||||
|
||||
@OperatorLog(HostOperatorType.DELETE)
|
||||
@OperatorLog(HostGroupOperatorType.MOVE)
|
||||
@PutMapping("/move")
|
||||
@Operation(summary = "移动位置")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:update')")
|
||||
public Integer moveHostGroup(@Validated @RequestBody DataGroupMoveDTO request) {
|
||||
return dataGroupApi.moveDataGroup(request);
|
||||
}
|
||||
|
||||
@OperatorLog(HostGroupOperatorType.DELETE)
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除主机分组")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:delete')")
|
||||
@@ -81,5 +87,23 @@ public class HostGroupController {
|
||||
return dataGroupApi.deleteDataGroupById(id);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/rel-list")
|
||||
@Operation(summary = "查询分组主机")
|
||||
@Parameter(name = "groupId", description = "groupId", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:query-rel')")
|
||||
public Set<Long> queryHostGroupRel(@RequestParam("groupId") Long groupId) {
|
||||
return dataGroupRelApi.getGroupRelList(DataGroupTypeEnum.HOST, groupId);
|
||||
}
|
||||
|
||||
@OperatorLog(HostGroupOperatorType.UPDATE_REL)
|
||||
@PostMapping("/update-rel")
|
||||
@Operation(summary = "修改分组主机")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:update-rel')")
|
||||
public HttpWrapper<?> updateGroupHost(@Validated @RequestBody DataGroupRelUpdateDTO request) {
|
||||
dataGroupRelApi.updateGroupRel(request);
|
||||
return HttpWrapper.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orion.ops.module.asset.convert;
|
||||
|
||||
import com.orion.ops.module.asset.entity.vo.HostGroupTreeVO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机配置 内部对象转换器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-11 14:16
|
||||
*/
|
||||
@Mapper
|
||||
public interface HostGroupConvert {
|
||||
|
||||
HostGroupConvert MAPPER = Mappers.getMapper(HostGroupConvert.class);
|
||||
|
||||
List<HostGroupTreeVO> toList(List<DataGroupDTO> list);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.orion.ops.module.asset.define.operator;
|
||||
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.Module;
|
||||
import com.orion.ops.framework.biz.operator.log.core.factory.InitializingOperatorTypes;
|
||||
import com.orion.ops.framework.biz.operator.log.core.model.OperatorType;
|
||||
|
||||
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.*;
|
||||
|
||||
/**
|
||||
* 主机分组 操作日志类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/10/10 17:30
|
||||
*/
|
||||
@Module("asset:host-group")
|
||||
public class HostGroupOperatorType extends InitializingOperatorTypes {
|
||||
|
||||
public static final String CREATE = "host-group:create";
|
||||
|
||||
public static final String RENAME = "host-group:rename";
|
||||
|
||||
public static final String MOVE = "host-group:move";
|
||||
|
||||
public static final String DELETE = "host-group:delete";
|
||||
|
||||
public static final String UPDATE_REL = "host-group:update-rel";
|
||||
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(L, CREATE, "创建主机分组 <sb>${name}</sb>"),
|
||||
new OperatorType(L, RENAME, "重命名主机分组 <sb>${before}</sb> -> <sb>${name}</sb>"),
|
||||
new OperatorType(L, MOVE, "移动主机分组 <sb>${source}</sb> 到 <sb>${target}(${position})</sb>"),
|
||||
new OperatorType(H, DELETE, "删除主机分组 <sb>${name}</sb>"),
|
||||
new OperatorType(M, UPDATE_REL, "修改分组内主机 <sb>${name}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.orion.ops.module.asset.entity.request.host;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机分组引用 更新请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-20 11:55
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "HostGroupRelUpdateRequest", description = "主机分组引用 更新请求对象")
|
||||
public class HostGroupRelUpdateRequest implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "分组id")
|
||||
private Long groupId;
|
||||
|
||||
@Schema(description = "主机id")
|
||||
private List<Long> hostIdList;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.orion.ops.module.asset.entity.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机秘钥 视图响应对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-20 11:55
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "HostGroupTreeVO", description = "主机秘钥 视图响应对象")
|
||||
public class HostGroupTreeVO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@JsonProperty("key")
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "父id")
|
||||
private Long parentId;
|
||||
|
||||
@JsonProperty("title")
|
||||
@Schema(description = "组名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "子节点")
|
||||
private List<HostGroupTreeVO> children;
|
||||
|
||||
}
|
||||
@@ -2,7 +2,8 @@ package com.orion.ops.module.infra.api;
|
||||
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupUpdateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupMoveDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRenameDTO;
|
||||
import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
@@ -31,9 +32,15 @@ public interface DataGroupApi {
|
||||
* @param dto dto
|
||||
* @return effect
|
||||
*/
|
||||
Integer renameDataGroup(DataGroupUpdateDTO dto);
|
||||
Integer renameDataGroup(DataGroupRenameDTO dto);
|
||||
|
||||
// FIXME drag
|
||||
/**
|
||||
* 移动分组
|
||||
*
|
||||
* @param dto dto
|
||||
* @return effect
|
||||
*/
|
||||
Integer moveDataGroup(DataGroupMoveDTO dto);
|
||||
|
||||
/**
|
||||
* 通过缓存查询数据分组
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.orion.ops.module.infra.api;
|
||||
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelUpdateDTO;
|
||||
import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,6 +17,13 @@ import java.util.Set;
|
||||
*/
|
||||
public interface DataGroupRelApi {
|
||||
|
||||
/**
|
||||
* 设置关联
|
||||
*
|
||||
* @param dto dto
|
||||
*/
|
||||
void updateGroupRel(DataGroupRelUpdateDTO dto);
|
||||
|
||||
/**
|
||||
* 添加关联
|
||||
*
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.orion.ops.module.infra.entity.dto.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据分组 移动请求业务对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-7 18:44
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataGroupMoveDTO", description = "数据分组 移动请求业务对象")
|
||||
public class DataGroupMoveDTO implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "目标id")
|
||||
private Long targetId;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "移动位置")
|
||||
private Integer position;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.orion.ops.module.infra.entity.dto.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据分组关联 更新请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-7 18:44
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataGroupRelUpdateDTO", description = "数据分组关联 更新请求对象")
|
||||
public class DataGroupRelUpdateDTO implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "组id")
|
||||
private Long groupId;
|
||||
|
||||
@Schema(description = "引用id")
|
||||
private List<Long> relIdList;
|
||||
|
||||
}
|
||||
@@ -6,12 +6,13 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据分组 更新请求业务对象
|
||||
* 数据分组 重命名请求业务对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -21,21 +22,16 @@ import java.io.Serializable;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataGroupUpdateDTO", description = "数据分组 更新请求业务对象")
|
||||
public class DataGroupUpdateDTO implements Serializable {
|
||||
@Schema(name = "DataGroupRenameDTO", description = "数据分组 重命名请求业务对象")
|
||||
public class DataGroupRenameDTO implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "父id")
|
||||
private Long parentId;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 32)
|
||||
@Schema(description = "组名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "排序")
|
||||
private Integer sort;
|
||||
|
||||
}
|
||||
@@ -6,9 +6,11 @@ import com.orion.ops.module.infra.convert.DataGroupProviderConvert;
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupUpdateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupMoveDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRenameDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupUpdateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupMoveRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRenameRequest;
|
||||
import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
|
||||
import com.orion.ops.module.infra.service.DataGroupService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -40,12 +42,19 @@ public class DataGroupApiImpl implements DataGroupApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer renameDataGroup(DataGroupUpdateDTO dto) {
|
||||
public Integer renameDataGroup(DataGroupRenameDTO dto) {
|
||||
Valid.valid(dto);
|
||||
DataGroupUpdateRequest request = DataGroupProviderConvert.MAPPER.toRequest(dto);
|
||||
DataGroupRenameRequest request = DataGroupProviderConvert.MAPPER.toRequest(dto);
|
||||
return dataGroupService.renameDataGroup(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer moveDataGroup(DataGroupMoveDTO dto) {
|
||||
Valid.valid(dto);
|
||||
DataGroupMoveRequest request = DataGroupProviderConvert.MAPPER.toRequest(dto);
|
||||
return dataGroupService.moveDataGroup(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataGroupDTO> getDataGroupList(DataGroupTypeEnum type) {
|
||||
List<DataGroupCacheDTO> rows = dataGroupService.getDataGroupListByCache(type.name());
|
||||
|
||||
@@ -5,7 +5,9 @@ import com.orion.ops.module.infra.api.DataGroupRelApi;
|
||||
import com.orion.ops.module.infra.convert.DataGroupRelProviderConvert;
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupRelCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelUpdateDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelUpdateRequest;
|
||||
import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
|
||||
import com.orion.ops.module.infra.service.DataGroupRelService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -31,6 +33,13 @@ public class DataGroupRelApiImpl implements DataGroupRelApi {
|
||||
@Resource
|
||||
private DataGroupRelService dataGroupRelService;
|
||||
|
||||
@Override
|
||||
public void updateGroupRel(DataGroupRelUpdateDTO dto) {
|
||||
Valid.valid(dto);
|
||||
DataGroupRelUpdateRequest request = DataGroupRelProviderConvert.MAPPER.toRequest(dto);
|
||||
dataGroupRelService.updateGroupRel(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroupRel(DataGroupRelCreateDTO dto) {
|
||||
Valid.valid(dto);
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.orion.ops.module.infra.convert;
|
||||
import com.orion.ops.module.infra.entity.domain.DataGroupDO;
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupUpdateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRenameRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface DataGroupConvert {
|
||||
|
||||
DataGroupDO to(DataGroupCreateRequest request);
|
||||
|
||||
DataGroupDO to(DataGroupUpdateRequest request);
|
||||
DataGroupDO to(DataGroupRenameRequest request);
|
||||
|
||||
DataGroupCacheDTO toCache(DataGroupDO domain);
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@ import com.orion.ops.module.infra.entity.domain.DataGroupDO;
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupUpdateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupMoveDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRenameDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupUpdateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupMoveRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRenameRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@@ -28,11 +30,13 @@ public interface DataGroupProviderConvert {
|
||||
|
||||
DataGroupDTO to(DataGroupDO domain);
|
||||
|
||||
DataGroupDO to(DataGroupUpdateDTO update);
|
||||
DataGroupDO to(DataGroupRenameDTO update);
|
||||
|
||||
DataGroupCreateRequest toRequest(DataGroupCreateDTO request);
|
||||
|
||||
DataGroupUpdateRequest toRequest(DataGroupUpdateDTO request);
|
||||
DataGroupRenameRequest toRequest(DataGroupRenameDTO request);
|
||||
|
||||
DataGroupMoveRequest toRequest(DataGroupMoveDTO request);
|
||||
|
||||
List<DataGroupDTO> toList(List<DataGroupCacheDTO> list);
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.orion.ops.module.infra.convert;
|
||||
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelUpdateDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelUpdateRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@@ -21,6 +23,8 @@ public interface DataGroupRelProviderConvert {
|
||||
|
||||
DataGroupRelCreateRequest toRequest(DataGroupRelCreateDTO request);
|
||||
|
||||
DataGroupRelUpdateRequest toRequest(DataGroupRelUpdateDTO request);
|
||||
|
||||
List<DataGroupRelCreateRequest> toList(List<DataGroupRelCreateDTO> list);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,20 @@ public interface DataGroupDAO extends IMapper<DataGroupDO> {
|
||||
*/
|
||||
Integer selectMaxSort(@Param("parentId") Long parentId, @Param("type") String type);
|
||||
|
||||
/**
|
||||
* 修改排序
|
||||
*
|
||||
* @param parentId parentId
|
||||
* @param condition 条件
|
||||
* @param referSort 对比值
|
||||
* @param addition 自增步长
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateSort(@Param("parentId") Long parentId,
|
||||
@Param("condition") String condition,
|
||||
@Param("referSort") Integer referSort,
|
||||
@Param("addition") Integer addition);
|
||||
|
||||
/**
|
||||
* 通过 parentId 查询
|
||||
*
|
||||
|
||||
@@ -17,6 +17,18 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface DataGroupRelDAO extends IMapper<DataGroupRelDO> {
|
||||
|
||||
/**
|
||||
* 通过 groupId 删除
|
||||
*
|
||||
* @param groupId groupId
|
||||
* @return effect
|
||||
*/
|
||||
default int deleteByGroupId(Long groupId) {
|
||||
LambdaQueryWrapper<DataGroupRelDO> wrapper = this.lambda()
|
||||
.eq(DataGroupRelDO::getGroupId, groupId);
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 groupId 删除
|
||||
*
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.orion.ops.module.infra.entity.request.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据分组 移动请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-7 18:44
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataGroupMoveRequest", description = "数据分组 移动请求对象")
|
||||
public class DataGroupMoveRequest implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "目标id")
|
||||
private Long targetId;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "移动位置")
|
||||
private Integer position;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.orion.ops.module.infra.entity.request.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据分组关联 更新请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-7 18:44
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataGroupRelUpdateRequest", description = "数据分组关联 更新请求对象")
|
||||
public class DataGroupRelUpdateRequest implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "组id")
|
||||
private Long groupId;
|
||||
|
||||
@Schema(description = "引用id")
|
||||
private List<Long> relIdList;
|
||||
|
||||
}
|
||||
@@ -22,20 +22,14 @@ import java.io.Serializable;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataGroupUpdateRequest", description = "数据分组 更新请求对象")
|
||||
public class DataGroupUpdateRequest implements Serializable {
|
||||
public class DataGroupRenameRequest implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "父id")
|
||||
private Long parentId;
|
||||
|
||||
@Size(max = 32)
|
||||
@Schema(description = "组名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "排序")
|
||||
private Integer sort;
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.orion.ops.module.infra.service;
|
||||
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupRelCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelUpdateRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -14,6 +15,13 @@ import java.util.List;
|
||||
*/
|
||||
public interface DataGroupRelService {
|
||||
|
||||
/**
|
||||
* 设置关联
|
||||
*
|
||||
* @param request request
|
||||
*/
|
||||
void updateGroupRel(DataGroupRelUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 添加关联
|
||||
*
|
||||
|
||||
@@ -2,7 +2,8 @@ package com.orion.ops.module.infra.service;
|
||||
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupUpdateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupMoveRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRenameRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,9 +30,15 @@ public interface DataGroupService {
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer renameDataGroup(DataGroupUpdateRequest request);
|
||||
Integer renameDataGroup(DataGroupRenameRequest request);
|
||||
|
||||
// FIXME drag
|
||||
/**
|
||||
* 移动分组
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer moveDataGroup(DataGroupMoveRequest request);
|
||||
|
||||
/**
|
||||
* 通过缓存查询数据分组 - 列表
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.orion.ops.module.infra.service.impl;
|
||||
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
@@ -15,6 +16,7 @@ import com.orion.ops.module.infra.entity.domain.DataGroupDO;
|
||||
import com.orion.ops.module.infra.entity.domain.DataGroupRelDO;
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupRelCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelUpdateRequest;
|
||||
import com.orion.ops.module.infra.service.DataGroupRelService;
|
||||
import com.orion.spring.SpringHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -45,6 +47,52 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
|
||||
@Resource
|
||||
private DataGroupRelDAO dataGroupRelDAO;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateGroupRel(DataGroupRelUpdateRequest request) {
|
||||
Long groupId = request.getGroupId();
|
||||
// 查询分组
|
||||
DataGroupDO group = dataGroupDAO.selectById(groupId);
|
||||
Valid.notNull(group, ErrorMessage.GROUP_ABSENT);
|
||||
List<Long> relIdList = request.getRelIdList();
|
||||
// 设置日志参数
|
||||
OperatorLogs.add(OperatorLogs.NAME, group.getName());
|
||||
if (Lists.isEmpty(relIdList)) {
|
||||
// 为空删除
|
||||
dataGroupRelDAO.deleteByGroupId(groupId);
|
||||
} else {
|
||||
// 差异变更
|
||||
List<DataGroupRelDO> records = dataGroupRelDAO.of()
|
||||
.createWrapper()
|
||||
.eq(DataGroupRelDO::getGroupId, group)
|
||||
.then()
|
||||
.list();
|
||||
// 查询删除的部分
|
||||
List<Long> deleteIdList = records.stream()
|
||||
.filter(s -> !relIdList.contains(s.getRelId()))
|
||||
.map(DataGroupRelDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if (!deleteIdList.isEmpty()) {
|
||||
dataGroupRelDAO.deleteBatchIds(deleteIdList);
|
||||
}
|
||||
// 查询新增的部分
|
||||
List<Long> persetRelIdList = records.stream()
|
||||
.map(DataGroupRelDO::getRelId)
|
||||
.collect(Collectors.toList());
|
||||
relIdList.removeIf(persetRelIdList::contains);
|
||||
if (!relIdList.isEmpty()) {
|
||||
List<DataGroupRelDO> insertRecords = relIdList.stream()
|
||||
.map(s -> DataGroupRelDO.builder()
|
||||
.groupId(groupId)
|
||||
.type(group.getType())
|
||||
.relId(s)
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
dataGroupRelDAO.insertBatch(insertRecords);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addGroupRel(DataGroupRelCreateRequest request) {
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.orion.ops.module.infra.service.impl;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.enums.MovePosition;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
import com.orion.ops.module.infra.convert.DataGroupConvert;
|
||||
@@ -13,7 +15,8 @@ import com.orion.ops.module.infra.define.cache.DataGroupCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.DataGroupDO;
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupUpdateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupMoveRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRenameRequest;
|
||||
import com.orion.ops.module.infra.service.DataGroupRelService;
|
||||
import com.orion.ops.module.infra.service.DataGroupService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -63,7 +66,7 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer renameDataGroup(DataGroupUpdateRequest request) {
|
||||
public Integer renameDataGroup(DataGroupRenameRequest request) {
|
||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||
String name = Valid.notBlank(request.getName());
|
||||
// 查询
|
||||
@@ -77,6 +80,8 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
.build();
|
||||
// 查询数据是否冲突
|
||||
this.checkDataGroupPresent(updateRecord);
|
||||
// 添加日志参数
|
||||
OperatorLogs.add(OperatorLogs.BEFORE, record.getName());
|
||||
// 更新
|
||||
int effect = dataGroupDAO.updateById(updateRecord);
|
||||
// 删除缓存
|
||||
@@ -85,12 +90,71 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer moveDataGroup(DataGroupMoveRequest request) {
|
||||
Long id = request.getId();
|
||||
Long targetId = request.getTargetId();
|
||||
MovePosition position = Valid.valid(MovePosition::of, request.getPosition());
|
||||
// 查询节点是否存在
|
||||
DataGroupDO moveRecord = dataGroupDAO.selectById(id);
|
||||
DataGroupDO targetRecord = dataGroupDAO.selectById(targetId);
|
||||
Valid.notNull(moveRecord, ErrorMessage.GROUP_ABSENT);
|
||||
Valid.notNull(targetRecord, ErrorMessage.GROUP_ABSENT);
|
||||
// 更新
|
||||
String type = moveRecord.getType();
|
||||
Long targetParentId = targetRecord.getParentId();
|
||||
int effect = 0;
|
||||
// 修改排序
|
||||
if (MovePosition.TOP.equals(position)) {
|
||||
// 移动到元素上 将大于等于 targetRecord 的排序都加 10
|
||||
dataGroupDAO.updateSort(targetParentId, ">=",
|
||||
targetRecord.getSort(), Const.DEFAULT_SORT);
|
||||
// 修改 parentId sort
|
||||
DataGroupDO update = DataGroupDO.builder()
|
||||
.id(id)
|
||||
.parentId(targetParentId)
|
||||
.sort(targetRecord.getSort())
|
||||
.build();
|
||||
effect = dataGroupDAO.updateById(update);
|
||||
} else if (MovePosition.IN.equals(position)) {
|
||||
// 移动到元素中 获取最大排序
|
||||
Integer newSort = dataGroupDAO.selectMaxSort(targetId, type) + Const.DEFAULT_SORT;
|
||||
// 修改 parentId sort
|
||||
DataGroupDO update = DataGroupDO.builder()
|
||||
.id(id)
|
||||
.parentId(targetId)
|
||||
.sort(newSort)
|
||||
.build();
|
||||
effect = dataGroupDAO.updateById(update);
|
||||
} else if (MovePosition.BOTTOM.equals(position)) {
|
||||
// 移动到元素下 将大于 targetRecord 的排序都加 10
|
||||
dataGroupDAO.updateSort(targetParentId, ">",
|
||||
targetRecord.getSort(), Const.DEFAULT_SORT);
|
||||
// 修改 parentId sort
|
||||
DataGroupDO update = DataGroupDO.builder()
|
||||
.id(id)
|
||||
.parentId(targetParentId)
|
||||
.sort(targetRecord.getSort() + 1)
|
||||
.build();
|
||||
effect = dataGroupDAO.updateById(update);
|
||||
}
|
||||
// 删除缓存
|
||||
RedisStrings.delete(DataGroupCacheKeyDefine.DATA_GROUP_LIST.format(type),
|
||||
DataGroupCacheKeyDefine.DATA_GROUP_TREE.format(type));
|
||||
// 添加日志参数
|
||||
OperatorLogs.add(OperatorLogs.SOURCE, moveRecord.getName());
|
||||
OperatorLogs.add(OperatorLogs.TARGET, targetRecord.getName());
|
||||
OperatorLogs.add(OperatorLogs.POSITION_NAME, position.name());
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataGroupCacheDTO> getDataGroupListByCache(String type) {
|
||||
// 查询缓存
|
||||
String key = DataGroupCacheKeyDefine.DATA_GROUP_LIST.format(type);
|
||||
List<DataGroupCacheDTO> list = RedisStrings.getJsonArray(key, DataGroupCacheKeyDefine.DATA_GROUP_LIST);
|
||||
if (list.isEmpty()) {
|
||||
if (Lists.isEmpty(list)) {
|
||||
// 查询数据库
|
||||
list = dataGroupDAO.of()
|
||||
.createWrapper()
|
||||
@@ -116,7 +180,7 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
// 查询缓存
|
||||
String key = DataGroupCacheKeyDefine.DATA_GROUP_TREE.format(type);
|
||||
List<DataGroupCacheDTO> treeData = RedisStrings.getJsonArray(key, DataGroupCacheKeyDefine.DATA_GROUP_TREE);
|
||||
if (treeData.isEmpty()) {
|
||||
if (Lists.isEmpty(treeData)) {
|
||||
// 查询列表缓存
|
||||
List<DataGroupCacheDTO> rows = this.getDataGroupListByCache(type);
|
||||
// 添加默认值 防止穿透
|
||||
@@ -127,7 +191,7 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
} else {
|
||||
// 构建树
|
||||
DataGroupCacheDTO rootNode = DataGroupCacheDTO.builder()
|
||||
.parentId(Const.ROOT_PARENT_ID)
|
||||
.id(Const.ROOT_PARENT_ID)
|
||||
.sort(Const.DEFAULT_SORT)
|
||||
.build();
|
||||
this.buildGroupTree(rootNode, rows);
|
||||
@@ -151,7 +215,7 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
List<DataGroupCacheDTO> nodes) {
|
||||
// 获取子节点
|
||||
List<DataGroupCacheDTO> childrenNodes = nodes.stream()
|
||||
.filter(s -> parentNode.getParentId().equals(s.getParentId()))
|
||||
.filter(s -> parentNode.getId().equals(s.getParentId()))
|
||||
.sorted(Comparator.comparing(DataGroupCacheDTO::getSort))
|
||||
.collect(Collectors.toList());
|
||||
if (childrenNodes.isEmpty()) {
|
||||
@@ -183,6 +247,8 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
// 删除缓存
|
||||
RedisStrings.delete(DataGroupCacheKeyDefine.DATA_GROUP_LIST.format(type),
|
||||
DataGroupCacheKeyDefine.DATA_GROUP_TREE.format(type));
|
||||
// 添加日志参数
|
||||
OperatorLogs.add(OperatorLogs.NAME, record.getName());
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,13 @@
|
||||
id, parent_id, name, type, sort, create_time, update_time, creator, updater, deleted
|
||||
</sql>
|
||||
|
||||
<update id="updateSort">
|
||||
UPDATE data_group
|
||||
SET sort = sort + #{addition}
|
||||
WHERE parent_id = #{parentId}
|
||||
AND sort ${condition} #{referSort}
|
||||
</update>
|
||||
|
||||
<select id="selectMaxSort" resultType="java.lang.Integer">
|
||||
SELECT IFNULL(MAX(sort), 0)
|
||||
FROM data_group
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
import type { DataGrid, Pagination } from '@/types/global';
|
||||
import type { TableData } from '@arco-design/web-vue/es/table/interface';
|
||||
import axios from 'axios';
|
||||
import qs from 'query-string';
|
||||
|
||||
/**
|
||||
* 数据分组关联创建请求
|
||||
*/
|
||||
export interface DataGroupRelCreateRequest {
|
||||
groupId?: number;
|
||||
relId?: number;
|
||||
type?: string;
|
||||
sort?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据分组关联更新请求
|
||||
*/
|
||||
export interface DataGroupRelUpdateRequest extends DataGroupRelCreateRequest {
|
||||
id?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据分组关联查询请求
|
||||
*/
|
||||
export interface DataGroupRelQueryRequest extends Pagination {
|
||||
searchValue?: string;
|
||||
id?: number;
|
||||
groupId?: number;
|
||||
relId?: number;
|
||||
type?: string;
|
||||
sort?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据分组关联查询响应
|
||||
*/
|
||||
export interface DataGroupRelQueryResponse extends TableData {
|
||||
id: number;
|
||||
groupId: number;
|
||||
relId: number;
|
||||
type: string;
|
||||
sort: number;
|
||||
createTime: number;
|
||||
updateTime: number;
|
||||
creator: string;
|
||||
updater: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据分组关联
|
||||
*/
|
||||
export function createDataGroupRel(request: DataGroupRelCreateRequest) {
|
||||
return axios.post('/infra/data-group-rel/create', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据分组关联
|
||||
*/
|
||||
export function updateDataGroupRel(request: DataGroupRelUpdateRequest) {
|
||||
return axios.put('/infra/data-group-rel/update', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据分组关联
|
||||
*/
|
||||
export function getDataGroupRel(id: number) {
|
||||
return axios.get<DataGroupRelQueryResponse>('/infra/data-group-rel/get', { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量查询数据分组关联
|
||||
*/
|
||||
export function batchGetDataGroupRelList(idList: Array<number>) {
|
||||
return axios.get<DataGroupRelQueryResponse[]>('/infra/data-group-rel/batch-get', {
|
||||
params: { idList },
|
||||
paramsSerializer: params => {
|
||||
return qs.stringify(params, { arrayFormat: 'comma' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部数据分组关联
|
||||
*/
|
||||
export function getDataGroupRelList(request: DataGroupRelQueryRequest) {
|
||||
return axios.post<Array<DataGroupRelQueryResponse>>('/infra/data-group-rel/list', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询数据分组关联
|
||||
*/
|
||||
export function getDataGroupRelPage(request: DataGroupRelQueryRequest) {
|
||||
return axios.post<DataGrid<DataGroupRelQueryResponse>>('/infra/data-group-rel/query', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据分组关联
|
||||
*/
|
||||
export function deleteDataGroupRel(id: number) {
|
||||
return axios.delete('/infra/data-group-rel/delete', { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除数据分组关联
|
||||
*/
|
||||
export function batchDeleteDataGroupRel(idList: Array<number>) {
|
||||
return axios.delete('/infra/data-group-rel/batch-delete', {
|
||||
params: { idList },
|
||||
paramsSerializer: params => {
|
||||
return qs.stringify(params, { arrayFormat: 'comma' });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -9,47 +9,58 @@ export interface HostGroupCreateRequest {
|
||||
}
|
||||
|
||||
/**
|
||||
* 主机分组更新请求
|
||||
* 主机分组重命名请求
|
||||
*/
|
||||
export interface HostGroupUpdateRequest extends HostGroupCreateRequest {
|
||||
export interface HostGroupRenameRequest {
|
||||
id?: number;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主机分组查询请求
|
||||
* 主机分组移动请求
|
||||
*/
|
||||
export interface HostGroupQueryRequest {
|
||||
searchValue?: string;
|
||||
export interface HostGroupMoveRequest {
|
||||
id?: number;
|
||||
parentId?: number;
|
||||
name?: string;
|
||||
type?: string;
|
||||
sort?: number;
|
||||
targetId?: number;
|
||||
position?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主机分组查询响应
|
||||
*/
|
||||
export interface HostGroupQueryResponse {
|
||||
id: number;
|
||||
parentId: number;
|
||||
name: string;
|
||||
sort: number;
|
||||
key: number;
|
||||
title: string;
|
||||
children: Array<HostGroupQueryResponse>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组内主机修改请求
|
||||
*/
|
||||
export interface HostGroupRelUpdateRequest {
|
||||
groupId?: number;
|
||||
relIdList?: Array<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建主机分组
|
||||
*/
|
||||
export function createHostGroup(request: HostGroupCreateRequest) {
|
||||
return axios.post('/asset/host-group/create', request);
|
||||
return axios.post<number>('/asset/host-group/create', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新主机分组
|
||||
* 更新主机分组名称
|
||||
*/
|
||||
export function updateHostGroup(request: HostGroupUpdateRequest) {
|
||||
return axios.put('/asset/host-group/update', request);
|
||||
export function updateHostGroupName(request: HostGroupRenameRequest) {
|
||||
return axios.put('/asset/host-group/rename', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动主机分组
|
||||
*/
|
||||
export function moveHostGroup(request: HostGroupMoveRequest) {
|
||||
return axios.put('/asset/host-group/move', request);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,3 +76,17 @@ export function getHostGroupTree() {
|
||||
export function deleteHostGroup(id: number) {
|
||||
return axios.delete('/asset/host-group/delete', { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分组内主机
|
||||
*/
|
||||
export function getHostGroupRelList() {
|
||||
return axios.get<Array<number>>('/asset/host-group/rel-list');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分组内主机
|
||||
*/
|
||||
export function updateHostGroupRel(request: HostGroupRelUpdateRequest) {
|
||||
return axios.post('/asset/host-group/update-rel', request);
|
||||
}
|
||||
|
||||
@@ -135,10 +135,10 @@ body {
|
||||
cursor: pointer;
|
||||
border: 1px solid transparent;
|
||||
transition: background-color 0.1s cubic-bezier(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
.click-icon-wrapper:hover {
|
||||
&:hover {
|
||||
background: var(--color-fill-3);
|
||||
}
|
||||
}
|
||||
|
||||
// -- element
|
||||
|
||||
@@ -115,6 +115,19 @@
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
</li>
|
||||
<!-- 刷新页面 -->
|
||||
<li>
|
||||
<a-tooltip content="刷新页面">
|
||||
<a-button class="nav-btn"
|
||||
type="outline"
|
||||
shape="circle"
|
||||
@click="reloadCurrent">
|
||||
<template #icon>
|
||||
<icon-refresh />
|
||||
</template>
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
</li>
|
||||
<!-- 偏好设置 -->
|
||||
<li>
|
||||
<a-popover :popup-visible="tippedPreference" position="br">
|
||||
@@ -184,24 +197,30 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, inject, ref } from 'vue';
|
||||
import { useDark, useFullscreen, useToggle } from '@vueuse/core';
|
||||
import { useAppStore, useTipsStore, useUserStore } from '@/store';
|
||||
import { LOCALE_OPTIONS } from '@/locale';
|
||||
import useLocale from '@/hooks/locale';
|
||||
import useUser from '@/hooks/user';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useDark, useFullscreen, useToggle } from '@vueuse/core';
|
||||
import { useAppStore, useTabBarStore, useTipsStore, useUserStore } from '@/store';
|
||||
import { LOCALE_OPTIONS } from '@/locale';
|
||||
import { triggerMouseEvent } from '@/utils';
|
||||
import Menu from '@/components/system/menu/tree/index.vue';
|
||||
import MessageBox from '@/components/system/message-box/index.vue';
|
||||
import { openAppSettingKey, toggleDrawerMenuKey } from '@/types/symbol';
|
||||
import { preferenceTipsKey } from './const';
|
||||
import { REDIRECT_ROUTE_NAME, routerToTag } from '@/router/constants';
|
||||
import Menu from '@/components/system/menu/tree/index.vue';
|
||||
import UpdatePasswordModal from '@/components/user/role/update-password-modal.vue';
|
||||
import MessageBox from '@/components/system/message-box/index.vue';
|
||||
|
||||
const tipsStore = useTipsStore();
|
||||
const appStore = useAppStore();
|
||||
const userStore = useUserStore();
|
||||
const tabBarStore = useTabBarStore();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { logout } = useUser();
|
||||
const { changeLocale, currentLocale } = useLocale();
|
||||
const { isFullscreen, toggle: toggleFullScreen } = useFullscreen();
|
||||
|
||||
// 主题
|
||||
const darkTheme = useDark({
|
||||
selector: 'body',
|
||||
@@ -254,6 +273,23 @@
|
||||
triggerMouseEvent(localeRef);
|
||||
};
|
||||
|
||||
// 刷新页面
|
||||
const reloadCurrent = async () => {
|
||||
if (appStore.tabBar) {
|
||||
// 重新加载 tab
|
||||
const itemData = routerToTag(route);
|
||||
tabBarStore.deleteCache(itemData);
|
||||
await router.push({
|
||||
name: REDIRECT_ROUTE_NAME,
|
||||
params: { path: route.fullPath },
|
||||
});
|
||||
tabBarStore.addCache(itemData.name);
|
||||
} else {
|
||||
// 刷新页面
|
||||
router.go(0);
|
||||
}
|
||||
};
|
||||
|
||||
// 退出登录
|
||||
const handleLogout = async () => {
|
||||
await logout();
|
||||
|
||||
@@ -44,9 +44,7 @@
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* 监听路由变化
|
||||
*/
|
||||
// 监听路由变化
|
||||
listenerRouteChange((route: RouteLocationNormalized) => {
|
||||
if (
|
||||
!route.meta.noAffix &&
|
||||
|
||||
@@ -112,7 +112,8 @@
|
||||
const tagClose = (tag: TagProps, idx: number) => {
|
||||
tabBarStore.deleteTab(idx, tag);
|
||||
if (props.itemData.fullPath === route.fullPath) {
|
||||
const latest = tagList.value[idx - 1]; // 获取队列的前一个tab
|
||||
// 获取队列的前一个 tab
|
||||
const latest = tagList.value[idx - 1];
|
||||
router.push({ name: latest.name });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
import type { MenuQueryResponse } from '@/api/system/menu';
|
||||
import { useCacheStore } from '@/store';
|
||||
import { ref, watch } from 'vue';
|
||||
import { findNode, flatNodeKeys, flatNodes } from '@/utils/tree';
|
||||
|
||||
const cacheStore = useCacheStore();
|
||||
|
||||
@@ -75,39 +76,35 @@
|
||||
return checkedKeys.value;
|
||||
};
|
||||
|
||||
// 通过规则 选择/取消选择
|
||||
const checkOrUncheckByRule = (rule: undefined | ((s: string) => boolean), check: boolean) => {
|
||||
unTriggerChange.value = true;
|
||||
const nodes: Array<MenuQueryResponse> = [];
|
||||
flatNodes(menuData.value, nodes);
|
||||
if (rule) {
|
||||
const ruleNodes = nodes.filter(s => s.permission)
|
||||
.filter(s => rule(s?.permission))
|
||||
.map(s => s.id)
|
||||
.filter(Boolean);
|
||||
if (check) {
|
||||
// 选择
|
||||
const checked = (rule: undefined | ((s: string) => boolean)) => {
|
||||
unTriggerChange.value = true;
|
||||
const nodes: Array<MenuQueryResponse> = [];
|
||||
flatNodes(menuData.value, nodes);
|
||||
if (rule) {
|
||||
const checkedNodes = nodes.filter(s => s.permission)
|
||||
.filter(s => rule(s?.permission))
|
||||
.map(s => s.id)
|
||||
.filter(Boolean);
|
||||
checkedKeys.value = [...new Set([...checkedKeys.value, ...checkedNodes])];
|
||||
checkedKeys.value = [...new Set([...checkedKeys.value, ...ruleNodes])];
|
||||
} else {
|
||||
checkedKeys.value = nodes.map(s => s.id).filter(Boolean);
|
||||
}
|
||||
};
|
||||
|
||||
// 取消选择
|
||||
const unchecked = (rule: undefined | ((s: string) => boolean)) => {
|
||||
unTriggerChange.value = true;
|
||||
const nodes: Array<MenuQueryResponse> = [];
|
||||
flatNodes(menuData.value, nodes);
|
||||
if (rule) {
|
||||
const uncheckedNodes = nodes.filter(s => s.permission)
|
||||
.filter(s => rule(s?.permission))
|
||||
.map(s => s.id)
|
||||
.filter(Boolean);
|
||||
checkedKeys.value = [...checkedKeys.value].filter(s => !uncheckedNodes.includes(s));
|
||||
checkedKeys.value = [...checkedKeys.value].filter(s => !ruleNodes.includes(s));
|
||||
}
|
||||
} else {
|
||||
if (check) {
|
||||
// 选择
|
||||
checkedKeys.value = nodes.map(s => s.id).filter(Boolean);
|
||||
} else {
|
||||
// 取消选择
|
||||
checkedKeys.value = [];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({ init, getValue, checked, unchecked });
|
||||
defineExpose({ init, getValue, checkOrUncheckByRule });
|
||||
|
||||
// 监听级联变化
|
||||
watch(checkedKeys, (after: Array<number>, before: Array<number>) => {
|
||||
@@ -119,7 +116,7 @@
|
||||
const beforeLength = before.length;
|
||||
if (afterLength > beforeLength) {
|
||||
// 选择 一定是最后一个
|
||||
checkMenu(after[afterLength - 1]);
|
||||
checkOrUncheckMenu(after[afterLength - 1], true);
|
||||
} else if (afterLength < beforeLength) {
|
||||
// 取消
|
||||
let uncheckedId = null;
|
||||
@@ -132,74 +129,28 @@
|
||||
if (uncheckedId == null) {
|
||||
uncheckedId = before[beforeLength - 1];
|
||||
}
|
||||
uncheckMenu(uncheckedId);
|
||||
checkOrUncheckMenu(uncheckedId, false);
|
||||
}
|
||||
});
|
||||
|
||||
// fixme 提成公共方法
|
||||
// 寻找当前节点
|
||||
const findNode = (id: number, arr: Array<MenuQueryResponse>): MenuQueryResponse | undefined => {
|
||||
for (let node of arr) {
|
||||
if (node.id === id) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
// 寻找子级
|
||||
for (let node of arr) {
|
||||
if (node?.children?.length) {
|
||||
const inChildNode = findNode(id, node.children);
|
||||
if (inChildNode) {
|
||||
return inChildNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
// 获取所有子节点id
|
||||
const flatChildrenId = (nodes: MenuQueryResponse[] | undefined, result: number[]) => {
|
||||
if (!nodes || !nodes.length) {
|
||||
return;
|
||||
}
|
||||
for (let node of nodes) {
|
||||
result.push(node.id);
|
||||
if (node.children) {
|
||||
flatChildrenId(node.children, result);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 展开节点
|
||||
const flatNodes = (nodes: Array<MenuQueryResponse>, result: Array<MenuQueryResponse>) => {
|
||||
if (!nodes || !nodes.length) {
|
||||
return;
|
||||
}
|
||||
nodes.forEach(s => {
|
||||
result.push(s);
|
||||
flatNodes(s.children, result);
|
||||
});
|
||||
};
|
||||
|
||||
// 级联选择菜单
|
||||
const checkMenu = (id: number) => {
|
||||
// 级联选择/取消选择菜单
|
||||
const checkOrUncheckMenu = (id: number, check: boolean) => {
|
||||
unTriggerChange.value = true;
|
||||
// 查询当前节点
|
||||
const node = findNode(id, menuData.value);
|
||||
const node = findNode(id, menuData.value, 'id');
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
const childrenId: number[] = [];
|
||||
// 获取所在子节点id
|
||||
flatChildrenId(node?.children, childrenId);
|
||||
flatNodeKeys(node.children, childrenId, 'id');
|
||||
if (check) {
|
||||
// 选中
|
||||
checkedKeys.value = [...new Set([...checkedKeys.value, ...childrenId])];
|
||||
};
|
||||
|
||||
// 级联取消选择菜单
|
||||
const uncheckMenu = (id: number) => {
|
||||
unTriggerChange.value = true;
|
||||
// 查询当前节点
|
||||
const node = findNode(id, menuData.value);
|
||||
const childrenId: number[] = [];
|
||||
// 获取所在子节点id
|
||||
flatChildrenId(node?.children, childrenId);
|
||||
} else {
|
||||
// 取消选择
|
||||
checkedKeys.value = checkedKeys.value.filter(s => !childrenId.includes(s));
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- 按钮组 -->
|
||||
<a-button-group class="mb4">
|
||||
<!-- 全选 -->
|
||||
<a-button type="text" size="mini" @click="toggleChecked">
|
||||
{{ checkedKeys?.length === allCheckedKeys?.length ? '反选' : '全选' }}
|
||||
</a-button>
|
||||
<!-- 展开 -->
|
||||
<a-button type="text" size="mini" @click="toggleExpanded">
|
||||
{{ expandedKeys?.length ? '折叠' : '展开' }}
|
||||
</a-button>
|
||||
</a-button-group>
|
||||
<!-- 菜单树 -->
|
||||
<a-tree
|
||||
checked-strategy="child"
|
||||
:checkable="true"
|
||||
:animation="false"
|
||||
:only-check-leaf="true"
|
||||
v-model:checked-keys="checkedKeys"
|
||||
v-model:expanded-keys="expandedKeys"
|
||||
:data="treeData" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'menu-selector-tree'
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { TreeNodeData } from '@arco-design/web-vue';
|
||||
import { ref } from 'vue';
|
||||
import { useCacheStore } from '@/store';
|
||||
|
||||
const treeData = ref<Array<TreeNodeData>>([]);
|
||||
|
||||
const allCheckedKeys = ref<Array<number>>([]);
|
||||
const allExpandedKeys = ref<Array<number>>([]);
|
||||
|
||||
const checkedKeys = ref<Array<number>>([]);
|
||||
const expandedKeys = ref<Array<number>>([]);
|
||||
|
||||
// 修改选中状态
|
||||
const toggleChecked = () => {
|
||||
checkedKeys.value = checkedKeys.value.length === allCheckedKeys.value.length ? [] : allCheckedKeys.value;
|
||||
};
|
||||
|
||||
// 修改折叠状态
|
||||
const toggleExpanded = () => {
|
||||
expandedKeys.value = expandedKeys?.value.length ? [] : allExpandedKeys.value;
|
||||
};
|
||||
|
||||
// 循环选中的 key
|
||||
const eachAllCheckKeys = (arr: Array<any>) => {
|
||||
arr.forEach((item) => {
|
||||
allCheckedKeys.value.push(item.key);
|
||||
if (item.children && item.children.length) {
|
||||
eachAllCheckKeys(item.children);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 循环展开的 key
|
||||
const eachAllExpandKeys = (arr: Array<any>) => {
|
||||
arr.forEach((item) => {
|
||||
if (item.children && item.children.length) {
|
||||
allExpandedKeys.value.push(item.key);
|
||||
eachAllExpandKeys(item.children);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 渲染数据
|
||||
const init = (keys: Array<number>) => {
|
||||
// 初始化数据
|
||||
allCheckedKeys.value = [];
|
||||
allExpandedKeys.value = [];
|
||||
checkedKeys.value = keys;
|
||||
expandedKeys.value = [];
|
||||
|
||||
// 渲染菜单
|
||||
const cacheStore = useCacheStore();
|
||||
let render = (arr: any[]): TreeNodeData[] => {
|
||||
return arr.map((s) => {
|
||||
// 当前节点
|
||||
const node = {
|
||||
key: s.id,
|
||||
title: s.name,
|
||||
children: undefined as unknown
|
||||
} as TreeNodeData;
|
||||
// 子节点
|
||||
if (s.children && s.children.length) {
|
||||
node.children = render(s.children);
|
||||
}
|
||||
return node;
|
||||
}).filter(Boolean);
|
||||
};
|
||||
|
||||
// 加载菜单
|
||||
treeData.value = render([...cacheStore.menus]);
|
||||
// 加载所有选中的key
|
||||
eachAllCheckKeys(treeData.value);
|
||||
// 加载所有展开的key
|
||||
eachAllExpandKeys(treeData.value);
|
||||
};
|
||||
init([]);
|
||||
|
||||
// 获取值
|
||||
const getValue = () => {
|
||||
if (!checkedKeys.value.length) {
|
||||
return [];
|
||||
}
|
||||
// 查询子节点上级父节点
|
||||
const mixed: number[] = [];
|
||||
const findParent = (arr: Array<TreeNodeData>, key: number) => {
|
||||
for (let node of arr) {
|
||||
// 是子节点 并且相同
|
||||
if (node.key === key) {
|
||||
mixed.push(key);
|
||||
return true;
|
||||
}
|
||||
if (node.children?.length) {
|
||||
const isFind = findParent(node.children, key);
|
||||
if (isFind) {
|
||||
mixed.push(node.key as number);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// 设置所有节点
|
||||
for (let key of checkedKeys.value) {
|
||||
findParent(treeData.value, key);
|
||||
}
|
||||
return new Set(mixed);
|
||||
};
|
||||
|
||||
defineExpose({ init, getValue });
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
</style>;
|
||||
@@ -179,6 +179,13 @@ export const objectTruthKeyCount = (obj: any, ignore: string[] = []) => {
|
||||
}, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* 休眠
|
||||
*/
|
||||
export const sleep = (ms: number) => {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取当前页面的缩放值
|
||||
*/
|
||||
|
||||
153
orion-ops-ui/src/utils/tree.ts
Normal file
153
orion-ops-ui/src/utils/tree.ts
Normal file
@@ -0,0 +1,153 @@
|
||||
import type { NodeData } from '@/types/global';
|
||||
|
||||
// 寻找当前节点
|
||||
export const findNode = <T extends NodeData>(key: any,
|
||||
nodes: Array<T>,
|
||||
keyName = 'key'): T => {
|
||||
if (!nodes || !nodes.length) {
|
||||
return undefined as unknown as T;
|
||||
}
|
||||
for (let node of nodes) {
|
||||
if (node[keyName] === key) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
// 寻找子级
|
||||
for (let node of nodes) {
|
||||
if (node.children?.length) {
|
||||
const childrenNode = findNode(key, node.children, keyName);
|
||||
if (childrenNode) {
|
||||
return childrenNode as T;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined as unknown as T;
|
||||
};
|
||||
|
||||
// 寻找父节点
|
||||
export const findParentNode = <T extends NodeData>(key: any,
|
||||
nodes: Array<T>,
|
||||
keyName = 'key',
|
||||
parent = (undefined as unknown as T)): T => {
|
||||
if (!nodes || !nodes.length) {
|
||||
return undefined as unknown as T;
|
||||
}
|
||||
for (let node of nodes) {
|
||||
if (node[keyName] === key) {
|
||||
if (parent) {
|
||||
return parent;
|
||||
} else {
|
||||
// 根节点
|
||||
return {
|
||||
root: true
|
||||
} as unknown as T;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 寻找子级
|
||||
for (let node of nodes) {
|
||||
if (node.children?.length) {
|
||||
const parentNode = findParentNode(key, node.children, keyName, node);
|
||||
if (parentNode) {
|
||||
return parentNode as T;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined as unknown as T;
|
||||
};
|
||||
|
||||
// 级联寻找父节点
|
||||
export const findParentNodes = <T extends NodeData>(key: any,
|
||||
nodes: Array<T>,
|
||||
result: Array<T>,
|
||||
keyName = 'key',
|
||||
parent = ([] as T[])) => {
|
||||
if (!nodes || !nodes.length) {
|
||||
return;
|
||||
}
|
||||
for (let node of nodes) {
|
||||
if (node[keyName] === key) {
|
||||
result.push(...parent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 寻找子级
|
||||
for (let node of nodes) {
|
||||
if (node.children?.length) {
|
||||
const currentParent = [...parent, node];
|
||||
findParentNodes(key, node.children, result, keyName, currentParent);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 检查是否包含子节点 单层
|
||||
export const hasChildren = <T extends NodeData>(key: string,
|
||||
nodes: Array<T>,
|
||||
keyName = 'key'): boolean => {
|
||||
if (!nodes || !nodes.length) {
|
||||
return false;
|
||||
}
|
||||
return !!nodes.find(s => s[keyName] === key);
|
||||
};
|
||||
|
||||
// 获取所有节点 key
|
||||
export const flatNodeKeys = <T extends NodeData, R>(nodes: Array<T>,
|
||||
result: Array<R>,
|
||||
keyName = 'key') => {
|
||||
if (!nodes || !nodes.length) {
|
||||
return;
|
||||
}
|
||||
for (let node of nodes) {
|
||||
result.push(node[keyName]);
|
||||
flatNodeKeys(node.children, result, keyName);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取所有节点
|
||||
export const flatNodes = <T extends NodeData>(nodes: Array<T>,
|
||||
result: Array<T>) => {
|
||||
if (!nodes || !nodes.length) {
|
||||
return;
|
||||
}
|
||||
nodes.forEach(s => {
|
||||
result.push(s);
|
||||
flatNodes(s.children, result);
|
||||
});
|
||||
};
|
||||
|
||||
// 移动节点
|
||||
export const moveNode = (nodes: Array<NodeData>,
|
||||
dragNode: NodeData,
|
||||
dropNode: NodeData,
|
||||
dropPosition: number) => {
|
||||
// dropPosition === -1 将 dragNode 拖拽到 dropNode 上
|
||||
// dropPosition === 0 将 dragNode 拖拽到 dropNode 中
|
||||
// dropPosition === 1 将 dragNode 拖拽到 dropNode 下
|
||||
const loop = (data: NodeData, key: number, callback: any) => {
|
||||
data.some((item: NodeData, index: any, arr: NodeData[]) => {
|
||||
if (item.key === key) {
|
||||
callback(item, index, arr);
|
||||
return true;
|
||||
}
|
||||
if (item.children) {
|
||||
return loop(item.children, key, callback);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
loop(nodes, dragNode.key as number, (_: NodeData, index: number, arr: NodeData[]) => {
|
||||
arr.splice(index, 1);
|
||||
});
|
||||
|
||||
if (dropPosition === 0) {
|
||||
loop(nodes, dropNode.key as number, (item: NodeData) => {
|
||||
item.children = item.children || [];
|
||||
item.children?.push(dragNode);
|
||||
});
|
||||
} else {
|
||||
loop(nodes, dropNode.key as number, (_: NodeData, index: number, arr: NodeData[]) => {
|
||||
arr.splice(dropPosition < 0 ? index : index + 1, 0, dragNode);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,14 +1,22 @@
|
||||
<template>
|
||||
<!-- 分组树 -->
|
||||
<a-tree
|
||||
v-if="treeData.length"
|
||||
ref="tree"
|
||||
class="tree-container"
|
||||
:blockNode="true"
|
||||
:draggable="true"
|
||||
:data="treeData">
|
||||
:data="treeData"
|
||||
@drop="moveGroup">
|
||||
<!-- 标题 -->
|
||||
<template #title="node">
|
||||
<!-- 修改名称输入框 -->
|
||||
<template v-if="node.editable">
|
||||
<a-input size="mini"
|
||||
ref="renameInput"
|
||||
v-model="currName"
|
||||
placeholder="名称"
|
||||
autofocus
|
||||
:max-length="32"
|
||||
:disabled="node.loading"
|
||||
@blur="() => saveNode(node.key)"
|
||||
@@ -21,30 +29,52 @@
|
||||
<icon-check v-else
|
||||
class="pointer"
|
||||
title="保存"
|
||||
@click="saveNode(node.key)" />
|
||||
@click="() => saveNode(node.key)" />
|
||||
</template>
|
||||
</a-input>
|
||||
</template>
|
||||
|
||||
<span class="node-title" v-else>
|
||||
<!-- 名称 -->
|
||||
<span v-else
|
||||
class="node-title-wrapper"
|
||||
@click="() => emits('selectKey', node.key)">
|
||||
{{ node.title }}
|
||||
</span>
|
||||
</template>
|
||||
<!-- 操作图标 -->
|
||||
<template #drag-icon="{ node }">
|
||||
<a-space v-if="!node.editable">
|
||||
<icon-edit class="tree-icon"
|
||||
<!-- 重命名 -->
|
||||
<span v-permission="['asset:host-group:update']"
|
||||
class="tree-icon"
|
||||
title="重命名"
|
||||
@click="rename(node.title, node.key)" />
|
||||
<icon-delete class="tree-icon"
|
||||
title="删除"
|
||||
@click="rename(node.title, node.key)" />
|
||||
<icon-plus class="tree-icon"
|
||||
@click="rename(node.title, node.key)">
|
||||
<icon-edit />
|
||||
</span>
|
||||
<!-- 删除 -->
|
||||
<a-popconfirm content="确认删除这条记录吗?"
|
||||
position="left"
|
||||
type="warning"
|
||||
@ok="deleteNode(node.key)">
|
||||
<span v-permission="['asset:host-group:delete']"
|
||||
class="tree-icon" title="删除">
|
||||
<icon-delete />
|
||||
</span>
|
||||
</a-popconfirm>
|
||||
<!-- 新增 -->
|
||||
<span v-permission="['asset:host-group:create']"
|
||||
class="tree-icon"
|
||||
title="新增"
|
||||
@click="rename(node.title, node.key)" />
|
||||
@click="addChildren(node)">
|
||||
<icon-plus />
|
||||
</span>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-tree>
|
||||
<!-- 无数据 -->
|
||||
<div v-else-if="!loading" class="empty-container">
|
||||
<span>暂无数据</span>
|
||||
<span>点击上方 '<icon-plus />' 添加一个分组吧~</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
@@ -55,51 +85,25 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { TreeNodeData } from '@arco-design/web-vue';
|
||||
import type { NodeData } from '@/types/global';
|
||||
import { nextTick, ref } from 'vue';
|
||||
import { nextTick, onMounted, ref } from 'vue';
|
||||
import { createGroupGroupPrefix, rootId } from '../types/const';
|
||||
import { findNode, findParentNode, moveNode } from '@/utils/tree';
|
||||
import { createHostGroup, deleteHostGroup, getHostGroupTree, updateHostGroupName, moveHostGroup } from '@/api/asset/host-group';
|
||||
import { isString } from '@/utils/is';
|
||||
|
||||
const props = defineProps({
|
||||
loading: Boolean
|
||||
});
|
||||
const emits = defineEmits(['loading', 'selectKey']);
|
||||
|
||||
const tree = ref();
|
||||
const modCount = ref(0);
|
||||
const renameInput = ref();
|
||||
const currName = ref();
|
||||
|
||||
// 提为工具 utils tree.js
|
||||
function sleep(ms: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
// 保存节点
|
||||
const saveNode = async (key: string) => {
|
||||
// 寻找节点
|
||||
const node = findNode<TreeNodeData>(key, treeData.value);
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
if (currName.value) {
|
||||
node.loading = true;
|
||||
try {
|
||||
if (key.startsWith('create')) {
|
||||
// 调用创建 api
|
||||
await sleep(340);
|
||||
node.key = 'await id';
|
||||
} else {
|
||||
// 调用重命名 api
|
||||
await sleep(340);
|
||||
}
|
||||
node.title = currName.value;
|
||||
} catch (e) {
|
||||
} finally {
|
||||
node.loading = false;
|
||||
}
|
||||
} else {
|
||||
if (key.startsWith('create')) {
|
||||
// 寻找父节点
|
||||
// 移除子节点
|
||||
}
|
||||
}
|
||||
node.editable = false;
|
||||
};
|
||||
const treeData = ref<Array<TreeNodeData>>([]);
|
||||
|
||||
// 重命名
|
||||
const rename = (title: string, key: string) => {
|
||||
const rename = (title: number, key: number) => {
|
||||
const node = findNode<TreeNodeData>(key, treeData.value);
|
||||
if (!node) {
|
||||
return;
|
||||
@@ -111,132 +115,181 @@
|
||||
});
|
||||
};
|
||||
|
||||
// 寻找当前节点
|
||||
const findNode = <T extends NodeData>(id: string, arr: Array<T>): T | undefined => {
|
||||
for (let node of arr) {
|
||||
if (node.key === id) {
|
||||
return node;
|
||||
// 删除节点
|
||||
const deleteNode = async (key: number) => {
|
||||
try {
|
||||
emits('loading', true);
|
||||
// 删除
|
||||
await deleteHostGroup(key);
|
||||
// 页面删除
|
||||
const parentNode = findParentNode<TreeNodeData>(key, treeData.value);
|
||||
if (!parentNode) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 寻找子级
|
||||
for (let node of arr) {
|
||||
if (node?.children?.length) {
|
||||
const inChildNode = findNode(id, node.children);
|
||||
if (inChildNode) {
|
||||
return inChildNode as T;
|
||||
const children = parentNode.root ? treeData.value : parentNode.children;
|
||||
if (children) {
|
||||
// 删除
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
if (children[i].key === key) {
|
||||
children.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
} catch (e) {
|
||||
} finally {
|
||||
emits('loading', false);
|
||||
}
|
||||
};
|
||||
|
||||
function onIconClick(node: any) {
|
||||
const children = node.children || [];
|
||||
children.push({
|
||||
title: 'new tree node',
|
||||
key: node.key + '-' + (children.length + 1)
|
||||
// 新增根节点
|
||||
const addRootNode = () => {
|
||||
const newKey = `${createGroupGroupPrefix}${Date.now()}`;
|
||||
treeData.value.push({
|
||||
title: 'new',
|
||||
key: newKey
|
||||
});
|
||||
node.children = children;
|
||||
// 编辑子节点
|
||||
const newNode = findNode<TreeNodeData>(newKey, treeData.value);
|
||||
if (newNode) {
|
||||
newNode.editable = true;
|
||||
currName.value = '';
|
||||
nextTick(() => {
|
||||
renameInput.value?.focus();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 新增子节点
|
||||
const addChildren = (parentNode: TreeNodeData) => {
|
||||
const newKey = `${createGroupGroupPrefix}${Date.now()}`;
|
||||
const children = parentNode.children || [];
|
||||
children.push({
|
||||
title: 'new',
|
||||
key: newKey
|
||||
});
|
||||
parentNode.children = children;
|
||||
treeData.value = [...treeData.value];
|
||||
nextTick(() => {
|
||||
// 展开
|
||||
tree.value.expandNode(parentNode.key);
|
||||
// 编辑子节点
|
||||
const newNode = findNode<TreeNodeData>(newKey, treeData.value);
|
||||
if (newNode) {
|
||||
newNode.editable = true;
|
||||
currName.value = '';
|
||||
nextTick(() => {
|
||||
renameInput.value?.focus();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const treeData = ref(
|
||||
[
|
||||
{
|
||||
title: 'Trunk',
|
||||
key: '0-0',
|
||||
children: [
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-0-1',
|
||||
},
|
||||
{
|
||||
title: 'Branch',
|
||||
key: '0-0-2',
|
||||
children: [
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-0-2-1'
|
||||
// 保存节点
|
||||
const saveNode = async (key: string | number) => {
|
||||
modCount.value++;
|
||||
if (modCount.value !== 1) {
|
||||
return;
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
// 寻找节点
|
||||
const node = findNode<TreeNodeData>(key, treeData.value);
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
if (currName.value) {
|
||||
node.loading = true;
|
||||
try {
|
||||
// 创建节点
|
||||
if (isString(key) && key.startsWith(createGroupGroupPrefix)) {
|
||||
const parent = findParentNode<TreeNodeData>(key, treeData.value);
|
||||
if (parent.root) {
|
||||
parent.key = rootId;
|
||||
}
|
||||
// 创建
|
||||
const { data } = await createHostGroup({
|
||||
parentId: parent.key as number,
|
||||
name: currName.value
|
||||
});
|
||||
node.key = data;
|
||||
} else {
|
||||
// 重命名节点
|
||||
await updateHostGroupName({
|
||||
id: key as unknown as number,
|
||||
name: currName.value
|
||||
});
|
||||
}
|
||||
node.title = currName.value;
|
||||
node.editable = false;
|
||||
} catch (e) {
|
||||
// 重复 重新聚焦
|
||||
setTimeout(() => {
|
||||
renameInput.value?.focus();
|
||||
}, 100);
|
||||
} finally {
|
||||
node.loading = false;
|
||||
}
|
||||
} else {
|
||||
// 未输入数据 并且为创建则移除节点
|
||||
if (isString(key) && key.startsWith(createGroupGroupPrefix)) {
|
||||
// 寻找父节点
|
||||
const parent = findParentNode(key, treeData.value);
|
||||
if (parent && parent.children) {
|
||||
// 移除子节点
|
||||
for (let i = 0; i < parent.children.length; i++) {
|
||||
if (parent.children[i].key === key) {
|
||||
parent.children.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
node.editable = false;
|
||||
}
|
||||
modCount.value = 0;
|
||||
};
|
||||
|
||||
// 移动分组
|
||||
const moveGroup = async (
|
||||
{
|
||||
title: 'Trunk',
|
||||
key: '0-1',
|
||||
children: [
|
||||
{
|
||||
title: 'Branch',
|
||||
key: '0-1-1',
|
||||
children: [
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-1-1-11',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-1-1-12',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-1-1-13',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-1-1-41',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-1-1-51',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-1-1-61',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-1-17-1',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-1-81-1',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-19-1-1',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-10-1-1',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-1-111-1',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-21-1-1',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-31-1-1',
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '40-1-1-2',
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
title: 'Leaf',
|
||||
key: '0-1-2',
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
);
|
||||
dragNode, dropNode, dropPosition
|
||||
}: {
|
||||
dragNode: TreeNodeData,
|
||||
dropNode: TreeNodeData,
|
||||
dropPosition: number
|
||||
}) => {
|
||||
try {
|
||||
emits('loading', true);
|
||||
// 移动
|
||||
await moveHostGroup({
|
||||
id: dragNode.key as number,
|
||||
targetId: dropNode.key as number,
|
||||
position: dropPosition
|
||||
});
|
||||
// 移动分组
|
||||
moveNode(treeData.value, dragNode, dropNode, dropPosition);
|
||||
} catch (e) {
|
||||
} finally {
|
||||
emits('loading', false);
|
||||
}
|
||||
};
|
||||
|
||||
// 加载数据
|
||||
const fetchTreeData = async () => {
|
||||
try {
|
||||
emits('loading', true);
|
||||
const { data } = await getHostGroupTree();
|
||||
treeData.value = data;
|
||||
} catch {
|
||||
} finally {
|
||||
emits('loading', false);
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({ addRootNode, fetchTreeData });
|
||||
|
||||
onMounted(() => {
|
||||
fetchTreeData();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@@ -246,6 +299,15 @@
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.empty-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
padding-top: 25px;
|
||||
color: var(--color-text-3);
|
||||
}
|
||||
|
||||
:deep(.arco-tree-node-selected) {
|
||||
.arco-tree-node-title {
|
||||
&:hover {
|
||||
@@ -268,25 +330,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
.node-title {
|
||||
|
||||
}
|
||||
|
||||
.node-handler {
|
||||
|
||||
}
|
||||
|
||||
:deep(.arco-tree-node-selected) {
|
||||
background-color: var(--color-fill-2);
|
||||
}
|
||||
|
||||
.node-title-wrapper {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tree-icon {
|
||||
font-size: 12px;
|
||||
color: rgb(var(--primary-6));
|
||||
}
|
||||
|
||||
.drag-icon {
|
||||
padding-left: -8px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,22 +1,41 @@
|
||||
<template>
|
||||
<!-- 左侧菜单 -->
|
||||
<div class="simple-card tree-card">
|
||||
<a-spin class="simple-card tree-card"
|
||||
:loading="treeLoading">
|
||||
<!-- 主机分组头部 -->
|
||||
<div class="tree-card-header">
|
||||
<!-- 标题 -->
|
||||
<div class="tree-card-title">
|
||||
主机菜单
|
||||
</div>
|
||||
<!-- 操作 -->
|
||||
<div class="tree-card-handler">
|
||||
<div v-permission="['asset:host-group:create']"
|
||||
class="click-icon-wrapper handler-icon-wrapper"
|
||||
title="根节点添加"
|
||||
@click="addRootNode">
|
||||
<icon-plus />
|
||||
</div>
|
||||
<div class="click-icon-wrapper handler-icon-wrapper"
|
||||
title="刷新"
|
||||
@click="refreshTree">
|
||||
<icon-refresh />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 主机分组树 -->
|
||||
<div class="tree-card-main">
|
||||
<host-group-tree ref="tree" />
|
||||
</div>
|
||||
<host-group-tree ref="tree"
|
||||
:loading="treeLoading"
|
||||
@loading="setTreeLoading"
|
||||
@select-key="selectGroup" />
|
||||
</div>
|
||||
</a-spin>
|
||||
<!-- 身体部分 -->
|
||||
<div class="simple-card view-body">
|
||||
右侧数据
|
||||
</div>
|
||||
<a-spin class="simple-card view-body"
|
||||
:loading="dataLoading">
|
||||
<host-transfer ref="transfer" />
|
||||
</a-spin>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
@@ -26,13 +45,36 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import useLoading from '@/hooks/loading';
|
||||
import HostGroupTree from './host-group-tree.vue';
|
||||
import HostTransfer from './host-transfer.vue';
|
||||
|
||||
const { loading: treeLoading, setLoading: setTreeLoading } = useLoading();
|
||||
const { loading: dataLoading, setLoading: setDataLoading } = useLoading();
|
||||
|
||||
const tree = ref();
|
||||
const transfer = ref();
|
||||
|
||||
// 添加根节点
|
||||
const addRootNode = () => {
|
||||
tree.value.addRootNode();
|
||||
};
|
||||
|
||||
// 刷新树
|
||||
const refreshTree = () => {
|
||||
tree.value.fetchTreeData();
|
||||
};
|
||||
|
||||
// 选中分组
|
||||
const selectGroup = (key: number) => {
|
||||
console.log(key);
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@tree-width: 26%;
|
||||
@tree-width: 50%;
|
||||
|
||||
.tree-card {
|
||||
margin-right: 16px;
|
||||
@@ -44,11 +86,12 @@
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0 16px;
|
||||
padding: 0 8px 0 16px;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
border-bottom: 1px var(--color-border-2) solid;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
&-title {
|
||||
@@ -60,6 +103,17 @@
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
&-handler {
|
||||
display: flex;
|
||||
|
||||
.handler-icon-wrapper {
|
||||
margin-left: 8px;
|
||||
color: rgb(var(--primary-6));
|
||||
padding: 4px;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
&-main {
|
||||
padding: 8px 8px 8px 16px;
|
||||
position: relative;
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
<template>
|
||||
<div class="transfer-container">
|
||||
<!-- 头部 -->
|
||||
<div class="transfer-header">
|
||||
<!-- 提示 -->
|
||||
<a-alert class="alert-wrapper">123123</a-alert>
|
||||
<!-- 保存按钮 -->
|
||||
<a-button class="save-button"
|
||||
type="primary"
|
||||
@click="save">
|
||||
保存
|
||||
<template #icon>
|
||||
<icon-check />
|
||||
</template>
|
||||
</a-button>
|
||||
</div>
|
||||
<!-- 传输框 -->
|
||||
<a-transfer v-model="value"
|
||||
:data="data"
|
||||
:source-input-search-props="{ placeholder:'请输入主机名称/编码/IP' }"
|
||||
:target-input-search-props="{ placeholder:'请输入主机名称/编码/IP' }"
|
||||
show-search
|
||||
one-way>
|
||||
<!-- 主机列表 -->
|
||||
<template #source-title="{ countTotal, countSelected, checked, indeterminate, onSelectAllChange}">
|
||||
<!-- 左侧标题 -->
|
||||
<div class="source-title-container">
|
||||
<a-checkbox style="margin-right: 8px;"
|
||||
:model-value="checked"
|
||||
:indeterminate="indeterminate"
|
||||
@change="onSelectAllChange" />
|
||||
<span>
|
||||
主机列表 {{ countSelected }} / {{ countTotal }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 右侧标题 -->
|
||||
<template #target-title="{ countTotal, countSelected, onClear }">
|
||||
<div class="target-title-container">
|
||||
<span>已选择 <span class="span-blue">{{ countTotal }}</span> 个</span>
|
||||
<span class="pointer"
|
||||
@click="onClear"
|
||||
title="清空">
|
||||
<icon-delete />
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</a-transfer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'host-transfer'
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { TransferItem } from '@arco-design/web-vue/es/transfer/interface';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useCacheStore } from '@/store';
|
||||
|
||||
const data = ref<Array<TransferItem>>([]);
|
||||
const value = ref([]);
|
||||
|
||||
// 保存
|
||||
const save = () => {
|
||||
console.log(value.value);
|
||||
};
|
||||
|
||||
// 加载主机
|
||||
onMounted(() => {
|
||||
const cacheStore = useCacheStore();
|
||||
data.value = Array(200).fill(undefined).map((_, index) => ({
|
||||
value: `option${index + 1}`,
|
||||
label: `Option ${index + 1}`,
|
||||
disabled: false
|
||||
}));
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.transfer-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
.transfer-header {
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.alert-wrapper {
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
.save-button {
|
||||
margin-left: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.arco-transfer) {
|
||||
height: calc(100% - 44px);
|
||||
|
||||
.arco-transfer-view {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.arco-transfer-view-target {
|
||||
|
||||
.arco-transfer-list-item-content {
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.arco-transfer-list-item-remove-btn {
|
||||
margin-right: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.source-title-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.target-title-container {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
svg {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -51,7 +51,6 @@
|
||||
// 加载用户列表
|
||||
|
||||
// 加载主机列表
|
||||
|
||||
render.value = true;
|
||||
});
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export const tabItems = [{
|
||||
key: tabItemKeys.SETTING,
|
||||
text: '分组配置',
|
||||
icon: 'icon-unordered-list',
|
||||
permission: []
|
||||
permission: ['asset:host-group:query']
|
||||
}, {
|
||||
key: tabItemKeys.ROLE_GRANT,
|
||||
text: '角色授权',
|
||||
@@ -22,3 +22,9 @@ export const tabItems = [{
|
||||
icon: 'icon-user',
|
||||
permission: []
|
||||
}];
|
||||
|
||||
// 创建前缀
|
||||
export const createGroupGroupPrefix = 'create-';
|
||||
|
||||
// 根id
|
||||
export const rootId = 0;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<template #title>
|
||||
{{ $t('workplace.categoriesPercent') }}
|
||||
</template>
|
||||
<Chart height="310px" :option="chartOption" />
|
||||
<chart height="310px" :option="chartOption" />
|
||||
</a-card>
|
||||
</a-spin>
|
||||
</template>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<template #extra>
|
||||
<a-link>{{ $t('workplace.viewMore') }}</a-link>
|
||||
</template>
|
||||
<Chart height="289px" :option="chartOption" />
|
||||
<chart height="289px" :option="chartOption" />
|
||||
</a-card>
|
||||
</a-spin>
|
||||
</template>
|
||||
|
||||
@@ -190,6 +190,7 @@
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import { useCacheStore, useDictStore } from '@/store';
|
||||
import usePermission from '@/hooks/permission';
|
||||
import { findParentNode } from '@/utils/tree';
|
||||
|
||||
const { toOptions, getDictValue, toggleDictValue } = useDictStore();
|
||||
const cacheStore = useCacheStore();
|
||||
@@ -215,36 +216,23 @@
|
||||
setFetchLoading(true);
|
||||
// 调用删除接口
|
||||
await deleteMenu(id);
|
||||
|
||||
// 获取父菜单
|
||||
const findParentMenu = (arr: any, id: number): any => {
|
||||
if (!arr || !arr.length) {
|
||||
return null;
|
||||
}
|
||||
// 当前级
|
||||
for (let e of arr) {
|
||||
if (e.id === id) {
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
// 子级
|
||||
for (let e of arr) {
|
||||
if (e.children && e.children.length) {
|
||||
if (findParentMenu(e.children, id)) {
|
||||
return e.children;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// 获取父级容器
|
||||
const parent = findParentMenu(tableRenderData.value, id) as unknown as MenuQueryResponse[];
|
||||
const parent = findParentNode(id, tableRenderData.value, 'id');
|
||||
if (parent) {
|
||||
// 页面删除 不重新调用接口
|
||||
let children;
|
||||
if (parent.root) {
|
||||
children = tableRenderData.value;
|
||||
} else {
|
||||
children = parent.children;
|
||||
}
|
||||
if (children) {
|
||||
// 删除
|
||||
for (let i = 0; i < parent.length; i++) {
|
||||
if (parent[i].id === id) {
|
||||
parent.splice(i, 1);
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
if (children[i].id === id) {
|
||||
children.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<div class="usn mb8">
|
||||
<a-space>
|
||||
<template v-for="opt of quickGrantMenuOperator" :key="opt.name">
|
||||
<a-button size="mini" type="text" @click="() => { table.checked(opt.rule) }">
|
||||
<a-button size="mini" type="text" @click="() => { table.checkOrUncheckByRule(opt.rule, true) }">
|
||||
{{ '全选' + opt.name }}
|
||||
</a-button>
|
||||
</template>
|
||||
@@ -32,7 +32,7 @@
|
||||
<div class="usn mb8">
|
||||
<a-space>
|
||||
<template v-for="opt of quickGrantMenuOperator" :key="opt.name">
|
||||
<a-button size="mini" type="text" @click="() => { table.unchecked(opt.rule) }">
|
||||
<a-button size="mini" type="text" @click="() => { table.checkOrUncheckByRule(opt.rule, false) }">
|
||||
{{ '反选' + opt.name }}
|
||||
</a-button>
|
||||
</template>
|
||||
|
||||
@@ -12,7 +12,7 @@ const addType = ['add', 'create'];
|
||||
const updateType = ['update', 'modify'];
|
||||
const deleteType = ['delete', 'remove'];
|
||||
const standardRead = [...queryType];
|
||||
const standardWrite = [...addType, ...updateType, ...deleteType];
|
||||
const standardWrite = [...addType, ...updateType];
|
||||
|
||||
// 快速分配菜单操作
|
||||
export const quickGrantMenuOperator = [
|
||||
|
||||
Reference in New Issue
Block a user