• 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();      
    },
  • 相关阅读:
    electron之打包成安装程序
    electron之环境安装、启动程序
    微信支付.net官方坑太多,我们来精简
    微信支付官方.net版之坑你没商量
    程序员出路在何方
    简单介绍
    mac中显示隐藏文件
    sublime Text 3 安装emmet
    Andriod学习笔记5:通过NDK在C++中实现日志输出
    Andriod学习笔记4:mac下搭建 Eclipse+CDT 集成开发环境
  • 原文地址:https://www.cnblogs.com/cx709452428/p/9212310.html
Copyright © 2020-2023  润新知