App.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <style lang="scss">
  2. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  3. @import "@/uni_modules/uview-ui/index.scss";
  4. @import 'static/css/common.scss';
  5. </style>
  6. <script>
  7. import region from "@/components/region/data";
  8. import {
  9. mapMutations
  10. } from 'vuex';
  11. import * as config from '@/config'
  12. import appUpdate from 'common/appUpdate.js'
  13. import app_push from './components/APPPush/app_push.js'
  14. import permision from "@/js_sdk/wa-permission/permission.js"
  15. export default {
  16. methods: {
  17. getLngLat(){
  18. uni.getLocation({
  19. type: 'gcj02',
  20. geocode: true,
  21. success: res => {
  22. if (res.latitude) {
  23. console.log(res)
  24. if(res.address.city){
  25. if(res.address.city.indexOf('市')!=-1){
  26. res.address.city=res.address.city.substring(0,res.address.city.length-1)
  27. }
  28. }
  29. if(res.address.province){
  30. if(res.address.province.indexOf('省')!=-1){
  31. res.address.province=res.address.province.substring(0,res.address.province.length-1)
  32. }
  33. }
  34. uni.setStorageSync('fPlaceObj',{
  35. fchoosearea:'全部',
  36. fchoosecity:res.address.city,
  37. fchooseprovince:res.address.province,
  38. selected:res.address.city
  39. })
  40. uni.setStorageSync('sPlaceObj',{
  41. schoosearea:'请选择区',
  42. schoosecity:'请选择市',
  43. schooseprovince:'全国',
  44. selected:'全国'
  45. })
  46. uni.setStorageSync('longitudeAndLatitude',res.longitude+','+res.latitude)
  47. }
  48. }
  49. })
  50. },
  51. checkOpenGPSServiceByAndroidIOS() {
  52. console.log()
  53. let system = uni.getSystemInfoSync(); // 获取系统信息
  54. console.log(system);
  55. if (system.platform === 'android') { // 判断平台
  56. var context = plus.android.importClass("android.content.Context");
  57. var locationManager = plus.android.importClass("android.location.LocationManager");
  58. var main = plus.android.runtimeMainActivity();
  59. var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  60. if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
  61. uni.showModal({
  62. title: '提示',
  63. content: '请打开定位服务功能',
  64. // showCancel: false, // 不显示取消按钮
  65. success(res) {
  66. if(res.confirm){
  67. if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
  68. var Intent = plus.android.importClass('android.content.Intent');
  69. var Settings = plus.android.importClass('android.provider.Settings');
  70. var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  71. main.startActivity(intent); // 打开系统设置GPS服务页面
  72. this.getLngLat()
  73. } else {
  74. uni.setStorageSync('fPlaceObj',{
  75. fchoosearea:'全部',
  76. fchoosecity:'市辖区',
  77. fchooseprovince:'北京',
  78. selected:res.address.city
  79. })
  80. uni.setStorageSync('sPlaceObj',{
  81. schoosearea:'请选择区',
  82. schoosecity:'请选择市',
  83. schooseprovince:'全国',
  84. selected:'全国'
  85. })
  86. uni.setStorageSync('longitudeAndLatitude','116.3972,39.9096')
  87. }
  88. }
  89. }
  90. });
  91. }else{
  92. this.getLngLat()
  93. }
  94. } else if (system.platform === 'ios') {
  95. console.log("苹果");
  96. var cllocationManger = plus.ios.import("CLLocationManager");
  97. var enable = cllocationManger.locationServicesEnabled();
  98. var status = cllocationManger.authorizationStatus();
  99. plus.ios.deleteObject(cllocationManger);
  100. if (enable && status != 2) {
  101. this.getLngLat()
  102. console.log("手机系统的定位已经打开");
  103. } else {
  104. console.log("手机系统的定位没有打开");
  105. uni.showModal({
  106. title: '提示',
  107. content: '请前往设置-隐私-定位服务打开定位服务功能',
  108. // showCancel: false, // 不显示取消按钮
  109. success(res) {
  110. if(res.confirm){
  111. var UIApplication = plus.ios.import("UIApplication");
  112. var application2 = UIApplication.sharedApplication();
  113. var NSURL2 = plus.ios.import("NSURL");
  114. // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
  115. // var setting2 = NSURL2.URLWithString("App-Prefs:root=LOCATION_SERVICES");
  116. // var setting2 = NSURL2.URLWithString("app-settings");
  117. var setting2 = NSURL2.URLWithString("App-Prefs:root=Privacy&path=LOCATION");
  118. // var setting2 = NSURL2.URLWithString("App-Prefs:root=Privacy&path=LOCATION_SERVICES");
  119. application2.openURL(setting2);
  120. plus.ios.deleteObject(setting2);
  121. plus.ios.deleteObject(NSURL2);
  122. plus.ios.deleteObject(application2);
  123. this.getLngLat()
  124. }
  125. }
  126. });
  127. }
  128. }
  129. },
  130. ...mapMutations(['login']),
  131. // vue的method里编写如下代码
  132. // async requestAndroidPermission(permisionID) {
  133. // var result = await permision.requestAndroidPermission(permisionID)
  134. // var strStatus
  135. // if (result == 1) {
  136. // strStatus = "已获得授权"
  137. // } else if (result == 0) {
  138. // strStatus = "未获得授权"
  139. // // permision.gotoAppPermissionSetting()
  140. // // 引导设置,判断是否有运输中订单,有订单,必须授权
  141. // } else {
  142. // strStatus = "被永久拒绝权限"
  143. // // permision.gotoAppPermissionSetting()
  144. // }
  145. // },
  146. },
  147. onLaunch: function() {
  148. var that = this
  149. // #ifdef APP-PLUS
  150. this.checkOpenGPSServiceByAndroidIOS()
  151. // uni.getNetworkType({
  152. // success: function (res) {
  153. // if(res.networkType=='none'){
  154. // let options = {
  155. // title: '提示',
  156. // info:'当前没有网络中',
  157. // okText: '连接Wifi',
  158. // cancelText:'开启流量',
  159. // infoAlignment:'center',
  160. // radius:10,
  161. // // cancelText: '否',
  162. // // showCancel:false,
  163. // okButtonColor:'#2772FB'
  164. // };
  165. // const native = uni.requireNativePlugin('AJ-Alert');
  166. // native.showAction(options, result => {
  167. // // #ifdef APP-PLUS
  168. // if (uni.getSystemInfoSync().platform == 'ios') {
  169. // plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
  170. // } else if (uni.getSystemInfoSync().platform == 'android') {
  171. // plus.runtime.quit();
  172. // }
  173. // // #endif
  174. // // 点击是的回调, result暂时没有返回内容
  175. // }, cancel => {
  176. // // 点击否的回调
  177. // });
  178. // }
  179. // console.log(res.networkType);
  180. // }
  181. // });
  182. console.log(uni.getStorageSync('userInfo'))
  183. if(uni.getStorageSync('userInfo')){
  184. that.$request.baseRequest('get', '/driverInfo/firstAuthentication', {
  185. driverPhone:uni.getStorageSync('userInfo').phone,
  186. }).then(res => {
  187. if (res.data.authenticationStatus == '已禁用') {
  188. // this.isShowAlert = true
  189. // this.alertTitle = '账号审核中'
  190. // this.confirmText = '退出APP'
  191. // this.showCancelButton = false
  192. let options = {
  193. title: '提示',
  194. info:'账号审核中',
  195. okText: '退出程序',
  196. infoAlignment:'center',
  197. radius:10,
  198. // cancelText: '否',
  199. showCancel:false,
  200. okButtonColor:'#2772FB'
  201. };
  202. const native = uni.requireNativePlugin('AJ-Alert');
  203. native.showAction(options, result => {
  204. // #ifdef APP-PLUS
  205. if (uni.getSystemInfoSync().platform == 'ios') {
  206. plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
  207. } else if (uni.getSystemInfoSync().platform == 'android') {
  208. plus.runtime.quit();
  209. }
  210. // #endif
  211. // 点击是的回调, result暂时没有返回内容
  212. }, cancel => {
  213. // 点击否的回调
  214. });
  215. // uni.showModal({
  216. // title: '提示',
  217. // content: '这是一个模态弹窗',
  218. // showCancel:false,
  219. // confirmText:'退出app',
  220. // // confirmColor:'#317AFE',
  221. // confirmColor:'#F54E40',
  222. // success: function (res) {
  223. // if (res.confirm) {
  224. // // #ifdef APP-PLUS
  225. // if (uni.getSystemInfoSync().platform == 'ios') {
  226. // plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
  227. // } else if (uni.getSystemInfoSync().platform == 'android') {
  228. // plus.runtime.quit();
  229. // }
  230. // // #endif
  231. // } else if (res.cancel) {
  232. // console.log('用户点击取消');
  233. // }
  234. // }
  235. // });
  236. } else {
  237. console.log(1231233212332312312213)
  238. }
  239. })
  240. }
  241. // #endif
  242. uni.setStorageSync("region", region);
  243. uni.getSystemInfo({
  244. success:function(e){
  245. Vue.prototype.statusBar = e.statusBarHeight
  246. // #ifndef MP
  247. if(e.platform == 'android') {
  248. Vue.prototype.customBar = e.statusBarHeight + 50
  249. }else {
  250. Vue.prototype.customBar = e.statusBarHeight + 45
  251. }
  252. // #endif
  253. // #ifdef MP-WEIXIN
  254. let custom = wx.getMenuButtonBoundingClientRect()
  255. Vue.prototype.customBar = custom.bottom + custom.top - e.statusBarHeight
  256. // #endif
  257. // #ifdef MP-ALIPAY
  258. Vue.prototype.customBar = e.statusBarHeight + e.titleBarHeight
  259. // #endif
  260. }
  261. })
  262. // #ifdef APP-PLUS
  263. var that=this
  264. //判断该用户是否需要开启持续定位
  265. if(uni.getStorageSync('userInfo')){
  266. this.$request.baseRequest('get', '/orderInfo/getData', {
  267. commonId:uni.getStorageSync('userInfo').id,
  268. }).then(res1 => {
  269. if(res1.data.length>0){
  270. that.$helper.fUN_AmapLocation.start({
  271. // intervalTime: 1000 * 60,
  272. intervalTime: 5000,
  273. // locationCacheEnable:true,
  274. isReport: false
  275. // url: 'http://192.168.0.66/fun/open/test_json.do',
  276. // params: {
  277. // a: 1,
  278. // B: '测试',
  279. // c: true
  280. // },
  281. // headers: {
  282. // a: '123',
  283. // B: 'abcd'
  284. // }
  285. },
  286. res => {
  287. // console.log('====确认装车开启连续定位====');
  288. // console.log(res)
  289. let _data = {
  290. orderId: res1.data[0].id,
  291. longitude: res.longitude,
  292. latitude: res.latitude,
  293. province: res.province,
  294. city: res.city,
  295. area: res.district
  296. }
  297. this.$helper.gjList.push(_data)
  298. uni.setStorageSync('mapGJ', this.$helper.gjList);
  299. // console.log('this.$helper.gjList')
  300. // console.log(this.$helper.gjList)
  301. // console.log("条数", uni.getStorageSync('mapGJ').length)
  302. if (uni.getStorageSync('mapGJ').length > 100) {
  303. console.log(JSON.stringify(uni.getStorageSync('mapGJ')) )
  304. this.$request.baseRequest('post', '/hyOrderTravelPath/api/addInfo', {
  305. orderId:"cdae6ec34c2349768c490a9fefa03fb3",
  306. longitudeLatitude:JSON.stringify(uni.getStorageSync('mapGJ'))
  307. }).then(res => {
  308. uni.removeStorageSync('mapGJ');
  309. this.$helper.gjList = []
  310. })
  311. .catch(res => {
  312. uni.$u.toast(res.message);
  313. });
  314. }
  315. //判断缓存数据条数,超过reportInterval时清空缓存,重新存入缓存
  316. }
  317. );
  318. }
  319. })
  320. }
  321. // this.$helper.fUN_AmapLocation.stop({}, result => {
  322. // console.log('====fUN_AmapLocation定位stop====', JSON.stringify(result));
  323. // this.$helper.fUN_AmapLocation.start(
  324. // {
  325. // intervalTime: 1000*60,
  326. // isReport: true,
  327. // reportInterval: 5,
  328. // url: 'http://192.168.0.66/fun/open/test_json.do',
  329. // params: { a: 1, B: '测试', c: true },
  330. // headers: { a: '123', B: 'abcd' }
  331. // },
  332. // res => {
  333. // //见下方定位返回示例
  334. // console.log('====确认装车开启连续定位====', JSON.stringify(res));
  335. // //判断缓存数据条数,超过reportInterval时清空缓存,重新存入缓存
  336. // }
  337. // );
  338. // });
  339. // fUN_AmapLocation.permission({}, result => {
  340. // console.log('====fUN_AmapLocation定位====');
  341. // });
  342. // fUN_AmapLocation.hasLocationPermissions(function(result) {
  343. // console.log('====fUN_AmapLocation定位权限===='+ result)
  344. // });
  345. // startLocation与start均可
  346. // this.$helper.fUN_AmapLocation.start(
  347. // {
  348. // intervalTime: 1000*10,
  349. // isReport: false,
  350. // },
  351. // result => {
  352. // //见下方定位返回示例
  353. // console.log('====fUN_AmapLocation定位====', JSON.stringify(result));
  354. // }
  355. // );
  356. // let isOpenLocation= permision.checkSystemEnableLocation()
  357. // console.log("isOpenLocation",isOpenLocation)
  358. // this.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
  359. let type = uni.getSystemInfoSync().platform
  360. console.log(type)
  361. if (type == "android") {
  362. appUpdate()
  363. }
  364. // plus.push.getClientInfoAsync((info) => {
  365. // var name = 'clientId'
  366. // var value = info.clientid
  367. // that.$store.commit('$uStore', {
  368. // name,
  369. // value
  370. // });
  371. // uni.setStorageSync("clientId", info.clientid)
  372. // console.log("info.clientid", info.clientid)
  373. // }, err => {});
  374. // 监听在线消息事件
  375. // plus.push.addEventListener("receive", function(msg) {
  376. // var title = msg.content.split(':')[0]
  377. // var content = msg.content.split(':')[1]
  378. // let params = {
  379. // inApp: true, // app内横幅提醒
  380. // voice: true, // 声音提醒
  381. // vibration: true, // 振动提醒
  382. // messageType: "",
  383. // messageTitle: title,
  384. // messageContent: content,
  385. // messageImage: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/logo.png'
  386. // }
  387. // console.log("msg", msg)
  388. // new app_push({
  389. // ...params
  390. // }).show();
  391. // var userInfo = uni.getStorageSync("userInfo")
  392. // var that = this
  393. // that.$request.baseRequest('get', '/notice/query/noticeNumber').then(res => {
  394. // if (res.data.data) {
  395. // let name = 'myTip';
  396. // let value = res.data.data.task;
  397. // that.$store.commit('$uStore', {
  398. // name,
  399. // value
  400. // });
  401. // if (value != 0 && value) {
  402. // uni.setTabBarBadge({
  403. // index: 4,
  404. // text: value + ""
  405. // })
  406. // }
  407. // name = 'taskTip';
  408. // value = res.data.data.task;
  409. // that.$store.commit('$uStore', {
  410. // name,
  411. // value
  412. // });
  413. // // name = 'contractTip';
  414. // // value = res.data.data.contractTip;
  415. // // that.$store.commit('$uStore', {
  416. // // name,
  417. // // value
  418. // // });
  419. // }
  420. // })
  421. // //其它逻辑
  422. // }, false);
  423. // //监听系统通知栏消息点击事件
  424. // plus.push.addEventListener('click', function(msg) {
  425. // //处理点击消息的业务逻辑代码
  426. // if (msg.content && msg.content.contains("任务")) {
  427. // uni.navigateTo({
  428. // url: '/pages/task/my_task'
  429. // })
  430. // } else if (msg.content && (msg.content.contains("合同") || msg.content.contains("交易"))) {
  431. // uni.navigateTo({
  432. // url: '/pageB/contract/contract'
  433. // })
  434. // }
  435. // }, false);
  436. // #endif
  437. // this.$socket.initWebIM(this.$ws, true, true)
  438. let userInfo = uni.getStorageSync('userInfo') || '';
  439. if (userInfo.id) {
  440. //更新登陆状态
  441. uni.getStorage({
  442. key: 'userInfo',
  443. success: (res) => {
  444. this.login(res.data);
  445. }
  446. });
  447. }
  448. },
  449. onShow: function() {
  450. console.log('App Show')
  451. },
  452. onHide: function() {
  453. console.log('App Hide')
  454. },
  455. }
  456. </script>
  457. <style>
  458. /*每个页面公共css */
  459. </style>