Initial commit
This commit is contained in:
190
miniprogram/pages/error-log/index.js
Normal file
190
miniprogram/pages/error-log/index.js
Normal file
@@ -0,0 +1,190 @@
|
||||
// pages/error-log/index.js
|
||||
Page({
|
||||
data: {
|
||||
errorLogs: [],
|
||||
showDetail: false,
|
||||
currentError: null
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadErrorLogs();
|
||||
},
|
||||
|
||||
// 加载错误日志
|
||||
loadErrorLogs() {
|
||||
try {
|
||||
const logs = wx.getStorageSync('error_logs') || [];
|
||||
|
||||
// 如果没有日志,添加一些示例数据
|
||||
if (logs.length === 0) {
|
||||
const sampleLogs = [
|
||||
{
|
||||
id: Date.now() + 1,
|
||||
timestamp: Date.now() - 3600000, // 1小时前
|
||||
type: '网络错误',
|
||||
level: 'error',
|
||||
message: 'request:fail url not in domain list',
|
||||
detail: {
|
||||
url: 'https://tral.cc/api/v1/users/login',
|
||||
method: 'POST',
|
||||
errMsg: 'request:fail url not in domain list',
|
||||
statusCode: null,
|
||||
stack: 'Error: request:fail url not in domain list\n at wx.request (native)\n at login (pages/login/index.js:45:5)\n at onTapLogin (pages/login/index.js:25:3)'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: Date.now() + 2,
|
||||
timestamp: Date.now() - 1800000, // 30分钟前
|
||||
type: '登录错误',
|
||||
level: 'error',
|
||||
message: '获取微信会话失败: 登录凭证code格式异常',
|
||||
detail: {
|
||||
url: 'https://tral.cc/api/v1/users/login',
|
||||
method: 'POST',
|
||||
errMsg: '登录凭证code格式异常',
|
||||
statusCode: 400,
|
||||
response: {
|
||||
code: 400,
|
||||
message: '登录凭证code格式异常',
|
||||
data: null
|
||||
},
|
||||
stack: 'Error: 登录凭证code格式异常\n at handleLoginResponse (utils/api.js:78:9)\n at login (pages/login/index.js:52:7)'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: Date.now() + 3,
|
||||
timestamp: Date.now() - 900000, // 15分钟前
|
||||
type: '网络超时',
|
||||
level: 'warning',
|
||||
message: '请求超时,请检查网络连接',
|
||||
detail: {
|
||||
url: 'https://tral.cc/api/v1/products',
|
||||
method: 'GET',
|
||||
errMsg: 'request:fail timeout',
|
||||
statusCode: null,
|
||||
timeout: 5000
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
wx.setStorageSync('error_logs', sampleLogs);
|
||||
this.setData({ errorLogs: sampleLogs });
|
||||
} else {
|
||||
// 按时间倒序排列
|
||||
logs.sort((a, b) => b.timestamp - a.timestamp);
|
||||
this.setData({ errorLogs: logs });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载错误日志失败:', error);
|
||||
wx.showToast({
|
||||
title: '加载日志失败',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 显示错误详情
|
||||
showErrorDetail(e) {
|
||||
const error = e.currentTarget.dataset.error;
|
||||
console.log('显示错误详情:', error);
|
||||
|
||||
this.setData({
|
||||
showDetail: true,
|
||||
currentError: error
|
||||
});
|
||||
},
|
||||
|
||||
// 关闭错误详情
|
||||
closeErrorDetail() {
|
||||
this.setData({
|
||||
showDetail: false,
|
||||
currentError: null
|
||||
});
|
||||
},
|
||||
|
||||
// 复制错误信息
|
||||
copyErrorInfo(e) {
|
||||
const text = e.currentTarget.dataset.text;
|
||||
wx.setClipboardData({
|
||||
data: text,
|
||||
success: () => {
|
||||
wx.showToast({
|
||||
title: '已复制到剪贴板',
|
||||
icon: 'success'
|
||||
});
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({
|
||||
title: '复制失败',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 清空错误日志
|
||||
clearErrorLogs() {
|
||||
wx.showModal({
|
||||
title: '确认清空',
|
||||
content: '确定要清空所有错误日志吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
wx.removeStorageSync('error_logs');
|
||||
this.setData({ errorLogs: [] });
|
||||
wx.showToast({
|
||||
title: '已清空日志',
|
||||
icon: 'success'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 导出错误日志
|
||||
exportErrorLogs() {
|
||||
const logs = this.data.errorLogs;
|
||||
if (logs.length === 0) {
|
||||
wx.showToast({
|
||||
title: '暂无日志可导出',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const exportData = JSON.stringify(logs, null, 2);
|
||||
wx.setClipboardData({
|
||||
data: exportData,
|
||||
success: () => {
|
||||
wx.showToast({
|
||||
title: '日志已复制到剪贴板',
|
||||
icon: 'success'
|
||||
});
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({
|
||||
title: '导出失败',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 格式化时间
|
||||
formatTime(timestamp) {
|
||||
const date = new Date(timestamp);
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
},
|
||||
|
||||
// 下拉刷新
|
||||
onPullDownRefresh() {
|
||||
this.loadErrorLogs();
|
||||
wx.stopPullDownRefresh();
|
||||
}
|
||||
});
|
||||
8
miniprogram/pages/error-log/index.json
Normal file
8
miniprogram/pages/error-log/index.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"navigationBarTitleText": "错误日志",
|
||||
"navigationBarBackgroundColor": "#007aff",
|
||||
"navigationBarTextStyle": "white",
|
||||
"backgroundColor": "#f5f5f5",
|
||||
"enablePullDownRefresh": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
105
miniprogram/pages/error-log/index.wxml
Normal file
105
miniprogram/pages/error-log/index.wxml
Normal file
@@ -0,0 +1,105 @@
|
||||
<!--pages/error-log/index.wxml-->
|
||||
<view class="error-log-container">
|
||||
<!-- 页面标题 -->
|
||||
<view class="header">
|
||||
<text class="title">错误日志</text>
|
||||
<view class="header-actions">
|
||||
<button class="action-btn export-btn" bindtap="exportErrorLogs">导出</button>
|
||||
<button class="action-btn clear-btn" bindtap="clearErrorLogs">清空</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 错误日志列表 -->
|
||||
<view class="error-list" wx:if="{{errorLogs.length > 0}}">
|
||||
<view class="error-item" wx:for="{{errorLogs}}" wx:key="id" bindtap="showErrorDetail" data-error="{{item}}">
|
||||
<view class="error-header">
|
||||
<view class="error-type {{item.level}}">{{item.type}}</view>
|
||||
<view class="error-time">{{formatTime(item.timestamp)}}</view>
|
||||
</view>
|
||||
<view class="error-message">{{item.message}}</view>
|
||||
<view class="error-preview" wx:if="{{item.detail.url}}">
|
||||
<text class="url">{{item.detail.url}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view class="empty-state" wx:else>
|
||||
<view class="empty-icon">📝</view>
|
||||
<view class="empty-text">暂无错误日志</view>
|
||||
</view>
|
||||
|
||||
<!-- 错误详情弹窗 -->
|
||||
<view class="error-detail-modal" wx:if="{{showDetail}}" bindtap="closeErrorDetail">
|
||||
<view class="modal-content" catchtap="">
|
||||
<view class="modal-header">
|
||||
<text class="modal-title">错误详情</text>
|
||||
<view class="close-btn" bindtap="closeErrorDetail">×</view>
|
||||
</view>
|
||||
|
||||
<scroll-view class="modal-body" scroll-y>
|
||||
<view class="detail-section">
|
||||
<view class="section-title">基本信息</view>
|
||||
<view class="detail-item">
|
||||
<text class="label">时间:</text>
|
||||
<text class="value">{{formatTime(currentError.timestamp)}}</text>
|
||||
</view>
|
||||
<view class="detail-item">
|
||||
<text class="label">类型:</text>
|
||||
<text class="value {{currentError.level}}">{{currentError.type}}</text>
|
||||
</view>
|
||||
<view class="detail-item">
|
||||
<text class="label">消息:</text>
|
||||
<text class="value">{{currentError.message}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="detail-section" wx:if="{{currentError.detail.url}}">
|
||||
<view class="section-title">请求信息</view>
|
||||
<view class="detail-item">
|
||||
<text class="label">URL:</text>
|
||||
<text class="value url-text">{{currentError.detail.url}}</text>
|
||||
<button class="copy-btn" bindtap="copyErrorInfo" data-text="{{currentError.detail.url}}">复制</button>
|
||||
</view>
|
||||
<view class="detail-item" wx:if="{{currentError.detail.method}}">
|
||||
<text class="label">方法:</text>
|
||||
<text class="value">{{currentError.detail.method}}</text>
|
||||
</view>
|
||||
<view class="detail-item" wx:if="{{currentError.detail.statusCode}}">
|
||||
<text class="label">状态码:</text>
|
||||
<text class="value">{{currentError.detail.statusCode}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="detail-section" wx:if="{{currentError.detail.errMsg}}">
|
||||
<view class="section-title">错误信息</view>
|
||||
<view class="error-msg-box">
|
||||
<text class="error-msg">{{currentError.detail.errMsg}}</text>
|
||||
<button class="copy-btn" bindtap="copyErrorInfo" data-text="{{currentError.detail.errMsg}}">复制</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="detail-section" wx:if="{{currentError.detail.response}}">
|
||||
<view class="section-title">响应数据</view>
|
||||
<view class="json-box">
|
||||
<text class="json-text">{{JSON.stringify(currentError.detail.response, null, 2)}}</text>
|
||||
<button class="copy-btn" bindtap="copyErrorInfo" data-text="{{JSON.stringify(currentError.detail.response, null, 2)}}">复制</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="detail-section" wx:if="{{currentError.detail.stack}}">
|
||||
<view class="section-title">堆栈信息</view>
|
||||
<view class="stack-box">
|
||||
<text class="stack-text">{{currentError.detail.stack}}</text>
|
||||
<button class="copy-btn" bindtap="copyErrorInfo" data-text="{{currentError.detail.stack}}">复制</button>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<view class="modal-footer">
|
||||
<button class="modal-btn copy-all-btn" bindtap="copyErrorInfo" data-text="{{JSON.stringify(currentError, null, 2)}}">复制完整信息</button>
|
||||
<button class="modal-btn close-modal-btn" bindtap="closeErrorDetail">关闭</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
285
miniprogram/pages/error-log/index.wxss
Normal file
285
miniprogram/pages/error-log/index.wxss
Normal file
@@ -0,0 +1,285 @@
|
||||
/* pages/error-log/index.wxss */
|
||||
.error-log-container {
|
||||
padding: 20rpx;
|
||||
background-color: #f5f5f5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* 页面标题 */
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
padding: 20rpx;
|
||||
background-color: #fff;
|
||||
border-radius: 12rpx;
|
||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
padding: 12rpx 24rpx;
|
||||
font-size: 28rpx;
|
||||
border-radius: 8rpx;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.export-btn {
|
||||
background-color: #007aff;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
background-color: #ff3b30;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* 错误日志列表 */
|
||||
.error-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.error-item {
|
||||
background-color: #fff;
|
||||
border-radius: 12rpx;
|
||||
padding: 24rpx;
|
||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
||||
border-left: 8rpx solid #ff3b30;
|
||||
}
|
||||
|
||||
.error-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.error-type {
|
||||
padding: 8rpx 16rpx;
|
||||
border-radius: 20rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.error-type.error {
|
||||
background-color: #ffebee;
|
||||
color: #d32f2f;
|
||||
}
|
||||
|
||||
.error-type.warning {
|
||||
background-color: #fff3e0;
|
||||
color: #f57c00;
|
||||
}
|
||||
|
||||
.error-type.info {
|
||||
background-color: #e3f2fd;
|
||||
color: #1976d2;
|
||||
}
|
||||
|
||||
.error-time {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
margin-bottom: 12rpx;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.error-preview {
|
||||
background-color: #f8f9fa;
|
||||
padding: 12rpx;
|
||||
border-radius: 8rpx;
|
||||
border: 1rpx solid #e9ecef;
|
||||
}
|
||||
|
||||
.url {
|
||||
font-size: 24rpx;
|
||||
color: #007aff;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* 空状态 */
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 100rpx 40rpx;
|
||||
background-color: #fff;
|
||||
border-radius: 12rpx;
|
||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 80rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 错误详情弹窗 */
|
||||
.error-detail-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
width: 100%;
|
||||
max-height: 80vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 30rpx;
|
||||
border-bottom: 1rpx solid #e9ecef;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
font-size: 48rpx;
|
||||
color: #999;
|
||||
width: 60rpx;
|
||||
height: 60rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
flex: 1;
|
||||
padding: 30rpx;
|
||||
max-height: 60vh;
|
||||
}
|
||||
|
||||
.detail-section {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 20rpx;
|
||||
padding-bottom: 10rpx;
|
||||
border-bottom: 2rpx solid #007aff;
|
||||
}
|
||||
|
||||
.detail-item {
|
||||
display: flex;
|
||||
margin-bottom: 16rpx;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
min-width: 120rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
flex: 1;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.url-text {
|
||||
color: #007aff;
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
padding: 8rpx 16rpx;
|
||||
font-size: 22rpx;
|
||||
background-color: #f8f9fa;
|
||||
color: #007aff;
|
||||
border: 1rpx solid #007aff;
|
||||
border-radius: 6rpx;
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
|
||||
.error-msg-box,
|
||||
.json-box,
|
||||
.stack-box {
|
||||
background-color: #f8f9fa;
|
||||
padding: 20rpx;
|
||||
border-radius: 8rpx;
|
||||
border: 1rpx solid #e9ecef;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.error-msg,
|
||||
.json-text,
|
||||
.stack-text {
|
||||
font-size: 24rpx;
|
||||
color: #333;
|
||||
line-height: 1.5;
|
||||
font-family: 'Courier New', monospace;
|
||||
word-break: break-all;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
padding: 30rpx;
|
||||
border-top: 1rpx solid #e9ecef;
|
||||
}
|
||||
|
||||
.modal-btn {
|
||||
flex: 1;
|
||||
padding: 20rpx;
|
||||
font-size: 28rpx;
|
||||
border-radius: 8rpx;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.copy-all-btn {
|
||||
background-color: #007aff;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.close-modal-btn {
|
||||
background-color: #f8f9fa;
|
||||
color: #333;
|
||||
border: 1rpx solid #e9ecef;
|
||||
}
|
||||
Reference in New Issue
Block a user