App.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. <script>//com.cityexpress1688.ptqs
  2. const toast = uni.requireNativePlugin('Ba-Toast');//android
  3. const callerID = uni.requireNativePlugin('Ba-CallerID');//android
  4. const KJPip = uni.requireNativePlugin('KJ-Pip');//ios
  5. //const bugly = uni.requireNativePlugin("LX-Bugly");
  6. // import {
  7. // UTSKeepalive
  8. // } from "@/uni_modules/wrs-uts-keepalive"
  9. // let keepalive = new UTSKeepalive()
  10. import {
  11. setRiderposition,
  12. changeLanguages,
  13. gcj02towgs
  14. } from '@/pages/api/basic';
  15. import api from "@/pages/api/api.js"
  16. export default {
  17. data() {
  18. return {
  19. startFl:0,
  20. timer:'',
  21. cid:'',
  22. isAndroid:false,
  23. androidflType:0,
  24. isInback:false,
  25. iosInit:false,
  26. audioObj:null,
  27. isfirst:true
  28. }
  29. },
  30. globalData:{
  31. _i18n:{},
  32. $t:{},
  33. imViewOpen:false,
  34. sj:{},
  35. iosfl:{},
  36. EXViewOpen:false,
  37. auditStatus:0,
  38. isOnline:true,
  39. token:'',
  40. initgoEasy:{},
  41. goEasycnt:false,
  42. goEasy:null
  43. },
  44. onLaunch: function() {
  45. console.log('App Launch')
  46. //bugly.init("23bea5717e","true")
  47. this.globalData.$t=str=>this.$t(str);
  48. this.globalData.sj=str=>this.getTimestr();
  49. this.globalData.iosfl=index=>this.showpiaof(index);
  50. this.globalData.token = uni.getStorageSync("token");
  51. this.globalData.imViewOpen = false;
  52. this.globalData.EXViewOpen = false;
  53. this.globalData.goEasy = this.goEasy;
  54. this.globalData.initgoEasy=str=>this.connectGoEasy();
  55. let systemInfo = uni.getSystemInfoSync();
  56. this.isAndroid = systemInfo.platform.toLowerCase() === 'android';
  57. var language = uni.getStorageSync('language');
  58. if(''==language||null==language||undefined==language){
  59. uni.setStorageSync('language',"zh-Hant");
  60. uni.setLocale('zh-Hant');
  61. if(!this.isAndroid){
  62. this.$i18n.locale = 'zh-Hant';
  63. }
  64. this.uploadLanguagesSet('zh-Hant');
  65. }
  66. else{
  67. uni.setLocale(language);
  68. if(!this.isAndroid){
  69. this.$i18n.locale = language;
  70. }
  71. this.uploadLanguagesSet(language);
  72. }
  73. this.connectGoEasy();
  74. if(!this.isAndroid){
  75. this.startLocation();
  76. }
  77. if(this.isAndroid){
  78. // 设置回调
  79. // UTSKeepalive.setCallback((resp)=>{
  80. // console.log('--------',resp)
  81. // let opt = resp.opt
  82. // switch (opt){
  83. // // 定位改变
  84. // case "onLocationChanged":
  85. // if(this.isAndroid) {
  86. // let location = resp.location
  87. // this.androidRecvitude(location.longitude,location.latitude);
  88. // } else {
  89. // let locations = resp.locations
  90. // }
  91. // break;
  92. // default:
  93. // break;
  94. // }
  95. // })
  96. // this.kaiqibaohuo();
  97. }
  98. uni.onPushMessage((res) => {
  99. console.log("收到推送消息:",res) //监听推送消息
  100. var payload=res.data.payload;
  101. if(payload.indexOf("rcuser")!=-1){
  102. this.updataxiaoxi(payload);
  103. }
  104. if(res.type=='click'){
  105. var content=res.data.title;
  106. plus.runtime.setBadgeNumber(0);
  107. }
  108. if(res.type=='receive'){
  109. plus.runtime.setBadgeNumber(0);
  110. var content=res.data.content;
  111. if(content.indexOf("location")!=-1){
  112. var objpl=JSON.parse(payload);
  113. this.cid=objpl.cid;
  114. this.getLocationL();
  115. return
  116. }
  117. uni.createPushMessage({
  118. content:res.data.content,
  119. success: (res) => {
  120. console.log(res);
  121. },
  122. fail(er) {
  123. }
  124. });
  125. }
  126. })
  127. var that = this;
  128. //android---------------------------------------------
  129. if(that.isAndroid){
  130. that.audioObj=uni.createInnerAudioContext();
  131. that.audioObj.src='hybrid/html/xuanfu/img/y800.mp3';
  132. }
  133. var globalEvent = uni.requireNativePlugin('globalEvent');
  134. globalEvent.addEventListener('baCallerIdEvent', function(e) {
  135. console.log('baCallerIdEvent:' + JSON.stringify(e));
  136. console.log(e);
  137. if(e.tag=='call'&&e.action=='onClick'){
  138. if(that.isInback){
  139. plus.runtime.launchApplication({pname:'com.cityexpress1688.ptqs'});
  140. }
  141. if(that.androidflType==1){
  142. uni.navigateTo({
  143. url:'/pages/imcall/audioCall?iscaller=0'
  144. })
  145. }
  146. else if(that.androidflType==2){
  147. uni.navigateTo({
  148. url:'/pages/imcall/GoeasyExchange?iscaller=0'
  149. })
  150. }
  151. that.audioObj.pause();
  152. that.hideFW();
  153. }
  154. if(e.tag=='uncall'&&e.action=='onClick'){
  155. that.audioObj.pause();
  156. that.hideFW();
  157. }
  158. });
  159. //ios-------------------------------------------------------------
  160. globalEvent.addEventListener('onPip', function(res) {
  161. console.log("onPip:" + JSON.stringify(res));
  162. if (res.method == "willStartPip") {
  163. console.log("即将开启画中画");
  164. } else if (res.method == "didStartPip") {
  165. console.log("已经开启画中画");
  166. } else if (res.method == "failedStartPip") {
  167. console.log("开启画中画失败");
  168. } else if (res.method == "willStopPip") {
  169. console.log("即将关闭画中画");
  170. //that.imdef();
  171. } else if (res.method == "didStopPip") {
  172. console.log("已经关闭画中画");
  173. } else if (res.method == "restorePip") {
  174. console.log("恢复");
  175. }
  176. });
  177. globalEvent.addEventListener('onWebview', function(res) {
  178. console.log("onWebview:" + JSON.stringify(res));
  179. if (res.method == "finish") {
  180. console.log("页面加载完成");
  181. } else if (res.method == "fail") {
  182. console.log("加载失败");
  183. }
  184. });
  185. if(!this.isAndroid){
  186. this.onH5SendDataCallBack();
  187. }
  188. },
  189. onShow: function() {
  190. console.log('App Show')
  191. this.isInback=false;
  192. this.initflaotView();
  193. //bugly.report("上报内容1111")
  194. if(!this.isAndroid){
  195. this.startLocation()
  196. }
  197. },
  198. onHide: function() {
  199. console.log('App Hide')
  200. this.isInback=true;
  201. // if(!this.isAndroid){
  202. // this.openPip1();
  203. // }
  204. // setInterval(() => {
  205. // console.log("定时任务 count: " + this.count)
  206. // }, 10000);
  207. if(!this.isAndroid){
  208. this.startLocation()
  209. }
  210. },
  211. methods: {
  212. getTimestr(){
  213. var time=new Date();
  214. var n,y,r,h,m,s;
  215. n=time.getFullYear();
  216. y=time.getMonth()+1;
  217. r=time.getDate();
  218. h=time.getHours();
  219. m=time.getMinutes();
  220. s=time.getSeconds();
  221. var timsStr = n+'-'+y+'-'+r+' '+h+':'+m+':'+s;
  222. return timsStr;
  223. },
  224. startLocation(){
  225. console.log('1startLocation')
  226. var token = uni.getStorageSync("token");
  227. //console.log('2222',that.token)
  228. if(token == '' || token == undefined || token == null){
  229. return;
  230. }
  231. else{
  232. if(this.startFl==0){
  233. //console.log(that.startFl);
  234. this.startFl=1;
  235. this.timer = setInterval(() => {
  236. this.getLocationL();
  237. }, 10000);
  238. }
  239. }
  240. },
  241. getLocationL(){
  242. var yszche=uni.getStorageSync('yszche');
  243. // console.log(this.startFl,yszche);
  244. if(1!=yszche){
  245. return;
  246. }
  247. var that = this;
  248. // console.log('uni.getLocation')
  249. uni.getLocation({
  250. type: "wgs84", //默认为 wgs84 返回 gps 坐标//谷歌地图使用 wgs84 坐标,其他地图使用 gcj02 坐标
  251. geocode: "true",
  252. isHighAccuracy: "true",
  253. accuracy: "best", // 精度值为20m
  254. success: function (res) {
  255. // console.log("app定位获取:", res);
  256. if(res.longitude>-180&&res.longitude<180){
  257. if(res.latitude>-90&&res.latitude<90){
  258. if(that.cid!=''){
  259. that.pushMsg(that.cid,res.longitude,res.latitude)
  260. }
  261. that.setRiderposition(res.longitude,res.latitude);
  262. }
  263. }
  264. },
  265. fail(err) {
  266. console.log('getLocation err')
  267. }
  268. });
  269. },
  270. androidRecvitude(longitude,latitude){
  271. var yszche=uni.getStorageSync('yszche');
  272. console.log(this.startFl,yszche);
  273. if(1!=yszche){
  274. return;
  275. }
  276. var token = uni.getStorageSync("token");
  277. //console.log('2222',that.token)
  278. if(token == '' || token == undefined || token == null){
  279. return;
  280. }
  281. this.setRiderposition(longitude,latitude);
  282. },
  283. setRiderposition(longitude,latitude){
  284. this.$http.post(`${setRiderposition}`, {
  285. "longitude":longitude,
  286. "latitude":latitude
  287. },true)
  288. .then(r => {
  289. // console.log('setRiderposition',r)
  290. })
  291. .catch(err => {
  292. console.log(err)
  293. })
  294. },
  295. async uploadLanguagesSet(lang){
  296. var userId = uni.getStorageSync('userId');
  297. if(lang=='yuenan'){
  298. lang='vi';
  299. }
  300. if(lang=='zh-Hans'){
  301. lang='zh-CN';
  302. }
  303. if(lang=='zh-Hant'){
  304. lang='zh-TW';
  305. }
  306. //console.log("changeLanguages");
  307. await this.$http.get(`${changeLanguages}`, {
  308. id:userId,
  309. lang:lang
  310. },false)
  311. .then(async r => {
  312. //console.log(r)
  313. })
  314. .catch(err => {
  315. console.log(err)
  316. })
  317. },
  318. updataxiaoxi(str){
  319. var xiaoxiList = uni.getStorageSync('dachexiaoxi');
  320. if(''==xiaoxiList||null==xiaoxiList||undefined==xiaoxiList){
  321. xiaoxiList=[];
  322. }
  323. xiaoxiList.push(str);
  324. uni.setStorageSync('dachexiaoxi',xiaoxiList);
  325. },
  326. pushMsg(cid,longitude,latitude){//消息推送
  327. var payloadData={
  328. longitude:longitude,
  329. latitude:latitude
  330. }
  331. api('pushMsgYH',{
  332. cid:cid,
  333. title:'骑手定位',
  334. content:'骑手定位',
  335. payload:payloadData
  336. },res=>{
  337. this.cid='';
  338. console.log(res)
  339. },failc=>{
  340. //console.log('getadvertis----',failc)
  341. })
  342. },
  343. //imcall&&immessage------------------------------------------------
  344. initflaotView(){
  345. if(this.isAndroid){
  346. if(this.isfirst){
  347. this.isPermissionFW();
  348. this.isfirst=false
  349. }
  350. }
  351. else{//ios
  352. // var that = this;
  353. // setTimeout(function() {
  354. // // 这里写要延时执行的代码
  355. // that.initPip("landscape");
  356. // }, 2000);
  357. }
  358. },
  359. imcallrecive(str){
  360. if(str.indexOf("\\\"")!=-1){
  361. str=str.replace(/\\\"/g, '\"');
  362. str = str.replace(/\"{/g, '{');
  363. str = str.replace(/}\"/g, '}');
  364. }
  365. var obj = JSON.parse(str)
  366. console.log('imcallrecive',obj)
  367. if(this.isAndroid){
  368. if(this.androidflType!=0){
  369. return;
  370. }
  371. var uobj={
  372. name:obj.nickName,
  373. content:this.$t('audioCall.cteyhcall'),
  374. call:this.$t('audioCall.jietingyy'),
  375. uncall:this.$t('audioCall.jujuejieting')
  376. }
  377. this.androidflType=1;
  378. this.showFW(uobj,false);
  379. this.audioObj.play();
  380. }
  381. else{//ios
  382. this.imCall();
  383. }
  384. },
  385. immessagerecive(str){
  386. if(str.indexOf("\\\"")!=-1){
  387. str=str.replace(/\\\"/g, '\"');
  388. str = str.replace(/\"{/g, '{');
  389. str = str.replace(/}\"/g, '}');
  390. }
  391. var obj = JSON.parse(str);
  392. if(this.isAndroid){
  393. if(this.androidflType!=0){
  394. return;
  395. }
  396. var uobj={
  397. name:obj.nickName,
  398. content:this.$t('exchange.cteyhmsg'),
  399. call:this.$t('exchange.chakanxinxi'),
  400. uncall:this.$t('exchange.quxiao')
  401. }
  402. this.androidflType=2;
  403. this.showFW(uobj,false);
  404. this.audioObj.play();
  405. }
  406. else{//ios
  407. this.imMessage();
  408. }
  409. },
  410. //android-------------------------------------------------
  411. showFW(obj,isInit) { //显示
  412. var that = this;
  413. if(!callerID){
  414. return
  415. }
  416. callerID.show({
  417. gravity: 1, //显示位置:0中间 1上 2下
  418. name:obj.name,//用户昵称 ,
  419. content:obj.content,//说明是骑手来电、来信息
  420. call: obj.call,//接听IM,查看IM信息
  421. uncall: obj.uncall,//拒绝接听IM,拒绝查看IM信息
  422. empty: "",
  423. avatar: "/static/logo.png",
  424. totalHint: "",
  425. tel: "",
  426. list:[]
  427. },
  428. (res) => {
  429. console.log(res);
  430. if(isInit){
  431. that.hideFW()
  432. }
  433. // uni.showToast({
  434. // title: res.msg,
  435. // icon: "none",
  436. // duration: 3000
  437. // })
  438. });
  439. },
  440. hideFW() { //隐藏
  441. this.androidflType=0;
  442. if(!callerID){
  443. return
  444. }
  445. callerID.hide(
  446. (res) => {
  447. console.log(res);
  448. // uni.showToast({
  449. // title: res.msg,
  450. // icon: "none",
  451. // duration: 3000
  452. // })
  453. });
  454. },
  455. permissionFW() { //申请悬浮窗权限
  456. if(!callerID){
  457. return
  458. }
  459. callerID.permission(
  460. (res) => {
  461. console.log(res);
  462. });
  463. },
  464. goPermissionFW() { //跳转到悬浮窗权限页面
  465. if(!callerID){
  466. return
  467. }
  468. callerID.goPermission(
  469. (res) => {
  470. console.log(res);
  471. });
  472. },
  473. isPermissionFW() { //是否申请悬浮窗权限
  474. var that = this;
  475. if(!callerID){
  476. return
  477. }
  478. callerID.isPermission(
  479. (res) => {
  480. console.log(res);
  481. if (res.data) {
  482. if(res.data.isPermission){
  483. var uobj={
  484. name:'CTE',
  485. content:'',
  486. call:'',
  487. uncall:''
  488. }
  489. that.showFW(uobj,true);
  490. }
  491. else{
  492. that.goPermissionFW();
  493. }
  494. }
  495. });
  496. },
  497. //ios--------------------------------------
  498. showpiaof(index){
  499. var that = this;
  500. if(index==1){
  501. setTimeout(function() {
  502. // 这里写要延时执行的代码
  503. that.initPip("landscape");
  504. }, 800);
  505. }
  506. if(index==2){
  507. that.closePip();
  508. }
  509. if(index==3){
  510. var language = uni.getStorageSync('language');
  511. if(language=='yuenan'){
  512. var dic = {
  513. "js": "changeImgvi()"
  514. }
  515. KJPip.webView_evaluateJavaScript(dic, (res) => {
  516. console.log("webView_evaluateJavaScript:" + JSON.stringify(res));
  517. })
  518. }
  519. else{
  520. var dic = {
  521. "js": "changeImg()"
  522. }
  523. KJPip.webView_evaluateJavaScript(dic, (res) => {
  524. console.log("webView_evaluateJavaScript:" + JSON.stringify(res));
  525. })
  526. }
  527. }
  528. if(index==4){
  529. var language = uni.getStorageSync('language');
  530. if(language=='yuenan'){
  531. var dic = {
  532. "js": "changeImgMSvi()"
  533. }
  534. KJPip.webView_evaluateJavaScript(dic, (res) => {
  535. console.log("webView_evaluateJavaScript:" + JSON.stringify(res));
  536. })
  537. }
  538. else{
  539. var dic = {
  540. "js": "changeImgMS()"
  541. }
  542. KJPip.webView_evaluateJavaScript(dic, (res) => {
  543. console.log("webView_evaluateJavaScript:" + JSON.stringify(res));
  544. })
  545. }
  546. }
  547. return '';
  548. },
  549. initPip(shape) {
  550. var dic = {
  551. "shape": shape, //弹窗形状 square(正方形) landscape(横向) portrait(竖向)
  552. }
  553. KJPip.initPip(dic)
  554. console.log('initPip')
  555. var that = this;
  556. that.iosInit=true;
  557. setTimeout(function() {
  558. // 这里写要延时执行的代码
  559. that.openPip1();
  560. }, 2000);
  561. },
  562. openPip1() {//打开,加载本地页面?language='+language
  563. var language = uni.getStorageSync('language');
  564. this.openPip(plus.io.convertLocalFileSystemURL("hybrid/html/xuanfu/index.html"));
  565. },
  566. openPip(url) {
  567. var that = this;
  568. KJPip.isPictureInPictureActive((res) => {
  569. console.log("isPictureInPictureActive:" + JSON.stringify(res));
  570. })
  571. KJPip.isPictureInPictureSuspended((res) => {
  572. console.log("isPictureInPictureSuspended:" + JSON.stringify(res));
  573. })
  574. KJPip.isPictureInPicturePossible((res) => {
  575. console.log("isPictureInPicturePossible:" + JSON.stringify(res));
  576. // if(!res.result){
  577. // setTimeout(function() {
  578. // // 这里写要延时执行的代码
  579. // //that.initPip("landscape");
  580. // }, 800);
  581. // }
  582. })
  583. KJPip.isPictureInPictureSupported((res) => {
  584. console.log("isPictureInPictureSupported:" + JSON.stringify(res));
  585. })
  586. var dic = {
  587. "url": url
  588. }
  589. KJPip.openPip(dic, (res) => {
  590. console.log("openPip:" + JSON.stringify(res));
  591. })
  592. },
  593. closePip() {//关闭弹窗
  594. KJPip.closePip()
  595. },
  596. imCall(){//收到IM语音通话请求
  597. uni.navigateTo({
  598. url:'/pages/imcall/audioCall?iscaller=0'
  599. })
  600. },
  601. imMessage(){//收到im文字聊天请求
  602. // plus.runtime.launchApplication({action:'cityexpress1688ptqs://'},
  603. // function(e){
  604. // console.log('launchApplication',e);
  605. // });
  606. // plus.runtime.openURL('cityexpress1688ptqs://', function(res) {
  607. // console.log('123123',res);
  608. // });
  609. uni.navigateTo({
  610. url:'/pages/imcall/GoeasyExchange?iscaller=0'
  611. })
  612. },
  613. imdef(){//收到im文字聊天请求
  614. var dic = {
  615. "js": "changeImgdef()"
  616. }
  617. KJPip.webView_evaluateJavaScript(dic, (res) => {
  618. console.log("webView_evaluateJavaScript:" + JSON.stringify(res));
  619. })
  620. },
  621. onH5SendDataCallBack() { //注意ios16之后,弹出里的内容不能点击
  622. var that = this;
  623. KJPip.onH5SendDataCallBack((res) => {
  624. console.log("onH5SendDataCallBack:",res);
  625. // if(res.result){
  626. // var obj = JSON.parse(res.result);
  627. // if(obj.key==1){
  628. // uni.navigateTo({
  629. // url:'/pages/imcall/audioCall?iscaller=0'
  630. // })
  631. // that.imdef();
  632. // }
  633. // else if(obj.key==2){
  634. // uni.navigateTo({
  635. // url:'/pages/imcall/ExchangeView?iscaller=0'
  636. // })
  637. // that.imdef();
  638. // }
  639. // }
  640. })
  641. },
  642. //GoEasy--------------------------------------------
  643. connectGoEasy() {
  644. var that = this;
  645. if(that.globalData.goEasycnt==true){
  646. that.goeasydisconnect();
  647. return;
  648. }
  649. var userInfo=uni.getStorageSync('userInfo');
  650. if(''==userInfo||null==userInfo||undefined==userInfo){
  651. return;
  652. }
  653. this.goEasy.connect({
  654. id:'userid_'+userInfo.userId,
  655. data: {
  656. name:userInfo.nickName,
  657. avatar:userInfo.avatar
  658. },
  659. onSuccess: () => {
  660. console.log('GoEasy connect successfully.')
  661. that.goEasyPush();
  662. that.globalData.goEasycnt=true;
  663. },
  664. onFailed: (error) => {
  665. console.log('Failed to connect GoEasy, code:' + error.code + ',error:' + error.content);
  666. },
  667. onProgress: (attempts) => {
  668. console.log('GoEasy is connecting', attempts);
  669. }
  670. });
  671. },
  672. goEasyPush(){
  673. var userInfo=uni.getStorageSync('userInfo');
  674. if(''==userInfo||null==userInfo||undefined==userInfo){
  675. return;
  676. }
  677. //console.log(userInfo);
  678. var that = this;
  679. var pubsub = this.goEasy.pubsub;
  680. pubsub.subscribe({
  681. channel:'userid_'+userInfo.userId,
  682. onMessage: function (message) {
  683. if(message.content){
  684. var obj = JSON.parse(message.content);
  685. if(obj.ptype==1){
  686. if(that.globalData.imViewOpen){
  687. return;
  688. }
  689. uni.setStorageSync('impayload',message.content);
  690. that.imcallrecive(message.content);
  691. }
  692. if(obj.ptype==2){
  693. if(that.globalData.EXViewOpen){
  694. return;
  695. }
  696. uni.setStorageSync('impayload',message.content);
  697. that.immessagerecive(message.content);
  698. }
  699. }
  700. console.log("Channel:" + message.channel + " content:" + message.content)
  701. },
  702. onSuccess: function () {
  703. console.log("Subscribe successfully.")
  704. },
  705. onFailed: function () {
  706. console.log("Subscribe successfully.")
  707. }
  708. });
  709. },
  710. //断开连接
  711. goeasydisconnect(){
  712. var that = this;
  713. this.goEasy.disconnect({
  714. onSuccess: function(){
  715. console.log("GoEasy disconnect successfully.")
  716. that.globalData.goEasycnt=false;
  717. that.connectGoEasy();
  718. },
  719. onFailed: function(error){
  720. console.log("Failed to disconnect GoEasy, code:"+error.code+ ",error:"+error.content);
  721. }
  722. });
  723. },
  724. //开启保活---------------------------------------------------------------------------------
  725. kaiqibaohuo(){
  726. if (this.isAndroid) {
  727. this.requestPermission([
  728. "android.permission.FOREGROUND_SERVICE",
  729. "android.permission.POST_NOTIFICATIONS",
  730. "android.permission.ACCESS_COARSE_LOCATION",
  731. "android.permission.ACCESS_FINE_LOCATION",
  732. "android.permission.WRITE_EXTERNAL_STORAGE",
  733. "android.permission.ACCESS_BACKGROUND_LOCATION"
  734. ]);
  735. } else {
  736. // var authorizationStatus = UTSKeepalive.getAuthorizationStatus();
  737. // if (authorizationStatus == 0) {// 没有授权过定位时,请求定位权限
  738. // keepalive.requestLocationAuthorization()
  739. // }
  740. // // 监听app前后台状态
  741. // UTSKeepalive.listenerApp((resp) => {
  742. // let opt = resp.opt
  743. // switch (opt) {
  744. // // app进入后台
  745. // case "enterBackground": {
  746. // var authorizationStatus = UTSKeepalive.getAuthorizationStatus();
  747. // console.log("authorizationStatus:" + authorizationStatus)
  748. // // app进入后台,此时采用定位保活还是采用播放音乐保活可以根据自己业务决定
  749. // if (authorizationStatus == 3) { // 当定位权限是总是一直定位时采用定位来保活
  750. // console.log("定位保活")
  751. // keepalive.startLocation({
  752. // desiredAccuracy: "NearestTenMeters",
  753. // allowsBackgroundLocationUpdates: true, // 允许后台更新位置
  754. // pausesLocationUpdatesAutomatically: false // 不允许自动暂停更新位置
  755. // })
  756. // } else { // 采用播放音乐保活
  757. // console.log("播放音乐保活")
  758. // UTSKeepalive.setCategory("playback")
  759. // var url = plus.io.convertLocalFileSystemURL('_www/static/bgmusic.mp3');
  760. // keepalive.playMusic({
  761. // url: url,
  762. // numberOfLoops: -1, // 循环此时,-1表示无限循环
  763. // volume: 0 // 音量,0
  764. // });
  765. // }
  766. // // 通知系统开始后台任务
  767. // UTSKeepalive.beginBackgroundTask()
  768. // }
  769. // break;
  770. // // app回到前台
  771. // case "enterForeground": {
  772. // // 停止播放音乐
  773. // keepalive.stopMusic()
  774. // // 停止定位
  775. // keepalive.stopLocation()
  776. // // 通知系统结束后台任务
  777. // UTSKeepalive.endBackgroundTask()
  778. // }
  779. // break;
  780. // default:
  781. // break;
  782. // }
  783. // })
  784. }
  785. },
  786. requestPermission: function(permissions) {
  787. var that = this;
  788. plus.android.requestPermissions(
  789. permissions,
  790. function(resultObj) {
  791. for (var i = 0; i < resultObj.granted.length; i++) {
  792. var grantedPermission = resultObj.granted[i];
  793. //console.log('已获取的权限:' + grantedPermission);
  794. }
  795. if(resultObj.granted.length>=5){
  796. // that.keepAlive();
  797. return;
  798. }
  799. for (var i = 0; i < resultObj.deniedPresent.length; i++) {
  800. var deniedPresentPermission = resultObj.deniedPresent[i];
  801. console.log('拒绝本次申请的权限:' + deniedPresentPermission);
  802. }
  803. for (var i = 0; i < resultObj.deniedAlways.length; i++) {
  804. var deniedAlwaysPermission = resultObj.deniedAlways[i];
  805. console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
  806. }
  807. // 若所需权限被永久拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限
  808. if (resultObj.deniedAlways.length > 0) {
  809. uni.showModal({
  810. cancelText: that.$t('index.quxiao'), // 取消按钮的文字
  811. confirmText: that.$t('index.queren'), // 确认按钮的文字
  812. title: that.$t('api.message'),
  813. content: that.$t('user.dingweiquanxian'),
  814. success: function (res) {
  815. if (res.confirm) { //这里是点击了确定以后
  816. that.kaiqidingwei();
  817. } else { //这里是点击了取消以后
  818. console.log('用户点击取消')
  819. }
  820. }
  821. })
  822. }
  823. },
  824. function(error) {
  825. console.log('申请权限错误:' + error.code + " = " + error.message);
  826. });
  827. },
  828. keepAlive() {
  829. console.log('keepAlive')
  830. // let params = this.getAndroidNotification();
  831. // console.log(params)
  832. // UTSKeepalive.startForegroundService(params)
  833. // UTSKeepalive.startJobService(params)
  834. // UTSKeepalive.startLocalService(params)
  835. // UTSKeepalive.startRemoteService(params)
  836. // UTSKeepalive.startScreenLockReceiver();
  837. // // 后台定位功能,用不到后台定位可以不需要调用
  838. // let locationParams = {}
  839. // locationParams.notification = params
  840. // locationParams.location = {
  841. // provider: "gps", // 支持gps、fused
  842. // minTimeMs:10000, // 间隔时间,这里为了测试效果,设置为500毫秒,实际情况根据自己业务设置
  843. // minDistanceM: 5.0 // 间隔距离,这里为了测试效果,设置为0.5米,实际情况根据自己业务设置
  844. // }
  845. // UTSKeepalive.startLocstionService(locationParams)
  846. },
  847. //开启定位权限------------------------------
  848. kaiqidingwei(){
  849. var Intent = plus.android.importClass("android.content.Intent");
  850. var Settings = plus.android.importClass("android.provider.Settings");
  851. var Uri = plus.android.importClass("android.net.Uri");
  852. var mainActivity = plus.android.runtimeMainActivity();
  853. var intent = new Intent();
  854. intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
  855. var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
  856. intent.setData(uri);
  857. mainActivity.startActivity(intent);
  858. },
  859. getAndroidNotification() {
  860. let channelId = 10
  861. let params = {}
  862. params.identifier = "123" // 通知ID,主要用于修改、删除通知,android里的identifier必须是数字,iOS的identifier可以是任意字符串
  863. params.channel = { // 如果已经channelId的channel则不创建,如果没有则会自动创建
  864. channelId: channelId,
  865. channelName: "騎手端持續為您服務",
  866. importance: 5, // 3: default 4: high 2: low 5: max 1: min 0: none
  867. lockscreenVisibility: 1, //1: public 0: private -1: secret
  868. // description: "Bảo hành"
  869. }
  870. params.notification = {
  871. channelId: channelId, // 此消息通知是属于哪个channel的
  872. contentTitle: "騎手端持續為您服務",
  873. // contentText: "Bảo hành",
  874. visibility: 1, // 1: public 0: private -1: secret
  875. smallIcon: { // 小图标,必传
  876. type: "resource", // 固定
  877. defType: "drawable", // 固定
  878. name: "not" // 文件名,不要带文件后缀,对应nativeResources/android/res/drawable文件夹下的图片
  879. },
  880. autoCancel: false
  881. }
  882. return params
  883. },
  884. },
  885. }
  886. </script>
  887. <style lang="scss">
  888. .content{
  889. display: flex;
  890. flex-direction: column;
  891. width: 94%;
  892. margin-left: 3%;
  893. background-color: white;
  894. border-radius: 16rpx;
  895. box-shadow: 0rpx 0rpx 10rpx 0rpx lightgray;
  896. }
  897. .contentInRowL{
  898. display: flex;
  899. flex-direction: row;
  900. justify-content: flex-start;
  901. }
  902. .contentInRowR{
  903. display: flex;
  904. flex-direction: row;
  905. justify-content:flex-end;
  906. }
  907. .contentInRowC{
  908. display: flex;
  909. flex-direction: row;
  910. justify-content: center;
  911. align-items: center;
  912. }
  913. .contentInRowS{
  914. display: flex;
  915. flex-direction: row;
  916. align-items: center;
  917. justify-content: space-between;
  918. }
  919. .contentColumn{
  920. display: flex;
  921. flex-direction: column;
  922. }
  923. .contentColumnC{
  924. display: flex;
  925. flex-direction: column;
  926. align-items: center;
  927. justify-content: center;
  928. }
  929. .text1row{
  930. overflow: hidden;
  931. text-overflow: ellipsis;
  932. /* #ifndef APP-PLUS-NVUE */
  933. display: -webkit-box;
  934. -webkit-line-clamp: 1;
  935. -webkit-box-orient: vertical;
  936. /* #endif */
  937. }
  938. .text2row{
  939. overflow: hidden;
  940. text-overflow: ellipsis;
  941. /* #ifndef APP-PLUS-NVUE */
  942. display: -webkit-box;
  943. -webkit-line-clamp: 2;
  944. -webkit-box-orient: vertical;
  945. /* #endif */
  946. }
  947. </style>