lrj
10 小时以前 7ad9c3c93f0cc103347ae2e2429e0122fb512e24
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
<!DOCTYPE html>
<html>
<head>
    <title>测试角色API</title>
</head>
<body>
    <h1>角色API测试</h1>
    <button onclick="testRoleAPI()">测试角色API</button>
    <div id="result"></div>
 
    <script>
        async function testRoleAPI() {
            const resultDiv = document.getElementById('result');
            resultDiv.innerHTML = '正在测试...';
            
            try {
                // 获取token(如果有的话)
                const token = localStorage.getItem('token');
                
                const headers = {
                    'Content-Type': 'application/json',
                };
                
                if (token) {
                    headers['Authorization'] = `Bearer ${token}`;
                }
                
                const query = `
                    query GetActiveRoles {
                        activeRoles {
                            id
                            code
                            name
                            description
                            state
                            createTime
                            updateTime
                        }
                    }
                `;
                
                const response = await fetch('/api/graphql', {
                    method: 'POST',
                    headers,
                    body: JSON.stringify({
                        query,
                        variables: {}
                    })
                });
                
                const result = await response.json();
                
                resultDiv.innerHTML = `
                    <h3>响应状态: ${response.status}</h3>
                    <h3>响应数据:</h3>
                    <pre>${JSON.stringify(result, null, 2)}</pre>
                `;
                
            } catch (error) {
                resultDiv.innerHTML = `
                    <h3>错误:</h3>
                    <pre>${error.message}</pre>
                `;
            }
        }
    </script>
</body>
</html>