/* * @Author: Yolo * @Date: 2020-11-13 13:27:19 * @Last Modified by: Yolo * @Last Modified time: 2020-12-08 10:10:01 * @Desc 通用方法 */ /** * 生成随机码 * @return 8f38d8c2-ee49-4d58-8872-c1c11a4860e8 */ export function uuid () { var s = []; var hexDigits = '0123456789abcdef'; for (var i = 0; i < 36; i++) { s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); } s[14] = '4'; s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); s[8] = s[13] = s[18] = s[23] = '-'; var uuid = s.join(''); return uuid; } /** * 初始化的时候如果 屏幕宽度小于 1420 直接隐藏左侧菜单 */ export function getIsCollapse () { const width = document.body.clientWidth; return width < 1420 } /** * 动态判断屏幕大小 */ export function getScreen () { const width = document.body.clientWidth; if (width >= 1200) { return 3; //大屏幕 } else if (width >= 992) { return 2; //中屏幕 } else if (width >= 768) { return 1; //小屏幕 } else { return 0; //超小屏幕 } } /** * 按钮权限通用包装 * @param {*} data * @param {*} authData */ export const ListButtonAuthAdapter = (data, authData) => { return data.map((item, index) => ({ ...item, buttonPermissions: authData[index], })); }; /** * 计算证书到期时间 // TODO: 抽离到通用计算中 * * @param {*} issueDate * @param {*} validDate * @param {*} flag * @param {*} birthday * @return {*} */ export const issueDateMethod = (issueDate, validDate, flag, birthday) => { var passPortExpirationDate = '' if (issueDate.indexOf('/') >= 0) { issueDate = issueDate.replaceAll('/', '-'); } else if (issueDate.indexOf('.') >= 0) { issueDate = issueDate.replaceAll('\\.', '-'); } else if (issueDate.indexOf('_') >= 0) { issueDate = issueDate.replaceAll('_', '-'); } if (issueDate && validDate) { validDate = validDate.replace(/[^0-9]/ig, ''); var issueDateVal; if (validDate != '65') { issueDateVal = new Date(issueDate) issueDateVal = new Date( issueDateVal.getFullYear() + parseInt(validDate), issueDateVal.getMonth(), issueDateVal.getDate() ); } else if (validDate == '65' && birthday) { issueDateVal = new Date(birthday) issueDateVal = new Date( issueDateVal.getFullYear() + 65, issueDateVal.getMonth(), issueDateVal.getDate() ); } // 含当天 if (flag) { issueDateVal.setDate((issueDateVal.getDate() + 1) - 1); } // 不含当天 else { issueDateVal.setDate((issueDateVal.getDate() + 1) - 1 * 2); } var year = issueDateVal.getFullYear(); var mStr = new String(issueDateVal.getMonth() + 1); var dStr = new String(issueDateVal.getDate()); if (mStr.length == 1) { mStr = '0' + mStr; } if (dStr.length == 1) { dStr = '0' + dStr; } passPortExpirationDate = year + '-' + mStr + '-' + dStr; } return passPortExpirationDate; }