From c3f51cc9f2f02f71a27ed6f5b9c968805442cfc5 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sat, 9 Mar 2024 17:25:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=98=BE=E7=A4=BA=E5=AE=B9=E9=87=8F=20*?= =?UTF-8?q?=E7=82=B9=EF=BC=81=E6=8C=89=E9=92=AE=E6=98=BE=E7=A4=BA=E6=96=87?= =?UTF-8?q?=E5=AD=97=E7=89=88=E5=AE=B9=E9=87=8F=E7=8A=B6=E5=86=B5=20?= =?UTF-8?q?=EF=BC=88=E6=88=91=E5=AE=9E=E5=9C=A8=E6=98=AF=E6=89=BE=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E4=B8=80=E5=9D=97=E5=9C=B0=E6=96=B9=E6=94=BE=E5=AE=B9?= =?UTF-8?q?=E9=87=8F=E6=98=BE=E7=A4=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++++ controllers/HomeController.php | 8 ++++++++ views/home/index.php | 23 +++++++++++++++-------- web/js/home_script.js | 2 ++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cfb7058..e0d32e6 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ 部分安全强化(ACL、RBAC) +首页容量显示(点!按钮) + 计划实现的功能 ------------------- @@ -71,6 +73,8 @@ 文件存储加密 +passwordless + 和管理员相关的功能 忘记密码 diff --git a/controllers/HomeController.php b/controllers/HomeController.php index bb7b617..8c1421d 100644 --- a/controllers/HomeController.php +++ b/controllers/HomeController.php @@ -6,6 +6,7 @@ use app\models\NewFolderForm; use app\models\RenameForm; use app\models\UploadForm; use app\models\ZipForm; +use app\utils\FileSizeHelper; use app\utils\FileTypeDetector; use Exception; use RecursiveDirectoryIterator; @@ -75,6 +76,7 @@ class HomeController extends Controller */ public function actionIndex($directory = null): Response|string { + $model = Yii::$app->user->identity; // if (Yii::$app->user->isGuest) { // Yii::$app->session->setFlash('error','请先登录'); // return $this->redirect(Yii::$app->user->loginUrl); @@ -101,10 +103,16 @@ class HomeController extends Controller $rawType = is_file($absolutePath) ? mime_content_type($absolutePath) : null; $directoryContents[$key] = ['name' => $item, 'type' => $type, 'lastModified' => $lastModified, 'size' => $size, 'rawType' => $rawType]; } + $usedSpace = FileSizeHelper::getDirectorySize(Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . Yii::$app->user->id); + $vaultUsedSpace = 0; // 保险箱已用空间,暂时为0 + $storageLimit = $model->storage_limit; return $this->render('index', [ 'directoryContents' => $directoryContents, 'parentDirectory' => $parentDirectory, 'directory' => $directory, // 将$directory传递给视图 + 'usedSpace' => $usedSpace, // B + 'vaultUsedSpace' => $vaultUsedSpace, // B + 'storageLimit' => $storageLimit, // MB ]); } diff --git a/views/home/index.php b/views/home/index.php index d0b45ae..76a7cb0 100644 --- a/views/home/index.php +++ b/views/home/index.php @@ -3,6 +3,9 @@ /* @var $this yii\web\View */ /* @var $directoryContents array 文件和文件夹内容数组 */ /* @var $parentDirectory string 父目录 */ +/* @var $usedSpace int */ +/* @var $vaultUsedSpace int */ +/* @var $storageLimit int */ /* @var $directory string 当前路径 */ @@ -14,6 +17,7 @@ use app\models\NewFolderForm; use app\models\RenameForm; use app\models\Share; use app\models\ZipForm; +use app\utils\FileSizeHelper; use yii\bootstrap5\ActiveForm; use yii\bootstrap5\Html; use app\assets\FontAwesomeAsset; @@ -25,6 +29,13 @@ use yii\web\View; $this->title = '文件管理'; $this->params['breadcrumbs'][] = $this->title; +$totalUsed_F = FileSizeHelper::formatBytes($usedSpace + $vaultUsedSpace); //总已用空间 格式化文本 +$storageLimit_F = FileSizeHelper::formatMegaBytes($storageLimit); //存储限制 格式化文本 +$is_unlimited = ($storageLimit === -1); //检查是否为无限制容量 +$usedPercent = $is_unlimited ? 0 : round($usedSpace / ($storageLimit * 1024 * 1024) * 100); //网盘已用百分比 +$vaultUsedPercent = $is_unlimited ? 0 : round($vaultUsedSpace / ($storageLimit * 1024 * 1024) * 100); //保险箱已用百分比 +$totalUsedPercent = min(($usedPercent + $vaultUsedPercent), 100); //总已用百分比 + FontAwesomeAsset::register($this); JqueryAsset::register($this); ViewerJsAsset::register($this); @@ -65,16 +76,12 @@ $this->registerCssFile('@web/css/home_style.css');
  • 'dropdown-item file-upload-btn']) ?>
  • 'dropdown-item folder-upload-btn']) ?>
  • - -
  • - -
  • -
  • - - 'dropdown-item offline-download-btn', 'disabled' => true]) ?> -
  • + diff --git a/web/js/home_script.js b/web/js/home_script.js index 528977d..db89246 100644 --- a/web/js/home_script.js +++ b/web/js/home_script.js @@ -669,3 +669,5 @@ $(document).on('click', '.create-collection-btn', function () { $('#collectionModal').modal('show'); }); +const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]') +const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl)) \ No newline at end of file