jq 前端common工具

String.prototype.capitalizeFirstLetter = function () {
return this.charAt(0).toUpperCase() + this.slice(1);
};

// 跳转页面
var flags = true;
// function jumpPage(href, type) {
// if (flags) {
// JYJSInterface.openNewPage(’’, 0, 0, “www/” + href, 0, ‘’);
// } else {
//
// if (type == ‘address’) {
// // iotCache.setItem(‘prevHref’, location.href);
// location.replace(href);
// // console.log(1);
// } else {
// location.href = href;
// }
// }
// }
function jumpPage(href, title, type) {
iotCache.setItem(‘prevHref’, location.pathname);
if (flags) {
gotoNagivatePage(href, title);
} else {
// location.href = href;
if (sysCommon.isNull(type)) {
type = “”;
}
if (type == ‘address’) {
// iotCache.setItem(‘prevHref’, location.href);
location.replace(href);
// console.log(1);
} else {
location.href = href;
}
}
}

// 关闭页面
// function closePage(href) {
// if (flags) {
// JYJSInterface.closePage(’’);
// } else {
// if (href != null) {
// // iotCache.setItem(‘prevHref’, location.href);
// location.replace(href);
// // console.log(1);
// } else {
// history.go(-1);
// }
// }
// }

function closePage(page, tag) {
// var page = iotCache.getItem(‘prevHref’);
if (flags) {
if (sysCommon.isNull(tag)) {
tag = “”;
}
gotoBack(tag, page);
} else {
// location.href = page;
if (href != null) {
// iotCache.setItem(‘prevHref’, location.href);
location.replace(href);
// console.log(1);
} else {
// history.go(-1);
window.opener=null;
window.open(’’,’_self’);
window.close();
}
}
}

$(‘body’).on(‘click’, ‘.js_return’, function () {
closePage();
})

//配置
var sysConfig = {
title: “”,
“defaultCity”: “山东/济南”,
“pageSize”: “20”, //每次请求多少条数数据
gridConfig: {
imgPath: “lib/imgs/”,
skin: “dhx_terrace”
},
“Debug”: true,
“AutoLoad”: false,
iCheckOptions: {
checkboxClass: ‘icheckbox_square-green’,
radioClass: ‘iradio_square-green’,
increaseArea: ‘20%’ // optional
}
};

//全局静态变量
var sysStatic = {
LoadType: {
“load”: 1,
“refresh”: 2,
“loadMore”: 3,
“loop”: 4
},
YESNO: {
“YES”: 1,
“NO”: 0,
“NONE”: -1
}

};
//错误类型
var sysErrorType = {
“GridDivIDNotNull”: “表格ID未配置”,
“GridHeaderNotNull”: “表格标题未配置”,
“GridColTypeNotNull”: “表格列类型未配置”,
};

//返回顶部
function sysScollTop() {
this.b = function () {
h = $(window).height() - 500,
t = $(document).scrollTop(),
t > h ? $("#moquu_top").show() : KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲moquu_top").hid…(this).scrollTop() > 58) {
$(".templatemo-nav").addClass(“sticky”)
} else {
$(".templatemo-nav").removeClass(“sticky”)
}
}

this.init = function () {
    var that = this;

    $(window).scroll(function () {
        that.b(),
            that.n()
    });

    that.b(),
        that.n();
}

$("#moquu_top").click(function () {
    $(document).scrollTop(0);
});

}

