Rewrite web front-end using React
This is a big commit, some font-end function are still working, including manage, error handle, as others.
This commit is contained in:
40
web/src/component/Common.js
Normal file
40
web/src/component/Common.js
Normal file
@@ -0,0 +1,40 @@
|
||||
export function CalcReadableFilesize(filesize) {
|
||||
if (filesize < 1024) {
|
||||
return filesize;
|
||||
}
|
||||
if (filesize < 1024 * 1024) {
|
||||
return Math.round(filesize / 1024) + "K";
|
||||
}
|
||||
if (filesize < 1024 * 1024 * 1024) {
|
||||
return Math.round(filesize / 1024 / 1024) + "M";
|
||||
}
|
||||
if (filesize < 1024 * 1024 * 1024 * 1024) {
|
||||
return Math.round(filesize / 1024 / 1024 / 1024) + "G";
|
||||
}
|
||||
}
|
||||
|
||||
export function CalcReadableFilesizeDetail(filesize) {
|
||||
if (filesize < 1024 * 1024) {
|
||||
return filesize;
|
||||
}
|
||||
if (filesize < 1024 * 1024 * 1024) {
|
||||
return numberWithCommas(Math.round(filesize / 1024)) + "K";
|
||||
}
|
||||
if (filesize < 1024 * 1024 * 1024 * 1024) {
|
||||
return numberWithCommas(Math.round(filesize / 1024 / 1024)) + "M";
|
||||
}
|
||||
if (filesize < 1024 * 1024 * 1024 * 1024 * 1024) {
|
||||
return numberWithCommas(Math.round(filesize / 1024 / 1024 / 1024)) + "G";
|
||||
}
|
||||
}
|
||||
|
||||
function numberWithCommas(x) {
|
||||
x = x.toString();
|
||||
var pattern = /(-?\d+)(\d{3})/;
|
||||
while (pattern.test(x)) x = x.replace(pattern, "$1,$2");
|
||||
return x;
|
||||
}
|
||||
|
||||
export function SayHello() {
|
||||
return "Hello";
|
||||
}
|
||||
Reference in New Issue
Block a user