123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- /**
- * 登录相关js
- *
- * @author CaiAoLin
- * @date 2017/6/8
- * @version
- */
- $(document).ready(function () {
- let referer = scUrlUtil.GetQueryString('referer');
- $("#login").click(function () {
- if (!valid()) {
- return false;
- }
- let account = $("#inputEmail").val();
- let pw = $("#inputPassword").val();
- $.ajax({
- url: '/login',
- type: 'post',
- data: {"account": account, "pw": pw},
- success: function (response) {
- if (response.error === 0) {
- const url = response.last_page !== null && response.last_page !== undefined && response.last_page !== '' ?
- response.last_page : '/pm';
- if (response.login_ask === 0) {
- location.href = url;
- } else {
- response.compilation_list = response.compilation_list === undefined || response.compilation_list === '' ?
- null : JSON.parse(response.compilation_list);
- if (response.compilation_list === null || response.compilation_list.length <= 0) {
- location.href = url;
- return false;
- }
- console.log(response.compilation_list);
- setVersion(response.compilation_list);
- $('#ver').modal('show');
- }
- } else if(response.error === 2) {
- $('#check_ssoId').val(response.ssoId);
- $('#phone').modal('show');
- } else {
- let msg = response.msg !== undefined ? response.msg : '未知错误';
- showError(msg, $("input"));
- }
- },
- error: function (result) {
- showError('内部程序错误', null);
- }
- });
- });
- $("input").blur(function () {
- cleanError();
- cleanValidError($(this));
- });
- $(".form-control").on('input', function () {
- $('#hint').html(' ');
- });
- $("#get-code").click(function() {
- const mobile = $("#mobile").val();
- if(!validMobile(mobile)){
- return false;
- }
- const btn = $(this);
- if(!btn.hasClass('disabled')){
- $.ajax({
- url: '/sms/code',
- type: 'post',
- data: { mobile: mobile, type: 1},
- error: function() {
- showValidError('短信接口出错!',$('#mobile'));
- },
- beforeSend: function() {
- },
- success: function(response) {
- if (response.err === 0) {
- codeSuccess(btn);
- } else {
- showValidError(response.msg,$('#mobile'));
- }
- }
- });
- }
- });
- $('#check-code').click(function () {
- const mobile = $("#mobile").val();
- const ssoId = $("#check_ssoId").val();
- const code = $("#code").val();
- if(!validMobile(mobile)) {
- return false;
- }
- if(ssoId === undefined || ssoId === '') {
- showValidError('账号有误!', $('#code'));
- return false;
- }
- if($.trim(code) === '') {
- showValidError('验证码不能为空!', $('#code'));
- return false;
- }
- $.ajax({
- url: '/sms/mobile',
- type: 'post',
- data: {ssoId: ssoId, mobile: mobile, code: code},
- error: function() {
- showValidError('接口出错!',$('#code'));
- },
- beforeSend: function() {
- },
- success: function(response) {
- if (response.err === 0) {
- $("#login").click();
- $('#phone').modal('hide');
- } else {
- showValidError(response.msg,$('#code'));
- }
- }
- })
- });
- });
- /**
- * 获取成功后的操作
- *
- * @param {Object} btn - 点击的按钮
- * @return {void}
- */
- function codeSuccess(btn) {
- let counter = 60;
- btn.removeClass('btn-primary').addClass('btn-outline-secondary disabled').text(counter + '秒 重新获取');
- btn.parents().siblings('div').children('input').removeAttr('readonly');
- const countDown = setInterval(function() {
- const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + '秒 ';
- // 倒数结束后
- if (countString === '') {
- clearInterval(countDown);
- btn.removeClass('btn-outline-secondary disabled').addClass('btn-primary').text('获取验证码');
- }
- const text = countString + '重新获取';
- btn.text(text);
- counter -= 1;
- }, 1000);
- }
- /**
- * 验证手机号是否正确
- *
- * @return {boolean}
- */
- function validMobile(mobile) {
- let result = true;
- if($.trim(mobile) === ''){
- showValidError('手机号不能为空!',$('#mobile'));
- return false;
- }
- let mobileValid = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/;
- if(!mobileValid.test(mobile)){
- showValidError('手机号码格式有误!',$('#mobile'));
- return false;
- }
- return result;
- }
- /**
- * 提示验证信息错误
- *
- * @param {string} msg
- * @param {object} element
- * @return {void}
- */
- function showValidError(msg, element) {
- if (element !== null) {
- element.addClass('is-invalid');
- element.siblings().text(msg);
- }
- }
- /**
- * 清除验证信息错误提示
- *
- * @return {void}
- */
- function cleanValidError(element) {
- element.removeClass('is-invalid');
- element.siblings().text('');
- }
- /**
- * 验证数据
- *
- * @return {boolean}
- */
- function valid() {
- let result = true;
- let account = $("#inputEmail").val();
- if (account === undefined || account === '') {
- showError('用户名不能为空!', $("#inputEmail"));
- return false;
- }
- let password = $("#inputPassword").val();
- if (password === undefined || password === '') {
- showError('密码不能为空!', $("#inputPassword"));
- return false;
- }
- return result;
- }
- /**
- * 提示错误
- *
- * @param {string} msg
- * @param {object} element
- * @return {void}
- */
- function showError(msg, element) {
- if (element !== null) {
- element.parent().addClass('has-danger');
- }
- $("#message").text(msg);
- $("#error-tips").show("fast");
- }
- /**
- * 清除错误提示
- *
- * @return {void}
- */
- function cleanError() {
- $("input").parent().removeClass('has-danger');
- $("#message").text('');
- $("#error-tips").hide("fast");
- }
- /**
- * 设置版本信息
- *
- * @param {Object} versionData
- * @return {void}
- */
- function setVersion(versionData) {
- let html = '';
- for (let version of versionData) {
- let description = version.description ? version.description : '介绍内容';
- let tmpHtml = '<div class="col-sm-6">' +
- '<div class="card card-block">' +
- '<div class="card-body">' +
- '<h3 class="card-title">'+ version.name +'</h3>' +
- '<p class="card-text">' + description + '</p>' +
- '<a class="btn btn-primary" href="/boot/'+ version._id.toString() +'">开始使用</a>' +
- '</div>' +
- '</div>' +
- '</div>';
- html += tmpHtml;
- }
- $("#version-area").html(html);
- }
|