var t = function(t) {
    return (t = t.toString())[1] ? t : "0" + t;
};

const getToken = function(){
	const app = getApp()
	let token = app && app.globalData && app.globalData.token || ''
	if(!token){
		token = uni.getStorageSync('token')
	}
	return token
}
const setToken = function(token){
	const app = getApp()
	uni.setStorageSync('token',token)
	if(app && app.globalData){
		app.globalData.token = token
	}
}

const getOpenid = function(){
	const app = getApp()
	let openid = app && app.globalData && app.globalData.openid || ''
	if(!openid){
		openid = uni.getStorageSync('openid')
	}
	return openid
}
const setOpenid = function(openid){
	const app = getApp()
	uni.setStorageSync('openid',openid)
	if(app && app.globalData){
		app.globalData.openid = openid
	}
}
module.exports = {
    formatTime: function(n) {
        var e = n.getFullYear(), r = n.getMonth() + 1, o = n.getDate(), i = n.getHours(), u = n.getMinutes(), a = n.getSeconds();
        return [ e, r, o ].map(t).join("-") + " " + [ i, u, a ].map(t).join(":");
    },
    throttle: function(t, n) {
        null != n && null != n || (n = 1500);
        var e = null;
        return function() {
            var r = +new Date();
            console.log(r + "," + e + "，" + new Date()), (r - e > n || !e) && (t(), e = r);
        };
    },
    formatLonLat: function(t, n) {
        if (void 0 === t || "" == t) return "";
        if (t += "", 0 == n) return parseFloat(t).toFixed(6);
        var e = t.indexOf("."), r = e < 0 ? t : t.substring(0, e), o = 0, i = 0;
        return e > 0 && (o = 60 * (o = "0" + t.substring(e)) + "", 2 == n ? (e = o.indexOf(".")) > 0 && (i = "0" + o.substring(e), 
        o = o.substring(0, e), e = (i = 60 * i + "").indexOf("."), i = i.substring(0, e + 4), 
        i = parseFloat(i).toFixed(0)) : 1 == n && (o = parseFloat(o).toFixed(6))), 2 == n ? r + "°" + o + "′" + i + "″" : 1 == n ? r + "°" + o + "′" : void 0;
    },
	getToken,
	setToken,
	getOpenid,
	setOpenid,
};