index1.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <view class="content">
  3. <image class="logo" src="/static/logo.png"></image>
  4. <button type="primary" @click="auth()">授权</button>
  5. <button type="primary" @click="start()">开启定位</button>
  6. <button type="primary" @click="send()">发送定位</button>
  7. <button type="primary" @click="pause()">暂停定位</button>
  8. <button type="primary" @click="restart()">重启定位</button>
  9. <button type="primary" @click="stop()">结束定位</button>
  10. </view>
  11. </template>
  12. <script>
  13. //插件对象
  14. var sdkwx = uni.requireNativePlugin('Hdgq-LocSdkWX');
  15. import * as config from '@/config/index.js'
  16. export default {
  17. data() {
  18. return {
  19. title: 'Hello',
  20. vehicleNumber:"辽HG6663",//车牌号
  21. driverName:"孙亚洲",//司机姓名
  22. remark:"测试",//备注
  23. appId: "", //网络货运企业APP的唯一标识
  24. appSecurity: "", //网络货运企业在省平台申请的接入安全码
  25. enterpriseSenderCode: "", //网络货运企业在省平台申请的企业发送代码
  26. environment: "debug", //环境:“debug”接入测试环境,“release”接入正式环境。
  27. shippingNoteInfos:[{
  28. shippingNoteNumber:"CY20221028860111",
  29. serialNumber:"0000",
  30. startCountrySubdivisionCode:"210804",
  31. endCountrySubdivisionCode:"210804",
  32. startLongitude: "122.17153",
  33. startLatitude:"40.266814",
  34. endLongitude:"122.146806",
  35. endLatitude: "40.261078",
  36. startLocationText:"营口市",
  37. endLocationText:"营口市",
  38. vehicleNumber:"辽HG6663",
  39. driverName:"孙亚洲",
  40. interval:"5000"
  41. }],//运单信息列表,一辆车运单数最大支持数为 10
  42. timer:""
  43. }
  44. },
  45. onLoad() {
  46. // console.log("appId-------------------",uni.getAccountInfoSync().miniProgram.appId)
  47. // let phoneType = uni.getSystemInfoSync().platform //判断手机类型
  48. // if( phoneType == "android"){
  49. // this.appId = "uni.UNIDCD13AC"
  50. // }else if(phoneType == "ios"){
  51. // this.appId = "uni.UNI9C76CB6"
  52. // }
  53. //隐私合规接口,HBuildx3.3.3及其以后的版本需要调用合规检查
  54. var isContains = true;//隐私权政策是否包含高德开平隐私权政策 true是包含
  55. var isShow = true;//隐私权政策是否弹窗展示告知用户 true是展示
  56. sdkwx.updatePrivacyShow(isContains, isShow);
  57. var isAgree = true;//隐私权政策是否取得用户同意 true是用户同意
  58. sdkwx.updatePrivacyAgree(isAgree);
  59. //检查定位权限
  60. sdkwx.checkLocationPermission(function(res){
  61. console.log(res);
  62. });
  63. },
  64. methods: {
  65. auth() {
  66. let phoneType = uni.getSystemInfoSync().platform //判断手机类型
  67. this.enterpriseSenderCode = config.def().enterpriseSenderCode
  68. this.environment = config.def().environment
  69. if (phoneType == "android") {
  70. this.appId = config.def().androidAppId
  71. this.appSecurity = config.def().androidAppSecurity
  72. } else if (phoneType == "ios") {
  73. // this.appId = "uni.UNIDCD13AC"
  74. // this.appSecurity = "b01e4805276646eeb25f0fad91de97a4f32e8c2c0e0d42e5b24cc4737e9f040f"
  75. this.appId = config.def().iosAppId
  76. this.appSecurity = config.def().iosAppSecurity
  77. }
  78. //授权
  79. // var appId = "uni.UNI9C76CB6";//网络货运企业APP的唯一标识
  80. // var appSecurity = "24c593b7037347e08857a6ab05fd231b0509f5bb7cb741078f524f506ad32db8";//网络货运企业在省平台申请的接入安全码
  81. // var enterpriseSenderCode = "23106960";//网络货运企业在省平台申请的企业发送代码
  82. // var environment = "debug";//环境:“debug”接入测试环境,“release”接入正式环境。
  83. sdkwx.auth(this.appId, this.appSecurity, this.enterpriseSenderCode, this.environment, function(res) {
  84. console.log(res);
  85. if (res.type == "onSuccess") {
  86. //成功
  87. console.log(res,"成功");
  88. } else if (res.type == "onFailure"){
  89. //失败
  90. var errorCode = res.data.errorCode;//错误码
  91. var errorMsg = res.data.errorMsg;//错误描述
  92. }
  93. uni.showModal({
  94. content:JSON.stringify(res)
  95. });
  96. });
  97. },
  98. start(){
  99. var that = this
  100. //开启定位
  101. var vehicleNumber= this.vehicleNumber;//车牌号
  102. var driverName = this.driverName;//司机姓名
  103. var remark = this.remark;//备注
  104. var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
  105. var startParam = uni.getStorageSync("sdkStartParam")
  106. console.log(startParam)
  107. // if(startParam){
  108. // this.$helper.sdkStart(startParam.carNo,startParam.driverName,startParam.remark,startParam.shippingNoteInfos)
  109. // }
  110. console.log("更换前",shippingNoteInfos)
  111. shippingNoteInfos = startParam.shippingNoteInfos
  112. shippingNoteInfos[0].shippingNoteNumber = 'CY20221028860222'
  113. console.log("更换后",shippingNoteInfos)
  114. sdkwx.start(vehicleNumber, driverName, remark, shippingNoteInfos, function(res){
  115. console.log(res);
  116. if (res.type == "onSuccess") {
  117. //成功
  118. console.log("开启定位成功!!!")
  119. console.log(res)
  120. var shippingNoteInfos = res.data[0]; //运单信息列表
  121. console.log(shippingNoteInfos, "查看返回的时间")
  122. if (shippingNoteInfos) {
  123. let dateTtime = Number(shippingNoteInfos.interval + 1000)
  124. console.log("开始定时", dateTtime)
  125. // that.timer = setTimeout(() => {
  126. // console.log("定时")
  127. // that.send()
  128. // }, dateTtime);
  129. }
  130. } else if (res.type == "onFailure"){
  131. //失败
  132. var errorCode = res.data.errorCode;//错误码
  133. var errorMsg = res.data.errorMsg;//错误描述
  134. }
  135. });
  136. },
  137. send(){
  138. var that = this
  139. //发送定位
  140. var vehicleNumber= this.vehicleNumber;//车牌号
  141. var driverName = this.driverName;//司机姓名
  142. var remark = this.remark;//备注
  143. var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
  144. sdkwx.send(vehicleNumber, driverName, remark, shippingNoteInfos, function(res){
  145. var shippingNoteInfos = res.data[0]; //运单信息列表
  146. if (res.type == "onSuccess") {
  147. console.log("App.vue发送定位成功")
  148. console.log(res);
  149. console.log("查看返回的时间",shippingNoteInfos)
  150. if (shippingNoteInfos) {
  151. let dateTime = Number(shippingNoteInfos.interval + 1000)
  152. console.log("定时开始", dateTime)
  153. that.timer = setTimeout(() => {
  154. //TODO
  155. that.send()
  156. }, dateTime);
  157. }
  158. } else if (res.type == "onFailure") {//失败
  159. console.log("App.vue发送定位失败", res)
  160. var errorCode = res.data.errorCode; //错误码
  161. var errorMsg = res.data.errorMsg; //错误描述
  162. let dateTime1 = Number(shippingNoteInfos.interval + 1000)
  163. console.log("定时开始", dateTime1)
  164. that.timer = setTimeout(() => { //失败也需要定时上传定位(为了解决频繁调用接口问题)
  165. that.send()
  166. }, dateTime1);
  167. }
  168. });
  169. },
  170. pause(){
  171. //暂停定位
  172. var vehicleNumber= this.vehicleNumber;//车牌号
  173. var driverName = this.driverName;//司机姓名
  174. var remark = this.remark;//备注
  175. var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
  176. sdkwx.pause(vehicleNumber, driverName, remark, shippingNoteInfos, function(res) {
  177. console.log(res);
  178. if (res.type == "onSuccess") {
  179. //成功
  180. } else if (res.type == "onFailure"){
  181. //失败
  182. var errorCode = res.data.errorCode;//错误码
  183. var errorMsg = res.data.errorMsg;//错误描述
  184. }
  185. });
  186. },
  187. restart(){
  188. //重启定位
  189. var vehicleNumber= this.vehicleNumber;//车牌号
  190. var driverName = this.driverName;//司机姓名
  191. var remark = this.remark;//备注
  192. var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
  193. sdkwx.restart(vehicleNumber, driverName, remark, shippingNoteInfos, function(res) {
  194. console.log(res);
  195. if (res.type == "onSuccess") {
  196. //成功
  197. var shippingNoteInfos = res.data;//运单信息列表
  198. } else if (res.type == "onFailure"){
  199. //失败
  200. var errorCode = res.data.errorCode;//错误码
  201. var errorMsg = res.data.errorMsg;//错误描述
  202. }
  203. });
  204. },
  205. stop(){
  206. var that = this
  207. //结束定位
  208. var vehicleNumber= this.vehicleNumber;//车牌号
  209. var driverName = this.driverName;//司机姓名
  210. var remark = this.remark;//备注
  211. var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
  212. sdkwx.stop(vehicleNumber, driverName, remark, shippingNoteInfos, function(res) {
  213. console.log(res);
  214. if (res.type == "onSuccess") {
  215. clearInterval(that.timer)
  216. console.log("结束成功!!!",res)
  217. //成功
  218. } else if (res.type == "onFailure"){
  219. console.log("结束失败!!!",res)
  220. //失败
  221. var errorCode = res.data.errorCode;//错误码
  222. var errorMsg = res.data.errorMsg;//错误描述
  223. }
  224. });
  225. },
  226. }
  227. }
  228. </script>
  229. <style>
  230. .content {
  231. display: flex;
  232. flex-direction: column;
  233. align-items: center;
  234. justify-content: center;
  235. }
  236. .logo {
  237. height: 200rpx;
  238. width: 200rpx;
  239. margin-top: 200rpx;
  240. margin-left: auto;
  241. margin-right: auto;
  242. margin-bottom: 50rpx;
  243. }
  244. .text-area {
  245. display: flex;
  246. justify-content: center;
  247. }
  248. .title {
  249. font-size: 36rpx;
  250. color: #8f8f94;
  251. }
  252. </style>