busInit.js 5.08 KB
//var _REQUESTURL = "http://localhost:9092";
var _REQUESTURL = "http://127.0.0.1:8080";

var _DEFAULT_SIZE = 10,
    _DEFAULT_PAGE = 1;

var _SYSTEMKEY = {
    "USERID": "adminUserId",
    "SESSIONID": "adminSessionId",
    "REDIRECTURL": "redirectUrl",
    "PAGEPARAMS": "pageParams",
    "SYSTEMUSER": "systemuser",
    "LOGINBACK": "loginback"
}

var CDNPATH = "";
var OSSPARAM = {
    region: 'oss-cn-qingdao',
    accessKeyId: 'LTAI0W9uVALkeFpo',
    accessKeySecret: 'U3wESI1dSTqhgX8EV5wc66b39cE8V9',
    bucket: 'luobaoan'
};
var SUBMITLOCK = false;
var _QUERYPARAM = {};

var REGULARBUS_ACTIVE_LINES_STATUS = {
    1: "售票",
    2: "检票",
    3: "发班",
    4: "停班",
    5: "停售",
    6: "募集"
}

function isLogin() {
    if (window.location.href.indexOf("login.html") == -1) {
        var user = getCookie(_SYSTEMKEY.SYSTEMUSER);
        if (!user) {
            window.location.href = "login.html";
        }
    }

}
isLogin();

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.htmlTrim = function() {
    return this.replace(/<[^>]*?>(.*?)/gi, '$1').replace(/(.*?)<\/[^>]*?>/gi, '$1');
}

Date.prototype.format = function(fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

function _putSession(key, val) {
    var session = window.localStorage;
    session.setItem(key, val);
    // setCookie(key, val);
}

function _getSession(key) {
    var session = window.localStorage;
    return session.getItem(key);
    // return getCookie(key);
}

function _removeSession(key) {
    var session = window.localStorage;
    return session.removeItem(key);
    // delCookie(key);
}

function _clearSession() {
    var session = window.localStorage;
    session.clear();
}

function setCookie(name, value) {
    var Days = 7;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

//读取cookies 
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

//删除cookies 
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

function _isLogin() {
    var sessionId = _getSession(_SYSTEMKEY.SESSIONID);
    console.log(sessionId);
    if (sessionId && sessionId.trim() != "") {
        return true;
    }
    return false;
}

function loginInit() {

}


function _getSessionId() {
    return _getSession(_SYSTEMKEY.SESSIONID);
}

function _putSessionId(sid) {
    _putSession(_SYSTEMKEY.SESSIONID, sid);
}

function getUuid() {
    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);
    });
}

function logout() {
    _putSession(_SYSTEMKEY.LOGINBACK, window.location.href);
    _removeSession(_SYSTEMKEY.SESSIONID);
    // location.href = LOGINURL;
}

function _getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

function _nullValue(value) {
    if (value) {
        return value;
    } else {
        return "";
    }
}
var m = "yrymaster";

function showError(message) {
    alert(message);
}


function _timestampToString(timestamp) {
    timestamp = timestamp + "";

    if (timestamp.length == 10) {
        timestamp = timestamp + "000";
    }
    // console.log(timestamp);
    timestamp = Number(timestamp);
    var date = new Date(timestamp);
    // var d = date.getDate();
    // var m = date.getMonth();
    // var y = date.getFullYear();

    // var now = new Date();
    // var nd = now.getDate();
    // var nm = now.getMonth();
    // var ny = now.getFullYear();

    // var format = "";

    // if (y == ny && m == nm) {
    //     if (d == nd) {
    //         s = "hh:mm";
    //     } else if (nd - 1 == d) {
    //         s = "昨天 hh:mm";
    //     } else if (nd == d - 1) {
    //         s = "明天 hh:mm";
    //     } else {
    //         s = "MM-dd hh:mm";
    //     }
    // } else if (y == ny) {
    var s = "MM-dd hh:mm";
    // } else {
    //     s = "yyyy-MM-dd hh:mm";
    // }

    return new Date(timestamp).format(s);
}

var  p = "YRY@34AJ1056921";