Files
vf_react/verify-prediction-market.js
2025-11-23 18:48:12 +08:00

185 lines
5.0 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 预测市场功能验证脚本
* 检查所有必需的文件和配置是否正确
*/
const fs = require('fs');
const path = require('path');
console.log('🔍 开始验证预测市场功能...\n');
let errors = 0;
let warnings = 0;
// 颜色输出
const colors = {
green: '\x1b[32m',
red: '\x1b[31m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
reset: '\x1b[0m',
};
function success(msg) {
console.log(`${colors.green}${msg}${colors.reset}`);
}
function error(msg) {
console.log(`${colors.red}${msg}${colors.reset}`);
errors++;
}
function warning(msg) {
console.log(`${colors.yellow}⚠️ ${msg}${colors.reset}`);
warnings++;
}
function info(msg) {
console.log(`${colors.blue} ${msg}${colors.reset}`);
}
// 1. 检查必需文件
console.log('📂 检查文件结构...\n');
const requiredFiles = [
'src/services/creditSystemService.js',
'src/services/predictionMarketService.js',
'src/views/ValueForum/index.js',
'src/views/ValueForum/PredictionTopicDetail.js',
'src/views/ValueForum/components/PredictionTopicCard.js',
'src/views/ValueForum/components/CreatePredictionModal.js',
'src/views/ValueForum/components/TradeModal.js',
'src/theme/forumTheme.js',
'src/routes/lazy-components.js',
'src/routes/routeConfig.js',
];
requiredFiles.forEach(file => {
const fullPath = path.join(__dirname, file);
if (fs.existsSync(fullPath)) {
success(`${file}`);
} else {
error(`文件不存在: ${file}`);
}
});
// 2. 检查主题文件
console.log('\n🎨 检查主题配置...\n');
const themeFile = path.join(__dirname, 'src/theme/forumTheme.js');
if (fs.existsSync(themeFile)) {
const content = fs.readFileSync(themeFile, 'utf8');
const requiredColors = ['success:', 'error:', 'warning:', 'info:', 'primary:'];
requiredColors.forEach(color => {
if (content.includes(color)) {
success(`主题包含 ${color} 定义`);
} else {
error(`主题缺少 ${color} 定义`);
}
});
// 检查具体的颜色值
if (content.includes('500: \'#4CAF50\'') || content.includes('500: "#4CAF50"')) {
success('success[500] 颜色已定义');
} else {
error('success[500] 颜色缺失');
}
if (content.includes('500: \'#F44336\'') || content.includes('500: "#F44336"')) {
success('error[500] 颜色已定义');
} else {
error('error[500] 颜色缺失');
}
}
// 3. 检查路由配置
console.log('\n🛣 检查路由配置...\n');
const routeConfigFile = path.join(__dirname, 'src/routes/routeConfig.js');
if (fs.existsSync(routeConfigFile)) {
const content = fs.readFileSync(routeConfigFile, 'utf8');
if (content.includes('value-forum/prediction/:topicId')) {
success('预测话题详情路由已配置');
} else {
error('预测话题详情路由未配置');
}
}
const lazyComponentsFile = path.join(__dirname, 'src/routes/lazy-components.js');
if (fs.existsSync(lazyComponentsFile)) {
const content = fs.readFileSync(lazyComponentsFile, 'utf8');
if (content.includes('PredictionTopicDetail')) {
success('PredictionTopicDetail 懒加载已配置');
} else {
error('PredictionTopicDetail 懒加载未配置');
}
}
// 4. 检查依赖
console.log('\n📦 检查npm依赖...\n');
const packageJsonFile = path.join(__dirname, 'package.json');
if (fs.existsSync(packageJsonFile)) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8'));
const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
const requiredDeps = [
'@chakra-ui/react',
'react',
'react-router-dom',
'framer-motion',
'lucide-react',
];
requiredDeps.forEach(dep => {
if (deps[dep]) {
success(`${dep}: ${deps[dep]}`);
} else {
error(`缺少依赖: ${dep}`);
}
});
}
// 5. 检查ES配置
console.log('\n🔌 检查Elasticsearch配置...\n');
const esServiceFile = path.join(__dirname, 'src/services/elasticsearchService.js');
if (fs.existsSync(esServiceFile)) {
const content = fs.readFileSync(esServiceFile, 'utf8');
if (content.includes('222.128.1.157:19200')) {
success('ES开发环境地址已配置: 222.128.1.157:19200');
} else {
warning('ES地址可能已修改请检查配置');
}
if (content.includes('forum_posts')) {
success('ES索引 forum_posts 已定义');
}
}
// 6. 输出总结
console.log('\n' + '='.repeat(50));
console.log(`\n📊 验证结果总结:\n`);
if (errors === 0 && warnings === 0) {
console.log(`${colors.green}🎉 所有检查通过!预测市场功能已正确配置。${colors.reset}\n`);
console.log(`${colors.blue}👉 下一步: 运行 npm start 启动应用${colors.reset}\n`);
process.exit(0);
} else {
if (errors > 0) {
console.log(`${colors.red}❌ 发现 ${errors} 个错误${colors.reset}`);
}
if (warnings > 0) {
console.log(`${colors.yellow}⚠️ 发现 ${warnings} 个警告${colors.reset}`);
}
console.log(`\n${colors.blue}📚 查看故障排除指南:${colors.reset}`);
console.log(` cat TROUBLESHOOTING.md\n`);
process.exit(errors > 0 ? 1 : 0);
}