mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-29 01:40:51 +00:00

perf: 聊天页优化 perf: md解析样式 perf: ui调整 perf: 懒加载和动态加载优化 perf: 去除console, perf: 图片cdn feat: 图片地址 perf: 登录顺序 feat: 流优化
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import crypto from 'crypto';
|
|
import { useToast } from '@/hooks/useToast';
|
|
|
|
/**
|
|
* copy text data
|
|
*/
|
|
export const useCopyData = () => {
|
|
const { toast } = useToast();
|
|
return {
|
|
copyData: (data: string, title: string = '复制成功') => {
|
|
try {
|
|
const textarea = document.createElement('textarea');
|
|
textarea.value = data;
|
|
document.body.appendChild(textarea);
|
|
textarea.select();
|
|
document.execCommand('copy');
|
|
document.body.removeChild(textarea);
|
|
toast({
|
|
title,
|
|
status: 'success',
|
|
duration: 1000
|
|
});
|
|
} catch (error) {
|
|
console.error(error);
|
|
toast({
|
|
title: '复制失败',
|
|
status: 'error'
|
|
});
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
export const createHashPassword = (text: string) => {
|
|
const hash = crypto.createHash('sha256').update(text).digest('hex');
|
|
return hash;
|
|
};
|
|
|
|
/**
|
|
* 读取文件内容
|
|
*/
|
|
export const loadLocalFileContent = (file: File) => {
|
|
return new Promise((resolve: (_: string) => void, reject) => {
|
|
const reader = new FileReader();
|
|
reader.onload = () => {
|
|
resolve(reader.result as string);
|
|
};
|
|
reader.onerror = (err) => {
|
|
reject(err);
|
|
};
|
|
reader.readAsText(file);
|
|
});
|
|
};
|