webViews.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <web-view :src="src">
  3. </web-view>
  4. </template>
  5. <script>
  6. import { getToken } from '@/utils/auth'
  7. import { server_url } from '@/utils/config.js'
  8. var wv;
  9. export default {
  10. data() {
  11. return {
  12. src: '',
  13. query: {},
  14. webviewServer: server_url,
  15. };
  16. },
  17. onLoad(query) {
  18. this.query = query
  19. this.initData(query)
  20. },
  21. onReady() {
  22. // #ifdef APP-PLUS
  23. var self = this;
  24. var currentWebview = this.$scope.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
  25. setTimeout(function () {
  26. wv = currentWebview.children()[0];
  27. wv.addEventListener(
  28. "progressChanged",
  29. function (e) {
  30. wv.canBack(function (e) {
  31. self.canBack = e.canBack;
  32. });
  33. },
  34. false
  35. );
  36. }, 500); //如果是页面初始化调用时,需要延时一下
  37. // #endif
  38. },
  39. // 设备上点击返回按钮时的处理
  40. onBackPress(e) {
  41. if (wv && this.canBack) {
  42. wv.back();
  43. } else {
  44. // 没有可返回的页面了, 可以做些其他的处理, 比如回首页等等
  45. }
  46. return true;
  47. },
  48. /* onNavigationBarButtonTap(e) {
  49. // 返回
  50. if (e.index === 0) {
  51. // #ifdef H5
  52. uni.navigateBack();
  53. // #endif
  54. // #ifdef APP-PLUS
  55. if (this.canBack) {
  56. wv.back();
  57. } else {
  58. // 没有可返回的页面了, 可以做些其他的处理, 比如回首页等等
  59. }
  60. // #endif
  61. }
  62. // 首页
  63. if (e.index === 1) {
  64. // 显示tabbar
  65. //uni.showTabBar({
  66. // animation: false
  67. //});
  68. uni.switchTab({
  69. url: '/pages/index/index'
  70. });
  71. }
  72. }, */
  73. watch: {
  74. authtoken: {
  75. immediate: true,
  76. deep: true,
  77. handler(newVal) {
  78. // console.log(newVal,'newValnewValnewVal')
  79. // this.initData(this.query)
  80. }
  81. }
  82. },
  83. computed: {
  84. token() {
  85. return this.$store.state.user.token
  86. }
  87. },
  88. methods: {
  89. getUuid() {
  90. var uuid = "";
  91. // #ifdef APP-PLUS
  92. if (plus.os.name == "Android") {
  93. try {
  94. var Build = plus.android.importClass("android.os.Build");
  95. var serial = Build.SERIAL;
  96. var mainActivity = plus.android.runtimeMainActivity();
  97. var Settings = plus.android.importClass("android.provider.Settings");
  98. var ANDROID_ID = Settings.Secure.getString(mainActivity.getContentResolver(), Settings.Secure.ANDROID_ID)
  99. uuid = `${ANDROID_ID}-${serial}`
  100. } catch (e) {
  101. console.log("获取设备唯一标识失败:", e);
  102. }
  103. }
  104. // #endif
  105. return uuid;
  106. },
  107. initData(query) {
  108. let urlParams = ''
  109. for (let key in query) {
  110. if (key != 'token') {
  111. urlParams += `&${key}=${query[key]}`
  112. }
  113. }
  114. urlParams += `&uuid=${this.getUuid()}`
  115. urlParams = urlParams.replace('&', '')
  116. this.src = `${this.webviewServer}/mobile/pages/attachedVessel/index/?${urlParams}`
  117. console.log('webview地址', this.src)
  118. },
  119. getLocation() {
  120. },
  121. scanCode() {
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss"></style>