新增获取权限说明
This commit is contained in:
parent
d06a841a59
commit
e3313c0db8
File diff suppressed because it is too large
Load Diff
@ -357,7 +357,12 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
scanQRcode() {
|
async scanQRcode() {
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
let result = await this.$store.dispatch("permission/requestPermissions",
|
||||||
|
'CAMERA')
|
||||||
|
if (result !== 1) return;
|
||||||
|
// #endif
|
||||||
uni.scanCode({
|
uni.scanCode({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -31,9 +31,14 @@
|
|||||||
let that = this;
|
let that = this;
|
||||||
uni.downloadFile({
|
uni.downloadFile({
|
||||||
url: imageUrl,
|
url: imageUrl,
|
||||||
success(res) {
|
success: async (res)=> {
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
let tempFilePath = res.tempFilePath; // 临时文件路径
|
let tempFilePath = res.tempFilePath; // 临时文件路径
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
let result = await this.$store.dispatch("permission/requestPermissions",
|
||||||
|
'WRITE_EXTERNAL_STORAGE')
|
||||||
|
if (result !== 1) return;
|
||||||
|
// #endif
|
||||||
uni.saveImageToPhotosAlbum({
|
uni.saveImageToPhotosAlbum({
|
||||||
filePath: tempFilePath,
|
filePath: tempFilePath,
|
||||||
success() {
|
success() {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="" style="background-color: #fff;">
|
<view class="" style="background-color: #fff;">
|
||||||
<u-sticky customNavHeight="0">
|
<u-sticky customNavHeight="0">
|
||||||
<view class="head_top">
|
<view class="head_top">
|
||||||
<!-- <u-search placeholder="搜索小区、办公楼等" @custom="searchMap"></u-search>
|
<!-- <u-search placeholder="搜索小区、办公楼等" @custom="searchMap"></u-search>
|
||||||
<view style="height: 20rpx;"></view> -->
|
<view style="height: 20rpx;"></view> -->
|
||||||
<u-tabs :list="tabsList" itemStyle="font-size: 32rpx;height: 74rpx;" :current="current" @change="changeCurrent"
|
<u-tabs :list="tabsList" itemStyle="font-size: 32rpx;height: 74rpx;" :current="current" @change="changeCurrent"
|
||||||
lineColor="#FF6D20" lineWidth="105rpx" height="7rpx"></u-tabs>
|
lineColor="#FF6D20" lineWidth="105rpx" height="7rpx"></u-tabs>
|
||||||
@ -97,8 +97,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
this.$store.dispatch("permission/requestPermissions",
|
||||||
|
'ACCESS_FINE_LOCATION').then(result => {
|
||||||
|
if (result == 1) {
|
||||||
|
this.getLoaction();
|
||||||
|
this.loadArea();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
// #ifndef APP-PLUS
|
||||||
this.getLoaction();
|
this.getLoaction();
|
||||||
this.loadArea();
|
this.loadArea();
|
||||||
|
// #endif
|
||||||
},
|
},
|
||||||
onShow() {},
|
onShow() {},
|
||||||
computed: {
|
computed: {
|
||||||
@ -250,7 +261,7 @@
|
|||||||
latitude: this.latitude,
|
latitude: this.latitude,
|
||||||
longitude: this.longitude
|
longitude: this.longitude
|
||||||
}
|
}
|
||||||
console.log({...obj});
|
console.log({ ...obj });
|
||||||
uni.navigateBack({
|
uni.navigateBack({
|
||||||
success: () => {
|
success: () => {
|
||||||
uni.$emit('changeAddress', obj)
|
uni.$emit('changeAddress', obj)
|
||||||
@ -260,7 +271,7 @@
|
|||||||
return Toast('地址有误,请重新选择')
|
return Toast('地址有误,请重新选择')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
searchMap(){
|
searchMap() {
|
||||||
uni.request({
|
uni.request({
|
||||||
url: 'https://restapi.amap.com/v3/place/text?keywords=北京大学&city=beijing&offset=20&page=1&key=0799f37420c0784f1e6cba230a68bdb1&extensions=all',
|
url: 'https://restapi.amap.com/v3/place/text?keywords=北京大学&city=beijing&offset=20&page=1&key=0799f37420c0784f1e6cba230a68bdb1&extensions=all',
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
|
@ -1564,7 +1564,7 @@
|
|||||||
title: '下单成功,请上传支付凭证!'
|
title: '下单成功,请上传支付凭证!'
|
||||||
}, {
|
}, {
|
||||||
tab: 5,
|
tab: 5,
|
||||||
url: "/pages/users/order_list/index"
|
url: "/pages/users/order_list/index?sale_type="+ this.sale_type
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
|
@ -245,7 +245,15 @@
|
|||||||
* 上传图片文件
|
* 上传图片文件
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uploadpic: function() {
|
uploadpic: async function() {
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
let result = await this.$store.dispatch("permission/requestPermissions",
|
||||||
|
'CAMERA')
|
||||||
|
if (result !== 1) return;
|
||||||
|
result = await this.$store.dispatch("permission/requestPermissions",
|
||||||
|
'READ_EXTERNAL_STORAGE')
|
||||||
|
if (result !== 1) return;
|
||||||
|
// #endif
|
||||||
let that = this;
|
let that = this;
|
||||||
if (that.open_update_info == 0) {
|
if (that.open_update_info == 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
import app from "./app";
|
import app from "./app";
|
||||||
import storage from "./storage.js";
|
import storage from "./storage.js";
|
||||||
|
import permission from "./permission.js";
|
||||||
export default {
|
export default {
|
||||||
app,
|
app,
|
||||||
storage
|
storage,
|
||||||
|
permission
|
||||||
};
|
};
|
249
store/modules/permission.js
Normal file
249
store/modules/permission.js
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
// 权限说明
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
WRITE_EXTERNAL_STORAGE: false,
|
||||||
|
READ_EXTERNAL_STORAGE: false,
|
||||||
|
CAMERA: false,
|
||||||
|
CALL_PHONE: false,
|
||||||
|
ACCESS_FINE_LOCATION: false,
|
||||||
|
/* #ifdef APP-PLUS */
|
||||||
|
isIos: plus.os.name == "iOS",
|
||||||
|
/* #endif */
|
||||||
|
mapping: {
|
||||||
|
'WRITE_EXTERNAL_STORAGE': {
|
||||||
|
title: "存储空间/照片权限说明",
|
||||||
|
content: "便于您使用该功能上传您的照片/图片/视频及用于更换头像、发布评论/分享、下载、与客服沟通等场景中读取和写入相册和文件内容。",
|
||||||
|
methods: 'SET_WRITE_EXTERNAL_STORAGE'
|
||||||
|
},
|
||||||
|
'READ_EXTERNAL_STORAGE': {
|
||||||
|
title: "存储空间/照片权限说明",
|
||||||
|
content: "便于您使用该功能上传您的照片/图片/视频及用于更换头像、发布评论/分享、下载、与客服沟通等场景中读取和写入相册和文件内容。",
|
||||||
|
methods: 'SET_READ_EXTERNAL_STORAGE'
|
||||||
|
},
|
||||||
|
'CAMERA': {
|
||||||
|
title: "相机/存储空间/照片权限说明",
|
||||||
|
content: "便于您使用该功能上传您的照片/图片/视频及用于更换头像、发布评论/分享、下载、与客服沟通等场景中读取和写入相册和文件内容。",
|
||||||
|
methods: 'SET_CAMERA'
|
||||||
|
},
|
||||||
|
'CALL_PHONE': {
|
||||||
|
title: "拨打/管理电话权限说明",
|
||||||
|
content: "便于您使用该功能联系商家或者商家与您联系等场景",
|
||||||
|
methods: 'SET_CALL_PHONE'
|
||||||
|
},
|
||||||
|
'ACCESS_FINE_LOCATION': {
|
||||||
|
title: "获取位置权限说明",
|
||||||
|
content: "便于您使用该功能查看附近店铺/附近商品/店铺所在位置等场景",
|
||||||
|
methods: 'SET_ACCESS_FINE_LOCATION'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const mutations = {
|
||||||
|
SET_WRITE_EXTERNAL_STORAGE(state, val) {
|
||||||
|
state.WRITE_EXTERNAL_STORAGE = val
|
||||||
|
},
|
||||||
|
SET_CALL_PHONE(state, val) {
|
||||||
|
state.CALL_PHONE = val
|
||||||
|
},
|
||||||
|
SET_READ_EXTERNAL_STORAGE(state, val) {
|
||||||
|
state.READ_EXTERNAL_STORAGE = val
|
||||||
|
},
|
||||||
|
SET_CAMERA(state, val) {
|
||||||
|
state.CAMERA = val
|
||||||
|
},
|
||||||
|
SET_ACCESS_FINE_LOCATION(state, val) {
|
||||||
|
state.ACCESS_FINE_LOCATION = val
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const actions = {
|
||||||
|
//权限获取
|
||||||
|
async requestPermissions({
|
||||||
|
state,
|
||||||
|
dispatch,
|
||||||
|
commit
|
||||||
|
}, permissionID) {
|
||||||
|
try {
|
||||||
|
if (!state[permissionID] && !state.isIos) {
|
||||||
|
var viewObj = await dispatch('nativeObjView', permissionID);
|
||||||
|
viewObj.show();
|
||||||
|
}
|
||||||
|
console.log('android.permission.' + permissionID, '当前手机权限');
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
//苹果不需要这个
|
||||||
|
if(state.isIos){
|
||||||
|
resolve(1);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 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);
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log('申请权限错误:' + error.code + " = " + error
|
||||||
|
.message);
|
||||||
|
resolve({
|
||||||
|
code: error.code,
|
||||||
|
message: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await requestAndroidPermission(
|
||||||
|
'android.permission.' + permissionID
|
||||||
|
);
|
||||||
|
if (result === 1) {
|
||||||
|
//'已获得授权'
|
||||||
|
commit(state.mapping[permissionID].methods, true)
|
||||||
|
} else if (result === 0) {
|
||||||
|
//'未获得授权'
|
||||||
|
commit(state.mapping[permissionID].methods, false)
|
||||||
|
} else {
|
||||||
|
commit(state.mapping[permissionID].methods, true)
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '操作权限已被拒绝,请手动前往设置',
|
||||||
|
confirmText: "立即设置",
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
dispatch('gotoAppPermissionSetting')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (viewObj) viewObj.close()
|
||||||
|
resolve(result);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
//提示框
|
||||||
|
nativeObjView({
|
||||||
|
state
|
||||||
|
}, permissionID) {
|
||||||
|
const systemInfo = uni.getSystemInfoSync();
|
||||||
|
const statusBarHeight = systemInfo.statusBarHeight;
|
||||||
|
const navigationBarHeight = systemInfo.platform === 'android' ? 48 :
|
||||||
|
44; // Set the navigation bar height based on the platform
|
||||||
|
const totalHeight = statusBarHeight + navigationBarHeight;
|
||||||
|
let view = new plus.nativeObj.View('per-modal', {
|
||||||
|
top: '0px',
|
||||||
|
left: '0px',
|
||||||
|
width: '100%',
|
||||||
|
backgroundColor: '#444',
|
||||||
|
//opacity: .5;
|
||||||
|
})
|
||||||
|
view.drawRect({
|
||||||
|
color: '#fff',
|
||||||
|
radius: '5px'
|
||||||
|
}, {
|
||||||
|
top: totalHeight + 'px',
|
||||||
|
left: '5%',
|
||||||
|
width: '90%',
|
||||||
|
height: "100px",
|
||||||
|
})
|
||||||
|
view.drawText(state.mapping[permissionID].title, {
|
||||||
|
top: totalHeight + 5 + 'px',
|
||||||
|
left: "8%",
|
||||||
|
height: "30px"
|
||||||
|
}, {
|
||||||
|
align: "left",
|
||||||
|
color: "#000",
|
||||||
|
}, {
|
||||||
|
onClick: function (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
view.drawText(state.mapping[permissionID].content, {
|
||||||
|
top: totalHeight + 35 + 'px',
|
||||||
|
height: "60px",
|
||||||
|
left: "8%",
|
||||||
|
width: "84%"
|
||||||
|
}, {
|
||||||
|
whiteSpace: 'normal',
|
||||||
|
size: "14px",
|
||||||
|
align: "left",
|
||||||
|
color: "#656563"
|
||||||
|
})
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
view = plus.nativeObj.View.getViewById('per-modal');
|
||||||
|
view.show()
|
||||||
|
view = null//展示的时候也得清空,不然影响下次的关闭,不知道为啥
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
view = plus.nativeObj.View.getViewById('per-modal');
|
||||||
|
view.close();
|
||||||
|
view = null
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
show,
|
||||||
|
close
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 跳转到**应用**的权限页面
|
||||||
|
gotoAppPermissionSetting({
|
||||||
|
state
|
||||||
|
}) {
|
||||||
|
if (state.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default {
|
||||||
|
namespaced: true,
|
||||||
|
state,
|
||||||
|
mutations,
|
||||||
|
actions
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user