//全局方法
function _sysCommon() {
var that = this;
//获取URL参数
this.getUrlParam = function (name) {
var reg = new RegExp("(^|&)" + name + “=([^&]*)(&|KaTeX parse error: Expected 'EOF', got '}' at position 176: …l; //返回参数值 }̲ this.getUr…)”); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return decodeURI(r[2]);
return null; //返回参数值
}
//登录失败处理cookie
this.SetErroLoginCookie = function () {
if (sysCookie.CheckCookie(“adminAccess_token”)) {
sysCookie.DeleteCookie(“adminAccess_token”);
}
if (sysCookie.CheckCookie(“isSaveCookie”) && 1 == sysCookie.GetCookie(“isSaveCookie”)) {
//保存用户名密码
} else {
//清楚cookie
sysCookie.ClearCookie();
}
}
//ajax
this.ajax = function (args, url, fn, completeFn) {
try {
$.ajax({
type: “post”,
async: true,
data: args,
url: url,
dataType: “json”,
success: function (result) {
// var success = eval(result.status) == 1;
try {
if (result.type == ‘notLogin’) {
logout();
}
} catch (e) {

                }
                fn(result);
            },
            error: function (xml, error, exception) {
                that.showAlert("网络连接错误,请检查网络" + xml.status);
                //                    alert(xml.status + ":" + xml.readyState + ":" + error + ":" + exception)
                // that.showAlert(xml.status + ":" + xml.readyState + ":" + error + ":" + exception);
            },
            complete: function () {
                completeFn && completeFn();
            }
        });
    } catch (e) {
        that.showAlert(e.message);
    }

}

this.syncAjax = function (args, url, fn) {
    args.sysCustomer = Constant.sysCustomer;
    args.token = iotCache.getItem(Constant.userToken);
    args.resourceUrl = sysURL.delplyUrl;
    try {
        $.ajax({
            type: "post",
            async: false,
            data: args,
            url: url,
            dataType: "json",
            success: function (data) {
                try {
                    if (result.type == 'notLogin') {
                        logout();
                    }
                } catch (e) {

                }
                fn(data);
            },
            error: function (xml, error, exception) {
                that.showAlert(xml.status + ":" + xml.readyState + ":" + error + ":" + exception);
            }
        });
    } catch (e) {
        that.showAlert(e.message);
    }
}

//alert
this.showAlert = function (message) {
    layer.msg(message, {
        time: 2000
    });
}
//成功信息
this.showSuccess = function (message) {
    layer.msg(message, {
        icon: 1,
        skin: 'layui-layer-molv'
    }); //对号
}
//错误信息
this.showError = function (message) {
    layer.msg(message, {
        icon: 5,
        shift: 6,
        skin: 'layui-layer-molv'
    }); //哭脸
}
//提示信息
this.showInfo = function (message) {
    layer.msg(message, {
        icon: 7,
        skin: 'layui-layer-molv'
    }); //叹号
}
//confim
this.showConfim = function (message, callback, cancelCallback) {
    layer.confirm(message, {
        icon: 3,
        title: '提示'
    }, function (index) {
        if (true == that.exeFunction(callback)) {
            layer.close(index);
        }
    }, function () {
        that.exeFunction(cancelCallback);
    });
}

//弹出iframe
this.PopWindow = function (url, title, size, cancelCallback, externalfunction) {
    var area = {
        w: $(window).width() - 30 + "px",
        h: $(window).height() - 30 + "px"
    };
    if (!that.isNull(size)) {
        area.w = size.width
        area.h = size.height;
    }
    //iframe窗
    return layer.open({
        type: 1,
        title: title,
        closeBtn: true,
        //shade: [0],
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        area: [area.w, area.h],
        content: url,
        success: function () { //层弹出后的成功回调方法
            that.exeFunction(externalfunction);
        },
        yes: function (index, layero) { //该回调携带两个参数,分别为当前层索引、当前层DOM对象
            //do something
            //如果设定了yes回调,需进行手工关闭
            if (false == that.exeFunction(cancelCallback)) {
                return false;
            } else {
                layer.close(index);
            }
        },
        cancel: function (index) { //该回调同样只携带当前层索引一个参数,无需进行手工关闭。如果不想关闭,return false即可,如 cancel: function(index){ return false; } 则不会关闭;
            if (false == that.exeFunction(cancelCallback)) {
                return false;
            } else {
                layer.close(index);
            }
        }
    });
}
//弹出内容
this.PopContent = function (content, size, cancelCallback, externalfunction) {
    var area = {
        w: $(window).width() / 2 + "px",
        h: $(window).height() / 3 * 2 + "px"
    };
    if (!that.isNull(size)) {
        area.w = size.width;
        area.h = size.height;
    }
    return layer.open({
        type: 1,
        title: false,
        closeBtn: true,
        area: [area.w, area.h],
        //skin: 'layui-layer-nobg', //没有背景色
        shadeClose: true,
        content: content,
        success: function () { //层弹出后的成功回调方法
            that.exeFunction(externalfunction);
        },
        yes: function (index, layero) { //该回调携带两个参数,分别为当前层索引、当前层DOM对象
            //do something
            //如果设定了yes回调,需进行手工关闭
            if (false == that.exeFunction(cancelCallback)) {
                return false;
            } else {
                layer.close(index);
            }
        },
        cancel: function (index) { // 该回调同样只携带当前层索引一个参数,无需进行手工关闭。如果不想关闭,return false即可,如 cancel: function(index){ return false; } 则不会关闭;
            if (false == that.exeFunction(cancelCallback)) {
                return false;
            } else {
                layer.close(index);
            }
        }
    });
}

this.ClosePop = function (obj) {
    layer.close(obj);
}

//判断是否为空 为空返回true
this.isNull = function (obj) {
    if (null == obj || undefined == obj || "" == obj || "undefined" == obj || "undefined" == typeof(obj) || "null" == obj) {
        return true;
    } else {
        return false;
    }
}
//判断是否为空  不为空返回true
this.isNotNull = function (obj) {
    if (that.isNull(obj)) {
        return false;
    } else {
        return true;
    }
}
//获取友好字符串(如果是null或者是undefined则为空字符串)
this.getFirendStr = function (str) {
    try {
        if (sysCommon.isNull(str)) {
            return "";
        } else {
            return str;
        }
    } catch (e) {
        console.log(e.message);
        return "";
    }
}

//判断是否是函数并 执行
this.exeFunction = function (fun) {
    if ("function" == typeof(fun)) {
        return fun();
    }
    return true;
}
//服务端返回错误
this.showErrorMsg = function (result) {
    if (!this.isNull(result.error)) {
        this.showAlert(result.error);
    } else {
        this.showAlert(result.info);
    }
}

//获取元素内容
this.getInnerText = function (element) {
    return (typeof element.textContent == "string") ? element.textContent : element.innerText;
}

//设置元素的内容
this.setInnerText = function (element, text) {
    if (typeof element.textContent == "string") {
        element.textContent = text;
    } else {
        element.innerText = text;
    }
}

//两种获取guid的方法-1
this.guid = function () {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0,
            v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}

//两种获取guid的方法-2
this.uuid = function () {
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");
    return uuid;
}

this.getNowDateTime = function () {
    var date = new Date();
    var month = date.getMonth() + 1
    if (month < 10) {
        month = "0" + month;
    }
    var day = date.getDate();
    if (day < 10) {
        day = "0" + day;
    }
    return date.getFullYear() + "-" + month + "-" + day + " " + (date.getHours() < 10 ? ("0" + date.getHours()) : date.getHours()) + ":" + (date.getMinutes() < 10 ? ("0" + date.getMinutes()) : date.getMinutes()) + ":" + (date.getSeconds() < 10 ? ("0" + date.getSeconds()) : date.getSeconds());
}


this.getNowDate = function () {
    var date = new Date();
    var month = date.getMonth() + 1
    if (month < 10) {
        month = "0" + month;
    }
    var day = date.getDate();
    if (day < 10) {
        day = "0" + day;
    }
    return date.getFullYear() + "-" + month + "-" + day;
}

this.dateFormet = function (timesta) {
    if (sysCommon.isNull(timesta)) {
        return "";
    }
    if (timesta > 24 * 60 * 60 * 1000) {
        return parseInt(timesta / (24 * 60 * 60 * 1000)) + "天" + parseInt((timesta % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)) + "小时"
    } else if (timesta > 60 * 60 * 1000) {
        return parseInt(timesta / (60 * 60 * 1000)) + "小时" + parseInt((timesta % (60 * 60 * 1000)) / (60 * 1000)) + "分"
    } else {
        return parseInt(timesta / (60 * 1000)) + "分";
    }
}

this.getStratTime = function (day) {
    var oneday = new Date();
    oneday.setHours(0);
    oneday.setMinutes(0);
    oneday.setSeconds(0);
    oneday.setMilliseconds(0);

    return oneday.getTime() + day * 24 * 60 * 60 * 1000;
}

//获取字符串时间的时间戳
//"2014-07-10 10:21:12"
this.GetTimesTamp = function (stringTime) {
    // 获取某个时间格式的时间戳
    if (that.isNull(stringTime)) {
        that.showError("字符串时间为空");
        return;
    }
    //return Date.parse(new Date(stringTime));


    var date = "2015-03-05 17:59:00.0";
    date = date.substring(0, 19);
    //date = date.replace(/-/g, "/");
    var timestamp = new Date(date).getTime();
    return timestamp;

    //2014-07-10 10:21:12的时间戳为:1404958872
    // console.log(stringTime + "的时间戳为:" + timestamp2);
}


//时间戳转为时间
this.GetDateTime4Timestamp = function (timestamp) {
    var date = new Date(timestamp);
    var Y = date.getFullYear();
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours());
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s;
};

this.GetDateTime4Timestamps = function (timestamp) {
    var date = new Date(timestamp);
    var Y = date.getFullYear();
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours());
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return h + ':' + m + ':' + s;
}

this.GetDateTime4Timestamps_2 = function (timestamp) {
    var date = new Date(timestamp);
    var Y = date.getFullYear();
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
    return Y + '-' + M + '-' + D;
}

this.GetDateTime4Timestamps_3 = function (timestamp) {
    var date = new Date(timestamp);
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours());
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
    return M + '-' + D + ' ' + h + ':' + m;
}

