|
@@ -5,29 +5,30 @@ import { getStaticContent } from '@/api/ajax';
|
|
|
import { setConfig } from './auth'
|
|
|
|
|
|
export function getConfigInfor() {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- let MethodName = 'sys_config_manager-GetLogo';
|
|
|
- getStaticContent(MethodName, {}).then(res => {
|
|
|
- setConfig(res);
|
|
|
- resolve(res)
|
|
|
- }).catch(err => {
|
|
|
- reject(err);
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let MethodName = 'sys_config_manager-GetLogo';
|
|
|
+ getStaticContent(MethodName, {}).then(res => {
|
|
|
+ setConfig(res);
|
|
|
+ resolve(res)
|
|
|
+ }).catch(err => {
|
|
|
+ reject(err);
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
}
|
|
|
|
|
|
//分:秒转秒
|
|
|
export function timeStrToSen(time) {
|
|
|
- if (!time) {
|
|
|
- return -1;
|
|
|
- }
|
|
|
- var pos = time.indexOf(':');
|
|
|
- var min = 0, sec = 0;;
|
|
|
- if (pos > 0) {
|
|
|
- min = parseInt(time.substring(0, pos));
|
|
|
- sec = parseFloat(time.substring(pos + 1))
|
|
|
- }
|
|
|
- return min * 60 + sec;
|
|
|
+ if (!time) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ var pos = time.indexOf(':');
|
|
|
+ var min = 0,
|
|
|
+ sec = 0;;
|
|
|
+ if (pos > 0) {
|
|
|
+ min = parseInt(time.substring(0, pos));
|
|
|
+ sec = parseFloat(time.substring(pos + 1))
|
|
|
+ }
|
|
|
+ return min * 60 + sec;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -41,46 +42,46 @@ export function timeStrToSen(time) {
|
|
|
* @returns {string | null}
|
|
|
*/
|
|
|
export function parseTime(time, cFormat) {
|
|
|
- if (arguments.length === 0 || !time) {
|
|
|
- return null
|
|
|
- }
|
|
|
- const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
|
|
|
- let date
|
|
|
- if (typeof time === 'object') {
|
|
|
- date = time
|
|
|
- } else {
|
|
|
- if ((typeof time === 'string')) {
|
|
|
- if ((/^[0-9]+$/.test(time))) {
|
|
|
- // support "1548221490638"
|
|
|
- time = parseInt(time)
|
|
|
- } else {
|
|
|
- // support safari
|
|
|
- // https://stackoverflow.com/questions/4310953/invalid-date-in-safari
|
|
|
- time = time.replace(new RegExp(/-/gm), '/')
|
|
|
- }
|
|
|
+ if (arguments.length === 0 || !time) {
|
|
|
+ return null
|
|
|
}
|
|
|
+ const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
|
|
|
+ let date
|
|
|
+ if (typeof time === 'object') {
|
|
|
+ date = time
|
|
|
+ } else {
|
|
|
+ if ((typeof time === 'string')) {
|
|
|
+ if ((/^[0-9]+$/.test(time))) {
|
|
|
+ // support "1548221490638"
|
|
|
+ time = parseInt(time)
|
|
|
+ } else {
|
|
|
+ // support safari
|
|
|
+ // https://stackoverflow.com/questions/4310953/invalid-date-in-safari
|
|
|
+ time = time.replace(new RegExp(/-/gm), '/')
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if ((typeof time === 'number') && (time.toString().length === 10)) {
|
|
|
- time = time * 1000
|
|
|
+ if ((typeof time === 'number') && (time.toString().length === 10)) {
|
|
|
+ time = time * 1000
|
|
|
+ }
|
|
|
+ date = new Date(time)
|
|
|
}
|
|
|
- date = new Date(time)
|
|
|
- }
|
|
|
- const formatObj = {
|
|
|
- y: date.getFullYear(),
|
|
|
- m: date.getMonth() + 1,
|
|
|
- d: date.getDate(),
|
|
|
- h: date.getHours(),
|
|
|
- i: date.getMinutes(),
|
|
|
- s: date.getSeconds(),
|
|
|
- a: date.getDay()
|
|
|
- }
|
|
|
- const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
|
|
|
- const value = formatObj[key]
|
|
|
- // Note: getDay() returns 0 on Sunday
|
|
|
- if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
|
|
|
- return value.toString().padStart(2, '0')
|
|
|
- })
|
|
|
- return time_str
|
|
|
+ const formatObj = {
|
|
|
+ y: date.getFullYear(),
|
|
|
+ m: date.getMonth() + 1,
|
|
|
+ d: date.getDate(),
|
|
|
+ h: date.getHours(),
|
|
|
+ i: date.getMinutes(),
|
|
|
+ s: date.getSeconds(),
|
|
|
+ a: date.getDay()
|
|
|
+ }
|
|
|
+ const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
|
|
|
+ const value = formatObj[key]
|
|
|
+ // Note: getDay() returns 0 on Sunday
|
|
|
+ if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
|
|
|
+ return value.toString().padStart(2, '0')
|
|
|
+ })
|
|
|
+ return time_str
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -89,41 +90,41 @@ export function parseTime(time, cFormat) {
|
|
|
* @returns {string}
|
|
|
*/
|
|
|
export function formatTime(time, option) {
|
|
|
- if (('' + time).length === 10) {
|
|
|
- time = parseInt(time) * 1000
|
|
|
- } else {
|
|
|
- time = +time
|
|
|
- }
|
|
|
- const d = new Date(time)
|
|
|
- const now = Date.now()
|
|
|
+ if (('' + time).length === 10) {
|
|
|
+ time = parseInt(time) * 1000
|
|
|
+ } else {
|
|
|
+ time = +time
|
|
|
+ }
|
|
|
+ const d = new Date(time)
|
|
|
+ const now = Date.now()
|
|
|
|
|
|
- const diff = (now - d) / 1000
|
|
|
+ const diff = (now - d) / 1000
|
|
|
|
|
|
- if (diff < 30) {
|
|
|
- return '刚刚'
|
|
|
- } else if (diff < 3600) {
|
|
|
- // less 1 hour
|
|
|
- return Math.ceil(diff / 60) + '分钟前'
|
|
|
- } else if (diff < 3600 * 24) {
|
|
|
- return Math.ceil(diff / 3600) + '小时前'
|
|
|
- } else if (diff < 3600 * 24 * 2) {
|
|
|
- return '1天前'
|
|
|
- }
|
|
|
- if (option) {
|
|
|
- return parseTime(time, option)
|
|
|
- } else {
|
|
|
- return (
|
|
|
- d.getMonth() +
|
|
|
- 1 +
|
|
|
- '月' +
|
|
|
- d.getDate() +
|
|
|
- '日' +
|
|
|
- d.getHours() +
|
|
|
- '时' +
|
|
|
- d.getMinutes() +
|
|
|
- '分'
|
|
|
- )
|
|
|
- }
|
|
|
+ if (diff < 30) {
|
|
|
+ return '刚刚'
|
|
|
+ } else if (diff < 3600) {
|
|
|
+ // less 1 hour
|
|
|
+ return Math.ceil(diff / 60) + '分钟前'
|
|
|
+ } else if (diff < 3600 * 24) {
|
|
|
+ return Math.ceil(diff / 3600) + '小时前'
|
|
|
+ } else if (diff < 3600 * 24 * 2) {
|
|
|
+ return '1天前'
|
|
|
+ }
|
|
|
+ if (option) {
|
|
|
+ return parseTime(time, option)
|
|
|
+ } else {
|
|
|
+ return (
|
|
|
+ d.getMonth() +
|
|
|
+ 1 +
|
|
|
+ '月' +
|
|
|
+ d.getDate() +
|
|
|
+ '日' +
|
|
|
+ d.getHours() +
|
|
|
+ '时' +
|
|
|
+ d.getMinutes() +
|
|
|
+ '分'
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -131,68 +132,96 @@ export function formatTime(time, option) {
|
|
|
* @returns {Object}
|
|
|
*/
|
|
|
export function param2Obj(url) {
|
|
|
- const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
|
|
|
- if (!search) {
|
|
|
- return {}
|
|
|
- }
|
|
|
- const obj = {}
|
|
|
- const searchArr = search.split('&')
|
|
|
- searchArr.forEach(v => {
|
|
|
- const index = v.indexOf('=')
|
|
|
- if (index !== -1) {
|
|
|
- const name = v.substring(0, index)
|
|
|
- const val = v.substring(index + 1, v.length)
|
|
|
- obj[name] = val
|
|
|
+ const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
|
|
|
+ if (!search) {
|
|
|
+ return {}
|
|
|
}
|
|
|
- })
|
|
|
- return obj
|
|
|
+ const obj = {}
|
|
|
+ const searchArr = search.split('&')
|
|
|
+ searchArr.forEach(v => {
|
|
|
+ const index = v.indexOf('=')
|
|
|
+ if (index !== -1) {
|
|
|
+ const name = v.substring(0, index)
|
|
|
+ const val = v.substring(index + 1, v.length)
|
|
|
+ obj[name] = val
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return obj
|
|
|
}
|
|
|
|
|
|
|
|
|
export function createComprisonFunction(propertyName) {
|
|
|
- return function (object1, object2) {
|
|
|
- var value1 = object1[propertyName];
|
|
|
- var value2 = object2[propertyName];
|
|
|
- if (value1 < value2) {
|
|
|
- return -1;
|
|
|
- } else if (value1 > value2) {
|
|
|
- return 1;
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
+ return function(object1, object2) {
|
|
|
+ var value1 = object1[propertyName];
|
|
|
+ var value2 = object2[propertyName];
|
|
|
+ if (value1 < value2) {
|
|
|
+ return -1;
|
|
|
+ } else if (value1 > value2) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
// 混淆数字
|
|
|
export function handleNumber(number) {
|
|
|
- let numberArr;
|
|
|
- numberArr = [
|
|
|
- number - 3,
|
|
|
- number - 2,
|
|
|
- number - 1,
|
|
|
- number + 1,
|
|
|
- number + 2,
|
|
|
- number + 3,
|
|
|
- ];
|
|
|
- numberArr = getRandomArrayElements(
|
|
|
- numberArr,
|
|
|
- 3
|
|
|
- );
|
|
|
- numberArr.push(number);
|
|
|
- numberArr.sort();
|
|
|
- return numberArr;
|
|
|
+ let numberArr;
|
|
|
+ numberArr = [
|
|
|
+ number - 3,
|
|
|
+ number - 2,
|
|
|
+ number - 1,
|
|
|
+ number + 1,
|
|
|
+ number + 2,
|
|
|
+ number + 3,
|
|
|
+ ];
|
|
|
+ numberArr = getRandomArrayElements(
|
|
|
+ numberArr,
|
|
|
+ 3
|
|
|
+ );
|
|
|
+ numberArr.push(number);
|
|
|
+ numberArr.sort();
|
|
|
+ return numberArr;
|
|
|
}
|
|
|
export function getRandomArrayElements(arr, count) {
|
|
|
- var shuffled = arr.slice(0),
|
|
|
- i = arr.length,
|
|
|
- min = i - count,
|
|
|
- temp,
|
|
|
- index;
|
|
|
- while (i-- > min) {
|
|
|
- index = Math.floor((i + 1) * Math.random());
|
|
|
- temp = shuffled[index];
|
|
|
- shuffled[index] = shuffled[i];
|
|
|
- shuffled[i] = temp;
|
|
|
- }
|
|
|
- return shuffled.slice(min);
|
|
|
+ var shuffled = arr.slice(0),
|
|
|
+ i = arr.length,
|
|
|
+ min = i - count,
|
|
|
+ temp,
|
|
|
+ index;
|
|
|
+ while (i-- > min) {
|
|
|
+ index = Math.floor((i + 1) * Math.random());
|
|
|
+ temp = shuffled[index];
|
|
|
+ shuffled[index] = shuffled[i];
|
|
|
+ shuffled[i] = temp;
|
|
|
+ }
|
|
|
+ return shuffled.slice(min);
|
|
|
+}
|
|
|
+//秒数转化为时分秒
|
|
|
+export function formatSeconds(value) {
|
|
|
+ var secondTime = parseInt(value); // 秒
|
|
|
+ var minuteTime = 0; // 分
|
|
|
+ var hourTime = 0; // 小时
|
|
|
+ if (secondTime > 60) { //如果秒数大于60,将秒数转换成整数
|
|
|
+ //获取分钟,除以60取整数,得到整数分钟
|
|
|
+ minuteTime = parseInt(secondTime / 60);
|
|
|
+ //获取秒数,秒数取余,得到整数秒数
|
|
|
+ secondTime = parseInt(secondTime % 60);
|
|
|
+ //如果分钟大于60,将分钟转换成小时
|
|
|
+ if (minuteTime > 60) {
|
|
|
+ //获取小时,获取分钟除以60,得到整数小时
|
|
|
+ hourTime = parseInt(minuteTime / 60);
|
|
|
+ //获取小时后取余的分,获取分钟除以60取余的分
|
|
|
+ minuteTime = parseInt(minuteTime % 60);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var result = "" + parseInt(secondTime) + "秒";
|
|
|
+
|
|
|
+ if (minuteTime > 0) {
|
|
|
+ result = "" + parseInt(minuteTime) + "分" + result;
|
|
|
+ }
|
|
|
+ if (hourTime > 0) {
|
|
|
+ result = "" + parseInt(hourTime) + "小时" + result;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|