2024-02-10 17:41:07 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/* @var $this yii\web\View */
|
|
|
|
/* @var $directoryContents array 文件和文件夹内容数组 */
|
|
|
|
/* @var $parentDirectory string 父目录 */
|
2024-02-11 16:04:21 +08:00
|
|
|
|
2024-02-10 17:41:07 +08:00
|
|
|
/* @var $directory string 当前路径 */
|
|
|
|
|
2024-02-11 16:04:21 +08:00
|
|
|
use app\models\RenameForm;
|
|
|
|
use yii\bootstrap5\ActiveForm;
|
2024-02-10 17:41:07 +08:00
|
|
|
use yii\bootstrap5\Html;
|
2024-02-11 12:39:05 +08:00
|
|
|
use app\assets\FontAwesomeAsset;
|
2024-02-11 16:04:21 +08:00
|
|
|
use yii\bootstrap5\Modal;
|
|
|
|
use yii\helpers\Url;
|
|
|
|
use yii\web\JqueryAsset;
|
|
|
|
use yii\web\View;
|
|
|
|
|
2024-02-10 17:41:07 +08:00
|
|
|
|
|
|
|
$this->title = '文件管理';
|
|
|
|
$this->params['breadcrumbs'][] = $this->title;
|
2024-02-11 12:39:05 +08:00
|
|
|
FontAwesomeAsset::register($this);
|
2024-02-11 16:04:21 +08:00
|
|
|
JqueryAsset::register($this);
|
|
|
|
$this->registerCssFile('@web/css/home_style.css');
|
2024-02-10 17:41:07 +08:00
|
|
|
?>
|
|
|
|
<div class="home-directory">
|
|
|
|
<h1><?= Html::encode($this->title) ?></h1>
|
|
|
|
|
2024-02-11 12:39:05 +08:00
|
|
|
<nav aria-label="breadcrumb">
|
|
|
|
<ol class="breadcrumb">
|
|
|
|
<?= Html::a('HOME', ['home/index'], ['class' => 'breadcrumb-item']) ?>
|
|
|
|
<?php if ($directory !== null): ?>
|
|
|
|
<?php
|
|
|
|
$parts = explode('/', $directory);
|
|
|
|
$path = '';
|
|
|
|
foreach ($parts as $part):
|
|
|
|
$path .= $part;
|
|
|
|
echo Html::a($part, ['home/index', 'directory' => $path], ['class' => 'breadcrumb-item']);
|
|
|
|
$path .= '/';
|
|
|
|
endforeach;
|
|
|
|
?>
|
|
|
|
<?php endif; ?>
|
|
|
|
</ol>
|
|
|
|
</nav>
|
2024-02-10 17:41:07 +08:00
|
|
|
|
2024-02-11 12:39:05 +08:00
|
|
|
<table class="table table-hover">
|
|
|
|
<thead class="table-light">
|
|
|
|
<tr>
|
2024-02-12 14:04:13 +08:00
|
|
|
<th scope="col" class="name-col">名称</th>
|
|
|
|
<th scope="col" class="modified-col">最近修改时间</th>
|
|
|
|
<th scope="col" class="size-col">大小</th>
|
|
|
|
<th scope="col" class="action-col">操作</th>
|
2024-02-11 12:39:05 +08:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2024-02-10 17:41:07 +08:00
|
|
|
<?php foreach ($directoryContents as $item): ?>
|
2024-02-11 12:39:05 +08:00
|
|
|
<?php $relativePath = $directory ? $directory . '/' . $item['name'] : $item['name']; ?>
|
2024-02-10 17:41:07 +08:00
|
|
|
<?php $absolutePath = Yii::getAlias('@app') . '/data/' . Yii::$app->user->id . '/' . $relativePath; ?>
|
2024-02-11 12:39:05 +08:00
|
|
|
<tr>
|
2024-02-12 14:04:13 +08:00
|
|
|
<?php if (is_dir($absolutePath)): ?> <!-- 如果是文件夹 -->
|
2024-02-11 12:39:05 +08:00
|
|
|
<td>
|
2024-02-11 16:04:21 +08:00
|
|
|
<?= Html::tag('i', '', ['class' => $item['type'] . ' file_icon']) ?>
|
|
|
|
<?= Html::a($item['name'], ['home/index', 'directory' => $relativePath], ['class' => 'file_name']) ?>
|
|
|
|
</td>
|
2024-02-12 14:04:13 +08:00
|
|
|
<td class="file_info">
|
|
|
|
<?= date('Y-m-d H:i:s', $item['lastModified']) ?>
|
|
|
|
</td>
|
|
|
|
<td class="file_info">
|
|
|
|
---
|
|
|
|
</td>
|
2024-02-11 16:04:21 +08:00
|
|
|
<td>
|
2024-02-12 13:03:37 +08:00
|
|
|
<?= Html::button(Html::tag('i', '', ['class' => 'fa-solid fa-download']), [
|
|
|
|
'value' => Url::to(['home/download', 'relativePath' => $relativePath]),
|
|
|
|
'class' => 'btn btn-outline-primary folder-download-btn',
|
|
|
|
'data-bs-toggle' => 'tooltip',
|
|
|
|
'data-bs-placement' => 'top',
|
|
|
|
'data-bs-title' => '打包下载'
|
|
|
|
]) ?>
|
2024-02-12 12:01:08 +08:00
|
|
|
<?= Html::button(Html::tag('i', '', ['class' => 'fa-regular fa-pen-to-square']), ['value' => $relativePath, 'class' => 'btn btn-outline-secondary rename-btn', 'data-bs-toggle' => 'tooltip', 'data-bs-placement' => 'top', 'data-bs-title' => '重命名']) ?>
|
2024-02-12 14:04:13 +08:00
|
|
|
<?= Html::button(Html::tag('i', '', ['class' => 'fa-regular fa-trash-can']), ['value' => $relativePath, 'class' => 'btn btn-outline-danger delete-btn', 'data-bs-toggle' => 'tooltip', 'data-bs-placement' => 'top', 'data-bs-title' => '删除']) ?>
|
2024-02-11 12:39:05 +08:00
|
|
|
</td>
|
2024-02-12 14:04:13 +08:00
|
|
|
<?php else: ?> <!-- 如果是文件 -->
|
2024-02-11 12:39:05 +08:00
|
|
|
<td>
|
2024-02-11 16:04:21 +08:00
|
|
|
<?= Html::tag('i', '', ['class' => $item['type'] . ' file_icon']) ?>
|
|
|
|
<?= Html::a($item['name'], ['home/download', 'relativePath' => $relativePath], ['class' => 'file_name']) ?>
|
|
|
|
</td>
|
2024-02-12 14:04:13 +08:00
|
|
|
<td class="file_info">
|
|
|
|
<?= date('Y-m-d H:i:s', $item['lastModified']) ?>
|
|
|
|
</td>
|
|
|
|
<td class="file_info">
|
|
|
|
<?= $item['size'] !== null ? Yii::$app->formatter->asShortSize($item['size'], 2) : '' ?>
|
|
|
|
</td>
|
2024-02-11 16:04:21 +08:00
|
|
|
<td>
|
|
|
|
<?= Html::button(Html::tag('i', '', ['class' => 'fa-regular fa-circle-down']), [
|
|
|
|
'value' => Url::to(['home/download', 'relativePath' => $relativePath]),
|
2024-02-12 12:01:08 +08:00
|
|
|
'class' => 'btn btn-outline-primary download-btn',
|
|
|
|
'data-bs-toggle' => 'tooltip',
|
|
|
|
'data-bs-placement' => 'top',
|
|
|
|
'data-bs-title' => '下载'
|
2024-02-11 16:04:21 +08:00
|
|
|
]) ?>
|
2024-02-12 12:01:08 +08:00
|
|
|
<?= Html::button(Html::tag('i', '', ['class' => 'fa-regular fa-pen-to-square']), ['value' => $relativePath, 'class' => 'btn btn-outline-secondary rename-btn', 'data-bs-toggle' => 'tooltip', 'data-bs-placement' => 'top', 'data-bs-title' => '重命名']) ?>
|
2024-02-12 14:04:13 +08:00
|
|
|
<?= Html::button(Html::tag('i', '', ['class' => 'fa-regular fa-trash-can']), ['value' => $relativePath, 'class' => 'btn btn-outline-danger delete-btn', 'data-bs-toggle' => 'tooltip', 'data-bs-placement' => 'top', 'data-bs-title' => '删除']) ?>
|
2024-02-11 12:39:05 +08:00
|
|
|
</td>
|
|
|
|
<?php endif; ?>
|
|
|
|
</tr>
|
2024-02-10 17:41:07 +08:00
|
|
|
<?php endforeach; ?>
|
2024-02-11 12:39:05 +08:00
|
|
|
</tbody>
|
|
|
|
</table>
|
2024-02-11 16:04:21 +08:00
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
Modal::begin([
|
|
|
|
'title' => '<h4>重命名文件/文件夹</h4>',
|
|
|
|
'id' => 'renameModal',
|
|
|
|
'size' => 'modal-lg',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$model = new RenameForm();
|
|
|
|
$form = ActiveForm::begin(['id' => 'rename-form', 'action' => ['home/rename'], 'method' => 'post']);
|
|
|
|
|
|
|
|
echo $form->field($model, 'newName')->textInput(['maxlength' => true])->label('新名称');
|
|
|
|
echo Html::hiddenInput('relativePath', '', ['id' => 'renameRelativePath']);
|
|
|
|
echo Html::submitButton('提交', ['class' => 'btn btn-primary']);
|
|
|
|
|
|
|
|
ActiveForm::end();
|
|
|
|
Modal::end();
|
|
|
|
|
2024-02-12 12:01:08 +08:00
|
|
|
Modal::begin([
|
|
|
|
'title' => '<h4>确认删除</h4>',
|
|
|
|
'id' => 'deleteModal',
|
|
|
|
'size' => 'modal-sm',
|
|
|
|
]);
|
|
|
|
|
|
|
|
echo Html::tag('div', '你确定要删除这个文件吗?', ['class' => 'modal-body']);
|
|
|
|
|
|
|
|
echo Html::beginForm(['home/delete'], 'post', ['id' => 'delete-form']);
|
|
|
|
echo Html::hiddenInput('relativePath', '', ['id' => 'deleteRelativePath']);
|
|
|
|
echo Html::submitButton('确认', ['class' => 'btn btn-danger']);
|
|
|
|
echo Html::endForm();
|
|
|
|
|
|
|
|
Modal::end();
|
2024-02-12 14:04:13 +08:00
|
|
|
$this->registerJsFile('@web/js/home_script.js', ['depends' => [JqueryAsset::class], 'position' => View::POS_END]);
|
2024-02-11 16:04:21 +08:00
|
|
|
?>
|
|
|
|
|