🔨 优化主机逻辑.

This commit is contained in:
lijiahangmax
2025-03-16 00:20:18 +08:00
parent d071ef64d8
commit 0db732fc19
12 changed files with 21 additions and 76 deletions

View File

@@ -85,7 +85,7 @@ public class HostGroupController {
@OperatorLog(HostGroupOperatorType.RENAME)
@PutMapping("/rename")
@Operation(summary = "修改名称")
@PreAuthorize("@ss.hasPermission('asset:host-group:update')")
@PreAuthorize("@ss.hasAnyPermission('asset:host-group:update', 'asset:host:query')")
public Integer updateHostGroupName(@Validated @RequestBody DataGroupRenameDTO request) {
return hostGroupService.updateHostGroupName(request);
}
@@ -112,7 +112,7 @@ public class HostGroupController {
@GetMapping("/rel-list")
@Operation(summary = "查询分组内主机")
@Parameter(name = "groupId", description = "groupId", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-group:update')")
@PreAuthorize("@ss.hasAnyPermission('asset:host-group:update', 'asset:host:query')")
public Set<Long> queryHostGroupRel(@RequestParam("groupId") Long groupId) {
return hostGroupService.queryHostGroupRel(groupId);
}

View File

@@ -28,10 +28,7 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.List;
@@ -78,6 +75,7 @@ public class HostCreateRequest implements Serializable {
@Schema(description = "主机端口")
private Integer port;
@NotEmpty
@Schema(description = "主机分组")
private List<Long> groupIdList;

View File

@@ -76,6 +76,7 @@ public class HostUpdateRequest implements Serializable {
@Schema(description = "主机端口")
private Integer port;
@NotEmpty
@Schema(description = "主机分组")
private List<Long> groupIdList;

View File

@@ -47,7 +47,7 @@
const initOptions = async () => {
setLoading(true);
try {
treeData.value = await cacheStore.loadHostGroups();
treeData.value = await cacheStore.loadHostGroupTree();
} catch (e) {
} finally {
setLoading(false);

View File

@@ -310,7 +310,7 @@
const fetchTreeData = async (force = false) => {
try {
emits('setLoading', true);
const groups = await cacheStore.loadHostGroups(force);
const groups = await cacheStore.loadHostGroupTree(force);
treeData.value = groups || [];
} catch (e) {
} finally {

View File

@@ -93,9 +93,9 @@ export default defineStore('cache', {
return await this.load('menus', () => getMenuList({}), ['infra:system-menu:query'], force);
},
// 获取主机分组列表
async loadHostGroups(force = false) {
return await this.load('hostGroups', getHostGroupTree, ['asset:host-group:update'], force);
// 获取主机分组
async loadHostGroupTree(force = false) {
return await this.load('hostGroups', getHostGroupTree, ['asset:host-group:update', 'asset:host:query'], force);
},
// 获取主机列表

View File

@@ -1,8 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import type { TreeNodeData } from '@arco-design/web-vue';
import type { NodeData } from './global';
declare module '@arco-design/web-vue' {
interface TreeNodeData extends NodeData {
export interface TreeNodeData extends TreeNodeData, NodeData {
}
}

View File

@@ -1,9 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import type { AxiosRequestConfig } from 'axios';
declare module 'axios' {
// eslint-disable-next-line no-shadow
export interface AxiosRequestConfig {
export interface AxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
// 是否添加 Authorization
setAuthorization?: boolean;
// 是否使用原始返回

View File

@@ -1,5 +1,3 @@
import { isEmptyStr } from './index';
/**
* 获取 base64 实际数据
*/
@@ -56,7 +54,7 @@ export function getPathAnalysis(path: string, paths: PathAnalysis[] = []): PathA
return paths;
}
const name = path.substring(lastSeparatorIndex, path.length);
if (!isEmptyStr(name) && name !== '/') {
if (name && name !== '/') {
paths.unshift({
name: name.substring(1, name.length),
path: path

View File

@@ -51,13 +51,6 @@ export function dataColor(str: string, colors: string[], defaultColor = ''): str
return colors[total % colors.length];
}
/**
* 判断值是否非空
*/
export function isEmptyStr(val: any) {
return typeof (val) === 'undefined' || val == null || val === '';
}
export const YMD_HMS = 'yyyy-MM-dd HH:mm:ss';
/**
@@ -144,54 +137,6 @@ export function toAnonymousNumber(value: string | undefined): number {
}
}
/**
* 格式化数字为 ,分割
*/
export function formatNumber(value: number = 0) {
const list = (value + '').split('.');
const prefix = list[0].charAt(0) === '-' ? '-' : '';
let num = prefix ? list[0].slice(1) : list[0];
let result = '';
while (num.length > 3) {
result = `,${num.slice(-3)}${result}`;
num = num.slice(0, num.length - 3);
}
if (num) {
result = num + result;
}
return `${prefix}${result}${list[1] ? `.${list[1]}` : ''}`;
}
/**
* 判断是否为数字
*/
export function isNumber(value: any, decimal = true, negative = true) {
let reg;
if (decimal && negative) {
reg = /^-?[0-9]*(\.[0-9]*)?$/;
} else if (!decimal && negative) {
reg = /^-?[0-9]*$/;
} else if (decimal && !negative) {
reg = /^[0-9]*(\.[0-9]*)?$/;
} else if (!decimal && !negative) {
reg = /^[0-9]*$/;
} else {
return false;
}
return (!isNaN(value) && reg.test(value)) || value === '';
}
/**
* 替换数字
*/
export function replaceNumber(value: string) {
const s = value.charAt(value.length - 1);
if (s === '.' || s === '-') {
return s.substring(0, value.length - 1);
}
return value;
}
/**
* 重设对象
*/

View File

@@ -151,7 +151,7 @@
// 全选
const selectAll = async () => {
// 从缓存中查询全部分组
const groups = await cacheStore.loadHostGroups();
const groups = await cacheStore.loadHostGroupTree();
const groupKeys: number[] = [];
flatNodeKeys(groups, groupKeys);
checkedGroups.value = groupKeys;
@@ -160,7 +160,7 @@
// 反选
const reverseSelect = async () => {
// 从缓存中查询全部分组
const groups = await cacheStore.loadHostGroups();
const groups = await cacheStore.loadHostGroupTree();
const groupKeys: number[] = [];
flatNodeKeys(groups, groupKeys);
checkedGroups.value = groupKeys.filter(s => !checkedGroups.value.includes(s));

View File

@@ -44,6 +44,11 @@ export const port = [{
message: '输入的端口不合法'
}] as FieldRule[];
export const groupIdList = [{
required: true,
message: '请选择主机分组'
}] as FieldRule[];
export const tags = [{
maxLength: 5,
message: '最多选择5个标签'
@@ -61,6 +66,7 @@ export default {
code,
address,
port,
groupIdList,
tags,
description,
} as Record<string, FieldRule | FieldRule[]>;