123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- /**
- * 配置定位权限
- */
- export function configLoccation(cb) {
- wx.getLocation({
- type: 'gcj02',
- success: function (res) {
- typeof cb == "function" && cb(0);
- },
- fail(res) {
- console.log(res);
- typeof cb == "function" && cb(-1);
- // 手机关闭定位 errMsg: "getLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF"
- // 小程序拒绝定位权限 errMsg: "getLocation:fail:auth denied" "getLocation:fail privacy permission is not authorized"
- let errMsg = res.errMsg || ''
- if (errMsg == 'getLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF') {
- wx.showModal({
- content: "手机定位服务,请前往手机系统设置开启手机定位服务",
- confirmText: "我知道了",
- showCancel: false,
-
- });
- } else if (errMsg == 'getLocation:fail:auth denied' || errMsg == "getLocation:fail privacy permission is not authorized" || errMsg.includes('auth deny')) {
- openSettingInfo();
- }
-
- }
- });
- }
-
- /**
- * 打开定位配置
- */
- function openSettingInfo() {
- wx.showModal({
- content: "授权定位有助于提高蓝牙数据的连接成功率",
- confirmText: "前往设置",
- showCancel: false,
- success(res) {
- if (res.confirm) {
- wx.openSetting({})
- }
- }
- });
- }
- /**
- * 配置蓝牙权限
- */
- export function configScopeBlue() {
- return new Promise((resolve, reject) => {
- wx.getSetting({
- success: res => {
- var status = res.authSetting;
- if (status["scope.bluetooth"] != undefined && status["scope.bluetooth"] != true) { //非初始化进入并且未授权
-
- wx.showModal({
- title: "申请小程序蓝牙权限",
- content: "您已拒绝授权开启小程序蓝牙权限,将无法进行激活操作,请前往设置界面,打开蓝牙权限",
- success: function (tip) {
- if (tip.confirm) {
- wx.openSetting({
- success: data => {
- if (data.authSetting["scope.bluetooth"] === true) {
- resolve(1);
- } else {
- reject("获取蓝牙权限失败");
- }
- },
- fail: () => {
- reject("获取蓝牙权限失败");
- }
- });
- } else {
- reject("小程序蓝牙权限获取失败,请稍后重试");
- }
- }
- });
- } else if (status["scope.bluetooth"] == undefined) { //初始化进入
- resolve("0");
- } else { //授权后默认加载
- resolve(1);
- }
- },
- fail: () => {
- reject("调用授权窗口失败");
- }
- });
- });
- };
-
- export function configBlueGoSetting(cb) {
- let errMsg = "小程序蓝牙权限获取失败,请稍后重试";
- wx.showModal({
- title: "申请小程序蓝牙权限",
- content: "您已拒绝授权开启小程序蓝牙权限,将无法进行激活操作,请前往设置界面,打开蓝牙权限",
- success: function (tip) {
- if (tip.confirm) {
- wx.openSetting({
- success: data => {
- if (data.authSetting["scope.bluetooth"] === true) {
- typeof cb === 'function' && cb(0)
- } else {
- typeof cb === 'function' && cb(1, errMsg);
- }
- },
- fail: () => {
- typeof cb === 'function' && cb(1, errMsg);
- }
- });
- } else {
- typeof cb === 'function' && cb(1, errMsg);
- }
- }
- });
-
- }
|