| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993 |
- <script>//com.cityexpress1688.ptqs
- const toast = uni.requireNativePlugin('Ba-Toast');//android
- const callerID = uni.requireNativePlugin('Ba-CallerID');//android
- const KJPip = uni.requireNativePlugin('KJ-Pip');//ios
- //const bugly = uni.requireNativePlugin("LX-Bugly");
- // import {
- // UTSKeepalive
- // } from "@/uni_modules/wrs-uts-keepalive"
- // let keepalive = new UTSKeepalive()
- import {
- setRiderposition,
- changeLanguages,
- gcj02towgs
- } from '@/pages/api/basic';
- import api from "@/pages/api/api.js"
- export default {
- data() {
- return {
- startFl:0,
- timer:'',
- cid:'',
- isAndroid:false,
- androidflType:0,
- isInback:false,
- iosInit:false,
- audioObj:null,
- isfirst:true
- }
- },
- globalData:{
- _i18n:{},
- $t:{},
- imViewOpen:false,
- sj:{},
- iosfl:{},
- EXViewOpen:false,
- auditStatus:0,
- isOnline:true,
- token:'',
- initgoEasy:{},
- goEasycnt:false,
- goEasy:null
- },
- onLaunch: function() {
- console.log('App Launch')
- //bugly.init("23bea5717e","true")
- this.globalData.$t=str=>this.$t(str);
- this.globalData.sj=str=>this.getTimestr();
- this.globalData.iosfl=index=>this.showpiaof(index);
- this.globalData.token = uni.getStorageSync("token");
- this.globalData.imViewOpen = false;
- this.globalData.EXViewOpen = false;
- this.globalData.goEasy = this.goEasy;
- this.globalData.initgoEasy=str=>this.connectGoEasy();
- let systemInfo = uni.getSystemInfoSync();
- this.isAndroid = systemInfo.platform.toLowerCase() === 'android';
- var language = uni.getStorageSync('language');
- if(''==language||null==language||undefined==language){
- uni.setStorageSync('language',"zh-Hant");
- uni.setLocale('zh-Hant');
- if(!this.isAndroid){
- this.$i18n.locale = 'zh-Hant';
- }
- this.uploadLanguagesSet('zh-Hant');
- }
- else{
- uni.setLocale(language);
- if(!this.isAndroid){
- this.$i18n.locale = language;
- }
- this.uploadLanguagesSet(language);
- }
-
- this.connectGoEasy();
- if(!this.isAndroid){
- this.startLocation();
- }
- if(this.isAndroid){
- // 设置回调
- // UTSKeepalive.setCallback((resp)=>{
- // console.log('--------',resp)
- // let opt = resp.opt
- // switch (opt){
- // // 定位改变
- // case "onLocationChanged":
- // if(this.isAndroid) {
- // let location = resp.location
- // this.androidRecvitude(location.longitude,location.latitude);
- // } else {
- // let locations = resp.locations
- // }
- // break;
- // default:
- // break;
- // }
- // })
- // this.kaiqibaohuo();
- }
-
-
- uni.onPushMessage((res) => {
- console.log("收到推送消息:",res) //监听推送消息
- var payload=res.data.payload;
- if(payload.indexOf("rcuser")!=-1){
- this.updataxiaoxi(payload);
- }
- if(res.type=='click'){
- var content=res.data.title;
- plus.runtime.setBadgeNumber(0);
-
- }
- if(res.type=='receive'){
- plus.runtime.setBadgeNumber(0);
-
- var content=res.data.content;
- if(content.indexOf("location")!=-1){
- var objpl=JSON.parse(payload);
- this.cid=objpl.cid;
- this.getLocationL();
- return
- }
- uni.createPushMessage({
- content:res.data.content,
- success: (res) => {
- console.log(res);
- },
- fail(er) {
- }
- });
- }
- })
- var that = this;
- //android---------------------------------------------
- if(that.isAndroid){
- that.audioObj=uni.createInnerAudioContext();
- that.audioObj.src='hybrid/html/xuanfu/img/y800.mp3';
- }
- var globalEvent = uni.requireNativePlugin('globalEvent');
- globalEvent.addEventListener('baCallerIdEvent', function(e) {
- console.log('baCallerIdEvent:' + JSON.stringify(e));
- console.log(e);
- if(e.tag=='call'&&e.action=='onClick'){
- if(that.isInback){
- plus.runtime.launchApplication({pname:'com.cityexpress1688.ptqs'});
- }
-
- if(that.androidflType==1){
- uni.navigateTo({
- url:'/pages/imcall/audioCall?iscaller=0'
- })
- }
- else if(that.androidflType==2){
- uni.navigateTo({
- url:'/pages/imcall/GoeasyExchange?iscaller=0'
- })
- }
- that.audioObj.pause();
- that.hideFW();
- }
- if(e.tag=='uncall'&&e.action=='onClick'){
- that.audioObj.pause();
- that.hideFW();
- }
- });
- //ios-------------------------------------------------------------
- globalEvent.addEventListener('onPip', function(res) {
- console.log("onPip:" + JSON.stringify(res));
- if (res.method == "willStartPip") {
- console.log("即将开启画中画");
- } else if (res.method == "didStartPip") {
- console.log("已经开启画中画");
-
- } else if (res.method == "failedStartPip") {
- console.log("开启画中画失败");
- } else if (res.method == "willStopPip") {
- console.log("即将关闭画中画");
- //that.imdef();
- } else if (res.method == "didStopPip") {
- console.log("已经关闭画中画");
-
- } else if (res.method == "restorePip") {
- console.log("恢复");
- }
- });
- globalEvent.addEventListener('onWebview', function(res) {
- console.log("onWebview:" + JSON.stringify(res));
- if (res.method == "finish") {
- console.log("页面加载完成");
- } else if (res.method == "fail") {
- console.log("加载失败");
- }
- });
- if(!this.isAndroid){
- this.onH5SendDataCallBack();
- }
-
- },
- onShow: function() {
- console.log('App Show')
-
- this.isInback=false;
- this.initflaotView();
-
- //bugly.report("上报内容1111")
-
- if(!this.isAndroid){
- this.startLocation()
- }
- },
- onHide: function() {
- console.log('App Hide')
- this.isInback=true;
- // if(!this.isAndroid){
- // this.openPip1();
- // }
-
- // setInterval(() => {
- // console.log("定时任务 count: " + this.count)
-
- // }, 10000);
-
- if(!this.isAndroid){
- this.startLocation()
- }
-
- },
-
- methods: {
- getTimestr(){
- var time=new Date();
- var n,y,r,h,m,s;
- n=time.getFullYear();
- y=time.getMonth()+1;
- r=time.getDate();
- h=time.getHours();
- m=time.getMinutes();
- s=time.getSeconds();
- var timsStr = n+'-'+y+'-'+r+' '+h+':'+m+':'+s;
- return timsStr;
- },
- startLocation(){
- console.log('1startLocation')
- var token = uni.getStorageSync("token");
- //console.log('2222',that.token)
- if(token == '' || token == undefined || token == null){
- return;
- }
- else{
- if(this.startFl==0){
- //console.log(that.startFl);
- this.startFl=1;
- this.timer = setInterval(() => {
- this.getLocationL();
- }, 10000);
- }
- }
- },
- getLocationL(){
- var yszche=uni.getStorageSync('yszche');
- // console.log(this.startFl,yszche);
- if(1!=yszche){
- return;
- }
- var that = this;
- // console.log('uni.getLocation')
- uni.getLocation({
- type: "wgs84", //默认为 wgs84 返回 gps 坐标//谷歌地图使用 wgs84 坐标,其他地图使用 gcj02 坐标
- geocode: "true",
- isHighAccuracy: "true",
- accuracy: "best", // 精度值为20m
- success: function (res) {
- // console.log("app定位获取:", res);
- if(res.longitude>-180&&res.longitude<180){
- if(res.latitude>-90&&res.latitude<90){
- if(that.cid!=''){
- that.pushMsg(that.cid,res.longitude,res.latitude)
- }
- that.setRiderposition(res.longitude,res.latitude);
- }
- }
- },
- fail(err) {
- console.log('getLocation err')
- }
- });
- },
- androidRecvitude(longitude,latitude){
- var yszche=uni.getStorageSync('yszche');
- console.log(this.startFl,yszche);
- if(1!=yszche){
- return;
- }
- var token = uni.getStorageSync("token");
- //console.log('2222',that.token)
- if(token == '' || token == undefined || token == null){
- return;
- }
- this.setRiderposition(longitude,latitude);
- },
- setRiderposition(longitude,latitude){
- this.$http.post(`${setRiderposition}`, {
- "longitude":longitude,
- "latitude":latitude
- },true)
- .then(r => {
- // console.log('setRiderposition',r)
- })
- .catch(err => {
- console.log(err)
- })
- },
- async uploadLanguagesSet(lang){
- var userId = uni.getStorageSync('userId');
- if(lang=='yuenan'){
- lang='vi';
- }
- if(lang=='zh-Hans'){
- lang='zh-CN';
- }
- if(lang=='zh-Hant'){
- lang='zh-TW';
- }
- //console.log("changeLanguages");
- await this.$http.get(`${changeLanguages}`, {
- id:userId,
- lang:lang
- },false)
- .then(async r => {
- //console.log(r)
- })
- .catch(err => {
- console.log(err)
- })
- },
- updataxiaoxi(str){
- var xiaoxiList = uni.getStorageSync('dachexiaoxi');
- if(''==xiaoxiList||null==xiaoxiList||undefined==xiaoxiList){
- xiaoxiList=[];
- }
- xiaoxiList.push(str);
- uni.setStorageSync('dachexiaoxi',xiaoxiList);
- },
- pushMsg(cid,longitude,latitude){//消息推送
- var payloadData={
- longitude:longitude,
- latitude:latitude
- }
- api('pushMsgYH',{
- cid:cid,
- title:'骑手定位',
- content:'骑手定位',
- payload:payloadData
- },res=>{
- this.cid='';
- console.log(res)
- },failc=>{
- //console.log('getadvertis----',failc)
- })
- },
-
- //imcall&&immessage------------------------------------------------
- initflaotView(){
- if(this.isAndroid){
- if(this.isfirst){
- this.isPermissionFW();
- this.isfirst=false
- }
- }
- else{//ios
- // var that = this;
- // setTimeout(function() {
- // // 这里写要延时执行的代码
- // that.initPip("landscape");
- // }, 2000);
- }
- },
- imcallrecive(str){
-
- if(str.indexOf("\\\"")!=-1){
- str=str.replace(/\\\"/g, '\"');
- str = str.replace(/\"{/g, '{');
- str = str.replace(/}\"/g, '}');
- }
- var obj = JSON.parse(str)
- console.log('imcallrecive',obj)
- if(this.isAndroid){
- if(this.androidflType!=0){
- return;
- }
- var uobj={
- name:obj.nickName,
- content:this.$t('audioCall.cteyhcall'),
- call:this.$t('audioCall.jietingyy'),
- uncall:this.$t('audioCall.jujuejieting')
- }
- this.androidflType=1;
- this.showFW(uobj,false);
- this.audioObj.play();
- }
- else{//ios
- this.imCall();
- }
- },
- immessagerecive(str){
- if(str.indexOf("\\\"")!=-1){
- str=str.replace(/\\\"/g, '\"');
- str = str.replace(/\"{/g, '{');
- str = str.replace(/}\"/g, '}');
- }
- var obj = JSON.parse(str);
- if(this.isAndroid){
- if(this.androidflType!=0){
- return;
- }
- var uobj={
- name:obj.nickName,
- content:this.$t('exchange.cteyhmsg'),
- call:this.$t('exchange.chakanxinxi'),
- uncall:this.$t('exchange.quxiao')
- }
- this.androidflType=2;
- this.showFW(uobj,false);
- this.audioObj.play();
- }
- else{//ios
- this.imMessage();
- }
- },
- //android-------------------------------------------------
- showFW(obj,isInit) { //显示
- var that = this;
- if(!callerID){
- return
- }
- callerID.show({
- gravity: 1, //显示位置:0中间 1上 2下
- name:obj.name,//用户昵称 ,
- content:obj.content,//说明是骑手来电、来信息
- call: obj.call,//接听IM,查看IM信息
- uncall: obj.uncall,//拒绝接听IM,拒绝查看IM信息
- empty: "",
- avatar: "/static/logo.png",
- totalHint: "",
- tel: "",
- list:[]
- },
- (res) => {
- console.log(res);
- if(isInit){
- that.hideFW()
- }
- // uni.showToast({
- // title: res.msg,
- // icon: "none",
- // duration: 3000
- // })
- });
- },
- hideFW() { //隐藏
- this.androidflType=0;
- if(!callerID){
- return
- }
- callerID.hide(
- (res) => {
- console.log(res);
- // uni.showToast({
- // title: res.msg,
- // icon: "none",
- // duration: 3000
- // })
- });
- },
- permissionFW() { //申请悬浮窗权限
- if(!callerID){
- return
- }
- callerID.permission(
- (res) => {
- console.log(res);
- });
- },
- goPermissionFW() { //跳转到悬浮窗权限页面
- if(!callerID){
- return
- }
- callerID.goPermission(
- (res) => {
- console.log(res);
- });
- },
- isPermissionFW() { //是否申请悬浮窗权限
- var that = this;
- if(!callerID){
- return
- }
- callerID.isPermission(
- (res) => {
- console.log(res);
- if (res.data) {
- if(res.data.isPermission){
- var uobj={
- name:'CTE',
- content:'',
- call:'',
- uncall:''
- }
- that.showFW(uobj,true);
- }
- else{
- that.goPermissionFW();
- }
- }
- });
- },
- //ios--------------------------------------
- showpiaof(index){
-
- var that = this;
- if(index==1){
- setTimeout(function() {
- // 这里写要延时执行的代码
- that.initPip("landscape");
- }, 800);
- }
- if(index==2){
- that.closePip();
- }
- if(index==3){
- var language = uni.getStorageSync('language');
- if(language=='yuenan'){
- var dic = {
- "js": "changeImgvi()"
- }
- KJPip.webView_evaluateJavaScript(dic, (res) => {
- console.log("webView_evaluateJavaScript:" + JSON.stringify(res));
- })
- }
- else{
- var dic = {
- "js": "changeImg()"
- }
- KJPip.webView_evaluateJavaScript(dic, (res) => {
- console.log("webView_evaluateJavaScript:" + JSON.stringify(res));
- })
- }
- }
- if(index==4){
- var language = uni.getStorageSync('language');
- if(language=='yuenan'){
- var dic = {
- "js": "changeImgMSvi()"
- }
- KJPip.webView_evaluateJavaScript(dic, (res) => {
- console.log("webView_evaluateJavaScript:" + JSON.stringify(res));
- })
- }
- else{
- var dic = {
- "js": "changeImgMS()"
- }
- KJPip.webView_evaluateJavaScript(dic, (res) => {
- console.log("webView_evaluateJavaScript:" + JSON.stringify(res));
- })
- }
- }
- return '';
- },
- initPip(shape) {
- var dic = {
- "shape": shape, //弹窗形状 square(正方形) landscape(横向) portrait(竖向)
- }
- KJPip.initPip(dic)
-
- console.log('initPip')
- var that = this;
- that.iosInit=true;
- setTimeout(function() {
- // 这里写要延时执行的代码
- that.openPip1();
- }, 2000);
- },
- openPip1() {//打开,加载本地页面?language='+language
- var language = uni.getStorageSync('language');
- this.openPip(plus.io.convertLocalFileSystemURL("hybrid/html/xuanfu/index.html"));
- },
- openPip(url) {
- var that = this;
- KJPip.isPictureInPictureActive((res) => {
- console.log("isPictureInPictureActive:" + JSON.stringify(res));
- })
- KJPip.isPictureInPictureSuspended((res) => {
- console.log("isPictureInPictureSuspended:" + JSON.stringify(res));
- })
- KJPip.isPictureInPicturePossible((res) => {
- console.log("isPictureInPicturePossible:" + JSON.stringify(res));
- // if(!res.result){
- // setTimeout(function() {
- // // 这里写要延时执行的代码
- // //that.initPip("landscape");
- // }, 800);
- // }
- })
- KJPip.isPictureInPictureSupported((res) => {
- console.log("isPictureInPictureSupported:" + JSON.stringify(res));
- })
- var dic = {
- "url": url
- }
- KJPip.openPip(dic, (res) => {
- console.log("openPip:" + JSON.stringify(res));
- })
- },
- closePip() {//关闭弹窗
- KJPip.closePip()
- },
-
- imCall(){//收到IM语音通话请求
-
- uni.navigateTo({
- url:'/pages/imcall/audioCall?iscaller=0'
- })
-
- },
-
- imMessage(){//收到im文字聊天请求
- // plus.runtime.launchApplication({action:'cityexpress1688ptqs://'},
- // function(e){
- // console.log('launchApplication',e);
- // });
- // plus.runtime.openURL('cityexpress1688ptqs://', function(res) {
- // console.log('123123',res);
- // });
- uni.navigateTo({
- url:'/pages/imcall/GoeasyExchange?iscaller=0'
- })
-
- },
-
- imdef(){//收到im文字聊天请求
- var dic = {
- "js": "changeImgdef()"
- }
- KJPip.webView_evaluateJavaScript(dic, (res) => {
- console.log("webView_evaluateJavaScript:" + JSON.stringify(res));
- })
- },
-
- onH5SendDataCallBack() { //注意ios16之后,弹出里的内容不能点击
- var that = this;
- KJPip.onH5SendDataCallBack((res) => {
- console.log("onH5SendDataCallBack:",res);
- // if(res.result){
- // var obj = JSON.parse(res.result);
- // if(obj.key==1){
- // uni.navigateTo({
- // url:'/pages/imcall/audioCall?iscaller=0'
- // })
- // that.imdef();
- // }
- // else if(obj.key==2){
- // uni.navigateTo({
- // url:'/pages/imcall/ExchangeView?iscaller=0'
- // })
- // that.imdef();
- // }
- // }
- })
- },
- //GoEasy--------------------------------------------
- connectGoEasy() {
- var that = this;
- if(that.globalData.goEasycnt==true){
- that.goeasydisconnect();
- return;
- }
- var userInfo=uni.getStorageSync('userInfo');
- if(''==userInfo||null==userInfo||undefined==userInfo){
- return;
- }
- this.goEasy.connect({
- id:'userid_'+userInfo.userId,
- data: {
- name:userInfo.nickName,
- avatar:userInfo.avatar
- },
- onSuccess: () => {
- console.log('GoEasy connect successfully.')
- that.goEasyPush();
- that.globalData.goEasycnt=true;
- },
- onFailed: (error) => {
- console.log('Failed to connect GoEasy, code:' + error.code + ',error:' + error.content);
- },
- onProgress: (attempts) => {
- console.log('GoEasy is connecting', attempts);
- }
- });
- },
- goEasyPush(){
- var userInfo=uni.getStorageSync('userInfo');
- if(''==userInfo||null==userInfo||undefined==userInfo){
- return;
- }
- //console.log(userInfo);
- var that = this;
- var pubsub = this.goEasy.pubsub;
- pubsub.subscribe({
- channel:'userid_'+userInfo.userId,
- onMessage: function (message) {
- if(message.content){
- var obj = JSON.parse(message.content);
- if(obj.ptype==1){
- if(that.globalData.imViewOpen){
- return;
- }
- uni.setStorageSync('impayload',message.content);
- that.imcallrecive(message.content);
- }
- if(obj.ptype==2){
- if(that.globalData.EXViewOpen){
- return;
- }
- uni.setStorageSync('impayload',message.content);
- that.immessagerecive(message.content);
- }
- }
- console.log("Channel:" + message.channel + " content:" + message.content)
- },
- onSuccess: function () {
- console.log("Subscribe successfully.")
- },
- onFailed: function () {
- console.log("Subscribe successfully.")
- }
- });
- },
- //断开连接
- goeasydisconnect(){
- var that = this;
- this.goEasy.disconnect({
- onSuccess: function(){
- console.log("GoEasy disconnect successfully.")
- that.globalData.goEasycnt=false;
- that.connectGoEasy();
- },
- onFailed: function(error){
- console.log("Failed to disconnect GoEasy, code:"+error.code+ ",error:"+error.content);
- }
- });
- },
- //开启保活---------------------------------------------------------------------------------
- kaiqibaohuo(){
- if (this.isAndroid) {
- this.requestPermission([
- "android.permission.FOREGROUND_SERVICE",
- "android.permission.POST_NOTIFICATIONS",
- "android.permission.ACCESS_COARSE_LOCATION",
- "android.permission.ACCESS_FINE_LOCATION",
- "android.permission.WRITE_EXTERNAL_STORAGE",
- "android.permission.ACCESS_BACKGROUND_LOCATION"
- ]);
-
- } else {
- // var authorizationStatus = UTSKeepalive.getAuthorizationStatus();
- // if (authorizationStatus == 0) {// 没有授权过定位时,请求定位权限
- // keepalive.requestLocationAuthorization()
- // }
-
- // // 监听app前后台状态
- // UTSKeepalive.listenerApp((resp) => {
- // let opt = resp.opt
- // switch (opt) {
- // // app进入后台
- // case "enterBackground": {
- // var authorizationStatus = UTSKeepalive.getAuthorizationStatus();
-
- // console.log("authorizationStatus:" + authorizationStatus)
-
- // // app进入后台,此时采用定位保活还是采用播放音乐保活可以根据自己业务决定
- // if (authorizationStatus == 3) { // 当定位权限是总是一直定位时采用定位来保活
- // console.log("定位保活")
- // keepalive.startLocation({
- // desiredAccuracy: "NearestTenMeters",
- // allowsBackgroundLocationUpdates: true, // 允许后台更新位置
- // pausesLocationUpdatesAutomatically: false // 不允许自动暂停更新位置
- // })
- // } else { // 采用播放音乐保活
- // console.log("播放音乐保活")
- // UTSKeepalive.setCategory("playback")
- // var url = plus.io.convertLocalFileSystemURL('_www/static/bgmusic.mp3');
-
- // keepalive.playMusic({
- // url: url,
- // numberOfLoops: -1, // 循环此时,-1表示无限循环
- // volume: 0 // 音量,0
- // });
- // }
- // // 通知系统开始后台任务
- // UTSKeepalive.beginBackgroundTask()
- // }
- // break;
- // // app回到前台
- // case "enterForeground": {
- // // 停止播放音乐
- // keepalive.stopMusic()
- // // 停止定位
- // keepalive.stopLocation()
- // // 通知系统结束后台任务
- // UTSKeepalive.endBackgroundTask()
- // }
-
- // break;
- // default:
- // break;
- // }
- // })
- }
- },
- requestPermission: function(permissions) {
- var that = this;
- plus.android.requestPermissions(
- permissions,
- function(resultObj) {
- for (var i = 0; i < resultObj.granted.length; i++) {
- var grantedPermission = resultObj.granted[i];
- //console.log('已获取的权限:' + grantedPermission);
- }
- if(resultObj.granted.length>=5){
- // that.keepAlive();
- return;
- }
- for (var i = 0; i < resultObj.deniedPresent.length; i++) {
- var deniedPresentPermission = resultObj.deniedPresent[i];
- console.log('拒绝本次申请的权限:' + deniedPresentPermission);
- }
- for (var i = 0; i < resultObj.deniedAlways.length; i++) {
- var deniedAlwaysPermission = resultObj.deniedAlways[i];
- console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
- }
- // 若所需权限被永久拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限
- if (resultObj.deniedAlways.length > 0) {
- uni.showModal({
- cancelText: that.$t('index.quxiao'), // 取消按钮的文字
- confirmText: that.$t('index.queren'), // 确认按钮的文字
- title: that.$t('api.message'),
- content: that.$t('user.dingweiquanxian'),
- success: function (res) {
- if (res.confirm) { //这里是点击了确定以后
- that.kaiqidingwei();
- } else { //这里是点击了取消以后
- console.log('用户点击取消')
- }
-
- }
- })
- }
- },
- function(error) {
- console.log('申请权限错误:' + error.code + " = " + error.message);
- });
- },
- keepAlive() {
- console.log('keepAlive')
- // let params = this.getAndroidNotification();
- // console.log(params)
- // UTSKeepalive.startForegroundService(params)
-
- // UTSKeepalive.startJobService(params)
- // UTSKeepalive.startLocalService(params)
- // UTSKeepalive.startRemoteService(params)
-
- // UTSKeepalive.startScreenLockReceiver();
- // // 后台定位功能,用不到后台定位可以不需要调用
- // let locationParams = {}
- // locationParams.notification = params
- // locationParams.location = {
- // provider: "gps", // 支持gps、fused
- // minTimeMs:10000, // 间隔时间,这里为了测试效果,设置为500毫秒,实际情况根据自己业务设置
- // minDistanceM: 5.0 // 间隔距离,这里为了测试效果,设置为0.5米,实际情况根据自己业务设置
- // }
- // UTSKeepalive.startLocstionService(locationParams)
- },
- //开启定位权限------------------------------
- kaiqidingwei(){
- 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);
- },
- getAndroidNotification() {
- let channelId = 10
- let params = {}
- params.identifier = "123" // 通知ID,主要用于修改、删除通知,android里的identifier必须是数字,iOS的identifier可以是任意字符串
- params.channel = { // 如果已经channelId的channel则不创建,如果没有则会自动创建
- channelId: channelId,
- channelName: "騎手端持續為您服務",
- importance: 5, // 3: default 4: high 2: low 5: max 1: min 0: none
- lockscreenVisibility: 1, //1: public 0: private -1: secret
- // description: "Bảo hành"
- }
- params.notification = {
- channelId: channelId, // 此消息通知是属于哪个channel的
- contentTitle: "騎手端持續為您服務",
- // contentText: "Bảo hành",
- visibility: 1, // 1: public 0: private -1: secret
- smallIcon: { // 小图标,必传
- type: "resource", // 固定
- defType: "drawable", // 固定
- name: "not" // 文件名,不要带文件后缀,对应nativeResources/android/res/drawable文件夹下的图片
- },
- autoCancel: false
- }
- return params
- },
- },
- }
- </script>
- <style lang="scss">
- .content{
- display: flex;
- flex-direction: column;
- width: 94%;
- margin-left: 3%;
- background-color: white;
- border-radius: 16rpx;
- box-shadow: 0rpx 0rpx 10rpx 0rpx lightgray;
- }
- .contentInRowL{
- display: flex;
- flex-direction: row;
- justify-content: flex-start;
- }
- .contentInRowR{
- display: flex;
- flex-direction: row;
- justify-content:flex-end;
- }
- .contentInRowC{
- display: flex;
- flex-direction: row;
- justify-content: center;
- align-items: center;
- }
- .contentInRowS{
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- }
- .contentColumn{
- display: flex;
- flex-direction: column;
- }
- .contentColumnC{
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- }
- .text1row{
- overflow: hidden;
- text-overflow: ellipsis;
- /* #ifndef APP-PLUS-NVUE */
- display: -webkit-box;
- -webkit-line-clamp: 1;
- -webkit-box-orient: vertical;
- /* #endif */
- }
- .text2row{
- overflow: hidden;
- text-overflow: ellipsis;
- /* #ifndef APP-PLUS-NVUE */
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- /* #endif */
- }
- </style>
|