Blame view

src/utils/util.js 2.56 KB
yangwei committed
1
import cookies from './util.cookies'
yuanbo committed
2 3 4 5 6
/**
 * @description: getUrlParam
 * @param {*} paraName
 * @author: renchao
 */
7
export function getUrlParam (paraName) {
yangwei committed
8 9 10 11 12 13 14 15 16 17 18 19
    let url = document.location.toString();
    let arrObj = url.split('?');

    if (arrObj.length > 1) {
        let arrPara = arrObj[1].split('&');
        let arr;

        for (let i = 0; i < arrPara.length; i++) {
            arr = arrPara[i].split('=');

            if (arr != null && arr[0] === paraName) {
                // 截取#之前的内容
20
                let result = arr[1].endsWith('#/') ? arr[1].substr(0, arr[1].indexOf('#')) : arr[1];
yangwei committed
21 22 23 24 25 26 27 28
                return result;
            }
        }
        return '';
    } else {
        return '';
    }
}
yuanbo committed
29 30 31 32 33
/**
 * @description: setToken
 * @param {*} token
 * @author: renchao
 */
34
export function setToken (token) {
yangwei committed
35 36 37 38
    if (token === undefined) {
        if (process.env.NODE_ENV === 'development') {
            sessionStorage.removeItem('token')
        } else {
39
            cookies.remove('ACCESS_TOKEN')
yangwei committed
40 41 42 43 44
        }
    } else {
        if (process.env.NODE_ENV === 'development') {
            sessionStorage.setItem('token', token);
        } else {
45
            cookies.set('ACCESS_TOKEN', token)
yangwei committed
46 47 48
        }
    }
}
yuanbo committed
49 50 51 52
/**
 * @description: getToken
 * @author: renchao
 */
53
export function getToken () {
yangwei committed
54 55 56 57 58 59
    if (process.env.NODE_ENV === 'development') {
        return sessionStorage.getItem('token')
    }
    return cookies.get('ACCESS_TOKEN')
}

60
// 获取当前时间
yuanbo committed
61 62 63 64 65
/**
 * @description: 获取当前时间
 * @param {*} type
 * @author: renchao
 */
66 67 68 69 70 71 72 73 74 75 76 77 78
export function getNewDate (type = 1) {
    const now = new Date();
    const year = now.getFullYear();
    const month = String(now.getMonth() + 1).padStart(2, '0');
    const day = String(now.getDate()).padStart(2, '0');
    const hours = String(now.getHours()).padStart(2, '0');
    const minutes = String(now.getMinutes()).padStart(2, '0');
    const seconds = String(now.getSeconds()).padStart(2, '0');
    if (type == 1) {
        return `${year}${month}${day}日`
    } else {
        return `${year}${month}${day}${hours}${minutes}${seconds}秒`
    }
yuanbo committed
79
}
xiaomiao committed
80 81 82 83 84 85 86 87 88 89 90

export function getNewDatesh () {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0');
  const day = String(now.getDate()).padStart(2, '0');
  const hours = String(now.getHours()).padStart(2, '0');
  const minutes = String(now.getMinutes()).padStart(2, '0');
  const seconds = String(now.getSeconds()).padStart(2, '0');
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}