衣天下
衣天下
  • 发布:2021-06-17 12:15
  • 更新:2021-06-17 18:18
  • 阅读:1204

【报Bug】uni.openDocument在iOS上报fail 文件没有发现

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 10.15.5

HBuilderX类型: 正式

HBuilderX版本号: 3.1.18

手机系统: iOS

手机系统版本号: IOS 14

手机厂商: 苹果

手机机型: iphone xs max

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

``
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title" @tap='clickHandler'>导出</text>
</view>
</view>
</template>

<script>
let doExport = require('@/js_sdk/exportExcel/exportExcel.js');
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {

    },  
    methods: {  
        clickHandler(){  
            var Excel_list = []  
            Excel_list.push([  
                {content: '序号',width: '200px',height: '25px',},  
                {content: '批次',width: '200px',height: '25px',},  
                {content: '发生日期',width: '200px',height: '25px',},  
                {content: '客户名称',width: '200px',height: '25px',},  
                {content: '店员',width: '200px',height: '25px',},  
                {content: '款号',width: '200px',height: '25px',},  
                {content: '名称',width: '200px',height: '25px',},  
                {content: '颜色',width: '200px',height: '25px',},  
                {content: '尺码',width: '200px',height: '25px',},  
                {content: '数量',width: '200px',height: '25px',},  
                {content: '发货情况',width: '200px',height: '25px',},  
                {content: '品牌',width: '200px',height: '25px',},  
            ])  
            doExport('销售报表',Excel_list,this.ExportCall)  
        },  
        ExportCall(e){  
            var url = ''  
            if(plus.os.name == 'Android'){  
                url = '/storage/emulated/0'  
            }else if(plus.os.name == 'iOS'){  
                url = 'file://'  
            }  
            console.log(url+e);  
            uni.openDocument({  
                filePath:url+e,  
                success(res) {  
                    console.log(res);  
                },  
                fail(e) {  
                    console.log(e);  
                }  
            })  
        }  
    }  
}  

</script>

<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

.logo {  
    height: 200rpx;  
    width: 200rpx;  
    margin-top: 200rpx;  
    margin-left: auto;  
    margin-right: auto;  
    margin-bottom: 50rpx;  
}  

.text-area {  
    display: flex;  
    justify-content: center;  
}  

.title {  
    font-size: 36rpx;  
    color: #8f8f94;  
}  

</style>

``

操作步骤:

本地生成一个Excel文件,然后使用openDocument打开,IOS下3.1.13版本可以正常打开文件,更新到3.1.18就报 {"errMsg":"openDocument:fail 文件没有发现"}

预期结果:

本地生成一个Excel文件,然后使用openDocument打开,IOS下3.1.13版本可以正常打开文件,更新到3.1.18就报 {"errMsg":"openDocument:fail 文件没有发现"}

实际结果:

本地生成一个Excel文件,然后使用openDocument打开,IOS下3.1.13版本可以正常打开文件,更新到3.1.18就报 {"errMsg":"openDocument:fail 文件没有发现"}

bug描述:

导出成功,文件位置:/var/mobile/Containers/Data/Application/E0575F5D-C442-479C-A5E2-FB18FED900FF/Documents/Pandora/documents/导出的Excel/20210617121042_销售报表/20210617121042_销售报表.xlsx at js_sdk/exportExcel/exportExcel.js:174   
12:10:44.715  file:///var/mobile/Containers/Data/Application/E0575F5D-C442-479C-A5E2-FB18FED900FF/Documents/Pandora/documents/导出的Excel/20210617121042_销售报表/20210617121042_销售报表.xlsx at pages/index/index.vue:47   
12:10:44.735  [Object] {"errMsg":"openDocument:fail 文件没有发现"}  at pages/index/index.vue:54 
2021-06-17 12:15 负责人:无 分享
已邀请:
衣天下

衣天下 (作者)

<template>  
    <view class="content">  
        <image class="logo" src="/static/logo.png"></image>  
        <view class="text-area">  
            <text class="title" @tap='clickHandler'>导出</text>  
        </view>  
    </view>  
</template>  

<script>  
    let doExport = require('@/js_sdk/exportExcel/exportExcel.js');  
    export default {  
        data() {  
            return {  
                title: 'Hello'  
            }  
        },  
        onLoad() {  

        },  
        methods: {  
            clickHandler(){  
                var Excel_list = []  
                Excel_list.push([  
                    {content: '序号',width: '200px',height: '25px',},  
                    {content: '批次',width: '200px',height: '25px',},  
                    {content: '发生日期',width: '200px',height: '25px',},  
                    {content: '客户名称',width: '200px',height: '25px',},  
                    {content: '店员',width: '200px',height: '25px',},  
                    {content: '款号',width: '200px',height: '25px',},  
                    {content: '名称',width: '200px',height: '25px',},  
                    {content: '颜色',width: '200px',height: '25px',},  
                    {content: '尺码',width: '200px',height: '25px',},  
                    {content: '数量',width: '200px',height: '25px',},  
                    {content: '发货情况',width: '200px',height: '25px',},  
                    {content: '品牌',width: '200px',height: '25px',},  
                ])  
                doExport('销售报表',Excel_list,this.ExportCall)  
            },  
            ExportCall(e){  
                var url = ''  
                if(plus.os.name == 'Android'){  
                    url = '/storage/emulated/0'  
                }else if(plus.os.name == 'iOS'){  
                    url = 'file://'  
                }  
                console.log(url+e);  
                uni.openDocument({  
                    filePath:url+e,  
                    success(res) {  
                        console.log(res);  
                    },  
                    fail(e) {  
                        console.log(e);  
                    }  
                })  
            }  
        }  
    }  
</script>  

<style>  
    .content {  
        display: flex;  
        flex-direction: column;  
        align-items: center;  
        justify-content: center;  
    }  

    .logo {  
        height: 200rpx;  
        width: 200rpx;  
        margin-top: 200rpx;  
        margin-left: auto;  
        margin-right: auto;  
        margin-bottom: 50rpx;  
    }  

    .text-area {  
        display: flex;  
        justify-content: center;  
    }  

    .title {  
        font-size: 36rpx;  
        color: #8f8f94;  
    }  
</style>  
衣天下

衣天下 (作者)

已上传demo

天生DR

天生DR - 天生我材必有用

养成好习惯 文件目录 用英文不要用中文和特殊字符 非要用的话 文件目录 文件名等 最好自己encode一下

在iOS 的真机系统下 在构建URL时 如果不对 中文做特殊处理 URL值为空

  • d***@nvr.cn

    请问下载的文件使用中文标题,然后openducument的时候无法打开,这个该怎么处理,如果下载不使用中文标题,文件分享出去标题不好区分

    2021-07-16 16:25

该问题目前已经被锁定, 无法添加新回复