【JS】global.js

/**
 * Created by Administrator on 2017/3/30 0030.
 */
//接口配置
//var BASEURL = "http://36.7.145.19:9380";
var BASEURL = "";
var api = {
    baseInfo: "api/infos/user/getBaseUserInfo",//用户基本信息
    goods: "api/goods/getGoodsTypelist",//商品接口
    totalInfo: "api/quotation/getTotalInfo",//今开昨收信息
    timeline: "api/quotation/getFS",//得到分时图数据
    kchart: "api/quotation/getkchart",//得到K线图数据
    open: "api/tran/position/open",//建仓
    cash: "api/tran/withdrawByBank",//提现
    toYeePay: "api/tran/pay/toYeePay",//易宝充值
    toWxPay: "api/tran/pay/toWxPay",//微信充值
    toULineAliPay: "api/tran/pay/toULineAliPay",//聚合支付宝充值
    updatepwd: "api/tran/security/updatePwd",//修改密码
    fundsrecord: "api/customers/fundsRecord/getlist",//出入金列表
    flow: "api/customers/flow/getlist",//账户流水操盘记录
    positionlist: "api/tran/position/getCurrPositionlist",//当前持仓列表
    acctInfo: "api/tran/acct/get", //用户信息
    login: "api/oauth/token", //登陆
    hispositionlist: "api/tran/position/getHisPositionlist", //获得历史仓位列表
    getRegCode: "api/customers/regist/getvcode",//获取注册验证码
    getCashCode: "api/tran/sms/sendWithdrawsSms",//获取提现验证码
    getFree: "api/withdraws/getCashCharge",//提现手续费
    getRestPwdCode: "/api/customers/password/getvcode",//重置密码验证码
    restpwd: "/api/customers/password/reset",//重置密码
    infoTimer: "/api/tran/infoTimer/getInfoTimer",
    tranList: "/api/tran/getDepositWithdrawList"
}
//正则表达式
var reg = {
    bankCardReg: /^(\d{16}|\d{19})$/,//银行卡号正则
    idCardReg: /^(\d{18})$/,//身份证正则
    vCodeReg: /^\d{4}$/,//4位短信验证码
    moneyRed: /^[1-9]\d?$/,//金额正则
    nameReg: new RegExp("^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9])*$")
}


//ajax
var ajax = {
    //purl 是接口url
    //data是传入参数
    //callbacl是成功后的回调函数
    //async是同步异步开发,默认异步可不传,如需同步,则必须传false
    post: function (purl, data, callback, show, callComplete, callErr) {
        var index;
        if (show == null) {
            show = true;
        }
        if (show) {
            index = layerUtil.load();
        }
        $.ajax({
            type: 'POST',
            url: purl,
            timeout: 100000,
            data: JSON.stringify(data),
            contentType: "application/json;charset=UTF-8",
            dataType: 'json',
            success: function (result) {
                //layer.close(index);
                if (result.code == 401) {
                    toLogin();
                    return;
                }
                callback && callback(result);
            },
            error: function (info) {
                //layer.close(index);
                callErr && callErr(info);
            },
            complete: function (xhr, status) {
                layer.close(index);
                callComplete && callComplete(xhr, status);
            },
            beforeSend: function (request) {
                request.setRequestHeader("Authorization", 'bearer ' + oauth.getToken());
            }


        });
    },
    get: function (purl, data, callback, show, callComplete, callErr) {
        var index;
        if (show == null) {
            show = true;
        }
        if (show) {
            index = layerUtil.load();
        }
        $.ajax({
            type: 'GET',
            url: purl,
            data: data,
            dataType: 'json',
            timeout: 100000,
            success: function (result) {
                //layer.close(index);
                if (result.code == 401) {
                    toLogin();
                    return;
                }
                callback && callback(result);
            },
            error: function (info) {
                //layer.close(index);
                callErr && callErr(info);
            },
            complete: function (xhr, status) {
                layer.close(index);
                callComplete && callComplete(xhr, status);
            },
            beforeSend: function (request) {
                request.setRequestHeader("Authorization", 'bearer ' + oauth.getToken());
            }
        });
    }
}


