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 1.6 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { i18n } from '~/langs';
  2. import { ACC_CARD_TYPE } from '~/const';
  3. export const getListValueWithKey = (list, key, k = 'k', v = 'v') => {
  4. for (let i = 0, iLen = list.length; i < iLen; i++) {
  5. const listI = list[i];
  6. if (listI[k] === key) return listI[v];
  7. }
  8. return key;
  9. };
  10. export const getUrlSearchParams = () => {
  11. const params = new URLSearchParams(location.search);
  12. const obj = {};
  13. params.forEach((value, key) => {
  14. obj[key] = value;
  15. });
  16. return obj;
  17. };
  18. export const transFileSize = (srcSize) => {
  19. if (null == srcSize || srcSize == '') {
  20. return '0 Bytes';
  21. }
  22. const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  23. srcSize = parseFloat(srcSize);
  24. const index = Math.floor(Math.log(srcSize) / Math.log(1024));
  25. const size = (srcSize / Math.pow(1024, index)).toFixed(2);
  26. return size + ' ' + unitArr[index];
  27. };
  28. export const renderSpecStr = (spec, showPoint) => {
  29. if (!spec) return '';
  30. var ngpu = `${spec.ComputeResource}: ${spec.AccCardsNum + '*' + getListValueWithKey(ACC_CARD_TYPE, spec.AccCardType)}`;
  31. var gpuMemStr = spec.GPUMemGiB != 0 ? `${i18n.t('resourcesManagement.gpuMem')}: ${spec.GPUMemGiB}GB, ` : '';
  32. var sharedMemStr = spec.ShareMemGiB != 0 ? `, ${i18n.t('resourcesManagement.shareMem')}: ${spec.ShareMemGiB}GB` : '';
  33. var pointStr = showPoint ? `, ${spec.UnitPrice == 0 ? i18n.t('resourcesManagement.free') : spec.UnitPrice + i18n.t('resourcesManagement.point_hr')}` : '';
  34. var specStr = `${ngpu}, CPU: ${spec.CpuCores}, ${gpuMemStr}${i18n.t('resourcesManagement.mem')}: ${spec.MemGiB}GB${sharedMemStr}${pointStr}`;
  35. return specStr;
  36. };