You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 802 B

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627
  1. export const getListValueWithKey = (list, key, k = 'k', v = 'v') => {
  2. for (let i = 0, iLen = list.length; i < iLen; i++) {
  3. const listI = list[i];
  4. if (listI[k] === key) return listI[v];
  5. }
  6. return key;
  7. };
  8. export const getUrlSearchParams = () => {
  9. const params = new URLSearchParams(location.search);
  10. const obj = {};
  11. params.forEach((value, key) => {
  12. obj[key] = value;
  13. });
  14. return obj;
  15. };
  16. export const transFileSize = (srcSize) => {
  17. if (null == srcSize || srcSize == '') {
  18. return '0 Bytes';
  19. }
  20. const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  21. srcSize = parseFloat(srcSize);
  22. const index = Math.floor(Math.log(srcSize) / Math.log(1024));
  23. const size = (srcSize / Math.pow(1024, index)).toFixed(2);
  24. return size + ' ' + unitArr[index];
  25. };