//隐藏控件
this.HideObj = function (obj) {
    try {
        if (this.isNotNull(obj)) {
            obj[0].style.display = "none";
        }
    } catch (e) {
        console.log(e.message);
    }
}
//显示控件
this.ShowObj = function (obj) {
    try {
        if (this.isNotNull(obj)) {
            obj[0].style.display = "";
        }
    } catch (e) {
        console.log(e.message);
    }
}
//滚动到底部自动加载更多
this.ScrollLoadMore = function (callback) {
    try {
        var that = this;
        $(window).scroll(function () {
            var scrollTop = $(this).scrollTop();
            var scrollHeight = $(document).height();
            var windowHeight = $(this).height();
            if (scrollTop + windowHeight == scrollHeight) {

                //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
                that.exeFunction(callback);


                //var page = Number($("#redgiftNextPage").attr('currentpage')) + 1;
                //redgiftList(page);
                //$("#redgiftNextPage").attr('currentpage', page + 1);

            }
        });

    } catch (e) {
        console.log(e.message);
    }

}

//返回顶部
this.ScrollTop = function () {
    $(document).scrollTop(0);
}

//设置定时器
this.SetInterval = function (fun, millisec) {
    var int = self.setInterval(function () {
        that.exeFunction(fun);
    }, millisec);
    return int;


}
//取消定时器
this.CancelInterval = function (int) {
    var ints = window.clearInterval(int);
    return ints;
}

