App.vue 18 KB

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