App.vue 19 KB

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