hmp 4 ani în urmă
părinte
comite
ad31180901
1 a modificat fișierele cu 30 adăugiri și 22 ștergeri
  1. 30 22
      utils/mpi.js

+ 30 - 22
utils/mpi.js

@@ -46,6 +46,20 @@ const getScopeDesc = (name) => {
 	return title
 }
 
+const settingModal = (content) => {
+	uni.showModal({
+		title: '提示',
+		content,
+		confirmText: '去设置',
+		cancelText: '暂不设置',
+		confirmColor: '#EF9944',
+		success: data => {
+			if (data.confirm) {
+				uni.openSetting();
+			}
+		}
+	});
+}
 
 //打开设置
 const openSetting = (authName) => {
@@ -56,21 +70,24 @@ const openSetting = (authName) => {
 		uni.getSetting({
 			success: (res) => {
 				console.log(res.authSetting);
-				if (res.authSetting[authName]) {
+				let status = res.authSetting[authName]
+				if (status == undefined) {
+					//首次授权
+					uni.authorize({
+						scope: authName,
+						success: (res) => {
+							//成功授权
+							resolve(res)
+						}
+					})
+					return
+				}
+				if (status) {
+					// 已授权
 					resolve(res)
 				} else {
-					uni.showModal({
-						title: '提示',
-						content,
-						confirmText: '去设置',
-						cancelText: '暂不设置',
-						confirmColor: '#EF9944',
-						success: data => {
-							if (data.confirm) {
-								uni.openSetting();
-							}
-						}
-					});
+					//未授权
+					settingModal(content)
 				}
 			}
 		})
@@ -294,13 +311,4 @@ mpi.versioning = (minVersion) => {
 		}
 	})
 }
-
-
-
-
-
-
-
-
-
 export default mpi