//日志
this.ShowLog = function (msg) {
    if (sysConfig.Debug) {
        console.log(this.getNowDateTime() + ": " + msg);
    }
}

// 是否微信
this.isWx = function () {
    return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1
}

};
var sysCommon = new _sysCommon();

//左侧导航栏组件
function sysLeftNavBar(json) {
this.id = json.id;
this.count = json.length;
this.items = [];
this.showRIcon = json.showRIcon == undefined ? false : json.showRIcon;
var that = this;

function init() {
    for (var i = 0; i < json.data.length; i++) {
        var id = json.data[i].id == "" ? sysCommon.guid() : json.data[i].id;
        var fn = json.data[i].fn == "" ? "" : ("onclick='" + json.data[i].fn + "();'");
        $("#" + that.id).append('<a href="' + json.data[i].href + '" id="' + id + '" class="list-group-item"  ' + fn + ' name="' + json.data[i].name + '">' + json.data[i].span + '</a>');
        that.items.push({
            "id": $("#" + id)[0].id,
            name: json.data[i].name
        });
    }
    $("#" + that.id + " a").bind("click", function () {
        $(this).addClass("active").siblings().removeClass("active");
        if (undefined != json.rightTtID && "" != json.rightTtID) {
            if (true == that.showRIcon) {
                $("#" + json.rightTtID).html($("#" + this.id)[0].innerHTML);
            } else {
                sysCommon.setInnerText($("#" + json.rightTtID)[0], sysCommon.getInnerText($("#" + this.id)[0]));
            }
        }
    });

}

init();

}

