⚡ 修改终端提示.
This commit is contained in:
@@ -63,7 +63,7 @@ public class AssetAuthorizedDataServiceController {
|
|||||||
@IgnoreLog(IgnoreLogMode.RET)
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
@GetMapping("/current-host")
|
@GetMapping("/current-host")
|
||||||
@Operation(summary = "查询当前用户已授权的主机")
|
@Operation(summary = "查询当前用户已授权的主机")
|
||||||
public AuthorizedHostWrapperVO getCurrentAuthorizedHost(@RequestParam("type") String type) {
|
public AuthorizedHostWrapperVO getCurrentAuthorizedHost(@RequestParam(value = "type", required = false) String type) {
|
||||||
return assetAuthorizedDataService.getUserAuthorizedHost(SecurityUtils.getLoginUserId(), type);
|
return assetAuthorizedDataService.getUserAuthorizedHost(SecurityUtils.getLoginUserId(), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,17 @@ public interface TerminalConnectLogDAO extends IMapper<TerminalConnectLogDO> {
|
|||||||
* @param limit limit
|
* @param limit limit
|
||||||
* @return hostId
|
* @return hostId
|
||||||
*/
|
*/
|
||||||
List<Long> selectLatestConnectHostId(@Param("userId") Long userId, @Param("type") String type, @Param("limit") Integer limit);
|
default List<Long> selectLatestConnectHostId(Long userId, String type, Integer limit) {
|
||||||
|
return this.of()
|
||||||
|
.createWrapper(true)
|
||||||
|
.select(TerminalConnectLogDO::getHostId)
|
||||||
|
.eq(TerminalConnectLogDO::getUserId, userId)
|
||||||
|
.eq(TerminalConnectLogDO::getType, type)
|
||||||
|
.orderByDesc(TerminalConnectLogDO::getId)
|
||||||
|
.then()
|
||||||
|
.limit(limit)
|
||||||
|
.list(TerminalConnectLogDO::getHostId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询终端连接日志用户数量
|
* 查询终端连接日志用户数量
|
||||||
|
|||||||
@@ -33,16 +33,6 @@
|
|||||||
id, user_id, username, host_id, host_name, host_address, type, session_id, status, start_time, end_time, extra_info, create_time, update_time, deleted
|
id, user_id, username, host_id, host_name, host_address, type, session_id, status, start_time, end_time, extra_info, create_time, update_time, deleted
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectLatestConnectHostId" resultType="java.lang.Long">
|
|
||||||
SELECT host_id
|
|
||||||
FROM terminal_connect_log
|
|
||||||
WHERE deleted = 0
|
|
||||||
AND type = #{type}
|
|
||||||
AND user_id = #{userId}
|
|
||||||
ORDER BY id DESC
|
|
||||||
LIMIT #{limit}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectConnectLogUserCount" resultMap="CountResultMap">
|
<select id="selectConnectLogUserCount" resultMap="CountResultMap">
|
||||||
SELECT DATE(create_time) connect_date, COUNT(1) total_count
|
SELECT DATE(create_time) connect_date, COUNT(1) total_count
|
||||||
FROM terminal_connect_log
|
FROM terminal_connect_log
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
v-model:selected-group="selectedGroup"
|
v-model:selected-group="selectedGroup"
|
||||||
:host-list="hostList"
|
:host-list="hostList"
|
||||||
:groups="hosts?.groupTree as any"
|
:groups="hosts?.groupTree as any"
|
||||||
:nodes="treeNodes" />
|
:nodes="treeNodes as any" />
|
||||||
<!-- 列表视图 -->
|
<!-- 列表视图 -->
|
||||||
<host-table v-else
|
<host-table v-else
|
||||||
v-model:selected-keys="selectedKeys"
|
v-model:selected-keys="selectedKeys"
|
||||||
@@ -83,13 +83,13 @@
|
|||||||
import { onMounted, ref, watch, computed } from 'vue';
|
import { onMounted, ref, watch, computed } from 'vue';
|
||||||
import { dataColor } from '@/utils';
|
import { dataColor } from '@/utils';
|
||||||
import { dictKeys, NewConnectionType, newConnectionTypeKey } from './types/const';
|
import { dictKeys, NewConnectionType, newConnectionTypeKey } from './types/const';
|
||||||
import { useDictStore } from '@/store';
|
import { useCacheStore, useDictStore } from '@/store';
|
||||||
import { tagLabelFilter } from '@/types/form';
|
import { tagLabelFilter } from '@/types/form';
|
||||||
import { tagColor } from '@/views/asset/host-list/types/const';
|
import { tagColor } from '@/views/asset/host-list/types/const';
|
||||||
import useLoading from '@/hooks/loading';
|
import useLoading from '@/hooks/loading';
|
||||||
import useVisible from '@/hooks/visible';
|
import useVisible from '@/hooks/visible';
|
||||||
import { getCurrentAuthorizedHost } from '@/api/asset/asset-authorized-data';
|
|
||||||
import { getAuthorizedHostOptions } from '@/types/options';
|
import { getAuthorizedHostOptions } from '@/types/options';
|
||||||
|
import { getLatestConnectHostId } from '@/api/asset/terminal-connect-log';
|
||||||
import HostTable from './components/host-table.vue';
|
import HostTable from './components/host-table.vue';
|
||||||
import HostGroup from './components/host-group.vue';
|
import HostGroup from './components/host-group.vue';
|
||||||
|
|
||||||
@@ -151,10 +151,13 @@
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
// 加载主机列表
|
// 加载主机列表
|
||||||
const { data } = await getCurrentAuthorizedHost(props.type);
|
const data = await useCacheStore().loadAuthorizedHosts(props.type);
|
||||||
hosts.value = data;
|
|
||||||
// 禁用别名
|
// 禁用别名
|
||||||
data.hostList.forEach(s => s.alias = undefined as unknown as string);
|
data.hostList.forEach(s => s.alias = undefined as unknown as string);
|
||||||
|
// 查询最近连接的主机
|
||||||
|
const { data: latestHosts } = await getLatestConnectHostId(props.type, 30);
|
||||||
|
data.latestHosts = latestHosts;
|
||||||
|
hosts.value = data;
|
||||||
// 设置主机搜索选项
|
// 设置主机搜索选项
|
||||||
filterOptions.value = getAuthorizedHostOptions(data.hostList);
|
filterOptions.value = getAuthorizedHostOptions(data.hostList);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
11
orion-visor-ui/src/store/modules/cache/index.ts
vendored
11
orion-visor-ui/src/store/modules/cache/index.ts
vendored
@@ -15,7 +15,7 @@ import { getHostKeyList } from '@/api/asset/host-key';
|
|||||||
import { getHostIdentityList } from '@/api/asset/host-identity';
|
import { getHostIdentityList } from '@/api/asset/host-identity';
|
||||||
import { getHostGroupTree } from '@/api/asset/host-group';
|
import { getHostGroupTree } from '@/api/asset/host-group';
|
||||||
import { getMenuList } from '@/api/system/menu';
|
import { getMenuList } from '@/api/system/menu';
|
||||||
import { getCurrentAuthorizedHostIdentity, getCurrentAuthorizedHostKey } from '@/api/asset/asset-authorized-data';
|
import { getCurrentAuthorizedHost, getCurrentAuthorizedHostIdentity, getCurrentAuthorizedHostKey } from '@/api/asset/asset-authorized-data';
|
||||||
import { getCommandSnippetGroupList } from '@/api/asset/command-snippet-group';
|
import { getCommandSnippetGroupList } from '@/api/asset/command-snippet-group';
|
||||||
import { getExecJobList } from '@/api/exec/exec-job';
|
import { getExecJobList } from '@/api/exec/exec-job';
|
||||||
import { getPathBookmarkGroupList } from '@/api/asset/path-bookmark-group';
|
import { getPathBookmarkGroupList } from '@/api/asset/path-bookmark-group';
|
||||||
@@ -99,8 +99,8 @@ export default defineStore('cache', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 获取主机列表
|
// 获取主机列表
|
||||||
async loadHosts(type: HostType, force = false) {
|
async loadHosts(type: HostType = '', force = false) {
|
||||||
return await this.load(`host_${type}`, () => getHostList(type), ['asset:host:query'], force);
|
return await this.load(`host_${type || 'ALL'}`, () => getHostList(type), ['asset:host:query'], force);
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取主机密钥列表
|
// 获取主机密钥列表
|
||||||
@@ -123,6 +123,11 @@ export default defineStore('cache', {
|
|||||||
return await this.load(`${type}_Tags`, () => getTagList(type), undefined, force);
|
return await this.load(`${type}_Tags`, () => getTagList(type), undefined, force);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 获取已授权的主机列表
|
||||||
|
async loadAuthorizedHosts(type: HostType = '', force = false) {
|
||||||
|
return await this.load(`authorizedHost_${type || 'ALL'}`, () => getCurrentAuthorizedHost(type), undefined, force);
|
||||||
|
},
|
||||||
|
|
||||||
// 获取已授权的主机密钥列表
|
// 获取已授权的主机密钥列表
|
||||||
async loadAuthorizedHostKeys(force = false) {
|
async loadAuthorizedHostKeys(force = false) {
|
||||||
return await this.load('authorizedHostKeys', getCurrentAuthorizedHostKey, undefined, force);
|
return await this.load('authorizedHostKeys', getCurrentAuthorizedHostKey, undefined, force);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// 缓存类型
|
// 缓存类型
|
||||||
export type CacheType = 'users' | 'menus' | 'roles'
|
export type CacheType = 'users' | 'menus' | 'roles'
|
||||||
| 'hostGroups' | 'hostKeys' | 'hostIdentities' | 'host_*'
|
| 'hostGroups' | 'host_*' | 'authorizedHost_*'
|
||||||
|
| 'hostKeys' | 'hostIdentities'
|
||||||
| 'dictKeys'
|
| 'dictKeys'
|
||||||
| 'execJob'
|
| 'execJob'
|
||||||
| 'authorizedHostKeys' | 'authorizedHostIdentities'
|
| 'authorizedHostKeys' | 'authorizedHostIdentities'
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import type {
|
|||||||
} from './types';
|
} from './types';
|
||||||
import type { ISshSession, ITerminalSession, PanelSessionTabType, TerminalPanelTabItem } from '@/views/host/terminal/types/define';
|
import type { ISshSession, ITerminalSession, PanelSessionTabType, TerminalPanelTabItem } from '@/views/host/terminal/types/define';
|
||||||
import type { AuthorizedHostQueryResponse } from '@/api/asset/asset-authorized-data';
|
import type { AuthorizedHostQueryResponse } from '@/api/asset/asset-authorized-data';
|
||||||
import { getCurrentAuthorizedHost } from '@/api/asset/asset-authorized-data';
|
|
||||||
import type { HostQueryResponse } from '@/api/asset/host';
|
import type { HostQueryResponse } from '@/api/asset/host';
|
||||||
import type { TerminalTheme, TerminalThemeSchema } from '@/api/asset/terminal';
|
import type { TerminalTheme, TerminalThemeSchema } from '@/api/asset/terminal';
|
||||||
import { getTerminalThemes } from '@/api/asset/terminal';
|
import { getTerminalThemes } from '@/api/asset/terminal';
|
||||||
@@ -21,6 +20,7 @@ import { getLatestConnectHostId } from '@/api/asset/terminal-connect-log';
|
|||||||
import { nextId } from '@/utils';
|
import { nextId } from '@/utils';
|
||||||
import { isObject } from '@/utils/is';
|
import { isObject } from '@/utils/is';
|
||||||
import { Message } from '@arco-design/web-vue';
|
import { Message } from '@arco-design/web-vue';
|
||||||
|
import { useCacheStore } from '@/store';
|
||||||
import { PanelSessionType, TerminalTabs } from '@/views/host/terminal/types/const';
|
import { PanelSessionType, TerminalTabs } from '@/views/host/terminal/types/const';
|
||||||
import TerminalTabManager from '@/views/host/terminal/handler/terminal-tab-manager';
|
import TerminalTabManager from '@/views/host/terminal/handler/terminal-tab-manager';
|
||||||
import TerminalSessionManager from '@/views/host/terminal/handler/terminal-session-manager';
|
import TerminalSessionManager from '@/views/host/terminal/handler/terminal-session-manager';
|
||||||
@@ -131,18 +131,18 @@ export default defineStore('terminal', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 加载主机列表
|
// 加载主机列表
|
||||||
async loadHosts() {
|
async loadHostList() {
|
||||||
if (this.hosts.hostList?.length) {
|
if (this.hosts.hostList?.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 查询授权主机
|
// 查询授权主机
|
||||||
const { data } = await getCurrentAuthorizedHost('SSH');
|
const data = await useCacheStore().loadAuthorizedHosts();
|
||||||
Object.keys(data).forEach(k => {
|
Object.keys(data).forEach(k => {
|
||||||
this.hosts[k as keyof AuthorizedHostQueryResponse] = data[k as keyof AuthorizedHostQueryResponse] as any;
|
this.hosts[k as keyof AuthorizedHostQueryResponse] = data[k as keyof AuthorizedHostQueryResponse] as any;
|
||||||
});
|
});
|
||||||
this.hosts.latestHosts = [];
|
this.hosts.latestHosts = [];
|
||||||
// 查询最近连接的主机
|
// 查询最近连接的主机
|
||||||
const { data: latestHosts } = await getLatestConnectHostId('SSH', 30);
|
const { data: latestHosts } = await getLatestConnectHostId('', 30);
|
||||||
this.hosts.latestHosts = latestHosts;
|
this.hosts.latestHosts = latestHosts;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@
|
|||||||
try {
|
try {
|
||||||
// 加载组内数据
|
// 加载组内数据
|
||||||
const { data } = await getHostGroupRelList(groupId as number);
|
const { data } = await getHostGroupRelList(groupId as number);
|
||||||
const hosts = await cacheStore.loadHosts('');
|
const hosts = await cacheStore.loadHosts();
|
||||||
selectedGroupHosts.value = data.map(s => hosts.find(h => h.id === s) as HostQueryResponse)
|
selectedGroupHosts.value = data.map(s => hosts.find(h => h.id === s) as HostQueryResponse)
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -138,6 +138,8 @@
|
|||||||
idList: checkedGroups.value
|
idList: checkedGroups.value
|
||||||
});
|
});
|
||||||
Message.success('授权成功');
|
Message.success('授权成功');
|
||||||
|
// 清空缓存
|
||||||
|
cacheStore.reset('authorizedHost_ALL', 'authorizedHost_SSH');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -96,6 +96,8 @@
|
|||||||
idList: selectedKeys.value
|
idList: selectedKeys.value
|
||||||
});
|
});
|
||||||
Message.success('授权成功');
|
Message.success('授权成功');
|
||||||
|
// 清空缓存
|
||||||
|
cacheStore.reset('authorizedHostIdentities');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -72,6 +72,8 @@
|
|||||||
idList: selectedKeys.value
|
idList: selectedKeys.value
|
||||||
});
|
});
|
||||||
Message.success('授权成功');
|
Message.success('授权成功');
|
||||||
|
// 清空缓存
|
||||||
|
cacheStore.reset('authorizedHostKeys');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -113,7 +113,7 @@
|
|||||||
|
|
||||||
// 加载主机列表
|
// 加载主机列表
|
||||||
const loadHosts = () => {
|
const loadHosts = () => {
|
||||||
cacheStore.loadHosts('').then(hosts => {
|
cacheStore.loadHosts().then(hosts => {
|
||||||
data.value = hosts.map(s => {
|
data.value = hosts.map(s => {
|
||||||
return {
|
return {
|
||||||
value: String(s.id),
|
value: String(s.id),
|
||||||
|
|||||||
@@ -339,7 +339,8 @@
|
|||||||
// 重新加载数据
|
// 重新加载数据
|
||||||
fetchCardData();
|
fetchCardData();
|
||||||
// 清空缓存
|
// 清空缓存
|
||||||
cacheStore.reset('host_', 'host_SSH');
|
cacheStore.reset('host_ALL', 'host_SSH',
|
||||||
|
'authorizedHost_ALL', 'authorizedHost_SSH');
|
||||||
};
|
};
|
||||||
|
|
||||||
defineExpose({ reload });
|
defineExpose({ reload });
|
||||||
|
|||||||
@@ -373,7 +373,8 @@
|
|||||||
// 重新加载数据
|
// 重新加载数据
|
||||||
fetchTableData();
|
fetchTableData();
|
||||||
// 清空缓存
|
// 清空缓存
|
||||||
cacheStore.reset('host_', 'host_SSH');
|
cacheStore.reset('host_ALL', 'host_SSH',
|
||||||
|
'authorizedHost_ALL', 'authorizedHost_SSH');
|
||||||
};
|
};
|
||||||
|
|
||||||
defineExpose({ reload });
|
defineExpose({ reload });
|
||||||
|
|||||||
@@ -79,7 +79,7 @@
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
fetchPreference, getCurrentSession, openSession,
|
fetchPreference, getCurrentSession, openSession,
|
||||||
layoutState, preference, loadHosts, hosts, tabManager, sessionManager
|
layoutState, preference, loadHostList, hosts, tabManager, sessionManager
|
||||||
} = useTerminalStore();
|
} = useTerminalStore();
|
||||||
const { loading, setLoading } = useLoading(true);
|
const { loading, setLoading } = useLoading(true);
|
||||||
const { enter: enterFull, exit: exitFull } = useFullscreen();
|
const { enter: enterFull, exit: exitFull } = useFullscreen();
|
||||||
@@ -165,7 +165,7 @@
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
// 加载主机
|
// 加载主机
|
||||||
await loadHosts();
|
await loadHostList();
|
||||||
// 默认连接主机
|
// 默认连接主机
|
||||||
const connect = route.query.connect as string;
|
const connect = route.query.connect as string;
|
||||||
if (connect) {
|
if (connect) {
|
||||||
|
|||||||
Reference in New Issue
Block a user