App.vue 27 KB

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