2023-06-07 23:26:00 +08:00
|
|
|
|
import { Label } from 'semantic-ui-react';
|
2023-11-27 22:43:46 +08:00
|
|
|
|
import {Tag} from "@douyinfe/semi-ui";
|
2023-06-07 23:26:00 +08:00
|
|
|
|
|
2023-05-16 21:33:59 +08:00
|
|
|
|
export function renderText(text, limit) {
|
|
|
|
|
|
if (text.length > limit) {
|
|
|
|
|
|
return text.slice(0, limit - 3) + '...';
|
|
|
|
|
|
}
|
|
|
|
|
|
return text;
|
2023-06-07 23:26:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function renderGroup(group) {
|
2023-06-16 15:20:06 +08:00
|
|
|
|
if (group === '') {
|
2023-11-27 22:43:46 +08:00
|
|
|
|
return <Tag size='large'>default</Tag>;
|
2023-06-07 23:26:00 +08:00
|
|
|
|
}
|
2023-06-16 15:20:06 +08:00
|
|
|
|
let groups = group.split(',');
|
2023-06-14 12:52:56 +08:00
|
|
|
|
groups.sort();
|
|
|
|
|
|
return <>
|
|
|
|
|
|
{groups.map((group) => {
|
2023-06-16 15:20:06 +08:00
|
|
|
|
if (group === 'vip' || group === 'pro') {
|
2023-11-27 22:43:46 +08:00
|
|
|
|
return <Tag size='large' color='yellow'>{group}</Tag>;
|
2023-06-16 15:20:06 +08:00
|
|
|
|
} else if (group === 'svip' || group === 'premium') {
|
2023-11-27 22:43:46 +08:00
|
|
|
|
return <Tag size='large' color='red'>{group}</Tag>;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (group === 'default') {
|
|
|
|
|
|
return <Tag size='large'>{group}</Tag>;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return <Tag size='large' color={stringToColor(group)}>{group}</Tag>;
|
2023-06-14 12:52:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
})}
|
2023-06-16 15:20:06 +08:00
|
|
|
|
</>;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function renderNumber(num) {
|
|
|
|
|
|
if (num >= 1000000000) {
|
|
|
|
|
|
return (num / 1000000000).toFixed(1) + 'B';
|
|
|
|
|
|
} else if (num >= 1000000) {
|
|
|
|
|
|
return (num / 1000000).toFixed(1) + 'M';
|
|
|
|
|
|
} else if (num >= 10000) {
|
|
|
|
|
|
return (num / 1000).toFixed(1) + 'k';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return num;
|
|
|
|
|
|
}
|
2023-06-20 20:09:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-11 20:42:51 +08:00
|
|
|
|
export function renderNumberWithPoint(num) {
|
|
|
|
|
|
num = num.toFixed(2);
|
|
|
|
|
|
if (num >= 100000) {
|
|
|
|
|
|
// Convert number to string to manipulate it
|
|
|
|
|
|
let numStr = num.toString();
|
|
|
|
|
|
// Find the position of the decimal point
|
|
|
|
|
|
let decimalPointIndex = numStr.indexOf('.');
|
|
|
|
|
|
|
|
|
|
|
|
let wholePart = numStr;
|
|
|
|
|
|
let decimalPart = '';
|
|
|
|
|
|
|
|
|
|
|
|
// If there is a decimal point, split the number into whole and decimal parts
|
|
|
|
|
|
if (decimalPointIndex !== -1) {
|
|
|
|
|
|
wholePart = numStr.slice(0, decimalPointIndex);
|
|
|
|
|
|
decimalPart = numStr.slice(decimalPointIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Take the first two and last two digits of the whole number part
|
|
|
|
|
|
let shortenedWholePart = wholePart.slice(0, 2) + '..' + wholePart.slice(-2);
|
|
|
|
|
|
|
|
|
|
|
|
// Return the formatted number
|
|
|
|
|
|
return shortenedWholePart + decimalPart;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the number is less than 100,000, return it unmodified
|
|
|
|
|
|
return num;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-21 16:35:51 +08:00
|
|
|
|
export function getQuotaPerUnit() {
|
|
|
|
|
|
let quotaPerUnit = localStorage.getItem('quota_per_unit');
|
|
|
|
|
|
quotaPerUnit = parseFloat(quotaPerUnit);
|
|
|
|
|
|
return quotaPerUnit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-07 18:31:14 +08:00
|
|
|
|
export function getQuotaWithUnit(quota, digits = 6) {
|
|
|
|
|
|
let quotaPerUnit = localStorage.getItem('quota_per_unit');
|
|
|
|
|
|
quotaPerUnit = parseFloat(quotaPerUnit);
|
|
|
|
|
|
return (quota / quotaPerUnit).toFixed(digits);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-20 20:09:17 +08:00
|
|
|
|
export function renderQuota(quota, digits = 2) {
|
|
|
|
|
|
let quotaPerUnit = localStorage.getItem('quota_per_unit');
|
|
|
|
|
|
let displayInCurrency = localStorage.getItem('display_in_currency');
|
|
|
|
|
|
quotaPerUnit = parseFloat(quotaPerUnit);
|
|
|
|
|
|
displayInCurrency = displayInCurrency === 'true';
|
|
|
|
|
|
if (displayInCurrency) {
|
|
|
|
|
|
return '$' + (quota / quotaPerUnit).toFixed(digits);
|
|
|
|
|
|
}
|
|
|
|
|
|
return renderNumber(quota);
|
2023-06-21 15:45:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function renderQuotaWithPrompt(quota, digits) {
|
|
|
|
|
|
let displayInCurrency = localStorage.getItem('display_in_currency');
|
|
|
|
|
|
displayInCurrency = displayInCurrency === 'true';
|
|
|
|
|
|
if (displayInCurrency) {
|
|
|
|
|
|
return `(等价金额:${renderQuota(quota, digits)})`;
|
|
|
|
|
|
}
|
|
|
|
|
|
return '';
|
2023-10-31 00:03:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const colors = ['amber', 'blue', 'cyan', 'green', 'grey', 'indigo',
|
|
|
|
|
|
'light-blue', 'lime', 'orange', 'pink',
|
|
|
|
|
|
'purple', 'red', 'teal', 'violet', 'yellow'
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
export function stringToColor(str) {
|
|
|
|
|
|
let sum = 0;
|
|
|
|
|
|
// 对字符串中的每个字符进行操作
|
|
|
|
|
|
for (let i = 0; i < str.length; i++) {
|
|
|
|
|
|
// 将字符的ASCII值加到sum中
|
|
|
|
|
|
sum += str.charCodeAt(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 使用模运算得到个位数
|
|
|
|
|
|
let i = sum % colors.length;
|
|
|
|
|
|
return colors[i];
|
2023-05-16 21:33:59 +08:00
|
|
|
|
}
|