功能增强

新增删除按钮
为按钮增加tooltips提示
This commit is contained in:
Chenx221 2024-02-12 12:01:08 +08:00
parent 0ce6a052f1
commit 78c9fe01dd
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021

View File

@ -52,20 +52,17 @@ $this->registerCssFile('@web/css/home_style.css');
<tbody> <tbody>
<?php foreach ($directoryContents as $item): ?> <?php foreach ($directoryContents as $item): ?>
<?php $relativePath = $directory ? $directory . '/' . $item['name'] : $item['name']; ?> <?php $relativePath = $directory ? $directory . '/' . $item['name'] : $item['name']; ?>
<!-- 修复错误的绝对路径问题-->
<?php $absolutePath = Yii::getAlias('@app') . '/data/' . Yii::$app->user->id . '/' . $relativePath; ?> <?php $absolutePath = Yii::getAlias('@app') . '/data/' . Yii::$app->user->id . '/' . $relativePath; ?>
<tr> <tr>
<?php if (is_dir($absolutePath)): ?> <?php if (is_dir($absolutePath)): ?>
<!-- 文件夹 -->
<td> <td>
<?= Html::tag('i', '', ['class' => $item['type'] . ' file_icon']) ?> <?= Html::tag('i', '', ['class' => $item['type'] . ' file_icon']) ?>
<?= Html::a($item['name'], ['home/index', 'directory' => $relativePath], ['class' => 'file_name']) ?> <?= Html::a($item['name'], ['home/index', 'directory' => $relativePath], ['class' => 'file_name']) ?>
</td> </td>
<td> <td>
<?= Html::button(Html::tag('i', '', ['class' => 'fa-regular fa-pen-to-square']), ['value' => $relativePath, 'class' => 'btn btn-outline-secondary rename-btn']) ?> <?= 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' => '重命名']) ?>
</td> </td>
<?php else: ?> <?php else: ?>
<!-- 文件 -->
<td> <td>
<?= Html::tag('i', '', ['class' => $item['type'] . ' file_icon']) ?> <?= Html::tag('i', '', ['class' => $item['type'] . ' file_icon']) ?>
<?= Html::a($item['name'], ['home/download', 'relativePath' => $relativePath], ['class' => 'file_name']) ?> <?= Html::a($item['name'], ['home/download', 'relativePath' => $relativePath], ['class' => 'file_name']) ?>
@ -73,9 +70,13 @@ $this->registerCssFile('@web/css/home_style.css');
<td> <td>
<?= Html::button(Html::tag('i', '', ['class' => 'fa-regular fa-circle-down']), [ <?= Html::button(Html::tag('i', '', ['class' => 'fa-regular fa-circle-down']), [
'value' => Url::to(['home/download', 'relativePath' => $relativePath]), 'value' => Url::to(['home/download', 'relativePath' => $relativePath]),
'class' => 'btn btn-outline-primary download-btn' 'class' => 'btn btn-outline-primary download-btn',
'data-bs-toggle' => 'tooltip',
'data-bs-placement' => 'top',
'data-bs-title' => '下载'
]) ?> ]) ?>
<?= Html::button(Html::tag('i', '', ['class' => 'fa-regular fa-pen-to-square']), ['value' => $relativePath, 'class' => 'btn btn-outline-secondary rename-btn']) ?> <?= 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' => '重命名']) ?>
<?= 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' => '删除'])?>
</td> </td>
<?php endif; ?> <?php endif; ?>
</tr> </tr>
@ -100,19 +101,20 @@ echo Html::submitButton('提交', ['class' => 'btn btn-primary']);
ActiveForm::end(); ActiveForm::end();
Modal::end(); Modal::end();
$this->registerJs( Modal::begin([
"$(document).on('click', '.rename-btn', function() { 'title' => '<h4>确认删除</h4>',
var relativePath = $(this).attr('value'); 'id' => 'deleteModal',
var fileName = $(this).closest('tr').find('td:first').text().trim(); 'size' => 'modal-sm',
$('#renameRelativePath').val(relativePath); ]);
$('#renameform-newname').val(fileName);
$('#renameModal').modal('show'); echo Html::tag('div', '你确定要删除这个文件吗?', ['class' => 'modal-body']);
})
.on('click', '.download-btn', function() { echo Html::beginForm(['home/delete'], 'post', ['id' => 'delete-form']);
window.location.href = $(this).attr('value'); echo Html::hiddenInput('relativePath', '', ['id' => 'deleteRelativePath']);
});", echo Html::submitButton('确认', ['class' => 'btn btn-danger']);
View::POS_READY, echo Html::endForm();
'button-handlers'
); Modal::end();
$this->registerJsFile('@web/js/home_script.js', ['depends' => [JqueryAsset::class],'position' => View::POS_END]);
?> ?>