
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CURL 命令展示</title>
<style>
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
position: relative;
background-color: #fff;
margin: 15% auto;
padding: 20px;
width: 70%;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.close {
position: absolute;
right: 20px;
top: 10px;
font-size: 24px;
cursor: pointer;
color: #666;
}
.curl-container {
margin: 15px 0;
padding: 15px;
background-color: #f5f5f5;
border-radius: 4px;
}
.curl-title {
font-weight: bold;
margin-bottom: 10px;
color: #333;
display: flex;
justify-content: space-between;
align-items: center;
}
.curl-command {
font-family: monospace;
white-space: pre-wrap;
word-break: break-all;
background-color: #e0e0e0;
color: #333;
padding: 10px;
border-radius: 4px;
position: relative;
}
.btn {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.btn:hover {
background-color: #45a049;
}
.copy-btn {
padding: 5px 10px;
background-color: #808080;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
}
.copy-btn:hover {
background-color: #666666;
}
.copy-success {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0, 0, 0, 0.8);
color: white;
padding: 5px 10px;
border-radius: 4px;
display: none;
}
</style>
</head>
<body>
<button class="btn" onclick="openModal()">显示 CURL 命令</button>
<div id="curlModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal()">×</span>
<h2>复制接口</h2>
<div class="curl-container">
<div class="curl-title">
<span>POST 请求:</span>
<button class="copy-btn" onclick="copyToClipboard('postCurl')">复制</button>
</div>
<div class="curl-command" id="postCurl">
<div class="copy-success">复制成功!</div>
</div>
</div>
<div class="curl-container">
<div class="curl-title">
<span>GET 请求:</span>
<button class="copy-btn" onclick="copyToClipboard('getCurl')">复制</button>
</div>
<div class="curl-command" id="getCurl">
<div class="copy-success">复制成功!</div>
</div>
</div>
</div>
</div>
<script>
// 模拟 API 返回数据
const apiResponse = {
"msg": "操作成功",
"code": 200,
"data": {
"postCurl": "curl --location --request POST 'http://api.example.com/mtt2277/getUser' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{}'",
"getCurl": "curl --location --request GET 'http://api.example.com/mtt2277/getUser'"
}
};
function openModal() {
document.getElementById('curlModal').style.display = 'block';
document.getElementById('postCurl').textContent = apiResponse.data.postCurl;
document.getElementById('getCurl').textContent = apiResponse.data.getCurl;
}
function closeModal() {
document.getElementById('curlModal').style.display = 'none';
}
function copyToClipboard(elementId) {
const element = document.getElementById(elementId);
const text = element.textContent;
const successMessage = element.querySelector('.copy-success');
navigator.clipboard.writeText(text).then(() => {
successMessage.style.display = 'block';
setTimeout(() => {
successMessage.style.display = 'none';
}, 1500);
}).catch(err => {
console.error('复制失败:', err);
});
}
// 点击模态框外部关闭
window.onclick = function(event) {
const modal = document.getElementById('curlModal');
if (event.target == modal) {
modal.style.display = 'none';
}
}
</script>
</body>
</html>