513 lines
17 KiB
Python
513 lines
17 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
玩Android Uniapp项目测试脚本
|
|
验证项目结构和基本功能
|
|
"""
|
|
|
|
import os
|
|
import json
|
|
from pathlib import Path
|
|
|
|
def check_project_structure():
|
|
"""检查项目结构"""
|
|
print("🔍 检查项目结构...")
|
|
|
|
required_files = [
|
|
'manifest.json',
|
|
'pages.json',
|
|
'App.vue',
|
|
'pages/index/index.vue',
|
|
'pages/project/project.vue',
|
|
'pages/wxarticle/wxarticle.vue',
|
|
'pages/tree/tree.vue',
|
|
'pages/mine/mine.vue',
|
|
'components/uni-load-more.vue',
|
|
'static/images/icons/home.png',
|
|
'static/images/icons/home-active.png',
|
|
]
|
|
|
|
missing_files = []
|
|
for file in required_files:
|
|
if not os.path.exists(file):
|
|
missing_files.append(file)
|
|
|
|
if missing_files:
|
|
print(f"❌ 缺少文件: {len(missing_files)} 个")
|
|
for file in missing_files:
|
|
print(f" - {file}")
|
|
return False
|
|
else:
|
|
print("✅ 项目结构完整")
|
|
return True
|
|
|
|
def check_json_files():
|
|
"""检查JSON配置文件"""
|
|
print("\n🔍 检查配置文件...")
|
|
|
|
# 检查manifest.json
|
|
try:
|
|
with open('manifest.json', 'r', encoding='utf-8') as f:
|
|
manifest = json.load(f)
|
|
print("✅ manifest.json 格式正确")
|
|
except Exception as e:
|
|
print(f"❌ manifest.json 错误: {e}")
|
|
return False
|
|
|
|
# 检查pages.json
|
|
try:
|
|
with open('pages.json', 'r', encoding='utf-8') as f:
|
|
pages = json.load(f)
|
|
|
|
# 检查必要的字段
|
|
required_fields = ['pages', 'globalStyle', 'tabBar']
|
|
for field in required_fields:
|
|
if field not in pages:
|
|
print(f"❌ pages.json 缺少字段: {field}")
|
|
return False
|
|
|
|
# 检查页面数量
|
|
if len(pages['pages']) != 5:
|
|
print(f"❌ pages.json 页面数量错误: {len(pages['pages'])} (应为5)")
|
|
return False
|
|
|
|
# 检查tabBar数量
|
|
if len(pages['tabBar']['list']) != 5:
|
|
print(f"❌ tabBar 数量错误: {len(pages['tabBar']['list'])} (应为5)")
|
|
return False
|
|
|
|
print("✅ pages.json 格式正确")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ pages.json 错误: {e}")
|
|
return False
|
|
|
|
def check_vue_files():
|
|
"""检查Vue文件基本结构"""
|
|
print("\n🔍 检查Vue文件...")
|
|
|
|
vue_files = [
|
|
'App.vue',
|
|
'pages/index/index.vue',
|
|
'components/uni-load-more.vue'
|
|
]
|
|
|
|
for file in vue_files:
|
|
try:
|
|
with open(file, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# 检查基本结构
|
|
if '<template>' not in content:
|
|
print(f"❌ {file} 缺少 <template> 标签")
|
|
return False
|
|
if '<script>' not in content:
|
|
print(f"❌ {file} 缺少 <script> 标签")
|
|
return False
|
|
if '<style' not in content: # 检查 <style> 或 <style scoped>
|
|
print(f"❌ {file} 缺少 <style> 标签")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ 读取 {file} 失败: {e}")
|
|
return False
|
|
|
|
print("✅ Vue文件结构正确")
|
|
return True
|
|
|
|
def check_icons():
|
|
"""检查图标文件"""
|
|
print("\n🔍 检查图标文件...")
|
|
|
|
icon_pairs = [
|
|
('home.png', 'home-active.png'),
|
|
('project.png', 'project-active.png'),
|
|
('wechat.png', 'wechat-active.png'),
|
|
('tree.png', 'tree-active.png'),
|
|
('mine.png', 'mine-active.png'),
|
|
]
|
|
|
|
icon_dir = 'static/images/icons'
|
|
missing_icons = []
|
|
|
|
for default, active in icon_pairs:
|
|
default_path = os.path.join(icon_dir, default)
|
|
active_path = os.path.join(icon_dir, active)
|
|
|
|
if not os.path.exists(default_path):
|
|
missing_icons.append(default)
|
|
if not os.path.exists(active_path):
|
|
missing_icons.append(active)
|
|
|
|
if missing_icons:
|
|
print(f"❌ 缺少图标: {len(missing_icons)} 个")
|
|
for icon in missing_icons:
|
|
print(f" - {icon}")
|
|
return False
|
|
else:
|
|
print("✅ 图标文件完整")
|
|
return True
|
|
|
|
def generate_test_report():
|
|
"""生成测试报告"""
|
|
print("\n" + "="*50)
|
|
print("玩Android Uniapp项目测试报告")
|
|
print("="*50)
|
|
|
|
tests = [
|
|
("项目结构检查", check_project_structure()),
|
|
("配置文件检查", check_json_files()),
|
|
("Vue文件检查", check_vue_files()),
|
|
("图标文件检查", check_icons()),
|
|
]
|
|
|
|
passed = sum(1 for _, result in tests if result)
|
|
total = len(tests)
|
|
|
|
print("\n📊 测试结果汇总:")
|
|
for name, result in tests:
|
|
status = "✅ 通过" if result else "❌ 失败"
|
|
print(f" {name}: {status}")
|
|
|
|
print(f"\n🎯 总体结果: {passed}/{total} 项测试通过")
|
|
|
|
if passed == total:
|
|
print("\n✨ 项目测试通过!可以导入HBuilder X进行打包。")
|
|
|
|
# 生成项目信息
|
|
print("\n📁 项目信息:")
|
|
print(f" 项目路径: {os.path.abspath('.')}")
|
|
print(f" 总文件数: {sum(len(files) for _, _, files in os.walk('.'))}")
|
|
print(f" 页面数量: 5个 (首页、项目、公众号、体系、我的)")
|
|
print(f" 组件数量: 1个 (uni-load-more)")
|
|
print(f" 图标数量: 10个 (5对导航图标)")
|
|
|
|
# 下一步建议
|
|
print("\n🚀 下一步建议:")
|
|
print(" 1. 将项目导入HBuilder X")
|
|
print(" 2. 运行到浏览器测试功能")
|
|
print(" 3. 打包为Android APK")
|
|
print(" 4. 继续开发其他页面功能")
|
|
|
|
return True
|
|
else:
|
|
print("\n⚠️ 项目测试未通过,请修复上述问题。")
|
|
return False
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print("开始测试玩Android Uniapp项目...")
|
|
|
|
# 切换到项目目录
|
|
project_dir = '/home/ubuntu/wanandroid/uniapp'
|
|
os.chdir(project_dir)
|
|
|
|
print(f"项目目录: {os.getcwd()}")
|
|
|
|
# 运行测试
|
|
success = generate_test_report()
|
|
|
|
# 创建简单的HTML预览
|
|
if success:
|
|
create_preview_html()
|
|
|
|
return success
|
|
|
|
def create_preview_html():
|
|
"""创建项目预览HTML"""
|
|
html_content = """
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>玩Android Uniapp项目预览</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
line-height: 1.6;
|
|
color: #333;
|
|
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
border-radius: 20px;
|
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.header {
|
|
background: linear-gradient(135deg, #3cc51f 0%, #2a9d1a 100%);
|
|
color: white;
|
|
padding: 40px 30px;
|
|
text-align: center;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 32px;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.header p {
|
|
opacity: 0.9;
|
|
font-size: 18px;
|
|
}
|
|
|
|
.content {
|
|
padding: 40px 30px;
|
|
}
|
|
|
|
.section {
|
|
margin-bottom: 40px;
|
|
}
|
|
|
|
.section h2 {
|
|
color: #3cc51f;
|
|
font-size: 24px;
|
|
margin-bottom: 20px;
|
|
padding-bottom: 10px;
|
|
border-bottom: 2px solid #f0f0f0;
|
|
}
|
|
|
|
.feature-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 20px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.feature-card {
|
|
background: #f8f9fa;
|
|
border-radius: 12px;
|
|
padding: 20px;
|
|
text-align: center;
|
|
transition: transform 0.3s, box-shadow 0.3s;
|
|
}
|
|
|
|
.feature-card:hover {
|
|
transform: translateY(-5px);
|
|
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.feature-icon {
|
|
font-size: 40px;
|
|
margin-bottom: 15px;
|
|
display: block;
|
|
}
|
|
|
|
.feature-title {
|
|
font-weight: 600;
|
|
margin-bottom: 10px;
|
|
color: #333;
|
|
}
|
|
|
|
.feature-desc {
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.status-badge {
|
|
display: inline-block;
|
|
padding: 5px 15px;
|
|
border-radius: 20px;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
margin-left: 10px;
|
|
}
|
|
|
|
.status-completed {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
}
|
|
|
|
.status-pending {
|
|
background: #fff3cd;
|
|
color: #856404;
|
|
}
|
|
|
|
.file-list {
|
|
background: #f8f9fa;
|
|
border-radius: 10px;
|
|
padding: 20px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.file-item {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 10px 0;
|
|
border-bottom: 1px solid #e9ecef;
|
|
}
|
|
|
|
.file-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.file-name {
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
|
|
.file-size {
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.footer {
|
|
text-align: center;
|
|
padding: 30px;
|
|
background: #f8f9fa;
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.success-message {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
padding: 15px;
|
|
border-radius: 10px;
|
|
margin: 20px 0;
|
|
text-align: center;
|
|
font-weight: 600;
|
|
}
|
|
|
|
@media (max-width: 600px) {
|
|
.container {
|
|
border-radius: 10px;
|
|
}
|
|
|
|
.header {
|
|
padding: 30px 20px;
|
|
}
|
|
|
|
.content {
|
|
padding: 30px 20px;
|
|
}
|
|
|
|
.feature-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>玩Android Uniapp客户端</h1>
|
|
<p>基于Uniapp框架开发的Android应用</p>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<div class="success-message">
|
|
✅ 项目测试通过!可以导入HBuilder X进行打包
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>项目概述</h2>
|
|
<p>这是一个基于Uniapp框架开发的玩Android客户端应用,集成了玩Android开放API,提供文章浏览、项目查看等功能。</p>
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>功能特性</h2>
|
|
<div class="feature-grid">
|
|
<div class="feature-card">
|
|
<span class="feature-icon">🏠</span>
|
|
<div class="feature-title">首页</div>
|
|
<div class="feature-desc">Banner轮播、文章列表、下拉刷新、上拉加载</div>
|
|
<span class="status-badge status-completed">已完成</span>
|
|
</div>
|
|
|
|
<div class="feature-card">
|
|
<span class="feature-icon">📦</span>
|
|
<div class="feature-title">项目</div>
|
|
<div class="feature-desc">开源项目浏览和分类查看</div>
|
|
<span class="status-badge status-pending">待开发</span>
|
|
</div>
|
|
|
|
<div class="feature-card">
|
|
<span class="feature-icon">📱</span>
|
|
<div class="feature-title">公众号</div>
|
|
<div class="feature-desc">技术公众号文章订阅</div>
|
|
<span class="status-badge status-pending">待开发</span>
|
|
</div>
|
|
|
|
<div class="feature-card">
|
|
<span class="feature-icon">🌳</span>
|
|
<div class="feature-title">体系</div>
|
|
<div class="feature-desc">技术知识体系结构</div>
|
|
<span class="status-badge status-pending">待开发</span>
|
|
</div>
|
|
|
|
<div class="feature-card">
|
|
<span class="feature-icon">👤</span>
|
|
<div class="feature-title">我的</div>
|
|
<div class="feature-desc">用户中心和个人设置</div>
|
|
<span class="status-badge status-pending">待开发</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>项目结构</h2>
|
|
<div class="file-list">
|
|
<div class="file-item">
|
|
<span class="file-name">pages/index/index.vue</span>
|
|
<span class="file-size">11.4 KB</span>
|
|
</div>
|
|
<div class="file-item">
|
|
<span class="file-name">pages.json</span>
|
|
<span class="file-size">2.3 KB</span>
|
|
</div>
|
|
<div class="file-item">
|
|
<span class="file-name">manifest.json</span>
|
|
<span class="file-size">1.5 KB</span>
|
|
</div>
|
|
<div class="file-item">
|
|
<span class="file-name">App.vue</span>
|
|
<span class="file-size">1.7 KB</span>
|
|
</div>
|
|
<div class="file-item">
|
|
<span class="file-name">components/uni-load-more.vue</span>
|
|
<span class="file-size">2.3 KB</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>使用说明</h2>
|
|
<p>1. 下载项目文件到本地</p>
|
|
<p>2. 使用HBuilder X导入项目</p>
|
|
<p>3. 运行到浏览器或手机模拟器测试</p>
|
|
<p>4. 打包为Android APK文件</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p>生成时间: 2026-03-17</p>
|
|
<p>项目路径: /home/ubuntu/wanandroid/uniapp</p>
|
|
<p>© 2026 玩Android Uniapp客户端</p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
with open('project_preview.html', 'w', encoding='utf-8') as f:
|
|
f.write(html_content)
|
|
|
|
print(f"\n📄 项目预览已生成: project_preview.html")
|
|
print(" 用浏览器打开此文件查看项目详情")
|
|
|
|
if __name__ == '__main__':
|
|
success = main()
|
|
exit(0 if success else 1) |