123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <template>
- <view class="content">
- <image class="logo" src="/static/logo.png"></image>
- <button type="primary" @click="auth()">授权</button>
- <button type="primary" @click="start()">开启定位</button>
- <button type="primary" @click="send()">发送定位</button>
- <button type="primary" @click="pause()">暂停定位</button>
- <button type="primary" @click="restart()">重启定位</button>
- <button type="primary" @click="stop()">结束定位</button>
- </view>
- </template>
- <script>
- //插件对象
- var sdkwx = uni.requireNativePlugin('Hdgq-LocSdkWX');
- import * as config from '@/config/index.js'
- export default {
- data() {
- return {
- title: 'Hello',
- vehicleNumber:"辽HG6663",//车牌号
- driverName:"孙亚洲",//司机姓名
- remark:"测试",//备注
- appId: "", //网络货运企业APP的唯一标识
- appSecurity: "", //网络货运企业在省平台申请的接入安全码
- enterpriseSenderCode: "", //网络货运企业在省平台申请的企业发送代码
- environment: "debug", //环境:“debug”接入测试环境,“release”接入正式环境。
- shippingNoteInfos:[{
- shippingNoteNumber:"CY20221028860111",
- serialNumber:"0000",
- startCountrySubdivisionCode:"210804",
- endCountrySubdivisionCode:"210804",
- startLongitude: "122.17153",
- startLatitude:"40.266814",
- endLongitude:"122.146806",
- endLatitude: "40.261078",
- startLocationText:"营口市",
- endLocationText:"营口市",
- vehicleNumber:"辽HG6663",
- driverName:"孙亚洲",
- interval:"5000"
- }],//运单信息列表,一辆车运单数最大支持数为 10
- timer:""
- }
- },
- onLoad() {
- // console.log("appId-------------------",uni.getAccountInfoSync().miniProgram.appId)
- // let phoneType = uni.getSystemInfoSync().platform //判断手机类型
- // if( phoneType == "android"){
- // this.appId = "uni.UNIDCD13AC"
- // }else if(phoneType == "ios"){
- // this.appId = "uni.UNI9C76CB6"
- // }
- //隐私合规接口,HBuildx3.3.3及其以后的版本需要调用合规检查
- 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);
- });
- },
- methods: {
- 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
- }
- //授权
- // var appId = "uni.UNI9C76CB6";//网络货运企业APP的唯一标识
- // var appSecurity = "24c593b7037347e08857a6ab05fd231b0509f5bb7cb741078f524f506ad32db8";//网络货运企业在省平台申请的接入安全码
- // var enterpriseSenderCode = "23106960";//网络货运企业在省平台申请的企业发送代码
- // var environment = "debug";//环境:“debug”接入测试环境,“release”接入正式环境。
- sdkwx.auth(this.appId, this.appSecurity, this.enterpriseSenderCode, this.environment, function(res) {
- console.log(res);
- if (res.type == "onSuccess") {
- //成功
- console.log(res,"成功");
- } else if (res.type == "onFailure"){
- //失败
- var errorCode = res.data.errorCode;//错误码
- var errorMsg = res.data.errorMsg;//错误描述
- }
- uni.showModal({
- content:JSON.stringify(res)
- });
- });
- },
- start(){
- var that = this
- //开启定位
- var vehicleNumber= this.vehicleNumber;//车牌号
- var driverName = this.driverName;//司机姓名
- var remark = this.remark;//备注
- var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
- var startParam = uni.getStorageSync("sdkStartParam")
-
- console.log(startParam)
- // if(startParam){
- // this.$helper.sdkStart(startParam.carNo,startParam.driverName,startParam.remark,startParam.shippingNoteInfos)
- // }
- console.log("更换前",shippingNoteInfos)
- shippingNoteInfos = startParam.shippingNoteInfos
- shippingNoteInfos[0].shippingNoteNumber = 'CY20221028860222'
- console.log("更换后",shippingNoteInfos)
- sdkwx.start(vehicleNumber, driverName, remark, shippingNoteInfos, function(res){
- console.log(res);
- if (res.type == "onSuccess") {
- //成功
- console.log("开启定位成功!!!")
- console.log(res)
- var shippingNoteInfos = res.data[0]; //运单信息列表
- console.log(shippingNoteInfos, "查看返回的时间")
- if (shippingNoteInfos) {
- let dateTtime = Number(shippingNoteInfos.interval + 1000)
- console.log("开始定时", dateTtime)
- // that.timer = setTimeout(() => {
- // console.log("定时")
- // that.send()
- // }, dateTtime);
- }
- } else if (res.type == "onFailure"){
- //失败
- var errorCode = res.data.errorCode;//错误码
- var errorMsg = res.data.errorMsg;//错误描述
- }
- });
- },
- send(){
- var that = this
- //发送定位
- var vehicleNumber= this.vehicleNumber;//车牌号
- var driverName = this.driverName;//司机姓名
- var remark = this.remark;//备注
- var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
- sdkwx.send(vehicleNumber, driverName, remark, shippingNoteInfos, function(res){
- var shippingNoteInfos = res.data[0]; //运单信息列表
- if (res.type == "onSuccess") {
- console.log("App.vue发送定位成功")
- console.log(res);
- console.log("查看返回的时间",shippingNoteInfos)
- 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; //错误描述
- let dateTime1 = Number(shippingNoteInfos.interval + 1000)
- console.log("定时开始", dateTime1)
- that.timer = setTimeout(() => { //失败也需要定时上传定位(为了解决频繁调用接口问题)
- that.send()
- }, dateTime1);
- }
- });
- },
- pause(){
- //暂停定位
- var vehicleNumber= this.vehicleNumber;//车牌号
- var driverName = this.driverName;//司机姓名
- var remark = this.remark;//备注
- var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
- sdkwx.pause(vehicleNumber, driverName, remark, shippingNoteInfos, function(res) {
- console.log(res);
- if (res.type == "onSuccess") {
- //成功
- } else if (res.type == "onFailure"){
- //失败
- var errorCode = res.data.errorCode;//错误码
- var errorMsg = res.data.errorMsg;//错误描述
- }
- });
- },
- restart(){
- //重启定位
- var vehicleNumber= this.vehicleNumber;//车牌号
- var driverName = this.driverName;//司机姓名
- var remark = this.remark;//备注
- var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
- sdkwx.restart(vehicleNumber, driverName, remark, shippingNoteInfos, function(res) {
- console.log(res);
-
- if (res.type == "onSuccess") {
- //成功
- var shippingNoteInfos = res.data;//运单信息列表
- } else if (res.type == "onFailure"){
- //失败
- var errorCode = res.data.errorCode;//错误码
- var errorMsg = res.data.errorMsg;//错误描述
- }
- });
- },
- stop(){
- var that = this
- //结束定位
- var vehicleNumber= this.vehicleNumber;//车牌号
- var driverName = this.driverName;//司机姓名
- var remark = this.remark;//备注
- var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
- sdkwx.stop(vehicleNumber, driverName, remark, shippingNoteInfos, function(res) {
- console.log(res);
- if (res.type == "onSuccess") {
- clearInterval(that.timer)
- console.log("结束成功!!!",res)
- //成功
- } else if (res.type == "onFailure"){
- console.log("结束失败!!!",res)
- //失败
- var errorCode = res.data.errorCode;//错误码
- var errorMsg = res.data.errorMsg;//错误描述
- }
- });
- },
- }
-
- }
- </script>
- <style>
- .content {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- }
- .logo {
- height: 200rpx;
- width: 200rpx;
- margin-top: 200rpx;
- margin-left: auto;
- margin-right: auto;
- margin-bottom: 50rpx;
- }
- .text-area {
- display: flex;
- justify-content: center;
- }
- .title {
- font-size: 36rpx;
- color: #8f8f94;
- }
- </style>
|