vue获取url数据
getUrlParam() {
let url = location.search;
let theRequest = {};
if (url.indexOf('?') !== -1) {
let strs = url.substr(1).split('&');
for (let i = 0; i < strs.length; i++) {
theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]);
}
}
return theRequest;
}
时分秒
dateFormat({ time } = {}) {
// console.log(time);
let newTime = time ? time.split('.')[0].replace('T', ' ') : '';
// console.log(newTime);
let date = new Date(Date.parse(newTime.replace(/-/g, '/')));
// console.log(date);
let year = date.getFullYear();
let month = (date.getMonth() + 1 < 10) ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
let hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
let minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
let second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
}
import { clearCookie } from '@/assets/js/utils/cookie';
import cookieKey from '@/assets/js/config/cookie-key';
import areas from '../config/area.js';
export function getUrlParam() {
let url = location.search;
let theRequest = {};
if (url.indexOf('?') !== -1) {
let strs = url.substr(1).split('&');
for (let i = 0; i < strs.length; i++) {
theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]);
}
}
return theRequest;
}
export function getArea({ provinceId = 0, cityId = 0, areaId = 0 }) {
let areaName = {};
for (let item of areas) {
if (provinceId === Number(item.id)) areaName.provinceName = item.name;
if (cityId === Number(item.id)) areaName.cityName = item.name;
if (areaId === Number(item.id)) areaName.areaName = item.name;
}
return areaName;
}
export function dateFormat({ time } = {}) {
// console.log(time);
let newTime = time ? time.split('.')[0].replace('T', ' ') : '';
// console.log(newTime);
let date = new Date(Date.parse(newTime.replace(/-/g, '/')));
// console.log(date);
let year = date.getFullYear();
let month = (date.getMonth() + 1 < 10) ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
let hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
let minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
let second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
}
export function dataSub(time) {
if (!time) return '';
let year = time.substring(0, 4);
let month = time.substring(4, 6);
let day = time.substring(6, 8);
let hour = time.substring(8, 10);
let minute = time.substring(10, 12);
let second = time.substring(12, 14);
return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
}
export function loginOut() {
clearCookie(cookieKey.userToken);
clearCookie(cookieKey.userDealerId);
location.href = '/login.html';
}
export function toFixed(num, len) {
// console.log(num);
let number = num.toString();
let numArr = number.split('.');
let rightNum = numArr[1];
// let returnNum = num;
if (rightNum && rightNum.length > len && len > 1) {
let posNum = rightNum.substr(len, 1);
let zs = rightNum.substr(len, 1);
if (zs === '5') {
rightNum = rightNum.substr(0, len) + (Number(posNum) + 1) + rightNum.substr(len + 1);
}
// let posNum = rightNum.substr(len, 1);
// if (zs === '5') {
// // console.log(rightNum);
// let centerNum = Number(posNum);
// if (centerNum % 2 === 0) {
// rightNum = rightNum.substr(0, len) + (Number(posNum) + 1) + rightNum.substr(len);
// }
// // console.log(rightNum);
// }
}
// console.log(parseFloat(numArr[0] + '.' + rightNum));
// console.log(parseFloat(numArr[0] + '.' + rightNum).toFixed(len));
return parseFloat(parseFloat(numArr[0] + '.' + rightNum).toFixed(len));
}
// export function dateFormat({ time } = {}) {
// let date = new Date(time);
// let year = date.getFullYear();
// let month = date.getMonth() + 1;
// let day = date.getDate();
// let hour = date.getHours();
// let minute = date.getMinutes();
// let second = date.getSeconds();
// return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
// }