// subPackage/home/pages/h5/h5page.js
const wxService = require('../../../../utils/wxService')
wxService.page({

  /**
   * 页面的初始数据
   */
  data: {
    path: '',
    title : '',
    h5WhitePages: [
      '/mp6Y/begin.html',
      '/mp6Y/index.html',
      '/v1/wx_oauth/redirect_uri'
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let url = options.url;
    console.log(options)
    if (url) {
      url = decodeURIComponent(url);
      this.data.title = options.title;
      wx.setNavigationBarTitle({
        title: this.data.title,
      });
      
      this.setData({
        path: url
      })
    }
  },
  webviewOnload (e) {
    // if (e.type === 'load') {
    //   const src = e.detail.src
    //   console.log(src)
    //   let pass = false
    //   const whitePages = this.data.h5WhitePages
    //   whitePages.map(item => {
    //     const regex = new RegExp(`${item}`, 'gi')
    //     if (!pass) {
    //       pass = regex.test(src)
    //     }
    //   })
    //   // 不在白名单页中统一返回到首页
    //   if (!pass) {
    //     wxService.router('/pages/userCenter/userCenter').back()
    //   }
    // }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    // 需要 encodeURIComponent path
    const { path } = this.data
    const enCodeUrl = encodeURIComponent(path)
    let sharePath = `/subPackage/page/pages/h5/h5page?url=${enCodeUrl}&title=${this.data.title}`
    return {
      // title: '分享给好友',
      path: sharePath,
      success(){
        wx.showToast({
          title: "转发成功",
          icon: 'success',
          duration: 2000
        })
      },
      fail() {
        wx.showToast({
          title: "转发失败",
          icon: 'none',
          duration: 2000
        })
      }
    }
  }
})