//右侧panel
function sysRightPanel(title, body, confimFunc, cancelFunc, externalfunction) {
var that = this;
if (!sysCommon.isNull($("#yhaiRightPanel"))) {
KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲yhaiRightPanel"…(document.body).append(html);
$("#gridboxDIV").append(html);
//确定按钮事件
$("#yhaiRightPanelConfim").unbind(“click”);
$("#yhaiRightPanelConfim").click(function () {
if (sysCommon.exeFunction(confimFunc)) {
$("#yhaiRightPanel")[0].style.display = “none”;
$("#yhaiRightPanel").remove();
}
});
//取消按钮事件
$("#yhaiRightPanelCanl").unbind(“click”);
$("#yhaiRightPanelCanl").click(function () {
if (sysCommon.exeFunction(cancelFunc)) {
$("#yhaiRightPanel")[0].style.display = “none”;
$("#yhaiRightPanel").remove();
}
});
this.close = function () {
$("#yhaiRightPanel")[0].style.display = “none”;
$("#yhaiRightPanel").remove();
}

if ("function" == typeof(externalfunction)) {
    try {
        externalfunction();
    } catch (e) {
        console.log(e.message);
    }
}

}

//构造表格
function sysXGrid(g) {
this.divID = g.divID == undefined ? sysCommon.showError(yhaiErrorType.GridDivIDNotNull) : g.divID;
this.header = g.header == undefined ? sysCommon.showError(yhaiErrorType.GridHeaderNotNull) : g.header;
this.colWidth = g.colWidth == undefined ? “” : g.colWidth;
this.colAlign = g.colAlign == undefined ? “” : g.colAlign;
this.colTypes = g.colTypes == undefined ? sysCommon.showError(yhaiErrorType.GridColTypeNotNull) : g.colTypes;
this.colSorting = g.colSorting == undefined ? “” : g.colSorting;
this.data = (g.data == undefined || g.data == null || g.data == “”) ? [] : {
rows: g.data
};
this.attachEvent = g.attachEvent == undefined ? null : g.attachEvent;

//初始化表格
var myGrid = new dhtmlXGridObject(this.divID);
myGrid.setImagePath(sysConfig.gridConfig.imgPath); //设置图片路径
myGrid.setSkin(sysConfig.gridConfig.skin); //设置自定义皮肤
myGrid.setHeader(this.header); //设置标题
myGrid.setInitWidths(this.colWidth); //设置初始列宽
myGrid.setColAlign(this.colAlign); //设置对齐方式
myGrid.setColTypes(this.colTypes); //设置列类型
myGrid.setColSorting(this.colSorting); //设置列排序类型
myGrid.selMultiRows = true;
//myGrid.setColumnColor("#CCE2FE");
//myGrid.attachEvent("onRowSelect", doOnRowSelect);//设置选中行事件
if (null != this.attachEvent) {
    $.each(this.attachEvent, function (key, value) {
        myGrid.attachEvent(value[0], value[1]); //设置选中行事件
    });
}
myGrid.enableRowsHover(true, 'grid_hover'); //设置行hover样式
myGrid.enableAlterCss("even", "uneven"); //间隔样式
myGrid.init(); //初始化表格
// myGrid.load(this.data, this.dataType);//加载数据
myGrid.parse(this.data, "json");


return myGrid;

}

//弹出模态框
var sysModal = function (title, body, confimfn, cancelfn, islg, externalfunction) {
if ($("#myModal") && $("#myModal").length > 0) {
$("#myModal").remove();
}
//是否大模态框
var lg = “”;
if (true == islg) {
lg = “modal-lg”;
}
var html = ’

’;
$(document.body).append(html);
$(’#myModal’).modal({
keyboard: true
});

//确定按钮事件
$("#btnConfim").unbind("click");
$("#btnConfim").click(function () {
    if ("function" == typeof(confimfn)) {
        if (true == confimfn()) {
            $('#myModal').modal('hide');
        }
    } else {
        $('#myModal').modal('hide');
    }
});
//取消按钮事件
$("#btnCanl").unbind("click");
$("#btnCanl").click(function () {
    if ("function" == typeof(cancelfn)) {
        if (true == cancelfn()) {
            $('#myModal').modal('hide');
        }
    } else {
        $('#myModal').modal('hide');
    }
});

//展示模态框
$('#myModal').modal({
    keyboard: true
});

if ("function" == typeof(externalfunction)) {
    try {
        externalfunction();
    } catch (e) {
        console.log(e.message);
    }
}

}

