加载脚本
await this . utils. loadScript ( 'https://unpkg.com/promise-polyfill/dist/polyfill.min.js' ) await this . utils. loadScript ( 'https://unpkg.com/jszip/dist/jszip.min.js' ) await this . utils. loadScript ( 'https://unpkg.com/docx-preview@0.1.9/dist/docx-preview.min.js' ) await this . utils. loadScript ( 'https://unpkg.com/xlsx/dist/xlsx.full.min.js' ) await this . utils. loadScript ( 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.9.179/pdf.min.js' )
WORD
< div id= "viewModalContainer" > < / div> const data = await fetch ( url) . then ( ( response ) => response. blob ( ) ) . then ( ( res ) => { this . $ ( 'dialog_lkw0jna2' ) . show ( ) docx. renderAsync ( res, document. getElementById ( 'viewModalContainer' ) , null , { } ) . then ( result => { console. log ( 'result' , result) } ) } ) return data
excel
< div id= "excelContainer" > < / div> const data = await fetch ( url) . then ( ( response ) => response. arrayBuffer ( ) ) . then ( ( res ) => { this . $ ( 'dialog_lkwbvqrc' ) . show ( ) const wb = XLSX . read ( res) ; console. log ( 'wb' , wb) let html = '' ; wb. SheetNames. forEach ( function ( name, index ) { let ws = wb. Sheets[ name] ; let str = XLSX . utils. sheet_to_html ( ws, { header : 1 , defval : '' } ) ; let startNo = str. indexOf ( ` <table> ` ) ; let endNo = str. indexOf ( ` </table> ` ) ; str = str. substring ( startNo, endNo + ` </table> ` . length) ; str = str. replace ( / (\b(?:id|t|v)=".*?") / g , '' ) ; str = str. replace ( '<table>' , ` <table border="1" style="border-collapse:collapse; width: 100%; border:1px solid #666666; margin-bottom:5px;font-size:14px;margin: 15px 0;"> ` ) ; html += str; } ) const dom = document. getElementById ( 'excelContainer' ) dom. innerHTML = html} )
pdf
< canvas id= "pdfContainer" > < / canvas> const loadingTask = pdfjsLib. getDocument ( url) loadingTask. promise. then ( res => { this . $ ( 'dialog_lkwbvqrg' ) . show ( ) const canvas = document. getElementById ( 'pdfContainer' ) res. getPage ( 1 ) . then ( function ( page ) { const viewport = page. getViewport ( { scale : 1 } ) ; const context = canvas. getContext ( '2d' ) ; canvas. height = viewport. height; canvas. width = viewport. width; page. render ( { canvasContext : context, viewport : viewport} ) ; } ) . catch ( error => { console. log ( 'error:' , error) } ) } )
img
this . utils. previewImage ( { current : rowData. path } )
video
window. open ( rowData. path)