Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
lumastoreapp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xieyishang
lumastoreapp
Commits
6abaf387
Commit
6abaf387
authored
Oct 31, 2024
by
xieyishang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
~~
parent
22c7b4dd
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
739 additions
and
5 deletions
+739
-5
components/showxieyi/showxieyi.vue
components/showxieyi/showxieyi.vue
+1
-1
main.js
main.js
+16
-0
manifest.json
manifest.json
+2
-2
pages/setup/setup.vue
pages/setup/setup.vue
+1
-1
pages/user/fenxiao/addcard/addcard.vue
pages/user/fenxiao/addcard/addcard.vue
+11
-1
utils/js_sdk/AS-NotifyTheAuthority/index.js
utils/js_sdk/AS-NotifyTheAuthority/index.js
+144
-0
utils/js_sdk/AS-NotifyTheAuthority/package.json
utils/js_sdk/AS-NotifyTheAuthority/package.json
+20
-0
utils/js_sdk/index.js
utils/js_sdk/index.js
+270
-0
utils/js_sdk/permission.js
utils/js_sdk/permission.js
+274
-0
No files found.
components/showxieyi/showxieyi.vue
View file @
6abaf387
...
...
@@ -7,7 +7,7 @@
<text
class=
"uni-tip-title"
>
用户协议和隐私政策
</text>
<view
class=
"uni-tip-content flex ali-c"
>
请您务必审慎阅读、充分理解"用户协议"和"隐私政策"各条款,包括但不限于为您提供软件内容的服务,我们需要收集您的设备信息、操作日志等个人信息您可以在设置中查看个人信息并修改你的信息您可阅读
<navigator
class=
"xieyitags"
url=
"/pages/Agreement/Agreementuser"
>
《用户协议》
</navigator>
和
<navigator
class=
"xieyitags"
url=
"/pages/Agreement/Agreement"
>
《隐私政策》
</navigator>
了解详细信息。如您同意,请点击"同意"开始接受我们的服务
</view>
<view
class=
"uni-tip-group-button"
>
<text
class=
"uni-tip-button"
@
click=
"cancel('tip')"
>
暂不使用
</text>
<text
class=
"uni-tip-button"
@
click=
"cancel('tip')"
>
拒绝
</text>
<text
class=
"uni-tip-button"
@
click=
"tongyi('tip')"
>
同意
</text>
</view>
</view>
...
...
main.js
View file @
6abaf387
...
...
@@ -6,6 +6,22 @@ import store from './store'//状态管理
import
LbPicker
from
'
@/components/lb-picker
'
Vue
.
component
(
"
lb-picker
"
,
LbPicker
)
//权限申请
import
{
addPermisionInterceptor
}
from
'
@/utils/js_sdk/index.js
'
addPermisionInterceptor
(
'
scanCode
'
,
'
为了扫码从相册获取图片, 我们需要申请您设备的相机和照片读取权限
'
);
//OK
addPermisionInterceptor
(
'
makePhoneCall
'
,
'
为了联系客服/用户/咨询等, 我们需要申请您设备的拨打电话权限
'
);
//OK
addPermisionInterceptor
(
'
chooseImage
'
,
'
为了上传产品资料和完善商户资料等, 我们需要申请您设备的相机和存储权限
'
)
addPermisionInterceptor
(
'
chooseVideo
'
,
'
为了发布产品图片视频等, 我们需要申请您设备的相机和存储权限
'
)
addPermisionInterceptor
(
'
saveImageToPhotosAlbum
'
,
'
为了保存商家码到手机相册, 我们需要申请您设备的存储权限
'
)
addPermisionInterceptor
(
'
chooseLocation
'
,
'
为了获取你的经营地址位置, 我们需要获取你的位置权限
'
)
import
{
getTimeOut
,
timestampToTime
,
//10位时间戳 转年月日时分秒
...
...
manifest.json
View file @
6abaf387
...
...
@@ -2,8 +2,8 @@
"name"
:
"鹿马商家助手"
,
"appid"
:
"__UNI__1EA80F1"
,
//这个是
web
的
"description"
:
"商家"
,
"versionName"
:
"1.20
2
"
,
"versionCode"
:
120
2
,
"versionName"
:
"1.20
6
"
,
"versionCode"
:
120
6
,
"transformPx"
:
false
,
"compatible"
:
{
"ignoreVersion"
:
true
//
true
表示忽略版本检查提示框,HBuilderX
1.9
.
0
及以上版本支持
...
...
pages/setup/setup.vue
View file @
6abaf387
...
...
@@ -76,7 +76,7 @@
<image
class=
"jiantousi"
src=
"/static/news/jiantousi.png"
mode=
""
></image>
</navigator>
<navigator
url=
"/pages/Agreement/Agreement"
class=
"list-cell b-b"
hover-class=
"cell-hover"
:hover-stay-time=
"50"
>
<text
class=
"cell-tit"
>
隐私
策略
</text>
<text
class=
"cell-tit"
>
隐私
政策
</text>
<image
class=
"jiantousi"
src=
"/static/news/jiantousi.png"
mode=
""
></image>
</navigator>
<view
class=
"list-cell b-b"
hover-class=
"cell-hover"
@
click=
"go"
:hover-stay-time=
"50"
>
...
...
pages/user/fenxiao/addcard/addcard.vue
View file @
6abaf387
...
...
@@ -55,7 +55,17 @@
};
},
onLoad
(
option
)
{
this
.
$showModal
({
title
:
'
温馨提示
'
,
concent
:
'
系统添加银行卡需要你填写(开户行 银行卡号 开户支行 姓名)是否同意?
'
,
confirmVal
:
'
同意
'
,
cancelVal
:
'
取消
'
,
}).
then
(
res
=>
{
}).
catch
(()
=>
{
uni
.
navigateBack
();
})
},
...
...
utils/js_sdk/AS-NotifyTheAuthority/index.js
0 → 100644
View file @
6abaf387
/**
* https://ext.dcloud.net.cn/plugin?id=11947
* 当前通知权限开启查询
* @returns {Boolean} true:已开启 false:未开启
*/
import
sj_show_modal
from
'
../../../components/G_show_modal/index.js
'
;
//弹窗
const
$showModal
=
(
op
=
{})
=>
{
console
.
info
(
"
ddd
"
);
return
new
Promise
((
resolve
,
reject
)
=>
{
let
ssm
=
new
sj_show_modal
({
...
op
,
$event
:
(
e
)
=>
{
if
(
e
.
res
)
{
resolve
(
e
);
}
else
{
reject
(
e
);
}
}
})
ssm
.
show
();
})
}
export
const
isNotificationsEnabled
=
()
=>
{
// #ifdef APP-PLUS
if
(
plus
.
os
.
name
==
'
Android
'
)
{
// 判断是Android
var
main
=
plus
.
android
.
runtimeMainActivity
()
var
NotificationManagerCompat
=
plus
.
android
.
importClass
(
'
android.support.v4.app.NotificationManagerCompat
'
)
if
(
NotificationManagerCompat
==
null
)
{
NotificationManagerCompat
=
plus
.
android
.
importClass
(
'
androidx.core.app.NotificationManagerCompat
'
)
}
// 返回是否有权限
return
NotificationManagerCompat
.
from
(
main
).
areNotificationsEnabled
()
}
else
if
(
plus
.
os
.
name
==
'
iOS
'
)
{
// 判断是iOS
var
isOn
=
undefined
var
types
=
0
var
app
=
plus
.
ios
.
invoke
(
'
UIApplication
'
,
'
sharedApplication
'
)
var
settings
=
plus
.
ios
.
invoke
(
app
,
'
currentUserNotificationSettings
'
)
if
(
settings
)
{
types
=
settings
.
plusGetAttribute
(
'
types
'
)
plus
.
ios
.
deleteObject
(
settings
)
}
else
{
types
=
plus
.
ios
.
invoke
(
app
,
'
enabledRemoteNotificationTypes
'
)
}
plus
.
ios
.
deleteObject
(
app
)
isOn
=
0
!=
types
// 返回是否有权限
return
isOn
}
// #endif
}
/**
* 前往系统设置的功能
* @param {Boolean} type true:开启 false:关闭
* @returns
*/
export
const
permissions
=
(
type
)
=>
{
// #ifdef APP-PLUS
if
(
plus
.
os
.
name
==
'
Android
'
)
{
// 判断是Android
var
main
=
plus
.
android
.
runtimeMainActivity
()
var
pkName
=
main
.
getPackageName
()
var
uid
=
main
.
getApplicationInfo
().
plusGetAttribute
(
'
uid
'
)
$showModal
({
title
:
`通知权限
${
type
?
'
开启
'
:
'
关闭
'
}
提醒`
,
concent
:
`是否前往设置
${
type
?
'
开启
'
:
'
关闭
'
}
通知权限?`
,
confirmVal
:
'
确定
'
,
cancelVal
:
'
取消
'
,
}).
then
(
res
=>
{
var
Intent
=
plus
.
android
.
importClass
(
'
android.content.Intent
'
)
var
Build
=
plus
.
android
.
importClass
(
'
android.os.Build
'
)
//android 8.0引导
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
{
var
intent
=
new
Intent
(
'
android.settings.APP_NOTIFICATION_SETTINGS
'
)
intent
.
putExtra
(
'
android.provider.extra.APP_PACKAGE
'
,
pkName
)
}
else
if
(
Build
.
VERSION
.
SDK_INT
>=
21
)
{
//android 5.0-7.0
var
intent
=
new
Intent
(
'
android.settings.APP_NOTIFICATION_SETTINGS
'
)
intent
.
putExtra
(
'
app_package
'
,
pkName
)
intent
.
putExtra
(
'
app_uid
'
,
uid
)
}
else
{
//(<21)其他--跳转到该应用管理的详情页
intent
.
setAction
(
Settings
.
ACTION_APPLICATION_DETAILS_SETTINGS
)
var
uri
=
Uri
.
fromParts
(
'
package
'
,
mainActivity
.
getPackageName
(),
null
)
intent
.
setData
(
uri
)
}
// 跳转到该应用的系统通知设置页
main
.
startActivity
(
intent
)
}).
catch
(
err
=>
{
console
.
log
(
'
err
'
,
err
)
console
.
log
(
'
点击了取消
'
)
})
}
else
if
(
plus
.
os
.
name
==
'
iOS
'
)
{
// 判断是iOS
var
app
=
plus
.
ios
.
invoke
(
'
UIApplication
'
,
'
sharedApplication
'
)
plus
.
ios
.
deleteObject
(
app
)
$showModal
({
title
:
`通知权限
${
type
?
'
开启
'
:
'
关闭
'
}
提醒`
,
concent
:
`是否前往设置
${
type
?
'
开启
'
:
'
关闭
'
}
通知权限?`
,
confirmVal
:
'
确定
'
,
cancelVal
:
'
取消
'
,
}).
then
(
res
=>
{
var
app
=
plus
.
ios
.
invoke
(
'
UIApplication
'
,
'
sharedApplication
'
)
var
setting
=
plus
.
ios
.
invoke
(
'
NSURL
'
,
'
URLWithString:
'
,
'
app-settings:
'
)
plus
.
ios
.
invoke
(
app
,
'
openURL:
'
,
setting
)
plus
.
ios
.
deleteObject
(
setting
)
plus
.
ios
.
deleteObject
(
app
)
}).
catch
(
err
=>
{
console
.
log
(
'
err
'
,
err
)
console
.
log
(
'
点击了取消
'
)
})
}
// #endif
}
\ No newline at end of file
utils/js_sdk/AS-NotifyTheAuthority/package.json
0 → 100644
View file @
6abaf387
{
"id"
:
"AS-NotifyTheAuthority"
,
"name"
:
"AS-NotifyTheAuthority(推送通知权限查询与前往设置的功能)"
,
"displayName"
:
"AS-NotifyTheAuthority(推送通知权限查询与前往设置的功能)"
,
"version"
:
"1.0.1"
,
"description"
:
"Android(安卓)IOS(苹果)的推送通知权限查询与前往设置的功能"
,
"keywords"
:
[
"通知权限"
,
"推送权限"
,
"ios通知"
,
"安卓通知"
,
"通知"
],
"dcloudext"
:
{
"category"
:
[
"JS SDK"
,
"通用 SDK"
]
}
}
\ No newline at end of file
utils/js_sdk/index.js
0 → 100644
View file @
6abaf387
// https://ext.dcloud.net.cn/plugin?id=15897
import
permisionUtil
from
"
./permission.js
"
import
sj_show_modal
from
'
../../components/G_show_modal/index.js
'
;
//弹窗
const
$showModal
=
(
op
=
{})
=>
{
console
.
info
(
"
ddd
"
);
return
new
Promise
((
resolve
,
reject
)
=>
{
let
ssm
=
new
sj_show_modal
({
...
op
,
$event
:
(
e
)
=>
{
if
(
e
.
res
)
{
resolve
(
e
);
}
else
{
reject
(
e
);
}
}
})
ssm
.
show
();
})
}
const
permisionMap
=
{
//选择图片
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
)
}
},
//获取经纬度
getLocation
:
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
)
}
}
}
const
resultHandler
=
function
(
args
,
err
)
{
args
.
fail
&&
args
.
fail
(
err
)
args
.
complete
&&
args
.
complete
(
err
)
}
/**
* @func addPermisionInterceptor
* @desc 添加权限申请说明
* @param {String} permisionName 要拦截的 uniApi 名称
* @param {String} content 申请权限说明信息
* @return {}
* @Author huiliyi
* @Email 1824159241@qq.com
*/
export
const
addPermisionInterceptor
=
function
(
permisionName
,
content
)
{
const
prefix
=
'
permision_
'
uni
.
addInterceptor
(
permisionName
,
{
//拦截器 https://uniapp.dcloud.net.cn/api/interceptor.html#addinterceptor
invoke
:
(
args
)
=>
{
//触发前
const
{
uniPlatform
,
platform
}
=
uni
.
getSystemInfoSync
()
if
(
uniPlatform
!=
'
app
'
||
platform
!=
"
android
"
)
return
true
return
new
Promise
(
(
resolve
,
reject
)
=>
{
//之前同意过
let
locstatus
=
uni
.
getStorageSync
(
prefix
+
permisionName
);
if
(
locstatus
==
1
)
{
resolve
(
args
)
return
}
//之前拒绝过
if
(
locstatus
===
0
||
locstatus
===
-
1
){
//拒绝后 设置成0 再店设置成-1 再点设置成 空
if
(
locstatus
===
0
){
uni
.
setStorageSync
(
prefix
+
permisionName
,
-
1
)
}
else
if
(
locstatus
===
-
1
){
uni
.
setStorageSync
(
prefix
+
permisionName
,
""
)
}
reject
(
args
)
resultHandler
(
args
,
{
errMsg
:
'
用户之前拒绝了权限请求,不再询问
'
})
console
.
info
(
"
用户之前拒绝了权限请求,不再询问
"
);
return
}
console
.
info
(
"
locstatus
"
,
locstatus
);
/*
uni.showModal({
title: '权限申请说明',
content,
cancelText: '不同意',
confirmText: '同意',
success: async (res) => {
try {
if (res.confirm) {
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: '用户已拒绝该权限'
})
uni.showModal({
title: '是否前往开启权限?',
cancelText: '否',
confirmText: '是',
success: (res) => {
if (res.confirm) {
permisionUtil.gotoAppPermissionSetting()
}
}
})
}
}
if (res.cancel) {
uni.setStorageSync(prefix + permisionName, 0)
reject(args)
resultHandler(args, {
errMsg: '用户不同意申请权限'
})
}
} catch (err) {
reject(args)
resultHandler(args, err)
}
},
fail: err => {
reject(args)
resultHandler(args, err)
}
})
*/
//申请弹窗
// let bool = await
$showModal
({
title
:
'
权限申请说明
'
,
concent
:
content
,
confirmVal
:
'
同意
'
,
cancelVal
:
'
不同意
'
,
}).
then
(
async
(
res
)
=>
{
try
{
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
:
'
用户已拒绝该权限
'
})
$showModal
({
title
:
'
提示
'
,
concent
:
'
是否前往开启权限?
'
,
confirmVal
:
'
是
'
,
cancelVal
:
'
否
'
,
}).
then
(
res
=>
{
//是
permisionUtil
.
gotoAppPermissionSetting
()
}).
catch
(
err
=>
{
//否
})
}
}
catch
(
err
)
{
reject
(
args
)
resultHandler
(
args
,
err
)
}
}).
catch
((
err
)
=>
{
//不同意
console
.
info
(
"
不同意
"
);
uni
.
setStorageSync
(
prefix
+
permisionName
,
0
)
reject
(
args
)
resultHandler
(
args
,
{
errMsg
:
'
用户不同意申请权限
'
})
})
});
},
fail
(
err
)
{
console
.
log
(
'
interceptor-fail
'
,
err
)
if
(
err
.
errMsg
.
includes
(
'
fail No Permission
'
)
||
(
err
.
errMsg
==
'
getLocation:fail 获取定位权限失败
'
&&
err
.
code
==
22
))
{
uni
.
setStorageSync
(
prefix
+
permisionName
,
0
)
$showModal
({
title
:
'
提示
'
,
concent
:
'
是否前往开启权限?
'
,
confirmVal
:
'
是
'
,
cancelVal
:
'
否
'
,
}).
then
(
res
=>
{
//是
permisionUtil
.
gotoAppPermissionSetting
()
}).
catch
(
err
=>
{
//否
})
}
}
})
}
\ No newline at end of file
utils/js_sdk/permission.js
0 → 100644
View file @
6abaf387
/**
* 本模块封装了Android、iOS的应用权限判断、打开应用权限设置界面、以及位置系统服务是否开启
*/
// https://ext.dcloud.net.cn/plugin?id=15897
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
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment