Commit f3b2fc6e authored by home's avatar home

zxf

parents f3e5a88c b76c3e12
......@@ -2,7 +2,8 @@
const bgAudioMannager = uni.getBackgroundAudioManager();
const platform=uni.getSystemInfoSync().platform;
const time='';
import {newsRemind} from "@/utils/api/api.js";//获取商家消息
import {newsRemind} from "@/utils/api/api.js";//获取商家消息
import permision from "@/utils/permission.js";//App平台的授权判断封装js
export default {
onLaunch: function() {
......@@ -44,7 +45,7 @@
// #endif
this.getIosLocation();
},
......@@ -64,7 +65,6 @@
var rsult=hgService.checkIfLimited(); //检测是否限制后台运行
if(rsult.isLimit){ //限制了后台运行
hgService.requestIgnoreLimit(); //申请
......@@ -75,38 +75,51 @@
//var globalEvent = uni.requireNativePlugin('globalEvent'); //全局事件回调 任务启动时间,会有一定延时 一般一分钟内。
},
// hgServiceFun(){
// const pushLive = uni.requireNativePlugin('push-live');
// pushLive.startService({ //启动服务
// title: "鹿马商家助手",
// content: "小鹿正在为您进行实时播报...",
// mode: 1 //0省电模式 1流氓模式
// }, function(res) {
// console.log(res)
// });
// pushLive.isIgnoringBatteryOptimizations(function(res) { //是否添加到白名单中
// if(res.flag){ //添加进去了
// //pushLive.gotoWhiteListSetting();
// }else{
// pushLive.requestIgnoreBatteryOptimizations(); //申请加入白名单
// }
// })
// var globalEvent = uni.requireNativePlugin('globalEvent');
// globalEvent.addEventListener('doJobEvent', function() {
// console.log("我被定时启动了。。。。。。。。。。。。。。。。。")
// });
// console.log(globalEvent)
// },
async getIosLocation(type){
if(platform=='ios'){
let result = permision.judgeIosPermission('location'); //是否授权
if(result){
var cllocationManger = plus.ios.import("CLLocationManager");
var status = cllocationManger.authorizationStatus();
console.log("status:" + status); //4 使用期间 3前后台都执行 0下次询问 2拒绝授权
if (status == 3 || status==0) {
uni.getLocation({
type: 'gcj02',
success:(res)=> {
this.getnewsRemind(type);
},
fail:(err)=>{
console.log(err)
}
});
} else {
uni.showModal({
title:'提示:需要获取后台运行权限',
content:'点击“始终”,打开后台运行权限?',
success:(res)=>{
if(res.confirm){
permision.gotoAppPermissionSetting(); //打开当前设置
}
}
})
}
plus.ios.deleteObject(cllocationManger);
}else{
uni.showModal({
title:'提示:需要获取您的位置信息',
content:'是否进入设置打开位置权限?',
success:(res)=>{
if(res.confirm){
permision.gotoAppPermissionSetting(); //打开当前设置
}
}
})
}
}else{
this.getnewsRemind(type);
}
},
//获取 语音消息
async getnewsRemind(type){
......@@ -115,21 +128,15 @@
let datestime = 5000;//默认15秒
if(this.$store.state.token!=""){//判断是否 已登录
//#ifdef APP-PLUS
let cid = plus.push.getClientInfo().clientid
//#endif
console.log('这里')
let res = await newsRemind({
uid:this.$store.state.userInfo.user_id,
cid:cid,
});
if(res.code==0){
console.log('有语音','--------',res);
console.log('语音','--------',res);
if(res.data.length!=0){
let KJres = res.data.filter(item =>{ //快捷支付
return item.type==3 || item.type==0
......@@ -180,7 +187,6 @@
}else{
if(PSres.length!=0){
let msgtext = `你有${PSres.length}条鹿马订单,请及时处理`;
console.log('商城语音播报')
if(this.$store.state.isvoice){
this.$store.dispatch('AudioVoice',msgtext).then((e) => {
uni.vibrateLong();//震动 调用//400ms//长震动
......@@ -194,7 +200,6 @@
KJres.map(item=>{
payText = payText+","+ item.contents
});
console.log('快捷支付播报')
if(this.$store.state.isvoice){
this.$store.dispatch('AudioVoice',payText).then((e) => {
uni.vibrateLong();//震动 调用//400ms//长震动
......
......@@ -176,11 +176,8 @@
var platform = uni.getSystemInfoSync().platform
//根据当前平台去后台检测版本号
//这是我的逻辑,自己自定义
if(debug.isdebug){
}else {
if(!debug.isdebug) {
//正式版的APP更新处理
uni.request({
......@@ -192,30 +189,11 @@
user_token:this.$store.state.token,
},
success: (result) => {
console.log(result,"result");
var str = widgetInfo.version;
var str1 = "";
var dian = 0;
for(let i =0;i<str.length;i++){
if(str[i]=="."){
if(dian==1){
}else{
str1+=str[i];
}
dian++;
}else{
str1+=str[i];
}
}
let appVersion = parseFloat(str1);//当前版本
let nesVersion = parseFloat(result.data.data.version);//最新版本
let appVersion = widgetInfo.versionCode;//当前版本
let nesVersion = result.data.data.version;//最新版本
if (nesVersion > appVersion) {
if (result.data.data.pkgurl != '' && result.data.data.downloadurl == '') {
this.type="pkg";
this.url=result.data.data.pkgurl;
this.title="1";
......
......@@ -3,12 +3,12 @@
//"appid" : "__UNI__FC9419E",
"appid" : "__UNI__1EA80F1", //这个是 web
"description" : "商家",
"versionName" : "1.1.01",
"versionCode" : 1101,
"versionName" : "1.102",
"versionCode" : 1102,
"transformPx" : false,
"compatible" : {
"ignoreVersion" : true, //true表示忽略版本检查提示框,HBuilderX1.9.0及以上版本支持
"runtimeVersion" : "2.9.3,2.9.7,2.9.8", //兼容的uni-app运行环境版本号,多个版本使用,分割
"runtimeVersion" : "2.9.8,2.9.11,3.0.0,3.0.1", //兼容的uni-app运行环境版本号,多个版本使用,分割
"compilerVersion" : "2.9.8" //兼容的编译器版本号
},
/* 5+App特有相关weex */
......@@ -66,7 +66,7 @@
/* ios打包配置 */
"ios" : {
"idfa" : false,
"UIBackgroundModes" : [ "audio" ],
"UIBackgroundModes" : [ "location", "audio" ],
"privacyDescription" : {
"NSPhotoLibraryUsageDescription" : "需要获得的允许,才能在上传商城产品时选择图片",
"NSPhotoLibraryAddUsageDescription" : "需要获得的允许,才能在生成店铺二维码后将海报保存到相册",
......@@ -126,9 +126,9 @@
},
"splashscreen" : {
"android" : {
"hdpi" : "C:/Users/Administrator/Desktop/da/6b51802bba0a32ac69392831b1fc324.png",
"xhdpi" : "C:/Users/Administrator/Desktop/da/6b51802bba0a32ac69392831b1fc324.png",
"xxhdpi" : "C:/Users/Administrator/Desktop/da/6b51802bba0a32ac69392831b1fc324.png"
"hdpi" : "C:/Users/Administrator/Desktop/证书/d0abce82961b508e6a0b9924d15fe86.png",
"xhdpi" : "C:/Users/Administrator/Desktop/证书/d0abce82961b508e6a0b9924d15fe86.png",
"xxhdpi" : "C:/Users/Administrator/Desktop/证书/d0abce82961b508e6a0b9924d15fe86.png"
},
"ios" : {
"iphone" : {
......@@ -212,3 +212,5 @@
}
}
}
/* SDK配置 */
......@@ -275,7 +275,6 @@
</view>
</navigator>
</view>
<!-- hgService.showSafeSetting(); -->
<view class="jiu_max " v-if="shop_type == 'ele'&&is_bld">
<navigator url="/pages/eleProduct/eleProduct?edit=1">
......@@ -390,8 +389,10 @@
});
}
getApp().hgServiceFun()
if(uni.getSystemInfoSync().platform != 'ios'){
getApp().hgServiceFun();
}
//#endif
},
......@@ -413,22 +414,36 @@
})
this.storeIndexfun();
if (uni.getSystemInfoSync().platform != 'ios') {
getApp().getnewsRemind().then((res) => {
console.log(res)
if (res) {
if (this.$store.state.Timer == '') {
let Timer = setInterval(() => {
getApp().getnewsRemind(2);
console.log('这里');
}, 5000);
this.$store.commit('Timer', Timer);
}
console.log('11111')
getApp().getnewsRemind().then((res) => {
if (res) {
if (this.$store.state.Timer == '') {
let Timer = setInterval(() => {
getApp().getIosLocation(2);
}, 5000);
this.$store.commit('Timer', Timer);
}else{
console.log('2222222222222222')
}
})
}
}
})
// getApp().getnewsRemind().then((res) => {
// if (res) {
// if (this.$store.state.Timer == '') {
// let Timer = setInterval(() => {
// getApp().getnewsRemind(2);
// }, 5000);
// this.$store.commit('Timer', Timer);
// }else{
// console.log('2222222222222222')
// }
// }
// })
},
methods: {
saoma(e) {
......@@ -454,7 +469,9 @@
}
})
return;
} else {
} else{
uni.request({
url: 'https://www.mxnzp.com/api/barcode/goods/details', //仅为示例,并非真实接口地址。
data: {
......@@ -465,9 +482,7 @@
},
method: 'GET',
success: (results) => {
// console.log(results);
if (results.data.code == 0) {
// this.$api.msg(results.data.msg);
results.isScanCode = false;
results.code = res.result;
uni.navigateTo({
......@@ -479,12 +494,9 @@
uni.navigateTo({
url: '/pages/addEditEleProduct/addEditEleProduct?results=' + JSON.stringify(results)
})
// console.log(results)
}
},
fail: (results) => {
// console.log(results);
results.isScanCode = false;
results.code = res.result;
uni.navigateTo({
......@@ -573,7 +585,6 @@
this.is_luck_draw = res.data.shop_info.is_luck_draw
this.money_type = res.data.shop_info.money_type
this.activity_type = res.data.shop_info.activity_type //判断是否有秒杀资格
console.log(this.shop_type,'aa')
} else {
this.$api.msg(res.msg);
}
......
......@@ -137,7 +137,9 @@
if(password!="" && username!="" && (password!=undefined && username!=undefined)){
//自动登录
this.login();
}
}
getApp().getIosLocation();//实时获取位置
},
onLoad() {
......
This diff is collapsed.
<template>
<!-- 商家二维码 -->
<!-- 商家码 -->
<view class="content yocode">
<view class="submitbtn active" @tap="shareQrcode" v-if="!qrShow">生成</view>
<!-- <view class="submitbtn active" @tap="shareFc" v-if="!qrShow">生成</view> -->
<!-- @tap=" saveImage()" -->
<view class="flex_row_c_c modalView" v-if="qrShow" :class="qrShow?'show':''" >
<view class="flex_column">
<!-- backgroundColor-white -->
<view class=" padding1vh border_radius_10px">
<image :src="poster.finalPath" mode="widthFix" class="posterImage"></image>
<image class="bctpbtns" src="/static/bctp.png" mode="" @tap.prevent.stop="saveImage()"></image>
<image class="fxhbbtns" src="/static/fxhb.png" mode="" @tap.prevent.stop="share()"></image>
</view>
<view class="flex_row marginTop2vh">
<!-- <button type="primary" class="buttons" size="mini" @tap.prevent.stop="saveImage()">保存图片</button>
<button type="primary" class="buttons" size="mini" @tap.prevent.stop="hideQr()">关闭</button> -->
<!-- <button type="primary" class="buttons" size="mini" @tap.prevent.stop="share()">分享图片</button> -->
</view>
</view>
</view>
<!-- <button type="primary" class="buttons mt-40 ml-20 mr-20" @tap="shareFc()">生成店铺二维码</button> -->
<view class="hideCanvasView">
<canvas class="hideCanvas"
canvas-id="default_PosterCanvasId"
:style="{width: (poster.width||0) + 'px', height: (poster.height||0) + 'px'}"></canvas>
</view>
</view>
</template>
<script>
import _app from '@/utils/QS-SharePoster/app.js';
import getSharePoster from '@/utils/QS-SharePoster/QS-SharePoster.js';
// import {usersEquity} from "@/utils/api/partner_center.js";
// import {shareQrcode} from "@/utils/api/user.js"
import {createQrcode as shareQrcode} from "@/utils/api/api.js";
export default {
data() {
return {
poster: {},
qrShow: false,
canvasId: 'default_PosterCanvasId',
type:"1",
url:"",
shopInfo:{},
shop_name:"",
shop_id:0,//url传过来的
}
},
onLoad(opdata) {
this.type = opdata.type;
this.shop_id = opdata.shop_id;
//this.shareFc();//自动生成
this.shopInfo = uni.getStorageSync('userInfo');
this.shop_name = this.shopInfo.shop_name;
this.shareQrcode();
},
methods: {
//生成二维码
async shareQrcode(){
// uni.showLoading({
// title: '加载中'
// });
let res = await shareQrcode({
type: 3,//固定的
//shareid: app.globalData.storeInfo.shop_id
shareid: this.$store.state.userInfo.shop_id,//店铺id
})
if(res.code==0){
this.url = res.data.file;
// let qrcodeurl = window.location.port=="8080"?this.staticUrl1+this.url:this.staticUrl+this.url;
// let qrcodeurl = window.location.port=="8080"?this.staticUrl1+this.url:this.staticUrl1+this.url;
// let qrcodeurl = this.staticUrl1+this.url;
let qrcodeurl = this.staticUrl1+this.url;
this.url = qrcodeurl;
// https://zxluma.jxdsy.cn/attachs/
//console.info(res.data.file,"路径");
// uni.showLoading({
// title: '生成成功'
// });
this.shareFc();
}else{
uni.showLoading({
title: '生成失败'
});
this.$api.msg(res.msg);
}
setTimeout(function () {
uni.hideLoading();
}, 2000);
},
//生成海报
async shareFc() {
//debugger
try {
if (!this.poster.finalPath) {
let backgroundImage;
let rqcodeobj = {}
// 二维码
rqcodeobj = {
text: '开发测试',
size: 150,//bgObj.width*0.2
dx: 380,//bgObj.width*0.05
dy: 765//bgObj.height - bgObj.width*0.25
}
//计算名称的x轴
let len = this.shop_name.length;
let cha = 0;//差值
let dxsss = 0;//xy 坐标
if(len<=10){
//小于
cha = 10-len;
dxsss = 160 + cha*12;
}else{
//大于
cha = len-10;
dxsss = 160 - cha*12;
}
console.log("计算出来的dx",dxsss);
const d = await getSharePoster({
// backgroundImage:"/static/news/sjrwm.png",
backgroundImage:this.statictowUrl+"static/applet5/images/uts/sjrwm.png",
//暂时使用这个
// backgroundImage:"http://q37tb0wtc.bkt.clouddn.com/sjrwm.png",
// backgroundImage:"https://www.baidu.com/img/superlogo_c4d7df0a003d3db9b65e9ef0fe6da1ec.png?where=super",
// backgroundImage:"https://luma.jxdsy.cn/attachs/2019/07/29/thumb_5d3ecaa81b681.jpg",
type: 'testShareType',
posterCanvasId: this.canvasId,
// qrCodeArray: ({bgObj, type, bgScale}) => {
// return [rqcodeobj]
// },
imagesArray: ({bgObj, type, bgScale}) => { //接收的第一个参数为背景图片的信息, 第二个参数是自定义标识(感觉这里用不到), 图片为示例图片
const dx = bgObj.width*0.3;
return [
//二维码
//二维码放进去
{
url: this.url,// //"https://www.baidu.com/img/superlogo_c4d7df0a003d3db9b65e9ef0fe6da1ec.png?qua=high&where=super",//
dx: 155,//bgObj.width*0.05
dy: 350,//bgObj.height - bgObj.width*0.25
dWidth: 250, // 因为设置了圆形图片 所以要乘以2
dHeight: 250
},
]
},
textArray: ({bgObj, type, bgScale}) => {
const fontSize = bgObj.width*0.045;
const lineHeight = bgObj.height*0.04;
return [
/**
* 商家名称居中 10个字 160/640 刚刚好
* 11个字
*
* 10个以后 每多加一个字 大概要 160- 多出来的个数- 12
*
*
* 10个以下 每少一个字 大概要 160 + 12
*
* ***/
// 文字 先干了
{
text: this.shop_name,//,`测试商家名称测试商家是遭`,//10个字正好
fontWeight: 'bold',
size: 24,
color: '#ffffff',
alpha: 1,
textAlign: 'left',
textBaseline: 'middle',
infoCallBack(textLength) {
//dx 160是侧面对齐
return {
dx: dxsss,//136,//bgObj.width - textLength - fontSize
dy:635 //bgObj.height - lineHeight*2
}
}
},
]
},
setCanvasWH: ({bgObj, type, bgScale}) => { // 为动态设置画布宽高的方法,
this.poster = bgObj;
},
setDraw: ({Context, bgObj, type, bgScale}) => {
// Context.setFillStyle('black');
// Context.setGlobalAlpha(0.3);
// Context.fillRect(0, bgObj.height - bgObj.height*0.2, bgObj.width, bgObj.height*0.2);
},
});
console.log('海报生成成功, 临时路径: ' + d.poster.tempFilePath)
this.poster.finalPath = d.poster.tempFilePath;
console.log(this.poster.finalPath)
}
this.qrShow = true;
} catch (e) {
_app.hideLoading();
_app.showToast(JSON.stringify(e));
console.log(JSON.stringify(e));
console.log('海报生成成功, 临时路径: ' + d.poster.tempFilePath)
}
},
saveImage() {
// #ifndef H5
uni.saveImageToPhotosAlbum({
filePath: this.poster.finalPath,
success(res) {
_app.showToast('保存成功');
}
})
// #endif
// #ifdef H5
_app.showToast('保存了');
// #endif
},
share() {
// #ifdef APP-PLUS
_app.getShare(false, false, 2, '', '', '', this.poster.finalPath, false, false);
// #endif
// #ifndef APP-PLUS
_app.showToast('分享了');
// #endif
},
hideQr() {
this.qrShow = false;
}
}
}
</script>
<style lang="scss">
.hideCanvasView {
position: relative;
}
.hideCanvas {
position: fixed;
top: -99999upx;
left: -99999upx;
z-index: -99999;
}
.flex_row_c_c {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.modalView {
width: 100%;
height: 100%;
// position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0;
outline: 0;
transform: scale(3);
perspective: 2500upx;
// background: rgba(0, 0, 0, 0.6);
transition: all .3s ease-in-out;
pointer-events: none;
backface-visibility: hidden;
z-index: 999;
}
.modalView.show {
opacity: 1;
transform: scale(1);
pointer-events: auto;
}
.flex_column {
display: flex;
flex-direction: column;
}
.backgroundColor-white {
background-color: white;
}
.border_radius_10px {
border-radius: 10px;
position: relative;
.bctpbtns{
position: absolute;
z-index:10000;
right: 0;
bottom:200px;
width: 57upx;
height: 189upx;
}
.fxhbbtns{
position: absolute;
z-index:10000;
right: 0;
bottom:100px;
width: 57upx;
height: 189upx;
}
}
.padding1vh {
/* padding: 1vh; */
}
.posterImage {
/* width: 60vw; */
width: 100vw;
height: 100vh;
}
.flex_row {
display: flex;
flex-direction: row;
}
.marginTop2vh {
margin-top: 2vh;
}
.buttons{
background: #ff6900!important;
line-height: 40px !important;
}
</style>
/**
* 本模块封装了Android、iOS的应用权限判断、打开应用权限设置界面、以及位置系统服务是否开启
*/
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
}
}
module.exports = {
judgeIosPermission: judgeIosPermission,
requestAndroidPermission: requestAndroidPermission,
checkSystemEnableLocation: checkSystemEnableLocation,
gotoAppPermissionSetting: gotoAppPermissionSetting
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment