更新记录

1.0.0(2023-04-18)

首次提交


平台兼容性

Android Android CPU类型 iOS
适用版本区间:5.0 - 10.0 armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 ×

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


系统分享、分享图片、文字、视频等 (超简单) 【请先测试是否符合需求】 不喜勿喷!

1、插件说明

系统分享 、可以将项目中的文件、图片、文字等分享至其他app。 2、作者qq 860987228

3、代码示例

<template>
    <view class="content">
        <button type="primary" @click="shareInfo('image')">分享图片</button>
        <button type="primary" @click="shareInfo('video')">分享视频</button>
        <button type="primary" @click="shareInfo('file')">分享文件</button>
        <button type="primary" @click="shareInfo('text')">分享文本</button>
        <button type="primary" @click="shareImggeInfo()">分享多图</button>
    </view>
</template>

<script>
export default {
    data() {
        return {

        };
    },
    methods: {
        handleShare(fullPath, contentType) {
            const plugin = uni.requireNativePlugin('suPlugin-ShareModule'); // shareFile shareIntent
            plugin.shareFile(fullPath, contentType, result => {
                uni.showModal({
                    title: '温馨提示',
                    content: JSON.stringify(result),
                    success: function(res) {
                        if (res.confirm) {
                            console.log('用户点击确定');
                        } else if (res.cancel) {
                            console.log('用户点击取消');
                        }
                    }
                });
            });
        },
        handleError(e) {
            uni.showModal({
                title: '温馨提示',
                content: '错误-1' + JSON.stringify(e),
                success: function(res) {
                    if (res.confirm) {
                        console.log('用户点击确定');
                    } else if (res.cancel) {
                        console.log('用户点击取消');
                    }
                }
            });
        },
        shareImggeInfo() {
            let self = this;
            let path = '_www/static/doc/logo.png';
            let paths = [];
            //如果是本地文件请参考:将本地_www copy到_doc/下进行分享,否则其他应用无权读取
            //如果是网络资源需要下载存储本地后,拿到绝对路径进行调用
            plus.io.resolveLocalFileSystemURL(path, function(entry) {
                plus.io.resolveLocalFileSystemURL(
                    '_doc/' + entry.name,
                    function(nfile) {
                        //文件如果存在删除后复制分享
                        if (nfile.isFile) nfile.remove();
                        plus.io.resolveLocalFileSystemURL('_doc/', function(ndir) {
                            entry.copyTo(ndir,entry.name,
                                function(nfobj) {
                                    let fullPath = nfobj.fullPath;
                                    paths = [fullPath];
                                    paths.push(fullPath); //模拟图片多张图
                                    self.handleImageShare(paths)
                                },
                                function(e) {
                                    console.log('错误' + JSON.stringify(e));
                                }
                            );
                        });
                    },
                    function(e) {
                        //文件不存在,直接复制分享
                        plus.io.resolveLocalFileSystemURL('_doc/', function(ndir) {
                            entry.copyTo(
                                ndir,
                                entry.name,
                                function(nfobj) {
                                    let fullPath = nfobj.fullPath;
                                    paths = [fullPath];
                                    paths.push(fullPath); //模拟图片多张图
                                    self.handleImageShare(paths)
                                },
                                function(e) {
                                    console.log('错误' + JSON.stringify(e));
                                }
                            );
                        });
                    }
                );
            });
        },
        /* 分享多图 */
        handleImageShare(fullPath){
            const plugin = uni.requireNativePlugin('suPlugin-ShareModule'); // shareFile shareIntent
            plugin.shareMultipleImages(fullPath, result => {

            });
        },
        shareInfo(type) {
            let self = this;
            let path = '';
            if (type == 'image') {
                path = '_www/static/doc/logo.png';
            }
            if (type == 'video') {
                path = '_www/static/doc/video.mp4';
            }
            if (type == 'file') {
                path = '_www/static/doc/testpdf.pdf';
            }
            if (type == 'text') {
                path = '如果吃鱼能补脑,那你得吃一头鲸鱼!';
                this.msg = path;
                this.handleShare(path, type);
                return false;
            }
            this.msg = path;
            //如果是本地文件请参考:将本地_www copy到_doc/下进行分享,否则其他应用无权读取
            //如果是网络资源需要下载存储本地后,拿到绝对路径进行调用
            plus.io.resolveLocalFileSystemURL(path, function(entry) {
                plus.io.resolveLocalFileSystemURL(
                    '_doc/' + entry.name,
                    function(nfile) {
                        //文件如果存在删除后复制分享
                        if (nfile.isFile) nfile.remove();
                        plus.io.resolveLocalFileSystemURL('_doc/', function(ndir) {
                            entry.copyTo(
                                ndir,
                                entry.name,
                                function(nfobj) {
                                    let fullPath = nfobj.fullPath;
                                    self.handleShare(fullPath, type);
                                },
                                function(e) {
                                    self.handleError(e);
                                }
                            );
                        });
                    },
                    function(e) {
                        //文件不存在,直接复制分享
                        plus.io.resolveLocalFileSystemURL('_doc/', function(ndir) {
                            entry.copyTo(
                                ndir,
                                entry.name,
                                function(nfobj) {
                                    let fullPath = nfobj.fullPath;
                                    self.handleShare(fullPath, type);
                                },
                                function(e) {
                                    self.handleError(e);
                                }
                            );
                        });
                    }
                );
            });
        }
    }
};
</script>

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

button {
    margin: 10rpx 0;
    width: 80%;
    font-size: 30rpx;
}
</style>

本地文件请参考:如果是本地_www下的文件请在manifest.json中设置  "plus": {"runmode": "liberate"} //解压资源运行),否则可能会导致文件无法找到
let imagePaths = ['/path/to/image1.jpg', '/path/to/image2.jpg', '/path/to/image3.jpg'];
let paths = []
for (let p of imagePaths) {
 const realPath = plus.io.convertLocalFileSystemURL(p) //转成绝对路径
  paths.push(realPath)
}
如果是网络路径先下载再转成绝对路径:如下
uni.showLoading({
        title: '稍后..'
    });
    uni.downloadFile({
        url: surl, // 换成你的文件地址
        success: res => {
            uni.hideLoading();
            if (res.statusCode === 200) {
                const {
                    tempFilePath
                } = res;
                let filePath = plus.io.convertLocalFileSystemURL(tempFilePath);
                self.handleShare(fullPath, type);
            } else {
                console.log('分享文件失败' + JSON.stringify(res))
            }
        },
        fail: e => {
            uni.hideLoading();
            uni.showModal({
                content: JSON.stringify(e) + '失败'
            });
        }
    });
就这样就完了 ?? 是不是很 so容易

隐私、权限声明

1. 本插件需要申请的系统权限列表:

android.permission.READ_EXTERNAL_STORAGE、 android.permission.WRITE_EXTERNAL_STORAGE

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

本插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问