💄 修改echart内容

This commit is contained in:
bunny 2025-06-04 18:50:06 +08:00
parent eaa5cd5952
commit 510c6ca457
3 changed files with 74 additions and 12 deletions

View File

@ -94,20 +94,54 @@ export const logOutputSize = (): string => {
return `${size.toFixed(2)} ${units[index]}`; return `${size.toFixed(2)} ${units[index]}`;
} }
// 计算文件夹字节大小 /**
function getFolderSize(folderPath: string) { *
* @param folderPath
* @param currentDepth 使
* @returns
*/
function getFolderSize(folderPath: string, currentDepth: number = 0): number {
// 公共常量定义
const EXCLUDED_FILE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg'];
const MAX_DEPTH = 10; // 最大递归深度限制
// 安全检查
if (!fs.existsSync(folderPath)) {
throw new Error(`文件夹不存在: ${folderPath}`);
}
if (currentDepth > MAX_DEPTH) {
console.warn(`达到最大递归深度 ${MAX_DEPTH},停止遍历: ${folderPath}`);
return 0;
}
let size = 0; let size = 0;
fs.readdirSync(folderPath).forEach((fileName: string) => { try {
const files = fs.readdirSync(folderPath);
for (const fileName of files) {
const filePath = path.join(folderPath, fileName); const filePath = path.join(folderPath, fileName);
try {
const stats = fs.statSync(filePath); const stats = fs.statSync(filePath);
if (stats.isFile()) { if (stats.isFile()) {
// 检查文件扩展名是否在排除列表中
const ext = path.extname(fileName).toLowerCase();
if (!EXCLUDED_FILE_EXTENSIONS.includes(ext)) {
size += stats.size; size += stats.size;
} else if (stats.isDirectory()) {
size += getFolderSize(filePath);
} }
}); } else if (stats.isDirectory()) {
size += getFolderSize(filePath, currentDepth + 1);
}
} catch (error) {
console.error(`无法访问文件: ${filePath}`, error);
}
}
} catch (error) {
console.error(`无法读取目录: ${folderPath}`, error);
}
return size; return size;
} }

View File

@ -1,4 +1,13 @@
import { BarChart, GaugeChart, LineChart, PictorialBarChart, PieChart } from 'echarts/charts'; import {
BarChart,
EffectScatterChart,
GaugeChart,
LineChart,
MapChart,
PictorialBarChart,
PieChart,
TreemapChart,
} from 'echarts/charts';
import { import {
DataZoomComponent, DataZoomComponent,
GraphicComponent, GraphicComponent,
@ -17,11 +26,13 @@ import type { App } from 'vue';
const { use } = echarts; const { use } = echarts;
use([ use([
PieChart, PieChart,
EffectScatterChart,
BarChart, BarChart,
LineChart, LineChart,
CanvasRenderer, CanvasRenderer,
SVGRenderer, SVGRenderer,
GridComponent, GridComponent,
TreemapChart,
TitleComponent, TitleComponent,
PolarComponent, PolarComponent,
LegendComponent, LegendComponent,
@ -32,6 +43,7 @@ use([
VisualMapComponent, VisualMapComponent,
PictorialBarChart, PictorialBarChart,
GaugeChart, GaugeChart,
MapChart,
]); ]);
/** /**

View File

@ -1,4 +1,5 @@
import { useDebounceFn, useEventListener } from '@vueuse/core'; import { useDebounceFn, useEventListener } from '@vueuse/core';
import type { EChartsType } from 'echarts';
import echarts from '@/plugins/echarts'; import echarts from '@/plugins/echarts';
@ -13,7 +14,7 @@ export const debounceChart = (myChart: echarts.ECharts | undefined) => {
/** 数字格式化 */ /** 数字格式化 */
export const formatter = (number: any) => { export const formatter = (number: any) => {
const numbers = number.toString().split('').reverse(); const numbers = number?.toString().split('').reverse();
const segs = []; const segs = [];
while (numbers.length) segs.push(numbers.splice(0, 3).join('')); while (numbers.length) segs.push(numbers.splice(0, 3).join(''));
@ -38,3 +39,18 @@ export const graphicLinearGradient = (
] ]
); );
}; };
export const resetSelect = (myChart: EChartsType) => {
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0,
});
};
export const selectSector = (myChart: EChartsType, dataIndex: number) => {
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex,
});
};