var oauth = {
    getToken: function () {
        var token = localStorage.getItem('AUTHORIZATION');
        return token;
    },
    setToken: function (token) {
        localStorage.setItem('AUTHORIZATION', token);
    },
    clean: function () {
        localStorage.removeItem('AUTHORIZATION');
    }
}
var util = {
    //格式化金额start
    formatMoney: function (src) {
        var pos = 2;
        var num = parseFloat(src).toFixed(pos);
        num = num.toString().replace(/\$|\,/g, '');
        if (isNaN(num)) num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num * 100 + 0.50000000001);
        cents = num % 100;
        num = Math.floor(num / 100).toString();
        if (cents < 10) cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
        return (((sign) ? '' : '-') + num + '.' + cents);
    },
    outputdollars: function (number) {
        if (number.length <= 3)
            return (number == '' ? '0' : number);
        else {
            var mod = number.length % 3;
            var output = (mod == 0 ? '' : (number.substring(0, mod)));
            for (i = 0; i < Math.floor(number.length / 3); i++) {
                if ((mod == 0) && (i == 0))
                    output += number.substring(mod + 3 * i, mod + 3 * i + 3);
                else
                    output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
            }
            return (output);
        }
    },
    outputcents: function (amount) {
        amount = Math.round(((amount) - Math.floor(amount)) * 100);
        return (amount < 10 ? '.0' + amount : '.' + amount);
    },
    //格式化金额stop
    //格式化时间
    formatTimeForH5: function (now) {
        var year = new Date(now).getFullYear();
        var month = new Date(now).getMonth() + 1 >= 10 ? new Date(now).getMonth() + 1 : '0' + (new Date(now).getMonth() + 1);
        var date = new Date(now).getDate() >= 10 ? new Date(now).getDate() : '0' + new Date(now).getDate();
        var hour = new Date(now).getHours();
        var minute = new Date(now).getMinutes();
        //var second = new Date(now).getSeconds();
        return (hour == '0' ? '00' : hour) + ":" + (minute == '0' ? '00' : minute) + "\n" + month + "/" + date
    },
    checkEquipment: function () {
        //平台、设备和操作系统
        var system = {
            win: false,
            mac: false,
            xll: false,
            ipad: false
        };
        //检测平台
        var p = navigator.platform;
        system.win = p.indexOf("Win") == 0;
        system.mac = p.indexOf("Mac") == 0;
        system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
        system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false;
        //跳转语句,如果是手机访问就自动跳转到wap.baidu.com页面
        if (system.win || system.mac || system.xll || system.ipad) {
            return 'pc';
        } else {
            var ua = navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == "micromessenger") {
                return 'wx';
            } else {
                return 'mobile';
            }
        }
    },
    getQueryString: function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    },
    isLogin: function () {
        var isVer = localStorage.getItem('isVer');
        if (isVer == '1') {
            return true;
        } else {
            return false;
        }
    },
    checkMobile: function (mobile) {
        if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(mobile))) {
            return false;
        } else {
            return true;
        }
    }
}


Date.prototype.Format = function (fmt) { //author: meizz
    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 urlTo(url) {
    if (!localStorage.getItem("isVer")) {
        toLogin();
        return;
    }
    location.href = url;
}




//交易密码弹出
function toLogin() {
    location.href = "./login.html?" + new Date().getTime();
}


Date.prototype.format = function (format) {
    var date = {
        "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+)/i.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1
                ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
        }
    }
    return format;
}




function Map() {


    var mapObj = {};


    this.put = function (key, value) {
        mapObj[key] = value;
    };


    this.remove = function (key) {
        if (mapObj.hasOwnProperty(key)) {
            delete mapObj[key];
        }
    };


    this.get = function (key) {
        if (mapObj.hasOwnProperty(key)) {
            return mapObj[key];
        }
        return null;
    };


    this.getKeys = function () {
        var keys = [];
        for (var k in mapObj) {
            keys.push(k);
        }
        return keys;
    };


    // 遍历map
    this.each = function (fn) {
        for (var key in mapObj) {
            fn(key, mapObj[key]);
        }
    };


    this.toString = function () {
        var str = "{";
        for (var k in mapObj) {
            str += "\"" + k + "\" : \"" + mapObj[k] + "\",";
        }
        str = str.substring(0, str.length - 1);
        str += "}";
        return str;
    }


}


function getUrl(uri) {
    return '/api/' + uri;
}




var Lock = {
    createNew: function () {
        var lock = {};


        lock.flag = true;


        lock.lockCnt = 0;


        lock.releaseCnt = 0;


        /**
         * 获取锁
         * @returns {boolean}
         */
        lock.getLock = function (timeout) {
            timeout = timeout == void(0) ? 10000 : timeout;
            if (lock.flag) {
                lock.flag = false;
                lock.lockCnt++;
                // 超时检查,未释放时将自动释放
                setTimeout(function () {
                    if (!lock.flag && lock.lockCnt - lock.releaseCnt == 1) {
                        lock.flag = true;
                        lock.releaseCnt++;
                    }
                }, timeout);
                return true;
            } else {
                return false;
            }
        };
        /**
         * 释放锁
         */
        lock.release = function () {
            if (!lock.flag) {
                lock.flag = true;
                lock.releaseCnt++;
            }
        }
        return lock;
    }
};


function dw2() {
    //窗口宽度
    var h = parseInt($(window).width());
    var f_width = parseInt($('.alertLayer').width());
    var f_width2 = parseInt($('.pwdOvTmBox').width());
    var f_width3 = parseInt($('.ajaxLayer').width());
    $('.alertLayer').css('left', (h - f_width) / 2 + 'px');
    $('.pwdOvTmBox').css('left', (h - f_width2) / 2 + 'px');
    $('.ajaxLayer').css('left', (h - f_width3) / 2 + 'px');




}
dw2();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值