@@ -116,6 +116,8 @@ export default {
116
116
isUrl: true ,
117
117
// input输入的url
118
118
inputUrl: ' ' ,
119
+ // 当前浏览的文件拓展名
120
+ extend: ' ' ,
119
121
// 上传文件名
120
122
uploadFileName: ' ' ,
121
123
// 通过iframe传入的文件
@@ -209,9 +211,9 @@ export default {
209
211
// 要预览的文件地址
210
212
this .uploadFileName = url .substr (url .lastIndexOf (' /' ) + 1 )
211
213
// 取得扩展名并统一转小写兼容大写
212
- const extend = getExtend (this .uploadFileName ).toLowerCase ()
214
+ this . extend = getExtend (this .uploadFileName ).toLowerCase ()
213
215
// 判断是否为office文件
214
- const isOffice = typeInfo .office .find ((item ) => item .indexOf (extend) > - 1 )
216
+ const isOffice = typeInfo .office .find ((item ) => item .indexOf (this . extend ) > - 1 )
215
217
// 判断是否需要使用外部微软第三方office在线浏览的方式
216
218
if (useOfficeMicroOnline && isOffice) {
217
219
// 展示微软第三方office在线浏览
@@ -233,7 +235,7 @@ export default {
233
235
responseType: ' blob'
234
236
})
235
237
.then (({ data }) => {
236
- const file = new File ([data], this .uploadFileName , {})
238
+ const file = new File ([data], this .uploadFileName , { type : data . type || ' ' })
237
239
this .handleChange ({ target: { files: [file] } })
238
240
})
239
241
.finally (() => {
@@ -245,7 +247,7 @@ export default {
245
247
renders[' notFind' ](
246
248
url,
247
249
this .$refs .output ,
248
- extend,
250
+ this . extend ,
249
251
this .uploadFileName
250
252
)
251
253
})
@@ -271,11 +273,12 @@ export default {
271
273
},
272
274
// 文件信息处理,对应文件渲染方法
273
275
displayResult (buffer , file ) {
276
+ console .log (' file' , file)
274
277
// 取得文件名
275
- const { name } = file
278
+ const { name , type } = file
276
279
this .uploadFileName = name
277
280
// 取得扩展名并统一转小写兼容大写
278
- const extend = getExtend (name).toLowerCase ()
281
+ const extend = type . split ( ' / ' )[ 1 ] || this . extend || getExtend (name).toLowerCase ()
279
282
// 不支持的类型不显示缩放按钮
280
283
if (! renders[extend]) {
281
284
this .showScale = false
0 commit comments