App.vue 17 KB

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