| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 | /** * admin 后台js * *///字符串为空function isNull(str) {    if (str == null || str == "" || str.length < 1)        return true;    else        return false;}//获取 str 字符长度,中文单字2字符,英文1字符Ffunction getblen(str) {    var l = str.length;    var blen = 0;    for (i = 0; i < l; i++) {        if ((str.charCodeAt(i) & 0xff00) != 0) {            blen++;        }        blen++;    }    return blen;}//textarea 字数提示function textarealength(obj, toplength) {    var note = $(obj).val();    var blen = getblen(note);    if (blen <= toplength) {        $(".textarea-length").html(blen);    } else {        $(".textarea-length").css('color', 'red');        $(".textarea-length").html(blen);    }}// js 正则验证邮箱function testEmail(strEmail) {    var myReg = /^[-a-z0-9\._]+@([-a-z0-9\-]+\.)+[a-z0-9]{2,3}$/i;    if (myReg.test(strEmail)) return true;    return false;}//检测邮箱格式function emailFormat(email) {    return email.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/) ? true : false;}//检测手机格式function phoneFormat(phone) {    return phone.match(/^1(3|4|5|6|7|8)\d{9}$/) ? true : false;}//检测密码规则--6位以上function pwdFormat(pwd) {    return pwd.match(/^.*(?=.{6,})/) ? true : false;}//检测密码规则--6位以上数字字母组合function pwdFormat6Mix(pwd) {    return pwd.match(/^.*(?=.{5,})(?=.*\d)(?=.*[a-z]).*$/) ? true : false;}//必须字母开头,长度在6-18之间,只能包含字符(或下划线)、数字function pwdFormat6MixNew(pwd) {    return pwd.match(/^[a-zA-Z]\w{5,17}$/) ? true : false;}// 删除条目function del(obj, id) {    layer.confirm('确认要删除吗?', function (index) {        $.post('delete', {            'id': id        }, function (res) {            if (res.code == 0) {                $(obj).parents("tr").remove();                topalert({                    type: 0,                    content: res.msg,                    speed: 1000                });            } else {                topalert({                    type: 2,                    content: res.msg,                    speed: 2000                });            }            layer.close(layer.index);        }, 'json');    });}//列表多选删除条目function del_all() {    var checkbox = $('.text-c input[name="checkbox[]"]');    var ids = new Array();    checkbox.each(function (x) {        if (this.checked)            ids.push(this.value);    })    var length = ids.length;    if (length == 0) {        layer.msg('请选择要删除的选项', {            icon: 5,            time: 1000        });        return false;    }    layer.confirm('确认要删除选中项吗?', function (index) {        $.post('delete', {            'id': ids        }, function (data) {            if (data.code == 0) {                layer.msg(data.msg, {                    icon: 1,                    time: 2000                });                window.location.reload();            } else {                layer.msg(data.msg, {                    icon: 5,                    time: 2000                });                return false;            }        }, 'json');    });}// 右上角提示框function topalert(options, callback) {    var defaults = {        type: 0,        content: '弹窗内容',        speed: "0",    };    var types = ['success', 'danger', 'error', 'info'];    var options = $.extend(defaults, options);    var length = $('.topalert').length;    var htmlstr = '<div class="Huialert Huialert-' + types[defaults.type] + ' topalert topalert' + length + '"><i class="Hui-iconfont"></i>' + options.content + '</div>';    if (options.speed == 0) {        $(document.body).addClass("modal-open").append(htmlstr);        $(".topalert" + length).fadeIn();    } else {        $(document.body).addClass("modal-open").append(htmlstr);        $(".topalert" + length).fadeIn();        setTimeout(function () {            $(".topalert" + length).fadeOut("normal", complete => {                $(".topalert" + length).remove();            });        }, options.speed);    }    if (callback) {        callback();    }}$(function () {    // 全选    $("input[name='allcheck']").change(function (e, x) {        // console.log(this.checked);        if (this.checked) {            $('.text-c input[name="checkbox[]"]').prop("checked", true);        } else {            $('.text-c input[name="checkbox[]"]').prop("checked", false);        }    })    // 图片预览    $('.pictureview').hover(function () {        console.log($(this).children('img').attr('src'));        var url = $(this).children('img').attr('src');        var img = '<img class="thumbnail" id="thumbview" src="' + url + '">';        $(this).append(img);    }, function () {        $('#thumbview').remove();    });    // 改变状态    $('.td-status .switch').on('switch-change', function () {        var id = $(this).data('id');        var data = {            'id': parseInt(id)        };        $.post('status', data, function (res) {            if (res.code == 0) {                topalert({                    type: 0,                    content: res.msg,                    speed: 1000                });            } else {                topalert({                    type: 1,                    content: res.msg,                    speed: 1000                });                return false;            }        }, 'json');    });    // 排序    $(".input-sort").change(function () {        var sort = $(this).val();        var id = $(this).data('id');        console.log(id);        console.log(sort);        $.post('sort', {            'id': id,            'sort': sort        }, function (res) {            if (res.code == 0) {                topalert({ type: 0, content: res.msg, speed: 2000 });            } else {                topalert({ type: 1, content: res.msg, speed: 2000 });                return false;            }        }, 'json');    });});
 |