web.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="web">
  3. <web-view :src="url"></web-view>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name: "web",
  9. data() {
  10. return {
  11. url: '',
  12. webviewStyles: {
  13. progress: {
  14. width: '100%',
  15. height: '100%',
  16. }
  17. }
  18. }
  19. },
  20. onLoad(option) { this.$commonLoad.onload(option);
  21. if (option.is_pay) {
  22. this.url = JSON.parse(option.url).url;
  23. // this.url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${option.data.appid}&redirect_uri=${window.location.origin}/pages/user-center/user-center&response_type=code&scope=snsapi_base&state=${option.data.state}#wechat_redirect`
  24. } else {
  25. this.getUrl(unescape(option.url));
  26. }
  27. },
  28. methods: {
  29. getUrl(url) {
  30. url = decodeURIComponent(url);
  31. let arr = url.split('?');
  32. let uri = arr[0];
  33. let param = arr[1] ? arr[1].split('&') : '';
  34. if (param) {
  35. url = uri;
  36. if (this.$user.isLogin()) {
  37. for (let i in param) {
  38. if (param[i] === 'visiter_id=') {
  39. let access_token = this.$store.state.user.accessToken;
  40. param[i] += access_token || '';
  41. }
  42. let userInfo = this.$store.state.user.info;
  43. if (param[i] === 'visiter_name=') {
  44. param[i] += encodeURIComponent(userInfo ? userInfo.nickname : '游客');
  45. }
  46. if (param[i] === 'avatar=') {
  47. param[i] += encodeURIComponent(userInfo ? userInfo.avatar : '');
  48. }
  49. }
  50. if (this.$store.state.user.info) {
  51. param.push('user_id=' + this.$store.state.user.info.options.user_id);
  52. }
  53. }
  54. let pages = getCurrentPages();
  55. if (pages.length > 1) {
  56. let page = pages[pages.length - 2];
  57. let goods = null;
  58. // #ifdef MP
  59. goods = page.data.goods;
  60. // #endif
  61. // #ifdef H5
  62. goods = page._data.goods;
  63. // #endif
  64. if (goods) {
  65. let goods = '';
  66. let product = '';
  67. // #ifdef MP
  68. goods = page.data.goods;
  69. // #endif
  70. // #ifdef H5
  71. goods = page._data.goods;
  72. // #endif
  73. product = {
  74. pid: goods.id,
  75. title: goods.name,
  76. img: goods.cover_pic,
  77. info: '',
  78. price: "¥" + goods.price,
  79. url: ""
  80. };
  81. if (page.route === 'plugins/integral_mall/goods/goods') {
  82. product.price = '';
  83. if (typeof goods.integral != 'undefined') {
  84. product.price += goods.integral + "积分 + ";
  85. }
  86. product.price += "¥" + goods.price;
  87. }
  88. if (page.route === 'plugins/step/goods/goods') {
  89. product.price = goods.price;
  90. }
  91. if (product) {
  92. param.push("product=" + encodeURIComponent(JSON.stringify(product)));
  93. }
  94. }
  95. }
  96. url = uri + '?' + param.join('&');
  97. } else {
  98. if (this.$user.isLogin() && this.$store.state.user.info) {
  99. url = uri + '?user_id=' + this.$store.state.user.info.options.user_id;
  100. }
  101. }
  102. this.url = url
  103. }
  104. },
  105. // #ifdef MP
  106. onShareAppMessage() {
  107. let args = {
  108. path: '/pages/web/web',
  109. params: {
  110. url: encodeURIComponent(this.url)
  111. }
  112. };
  113. return this.$shareAppMessage(args);
  114. },
  115. // #endif
  116. }
  117. </script>
  118. <style scoped>
  119. .web {
  120. position: absolute;
  121. top: 0;
  122. left: 0;
  123. width: 100%;
  124. height: 100%;
  125. }
  126. </style>