<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. Linux vi/vim命令

    转自:http://www.runoob.com/linux/linux-vim.html Linux vi/vim 所有的 Unix Like 系统都会内建 vi 文书编辑器,其他的文书编辑器则不一 ...

  2. spring cloud consul上下线体验

    spring cloud consul中默认会将spring.application.name作为ID 同一服务起多个实例时,ID默认会变成${spring.application.name}-${s ...

  3. PCL中有哪些可用的PointT类型(3)

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=268 PointXYZRGBNormal - float x, y, z, ...

  4. openstack部署glance

    一.建立glance数据库并且给权限设置第三方登录 mysql -uroot -p0330 CREATE DATABASE glance; GRANT ALL PRIVILEGES ON glance ...

  5. ASP.NET Core 入门笔记8,ASP.NET Core MVC 分部视图入门

    一.前言 1.本教程主要内容 ASP.NET Core MVC (Razor)分部视图简介 ASP.NET Core MVC (Razor)分部视图基础教程 ASP.NET Core MVC (Raz ...

  6. Unity学习

    UnityAPI常用方法和类 Unity中的动画系统和Timeline (1) 普通动画创建 (2) 按钮动画和2D精灵动画 (3) 模型和动画导入 C#编程 (1) 委托 Lambda表达式和事件 ...

  7. 配置glance使用ceph作为后端存储

    在ceph监视器上执行 1.创建pool池 为glance服务创建pool池(因为我只有一个OSD节点,所以要将副本数设置为1) ceph osd pool create glance-images  ...

  8. Email功能的设定

    在前期制定发送邮件功能时,都是使用导入import smtplib模块来实现,虽说能实现, 但是对新人.刚接触的来说不太友好,虽然网上五花八门的教程一大推,但还是要自己花不少时间才搞定(笔者就是) 在 ...

  9. Spring 如何解决循环依赖问题?

    在关于Spring的面试中,我们经常会被问到一个问题,就是Spring是如何解决循环依赖的问题的. 这个问题算是关于Spring的一个高频面试题,因为如果不刻意研读,相信即使读过源码,面试者也不一定能 ...

  10. php通过session来实现登录验证

    1.概述 这几天在做一个内部统计管理系统,所有内容需要登录后才能查看.这就需要系统内部每个模块都有登录验证的功能.在网上找了一圈资料,决定用session来做. 2.系统概况 后端语言:php(用的是 ...