webview.js 1.47 KB
import config from '../../config';
import { verify } from '../../common/api';
import commonModel from '../../models/common';

Page({
  data: {
    url: '',
    title: '',
  },

  onLoad: function(options) {
    if (options && options.scene && options.scene.length > 0) {
      let code = options.scene;

      return commonModel.getMiniAppRealParam(code)
        .then(json => {
          if (json) {
            this.load(json);
          }
        })
        .catch(() => {});
    }

    this.load(options);
  },

  onShareAppMessage: function() {
    return {
      title: this.data.title,
      path: '/pages/webview/webview?url=' + this.data.url,
    };
  },

  load: function(options) {
    let app = getApp();
    let url = options.url;

    if (options && options.url) {
      let params = {};
      let sys = wx.getSystemInfoSync();

      params.uid = app.getUid();
      params.udid = app._getSync('udid');
      params.session_key = app._getSync('sessionKey');
      params.app_version = config.apiParams.app_version;
      params.client_type = config.apiParams.client_type;
      params.screen_size = `${sys.windowWidth}x${sys.windowHeight}`;
      params.os_version = sys.version;

      verify.sign(params);

      this.setData({
        url: decodeURIComponent(`${url}`)
      });
    }
  },

  bindGetMsg: function(e) {
    if (e.detail && e.detail.data && e.detail.data[0] && e.detail.data[0].title) {
      this.setData({
        title: e.detail.data[0].title,
      });
    }
  }
});