518 行
21 KiB
HTML
518 行
21 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>订单同步功能测试</title>
|
|
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
|
|
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
|
|
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 20px;
|
|
background-color: #f5f5f5;
|
|
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
|
|
}
|
|
|
|
.test-container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.test-header {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
margin-bottom: 20px;
|
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.test-section {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
margin-bottom: 20px;
|
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.test-result {
|
|
margin-top: 15px;
|
|
padding: 15px;
|
|
border-radius: 4px;
|
|
border-left: 4px solid #409eff;
|
|
background-color: #f4f4f5;
|
|
}
|
|
|
|
.test-result.success {
|
|
border-left-color: #67c23a;
|
|
background-color: #f0f9ff;
|
|
}
|
|
|
|
.test-result.error {
|
|
border-left-color: #f56c6c;
|
|
background-color: #fef0f0;
|
|
}
|
|
|
|
.json-display {
|
|
background: #2d3748;
|
|
color: #e2e8f0;
|
|
padding: 15px;
|
|
border-radius: 4px;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 12px;
|
|
overflow-x: auto;
|
|
white-space: pre-wrap;
|
|
word-break: break-all;
|
|
}
|
|
|
|
.test-stats {
|
|
display: flex;
|
|
gap: 20px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.stat-card {
|
|
flex: 1;
|
|
text-align: center;
|
|
padding: 20px;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.stat-number {
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.stat-label {
|
|
font-size: 14px;
|
|
opacity: 0.9;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="testApp" class="test-container">
|
|
<div class="test-header">
|
|
<h1>订单同步功能测试</h1>
|
|
<p>此页面用于测试小程序订单到骑手订单系统的同步功能</p>
|
|
|
|
<div class="test-stats">
|
|
<div class="stat-card">
|
|
<div class="stat-number">{{ testResults.length }}</div>
|
|
<div class="stat-label">已执行测试</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-number">{{ successCount }}</div>
|
|
<div class="stat-label">成功测试</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-number">{{ errorCount }}</div>
|
|
<div class="stat-label">失败测试</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-number">{{ successRate }}%</div>
|
|
<div class="stat-label">成功率</div>
|
|
</div>
|
|
</div>
|
|
|
|
<el-button type="primary" @click="runAllTests" :loading="testing" size="large">
|
|
{{ testing ? '测试中...' : '运行所有测试' }}
|
|
</el-button>
|
|
<el-button @click="clearResults" size="large">清空结果</el-button>
|
|
</div>
|
|
|
|
<!-- 单项测试 -->
|
|
<div class="test-section">
|
|
<h3>1. 同步统计测试</h3>
|
|
<p>测试获取订单同步统计信息的功能</p>
|
|
<el-button type="success" @click="testSyncStatistics" :loading="loadingStats">测试同步统计</el-button>
|
|
|
|
<div v-if="statsResult" class="test-result" :class="statsResult.success ? 'success' : 'error'">
|
|
<h4>测试结果:{{ statsResult.success ? '成功' : '失败' }}</h4>
|
|
<p>{{ statsResult.message }}</p>
|
|
<div class="json-display">{{ JSON.stringify(statsResult.data, null, 2) }}</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h3>2. 可同步订单测试</h3>
|
|
<p>测试获取可同步订单列表的功能</p>
|
|
|
|
<el-form :model="syncableForm" inline>
|
|
<el-form-item label="开始日期">
|
|
<el-date-picker v-model="syncableForm.startDate" type="datetime" placeholder="选择开始日期"></el-date-picker>
|
|
</el-form-item>
|
|
<el-form-item label="结束日期">
|
|
<el-date-picker v-model="syncableForm.endDate" type="datetime" placeholder="选择结束日期"></el-date-picker>
|
|
</el-form-item>
|
|
<el-form-item label="限制数量">
|
|
<el-input-number v-model="syncableForm.limit" :min="1" :max="100"></el-input-number>
|
|
</el-form-item>
|
|
</el-form>
|
|
|
|
<el-button type="success" @click="testSyncableOrders" :loading="loadingSyncable">测试可同步订单</el-button>
|
|
|
|
<div v-if="syncableResult" class="test-result" :class="syncableResult.success ? 'success' : 'error'">
|
|
<h4>测试结果:{{ syncableResult.success ? '成功' : '失败' }}</h4>
|
|
<p>{{ syncableResult.message }}</p>
|
|
<div class="json-display">{{ JSON.stringify(syncableResult.data, null, 2) }}</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h3>3. 单个订单同步测试</h3>
|
|
<p>测试同步单个订单的功能</p>
|
|
|
|
<el-form :model="singleSyncForm" inline>
|
|
<el-form-item label="订单ID">
|
|
<el-input v-model="singleSyncForm.orderId" placeholder="输入订单ID"></el-input>
|
|
</el-form-item>
|
|
</el-form>
|
|
|
|
<el-button type="success" @click="testSingleSync" :loading="loadingSingle">测试单个同步</el-button>
|
|
|
|
<div v-if="singleResult" class="test-result" :class="singleResult.success ? 'success' : 'error'">
|
|
<h4>测试结果:{{ singleResult.success ? '成功' : '失败' }}</h4>
|
|
<p>{{ singleResult.message }}</p>
|
|
<div class="json-display">{{ JSON.stringify(singleResult.data, null, 2) }}</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h3>4. 批量订单同步测试</h3>
|
|
<p>测试批量同步订单的功能</p>
|
|
|
|
<el-form :model="batchSyncForm" inline>
|
|
<el-form-item label="订单ID列表">
|
|
<el-input v-model="batchSyncForm.orderIds" placeholder="输入订单ID,用逗号分隔" style="width: 300px;"></el-input>
|
|
</el-form-item>
|
|
</el-form>
|
|
|
|
<el-button type="success" @click="testBatchSync" :loading="loadingBatch">测试批量同步</el-button>
|
|
|
|
<div v-if="batchResult" class="test-result" :class="batchResult.success ? 'success' : 'error'">
|
|
<h4>测试结果:{{ batchResult.success ? '成功' : '失败' }}</h4>
|
|
<p>{{ batchResult.message }}</p>
|
|
<div class="json-display">{{ JSON.stringify(batchResult.data, null, 2) }}</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 综合测试结果 -->
|
|
<div class="test-section" v-if="testResults.length > 0">
|
|
<h3>测试结果汇总</h3>
|
|
<el-table :data="testResults" style="width: 100%">
|
|
<el-table-column prop="name" label="测试项目" width="200"></el-table-column>
|
|
<el-table-column prop="status" label="状态" width="100">
|
|
<template slot-scope="scope">
|
|
<el-tag :type="scope.row.success ? 'success' : 'danger'">
|
|
{{ scope.row.success ? '成功' : '失败' }}
|
|
</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column prop="message" label="结果信息"></el-table-column>
|
|
<el-table-column prop="duration" label="耗时(ms)" width="100"></el-table-column>
|
|
</el-table>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
new Vue({
|
|
el: '#testApp',
|
|
data() {
|
|
return {
|
|
testing: false,
|
|
loadingStats: false,
|
|
loadingSyncable: false,
|
|
loadingSingle: false,
|
|
loadingBatch: false,
|
|
|
|
statsResult: null,
|
|
syncableResult: null,
|
|
singleResult: null,
|
|
batchResult: null,
|
|
|
|
testResults: [],
|
|
|
|
syncableForm: {
|
|
startDate: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
|
|
endDate: new Date(),
|
|
limit: 10
|
|
},
|
|
|
|
singleSyncForm: {
|
|
orderId: ''
|
|
},
|
|
|
|
batchSyncForm: {
|
|
orderIds: ''
|
|
}
|
|
}
|
|
},
|
|
|
|
computed: {
|
|
successCount() {
|
|
return this.testResults.filter(r => r.success).length;
|
|
},
|
|
|
|
errorCount() {
|
|
return this.testResults.filter(r => !r.success).length;
|
|
},
|
|
|
|
successRate() {
|
|
if (this.testResults.length === 0) return 0;
|
|
return Math.round((this.successCount / this.testResults.length) * 100);
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
async runAllTests() {
|
|
this.testing = true;
|
|
this.testResults = [];
|
|
|
|
try {
|
|
const response = await fetch('/Retail/TestSync/testAllSyncFunctions', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
}
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success') {
|
|
// 处理综合测试结果
|
|
const results = data.data;
|
|
|
|
for (const [key, result] of Object.entries(results)) {
|
|
this.testResults.push({
|
|
name: this.getTestName(key),
|
|
success: result.success,
|
|
message: result.message,
|
|
duration: result.duration || 0
|
|
});
|
|
}
|
|
|
|
this.$message.success('所有测试执行完成');
|
|
} else {
|
|
this.$message.error(data.message || '综合测试失败');
|
|
}
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
this.$message.error('网络错误');
|
|
} finally {
|
|
this.testing = false;
|
|
}
|
|
},
|
|
|
|
async testSyncStatistics() {
|
|
this.loadingStats = true;
|
|
const startTime = Date.now();
|
|
|
|
try {
|
|
const response = await fetch('/Retail/TestSync/testSyncStatistics', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
}
|
|
});
|
|
|
|
const data = await response.json();
|
|
const duration = Date.now() - startTime;
|
|
|
|
this.statsResult = {
|
|
success: data.status === 'success',
|
|
message: data.message,
|
|
data: data.data
|
|
};
|
|
|
|
this.addTestResult('同步统计测试', this.statsResult.success, this.statsResult.message, duration);
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
this.statsResult = {
|
|
success: false,
|
|
message: '网络错误: ' + error.message,
|
|
data: null
|
|
};
|
|
|
|
this.addTestResult('同步统计测试', false, '网络错误', Date.now() - startTime);
|
|
} finally {
|
|
this.loadingStats = false;
|
|
}
|
|
},
|
|
|
|
async testSyncableOrders() {
|
|
this.loadingSyncable = true;
|
|
const startTime = Date.now();
|
|
|
|
try {
|
|
const params = {
|
|
start_date: this.formatDate(this.syncableForm.startDate),
|
|
end_date: this.formatDate(this.syncableForm.endDate),
|
|
limit: this.syncableForm.limit
|
|
};
|
|
|
|
const response = await fetch('/Retail/TestSync/testGetSyncableOrders', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(params)
|
|
});
|
|
|
|
const data = await response.json();
|
|
const duration = Date.now() - startTime;
|
|
|
|
this.syncableResult = {
|
|
success: data.status === 'success',
|
|
message: data.message,
|
|
data: data.data
|
|
};
|
|
|
|
this.addTestResult('可同步订单测试', this.syncableResult.success, this.syncableResult.message, duration);
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
this.syncableResult = {
|
|
success: false,
|
|
message: '网络错误: ' + error.message,
|
|
data: null
|
|
};
|
|
|
|
this.addTestResult('可同步订单测试', false, '网络错误', Date.now() - startTime);
|
|
} finally {
|
|
this.loadingSyncable = false;
|
|
}
|
|
},
|
|
|
|
async testSingleSync() {
|
|
if (!this.singleSyncForm.orderId) {
|
|
this.$message.warning('请输入订单ID');
|
|
return;
|
|
}
|
|
|
|
this.loadingSingle = true;
|
|
const startTime = Date.now();
|
|
|
|
try {
|
|
const response = await fetch('/Retail/TestSync/testSyncSingleOrder', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
order_id: this.singleSyncForm.orderId
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
const duration = Date.now() - startTime;
|
|
|
|
this.singleResult = {
|
|
success: data.status === 'success',
|
|
message: data.message,
|
|
data: data.data
|
|
};
|
|
|
|
this.addTestResult('单个订单同步测试', this.singleResult.success, this.singleResult.message, duration);
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
this.singleResult = {
|
|
success: false,
|
|
message: '网络错误: ' + error.message,
|
|
data: null
|
|
};
|
|
|
|
this.addTestResult('单个订单同步测试', false, '网络错误', Date.now() - startTime);
|
|
} finally {
|
|
this.loadingSingle = false;
|
|
}
|
|
},
|
|
|
|
async testBatchSync() {
|
|
if (!this.batchSyncForm.orderIds) {
|
|
this.$message.warning('请输入订单ID列表');
|
|
return;
|
|
}
|
|
|
|
this.loadingBatch = true;
|
|
const startTime = Date.now();
|
|
|
|
try {
|
|
const orderIds = this.batchSyncForm.orderIds.split(',').map(id => id.trim()).filter(id => id);
|
|
|
|
const response = await fetch('/Retail/TestSync/testBatchSyncOrders', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
order_ids: orderIds
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
const duration = Date.now() - startTime;
|
|
|
|
this.batchResult = {
|
|
success: data.status === 'success',
|
|
message: data.message,
|
|
data: data.data
|
|
};
|
|
|
|
this.addTestResult('批量订单同步测试', this.batchResult.success, this.batchResult.message, duration);
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
this.batchResult = {
|
|
success: false,
|
|
message: '网络错误: ' + error.message,
|
|
data: null
|
|
};
|
|
|
|
this.addTestResult('批量订单同步测试', false, '网络错误', Date.now() - startTime);
|
|
} finally {
|
|
this.loadingBatch = false;
|
|
}
|
|
},
|
|
|
|
addTestResult(name, success, message, duration) {
|
|
this.testResults.push({
|
|
name,
|
|
success,
|
|
message,
|
|
duration
|
|
});
|
|
},
|
|
|
|
clearResults() {
|
|
this.testResults = [];
|
|
this.statsResult = null;
|
|
this.syncableResult = null;
|
|
this.singleResult = null;
|
|
this.batchResult = null;
|
|
},
|
|
|
|
formatDate(date) {
|
|
if (!date) return '';
|
|
return new Date(date).toISOString().slice(0, 19).replace('T', ' ');
|
|
},
|
|
|
|
getTestName(key) {
|
|
const names = {
|
|
'sync_statistics': '同步统计测试',
|
|
'syncable_orders': '可同步订单测试',
|
|
'single_sync': '单个订单同步测试',
|
|
'batch_sync': '批量订单同步测试'
|
|
};
|
|
return names[key] || key;
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |