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();      
    },
  • 相关阅读:
    Java加密与解密之非对称加密算法
    Java加密与解密之对称加密算法
    Java加密与解密之消息摘要算法
    基于Spring Cloud Zookeeper的服务注册与发现
    .NET 5.0正式发布,新功能特性(翻译)
    C# 9.0 中的新增功能
    C# 规范建议
    Flutter Weekly Issue 70
    Android 开发技术周报 Issue#298
    Flutter Weekly Issue 69
  • 原文地址:https://www.cnblogs.com/cx709452428/p/9212310.html
Copyright © 2011-2022 走看看