ui-curl样式参考

<!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()">&times;</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> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

javachen__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值