重写ssh前端组件,通用化

This commit is contained in:
dengqichen 2025-12-06 23:47:24 +08:00
parent 6d2f0cb95c
commit 7025eebd51
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,42 @@
/**
* Terminal
*/
import type { LayoutOrientation } from './types';
import { getHeightFromWidth } from '@/lib/screenUtils';
/**
*
* @param containerSize px
* @param orientation
* @returns px
*/
export const getMinSplitSize = (containerSize: number, orientation: LayoutOrientation): number => {
if (orientation === 'horizontal') {
// 左右分屏最小宽度520px
return 520;
} else {
// 上下分屏根据520px宽度和屏幕比例计算对应的高度
return getHeightFromWidth(520);
}
};
/**
*
* @param minPixels
* @param containerSize px
* @param totalPercent
* @returns
*/
export const getMinSplitPercent = (
minPixels: number,
containerSize: number,
totalPercent: number
): number => {
if (!containerSize) return totalPercent * 0.2;
// 将像素转换为百分比
const minPercent = (minPixels / containerSize) * totalPercent;
// 确保不超过总量的50%
return Math.min(totalPercent * 0.5, minPercent);
};

View File

@ -0,0 +1,23 @@
/**
*
*/
/**
* :
* @returns (height / width)
*/
export const getScreenAspectRatio = (): number => {
const width = window.screen.width;
const height = window.screen.height;
return height / width;
};
/**
*
* @param width px
* @returns px
*/
export const getHeightFromWidth = (width: number): number => {
const ratio = getScreenAspectRatio();
return Math.round(width * ratio);
};