We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
export const readFile = (file: File, index1?: number) => { const index = index1 || 0; const encodes = ["utf-8", "gb2312", "gbk"]; const encoding = encodes[index]; var reader = new FileReader(); reader.readAsText(file, encoding); reader.onloadstart = function () { // 开始加载,可替换loading }; reader.onerror = function () { // loading结束 console.error("上传文件失败,请刷新重试"); }; reader.onload = function () { // loading结束 if (reader.result) { if (/�/.test(reader.result as any)) { //有乱码 if (index + 1 <= encodes.length) { readFile(file, index + 1); } else { console.error( "检测到您的文件有乱码,本系统仅支持utf-8,gb2312,gbk三种编码方式,请检查您的文件编码" ); } } else { // 限制500写死 if ((reader.result as string).split("\n").length > 500) { console.error( "检测到您的文件>500" ); } } // 获取结果 const text = (reader.result as string).split('\n'); // todo,处理结果里逻辑 } }; } export const identifyFiles = (files: File[]) => { // 获取上传的files文件 if (files?.length === 0) { console.error('请选择文件'); } const file = files[files.length - 1]; if (file) { if (file.type != "text/plain") { console.error("本功能只支持导入txt文件"); return; } readFile(file); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: