H5内嵌微信、IOS、android查看文件

H5嵌入三端查看文件 方法

loadFile 与安卓、IOS工程师约定好的调用方法
  • window.webkit.messageHandlers.loadFile
  • window.android.loadFile
// 查看文件
export function handleShowFile(fileurl) {
    if (this.$store.state.isWeixin) {
        wx.miniProgram.getEnv(res => {
            if (res.miniprogram) {
                wx.miniProgram.navigateTo({
                    url: `/myPackage/pages/showf/index?urlf= fileurl`,
                });
            }
        });
    } else {
        if (this.$store.state.isAndroid) {
            window.android.loadFile(fileurl);
        } else if (this.$store.state.isIOS) {
            try {
                window.webkit.messageHandlers.loadFile.postMessage(fileurl);
            } catch {
                console.log('当前不在IOS系统');
            }
        }

    }
}
posted @ 2021-12-15 11:39  Hekiss  阅读(72)  评论(0编辑  收藏  举报