@dongkboy 1 жил өмнө
parent
commit
4e23dc54b5

+ 14 - 2
main.js

@@ -2,7 +2,10 @@ import Vue from 'vue'
 import uView from "uview-ui";
 Vue.use(uView);
 import App from './App'
-
+import {
+	addPermisionInterceptor,
+	removePermisionInterceptor
+} from '@/uni_modules/x-perm-apply-instr/js_sdk/index.js'
 //数据管理中心
 import store from '@/store'
 Vue.prototype.$store = store;
@@ -83,4 +86,13 @@ plus.nativeUI.toast = (function(str) {
 		})
 	}
 });
-// #endif
+// #endif
+
+addPermisionInterceptor('chooseImage', '为了正确识别证件内容,实现图片转文字功能等, 我们需要申请您设备的相机和存储权限')
+addPermisionInterceptor('chooseVideo', '为了发布信息图片视频等, 我们需要申请您设备的相机和存储权限')
+addPermisionInterceptor('saveImageToPhotosAlbum', '为了保存推广海报到手机相册, 我们需要申请您设备的存储权限')
+addPermisionInterceptor('getLocation', '为了根据您的位置展示信息, 我们需要申请您设备的位置权限')
+addPermisionInterceptor('makePhoneCall', '为了联系客服/用户/咨询等, 我们需要申请您设备的拨打电话权限')
+addPermisionInterceptor('getRecorderManager', '为了使用语言消息功能等, 我们需要申请您设备的麦克风权限')
+addPermisionInterceptor('startLocationUpdate', '为了根据您的位置展示信息, 我们需要申请您设备的位置权限')
+addPermisionInterceptor('scanCode', '为了识别二维码信息, 我们需要申请您设备的相机权限')

+ 38 - 0
uni_modules/x-perm-apply-instr/changelog.md

@@ -0,0 +1,38 @@
+## 2.0.3(2024-12-21)
+增加连接蓝牙设备支持 startBluetoothDevicesDiscovery
+## 2.0.2(2024-11-18)
+popup 优化
+## 2.0.1(2024-11-07)
+弹框优化
+## 2.0.0(2024-11-05)
+权限申请说明弹窗修改为顶部原生弹窗,与申请系统权限弹窗同步显示
+## 1.1.5(2024-08-02)
+添加拦截器时增加 once 入参, once 只询问用户一次如果用户不同意申请或同意后拒绝权限将不会再次弹窗
+## 1.1.3(2024-07-30)
+增加 uni.scanCode 支持
+## 1.1.2(2024-07-17)
+chooseImage 和 chooseVideo 的相机和存储权限可以单独申请
+## 1.1.1(2024-06-24)
+优化
+## 1.1.0(2024-06-23)
+增加  startLocationUpdate 支持
+## 1.0.9(2024-04-22)
+1
+## 1.0.8(2024-04-21)
+1
+## 1.0.7(2024-04-21)
+增加 getRecorderManager 拦截支持
+## 1.0.6(2024-04-15)
+文档修改
+## 1.0.5(2024-04-10)
+优化
+## 1.0.4(2024-03-19)
+更新文档
+## 1.0.3(2024-01-16)
+优化
+## 1.0.2(2024-01-03)
+1
+## 1.0.1(2023-12-16)
+解耦
+## 1.0.0(2023-12-14)
+初版

+ 298 - 0
uni_modules/x-perm-apply-instr/js_sdk/index.js

