<!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>
|