webViews.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <web-view :src="src">
  3. </web-view>
  4. </template>
  5. <script>
  6. import { sendPos } from "@/api/core/api";
  7. import {
  8. server_url
  9. } from '@/utils/config.js'
  10. var wv;
  11. export default {
  12. data() {
  13. return {
  14. timer: '',
  15. src: '',
  16. query: {},
  17. webviewServer: server_url,
  18. uuid: '',
  19. };
  20. },
  21. onLoad(query) {
  22. this.query = query
  23. this.initData(query)
  24. },
  25. onReady() {
  26. // #ifdef APP-PLUS
  27. var self = this;
  28. var currentWebview = this.$scope
  29. .$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
  30. setTimeout(function() {
  31. wv = currentWebview.children()[0];
  32. wv.addEventListener(
  33. "progressChanged",
  34. function(e) {
  35. wv.canBack(function(e) {
  36. self.canBack = e.canBack;
  37. });
  38. },
  39. false
  40. );
  41. }, 500); //如果是页面初始化调用时,需要延时一下
  42. // #endif
  43. },
  44. // 设备上点击返回按钮时的处理
  45. onBackPress(e) {
  46. if (wv && this.canBack) {
  47. wv.back();
  48. } else {
  49. // 没有可返回的页面了, 可以做些其他的处理, 比如回首页等等
  50. }
  51. return true;
  52. },
  53. /* onNavigationBarButtonTap(e) {
  54. // 返回
  55. if (e.index === 0) {
  56. // #ifdef H5
  57. uni.navigateBack();
  58. // #endif
  59. // #ifdef APP-PLUS
  60. if (this.canBack) {
  61. wv.back();
  62. } else {
  63. // 没有可返回的页面了, 可以做些其他的处理, 比如回首页等等
  64. }
  65. // #endif
  66. }
  67. // 首页
  68. if (e.index === 1) {
  69. // 显示tabbar
  70. //uni.showTabBar({
  71. // animation: false
  72. //});
  73. uni.switchTab({
  74. url: '/pages/index/index'
  75. });
  76. }
  77. }, */
  78. watch: {
  79. authtoken: {
  80. immediate: true,
  81. deep: true,
  82. handler(newVal) {
  83. // console.log(newVal,'newValnewValnewVal')
  84. // this.initData(this.query)
  85. }
  86. }
  87. },
  88. computed: {
  89. token() {
  90. return this.$store.state.user.token
  91. }
  92. },
  93. methods: {
  94. getUuid() {
  95. var uuid = "";
  96. // #ifdef APP-PLUS
  97. if (plus.os.name == "Android") {
  98. try {
  99. var Build = plus.android.importClass("android.os.Build");
  100. var serial = Build.SERIAL;
  101. var mainActivity = plus.android.runtimeMainActivity();
  102. var Settings = plus.android.importClass("android.provider.Settings");
  103. var ANDROID_ID = Settings.Secure.getString(mainActivity.getContentResolver(), Settings.Secure
  104. .ANDROID_ID)
  105. uuid = `${ANDROID_ID}-${serial}`
  106. } catch (e) {
  107. console.log("获取设备唯一标识失败:", e);
  108. }
  109. }
  110. // #endif
  111. return uuid;
  112. },
  113. initData(query) {
  114. let urlParams = ''
  115. for (let key in query) {
  116. if (key != 'token') {
  117. urlParams += `&${key}=${query[key]}`
  118. }
  119. }
  120. urlParams += `&uuid=${this.getUuid()}`
  121. urlParams = urlParams.replace('&', '')
  122. this.src = `${this.webviewServer}/mobile/pages/attachedVessel/index/?${urlParams}`
  123. console.log('webview地址', this.src)
  124. this.uuid = this.getUuid()
  125. //测试背景音频播放
  126. // try {
  127. // const bgAudioManager = uni.getBackgroundAudioManager();
  128. // bgAudioManager.title = '致爱丽丝';
  129. // bgAudioManager.singer = '暂无';
  130. // bgAudioManager.coverImgUrl = 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/music-a.png';
  131. // bgAudioManager.src = 'https://web-ext-storage.dcloud.net.cn/uni-app/ForElise.mp3';
  132. // } catch (error) {
  133. // //TODO handle the exception
  134. // console.log('语音播报失败', error)
  135. // }
  136. try {
  137. let this_ = this
  138. this.timer = setInterval(() => {
  139. uni.getLocation({
  140. type: 'gcj02',
  141. isHighAccuracy: true,
  142. success: function(res) {
  143. console.log('持续位置信息', res)
  144. // console.log('当前位置的经度:' + res.longitude);
  145. // console.log('当前位置的纬度:' + res.latitude);
  146. let datas = {
  147. deviceId:this_.uuid,
  148. gpsTime:this_.dayjs().format('YYYY-MM-DD HH:mm:ss'),
  149. lat02:res.latitude,
  150. lng02:res.longitude,
  151. accuracy:res.accuracy,
  152. speed:res.speed
  153. }
  154. console.log('上传定位信息',datas)
  155. sendPos(datas).then(res => {
  156. console.log('位置信息上传成功', res)
  157. }).catch(err => {
  158. console.log('位置信息上传失败', err)
  159. })
  160. }
  161. });
  162. }, 8 * 1000)
  163. // uni.startLocationUpdate({
  164. // type:'gcj02',
  165. // // success: res => console.log('开启小程序接收位置消息成功'),
  166. // fail: err => console.error('开启接收位置消息失败:', err),
  167. // complete: msg => console.log('调用开启接收位置消息 API 完成')
  168. // });
  169. // uni.onLocationChange((res) => {
  170. // console.log('持续位置信息', res)
  171. // });
  172. } catch (error) {
  173. console.log('获取定位失败', error)
  174. }
  175. },
  176. getLocation() {
  177. },
  178. scanCode() {
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss"></style>