function sysTree(divID, data, clickfn) {

var IDMark_Switch = "_switch";
var IDMark_Icon = "_ico";
var IDMark_Span = "_span";
var IDMark_Input = "_input";
var IDMark_Check = "_check";
var IDMark_Ul = "_ul";
var IDMark_A = "_a";
var setting = {
    edit: {
        enable: true,
        showRemoveBtn: false,
        showRenameBtn: false
    },
    data: {
        key: {
            //itle: "m",
            // name: "text",
            //url: "u"
        },
        simpleData: {
            enable: true
        }
    },
    view: {
        showLine: false,
        addHoverDom: addHoverDom,
        removeHoverDom: removeHoverDom
    },
    callback: {
        onClick: onClick
    }
};


//点击树节点事件
function onClick(event, treeId, treeNode, clickFlag) {
    if ($(".paddTee").length > 0 && $("#diyBtn3_" + treeNode.id).length <= 0) {
        $(".paddTee").unbind().remove();
    }
    $("#gridTitleName").html(treeNode.name);
    if ("function" == typeof(clickfn)) {
        clickfn();
    }
}

//hover节点下拉功能按钮
function addHoverDom(treeId, treeNode) {
    if (treeNode.parentNode && treeNode.parentNode.id != 1) return;
    var aObj = $("#" + treeNode.tId + IDMark_A);
    //1. 设置按钮
    if ($("#diyBtn1_" + treeNode.id).length > 0) return;
    var editStr = "<a id='diyBtn1_" + treeNode.id + "' style='margin:0 0 0 0px; background-color: #fff;padding-left:5px;'>设置</a>";
    aObj.append(editStr);
    var btn = $("#diyBtn1_" + treeNode.id);
    if (btn) btn.bind("click", function () {
        var editStr = '<div class="paddTee" id="diyBtn3_' + treeNode.id + '"> <span data-type="next">新建下级部门</span> <span  data-type="level">新建平级部门</span> <span class="line"></span> <span data-type="edit">编辑部门</span> <span data-type="disable">停用部门</span> <span data-type="delete">删除部门</span> </div>';
        //当为树根节点时只有新建下级
        if (null == treeNode.pId) {
            editStr = '<div class="paddTee" style="margin-left:75px;" id="diyBtn3_' + treeNode.id + '"> <span style="font-size:10pt;font-weight:normal;" data-type="next">新建下级部门</span> </div>';
        }
        if (treeNode.parentNode && treeNode.parentNode.id != 1) return;
        var aObj = $("#" + treeNode.tId + IDMark_A);
        if ($(".paddTee").length > 0 && $("#diyBtn3_" + treeNode.id).length <= 0) {
            $(".paddTee").unbind().remove();
        }
        if ($("#diyBtn3_" + treeNode.id).length > 0) return;

        aObj.append(editStr);
        thisID = treeNode.id;
        btnFunc(treeNode);
    });
}

//hover节点删除下拉功能按钮
function removeHoverDom(treeId, treeNode) {
    $("#diyBtn1_" + treeNode.id).unbind().remove();
    $("#diyBtn2_" + treeNode.id).unbind().remove();
}

//点击下拉功能节点事件
function btnFunc(treeNode) {
    $(".paddTee span").unbind();
    $(".paddTee span").bind("click", function () {
        $("#diyBtn3_" + treeNode.id).unbind().remove();

        switch ($(this).attr("data-type")) {
            case "next": { //下级
                Department.AddNewDept(treeNode, true);
            }
                break;
            case "level": { //平级
                Department.AddNewDept(treeNode, false);
            }
                break;
            case "edit": { //编辑部门
                Department.EditDept(treeNode);
            }
                break;
            case "disable": { //停用部门
                Department.DisableDepart(treeNode);
            }
                break;
            case "delete": { //删除部门
                Department.DeleteDepart(treeNode);
            }
                break;
        }
    });
}

//创建树
if ("" == divID || undefined == divID || null == divID) {
    layer.msg("树容器未定义");
}

$("#" + divID).html('<ul id="' + divID + 'UL" class="ztree"></ul>');
return $.fn.zTree.init($("#" + divID + "UL"), setting, data);

}

//哈希表
function HashTable() {
//存数据的实体
this._Hash = new Object();

//新增键值
this.Add = function (key, value) {
    if (typeof(key) != "undefined") {
        this._Hash[key] = value;
        return true;
    } else {
        return false;
    }
}

//删除键值
this.Remove = function (key) {
    delete this._Hash[key];
}

//数量
this.Count = function () {
    var i = 0;
    for (var k in this._Hash) {
        i++;
    }
    return i;
}

//获取值
this.Items = function (key) {
    var value = this._Hash[key];
    return typeof(value) == "undefined" ? null : value
}

//获取值
this.GetValue = function (key) {
    return this.Items(key);
}

//获取值
this.Get = function (key) {
    return this.Items(key);
}

//赋值
this.SetValue = function (key, value) {
    return this._Hash[key] = value;
}

//是否包含键
this.Contains = function (key) {
    return typeof(this._Hash[key]) != "undefined";
}

//清空哈希表
this.Clear = function () {
    for (var k in this._Hash) {
        delete this._Hash[k];
    }
}

//获取所有键
this.AllKeys = function () {
    return this._Hash;
}

}

