mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 05:43:51 +00:00
(feature)(chat-sdk) add export log (#1482)
This commit is contained in:
@@ -70,13 +70,13 @@ export const getFormattedValue = (value: number | string, remainZero?: boolean)
|
||||
+value >= 100000000
|
||||
? NumericUnit.OneHundredMillion
|
||||
: +value >= 10000
|
||||
? NumericUnit.TenThousand
|
||||
: NumericUnit.None;
|
||||
? NumericUnit.TenThousand
|
||||
: NumericUnit.None;
|
||||
|
||||
let formattedValue = formatByUnit(value, unit);
|
||||
formattedValue = formatByDecimalPlaces(
|
||||
formattedValue,
|
||||
unit === NumericUnit.OneHundredMillion ? 2 : +value < 1 ? 3 : 1,
|
||||
unit === NumericUnit.OneHundredMillion ? 2 : +value < 1 ? 3 : 1
|
||||
);
|
||||
formattedValue = formatByThousandSeperator(formattedValue);
|
||||
if ((typeof formattedValue === 'number' && isNaN(formattedValue)) || +formattedValue === 0) {
|
||||
@@ -88,11 +88,11 @@ export const getFormattedValue = (value: number | string, remainZero?: boolean)
|
||||
export const formatNumberWithCN = (num: number) => {
|
||||
if (isNaN(num)) return '-';
|
||||
if (num >= 10000) {
|
||||
return (num / 10000).toFixed(1) + "万";
|
||||
return (num / 10000).toFixed(1) + '万';
|
||||
} else {
|
||||
return formatByDecimalPlaces(num, 2);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const groupByColumn = (data: any[], column: string) => {
|
||||
return data.reduce((result, item) => {
|
||||
@@ -124,11 +124,15 @@ export const normalizeTrendData = (
|
||||
valueColumnName: string,
|
||||
startDate: string,
|
||||
endDate: string,
|
||||
dateType?: string,
|
||||
dateType?: string
|
||||
) => {
|
||||
const dateList = enumerateDaysBetweenDates(moment(startDate), moment(endDate), dateType);
|
||||
const result = dateList.map((date) => {
|
||||
const item = resultList.find((result) => moment(result[dateColumnName]).format(dateType === 'months' ? 'YYYY-MM' : 'YYYY-MM-DD') === date);
|
||||
const result = dateList.map(date => {
|
||||
const item = resultList.find(
|
||||
result =>
|
||||
moment(result[dateColumnName]).format(dateType === 'months' ? 'YYYY-MM' : 'YYYY-MM-DD') ===
|
||||
date
|
||||
);
|
||||
return {
|
||||
...(item || {}),
|
||||
[dateColumnName]: date,
|
||||
@@ -139,7 +143,7 @@ export const normalizeTrendData = (
|
||||
};
|
||||
|
||||
export const getMinMaxDate = (resultList: any[], dateColumnName: string) => {
|
||||
const dateList = resultList.map((item) => moment(item[dateColumnName]));
|
||||
const dateList = resultList.map(item => moment(item[dateColumnName]));
|
||||
return [moment.min(dateList).format('YYYY-MM-DD'), moment.max(dateList).format('YYYY-MM-DD')];
|
||||
};
|
||||
|
||||
@@ -147,10 +151,10 @@ export function hexToRgbObj(hex) {
|
||||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
return result
|
||||
? {
|
||||
r: parseInt(result[1], 16),
|
||||
g: parseInt(result[2], 16),
|
||||
b: parseInt(result[3], 16),
|
||||
}
|
||||
r: parseInt(result[1], 16),
|
||||
g: parseInt(result[2], 16),
|
||||
b: parseInt(result[3], 16),
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
@@ -177,7 +181,6 @@ export const isIOS = window.navigator.userAgent.match(/(iPhone|iPod|ios)/i);
|
||||
|
||||
export const isAndroid = window.navigator.userAgent.match(/(Android)/i);
|
||||
|
||||
|
||||
export function isProd() {
|
||||
return process.env.NODE_ENV === 'production';
|
||||
}
|
||||
@@ -248,7 +251,7 @@ export const getTextWidth = (
|
||||
text: string,
|
||||
fontSize: string = '16px',
|
||||
fontWeight: string = 'normal',
|
||||
fontFamily: string = 'DINPro Medium',
|
||||
fontFamily: string = 'DINPro Medium'
|
||||
): number => {
|
||||
const canvas = utilCanvas || (utilCanvas = document.createElement('canvas'));
|
||||
const context = canvas.getContext('2d');
|
||||
@@ -271,3 +274,32 @@ export function jsonParse(config: any, defaultReturn?: any) {
|
||||
return defaultReturn;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出文本文件的函数
|
||||
* @param content - 要导出的文本内容
|
||||
* @param fileName - 导出的文件名
|
||||
* @param mimeType - 文件的 MIME 类型,默认为 'text/plain'
|
||||
*/
|
||||
export function exportTextFile(content: string, fileName: string, mimeType: string = 'text/plain') {
|
||||
// 创建一个 Blob 对象
|
||||
const blob = new Blob([content], { type: mimeType });
|
||||
|
||||
// 创建一个 URL 对象
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
// 创建一个 <a> 元素
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
|
||||
// 触发下载
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// 移除 <a> 元素
|
||||
document.body.removeChild(a);
|
||||
|
||||
// 释放 URL 对象
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user