You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

blue_power_tool.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * 配置定位权限
  3. */
  4. export function configLoccation(cb) {
  5. wx.getLocation({
  6. type: 'gcj02',
  7. success: function (res) {
  8. typeof cb == "function" && cb(0);
  9. },
  10. fail(res) {
  11. console.log(res);
  12. typeof cb == "function" && cb(-1);
  13. // 手机关闭定位 errMsg: "getLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF"
  14. // 小程序拒绝定位权限 errMsg: "getLocation:fail:auth denied" "getLocation:fail privacy permission is not authorized"
  15. let errMsg = res.errMsg || ''
  16. if (errMsg == 'getLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF') {
  17. wx.showModal({
  18. content: "手机定位服务,请前往手机系统设置开启手机定位服务",
  19. confirmText: "我知道了",
  20. showCancel: false,
  21. });
  22. } else if (errMsg == 'getLocation:fail:auth denied' || errMsg == "getLocation:fail privacy permission is not authorized" || errMsg.includes('auth deny')) {
  23. openSettingInfo();
  24. }
  25. }
  26. });
  27. }
  28. /**
  29. * 打开定位配置
  30. */
  31. function openSettingInfo() {
  32. wx.showModal({
  33. content: "授权定位有助于提高蓝牙数据的连接成功率",
  34. confirmText: "前往设置",
  35. showCancel: false,
  36. success(res) {
  37. if (res.confirm) {
  38. wx.openSetting({})
  39. }
  40. }
  41. });
  42. }
  43. /**
  44. * 配置蓝牙权限
  45. */
  46. export function configScopeBlue() {
  47. return new Promise((resolve, reject) => {
  48. wx.getSetting({
  49. success: res => {
  50. var status = res.authSetting;
  51. if (status["scope.bluetooth"] != undefined && status["scope.bluetooth"] != true) { //非初始化进入并且未授权
  52. wx.showModal({
  53. title: "申请小程序蓝牙权限",
  54. content: "您已拒绝授权开启小程序蓝牙权限,将无法进行激活操作,请前往设置界面,打开蓝牙权限",
  55. success: function (tip) {
  56. if (tip.confirm) {
  57. wx.openSetting({
  58. success: data => {
  59. if (data.authSetting["scope.bluetooth"] === true) {
  60. resolve(1);
  61. } else {
  62. reject("获取蓝牙权限失败");
  63. }
  64. },
  65. fail: () => {
  66. reject("获取蓝牙权限失败");
  67. }
  68. });
  69. } else {
  70. reject("小程序蓝牙权限获取失败,请稍后重试");
  71. }
  72. }
  73. });
  74. } else if (status["scope.bluetooth"] == undefined) { //初始化进入
  75. resolve("0");
  76. } else { //授权后默认加载
  77. resolve(1);
  78. }
  79. },
  80. fail: () => {
  81. reject("调用授权窗口失败");
  82. }
  83. });
  84. });
  85. };
  86. export function configBlueGoSetting(cb) {
  87. let errMsg = "小程序蓝牙权限获取失败,请稍后重试";
  88. wx.showModal({
  89. title: "申请小程序蓝牙权限",
  90. content: "您已拒绝授权开启小程序蓝牙权限,将无法进行激活操作,请前往设置界面,打开蓝牙权限",
  91. success: function (tip) {
  92. if (tip.confirm) {
  93. wx.openSetting({
  94. success: data => {
  95. if (data.authSetting["scope.bluetooth"] === true) {
  96. typeof cb === 'function' && cb(0)
  97. } else {
  98. typeof cb === 'function' && cb(1, errMsg);
  99. }
  100. },
  101. fail: () => {
  102. typeof cb === 'function' && cb(1, errMsg);
  103. }
  104. });
  105. } else {
  106. typeof cb === 'function' && cb(1, errMsg);
  107. }
  108. }
  109. });
  110. }