读取接口访问的url,预览文档的内容
onClick={async () => {
if (record.fileUrl) {
const res = await viewDirectory(record.fileUrl);
if (record.fileUrl.includes('.pdf')) {
const binaryData: any = [];
binaryData.push(res);
const url = window.URL.createObjectURL(res);
window.location.href = url;
} else if (record.fileUrl.includes('.docx')) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
showModal();
renderAsync(res, childRef.current, null, {
className: 'kaimo-docx-666', // string:默认和文档样式类的类名/前缀
inWrapper: true, // boolean:启用围绕文档内容的包装器渲染
ignoreWidth: false, // boolean:禁用页面的渲染宽度
ignoreHeight: false, // boolean:禁止渲染页面高度
ignoreFonts: false, // boolean:禁用字体渲染
breakPages: true, // boolean:在分页符上启用分页
ignoreLastRenderedPageBreak: true, // boolean:在 lastRenderedPageBreak 元素上禁用分页
experimental: false, // boolean:启用实验功能(制表符停止计算)
trimXmlDeclaration: true, // boolean:如果为true,解析前会从 xmlTemplate 文档中移除 xmlTemplate 声明
useBase64URL: false, // boolean:如果为true,图片、字体等会转为base 64 URL,否则使用URL.createObjectURL
useMathMLPolyfill: false, // boolean:包括用于 chrome、edge 等的 MathML polyfill。
showChanges: false, // boolean:启用文档更改的实验性渲染(插入/删除)
debug: false, // boolean:启用额外的日志记录
}).then((ress) => {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
console.log('res---->', ress);
});
} else if (record.fileUrl.includes('.xlsx')) {
<FileViewer
fileType={'xlsx'} //文件类型
filePath={res} //文件地址
onError={(e: any) => {
console.log('错误信息', e);
}}
errorComponent={console.log('发生错误')}
unsupportedComponent={message.error('解析失败,请下载后查看')}
/>;
}
} else {
message.error('不存在文件');
}
}}
结果:word文档内容

2212

被折叠的 条评论
为什么被折叠?



