zoukankan      html  css  js  c++  java
  • hbuilder打包集成文件预览

    <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();      
    },
  • 相关阅读:
    ssh 代理详细解释
    c++ extern c
    php 删除换行符
    doxygen 模板
    php 判断字符串
    php 链接 mysql 数据库
    远程桌面管理:tsmmc.msc在xp系统中的使用
    更改Server 2008域用户密码策略
    Windows Server 2008 IIS7部署
    iis6中FTP配置的技巧和细节
  • 原文地址:https://www.cnblogs.com/cx709452428/p/9212310.html
Copyright © 2011-2022 走看看