App.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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. // #ifdef APP-PLUS
  14. // import APPUpdate from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
  15. import APPUpdate, {
  16. getCurrentNo
  17. } from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
  18. // #endif
  19. import app_push from './components/APPPush/app_push.js'
  20. import permision from "@/js_sdk/wa-permission/permission.js"
  21. //插件对象
  22. var sdkwx = uni.requireNativePlugin('Hdgq-LocSdkWX');
  23. export default {
  24. data() {
  25. return {
  26. shippingNoteInfos: [{
  27. shippingNoteNumber: '',
  28. serialNumber: "",
  29. startCountrySubdivisionCode: "",
  30. endCountrySubdivisionCode: "",
  31. startLongitude: "",
  32. startLatitude: "",
  33. endLongitude: "",
  34. endLatitude: "",
  35. startLocationText: "",
  36. endLocationText: "",
  37. vehicleNumber: "",
  38. driverName: "",
  39. interval: "",
  40. }],
  41. //网络货运信息定位
  42. appId: "", //网络货运企业APP的唯一标识
  43. appSecurity: "", //网络货运企业在省平台申请的接入安全码
  44. enterpriseSenderCode: "", //网络货运企业在省平台申请的企业发送代码
  45. environment: "", //环境:“debug”接入测试环境,“release”接入正式环境。
  46. version: "" // 版本号
  47. }
  48. },
  49. methods: {
  50. ...mapMutations(['login', "firstAuthentication"]),
  51. // 检查APP是否有新版本
  52. onAPPUpdate() {
  53. // true 没有新版本的时候有提示,默认:false
  54. APPUpdate(true);
  55. },
  56. // vue的method里编写如下代码
  57. // async requestAndroidPermission(permisionID) {
  58. // var result = await permision.requestAndroidPermission(permisionID)
  59. // var strStatus
  60. // if (result == 1) {
  61. // strStatus = "已获得授权"
  62. // } else if (result == 0) {
  63. // strStatus = "未获得授权"
  64. // // permision.gotoAppPermissionSetting()
  65. // // 引导设置,判断是否有运输中订单,有订单,必须授权
  66. // } else {
  67. // strStatus = "被永久拒绝权限"
  68. // // permision.gotoAppPermissionSetting()
  69. // }
  70. // },
  71. restart() { //开启定位
  72. var remark = "测试"; //备注
  73. let that = this
  74. sdkwx.restart(this.shippingNoteInfos[0].vehicleNumber, this.shippingNoteInfos[0].driverName, remark, this
  75. .shippingNoteInfos,
  76. function(res) {
  77. if (res.type == "onSuccess") {
  78. //成功
  79. console.log("开启定位成功!!!")
  80. console.log(res)
  81. var shippingNoteInfos = res.data[0]; //运单信息列表
  82. console.log(shippingNoteInfos, "sdassss")
  83. if (shippingNoteInfos) {
  84. that.send()
  85. let dateTtime = Number(shippingNoteInfos.interval + 60000)
  86. console.log("开始定时", dateTtime)
  87. that.timer = setTimeout(() => {
  88. console.log("定时")
  89. that.send()
  90. }, dateTtime);
  91. }
  92. } else if (res.type == "onFailure") {
  93. //失败
  94. console.log("开启定位失败!!!")
  95. console.log(res)
  96. var errorCode = res.data.errorCode; //错误码
  97. var errorMsg = res.data.errorMsg; //错误描述
  98. that.timer = setTimeout(() => { //失败也需要定时发送定位
  99. console.log("定时")
  100. that.send()
  101. }, 915204); //15分钟
  102. }
  103. });
  104. },
  105. send() { //发送定位
  106. var remark = ""
  107. var that = this
  108. console.log("send参数", this.shippingNoteInfos)
  109. sdkwx.send(this.shippingNoteInfos[0].vehicleNumber, this.shippingNoteInfos[0].driverName, remark, this
  110. .shippingNoteInfos,
  111. function(res) {
  112. if (res.type == "onSuccess") {
  113. console.log("App.vue发送定位成功")
  114. console.log(res);
  115. var shippingNoteInfos = res.data[0]; //运单信息列表
  116. if (shippingNoteInfos) {
  117. let dateTime = Number(shippingNoteInfos.interval + 1000)
  118. console.log("定时开始", dateTime)
  119. that.timer = setTimeout(() => {
  120. //TODO
  121. that.send()
  122. }, dateTime);
  123. }
  124. } else if (res.type == "onFailure") {
  125. console.log("App.vue发送定位失败", res)
  126. //失败
  127. var errorCode = res.data.errorCode; //错误码
  128. var errorMsg = res.data.errorMsg; //错误描述
  129. console.log("定时开始", "915204")
  130. that.timer = setTimeout(() => { //失败也需要定时上传定位(为了解决频繁调用接口问题)
  131. that.send()
  132. }, 915204);
  133. }
  134. });
  135. },
  136. auth() { //授权
  137. let phoneType = uni.getSystemInfoSync().platform //判断手机类型
  138. this.enterpriseSenderCode = config.def().enterpriseSenderCode
  139. this.environment = config.def().environment
  140. if (phoneType == "android") {
  141. this.appId = config.def().androidAppId
  142. this.appSecurity = config.def().androidAppSecurity
  143. } else if (phoneType == "ios") {
  144. // this.appId = "uni.UNIDCD13AC"
  145. // this.appSecurity = "b01e4805276646eeb25f0fad91de97a4f32e8c2c0e0d42e5b24cc4737e9f040f"
  146. this.appId = config.def().iosAppId
  147. this.appSecurity = config.def().iosAppSecurity
  148. }
  149. let that = this
  150. sdkwx.auth(this.appId, this.appSecurity, this.enterpriseSenderCode, this.environment, function(res) {
  151. if (res.type == "onSuccess") {
  152. //成功
  153. that.restart()
  154. console.log("授权成功")
  155. console.log(res)
  156. } else if (res.type == "onFailure") {
  157. //失败
  158. var errorCode = res.data.errorCode; //错误码
  159. var errorMsg = res.data.errorMsg; //错误描述
  160. console.log("授权失败")
  161. console.log(res)
  162. }
  163. });
  164. },
  165. },
  166. onLaunch: function() {
  167. console.log("onlaunch")
  168. var that = this
  169. // #ifdef APP-PLUS
  170. // APPUpdate();
  171. // this.$tabbarView.init()
  172. // uni.getNetworkType({
  173. // success: function (res) {
  174. // if(res.networkType=='none'){
  175. // let options = {
  176. // title: '提示',
  177. // info:'当前没有网络中',
  178. // okText: '连接Wifi',
  179. // cancelText:'开启流量',
  180. // infoAlignment:'center',
  181. // radius:10,
  182. // // cancelText: '否',
  183. // // showCancel:false,
  184. // okButtonColor:'#2772FB'
  185. // };
  186. // const native = uni.requireNativePlugin('AJ-Alert');
  187. // native.showAction(options, result => {
  188. // // #ifdef APP-PLUS
  189. // if (uni.getSystemInfoSync().platform == 'ios') {
  190. // plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
  191. // } else if (uni.getSystemInfoSync().platform == 'android') {
  192. // plus.runtime.quit();
  193. // }
  194. // // #endif
  195. // // 点击是的回调, result暂时没有返回内容
  196. // }, cancel => {
  197. // // 点击否的回调
  198. // });
  199. // }
  200. // console.log(res.networkType);
  201. // }
  202. // });
  203. uni.getSystemInfo({
  204. success(res) {
  205. uni.setStorageSync('phoneType', res)
  206. }
  207. });
  208. console.log(uni.getStorageSync('userInfo'))
  209. if (uni.getStorageSync('userInfo')) {
  210. that.$request.baseRequest('get', '/driverInfo/firstAuthentication', {
  211. driverPhone: uni.getStorageSync('userInfo').phone,
  212. }).then(res => {
  213. if (res.data.authenticationStatus == '已禁用') {
  214. // this.isShowAlert = true
  215. // this.alertTitle = '账号审核中'
  216. // this.confirmText = '退出APP'
  217. // this.showCancelButton = false
  218. let options = {
  219. title: '提示',
  220. info: '账号审核中',
  221. okText: '退出程序',
  222. infoAlignment: 'center',
  223. radius: 10,
  224. // cancelText: '否',
  225. showCancel: false,
  226. okButtonColor: '#2772FB'
  227. };
  228. const native = uni.requireNativePlugin('AJ-Alert');
  229. native.showAction(options, result => {
  230. // #ifdef APP-PLUS
  231. if (uni.getSystemInfoSync().platform == 'ios') {
  232. plus.ios.import("UIApplication").sharedApplication().performSelector(
  233. "exit")
  234. } else if (uni.getSystemInfoSync().platform == 'android') {
  235. plus.runtime.quit();
  236. }
  237. // #endif
  238. // 点击是的回调, result暂时没有返回内容
  239. }, cancel => {
  240. // 点击否的回调
  241. });
  242. // uni.showModal({
  243. // title: '提示',
  244. // content: '这是一个模态弹窗',
  245. // showCancel:false,
  246. // confirmText:'退出app',
  247. // // confirmColor:'#317AFE',
  248. // confirmColor:'#F54E40',
  249. // success: function (res) {
  250. // if (res.confirm) {
  251. // // #ifdef APP-PLUS
  252. // if (uni.getSystemInfoSync().platform == 'ios') {
  253. // plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
  254. // } else if (uni.getSystemInfoSync().platform == 'android') {
  255. // plus.runtime.quit();
  256. // }
  257. // // #endif
  258. // } else if (res.cancel) {
  259. // console.log('用户点击取消');
  260. // }
  261. // }
  262. // });
  263. } else {
  264. console.log(1231233212332312312213)
  265. }
  266. })
  267. }
  268. // #endif
  269. uni.setStorageSync("region", region);
  270. uni.getSystemInfo({
  271. success: function(e) {
  272. Vue.prototype.statusBar = e.statusBarHeight
  273. // #ifndef MP
  274. if (e.platform == 'android') {
  275. Vue.prototype.customBar = e.statusBarHeight + 50
  276. } else {
  277. Vue.prototype.customBar = e.statusBarHeight + 45
  278. }
  279. // #endif
  280. // #ifdef MP-WEIXIN
  281. let custom = wx.getMenuButtonBoundingClientRect()
  282. Vue.prototype.customBar = custom.bottom + custom.top - e.statusBarHeight
  283. // #endif
  284. // #ifdef MP-ALIPAY
  285. Vue.prototype.customBar = e.statusBarHeight + e.titleBarHeight
  286. // #endif
  287. }
  288. })
  289. // #ifdef APP-PLUS
  290. var that = this
  291. //判断该用户是否需要开启持续定位
  292. if (uni.getStorageSync('userInfo')) {
  293. this.$request.baseRequest('get', '/orderInfo/getData', {
  294. commonId: uni.getStorageSync('userInfo').id,
  295. }).then(res1 => {
  296. console.log("/orderInfo/getData 查看该用户有多少订单", res1.data)
  297. if (res1.data.length > 0) {
  298. this.shippingNoteInfos[0].shippingNoteNumber = res1.data[0].orderNo //运单号
  299. this.shippingNoteInfos[0].serialNumber = "0000" //分单号
  300. this.shippingNoteInfos[0].startCountrySubdivisionCode = res1.data[0].sendAdCode //起点位置行政区划代码,调 用 start/stop/pause/restart 时 必填,调用 send 非必填
  301. this.shippingNoteInfos[0].endCountrySubdivisionCode = res1.data[0].unsendAdCode //到达位置行政区划代码,调 用 start/stop/pause/restart 时 必填,调用 send 非必填
  302. this.shippingNoteInfos[0].startLongitude = res1.data[0].sendLongitude //起点位置经度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  303. this.shippingNoteInfos[0].startLatitude = res1.data[0].sendLatitude //起点位置纬度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  304. this.shippingNoteInfos[0].endLongitude = res1.data[0].unsendLongitude //到达位置经度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  305. this.shippingNoteInfos[0].endLatitude = res1.data[0].unsendLatitude //到达位置纬度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  306. this.shippingNoteInfos[0].driverName = res1.data[0].driverName //司机姓名,SDK 回调返回, 调用 start/stop/pause/restart/ 必填,send 时非必填
  307. this.shippingNoteInfos[0].vehicleNumber = res1.data[0].carNumber //车牌号,SDK 回调返回,调 用 start/stop/pause/restart/必 填,send 时非必填
  308. this.shippingNoteInfos[0].startLocationText = res1.data[0].sendCity //起点地址文字描述,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  309. this.shippingNoteInfos[0].endLocationText = res1.data[0].unloadCity //到达地址文字描述,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  310. this.shippingNoteInfos[0].interval = "5000"
  311. console.log("查看参数", this.shippingNoteInfos)
  312. // that.auth()
  313. that.$helper.fUN_AmapLocation.start({
  314. // intervalTime: 1000 * 60,
  315. intervalTime: 5000,
  316. // locationCacheEnable:true,
  317. isReport: false
  318. // url: 'http://192.168.0.66/fun/open/test_json.do',
  319. // params: {
  320. // a: 1,
  321. // B: '测试',
  322. // c: true
  323. // },
  324. // headers: {
  325. // a: '123',
  326. // B: 'abcd'
  327. // }
  328. },
  329. res => {
  330. // console.log('====确认装车开启连续定位====');
  331. // console.log(res)
  332. let _data = {
  333. orderId: res1.data[0].id,
  334. longitude: res.longitude,
  335. latitude: res.latitude,
  336. province: res.province,
  337. city: res.city,
  338. area: res.district
  339. }
  340. this.$helper.gjList.push(_data)
  341. uni.setStorageSync('mapGJ', this.$helper.gjList);
  342. // console.log('this.$helper.gjList')
  343. // console.log(this.$helper.gjList)
  344. // console.log("条数", uni.getStorageSync('mapGJ').length)
  345. if (uni.getStorageSync('mapGJ').length > 100) {
  346. // console.log(JSON.stringify(uni.getStorageSync('mapGJ')))
  347. this.$request.baseRequest('post', '/hyOrderTravelPath/api/addInfo', {
  348. orderId: "cdae6ec34c2349768c490a9fefa03fb3",
  349. longitudeLatitude: JSON.stringify(uni.getStorageSync(
  350. 'mapGJ'))
  351. }).then(res => {
  352. uni.removeStorageSync('mapGJ');
  353. this.$helper.gjList = []
  354. })
  355. .catch(res => {
  356. uni.$u.toast(res.message);
  357. });
  358. }
  359. //判断缓存数据条数,超过reportInterval时清空缓存,重新存入缓存
  360. }
  361. );
  362. }
  363. })
  364. }
  365. // this.$helper.fUN_AmapLocation.stop({}, result => {
  366. // console.log('====fUN_AmapLocation定位stop====', JSON.stringify(result));
  367. // this.$helper.fUN_AmapLocation.start(
  368. // {
  369. // intervalTime: 1000*60,
  370. // isReport: true,
  371. // reportInterval: 5,
  372. // url: 'http://192.168.0.66/fun/open/test_json.do',
  373. // params: { a: 1, B: '测试', c: true },
  374. // headers: { a: '123', B: 'abcd' }
  375. // },
  376. // res => {
  377. // //见下方定位返回示例
  378. // console.log('====确认装车开启连续定位====', JSON.stringify(res));
  379. // //判断缓存数据条数,超过reportInterval时清空缓存,重新存入缓存
  380. // }
  381. // );
  382. // });
  383. // fUN_AmapLocation.permission({}, result => {
  384. // console.log('====fUN_AmapLocation定位====');
  385. // });
  386. // fUN_AmapLocation.hasLocationPermissions(function(result) {
  387. // console.log('====fUN_AmapLocation定位权限===='+ result)
  388. // });
  389. // startLocation与start均可
  390. // this.$helper.fUN_AmapLocation.start(
  391. // {
  392. // intervalTime: 1000*10,
  393. // isReport: false,
  394. // },
  395. // result => {
  396. // //见下方定位返回示例
  397. // console.log('====fUN_AmapLocation定位====', JSON.stringify(result));
  398. // }
  399. // );
  400. // let isOpenLocation= permision.checkSystemEnableLocation()
  401. // console.log("isOpenLocation",isOpenLocation)
  402. // this.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
  403. let type = uni.getSystemInfoSync().platform
  404. if (type == "android") {
  405. // appUpdate()
  406. APPUpdate()
  407. }
  408. // plus.push.getClientInfoAsync((info) => {
  409. // var name = 'clientId'
  410. // var value = info.clientid
  411. // that.$store.commit('$uStore', {
  412. // name,
  413. // value
  414. // });
  415. // uni.setStorageSync("clientId", info.clientid)
  416. // console.log("info.clientid", info.clientid)
  417. // }, err => {});
  418. // 监听在线消息事件
  419. // plus.push.addEventListener("receive", function(msg) {
  420. // var title = msg.content.split(':')[0]
  421. // var content = msg.content.split(':')[1]
  422. // let params = {
  423. // inApp: true, // app内横幅提醒
  424. // voice: true, // 声音提醒
  425. // vibration: true, // 振动提醒
  426. // messageType: "",
  427. // messageTitle: title,
  428. // messageContent: content,
  429. // messageImage: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/logo.png'
  430. // }
  431. // console.log("msg", msg)
  432. // new app_push({
  433. // ...params
  434. // }).show();
  435. // var userInfo = uni.getStorageSync("userInfo")
  436. // var that = this
  437. // that.$request.baseRequest('get', '/notice/query/noticeNumber').then(res => {
  438. // if (res.data.data) {
  439. // let name = 'myTip';
  440. // let value = res.data.data.task;
  441. // that.$store.commit('$uStore', {
  442. // name,
  443. // value
  444. // });
  445. // if (value != 0 && value) {
  446. // uni.setTabBarBadge({
  447. // index: 4,
  448. // text: value + ""
  449. // })
  450. // }
  451. // name = 'taskTip';
  452. // value = res.data.data.task;
  453. // that.$store.commit('$uStore', {
  454. // name,
  455. // value
  456. // });
  457. // // name = 'contractTip';
  458. // // value = res.data.data.contractTip;
  459. // // that.$store.commit('$uStore', {
  460. // // name,
  461. // // value
  462. // // });
  463. // }
  464. // })
  465. // //其它逻辑
  466. // }, false);
  467. // //监听系统通知栏消息点击事件
  468. // plus.push.addEventListener('click', function(msg) {
  469. // //处理点击消息的业务逻辑代码
  470. // if (msg.content && msg.content.contains("任务")) {
  471. // uni.navigateTo({
  472. // url: '/pages/task/my_task'
  473. // })
  474. // } else if (msg.content && (msg.content.contains("合同") || msg.content.contains("交易"))) {
  475. // uni.navigateTo({
  476. // url: '/pageB/contract/contract'
  477. // })
  478. // }
  479. // }, false);
  480. // #endif
  481. // this.$socket.initWebIM(this.$ws, true, true)
  482. let userInfo = uni.getStorageSync('userInfo') || '';
  483. if (userInfo.id) {
  484. //更新登陆状态
  485. uni.getStorage({
  486. key: 'userInfo',
  487. success: (res) => {
  488. this.login(res.data);
  489. }
  490. });
  491. }
  492. },
  493. onShow: function() {
  494. console.log('App Show')
  495. // #ifdef APP-PLUS
  496. // var isContains = true;//隐私权政策是否包含高德开平隐私权政策 true是包含
  497. // var isShow = true;//隐私权政策是否弹窗展示告知用户 true是展示
  498. // sdkwx.updatePrivacyShow(isContains, isShow);
  499. // var isAgree = true;//隐私权政策是否取得用户同意 true是用户同意
  500. // sdkwx.updatePrivacyAgree(isAgree);
  501. // //检查定位权限
  502. // sdkwx.checkLocationPermission(function(res){
  503. // console.log(res);
  504. // });
  505. getCurrentNo(res => {
  506. // 进页面获取当前APP版本号(用于页面显示)
  507. this.version = res.versionName;
  508. });
  509. // #endif
  510. },
  511. onHide: function() {
  512. console.log('App Hide')
  513. },
  514. }
  515. </script>
  516. <style>
  517. /*每个页面公共css */
  518. </style>