//cookie
var sysCookie = {
//获取cookie
“GetCookie”: function (c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + “=”);
if (c_start != -1) {
c_start = c_start + c_name.length + 1;
c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) c_end = document.cookie.length;
return unescape(document.cookie.substring(c_start, c_end));
}
}
return “”;
},
//设置cookie
“SetCookie”: function (c_name, value, expiredays) {
var exdate = new Date();
if (undefined == expiredays || null == expiredays || “” == expiredays) {
expiredays = 365;
}
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = c_name + “=” + escape(value) + ((expiredays == null) ? “” : “; expires=” + exdate.toGMTString());
},
//检查cookie
“CheckCookie”: function (name) {
username = this.GetCookie(name)
if (username != null && username != “”) {
return true;
} else {
return false;
}
},
//删除cookie
“DeleteCookie”: function (name) {
var date = new Date();
date.setTime(date.getTime() - 10000);
document.cookie = name + “=v; expire=” + date.toGMTString();
},
//清空cookie
“ClearCookie”: function () {
var keys = document.cookie.match(/[^ =;]+(?==)/g);
if (keys) {
for (var i = keys.length; i–😉
document.cookie = keys[i] + ‘=0;expires=’ + new Date(0).toUTCString()
}
}
}

//获取省市控件的信息
function GetCityPickerValue(obj) {
if (sysCommon.isNull(obj.citypicker(‘getText’).val())) {
return {
province: “”,
city: “”,
county: “”
}
}
var position = obj.citypicker(‘getText’).val().split("/");
if (sysCommon.isNull(position)) {
return {
province: “”,
city: “”,
county: “”
}
}
var province = “”;
var city = “”;
var county = “”;

if (sysCommon.isNotNull(position[0])) {
    province = position[0];
}
if (sysCommon.isNotNull(position[1])) {
    city = position[1];
}
if (sysCommon.isNotNull(position[2])) {
    county = position[2];
}
return {
    "province": province,
    "city": city,
    "county": county
}

}

//将省市转化为一行
function ConvertPosition(province, city, county) {
var position = “”;
if (sysCommon.isNotNull(province)) {
position = province;
if (sysCommon.isNotNull(city)) {
position += “,” + city;
if (sysCommon.isNotNull(county)) {
position += “,” + county;
}
}
}
return position;
}

// 用户退出
function logout() {
// iotCache.delete(Constant.userToken); // clean loginToken
// iotCache.delete(Constant.userInfo); // clean userInfo
// iotCache.delete(Constant.loginStatus);
iotCache.removeItem(Constant.userToken);
iotCache.removeItem(Constant.userInfo);
iotCache.removeItem(Constant.loginStatus);
location.href = sysURL.login;
}

function PopContent(content, size, cancelCallback, externalfunction, endfunction) {
var that = this;
var area = {
w: $(window).width() / 2 + “px”,
h: $(window).height() / 3 * 2 + “px”
};
if (!this.isNull(size)) {
area.w = size.width
area.h = size.height;
}
return layer.open({
type: 1,
title: false,
closeBtn: false,
area: [area.w, area.h],
//skin: ‘layui-layer-nobg’, //没有背景色
shadeClose: true,
content: content,
success: function () { //层弹出后的成功回调方法
that.exeFunction(externalfunction);
},
yes: function (index, layero) { //该回调携带两个参数,分别为当前层索引、当前层DOM对象
//do something
//如果设定了yes回调,需进行手工关闭
if (false == that.exeFunction(cancelCallback)) {
return false;
} else {
layer.close(index);
}
},
cancel: function (index) { //该回调同样只携带当前层索引一个参数,无需进行手工关闭。如果不想关闭,return false即可,如 cancel: function(index){ return false; } 则不会关闭;

        if (false == that.exeFunction(cancelCallback)) {
            return false;
        } else {
            layer.close(index);
        }
    },
    end: function (index) {
        if (false == that.exeFunction(endfunction)) {
            return false;
        } else {
            layer.close(index);
        }
    }
});

}

function ClosePop(obj) {
layer.close(obj);
}

var isNet = 0;
var appTag = “bianminxinxi/”;

