login.js 1.02 KB
var common = require('../utils/common');
var base = require('./base');

function login(obj) {
    var _this = this;
    _this.env = obj.env;
    _this.url = obj.loginUrl;

    _this.goLogin = function () {
        if (_this.env === 'miniprogram') {
            wx.miniProgram.switchTab({url: _this.url});
        } else if (_this.env === 'app') {
            var loginButton = document.getElementById('yosdk-login');
            if (!loginButton) {
                loginButton = common.createLinkButton(_this.url, 'yosdk-login');
            }
            loginButton.click();
        } else {
            window.location.href = _this.url;
        }
        return false;
    };

    _this.auth = function (nodeList, user) {
        if (!user.uid) {
            [].forEach.call(nodeList, function(value) {
                value.onclick = function (event) {
                    event.preventDefault();
                    _this.goLogin();
                }
            });
            return true;
        }
    }
}

module.exports = login;