//忽略所有JS错误
    //function killerrors() { return true; }
    //window.onerror = killerrors;
//忽略错误结束,加载页面JS执行

layui.define(['jquery', 'layer'], function (exports) {
    var $ = layui.jquery;
    window.$ = $;
    window.jQuery = $;
    window.layui = layui;

    var basic = new function () {
        var layui = this;
        layui.$root_url = "/yntsys/";
        layui.$api_url = "http://localhost:50012"; //登录API
        layui.$Basicapi_url = "http://localhost:50013"; //基础服务接口
        layui.$Kapi_url = "http://localhost:50014"; //幼儿园业务

        //layui.$api_url = "http://47.109.29.153:50012"; //登录API
        //layui.$Basicapi_url = "http://47.109.29.153:50013"; //基础服务接口
        //layui.$Kapi_url = "http://47.109.29.153:50014"; //幼儿园业务
        //$token = sessionStorage.getItem("token");
        layui.$token1 = sessionStorage.getItem("token"); //与API交互
        layui.$token2 = sessionStorage.getItem("ss_admin_access_token"); //与原框架交互
        layui.$jgid = sessionStorage.getItem("jgid"); //机构ID

        layui.PER_PAGE = 30;
        layui.ADMIN_ACCESS_TOKEN_NAME = "ss_admin_access_token";
        layui.USER_ACCESS_TOKEN_NAME = "ss_user_access_token";
        layui.DEFAULT_AVATAR_URL = '/sitefiles/assets/images/default_avatar.png';
        layui.$type = "admin";

        try {
            layui.scripts = document.getElementsByTagName("script");
            layui.dataValue = scripts[scripts.length - 1].getAttribute("data-type");
            if (dataValue) $type = dataValue;
        } catch (e) {
        }

        layui.$apiUrl = "/api/admin";
        layui.$rootUrl = "/ss-admin";
        layui.$token =
            sessionStorage.getItem(layui.ADMIN_ACCESS_TOKEN_NAME) ||
            localStorage.getItem(layui.ADMIN_ACCESS_TOKEN_NAME);

        if (layui.$type === "user") {
            layui.$apiUrl = "/api/home";
            layui.$rootUrl = "/home";
            layui.$token = localStorage.getItem(layui.USER_ACCESS_TOKEN_NAME);
        }
    };

    //alert("获取到token：" + $token);

    //此处会造成死循环，必须把登录页排除掉
    if (basic.$token == null) {
        //top.location.href = "/ss-admin/login";
    }

    if (window.axios) {
        layui.$_api = axios.create({
            baseURL: $api_url,
            headers: {
                Authorization: "Bearer "+$token
            }
        });
    }

    //全局ajax设置
    $.ajaxSetup({
        //timeout: 60000, //设置接口超时时间，默认60秒。
        //请求失败遇到异常触发
        error: function (XMLHttpRequest, status, e) {
            console.info(XMLHttpRequest.responseText);
            // alert("err");
        },
        //发送请求前触发
        beforeSend: function (xhr) {
            //可以设置自定义标头
            xhr.setRequestHeader('Authorization', "Bearer " + layui.basic.$token1);
            xhr.setRequestHeader('jgid', sessionStorage.getItem("jgid"));
            xhr.setRequestHeader('auth', sessionStorage.getItem("pc"));
        }
    });

    //配置搜索筛选二次加载列表
    this.loadtable = function () {
        mainTable.reload();
    }
    //父页面弹出框
    this.openPLayer = function (title, content, fn) {
        parent.layer.open({
            type: 2,
            title: title,
            shadeClose: true,
            maxmin: true,
            shade: 0.8,
            area: ['95%', '98%'],
            content: content,
            //btn: '关闭返回',
            yes: function (index, layero) {
                // debugger;
                //parent.location.reload();
                layer.msg('添加结束！');
                if (fn) fn(layero);
                parent.layer.close(index);
            },
            cancel: function (index) {
                parent.layer.close(index);
                location.reload();
            },
            end: function () {
                if (fn) fn();
            }
        });
    }
    //弹出框
    this.openSLayer = function (title, content, fn) {
        layer.open({
            type: 2,
            title: title,
            shadeClose: true,
            maxmin: true,
            shade: 0.8,
            area: ['95%', '98%'],
            content: content,
            //btn: '关闭返回',
            yes: function (index, layero) {
                //debugger;
                //layer.msg('添加结束！');
                if (fn) fn(layero);
                layer.close(index);
            },
            cancel: function (index) {
                layer.close(index);
            },
            end: function () {
                if (fn) fn();
            }
        });
    }
    //div弹出框
    this.openDLayer = function (title, content, fn) {
        layer.open({
            type: 1,
            title: title,
            shadeClose: true,
            maxmin: true,
            shade: 0.8,
            area: ['95%', '98%'],
            content: content,
            //btn: '关闭返回',
            yes: function (index, layero) {
                if (fn) fn(layero);
                layer.close(index);
            },
            cancel: function (index) {
                layer.close(index);
            }
        });
    }
    //删除数据
    this.removeList = function (delapi, datas, fn) {
        AjaxPost(
            delapi,
            datas,
            function (res) {
                if (!res.iserror) {
                    layer.msg(res.message);
                    if (fn) fn(res);
                }
            }
        );
    }
    exports('basic', basic);
});




