添加网站文件
This commit is contained in:
108
public/static/common/js/Time.js
Normal file
108
public/static/common/js/Time.js
Normal file
@@ -0,0 +1,108 @@
|
||||
var Times = {
|
||||
// 获取几天前日期
|
||||
getDay: function(day){
|
||||
var today = new Date();
|
||||
var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
|
||||
|
||||
today.setTime(targetday_milliseconds);
|
||||
|
||||
var tYear = today.getFullYear();
|
||||
var tMonth = today.getMonth();
|
||||
var tDate = today.getDate();
|
||||
|
||||
tMonth = Times.doHandleMonth(tMonth + 1);
|
||||
tDate = Times.doHandleMonth(tDate);
|
||||
|
||||
return tYear+"-"+tMonth+"-"+tDate;
|
||||
}
|
||||
// 处理月份
|
||||
,doHandleMonth: function(month){
|
||||
var m = month;
|
||||
if(month.toString().length === 1){
|
||||
m = "0" + month;
|
||||
}
|
||||
return m;
|
||||
},
|
||||
/**
|
||||
* Notes: 日期时间格式 转 时间戳
|
||||
* date: 日期时间 如: 2020-12-1 13:23:11
|
||||
*/
|
||||
tostrtime: function(date) {
|
||||
return Date.parse(new Date(date)) / 1000;
|
||||
},
|
||||
timestampToTime: function(timestamp) {
|
||||
var date = new Date(timestamp * 1000);
|
||||
var Y = date.getFullYear() + '-';
|
||||
var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
|
||||
var D = 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;
|
||||
},
|
||||
/**
|
||||
* Notes: 今天的开始时间和结束时间
|
||||
* isStamp: 是否转成时间戳
|
||||
*/
|
||||
today: function(isStamp) {
|
||||
isStamp = isStamp === undefined ? true : isStamp;
|
||||
|
||||
var start = Times.getDay(0) + " 00:00:00"
|
||||
var end = Times.getDay(0) + " 23:59:59"
|
||||
if (isStamp) {
|
||||
start = Times.tostrtime(start);
|
||||
end = Times.tostrtime(end);
|
||||
}
|
||||
return [start, end];
|
||||
},
|
||||
/**
|
||||
* Notes: 本月开始和结束
|
||||
* isStamp: 是否转成时间戳
|
||||
*/
|
||||
month: function(isStamp) {
|
||||
isStamp = isStamp === undefined ? true : isStamp;
|
||||
var date=new Date();
|
||||
// 开始时间
|
||||
var Year = date.getFullYear();
|
||||
var Month = (date.getMonth() +1) < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1;
|
||||
var start = Year + '-' + Month + '-01 00:00:00'
|
||||
// 结束时间
|
||||
var currentMonth=date.getMonth();
|
||||
var nextMonth=++currentMonth;
|
||||
var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
|
||||
var oneDay=1000*60*60*24;
|
||||
var lastDate = new Date(nextMonthFirstDay-oneDay);
|
||||
var endDate = lastDate.getFullYear()+"-"+((lastDate.getMonth()+1)<10?"0":"")+(lastDate.getMonth()+1)+"-"+(lastDate.getDate()<10?"0":"")+lastDate.getDate();
|
||||
var end = endDate + ' 23:59:59';
|
||||
|
||||
if (isStamp) {
|
||||
start = Times.tostrtime(start);
|
||||
end = Times.tostrtime(end);
|
||||
}
|
||||
return [start, end];
|
||||
|
||||
},
|
||||
/**
|
||||
* 获取几天前零点到现在/昨日结束的时间
|
||||
* Notes: 本月开始和结束
|
||||
* isStamp: 是否转成时间戳
|
||||
*/
|
||||
dayToNow: function(day, isStamp){
|
||||
day = day === undefined ? -1 : day;
|
||||
isStamp = isStamp === undefined ? true : isStamp;
|
||||
var start = Times.getDay(day) + " 00:00:00";
|
||||
var end = Times.getDay(day) + " 23:59:59";
|
||||
if (isStamp) {
|
||||
start = Times.tostrtime(start);
|
||||
end = Times.tostrtime(end);
|
||||
}
|
||||
return [start, end];
|
||||
},
|
||||
/**
|
||||
* 获取当前时间戳
|
||||
*/
|
||||
curTimestamp : function() {
|
||||
return Date.parse(new Date()) / 1000
|
||||
}
|
||||
};
|
||||
2
public/static/common/js/area.js
Normal file
2
public/static/common/js/area.js
Normal file
File diff suppressed because one or more lines are too long
118
public/static/common/js/function.js
Normal file
118
public/static/common/js/function.js
Normal file
@@ -0,0 +1,118 @@
|
||||
function getImageWidth(url, callback) {
|
||||
var img = new Image();
|
||||
img.src = url;
|
||||
if (img.complete) {
|
||||
callback(img.width, img.height);
|
||||
} else {
|
||||
img.onload = function () {
|
||||
callback(img.width, img.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
function in_array(search,array){
|
||||
for(var i in array){
|
||||
if(array[i]==search){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function uniq(array){
|
||||
var temp = [];
|
||||
for(var i = 0; i < array.length; i++){
|
||||
if(temp.indexOf(array[i]) == -1){
|
||||
temp.push(array[i]);
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
//判断字符串是否为空格
|
||||
function isEmptyString(str) {
|
||||
str = str.replace(/(^\s*)|(\s*$)/g, "");
|
||||
if (str.length == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//数组去重
|
||||
function unique(arr){
|
||||
var hash=[];
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if(hash.indexOf(arr[i])==-1){
|
||||
hash.push(arr[i]);
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
//元素交换
|
||||
function swop(first, second) {
|
||||
html = first.html();
|
||||
first.html(second.html());
|
||||
second.html(html);
|
||||
}
|
||||
//笛卡尔积生成
|
||||
function cartesianProduct(arr) {
|
||||
if (arr.length < 2) return arr[0] || [];
|
||||
return [].reduce.call(arr, function (col, set) {
|
||||
let res = [];
|
||||
col.forEach(c => {
|
||||
set.forEach(s => {
|
||||
let t = [].concat(Array.isArray(c) ? c : [c]);
|
||||
t.push(s);
|
||||
res.push(t);
|
||||
})
|
||||
});
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//元素交换
|
||||
function swop(first, second) {
|
||||
html = first.html();
|
||||
first.html(second.html());
|
||||
second.html(html);
|
||||
}
|
||||
//数组去重
|
||||
function unique(arr){
|
||||
var hash=[];
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if(hash.indexOf(arr[i])==-1){
|
||||
hash.push(arr[i]);
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
//转换数组格式
|
||||
function array_column(data,key) {
|
||||
var result = [];
|
||||
for(var i in data){
|
||||
result[data[i][key]] = data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function array_unique(arr){
|
||||
for(var i=0; i<arr.length; i++){
|
||||
for(var j=i+1; j<arr.length; j++){
|
||||
if(arr[i]==arr[j]){
|
||||
arr.splice(j,1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为整数
|
||||
* @param obj
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isInteger(obj) {
|
||||
return obj % 1 === 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user