App.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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:'#F5BA3C'
  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: '#F5BA3C'
  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]
  302. .sendAdCode //起点位置行政区划代码,调 用 start/stop/pause/restart 时 必填,调用 send 非必填
  303. this.shippingNoteInfos[0].endCountrySubdivisionCode = res1.data[0]
  304. .unsendAdCode //到达位置行政区划代码,调 用 start/stop/pause/restart 时 必填,调用 send 非必填
  305. this.shippingNoteInfos[0].startLongitude = res1.data[0]
  306. .sendLongitude //起点位置经度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  307. this.shippingNoteInfos[0].startLatitude = res1.data[0]
  308. .sendLatitude //起点位置纬度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  309. this.shippingNoteInfos[0].endLongitude = res1.data[0]
  310. .unsendLongitude //到达位置经度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  311. this.shippingNoteInfos[0].endLatitude = res1.data[0]
  312. .unsendLatitude //到达位置纬度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  313. this.shippingNoteInfos[0].driverName = res1.data[0]
  314. .driverName //司机姓名,SDK 回调返回, 调用 start/stop/pause/restart/ 必填,send 时非必填
  315. this.shippingNoteInfos[0].vehicleNumber = res1.data[0]
  316. .carNumber //车牌号,SDK 回调返回,调 用 start/stop/pause/restart/必 填,send 时非必填
  317. this.shippingNoteInfos[0].startLocationText = res1.data[0]
  318. .sendCity //起点地址文字描述,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  319. this.shippingNoteInfos[0].endLocationText = res1.data[0]
  320. .unloadCity //到达地址文字描述,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  321. this.shippingNoteInfos[0].interval = "5000"
  322. console.log("查看参数", this.shippingNoteInfos)
  323. that.auth()
  324. //判断有没有定位权限 有权限 定位 没权限不操作
  325. let system = uni.getSystemInfoSync(); // 获取系统信息
  326. if (system.platform === 'android') { // 判断平台
  327. var context = plus.android.importClass("android.content.Context");
  328. var locationManager = plus.android.importClass("android.location.LocationManager");
  329. var main = plus.android.runtimeMainActivity();
  330. var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  331. if (mainSvr) {
  332. that.$helper.fUN_AmapLocation.start({
  333. intervalTime: 60000,
  334. isReport: false
  335. },
  336. res => {
  337. that.id = res1.data[0].id
  338. let _data = {
  339. orderId: res1.data[0].id,
  340. longitude: res.longitude,
  341. latitude: res.latitude,
  342. province: res.province,
  343. city: res.city,
  344. area: res.district
  345. }
  346. this.$helper.gjList.push(_data)
  347. uni.setStorageSync('mapGJ', this.$helper.gjList);
  348. if (uni.getStorageSync('mapGJ').length > 10) {
  349. this.$request.baseRequest('post',
  350. '/hyOrderTravelPath/api/addInfo', {
  351. orderId: that.id,
  352. // orderId: "cdae6ec34c2349768c490a9fefa03fb3",
  353. longitudeLatitude: JSON.stringify(uni
  354. .getStorageSync(
  355. 'mapGJ'))
  356. }).then(res => {
  357. uni.removeStorageSync('mapGJ');
  358. this.$helper.gjList = []
  359. })
  360. .catch(res => {
  361. uni.$u.toast(res.message);
  362. });
  363. }
  364. }
  365. );
  366. }
  367. } else if (system.platform === 'ios') {
  368. // console.log("苹果");
  369. var cllocationManger = plus.ios.import("CLLocationManager");
  370. var enable = cllocationManger.locationServicesEnabled();
  371. var status = cllocationManger.authorizationStatus();
  372. plus.ios.deleteObject(cllocationManger);
  373. if (enable && status != 2) {
  374. that.$helper.fUN_AmapLocation.start({
  375. intervalTime: 60000,
  376. isReport: false
  377. },
  378. res => {
  379. that.id = res1.data[0].id
  380. let _data = {
  381. orderId: res1.data[0].id,
  382. longitude: res.longitude,
  383. latitude: res.latitude,
  384. province: res.province,
  385. city: res.city,
  386. area: res.district
  387. }
  388. this.$helper.gjList.push(_data)
  389. uni.setStorageSync('mapGJ', this.$helper.gjList);
  390. if (uni.getStorageSync('mapGJ').length > 10) {
  391. this.$request.baseRequest('post',
  392. '/hyOrderTravelPath/api/addInfo', {
  393. orderId: that.id,
  394. longitudeLatitude: JSON.stringify(uni
  395. .getStorageSync(
  396. 'mapGJ'))
  397. }).then(res => {
  398. uni.removeStorageSync('mapGJ');
  399. this.$helper.gjList = []
  400. })
  401. .catch(res => {
  402. uni.$u.toast(res.message);
  403. });
  404. }
  405. }
  406. );
  407. }
  408. }
  409. }
  410. })
  411. }
  412. let type = uni.getSystemInfoSync().platform
  413. if (type == "android") {
  414. // appUpdate()
  415. APPUpdate()
  416. }
  417. // plus.push.getClientInfoAsync((info) => {
  418. // var name = 'clientId'
  419. // var value = info.clientid
  420. // that.$store.commit('$uStore', {
  421. // name,
  422. // value
  423. // });
  424. // uni.setStorageSync("clientId", info.clientid)
  425. // console.log("info.clientid", info.clientid)
  426. // }, err => {});
  427. // 监听在线消息事件
  428. // plus.push.addEventListener("receive", function(msg) {
  429. // var title = msg.content.split(':')[0]
  430. // var content = msg.content.split(':')[1]
  431. // let params = {
  432. // inApp: true, // app内横幅提醒
  433. // voice: true, // 声音提醒
  434. // vibration: true, // 振动提醒
  435. // messageType: "",
  436. // messageTitle: title,
  437. // messageContent: content,
  438. // messageImage: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/logo.png'
  439. // }
  440. // console.log("msg", msg)
  441. // new app_push({
  442. // ...params
  443. // }).show();
  444. // var userInfo = uni.getStorageSync("userInfo")
  445. // var that = this
  446. // that.$request.baseRequest('get', '/notice/query/noticeNumber').then(res => {
  447. // if (res.data.data) {
  448. // let name = 'myTip';
  449. // let value = res.data.data.task;
  450. // that.$store.commit('$uStore', {
  451. // name,
  452. // value
  453. // });
  454. // if (value != 0 && value) {
  455. // uni.setTabBarBadge({
  456. // index: 4,
  457. // text: value + ""
  458. // })
  459. // }
  460. // name = 'taskTip';
  461. // value = res.data.data.task;
  462. // that.$store.commit('$uStore', {
  463. // name,
  464. // value
  465. // });
  466. // // name = 'contractTip';
  467. // // value = res.data.data.contractTip;
  468. // // that.$store.commit('$uStore', {
  469. // // name,
  470. // // value
  471. // // });
  472. // }
  473. // })
  474. // //其它逻辑
  475. // }, false);
  476. // //监听系统通知栏消息点击事件
  477. // plus.push.addEventListener('click', function(msg) {
  478. // //处理点击消息的业务逻辑代码
  479. // if (msg.content && msg.content.contains("任务")) {
  480. // uni.navigateTo({
  481. // url: '/pages/task/my_task'
  482. // })
  483. // } else if (msg.content && (msg.content.contains("合同") || msg.content.contains("交易"))) {
  484. // uni.navigateTo({
  485. // url: '/pageB/contract/contract'
  486. // })
  487. // }
  488. // }, false);
  489. // #endif
  490. // this.$socket.initWebIM(this.$ws, true, true)
  491. let userInfo = uni.getStorageSync('userInfo') || '';
  492. if (userInfo.id) {
  493. //更新登陆状态
  494. uni.getStorage({
  495. key: 'userInfo',
  496. success: (res) => {
  497. this.login(res.data);
  498. }
  499. });
  500. }
  501. },
  502. onShow: function() {
  503. console.log('App Show')
  504. // #ifdef APP-PLUS
  505. var isContains = true;//隐私权政策是否包含高德开平隐私权政策 true是包含
  506. var isShow = true;//隐私权政策是否弹窗展示告知用户 true是展示
  507. sdkwx.updatePrivacyShow(isContains, isShow);
  508. var isAgree = true;//隐私权政策是否取得用户同意 true是用户同意
  509. sdkwx.updatePrivacyAgree(isAgree);
  510. //检查定位权限
  511. sdkwx.checkLocationPermission(function(res){
  512. console.log(res);
  513. });
  514. getCurrentNo(res => {
  515. // 进页面获取当前APP版本号(用于页面显示)
  516. this.version = res.versionName;
  517. });
  518. // #endif
  519. },
  520. onHide: function() {
  521. console.log('App Hide')
  522. },
  523. }
  524. </script>
  525. <style>
  526. /* .uni-input-input{
  527. filter: blur(4px);
  528. }
  529. uni-image{
  530. filter: blur(4px);
  531. } */
  532. /*每个页面公共css */
  533. </style>