<div class="attachments">
<div class="name">附件</div>
<div class="itemFile" v-for="(item,index) in attachments">
<span @click="scanFile(item.url)">{{item.fileName}}</span>
</div>
</div>
scanFile(url){
var vm=this;
var prefixUrl=window.localStorage.prefixUrl;
// var fileURL='http://report.zkteco.com/file/globalservice/pdf/%E9%9B%86%E8%AE%AD%E8%90%A51_%E7%9C%8B%E5%9B%BE%E7%8E%8B_1526894807867.pdf';
var fileURL = prefixUrl+'/file/'+url;
console.log(fileURL);
if(fileURL !=''){
plus.nativeUI.actionSheet({
cancel: 'Cancel',
buttons: [{
title: 'Download the file'
}, {
title: 'OK'
}]
}, function(e) {
var i = e.index;
if(i == 1) {
}else if(i == 2) {
console.log(1002);
plus.nativeUI.showWaiting('');
var localURL = vm.getLocalImg(fileURL);
vm.openfiles(localURL);/*打开文件*/
}else{
}
});
return false;
}
console.log(1003);
},
/*检测文件是否存在并打开*/
openfiles (localURL) {
let vm=this;
console.log(1004);
plus.io.resolveLocalFileSystemURL(plus.io.convertAbsoluteFileSystem(localURL), function(entry) {
plus.nativeUI.closeWaiting();
//              localURL = plus.io.convertLocalFileSystemURL(localURL);
plus.runtime.openFile( plus.io.convertAbsoluteFileSystem(localURL), null, function () {
plus.nativeUI.alert( 'The file could not be opened', function(){}, official, 'OK');
});
}, function(e) {
setTimeout(function() {
console.log(1005);
vm.openfiles(localURL);/*等待图片下载完成*/
},300); 
});     
},
//获取缓存图片
getLocalImg(source){
let vm=this;
if(source == null || source == '' || source == 'undefined'){
return '';
}else if(source.indexOf('../public')==0){
return source;
}
 
source = source.indexOf('http')<0? (webRoot + source) : source;
 
var lastName = source.split('/').pop();
var localName = "_downloads/" + lastName;
plus.io.resolveLocalFileSystemURL(localName, function(entry) {
}, function(e) {
vm.downloadSource(source,localName);
});     
return plus.io.convertLocalFileSystemURL(localName);
},
/*下载图片到缓存*/
downloadSource (source,localName) {
var regChinese = /[\u4E00-\u9FA5]/g;
var tmpLoadUrl = source.replace(regChinese, 'chineseRemoveAfter');
if (tmpLoadUrl.indexOf('chineseRemoveAfter') != -1) {
source = encodeURI(source);
}
var dtask = plus.downloader.createDownload(source,{filename:localName}, function ( d, status ) {
if ( status == 200 ) {
console.log(d.filename);
}else{
console.log('error');
}
});
dtask.start();      
},

hbuilder打包集成文件预览的更多相关文章

  1. java实现office文件预览

    不知觉就过了这个久了,继上篇java实现文件上传下载后,今天给大家分享一篇java实现的对office文件预览功能. 相信大家在平常的项目中会遇到需要对文件实现预览功能,这里不用下载节省很多事.大家请 ...

  2. Qt SD卡 文件系统挂载、文件预览

    /********************************************************************************** * Qt SD卡 文件系统挂载. ...

  3. Jquery.Treeview+Jquery UI制作Web文件预览

    效果图: 前台Html: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="D ...

  4. Vue PDF文件预览vue-pdf

       最近做项目,遇到预览PDF这个功能,在网上找了找,大多推荐的是pdf.js,不过在Vue中还是想偷懒直接npm组件,最后找到了一个还不错的Vue-pdf 组件,GitHub地址:https:// ...

  5. 关于pc端 app端pdf,word xls等文件预览的功能

    第一种用H5标签<iframe>标签实现 返回的文件类型,文件流,文件流返回必须在设置 contentType对应的Mime Type, 返回文件的物理位置. 已经实测可以支持的文件类型 ...

  6. odoo13之文件预览widget/模块

    本文示例代码可查看github仓库:odoo13_file_preview 文件预览效果图展示 效果描述: 1.当点击图片或者文件时展开图片. 2.当点击关闭按钮时关闭图片预览. 3.当点击下载按钮时 ...

  7. 手把手教你用 Spring Boot搭建一个在线文件预览系统!支持ppt、doc等多种类型文件预览

    昨晚搭建环境都花了好一会时间,主要在浪费在了安装 openoffice 这个依赖环境上(Mac 需要手动安装). 然后,又一步一步功能演示,记录,调试项目,并且简单研究了一下核心代码之后才把这篇文章写 ...

  8. java 文件转成pdf文件 预览

    一.前端代码 //预览功能 preview: function () { //判断选中状态 var ids =""; var num = 0; $(".checkbox& ...

  9. COS控制台进阶 - 文件预览和在线编辑

    导语 | COS控制台新上线了文件预览功能,用户可在控制台内直接预览.编辑文件内容. 前不久,微软发布了 vscode for web 的公告,是基于web的在线代码编辑器,无需下载安装可以直接在we ...

随机推荐

  1. Spring源码整理

    转载:https://www.cnblogs.com/ITtangtang/p/3978349.html  感谢博主

  2. lumen返回网站base url

    可以使用全局帮助函数url() echo url(); //输出http://test.domain.com

  3. MSSQL Server 2005 安装补丁出现 Setup Support Files Failure

    给MSSQL Server 2005 安装补丁时出现  Setup Support Files Failure,检查了错误日志,不是系统错误,而是应用错误.出现这个错误的原因:以我的安装为例,我开始装 ...

  4. docker容器内存和CPU使用限制

    docker容器内存和CPU使用限制 示例如下 sudo docker run --name seckill0 -p 8080:8080 -m 1024M --cpus=0.2 -d seckill: ...

  5. 【VS开发】VS2010中导入ActiveX控件

    方法1: 1.首先在在项目上面右击添加类,如下图所示: 2.点击添加ActiveX控件中的MFC类 3.找到需要添加的ActiveX类. 4.点击完成即可. 5.此时转到资源视图,打开如下视图.可能工 ...

  6. python脚本调用外部程序的若干种方式以及利弊

    脚本执行外部程序的常用几种方式: # os.popen(path)# subprocess.run(cmd,shell=True)# subprocess.check_call(cmd,shell = ...

  7. [转帖]nginx1.17.2版本源码安装

    nginx1.17.2版本源码安装 原创: 沧海书生 Ansible爱好者 昨天 公众号里面的内容 这里简单测试了下 在x86的虚拟机里面编译安装 nginx 仅make make install n ...

  8. 【转帖】linux下的各个目录的含义

    linux下的各个目录的含义 http://embeddedlinux.org.cn/emb-linux/entry-level/200809/22-85.html/bin/usr/local/bin ...

  9. PHP中的闭包

    1.语句结构 在PHP中,由于存在函数内部不能访问全局作用的,所以就需要一种可以引入上一级作用域的语法结构,这种就是 function () use () {} 将需要引入到这个函数作用于内的变量写入 ...

  10. 什么是时序时空数据库TSDB

    时序时空数据库(Time Series & Spatial Temporal Database,简称 TSDB)是一种高性能.低成本.稳定可靠的在线时序时空数据库服务,提供高效读写.高压缩比存 ...