UNPKG

h5-cli

Version:

hello

145 lines (124 loc) 4.65 kB
"use strict"; define(function (require, exports, module) { var md5 = require("libs/md5"); var PageModule = require("component/PageModule"); var registerToken = require("mods/register-token/index"); var page = PageModule.render({ init: function init() { var self = this; //\u76f4\u63a5\u8df3\u8f6c\u5230\u67d0\u4e2a\u754c\u9762 this.redirecturl = this.query.redirecturl; //\u76f4\u63a5\u8fd4\u56de\u5230\u4e0a\u4e00\u4e2aview this.backview = this.query.backview; //\u662f\u5426\u81ea\u52a8\u767b\u5f55 this.autoLogin = this.query.aotuLogin; this.cacheModule = this.cache.getCacheModule(); this.corpId = this.query.corpId; this.unionId = this.query.unionId; var phone = this.cacheModule.get("phone"); if (phone && phone.value) { $('#J_PhoneNumber').val(phone.value); } console.log(this.unionId); console.info(this.query.unionId); $('#forgetPwd').attr('href', 'forget-pwd.html?unionId=' + this.unionId + '&target=_blank'); $('#registerNew').attr('href', 'register.html?unionId=' + this.unionId + '&target=_blank'); this.regEvent(); }, regEvent: function regEvent() { var self = this; $('#J_Submit').click(function () { self.submit(); }); if (this.autoLogin) { //\u81ea\u52a8\u8c03\u7528\u4e00\u6b21\u63a5\u53e3\u770b\u770b\u662f\u5426\u5df2\u7ecf\u767b\u5f55 this.io.get("/user-web/restapi/ytUsers/getUserInfo", {}, function (result) { self.util.alert("\u81ea\u52a8\u767b\u5f55\u6210\u529f\uff0c\u6b63\u5728\u8df3\u8f6c"); setTimeout(function () { self.onSuccess(result); }, 3000); }, function () {}); } var referrer = document.referrer; if (referrer) { $('#J_RegisterLink a,.top-notice').each(function () { var href = $(this).attr("href"); $(this).attr("href", href + "&redirecturl=" + encodeURIComponent(referrer)); }); } }, submit: function submit() { var phoneNumber = $.trim($('#J_PhoneNumber').val()); var pwd = $.trim($('#J_Pwd').val()); if (!/^\d{11}$/.test(phoneNumber)) { this.util.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7\u7801"); return; } if (pwd.length == 0) { this.util.alert("\u8bf7\u8f93\u5165\u5bc6\u7801"); return; } if (!(pwd && pwd.length >= 6 && pwd.length <= 50)) { this.util.alert("\u5bc6\u7801\u4e0d\u6b63\u786e"); return; } this.util.waitAlert("\u8bf7\u6c42\u4e2d..."); //\u7f13\u5b58\u624b\u673a\u53f7 // this.cache.set("phoneNumber", phoneNumber); this.phoneNumber = phoneNumber; console.log(this.corpId); console.log(this.unionId); if (this.unionId) { this.get("/user-web/restapi/common/ytUsers/login", { phoneNum: phoneNumber, password: md5(pwd), unionId: this.unionId }); } else { this.get("/user-web/restapi/common/ytUsers/login", { phoneNum: phoneNumber, password: md5(pwd), corpId: this.corpId, unionId: this.unionId }); } }, onSuccess: function onSuccess(result) { var self = this; if (result.success) { self.util.alert("\u767b\u5f55\u6210\u529f"); //\u9884\u7ea6\u6210\u529f\u767b\u8bb0\u8bbe\u5907\u53f7\uff0c \u7136\u540e\u8df3\u8f6c registerToken.onComplate = function () { try { if (window.localStorage) { localStorage.clear(); } var cache = self.cache.getCacheModule(); cache.remove("patient"); cache = self.cache.getCacheModule("AsynDataCache"); cache.clear(); //\u7f13\u5b58\u624b\u673a\u53f7\u7801 self.cacheModule.set("phone", self.phoneNumber, '\u624b\u673a\u53f7\u7801'); } catch (e) { console.log(e); } console.log(self); if (self.backview && self.util.isInYuantuApp()) { //\u5728native\u4e2d\u76f4\u63a5\u8fd4\u56de self.util.goBack(true); } else if (self.redirecturl && self.redirecturl != "undefined") { //\u5728h5\u4e2d\u8fd4\u56de\u5230\u6765\u8def\u9875\u9762 window.location.replace(self.redirecturl); } else { self.util.goBack(true); } }; //\u767b\u8bb0\u8bbe\u5907 registerToken.init(); } } }); //\u9875\u9762 page.init(); module.exports = page; });