function gotoLogin() {
var dataHref = ‘login.html’;
var dataName = “登录”;

try {
    window.webkit.messageHandlers.openNewPage.postMessage({
        href: "",
        title: dataName,
        isShowBack: 1,
        isNet: isNet,
        url: dataHref,
        needLocation: 0,
        data: "",//附加参数
        backType: "",//返回回调类型
    });
} catch (error) {
    try {
        // JYJSInterface.openNewPage(dataName, 1, isNet, appTag + dataHref, 0, "", "");
        JYJSInterface.openNewNativePage("login", "登录", "");
    } catch (error) {
        // window.location.href = dataHref;
    }
}

}
function openNewNativePage(type, title, data) {
try {
window.webkit.messageHandlers.openNewNativePage.postMessage({
“type”: type,
“title”: title,
“data”: data
});
} catch (error) {
try {
JYJSInterface.openNewNativePage(type, title, data);
} catch (error) {
// wx.miniProgram.navigateTo({
// url: ‘…/applyFor/applyFor?type=popMoney&title=提现申请&data=’+accountAmount
// });
}
}
}
function gotoShopCar() {
var dataHref = ‘shopCar.html’;
var dataName = “购物车”;

try {
    window.webkit.messageHandlers.openNewPage.postMessage({
        href: "",
        title: dataName,
        isShowBack: 1,
        isNet: isNet,
        url: dataHref,
        needLocation: 0,
        data: "",//附加参数
        backType: "",//返回回调类型
    });
} catch (error) {
    try {
        JYJSInterface.openNewPage(dataName, 1, isNet, appTag + dataHref, 0, "", "");
    } catch (error) {
        // window.location.href = dataHref;
    }
}

}
// var bminUrl = ‘http://o2o.waimai101.com/h5/bianminxinxi/’
function gotoNagivatePage(url, tilte) {
var dataHref = url;
if (sysCommon.isNull(tilte)) {
tilte = “”;
}
var dataName = tilte;

try {
    window.webkit.messageHandlers.openNewPage.postMessage({
        href: "",
        title: dataName,
        isShowBack: 1,
        isNet: isNet,
        url: dataHref,
        needLocation: 0,
        data: "",//附加参数
        backType: "",//返回回调类型
    });
} catch (error) {
    try {
        JYJSInterface.openNewPage(dataName, 1, isNet, appTag + dataHref, 0, "", "");
    } catch (error) {
        window.location.href = dataHref;
    }
}

}
function gotoNewPagePos(url, tilte) {
var dataHref = url;
if (sysCommon.isNull(tilte)) {
tilte = “”;
}
var dataName = tilte;

try {
    window.webkit.messageHandlers.openNewPage.postMessage({
        href: "",
        title: dataName,
        isShowBack: 1,
        isNet: 1,
        url: dataHref,
        needLocation: 1,
        data: "",//附加参数
        backType: "",//返回回调类型
    });
} catch (error) {
    try {
        JYJSInterface.openNewPage(dataName, 1, 1, dataHref, 1, "", 1);
    } catch (error) {
        window.location.href = dataHref;
    }
}

}

// 苹果调用原生打电话
function gotoTelPhone(phone) {
try {
window.webkit.messageHandlers.openPhonePage.postMessage({
phone: phone
});
} catch (error) {

}

}

function gotoBack(tag, page) {
if (sysCommon.isNull(tag)) {
tag = “”;
}
try {
window.webkit.messageHandlers.closePage.postMessage({
data: tag//附加参数
});
} catch (error) {
try {
JYJSInterface.closePage(tag);
} catch (error) {
if (sysCommon.isNotNull(page)) {
location.href = page;
} else {
history.go(-1);
}
}
}
}

function gotoPay(orderNo, money, fuc, params) {
if (sysCommon.isNull(orderNo)) {
sysCommon.showAlert(“订单编号不能为空”);
return;
} else {
orderNo = “” + orderNo;
}
try {
window.webkit.messageHandlers.openPayPage.postMessage({
title: “支付”,
orderNo: orderNo,
money: money,//附加参数
sysPayType: “xinxifabu”,
fuc: fuc,
params: params,
});
} catch (error) {
try {
JYJSInterface.openPayPage(“支付”, orderNo, money, “xinxifabu”);
} catch (error) {
// window.location.href = dataHref;
wx.miniProgram.navigateTo({
url: ‘…/payment/payment?orderNo=’ + orderNo + ‘&price=’ + money + ‘&sysPayType=xinxifabu’,
})
}
}
}

function passThrough(func, param) {
if (sysCommon.isNull(param)) {
param = “”;
}
try {
window.webkit.messageHandlers.passThrough.postMessage({
func: func,//附加参数
param: param
});
} catch (error) {
try {

        JYJSInterface.passThrough(func, param);
    } catch (error) {

    }
}

}

//清楚缓存
window.cleanH5 = function () {
iotCache.clear();
}
//清楚缓存
window.setToken = function (token) {
iotCache.setItem(“token”, token);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shuai1995_cn_com

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值