@@ -116,6 +116,8 @@ export default {
116116 isUrl: true ,
117117 // input输入的url
118118 inputUrl: ' ' ,
119+ // 当前浏览的文件拓展名
120+ extend: ' ' ,
119121 // 上传文件名
120122 uploadFileName: ' ' ,
121123 // 通过iframe传入的文件
@@ -209,9 +211,9 @@ export default {
209211 // 要预览的文件地址
210212 this .uploadFileName = url .substr (url .lastIndexOf (' /' ) + 1 )
211213 // 取得扩展名并统一转小写兼容大写
212- const extend = getExtend (this .uploadFileName ).toLowerCase ()
214+ this . extend = getExtend (this .uploadFileName ).toLowerCase ()
213215 // 判断是否为office文件
214- const isOffice = typeInfo .office .find ((item ) => item .indexOf (extend) > - 1 )
216+ const isOffice = typeInfo .office .find ((item ) => item .indexOf (this . extend ) > - 1 )
215217 // 判断是否需要使用外部微软第三方office在线浏览的方式
216218 if (useOfficeMicroOnline && isOffice) {
217219 // 展示微软第三方office在线浏览
@@ -233,7 +235,7 @@ export default {
233235 responseType: ' blob'
234236 })
235237 .then (({ data }) => {
236- const file = new File ([data], this .uploadFileName , {})
238+ const file = new File ([data], this .uploadFileName , { type : data . type || ' ' })
237239 this .handleChange ({ target: { files: [file] } })
238240 })
239241 .finally (() => {
@@ -245,7 +247,7 @@ export default {
245247 renders[' notFind' ](
246248 url,
247249 this .$refs .output ,
248- extend,
250+ this . extend ,
249251 this .uploadFileName
250252 )
251253 })
@@ -271,11 +273,12 @@ export default {
271273 },
272274 // 文件信息处理,对应文件渲染方法
273275 displayResult (buffer , file ) {
276+ console .log (' file' , file)
274277 // 取得文件名
275- const { name } = file
278+ const { name , type } = file
276279 this .uploadFileName = name
277280 // 取得扩展名并统一转小写兼容大写
278- const extend = getExtend (name).toLowerCase ()
281+ const extend = type . split ( ' / ' )[ 1 ] || this . extend || getExtend (name).toLowerCase ()
279282 // 不支持的类型不显示缩放按钮
280283 if (! renders[extend]) {
281284 this .showScale = false
0 commit comments