wap.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view>
  3. <web-view v-if="!reload" class="custom-webview" :src="url" :webview-styles="{progress: {
  4. color: '#FF3333'
  5. }}"></web-view>
  6. </view>
  7. </template>
  8. <script>
  9. import _data from '../../common/_data';
  10. import _action from '@/common/_action.js'
  11. export default {
  12. data() {
  13. return {
  14. url: '',
  15. reload: false
  16. }
  17. },
  18. onShow() {
  19. // this.url = _data.data('bottom_url');
  20. // console.log(this.url);
  21. // this.getWebUrl();
  22. _action.getWebUrl();
  23. let _this = this;
  24. uni.$on('show_weburl', function(url) {
  25. _this.url = url;
  26. })
  27. },
  28. onLoad(option) {
  29. if ('url' in option) {
  30. option.url = decodeURIComponent(option.url);
  31. if (/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/.test(option.url)) {
  32. if (!/^http/.test(option.url)) {
  33. option.url = 'http://' + option.url;
  34. }
  35. this.url = option.url;
  36. }
  37. }
  38. if ('title' in option) {
  39. uni.setNavigationBarTitle({
  40. title: option.title,
  41. });
  42. }
  43. if ('agent_user_id' in option) {
  44. this.agent_user_id = option.agent_user_id;
  45. }
  46. },
  47. computed: {
  48. },
  49. methods: {
  50. getWebUrl() {
  51. let _this = this;
  52. this.$httpSend({
  53. path: '/im/middle.Middle/get_list',
  54. success: function(res) {
  55. console.log("res网站", res);
  56. let arr = res;
  57. let url = ''
  58. if (arr.length) {
  59. arr.forEach(item => {
  60. if (item.status == 1) {
  61. url = item.url;
  62. return
  63. }
  64. })
  65. if (!url) {
  66. uni.setTabBarItem({
  67. index: 2,
  68. visible: false
  69. })
  70. } else {
  71. _this.url = url;
  72. }
  73. } else {
  74. uni.setTabBarItem({
  75. index: 2,
  76. visible: false
  77. })
  78. }
  79. }
  80. })
  81. },
  82. },
  83. onNavigationBarButtonTap(e) {
  84. console.log(e.index)
  85. // #ifdef APP-PLUS
  86. let currentWebview = this.$mp.page.$getAppWebview().children()[0]; //获取当前页面的webview对象
  87. // #endif
  88. switch (e.index) {
  89. case 0:
  90. //跳转客服
  91. //pages/details/index?user_id=271&is_type=0
  92. // if (!this.agent_user_id) uni.showToast({
  93. // title: '改商户暂未设置客服',
  94. // icon: 'none'
  95. // });
  96. // uni.navigateTo({
  97. // url: '/pages/details/index?is_type=0&user_id=' + this.agent_user_id
  98. // });
  99. this.$httpSend({
  100. path: '/im/get/kefu',
  101. success(data) {
  102. console.log('客服数据', data)
  103. uni.navigateTo({
  104. 'url': '/pages/chat/message?list_id=' + data
  105. })
  106. }
  107. });
  108. break;
  109. case 1:
  110. // #ifdef APP-PLUS
  111. currentWebview.reload();
  112. // #endif
  113. // #ifdef H5
  114. // location.reload();
  115. let _this = this;
  116. _this.reload = true;
  117. setTimeout(() => {
  118. this.reload = false;
  119. _action.getWebUrl();
  120. let _this = this;
  121. uni.$on('show_weburl', function(url) {
  122. _this.url = url;
  123. })
  124. }, 10)
  125. // #endif
  126. break;
  127. case 2:
  128. uni.switchTab({
  129. url: '../push/game',
  130. });
  131. break;
  132. case 3:
  133. uni.navigateBack();
  134. break;
  135. default:
  136. break;
  137. }
  138. },
  139. }
  140. </script>
  141. <style>
  142. .custom-webview {
  143. flex: 1;
  144. }
  145. </style>