This commit is contained in:
sjk
2025-11-17 14:11:46 +08:00
commit ad4a600af9
1659 changed files with 171560 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
// pages/network-test/index.js
const { config } = require('../../config/index');
Page({
data: {
testResults: [],
isLoading: false
},
onLoad() {
console.log('Network test page loaded');
console.log('API Base:', config.apiBase);
},
// 测试基本连接
testBasicConnection() {
this.setData({ isLoading: true });
wx.request({
url: `${config.apiBase}/health`,
method: 'GET',
success: (res) => {
console.log('Health check success:', res);
this.addTestResult('Health Check', 'SUCCESS', res.statusCode, JSON.stringify(res.data));
},
fail: (err) => {
console.error('Health check failed:', err);
this.addTestResult('Health Check', 'FAILED', 0, err.errMsg);
},
complete: () => {
this.setData({ isLoading: false });
}
});
},
// 测试分类接口
testCategoriesAPI() {
this.setData({ isLoading: true });
wx.request({
url: `${config.apiBase}/products/categories`,
method: 'GET',
success: (res) => {
console.log('Categories API success:', res);
this.addTestResult('Categories API', 'SUCCESS', res.statusCode, `${res.data?.data?.length || 0} categories`);
},
fail: (err) => {
console.error('Categories API failed:', err);
this.addTestResult('Categories API', 'FAILED', 0, err.errMsg);
},
complete: () => {
this.setData({ isLoading: false });
}
});
},
// 添加测试结果
addTestResult(testName, status, statusCode, message) {
const result = {
testName,
status,
statusCode,
message,
timestamp: new Date().toLocaleTimeString()
};
const results = [...this.data.testResults, result];
this.setData({ testResults: results });
},
// 清除测试结果
clearResults() {
this.setData({ testResults: [] });
},
// 测试所有接口
testAll() {
this.clearResults();
setTimeout(() => this.testBasicConnection(), 100);
setTimeout(() => this.testCategoriesAPI(), 1000);
}
});

View File

@@ -0,0 +1,3 @@
{
"usingComponents": {}
}

View File

@@ -0,0 +1,43 @@
<!--pages/network-test/index.wxml-->
<view class="container">
<view class="header">
<text class="title">网络连接测试</text>
<text class="subtitle">API Base: {{apiBase}}</text>
</view>
<view class="test-buttons">
<button class="test-btn" bindtap="testBasicConnection" disabled="{{isLoading}}">
测试健康检查
</button>
<button class="test-btn" bindtap="testCategoriesAPI" disabled="{{isLoading}}">
测试分类接口
</button>
<button class="test-btn primary" bindtap="testAll" disabled="{{isLoading}}">
测试所有接口
</button>
<button class="test-btn secondary" bindtap="clearResults">
清除结果
</button>
</view>
<view class="loading" wx:if="{{isLoading}}">
<text>测试中...</text>
</view>
<view class="results" wx:if="{{testResults.length > 0}}">
<text class="results-title">测试结果:</text>
<view class="result-item" wx:for="{{testResults}}" wx:key="index">
<view class="result-header">
<text class="test-name">{{item.testName}}</text>
<text class="status {{item.status === 'SUCCESS' ? 'success' : 'failed'}}">
{{item.status}}
</text>
<text class="timestamp">{{item.timestamp}}</text>
</view>
<view class="result-details">
<text class="status-code">状态码: {{item.statusCode}}</text>
<text class="message">{{item.message}}</text>
</view>
</view>
</view>
</view>

View File

@@ -0,0 +1,141 @@
/* pages/network-test/index.wxss */
.container {
padding: 20rpx;
background-color: #f5f5f5;
min-height: 100vh;
}
.header {
text-align: center;
margin-bottom: 40rpx;
padding: 20rpx;
background-color: white;
border-radius: 10rpx;
}
.title {
display: block;
font-size: 36rpx;
font-weight: bold;
color: #333;
margin-bottom: 10rpx;
}
.subtitle {
display: block;
font-size: 24rpx;
color: #666;
}
.test-buttons {
display: flex;
flex-direction: column;
gap: 20rpx;
margin-bottom: 40rpx;
}
.test-btn {
padding: 20rpx;
border-radius: 10rpx;
font-size: 28rpx;
border: none;
}
.test-btn.primary {
background-color: #07c160;
color: white;
}
.test-btn.secondary {
background-color: #ff6b6b;
color: white;
}
.test-btn:not(.primary):not(.secondary) {
background-color: #1989fa;
color: white;
}
.test-btn[disabled] {
background-color: #ccc !important;
color: #999 !important;
}
.loading {
text-align: center;
padding: 40rpx;
color: #666;
}
.results {
background-color: white;
border-radius: 10rpx;
padding: 20rpx;
}
.results-title {
display: block;
font-size: 32rpx;
font-weight: bold;
color: #333;
margin-bottom: 20rpx;
}
.result-item {
border-bottom: 1rpx solid #eee;
padding: 20rpx 0;
}
.result-item:last-child {
border-bottom: none;
}
.result-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10rpx;
}
.test-name {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.status {
font-size: 24rpx;
padding: 4rpx 12rpx;
border-radius: 20rpx;
color: white;
}
.status.success {
background-color: #07c160;
}
.status.failed {
background-color: #ff6b6b;
}
.timestamp {
font-size: 20rpx;
color: #999;
}
.result-details {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.status-code {
font-size: 24rpx;
color: #666;
}
.message {
font-size: 24rpx;
color: #333;
word-break: break-all;
}