File size: 2,374 Bytes
7d11307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
document.addEventListener('DOMContentLoaded', function() {
    const convertForm = document.getElementById('convertForm');
    const resultCard = document.getElementById('resultCard');
    const convertResult = document.getElementById('convertResult');
    const copyBtn = document.getElementById('copyBtn');
    const toast = document.getElementById('toast');
    
    // 表单提交事件
    convertForm.addEventListener('submit', function(e) {
        e.preventDefault();
        
        // 获取表单数据
        const formData = new FormData(convertForm);
        
        // 显示加载提示
        showToast('正在处理,请稍候...');
        
        // 发送 AJAX 请求
        fetch('/convert', {
            method: 'POST',
            body: formData
        })
        .then(response => response.json())
        .then(data => {
            if (data.status === 'success') {
                // 显示结果
                convertResult.value = data.result;
                resultCard.style.display = 'block';
                
                // 滚动到结果区域
                resultCard.scrollIntoView({ behavior: 'smooth' });
            } else {
                showToast('错误: ' + data.message, 'error');
            }
        })
        .catch(error => {
            showToast('请求失败: ' + error, 'error');
        });
    });
    
    // 复制按钮事件
    copyBtn.addEventListener('click', function() {
        convertResult.select();
        document.execCommand('copy');
        
        // 不选中文本
        window.getSelection().removeAllRanges();
        
        showToast('已复制到剪贴板!');
    });
    
    // 显示提示消息
    function showToast(message, type = 'info') {
        toast.textContent = message;
        toast.className = 'toast show ' + type;
        
        // 3秒后隐藏
        setTimeout(function() {
            toast.className = 'toast';
        }, 3000);
    }
    
    // 输入框聚焦动画
    const inputs = document.querySelectorAll('input, textarea, select');
    inputs.forEach(input => {
        input.addEventListener('focus', function() {
            this.parentElement.classList.add('focused');
        });
        
        input.addEventListener('blur', function() {
            this.parentElement.classList.remove('focused');
        });
    });
});