App.vue 18 KB

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