feat(developer): 添加应用删除功能并更新配置
添加开发者应用删除功能,包括前端确认对话框和后端删除逻辑 更新配置文件中的数据库和SMTP密码
This commit is contained in:
@@ -47,6 +47,8 @@ if (!($conn instanceof mysqli)) {
|
|||||||
<link href="../css/bootstrap.min.css" rel="stylesheet">
|
<link href="../css/bootstrap.min.css" rel="stylesheet">
|
||||||
<!-- 自定义CSS -->
|
<!-- 自定义CSS -->
|
||||||
<link rel="stylesheet" href="../styles.css">
|
<link rel="stylesheet" href="../styles.css">
|
||||||
|
<!-- SweetAlert2 -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||||
<style>
|
<style>
|
||||||
.blur-bg {
|
.blur-bg {
|
||||||
backdrop-filter: blur(10px);
|
backdrop-filter: blur(10px);
|
||||||
@@ -213,9 +215,10 @@ if (!($conn instanceof mysqli)) {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</p>
|
</p>
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
<a href="edit_app.php?id=<?php echo $app['id']; ?>", class="btn btn-primary">编辑</a>
|
<a href="edit_app.php?id=<?php echo $app['id']; ?>", class="btn btn-primary">编辑</a>
|
||||||
<a href="version_control.php?id=<?php echo $app['id']; ?>", class="btn btn-secondary">版本控制</a>
|
<a href="version_control.php?id=<?php echo $app['id']; ?>", class="btn btn-secondary">版本控制</a>
|
||||||
</div>
|
<a href="#" class="delete-btn btn btn-danger" data-app-id="<?php echo $app['id']; ?>">删除</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@@ -223,10 +226,54 @@ if (!($conn instanceof mysqli)) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Bootstrap JS and Popper -->
|
<!-- Bootstrap JS and Popper -->
|
||||||
<script src="/js/bootstrap.bundle.js"></script>
|
<script src="../js/bootstrap.bundle.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
document.body.classList.add('page-transition');
|
document.body.classList.add('page-transition');
|
||||||
|
|
||||||
|
// 删除按钮事件处理
|
||||||
|
const deleteButtons = document.querySelectorAll('.delete-btn');
|
||||||
|
deleteButtons.forEach(button => {
|
||||||
|
button.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const appId = this.getAttribute('data-app-id');
|
||||||
|
const appName = this.closest('.card').querySelector('.card-title').textContent;
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: '确认删除',
|
||||||
|
text: `您确定要删除应用"${appName}"吗?此操作不可撤销。`,
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#d33',
|
||||||
|
cancelButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: '删除',
|
||||||
|
cancelButtonText: '取消'
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
fetch('delete_app.php', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
body: `app_id=${encodeURIComponent(appId)}`
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
Swal.fire('删除成功', data.message, 'success').then(() => {
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Swal.fire('删除失败', data.message, 'error');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
Swal.fire('错误', '删除过程中发生错误', 'error');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
81
developer/delete_app.php
Normal file
81
developer/delete_app.php
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
// 引入配置文件
|
||||||
|
require_once '../config.php';
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
// 检查开发者是否已登录
|
||||||
|
if (!isset($_SESSION['developer_id'])) {
|
||||||
|
http_response_code(403);
|
||||||
|
echo json_encode(['success' => false, 'message' => '未授权访问']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证请求方法和参数
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['app_id'])) {
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(['success' => false, 'message' => '无效的请求参数']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$appId = intval($_POST['app_id']);
|
||||||
|
$developerId = $_SESSION['developer_id'];
|
||||||
|
|
||||||
|
// 检查数据库连接
|
||||||
|
if (!($conn instanceof mysqli)) {
|
||||||
|
log_error('数据库连接错误: 连接不是MySQLi实例', __FILE__, __LINE__);
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode(['success' => false, 'message' => '数据库连接错误']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证应用所有权
|
||||||
|
$stmt = $conn->prepare('SELECT id FROM apps WHERE id = ? AND developer_id = ?');
|
||||||
|
if (!$stmt) {
|
||||||
|
log_error('验证应用所有权查询准备失败: ' . $conn->error, __FILE__, __LINE__);
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode(['success' => false, 'message' => '服务器错误']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->bind_param('ii', $appId, $developerId);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
if ($result->num_rows === 0) {
|
||||||
|
$stmt->close();
|
||||||
|
http_response_code(403);
|
||||||
|
echo json_encode(['success' => false, 'message' => '您没有权限删除此应用']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
// 开始事务
|
||||||
|
$conn->begin_transaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 删除应用的版本记录
|
||||||
|
$stmt = $conn->prepare('DELETE FROM app_versions WHERE app_id = ?');
|
||||||
|
if (!$stmt) throw new Exception('删除版本记录准备失败: ' . $conn->error);
|
||||||
|
$stmt->bind_param('i', $appId);
|
||||||
|
if (!$stmt->execute()) throw new Exception('删除版本记录执行失败: ' . $stmt->error);
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
// 删除应用记录
|
||||||
|
$stmt = $conn->prepare('DELETE FROM apps WHERE id = ? AND developer_id = ?');
|
||||||
|
if (!$stmt) throw new Exception('删除应用记录准备失败: ' . $conn->error);
|
||||||
|
$stmt->bind_param('ii', $appId, $developerId);
|
||||||
|
if (!$stmt->execute()) throw new Exception('删除应用记录执行失败: ' . $stmt->error);
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
// 提交事务
|
||||||
|
$conn->commit();
|
||||||
|
echo json_encode(['success' => true, 'message' => '应用已成功删除']);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// 回滚事务
|
||||||
|
$conn->rollback();
|
||||||
|
log_error('删除应用失败: ' . $e->getMessage(), __FILE__, __LINE__);
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode(['success' => false, 'message' => '删除应用失败: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user