共计 2259 个字符,预计需要花费 6 分钟才能阅读完成。
在接口拦挡 options.isExport,下载接口返回文件,通过 a 标签
/**
- 依据枚举组装 options 函数
*/
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;
}
/**
- 依据 id 取得枚举的 name
*/
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;
}
/**
- 依据 name 取得枚举的 id
*/
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;
}
/**
- 获取数组对象中某个属性
*/
export function getArrayProps(array, key) {
const keys = key || 'id';
const res = [];
if (array) {
array.forEach(t => {res.push(t[keys]);
});
}
return res;
}
/**
- 去除参数 前后空格
*/
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;
/**
- 生成 uuid
*/
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;
}
正文完
发表至: javascript
2020-11-19