|
-
- import { i18n } from '~/langs';
- import { ACC_CARD_TYPE } from '~/const';
-
- export const getListValueWithKey = (list, key, k = 'k', v = 'v') => {
- for (let i = 0, iLen = list.length; i < iLen; i++) {
- const listI = list[i];
- if (listI[k] === key) return listI[v];
- }
- return key;
- };
-
- export const getUrlSearchParams = () => {
- const params = new URLSearchParams(location.search);
- const obj = {};
- params.forEach((value, key) => {
- obj[key] = value;
- });
- return obj;
- };
-
- export const transFileSize = (srcSize) => {
- if (null == srcSize || srcSize == '') {
- return '0 Bytes';
- }
- const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
- srcSize = parseFloat(srcSize);
- const index = Math.floor(Math.log(srcSize) / Math.log(1024));
- const size = (srcSize / Math.pow(1024, index)).toFixed(2);
- return size + ' ' + unitArr[index];
- };
-
- export const renderSpecStr = (spec, showPoint) => {
- if (!spec) return '';
- var ngpu = `${spec.ComputeResource}: ${spec.AccCardsNum + '*' + getListValueWithKey(ACC_CARD_TYPE, spec.AccCardType)}`;
- var gpuMemStr = spec.GPUMemGiB != 0 ? `${i18n.t('resourcesManagement.gpuMem')}: ${spec.GPUMemGiB}GB, ` : '';
- var sharedMemStr = spec.ShareMemGiB != 0 ? `, ${i18n.t('resourcesManagement.shareMem')}: ${spec.ShareMemGiB}GB` : '';
- var pointStr = showPoint ? `, ${spec.UnitPrice == 0 ? i18n.t('resourcesManagement.free') : spec.UnitPrice + i18n.t('resourcesManagement.point_hr')}` : '';
- var specStr = `${ngpu}, CPU: ${spec.CpuCores}, ${gpuMemStr}${i18n.t('resourcesManagement.mem')}: ${spec.MemGiB}GB${sharedMemStr}${pointStr}`;
- return specStr;
- };
|