更新记录

1.3.0(2022-03-11)

本次主要更新: 1.修复 选择文件之后,不会掉 2.优化相关逻辑

1.2.0(2022-01-26)

本次主要更新: 1.修复ExportOrMoveURLStrs 传的文件路径不存在,出现闪退bug

1.1.0(2021-05-31)

本次主要更新: 1.去除savePath参数配置 2.增加 mode(打开、导入、导出、移动)、多选、后缀名

查看更多

平台兼容性

Android iOS
× 适用版本区间:11 - 16

原生插件通用使用流程:

  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原生插件配置”->”云端插件“列表中删除该插件重新选择


KJ-File

系统文件选择、支持andorid10、限制文件类型(android):https://ext.dcloud.net.cn/plugin?id=7334 文件选择器、快速查询文件、自定义路径、完全自定义UI界面、可多选、自定义类型(android):https://ext.dcloud.net.cn/plugin?id=7608

导入插件

const KJFile = uni.requireNativePlugin('KJ-File');

使用

<template>
    <view>
        <button type="primary" @click="select">选择文件</button>
        <button type="primary" @click="select_v2">选择文件_V2</button>
        <button type="primary" @click="ExportToService">保存文件到服务</button>
        <image :src="filePath">
        <view>文件名:{{fileName}}</view>
    </view>
</template>

<script>
    const KJFile = uni.requireNativePlugin('KJ-File');

    export default {
        data() {
            return {
                filePath: '',
                fileName: ''
            }
        },
        onLoad() {},
        methods: {
            copyToOtherPath(copyPath, copyPathName, filePath) {
                console.log("copyPath:"+copyPath);
                console.log("copyPathName:"+copyPathName);
                console.log("filePath:"+filePath);
                filePath = filePath.replace("file://", "");

                var NSFileManager = plus.ios.importClass("NSFileManager");
                var fileManager = NSFileManager.defaultManager();

                var isFileExist_Path = plus.ios.invoke(fileManager, "fileExistsAtPath:", copyPath);
                console.log("isFileExist_Path:" + isFileExist_Path);
                if (isFileExist_Path == false) {
                    var isCreateDirectory = plus.ios.invoke(fileManager,
                        "createDirectoryAtPath:withIntermediateDirectories:attributes:error:", copyPath, true, null,
                        null);
                    console.log("isCreateDirectory:" + isCreateDirectory);
                }

                var isFileExist_PathName = plus.ios.invoke(fileManager, "fileExistsAtPath:", copyPathName);
                console.log("isFileExist_PathName:" + isFileExist_PathName);
                if (isFileExist_PathName == true) {
                    var isRemove = plus.ios.invoke(fileManager, "removeItemAtPath:error:", copyPathName, null);
                    console.log("isRemove:" + isRemove);
                }

                var isCopy = plus.ios.invoke(fileManager, "copyItemAtPath:toPath:error:", filePath, copyPathName, null);
                console.log("isCopy:" + isCopy);
            },
            select() {
                /**
                 * allowedUTIs如果需要获取更多,访问:https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html
                 */
                var dic = {
                    /**
                     * 关于 "savePath" select_v2版本已去除,为了适配之前的版本  想实现复制功能的话,可以使用copyToOtherPath方法
                     * mode 默认使用的是Import
                     * **/
                    "savePath": plus.io.convertLocalFileSystemURL("_doc/KJ-File"), //复制的绝对路径,一定要是_doc目录
                    "allowedUTIs": [
                        "public.data",
                        "com.microsoft.powerpoint.ppt",
                        "com.microsoft.word.doc",
                        "com.microsoft.excel.xls",
                        "org.openxmlformats.presentationml.presentation",//pptx
                        "org.openxmlformats.wordprocessingml.document",//docx
                        "org.openxmlformats.spreadsheetml.sheet",//xlsx
                        "public.avi",
                        "public.3gpp",
                        "public.mpeg-4",
                        "com.compuserve.gif",
                        "public.jpeg",
                        "public.png",
                        "public.plain-text",
                        "com.adobe.pdf"
                    ],
                }
                KJFile.select(dic, (res) => {
                    console.log("select: " + JSON.stringify(res));
                    this.filePath = "file://" + res.filePath; //以选择的是图片为例
                    this.fileName = res.fileName;
                });
            },
            select_v2() {
                /**
                 * allowedUTIs如果需要获取更多,访问:https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html
                 */
                var dic = {
                    /**
                     * mode
                     * Open->打开(提供对文档的访问权限,可以在适当位置进行编辑); Import->导入(将外部文档复制到您的应用中,使原始文档保持不变); 
                     * ExportToService->导出(将应用内的文档导出到所选的外部目标位置); MoveToService->移动(在应用程序中定位文档的外部目标)
                     * **/
                    "mode": "Import",
                    "allowsMultipleSelection": true, //是否多选 默认false
                    "shouldShowFileExtensions": true, //是否显示后缀名 iOS13 默认false
                    "allowedUTIs": ["public.data",
                        "public.data",
                        "com.microsoft.powerpoint.ppt",
                        "com.microsoft.word.doc",
                        "com.microsoft.excel.xls",
                        "org.openxmlformats.presentationml.presentation",//pptx
                        "org.openxmlformats.wordprocessingml.document",//docx
                        "org.openxmlformats.spreadsheetml.sheet",//xlsx
                        "public.avi",
                        "public.3gpp",
                        "public.mpeg-4",
                        "com.compuserve.gif",
                        "public.jpeg",
                        "public.png",
                        "public.plain-text",
                        "com.adobe.pdf"
                    ],
                }
                KJFile.select_v2(dic, (res) => {
                    console.log("select_v2: " + JSON.stringify(res));
                    var item = res.results[0];

                    //复制到app目录
                    var copyPath = plus.io.convertLocalFileSystemURL("_doc/KJ-File");
                    var copyPathName = copyPath + "/" + item.fileName;
                    var filePath = item.filePath;
                    this.copyToOtherPath(copyPath, copyPathName,filePath);

                    this.filePath = copyPathName; //以选择的是图片为例
                    this.fileName = item.fileName;
                });
            },
            ExportToService() {
                var dic = {
                    /**
                     * mode
                     * Open->打开(提供对文档的访问权限,可以在适当位置进行编辑); Import->导入(将外部文档复制到您的应用中,使原始文档保持不变); 
                     * ExportToService->导出(将应用内的文档导出到所选的外部目标位置); MoveToService->移动(在应用程序中定位文档的外部目标)
                     * **/
                    "mode": "ExportToService", //Open Import ExportToService MoveToService
                    "ExportOrMoveURLStrs": [plus.io.convertLocalFileSystemURL("static/test.mp4")], //导出或移动的文件绝对路径
                }
                KJFile.select_v2(dic, (res) => {
                    console.log("ExportToService: " + JSON.stringify(res));
                });
            }
        }
    }
</script>

隐私、权限声明

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

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

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

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