14 changed files with 232 additions and 170 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,129 +0,0 @@ |
|||
#!/usr/bin/env node
|
|||
|
|||
/** |
|||
* 用户资料系统测试脚本 |
|||
* 用于验证系统功能是否正常 |
|||
*/ |
|||
|
|||
import { execSync } from 'child_process'; |
|||
import fs from 'fs'; |
|||
import path from 'path'; |
|||
|
|||
console.log('🧪 开始测试用户资料系统...\n'); |
|||
|
|||
// 检查必要的文件是否存在
|
|||
const requiredFiles = [ |
|||
'src/controllers/Page/PageController.js', |
|||
'src/views/page/profile/index.pug', |
|||
'public/js/profile.js', |
|||
'src/db/migrations/20250901000000_add_profile_fields.mjs' |
|||
]; |
|||
|
|||
console.log('📁 检查必要文件...'); |
|||
let allFilesExist = true; |
|||
|
|||
requiredFiles.forEach(file => { |
|||
if (fs.existsSync(file)) { |
|||
console.log(`✅ ${file}`); |
|||
} else { |
|||
console.log(`❌ ${file} - 文件不存在`); |
|||
allFilesExist = false; |
|||
} |
|||
}); |
|||
|
|||
if (!allFilesExist) { |
|||
console.log('\n❌ 部分必要文件缺失,请检查文件创建'); |
|||
process.exit(1); |
|||
} |
|||
|
|||
console.log('\n✅ 所有必要文件都存在'); |
|||
|
|||
// 检查数据库迁移文件
|
|||
console.log('\n🗄️ 检查数据库迁移...'); |
|||
try { |
|||
const migrationContent = fs.readFileSync('src/db/migrations/20250901000000_add_profile_fields.mjs', 'utf8'); |
|||
if (migrationContent.includes('name') && migrationContent.includes('bio') && migrationContent.includes('avatar')) { |
|||
console.log('✅ 数据库迁移文件包含必要字段'); |
|||
} else { |
|||
console.log('❌ 数据库迁移文件缺少必要字段'); |
|||
} |
|||
} catch (error) { |
|||
console.log('❌ 无法读取数据库迁移文件'); |
|||
} |
|||
|
|||
// 检查路由配置
|
|||
console.log('\n🛣️ 检查路由配置...'); |
|||
try { |
|||
const controllerContent = fs.readFileSync('src/controllers/Page/PageController.js', 'utf8'); |
|||
|
|||
const hasProfileGet = controllerContent.includes('profileGet'); |
|||
const hasProfileUpdate = controllerContent.includes('profileUpdate'); |
|||
const hasChangePassword = controllerContent.includes('changePassword'); |
|||
const hasProfileRoutes = controllerContent.includes('/profile/update') && controllerContent.includes('/profile/change-password'); |
|||
|
|||
if (hasProfileGet && hasProfileUpdate && hasChangePassword && hasProfileRoutes) { |
|||
console.log('✅ 控制器方法已实现'); |
|||
console.log('✅ 路由配置已添加'); |
|||
} else { |
|||
console.log('❌ 控制器方法或路由配置不完整'); |
|||
} |
|||
} catch (error) { |
|||
console.log('❌ 无法读取控制器文件'); |
|||
} |
|||
|
|||
// 检查前端模板
|
|||
console.log('\n🎨 检查前端模板...'); |
|||
try { |
|||
const templateContent = fs.readFileSync('src/views/page/profile/index.pug', 'utf8'); |
|||
|
|||
const hasProfileForm = templateContent.includes('profileForm'); |
|||
const hasPasswordForm = templateContent.includes('passwordForm'); |
|||
const hasUserFields = templateContent.includes('username') && templateContent.includes('email') && templateContent.includes('name'); |
|||
const hasInlineStyles = templateContent.includes('style.') && templateContent.includes('.profile-container'); |
|||
|
|||
if (hasProfileForm && hasPasswordForm && hasUserFields && hasInlineStyles) { |
|||
console.log('✅ 前端模板包含必要表单和样式'); |
|||
} else { |
|||
console.log('❌ 前端模板缺少必要元素'); |
|||
} |
|||
} catch (error) { |
|||
console.log('❌ 无法读取前端模板文件'); |
|||
} |
|||
|
|||
// 检查JavaScript功能
|
|||
console.log('\n⚡ 检查JavaScript功能...'); |
|||
try { |
|||
const jsContent = fs.readFileSync('public/js/profile.js', 'utf8'); |
|||
|
|||
const hasProfileUpdate = jsContent.includes('handleProfileUpdate'); |
|||
const hasPasswordChange = jsContent.includes('handlePasswordChange'); |
|||
const hasValidation = jsContent.includes('validateField'); |
|||
const hasIIFE = jsContent.includes('(function()') && jsContent.includes('})();'); |
|||
|
|||
if (hasProfileUpdate && hasPasswordChange && hasValidation && hasIIFE) { |
|||
console.log('✅ JavaScript文件包含必要功能,使用IIFE模式'); |
|||
} else { |
|||
console.log('❌ JavaScript文件缺少必要功能'); |
|||
} |
|||
} catch (error) { |
|||
console.log('❌ 无法读取JavaScript文件'); |
|||
} |
|||
|
|||
console.log('\n📋 测试完成!'); |
|||
console.log('\n📝 下一步操作:'); |
|||
console.log('1. 运行数据库迁移: npm run migrate'); |
|||
console.log('2. 启动应用: npm start'); |
|||
console.log('3. 访问 /profile 页面测试功能'); |
|||
console.log('4. 确保用户已登录才能访问资料页面'); |
|||
|
|||
console.log('\n🔧 如果遇到问题:'); |
|||
console.log('- 检查数据库连接'); |
|||
console.log('- 确认用户表结构正确'); |
|||
console.log('- 查看浏览器控制台错误信息'); |
|||
console.log('- 检查服务器日志'); |
|||
|
|||
console.log('\n✨ 重构完成:'); |
|||
console.log('- 样式已内联到Pug模板中'); |
|||
console.log('- JavaScript使用IIFE模式,避免全局污染'); |
|||
console.log('- 界面设计更简洁,与项目风格保持一致'); |
|||
console.log('- 代码结构更清晰,易于维护'); |
|||
@ -1,4 +1,26 @@ |
|||
import { app } from "@/global" |
|||
|
|||
export function formatResponse(success, data = null, error = null) { |
|||
return { success, error, data } |
|||
function ResponseSuccess(data = null, message = null) { |
|||
return { success: true, error: message, data } |
|||
} |
|||
|
|||
function ResponseError(data = null, message = null) { |
|||
return { success: false, error: message, data } |
|||
} |
|||
|
|||
function ResponseJSON(statusCode = 200, data = null, message = null) { |
|||
app.currentContext.status = statusCode |
|||
return (app.currentContext.body = { success: true, error: message, data }) |
|||
} |
|||
|
|||
const R = { |
|||
ResponseSuccess, |
|||
ResponseError, |
|||
ResponseJSON, |
|||
} |
|||
|
|||
R.SUCCESS = 200 |
|||
R.ERROR = 500 |
|||
R.NOTFOUND = 404 |
|||
|
|||
export { R } |
|||
|
|||
Loading…
Reference in new issue