123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546 |
- <style lang="scss">
- /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
- @import "@/uni_modules/uview-ui/index.scss";
- @import 'static/css/common.scss';
- </style>
- <script>
- import region from "@/components/region/data";
- import {
- mapMutations
- } from 'vuex';
- import * as config from '@/config'
- // import appUpdate from 'common/appUpdate.js'
- // #ifdef APP-PLUS
- // import APPUpdate from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
- import APPUpdate, {
- getCurrentNo
- } from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
- // #endif
- import app_push from './components/APPPush/app_push.js'
- import permision from "@/js_sdk/wa-permission/permission.js"
- //插件对象
- var sdkwx = uni.requireNativePlugin('Hdgq-LocSdkWX');
- export default {
- data() {
- return {
- shippingNoteInfos: [{
- shippingNoteNumber: '',
- serialNumber: "",
- startCountrySubdivisionCode: "",
- endCountrySubdivisionCode: "",
- startLongitude: "",
- startLatitude: "",
- endLongitude: "",
- endLatitude: "",
- startLocationText: "",
- endLocationText: "",
- vehicleNumber: "",
- driverName: "",
- interval: "",
- }],
- //网络货运信息定位
- appId: "", //网络货运企业APP的唯一标识
- appSecurity: "", //网络货运企业在省平台申请的接入安全码
- enterpriseSenderCode: "", //网络货运企业在省平台申请的企业发送代码
- environment: "", //环境:“debug”接入测试环境,“release”接入正式环境。
- version: "", // 版本号
- id: ""
- }
- },
- methods: {
- ...mapMutations(['login', "firstAuthentication"]),
- // 检查APP是否有新版本
- onAPPUpdate() {
- // true 没有新版本的时候有提示,默认:false
- APPUpdate(true);
- },
- // vue的method里编写如下代码
- // async requestAndroidPermission(permisionID) {
- // var result = await permision.requestAndroidPermission(permisionID)
- // var strStatus
- // if (result == 1) {
- // strStatus = "已获得授权"
- // } else if (result == 0) {
- // strStatus = "未获得授权"
- // // permision.gotoAppPermissionSetting()
- // // 引导设置,判断是否有运输中订单,有订单,必须授权
- // } else {
- // strStatus = "被永久拒绝权限"
- // // permision.gotoAppPermissionSetting()
- // }
- // },
- restart() { //开启定位
- var remark = "测试"; //备注
- let that = this
- sdkwx.restart(this.shippingNoteInfos[0].vehicleNumber, this.shippingNoteInfos[0].driverName, remark, this
- .shippingNoteInfos,
- function(res) {
- if (res.type == "onSuccess") {
- //成功
- console.log("开启定位成功!!!")
- console.log(res)
- var shippingNoteInfos = res.data[0]; //运单信息列表
- console.log(shippingNoteInfos, "sdassss")
- if (shippingNoteInfos) {
- that.send()
- let dateTtime = Number(shippingNoteInfos.interval + 60000)
- console.log("开始定时", dateTtime)
- that.timer = setTimeout(() => {
- console.log("定时")
- that.send()
- }, dateTtime);
- }
- } else if (res.type == "onFailure") {
- //失败
- console.log("开启定位失败!!!")
- console.log(res)
- var errorCode = res.data.errorCode; //错误码
- var errorMsg = res.data.errorMsg; //错误描述
- that.timer = setTimeout(() => { //失败也需要定时发送定位
- console.log("定时")
- that.send()
- }, 915204); //15分钟
- }
- });
- },
- send() { //发送定位
- var remark = ""
- var that = this
- console.log("send参数", this.shippingNoteInfos)
- sdkwx.send(this.shippingNoteInfos[0].vehicleNumber, this.shippingNoteInfos[0].driverName, remark, this
- .shippingNoteInfos,
- function(res) {
- if (res.type == "onSuccess") {
- console.log("App.vue发送定位成功")
- console.log(res);
- var shippingNoteInfos = res.data[0]; //运单信息列表
- if (shippingNoteInfos) {
- let dateTime = Number(shippingNoteInfos.interval + 1000)
- console.log("定时开始", dateTime)
- that.timer = setTimeout(() => {
- //TODO
- that.send()
- }, dateTime);
- }
- } else if (res.type == "onFailure") {
- console.log("App.vue发送定位失败", res)
- //失败
- var errorCode = res.data.errorCode; //错误码
- var errorMsg = res.data.errorMsg; //错误描述
- console.log("定时开始", "915204")
- that.timer = setTimeout(() => { //失败也需要定时上传定位(为了解决频繁调用接口问题)
- that.send()
- }, 915204);
- }
- });
- },
- auth() { //授权
- let phoneType = uni.getSystemInfoSync().platform //判断手机类型
- this.enterpriseSenderCode = config.def().enterpriseSenderCode
- this.environment = config.def().environment
- if (phoneType == "android") {
- this.appId = config.def().androidAppId
- this.appSecurity = config.def().androidAppSecurity
- } else if (phoneType == "ios") {
- // this.appId = "uni.UNIDCD13AC"
- // this.appSecurity = "b01e4805276646eeb25f0fad91de97a4f32e8c2c0e0d42e5b24cc4737e9f040f"
- this.appId = config.def().iosAppId
- this.appSecurity = config.def().iosAppSecurity
- }
- let that = this
- sdkwx.auth(this.appId, this.appSecurity, this.enterpriseSenderCode, this.environment, function(res) {
- if (res.type == "onSuccess") {
- //成功
- that.restart()
- console.log("授权成功")
- console.log(res)
- } else if (res.type == "onFailure") {
- //失败
- var errorCode = res.data.errorCode; //错误码
- var errorMsg = res.data.errorMsg; //错误描述
- console.log("授权失败")
- console.log(res)
- }
- });
- },
- },
- onLaunch: function() {
- console.log("onlaunch")
- var that = this
- // #ifdef APP-PLUS
- // APPUpdate();
- // this.$tabbarView.init()
- // uni.getNetworkType({
- // success: function (res) {
- // if(res.networkType=='none'){
- // let options = {
- // title: '提示',
- // info:'当前没有网络中',
- // okText: '连接Wifi',
- // cancelText:'开启流量',
- // infoAlignment:'center',
- // radius:10,
- // // cancelText: '否',
- // // showCancel:false,
- // okButtonColor:'#2772FB'
- // };
- // const native = uni.requireNativePlugin('AJ-Alert');
- // native.showAction(options, result => {
- // // #ifdef APP-PLUS
- // if (uni.getSystemInfoSync().platform == 'ios') {
- // plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
- // } else if (uni.getSystemInfoSync().platform == 'android') {
- // plus.runtime.quit();
- // }
- // // #endif
- // // 点击是的回调, result暂时没有返回内容
- // }, cancel => {
- // // 点击否的回调
- // });
- // }
- // console.log(res.networkType);
- // }
- // });
- uni.getSystemInfo({
- success(res) {
- uni.setStorageSync('phoneType', res)
- }
- });
- console.log(uni.getStorageSync('userInfo'))
- if (uni.getStorageSync('userInfo')) {
- that.$request.baseRequest('get', '/driverInfo/firstAuthentication', {
- driverPhone: uni.getStorageSync('userInfo').phone,
- }).then(res => {
- if (res.data.authenticationStatus == '已禁用') {
- // this.isShowAlert = true
- // this.alertTitle = '账号审核中'
- // this.confirmText = '退出APP'
- // this.showCancelButton = false
- let options = {
- title: '提示',
- info: '账号审核中',
- okText: '退出程序',
- infoAlignment: 'center',
- radius: 10,
- // cancelText: '否',
- showCancel: false,
- okButtonColor: '#2772FB'
- };
- const native = uni.requireNativePlugin('AJ-Alert');
- native.showAction(options, result => {
- // #ifdef APP-PLUS
- if (uni.getSystemInfoSync().platform == 'ios') {
- plus.ios.import("UIApplication").sharedApplication().performSelector(
- "exit")
- } else if (uni.getSystemInfoSync().platform == 'android') {
- plus.runtime.quit();
- }
- // #endif
- // 点击是的回调, result暂时没有返回内容
- }, cancel => {
- // 点击否的回调
- });
- // uni.showModal({
- // title: '提示',
- // content: '这是一个模态弹窗',
- // showCancel:false,
- // confirmText:'退出app',
- // // confirmColor:'#317AFE',
- // confirmColor:'#F54E40',
- // success: function (res) {
- // if (res.confirm) {
- // // #ifdef APP-PLUS
- // if (uni.getSystemInfoSync().platform == 'ios') {
- // plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
- // } else if (uni.getSystemInfoSync().platform == 'android') {
- // plus.runtime.quit();
- // }
- // // #endif
- // } else if (res.cancel) {
- // console.log('用户点击取消');
- // }
- // }
- // });
- } else {
- console.log(1231233212332312312213)
- }
- })
- }
- // #endif
- uni.setStorageSync("region", region);
- uni.getSystemInfo({
- success: function(e) {
- Vue.prototype.statusBar = e.statusBarHeight
- // #ifndef MP
- if (e.platform == 'android') {
- Vue.prototype.customBar = e.statusBarHeight + 50
- } else {
- Vue.prototype.customBar = e.statusBarHeight + 45
- }
- // #endif
- // #ifdef MP-WEIXIN
- let custom = wx.getMenuButtonBoundingClientRect()
- Vue.prototype.customBar = custom.bottom + custom.top - e.statusBarHeight
- // #endif
- // #ifdef MP-ALIPAY
- Vue.prototype.customBar = e.statusBarHeight + e.titleBarHeight
- // #endif
- }
- })
- // #ifdef APP-PLUS
- var that = this
- //判断该用户是否需要开启持续定位
- if (uni.getStorageSync('userInfo')) {
- this.$request.baseRequest('get', '/orderInfo/getData', {
- commonId: uni.getStorageSync('userInfo').id,
- }).then(res1 => {
- console.log("/orderInfo/getData 查看该用户有多少订单", res1.data)
- if (res1.data.length > 0) {
- this.shippingNoteInfos[0].shippingNoteNumber = res1.data[0].orderNo //运单号
- this.shippingNoteInfos[0].serialNumber = "0000" //分单号
- this.shippingNoteInfos[0].startCountrySubdivisionCode = res1.data[0]
- .sendAdCode //起点位置行政区划代码,调 用 start/stop/pause/restart 时 必填,调用 send 非必填
- this.shippingNoteInfos[0].endCountrySubdivisionCode = res1.data[0]
- .unsendAdCode //到达位置行政区划代码,调 用 start/stop/pause/restart 时 必填,调用 send 非必填
- this.shippingNoteInfos[0].startLongitude = res1.data[0]
- .sendLongitude //起点位置经度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
- this.shippingNoteInfos[0].startLatitude = res1.data[0]
- .sendLatitude //起点位置纬度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
- this.shippingNoteInfos[0].endLongitude = res1.data[0]
- .unsendLongitude //到达位置经度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
- this.shippingNoteInfos[0].endLatitude = res1.data[0]
- .unsendLatitude //到达位置纬度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
- this.shippingNoteInfos[0].driverName = res1.data[0]
- .driverName //司机姓名,SDK 回调返回, 调用 start/stop/pause/restart/ 必填,send 时非必填
- this.shippingNoteInfos[0].vehicleNumber = res1.data[0]
- .carNumber //车牌号,SDK 回调返回,调 用 start/stop/pause/restart/必 填,send 时非必填
- this.shippingNoteInfos[0].startLocationText = res1.data[0]
- .sendCity //起点地址文字描述,调用 start/stop/pause/restart 时必 填,调用 send 非必填
- this.shippingNoteInfos[0].endLocationText = res1.data[0]
- .unloadCity //到达地址文字描述,调用 start/stop/pause/restart 时必 填,调用 send 非必填
- this.shippingNoteInfos[0].interval = "5000"
- console.log("查看参数", this.shippingNoteInfos)
- // that.auth()
- //判断有没有定位权限 有权限 定位 没权限不操作
- let system = uni.getSystemInfoSync(); // 获取系统信息
- if (system.platform === 'android') { // 判断平台
- var context = plus.android.importClass("android.content.Context");
- var locationManager = plus.android.importClass("android.location.LocationManager");
- var main = plus.android.runtimeMainActivity();
- var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
- if (mainSvr) {
- that.$helper.fUN_AmapLocation.start({
- intervalTime: 60000,
- isReport: false
- },
- res => {
- that.id = res1.data[0].id
- let _data = {
- orderId: res1.data[0].id,
- longitude: res.longitude,
- latitude: res.latitude,
- province: res.province,
- city: res.city,
- area: res.district
- }
- this.$helper.gjList.push(_data)
- uni.setStorageSync('mapGJ', this.$helper.gjList);
- if (uni.getStorageSync('mapGJ').length > 10) {
- this.$request.baseRequest('post',
- '/hyOrderTravelPath/api/addInfo', {
- orderId: that.id,
- // orderId: "cdae6ec34c2349768c490a9fefa03fb3",
- longitudeLatitude: JSON.stringify(uni
- .getStorageSync(
- 'mapGJ'))
- }).then(res => {
- uni.removeStorageSync('mapGJ');
- this.$helper.gjList = []
- })
- .catch(res => {
- uni.$u.toast(res.message);
- });
- }
- }
- );
- }
- } else if (system.platform === 'ios') {
- // console.log("苹果");
- var cllocationManger = plus.ios.import("CLLocationManager");
- var enable = cllocationManger.locationServicesEnabled();
- var status = cllocationManger.authorizationStatus();
- plus.ios.deleteObject(cllocationManger);
- if (enable && status != 2) {
- that.$helper.fUN_AmapLocation.start({
- intervalTime: 60000,
- isReport: false
- },
- res => {
- that.id = res1.data[0].id
- let _data = {
- orderId: res1.data[0].id,
- longitude: res.longitude,
- latitude: res.latitude,
- province: res.province,
- city: res.city,
- area: res.district
- }
- this.$helper.gjList.push(_data)
- uni.setStorageSync('mapGJ', this.$helper.gjList);
- if (uni.getStorageSync('mapGJ').length > 100) {
- this.$request.baseRequest('post',
- '/hyOrderTravelPath/api/addInfo', {
- orderId: that.id,
- longitudeLatitude: JSON.stringify(uni
- .getStorageSync(
- 'mapGJ'))
- }).then(res => {
- uni.removeStorageSync('mapGJ');
- this.$helper.gjList = []
- })
- .catch(res => {
- uni.$u.toast(res.message);
- });
- }
- }
- );
- }
- }
- }
- })
- }
- let type = uni.getSystemInfoSync().platform
- if (type == "android") {
- // appUpdate()
- APPUpdate()
- }
- // plus.push.getClientInfoAsync((info) => {
- // var name = 'clientId'
- // var value = info.clientid
- // that.$store.commit('$uStore', {
- // name,
- // value
- // });
- // uni.setStorageSync("clientId", info.clientid)
- // console.log("info.clientid", info.clientid)
- // }, err => {});
- // 监听在线消息事件
- // plus.push.addEventListener("receive", function(msg) {
- // var title = msg.content.split(':')[0]
- // var content = msg.content.split(':')[1]
- // let params = {
- // inApp: true, // app内横幅提醒
- // voice: true, // 声音提醒
- // vibration: true, // 振动提醒
- // messageType: "",
- // messageTitle: title,
- // messageContent: content,
- // messageImage: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/logo.png'
- // }
- // console.log("msg", msg)
- // new app_push({
- // ...params
- // }).show();
- // var userInfo = uni.getStorageSync("userInfo")
- // var that = this
- // that.$request.baseRequest('get', '/notice/query/noticeNumber').then(res => {
- // if (res.data.data) {
- // let name = 'myTip';
- // let value = res.data.data.task;
- // that.$store.commit('$uStore', {
- // name,
- // value
- // });
- // if (value != 0 && value) {
- // uni.setTabBarBadge({
- // index: 4,
- // text: value + ""
- // })
- // }
- // name = 'taskTip';
- // value = res.data.data.task;
- // that.$store.commit('$uStore', {
- // name,
- // value
- // });
- // // name = 'contractTip';
- // // value = res.data.data.contractTip;
- // // that.$store.commit('$uStore', {
- // // name,
- // // value
- // // });
- // }
- // })
- // //其它逻辑
- // }, false);
- // //监听系统通知栏消息点击事件
- // plus.push.addEventListener('click', function(msg) {
- // //处理点击消息的业务逻辑代码
- // if (msg.content && msg.content.contains("任务")) {
- // uni.navigateTo({
- // url: '/pages/task/my_task'
- // })
- // } else if (msg.content && (msg.content.contains("合同") || msg.content.contains("交易"))) {
- // uni.navigateTo({
- // url: '/pageB/contract/contract'
- // })
- // }
- // }, false);
- // #endif
- // this.$socket.initWebIM(this.$ws, true, true)
- let userInfo = uni.getStorageSync('userInfo') || '';
- if (userInfo.id) {
- //更新登陆状态
- uni.getStorage({
- key: 'userInfo',
- success: (res) => {
- this.login(res.data);
- }
- });
- }
- },
- onShow: function() {
- console.log('App Show')
- // #ifdef APP-PLUS
- // var isContains = true;//隐私权政策是否包含高德开平隐私权政策 true是包含
- // var isShow = true;//隐私权政策是否弹窗展示告知用户 true是展示
- // sdkwx.updatePrivacyShow(isContains, isShow);
- // var isAgree = true;//隐私权政策是否取得用户同意 true是用户同意
- // sdkwx.updatePrivacyAgree(isAgree);
- // //检查定位权限
- // sdkwx.checkLocationPermission(function(res){
- // console.log(res);
- // });
- getCurrentNo(res => {
- // 进页面获取当前APP版本号(用于页面显示)
- this.version = res.versionName;
- });
- // #endif
- },
- onHide: function() {
- console.log('App Hide')
- },
- }
- </script>
- <style>
- /* .uni-input-input{
- filter: blur(4px);
- }
- uni-image{
- filter: blur(4px);
- } */
- /*每个页面公共css */
- </style>
|