web.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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) {
  21. this.getUrl(unescape(option.url));
  22. },
  23. onShareAppMessage() {
  24. let args = {
  25. path: '/pages/web/web',
  26. params: {
  27. url: encodeURIComponent(this.url)
  28. }
  29. };
  30. return this.$shareAppMessage(args);
  31. },
  32. methods: {
  33. getUrl(url) {
  34. url = decodeURIComponent(url);
  35. let arr = url.split('?');
  36. let uri = arr[0];
  37. let param = arr[1] ? arr[1].split('&') : '';
  38. if (param) {
  39. url = uri;
  40. if (this.$user.isLogin()) {
  41. for (let i in param) {
  42. if (param[i] === 'visiter_id=') {
  43. let access_token = this.$store.state.user.accessToken;
  44. param[i] += access_token || '';
  45. }
  46. let userInfo = this.$store.state.user.info;
  47. if (param[i] === 'visiter_name=') {
  48. param[i] += encodeURIComponent(userInfo ? userInfo.nickname : '游客');
  49. }
  50. if (param[i] === 'avatar=') {
  51. param[i] += encodeURIComponent(userInfo ? userInfo.avatar : '');
  52. }
  53. }
  54. }
  55. let pages = getCurrentPages();
  56. if (pages.length > 1) {
  57. let page = pages[pages.length - 2];
  58. if (page.data.goods) {
  59. let goods = '';
  60. let product = '';
  61. goods = page.data.goods;
  62. product = {
  63. pid: goods.id,
  64. title: goods.name,
  65. img: goods.cover_pic,
  66. info: '',
  67. price: "¥" + goods.price,
  68. url: ""
  69. };
  70. if (page.route === 'plugins/integral_mall/goods/goods') {
  71. product.price = '';
  72. if (typeof goods.integral != 'undefined') {
  73. product.price += goods.integral + "积分 + ";
  74. }
  75. product.price += "¥" + goods.price;
  76. }
  77. if (page.route === 'plugins/step/goods/goods') {
  78. product.price = goods.price;
  79. }
  80. if (product) {
  81. param.push("product=" + encodeURIComponent(JSON.stringify(product)));
  82. }
  83. }
  84. }
  85. url = uri + '?' + param.join('&');
  86. }
  87. this.url = url
  88. }
  89. }
  90. }
  91. </script>
  92. <style scoped>
  93. .web {
  94. position: absolute;
  95. top: 0;
  96. left: 0;
  97. width: 100%;
  98. height: 100%;
  99. }
  100. </style>