新增批量删除功能,修复故障的单文件删除功能

This commit is contained in:
Chenx221 2024-02-16 12:10:27 +08:00
parent 7459ef24b8
commit 1551514abf
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
2 changed files with 47 additions and 26 deletions

View File

@ -210,7 +210,12 @@ class HomeController extends Controller
*/ */
public function actionDelete() public function actionDelete()
{ {
$relativePath = Yii::$app->request->post('relativePath'); $relativePaths = Yii::$app->request->post('relativePath');
if (!is_array($relativePaths)) {
$relativePaths = [$relativePaths];
}
foreach ($relativePaths as $relativePath) {
$relativePath = rawurldecode($relativePath); $relativePath = rawurldecode($relativePath);
if (!preg_match($this->pattern, $relativePath) || str_contains($relativePath, '..')) { if (!preg_match($this->pattern, $relativePath) || str_contains($relativePath, '..')) {
throw new NotFoundHttpException('Invalid file path.'); throw new NotFoundHttpException('Invalid file path.');
@ -239,7 +244,8 @@ class HomeController extends Controller
Yii::$app->session->setFlash('success', 'File deleted successfully.'); Yii::$app->session->setFlash('success', 'File deleted successfully.');
} }
} }
return $this->redirect(['index', 'directory' => dirname($relativePath)]); }
return $this->redirect(['index', 'directory' => dirname($relativePaths[0])]);
} }
/** /**

View File

@ -150,8 +150,23 @@ $(document).on('click', '.single-share-btn', function () {
}); });
$(document).on('click', '.batch-delete-btn', function () { $(document).on('click', '.batch-delete-btn', function () {
console.log('删除按钮被点击'); var relativePaths = $('.select-item:checked').map(function () {
// 在这里添加你的代码 return $(this).data('relativePath');
}).get();
$.ajax({
type: "POST",
url: "index.php?r=home%2Fdelete",
data: { relativePath: relativePaths },
success: function(response) {
// 处理响应
location.reload();
},
error: function() {
// 处理错误
console.error('AJAX request failed.');
location.reload();
}
});
}); });
//下面的代码实现了各种按钮/样式功能,建议别看了( //下面的代码实现了各种按钮/样式功能,建议别看了(