// 测试小程序端区域数据加载
|
const http = require('http');
|
|
console.log('=== 测试小程序端区域数据加载 ===\n');
|
|
// 模拟小程序的GraphQL请求
|
const query = `
|
query {
|
allRegions {
|
id
|
name
|
pid
|
leafFlag
|
}
|
}
|
`;
|
|
const requestData = {
|
query: query,
|
variables: {}
|
};
|
|
const options = {
|
hostname: 'localhost',
|
port: 8080,
|
path: '/api/graphql',
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
'Content-Length': Buffer.byteLength(JSON.stringify(requestData))
|
}
|
};
|
|
console.log('请求配置:', options);
|
console.log('请求数据:', JSON.stringify(requestData, null, 2));
|
|
const req = http.request(options, (res) => {
|
let data = '';
|
|
console.log(`响应状态码: ${res.statusCode}`);
|
console.log(`响应头:`, res.headers);
|
|
res.on('data', (chunk) => {
|
data += chunk;
|
});
|
|
res.on('end', () => {
|
try {
|
const response = JSON.parse(data);
|
console.log('\n=== 响应数据 ===');
|
console.log(JSON.stringify(response, null, 2));
|
|
if (response.data && response.data.allRegions) {
|
const allRegions = response.data.allRegions;
|
const leafRegions = allRegions.filter(region => region.leafFlag === true);
|
|
console.log('\n=== 数据分析 ===');
|
console.log(`总区域数量: ${allRegions.length}`);
|
console.log(`叶子节点区域数量: ${leafRegions.length}`);
|
|
console.log('\n=== 叶子节点区域列表 ===');
|
leafRegions.forEach((region, index) => {
|
console.log(`${index + 1}. ${region.name} (ID: ${region.id}, PID: ${region.pid})`);
|
});
|
|
if (leafRegions.length === 0) {
|
console.log('❌ 没有找到叶子节点区域!');
|
} else {
|
console.log(`✅ 找到 ${leafRegions.length} 个叶子节点区域`);
|
}
|
} else {
|
console.log('❌ 响应中没有区域数据');
|
}
|
} catch (error) {
|
console.log('❌ 解析响应失败:', error.message);
|
console.log('原始响应:', data);
|
}
|
});
|
});
|
|
req.on('error', (error) => {
|
console.log('❌ 请求失败:', error.message);
|
});
|
|
req.write(JSON.stringify(requestData));
|
req.end();
|