diff --git a/controllers/UserController.php b/controllers/UserController.php index 1385e7a..e51dc0e 100644 --- a/controllers/UserController.php +++ b/controllers/UserController.php @@ -4,6 +4,7 @@ namespace app\controllers; use app\models\User; use app\models\UserSearch; +use app\utils\FileSizeHelper; use ReCaptcha\ReCaptcha; use Yii; use yii\base\Exception; @@ -321,7 +322,7 @@ class UserController extends Controller /** * @return string|Response */ - public function actionInfo() + public function actionInfo(): Response|string { if (Yii::$app->user->isGuest) { Yii::$app->session->setFlash('error', '请先登录'); @@ -329,8 +330,17 @@ class UserController extends Controller } $model = Yii::$app->user->identity; + $dataDirectory = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . Yii::$app->user->id; + $usedSpace = FileSizeHelper::getDirectorySize($dataDirectory); + $vaultUsedSpace = 0; // 保险箱已用空间,暂时为0 + $storageLimit = $model->storage_limit; + return $this->render('info', [ 'model' => $model, + 'usedSpace' => $usedSpace, // B + 'vaultUsedSpace' => $vaultUsedSpace, + 'storageLimit' => $storageLimit, // MB ]); } + } diff --git a/views/user/info.php b/views/user/info.php index e9cd3af..6c2045c 100644 --- a/views/user/info.php +++ b/views/user/info.php @@ -3,8 +3,13 @@ /* @var $this yii\web\View */ /* @var $model app\models\User */ +/* @var $usedSpace int */ +/* @var $vaultUsedSpace int */ + +/* @var $storageLimit int */ use app\assets\FontAwesomeAsset; +use app\utils\FileSizeHelper; use app\utils\IPLocation; use yii\bootstrap5\Html; @@ -12,9 +17,15 @@ $this->title = '个人设置'; FontAwesomeAsset::register($this); $this->registerCssFile('@web/css/user-info.css'); $details = IPLocation::getDetails($model->last_login_ip); -//if (is_null($details)) { -// echo ''; -//} + +$usedSpace_F = FileSizeHelper::formatBytes($usedSpace); +$vaultUsedSpace_F = FileSizeHelper::formatBytes($vaultUsedSpace); +$storageLimit_F = FileSizeHelper::formatMegaBytes($storageLimit); +$totalUsed_F = FileSizeHelper::formatBytes($usedSpace + $vaultUsedSpace); +$is_unlimited = ($storageLimit === -1); +$usedPercent = $is_unlimited ? 0 : round($usedSpace / $storageLimit * 100); +$vaultUsedPercent = $is_unlimited ? 0 : round($vaultUsedSpace / $storageLimit * 100); +$totalUsedPercent = min(($usedPercent + $vaultUsedPercent), 100); ?>
@@ -71,7 +82,7 @@ $details = IPLocation::getDetails($model->last_login_ip); 存储空间 - N/A + @@ -82,31 +93,34 @@ $details = IPLocation::getDetails($model->last_login_ip);

当前已使用容量

- N/A GB - / N/A TB + + + /
-

N/A% 已用

+

% 已用

网盘已用空间 - N/A GB
保险箱已用空间 - N/A GB