| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028 |
- <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 {
- Mycallback
- } from "@/uni_modules/gzf-appdelegate"
- let notecallback = new Mycallback();
- 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,
- xdaudioObj:null,
- }
- },
- 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',"yuenan");
- uni.setLocale('yuenan');
- if(!this.isAndroid){
- this.$i18n.locale = 'yuenan';
- }
- this.uploadLanguagesSet('yuenan');
- }
- else{
- uni.setLocale(language);
- if(!this.isAndroid){
- this.$i18n.locale = language;
- }
- this.uploadLanguagesSet(language);
- }
-
- this.connectGoEasy();
- if(!this.isAndroid){
- console.log('11111-----')
- this.startLocation();
- }
- if(this.isAndroid){
- console.log('11111-----2')
- // 设置回调
- 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);
- //this.androidRecvitude(11.1111111,22.2222222);
- } else {
- let locations = resp.locations
- }
- break;
- default:
- break;
- }
- })
- this.kaiqibaohuo();
- }
-
-
- uni.onPushMessage((res) => {
- console.log("收到推送消息:",res) //监听推送消息
-
- var payload=res.data.payload;
- this.xindingdantx(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;
- that.xdaudioObj=uni.createInnerAudioContext();
- that.xdaudioObj.src='static/CTENEW.mp3';
- //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')
- plus.runtime.setBadgeNumber(0);
- this.isInback=false;
- this.initflaotView();
-
- //bugly.report("上报内容1111")
- if(!this.isAndroid){
- this.startLocation()
- notecallback.onCallback((resp)=>{
- console.log("onCallback 收到推送消息:",resp) //监听推送消息
- //var payload=resp.data.payload;
- this.xindingdantx("payload");
- })
- }
-
-
-
- },
- 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()
- }
- else{
- console.log('this.isAndroid');
- //this.startLocation()
- }
- },
-
- methods: {
- xindingdantx(obj){
- //判断是否收到新订单
- console.log(obj);
- this.xdaudioObj.play();
-
- var dj = JSON.parse(obj);
- console.log(dj);
- if(dj.type==0){
- if(this.globalData.isOnline){
- this.xdaudioObj.play();
- }
- }
-
- },
- setScreenOrientation() {
- uni.setScreenOrientation({
- orientation: 'portrait-primary'
- });
- },
- 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;
- 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;
- callerID.hide(
- (res) => {
- console.log(res);
- // uni.showToast({
- // title: res.msg,
- // icon: "none",
- // duration: 3000
- // })
- });
- },
- permissionFW() { //申请悬浮窗权限
- callerID.permission(
- (res) => {
- console.log(res);
- });
- },
- goPermissionFW() { //跳转到悬浮窗权限页面
- callerID.goPermission(
- (res) => {
- console.log(res);
- });
- },
- isPermissionFW() { //是否申请悬浮窗权限
- var that = this;
- 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()
- }
- console.log('kaiqibaohuokaiqibaohuokaiqibaohuo-----')
-
- // 监听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:3000, // 间隔时间,这里为了测试效果,设置为500毫秒,实际情况根据自己业务设置
- minDistanceM: 15 // 间隔距离,这里为了测试效果,设置为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);
- console.log("kaiqidingwei------")
- },
- getAndroidNotification() {
- let channelId = 10
- let params = {}
- params.identifier = "123" // 通知ID,主要用于修改、删除通知,android里的identifier必须是数字,iOS的identifier可以是任意字符串
- params.channel = { // 如果已经channelId的channel则不创建,如果没有则会自动创建
- channelId: channelId,
- channelName: "Bảo hành",
- 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: "Bảo hành",
- 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>
|