web.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view>
  3. <web-view :src="url" v-if="url"/>
  4. <text style="text-align: center;color: red;" v-else>无效的地址</text>
  5. </view>
  6. </template>
  7. <script>
  8. import _hook from '../../common/_hook';
  9. export default {
  10. components: {
  11. },
  12. data() {
  13. return {
  14. url: false,
  15. agent_user_id:0
  16. }
  17. },
  18. onShow(){
  19. _hook.routeTabBarHook();
  20. },
  21. onLoad(option) {
  22. if('url' in option){
  23. option.url = decodeURIComponent(option.url);
  24. if(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/.test(option.url)){
  25. if(!/^http/.test(option.url)){
  26. option.url = 'http://' + option.url;
  27. }
  28. this.url = option.url;
  29. }
  30. }
  31. if('title' in option){
  32. uni.setNavigationBarTitle({
  33. title: option.title,
  34. });
  35. }
  36. if('agent_user_id' in option){
  37. this.agent_user_id = option.agent_user_id;
  38. }
  39. },
  40. computed: {
  41. },
  42. methods: {
  43. },
  44. onNavigationBarButtonTap(e) {
  45. console.log(e.index)
  46. // #ifdef APP-PLUS
  47. let currentWebview = this.$mp.page.$getAppWebview().children()[0]; //获取当前页面的webview对象
  48. // #endif
  49. switch (e.index){
  50. case 0:
  51. //跳转客服
  52. //pages/details/index?user_id=271&is_type=0
  53. if(!this.agent_user_id) uni.showToast({title: '改商户暂未设置客服',icon:'none'});
  54. uni.navigateTo({
  55. url: '/pages/details/index?is_type=0&user_id='+this.agent_user_id
  56. });
  57. break;
  58. case 1:
  59. // #ifdef APP-PLUS
  60. currentWebview.reload();
  61. // #endif
  62. // #ifdef H5
  63. location.reload();
  64. // #endif
  65. break;
  66. case 2:
  67. uni.switchTab({
  68. url: '../push/game',
  69. });
  70. break;
  71. case 3:
  72. uni.navigateBack();
  73. break;
  74. default:
  75. break;
  76. }
  77. },
  78. }
  79. </script>
  80. <style>
  81. </style>