在接口攔截 options.isExport,下載接口返回文件,經過a標籤
git
/**數組
*/dom
export function getSelectedOptions(enumList) { const array = []; enumList.forEach(item => { array.push( <Select.Option value={item.id} key={item.id}> {item.name} </Select.Option> ); }); return array; }
/**函數
*/ui
export function getEnumNameById(enumList, id) { if (id === '' || !enumList) return null; const result = enumList.find(item => String(item.id) === String(id)); return result ? result.name : null; }
/**url
*/spa
export function getEnumIdByName(enumList, name) { if (!name || !enumList) return null; const result = enumList.find(item => String(item.name) === String(name)); return result ? result.id : null; }
/**prototype
*/3d
export function getArrayProps(array, key) { const keys = key || 'id'; const res = []; if (array) { array.forEach(t => { res.push(t[keys]); }); } return res; }
/**code
*/
export function paramsTrim(params) { const values = {}; for (const key in params) { if ({}.hasOwnProperty.call(params, key)) { if (typeof params[key] === 'string') { values[key] = params[key].trim(); } else { values[key] = params[key]; } } } return values; }
/**
*/
export function getUrlPrmt(url) { const tempUrl = url || window.location.href || ''; const pa = tempUrl.substring(tempUrl.indexOf('?') + 1); const arrS = pa.split('&'); const rs = {}; for (let i = 0, len = arrS.length; i < len; i += 1) { const pos = arrS[i].indexOf('='); if (pos !== -1) { const name = arrS[i].substring(0, pos); const value = window.decodeURIComponent(arrS[i].substring(pos + 1)); rs[name] = value; } } return rs; }
/**
*/
export function isHas(obj, key) { const isObj = Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object; if (key === null || key === undefined || isObj === false) { return isObj; } let isHaskey = false; if (isObj && Object.prototype.hasOwnProperty.call(obj, key) && obj !== undefined) { isHaskey = obj[key] !== null && obj[key] !== undefined; } else { isHaskey = false; } return isHaskey; }
/**
*/
export function isArrayFn(value) { if (typeof Array.isArray === 'function') { return Array.isArray(value) && value.length > 0; } return Object.prototype.toString.call(value) === '[object Array]' && value.length > 0; } export default isArrayFn;
/**
*/
export function uuidGenerate() { const s = []; const hexDigits = '0123456789abcdef'; for (let i = 0; i < 36; i += 1) { s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); if ([8, 13, 18, 25].includes(i)) { s[i] = '-'; } } s[14] = '4'; s[19] = hexDigits.substr((s[19] && 0x3) || 0x8, 1); const uuid = s.join(''); return uuid; }