123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- if (window !== top) {
- top.location.href = location.href;
- }
- layui.use(['request', 'form', 'button', 'yaml'], function() {
- var $ = layui.jquery,
- request = layui.request,
- form = layui.form,
- button = layui.button,
- yaml = layui.yaml;
- var URL = yaml.load("config/cool.config.yml").admin.url;
- var PKI;
- //刷新验证码
- window.captcha = function() {
- $.get(request.getAdminServerUrl() +'/guest/captcha?' + Math.random(), function (res) {
- if (res.success) {
- $('[name="key"]').val(res.data.key);
- $("#captchaImage").attr('src', res.data.image);
- }
- });
- };
- //init
- layer.ready(function() {
- layui.data('server',
- null);
- layui.data('server', {
- key: 'url',
- value: URL
- });
- layui.data('server', {
- key: 'login',
- value: location.href
- });
- //初始化 RSA_PUBLIC_KEY
- $.get(request.getAdminServerUrl() +'/guest/pki', function (res) {
- if (res.success) {
- PKI = res.data;
- }
- });
- //初始化化验证码
- window.captcha();
- });
- //表单提交
- form.on('submit(login)', function (data) {
- var btn = button.load({elem: '.login'});
- data.field.captcha = $('#captcha').val();
- data.field.password = encrypt(data.field.password);
- request.http({
- url: '/login',
- data: data.field,
- type: "post",
- dataType: 'json',
- sendToken: false,
- success: function (res) {
- btn.stop(function() {
- if (res.success) {
- layui.data('server', {
- key: 'accessToken',
- value: {name:'accessToken', value: res.data.accessToken}
- });
- layui.data('server', {
- key: 'permissions',
- value: res.data.permissions
- });
- button.load({elem: '.login', time: 200,
- done: function () {
- location.href = "index.html"
- }
- });
- } else {
- captcha();
- $(".sign").hide();
- $(".error").show().html(res.msg);
- }
- })
- }
- });
- return false;
- });
- //清空input
- window.empty = function(name) {
- $('[name="' + name + '"]').val('');
- };
- //RSA加密
- window.encrypt = function (data) {
- if (PKI) {
- var r = new JSEncrypt();
- r.setPublicKey('-----BEGIN PUBLIC KEY-----' + PKI + '-----END PUBLIC KEY-----');
- return r.encrypt(JSON.stringify(data));
- } else {
- layer.msg("password rsa error");
- return false;
- }
- };
- });
|