@@ -0,0 +1,298 @@
+import permisionUtil from "./permission.js"
+import { popup } from './native_popup.js'
+
+const prefix = 'permision_'
+const {
+    uniPlatform,
+    platform
+} = uni.getSystemInfoSync()
+
+const permisionMap = {
+    startBluetoothDevicesDiscovery: async function() {
+        try {
+            const status1 = await permisionUtil.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
+            const status2 = await permisionUtil.requestAndroidPermission('android.permission.BLUETOOTH_SCAN')
+            const status3 = await permisionUtil.requestAndroidPermission('android.permission.BLUETOOTH_CONNECT')
+            if (status1 == 1 && status2 == 1 && status3 == 1) {
+                return Promise.resolve(1)
+            } else {
+                return Promise.resolve(-1)
+            }
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    scanCode: async function() {
+        try {
+            const status1 = await permisionUtil.requestAndroidPermission('android.permission.CAMERA')
+            const status2 = await permisionUtil.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
+            if (status1 == 1 || status2 == 1) {
+                return Promise.resolve(1)
+            } else {
+                return Promise.resolve(-1)
+            }
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    album: async function() {
+        try {
+            const status = await permisionUtil.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
+            return Promise.resolve(status)
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    camera: async function() {
+        try {
+            const status = await permisionUtil.requestAndroidPermission('android.permission.CAMERA')
+            return Promise.resolve(status)
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    chooseFile: async function() {
+        try {
+            const status = await permisionUtil.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
+            return Promise.resolve(status)
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    chooseImage: async function() {
+        try {
+            const status1 = await permisionUtil.requestAndroidPermission('android.permission.CAMERA')
+            const status2 = await permisionUtil.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
+            if (status1 == 1 || status2 == 1) {
+                return Promise.resolve(1)
+            } else {
+                return Promise.resolve(-1)
+            }
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    chooseVideo: async function() {
+        try {
+            const status1 = await permisionUtil.requestAndroidPermission('android.permission.CAMERA')
+            const status2 = await permisionUtil.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
+            if (status1 == 1 || status2 == 1) {
+                return Promise.resolve(1)
+            } else {
+                return Promise.resolve(-1)
+            }
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    saveImageToPhotosAlbum: async function() {
+        try {
+            const status = await permisionUtil.requestAndroidPermission('android.permission.WRITE_EXTERNAL_STORAGE')
+            return Promise.resolve(status)
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    saveVideoToPhotosAlbum: async function() {
+        try {
+            const status = await permisionUtil.requestAndroidPermission('android.permission.WRITE_EXTERNAL_STORAGE')
+            return Promise.resolve(status)
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    getLocation: async function() {
+        try {
+            const status = await permisionUtil.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
+            return Promise.resolve(status)
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    startLocationUpdate: async function() {
+        try {
+            const status = await permisionUtil.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
+            return Promise.resolve(status)
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    makePhoneCall: async function() {
+        try {
+            const status = await permisionUtil.requestAndroidPermission('android.permission.CALL_PHONE')
+            return Promise.resolve(status)
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    },
+    getRecorderManager: async function() {
+        try {
+            const status = await permisionUtil.requestAndroidPermission('android.permission.RECORD_AUDIO')
+            return Promise.resolve(status)
+        } catch (e) {
+            return Promise.resolve(0)
+        }
+    }
+}
+
+const resultHandler = function(args, err) {
+    args.fail && args.fail(err)
+    args.complete && args.complete(err)
+}
+
+let getRecorderManagerFlag = false
+const _getRecorderManager = uni.getRecorderManager
+
+const gotoAppPermissionSetting = function() {
+    uni.showModal({
+        title: '提示',
+        content: '当前功能需要开启相应权限,是否前往开启?',
+        cancelText: '否',
+        confirmText: '是',
+        success: (res) => {
+            if (res.confirm) {
+                permisionUtil.gotoAppPermissionSetting()
+            }
+        }
+    })
+}
+
+/**
+ * @func addPermisionInterceptor
+ * @desc 添加权限申请说明拦截
+ * @param {String} permisionName 要拦截的 uniApi 名称
+ * @param {String} content 申请权限说明信息
+ * @param {Boolean} once 只询问一次, 用户不同意申请或拒绝权限将无法使用 uniApi, 如果要继续使用 Api 先用 removePermisionInterceptor 函数移除拦截再调用 Api
+ * @return 无
+ * @Author huiliyi
+ * @Email 1824159241@qq.com
+ */
+export const addPermisionInterceptor = function(permisionName, content, once) {
+    if (uniPlatform != 'app' || platform != 'android') return
+    const getRecorderManagerAdapter = function() {
+        const recorder = _getRecorderManager()
+        const _start = recorder.start.bind(recorder)
+        recorder.start = async function(options) {
+            const perm = uni.getStorageSync(prefix + permisionName)
+            if (perm == 1) {
+                _start(options)
+                return
+            }
+            if (once && typeof perm == 'number') {
+                console.error(`用户不同意申请或已拒绝权限`)
+                return
+            }
+            try {
+                popup.show({ content })
+                let status = 0
+                if (permisionMap[permisionName]) {
+                    status = await permisionMap[permisionName]()
+                } else {
+                    status = 1
+                    console.error(`addPermisionInterceptor fail, ${permisionName}-未配置获取权限方法`)
+                }
+                uni.setStorageSync(prefix + permisionName, status)
+                if (status === 1) {
+                    _start(options)
+                }
+                if (status === 0) {
+                    console.error(`申请麦克风权限失败`)
+                }
+                if (status === -1) {
+                    console.error(`用户已拒绝麦克风权限`)
+                    gotoAppPermissionSetting()
+                }
+            } catch (err) {
+                console.error(err)
+            } finally {
+                popup.close()
+            }
+        }
+        return recorder
+    }
+    if (permisionName == 'getRecorderManager') {
+        if (getRecorderManagerFlag) return
+        uni.getRecorderManager = getRecorderManagerAdapter
+        getRecorderManagerFlag = true
+        return
+    }
+    uni.addInterceptor(permisionName, {
+        invoke(args) {
+            if (args.sourceType && Array.isArray(args.sourceType) && args.sourceType.length == 1) permisionName = args.sourceType[0]
+            return new Promise(async (resolve, reject) => {
+                const perm = uni.getStorageSync(prefix + permisionName)
+                if (perm == 1) {
+                    resolve(args)
+                    return
+                }
+                if (once && typeof perm == 'number') {
+                    reject(args)
+                    resultHandler(args, {
+                        errMsg: '用户不同意申请或已拒绝权限'
+                    })
+                    return
+                }
+                try {
+                    popup.show({ content })
+                    let status = 0
+                    if (permisionMap[permisionName]) {
+                        status = await permisionMap[permisionName]()
+                    } else {
+                        status = 1
+                        console.error(`addPermisionInterceptor fail, ${permisionName}-未配置获取权限方法`)
+                    }
+                    uni.setStorageSync(prefix + permisionName, status)
+                    if (status === 1) {
+                        resolve(args)
+                    }
+                    if (status === 0) {
+                        reject(args)
+                        resultHandler(args, {
+                            errMsg: '申请权限失败'
+                        })
+                    }
+                    if (status === -1) {
+                        reject(args)
+                        resultHandler(args, {
+                            errMsg: '用户已拒绝该权限'
+                        })
+                        gotoAppPermissionSetting()
+                    }
+                } catch (err) {
+                    reject(args)
+                    resultHandler(args, err)
+                } finally {
+                    popup.close()
+                }
+            });
+        },
+        success: (res) => {
+            console.log(res);
+        },
+        fail(err) {
+            console.log('interceptor-fail', err)
+            const errMsg = String(err?.errMsg)
+            if (errMsg.includes('fail No Permission') || (errMsg.includes('fail') && errMsg.includes('权限'))) {
+                uni.setStorageSync(prefix + permisionName, 0)
+                gotoAppPermissionSetting()
+            }
+        }
+    })
+}
+
+/**
+ * @func removePermisionInterceptor
+ * @desc 移除权限申请说明拦截
+ * @param {String} permisionName 要移除拦截的 uniApi 名称
+ * @return 无
+ * @Author huiliyi
+ * @Email 1824159241@qq.com
+ */
+export const removePermisionInterceptor = function(permisionName) {
+    if (permisionName == 'getRecorderManager') {
+        getRecorderManagerFlag = false
+        uni.getRecorderManager = _getRecorderManager
+    }
+    uni.removeInterceptor(permisionName)
+    uni.removeStorageSync(prefix + permisionName)
+}

+ 99 - 0
uni_modules/x-perm-apply-instr/js_sdk/native_popup.js

@@ -0,0 +1,99 @@
+export class NativePopup {
+    constructor(options = {}) {
+        this.sysInfo = uni.getSystemInfoSync()
+
+        const { bgColor = '#fff', titleColor = '#000', contentColor = "#272727" } = options
+
+        this.bgColor = bgColor
+        this.titleColor = titleColor
+        this.contentColor = contentColor
+    }
+
+    createPopup = () => {
+        const { statusBarHeight, screenWidth } = this.sysInfo
+
+        const popupView = new plus.nativeObj.View('popupView', {
+            top: 0,
+            left: 0,
+            width: screenWidth,
+            height: 110 + statusBarHeight + 'px',
+            // backgroundColor: 'blue' // debug
+        })
+
+        popupView.addEventListener("click", this.close)
+
+        const bgPadding = 15
+
+        popupView.drawRect({
+            color: 'rgba(0, 0, 0, 0.1)',
+            radius: '10px'
+        }, {
+            top: statusBarHeight + 7 + 'px',
+            left: bgPadding - 2 + 'px',
+            width: screenWidth - bgPadding * 2 + 4 + 'px',
+            height: "100px",
+        })
+
+        popupView.drawRect({
+            color: this.bgColor,
+            radius: '10px'
+        }, {
+            top: statusBarHeight + 5 + 'px',
+            left: bgPadding + 'px',
+            width: screenWidth - bgPadding * 2 + 'px',
+            height: "100px",
+        })
+
+        const padding = 10
+
+        popupView.drawText(this.title, {
+            top: statusBarHeight + 10 + 'px',
+            left: padding + bgPadding + 'px',
+            height: "30px",
+            width: screenWidth - bgPadding * 2 - padding * 2 + 'px',
+        }, {
+            size: "16px",
+            weight: "bold",
+            align: "left",
+            color: this.titleColor,
+        }, {
+            onClick: function(e) {
+                console.log(e);
+            }
+        })
+
+        popupView.drawText(this.content, {
+            top: statusBarHeight + 40 + 'px',
+            height: "60px",
+            left: padding + bgPadding + 'px',
+            width: screenWidth - bgPadding * 2 - padding * 2 + 'px',
+        }, {
+            size: "14px",
+            align: "left",
+            color: this.contentColor,
+            whiteSpace: 'normal',
+        })
+
+        this.popupView = popupView
+
+        return popupView
+    }
+
+    show = (options = {}) => {
+        this.close()
+
+        const { title = '权限申请说明', content = '' } = options
+        this.title = title
+        this.content = content
+
+        this.createPopup()
+
+        this.popupView.show()
+    }
+
+    close = () => {
+        this.popupView && this.popupView.close()
+    }
+}
+
+export const popup = new NativePopup()

+ 276 - 0
uni_modules/x-perm-apply-instr/js_sdk/permission.js

@@ -0,0 +1,276 @@
+/**
+ * 此文件来源于 https://ext.dcloud.net.cn/plugin?id=594 
+ * 没有将该插件声明为依赖是为避免插件作者更新导致使用方式变化, 所以直接拷贝了一份使用, 有问题请联系QQ:1824159241
+ */
+/**
+ * 本模块封装了Android、iOS的应用权限判断、打开应用权限设置界面、以及位置系统服务是否开启
+ */
+
+var isIos
+// #ifdef APP-PLUS
+isIos = (plus.os.name == "iOS")
+// #endif
+
+// 判断推送权限是否开启
+function judgeIosPermissionPush() {
+    var result = false;
+    var UIApplication = plus.ios.import("UIApplication");
+    var app = UIApplication.sharedApplication();
+    var enabledTypes = 0;
+    if (app.currentUserNotificationSettings) {
+        var settings = app.currentUserNotificationSettings();
+        enabledTypes = settings.plusGetAttribute("types");
+        console.log("enabledTypes1:" + enabledTypes);
+        if (enabledTypes == 0) {
+            console.log("推送权限没有开启");
+        } else {
+            result = true;
+            console.log("已经开启推送功能!")
+        }
+        plus.ios.deleteObject(settings);
+    } else {
+        enabledTypes = app.enabledRemoteNotificationTypes();
+        if (enabledTypes == 0) {
+            console.log("推送权限没有开启!");
+        } else {
+            result = true;
+            console.log("已经开启推送功能!")
+        }
+        console.log("enabledTypes2:" + enabledTypes);
+    }
+    plus.ios.deleteObject(app);
+    plus.ios.deleteObject(UIApplication);
+    return result;
+}
+
+// 判断定位权限是否开启
+function judgeIosPermissionLocation() {
+    var result = false;
+    var cllocationManger = plus.ios.import("CLLocationManager");
+    var status = cllocationManger.authorizationStatus();
+    result = (status != 2)
+    console.log("定位权限开启:" + result);
+    // 以下代码判断了手机设备的定位是否关闭,推荐另行使用方法 checkSystemEnableLocation
+    /* var enable = cllocationManger.locationServicesEnabled();
+    var status = cllocationManger.authorizationStatus();
+    console.log("enable:" + enable);
+    console.log("status:" + status);
+    if (enable && status != 2) {
+    	result = true;
+    	console.log("手机定位服务已开启且已授予定位权限");
+    } else {
+    	console.log("手机系统的定位没有打开或未给予定位权限");
+    } */
+    plus.ios.deleteObject(cllocationManger);
+    return result;
+}
+
+// 判断麦克风权限是否开启
+function judgeIosPermissionRecord() {
+    var result = false;
+    var avaudiosession = plus.ios.import("AVAudioSession");
+    var avaudio = avaudiosession.sharedInstance();
+    var permissionStatus = avaudio.recordPermission();
+    console.log("permissionStatus:" + permissionStatus);
+    if (permissionStatus == 1684369017 || permissionStatus == 1970168948) {
+        console.log("麦克风权限没有开启");
+    } else {
+        result = true;
+        console.log("麦克风权限已经开启");
+    }
+    plus.ios.deleteObject(avaudiosession);
+    return result;
+}
+
+// 判断相机权限是否开启
+function judgeIosPermissionCamera() {
+    var result = false;
+    var AVCaptureDevice = plus.ios.import("AVCaptureDevice");
+    var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide');
+    console.log("authStatus:" + authStatus);
+    if (authStatus == 3) {
+        result = true;
+        console.log("相机权限已经开启");
+    } else {
+        console.log("相机权限没有开启");
+    }
+    plus.ios.deleteObject(AVCaptureDevice);
+    return result;
+}
+
+// 判断相册权限是否开启
+function judgeIosPermissionPhotoLibrary() {
+    var result = false;
+    var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary");
+    var authStatus = PHPhotoLibrary.authorizationStatus();
+    console.log("authStatus:" + authStatus);
+    if (authStatus == 3) {
+        result = true;
+        console.log("相册权限已经开启");
+    } else {
+        console.log("相册权限没有开启");
+    }
+    plus.ios.deleteObject(PHPhotoLibrary);
+    return result;
+}
+
+// 判断通讯录权限是否开启
+function judgeIosPermissionContact() {
+    var result = false;
+    var CNContactStore = plus.ios.import("CNContactStore");
+    var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0);
+    if (cnAuthStatus == 3) {
+        result = true;
+        console.log("通讯录权限已经开启");
+    } else {
+        console.log("通讯录权限没有开启");
+    }
+    plus.ios.deleteObject(CNContactStore);
+    return result;
+}
+
+// 判断日历权限是否开启
+function judgeIosPermissionCalendar() {
+    var result = false;
+    var EKEventStore = plus.ios.import("EKEventStore");
+    var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0);
+    if (ekAuthStatus == 3) {
+        result = true;
+        console.log("日历权限已经开启");
+    } else {
+        console.log("日历权限没有开启");
+    }
+    plus.ios.deleteObject(EKEventStore);
+    return result;
+}
+
+// 判断备忘录权限是否开启
+function judgeIosPermissionMemo() {
+    var result = false;
+    var EKEventStore = plus.ios.import("EKEventStore");
+    var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1);
+    if (ekAuthStatus == 3) {
+        result = true;
+        console.log("备忘录权限已经开启");
+    } else {
+        console.log("备忘录权限没有开启");
+    }
+    plus.ios.deleteObject(EKEventStore);
+    return result;
+}
+
+// Android权限查询
+function requestAndroidPermission(permissionID) {
+    return new Promise((resolve, reject) => {
+        plus.android.requestPermissions(
+            [permissionID], // 理论上支持多个权限同时查询,但实际上本函数封装只处理了一个权限的情况。有需要的可自行扩展封装
+            function(resultObj) {
+                var result = 0;
+                for (var i = 0; i < resultObj.granted.length; i++) {
+                    var grantedPermission = resultObj.granted[i];
+                    console.log('已获取的权限:' + grantedPermission);
+                    result = 1
+                }
+                for (var i = 0; i < resultObj.deniedPresent.length; i++) {
+                    var deniedPresentPermission = resultObj.deniedPresent[i];
+                    console.log('拒绝本次申请的权限:' + deniedPresentPermission);
+                    result = 0
+                }
+                for (var i = 0; i < resultObj.deniedAlways.length; i++) {
+                    var deniedAlwaysPermission = resultObj.deniedAlways[i];
+                    console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
+                    result = -1
+                }
+                resolve(result);
+                // 若所需权限被拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限
+                // if (result != 1) {
+                // gotoAppPermissionSetting()
+                // }
+            },
+            function(error) {
+                console.log('申请权限错误:' + error.code + " = " + error.message);
+                resolve({
+                    code: error.code,
+                    message: error.message
+                });
+            }
+        );
+    });
+}
+
+// 使用一个方法,根据参数判断权限
+function judgeIosPermission(permissionID) {
+    if (permissionID == "location") {
+        return judgeIosPermissionLocation()
+    } else if (permissionID == "camera") {
+        return judgeIosPermissionCamera()
+    } else if (permissionID == "photoLibrary") {
+        return judgeIosPermissionPhotoLibrary()
+    } else if (permissionID == "record") {
+        return judgeIosPermissionRecord()
+    } else if (permissionID == "push") {
+        return judgeIosPermissionPush()
+    } else if (permissionID == "contact") {
+        return judgeIosPermissionContact()
+    } else if (permissionID == "calendar") {
+        return judgeIosPermissionCalendar()
+    } else if (permissionID == "memo") {
+        return judgeIosPermissionMemo()
+    }
+    return false;
+}
+
+// 跳转到**应用**的权限页面
+function gotoAppPermissionSetting() {
+    if (isIos) {
+        var UIApplication = plus.ios.import("UIApplication");
+        var application2 = UIApplication.sharedApplication();
+        var NSURL2 = plus.ios.import("NSURL");
+        // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");		
+        var setting2 = NSURL2.URLWithString("app-settings:");
+        application2.openURL(setting2);
+
+        plus.ios.deleteObject(setting2);
+        plus.ios.deleteObject(NSURL2);
+        plus.ios.deleteObject(application2);
+    } else {
+        // console.log(plus.device.vendor);
+        var Intent = plus.android.importClass("android.content.Intent");
+        var Settings = plus.android.importClass("android.provider.Settings");
+        var Uri = plus.android.importClass("android.net.Uri");
+        var mainActivity = plus.android.runtimeMainActivity();
+        var intent = new Intent();
+        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
+        var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
+        intent.setData(uri);
+        mainActivity.startActivity(intent);
+    }
+}
+
+// 检查系统的设备服务是否开启
+// var checkSystemEnableLocation = async function () {
+function checkSystemEnableLocation() {
+    if (isIos) {
+        var result = false;
+        var cllocationManger = plus.ios.import("CLLocationManager");
+        var result = cllocationManger.locationServicesEnabled();
+        console.log("系统定位开启:" + result);
+        plus.ios.deleteObject(cllocationManger);
+        return result;
+    } else {
+        var context = plus.android.importClass("android.content.Context");
+        var locationManager = plus.android.importClass("android.location.LocationManager");
+        var main = plus.android.runtimeMainActivity();
+        var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
+        var result = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER);
+        console.log("系统定位开启:" + result);
+        return result
+    }
+}
+
+export default {
+    judgeIosPermission: judgeIosPermission,
+    requestAndroidPermission: requestAndroidPermission,
+    checkSystemEnableLocation: checkSystemEnableLocation,
+    gotoAppPermissionSetting: gotoAppPermissionSetting
+}

+ 87 - 0
uni_modules/x-perm-apply-instr/package.json

@@ -0,0 +1,87 @@
+{
+    "id": "x-perm-apply-instr",
+    "displayName": "权限申请说明、权限申请的使用目的、华为上架、小米上架(无需改动代码、全局处理)",
+    "version": "2.0.3",
+    "description": "安卓权限申请的使用目的说明弹窗, 解决华为、小米等应用商店上架审核不通过问题, 无需改动原本代码逻辑",
+    "keywords": [
+        "权限申请",
+        "权限申请的目的",
+        "权限申请的使用目的",
+        "上架",
+        "华为上架"
+    ],
+    "repository": "",
+    "engines": {
+    },
+    "dcloudext": {
+        "type": "sdk-js",
+        "sale": {
+            "regular": {
+                "price": "0.00"
+            },
+            "sourcecode": {
+                "price": "0.00"
+            }
+        },
+        "contact": {
+            "qq": ""
+        },
+        "declaration": {
+            "ads": "无",
+            "data": "插件不采集任何数据",
+            "permissions": "无"
+        },
+        "npmurl": ""
+    },
+    "uni_modules": {
+        "dependencies": [],
+        "encrypt": [],
+        "platforms": {
+            "cloud": {
+                "tcb": "y",
+                "aliyun": "y",
+                "alipay": "n"
+            },
+            "client": {
+                "Vue": {
+                    "vue2": "y",
+                    "vue3": "y"
+                },
+                "App": {
+                    "app-vue": "y",
+                    "app-nvue": "u",
+                    "app-uvue": "u",
+                    "app-harmony": "u"
+                },
+                "H5-mobile": {
+                    "Safari": "u",
+                    "Android Browser": "u",
+                    "微信浏览器(Android)": "u",
+                    "QQ浏览器(Android)": "u"
+                },
+                "H5-pc": {
+                    "Chrome": "u",
+                    "IE": "u",
+                    "Edge": "u",
+                    "Firefox": "u",
+                    "Safari": "u"
+                },
+                "小程序": {
+                    "微信": "u",
+                    "阿里": "u",
+                    "百度": "u",
+                    "字节跳动": "u",
+                    "QQ": "u",
+                    "钉钉": "u",
+                    "快手": "u",
+                    "飞书": "u",
+                    "京东": "u"
+                },
+                "快应用": {
+                    "华为": "u",
+                    "联盟": "u"
+                }
+            }
+        }
+    }
+}

+ 60 - 0
uni_modules/x-perm-apply-instr/readme.md

@@ -0,0 +1,60 @@
+# x-perm-apply-instr
+
+### 安卓应用申请权限时弹窗告知用户使用目的
+
+## 用法说明, 在main.js引入
+```js
+import { addPermisionInterceptor, removePermisionInterceptor } from '@/uni_modules/x-perm-apply-instr/js_sdk/index.js'
+addPermisionInterceptor('chooseImage', '为了修改个人头像和发布信息图片视频等, 我们需要申请您设备的相机和存储权限')
+addPermisionInterceptor('chooseVideo', '为了发布信息图片视频等, 我们需要申请您设备的相机和存储权限')
+addPermisionInterceptor('saveImageToPhotosAlbum', '为了保存推广海报到手机相册, 我们需要申请您设备的存储权限')
+addPermisionInterceptor('getLocation', '为了根据您的位置展示信息, 我们需要申请您设备的位置权限')
+addPermisionInterceptor('makePhoneCall', '为了联系客服/用户/咨询等, 我们需要申请您设备的拨打电话权限')
+addPermisionInterceptor('getRecorderManager', '为了使用语言消息功能等, 我们需要申请您设备的麦克风权限')
+addPermisionInterceptor('startLocationUpdate', '为了根据您的位置展示信息, 我们需要申请您设备的位置权限')
+addPermisionInterceptor('scanCode', '为了识别二维码信息, 我们需要申请您设备的相机权限')
+```
+
+**addPermisionInterceptor 添加 uniApi 调用拦截**
+
+| 位置	| 类型			| 描述																															| 可选值																												|
+| ----	| -------------	| ------------------------------------------------------------																	 | ------------------------------------------------------------																	 |
+| 0		| String		| 要拦截的 uniApi 名称																											| scanCode、chooseImage、chooseVideo、saveImageToPhotosAlbum、saveVideoToPhotosAlbum、getLocation、startLocationUpdate、makePhoneCall、getRecorderManager、startBluetoothDevicesDiscovery	|
+| 1		| String		| 申请权限说明信息																												| 自定义文本																							|
+| 2		| Boolean		| 只询问一次, 用户不同意申请或拒绝权限将无法使用 uniApi, 如果要继续使用 Api 先用 removePermisionInterceptor 函数移除拦截再调用 Api	| true, false	|
+
+**removePermisionInterceptor 移除 uniApi 调用拦截**
+
+| 位置 | 类型        | 描述                     | 可选值                |
+| ---- | ------------- | ------------------------ | ------------------------ |
+| 0    | String | 要移除拦截的 uniApi 名称 | 同上 |
+
+### 注意, 如果需要拦截 getRecorderManager , 在使用时不要直接在 script 下初始化, 会导致拦截失败, 请在 onLoad 或 onReady 中调用
+
+``` vue
+<script>
+	// 错误写法
+	const recorderManager = uni.getRecorderManager();
+	// 正确写法
+	let recorderManager = null
+    export default {
+		onLoad() {
+			recorderManager = uni.getRecorderManager();
+		}
+    }
+</script>
+```
+
+## 手动控制权限说明弹窗(自行控制显示、关闭逻辑)
+```js
+import { popup } from '@/uni_modules/x-perm-apply-instr/js_sdk/native_popup.js'
+// 显示
+popup.show({
+    title: '权限申请说明',
+    content: '为了xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
+})
+// 关闭
+popup.close()
+```
+
+### 插件如果对你有帮助给个好评吧~