webview.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <web-view cache="no-cache" :src="webViewSrc" @message="getMSG"></web-view>
  3. </template>
  4. <script>
  5. import {getToken} from '@/libs/auth.js';
  6. export default {
  7. data() {
  8. return {
  9. webViewSrc:""
  10. }
  11. },
  12. onLoad(options) {
  13. this.init(options)
  14. },
  15. methods: {
  16. init(options){
  17. let t=new Date().getTime();
  18. if(options.type==='scan'){
  19. let href="http://h5.xazhyc.com/scanApp/#/pages/index/index"
  20. let qrcode=uni.getStorageSync('qrcode')
  21. qrcode=qrcode.split('?')[1]
  22. this.webViewSrc=`${href}?token=${getToken()}&${qrcode}&v=${t}`
  23. console.log(`${href}?token=${getToken()}&${qrcode}&v=${t}`)
  24. uni.setNavigationBarTitle({
  25. title:"扫码操作"
  26. })
  27. }else{
  28. let other=""
  29. for(let key in options){
  30. if(key!=='href'&&key!=='name'){
  31. other+=`${key}=${options[key]}&`
  32. }
  33. }
  34. this.webViewSrc=`${options.href}?token=${getToken()}&${other}v=${t}`
  35. uni.setNavigationBarTitle({
  36. title:`${options.name}`
  37. })
  38. }
  39. },
  40. getMSG(){
  41. }
  42. },
  43. onBackPress(e){
  44. // console.log(e)
  45. }
  46. }
  47. </script>