This commit is contained in:
Felix
2025-12-12 20:23:28 +08:00
parent d293a334e4
commit 02dcd7897f
8 changed files with 145 additions and 108 deletions

View File

@@ -1,5 +1,6 @@
// assessment.ts
import apiManager from '../../utils/api'
import logger from '../../utils/logger'
const recorderManager = wx.getRecorderManager()
let recorderHandlersBound = false
@@ -580,7 +581,7 @@ Page<IPageData, IPageInstance>({
// 松开结束录音
handleRecordEnd() {
console.log('---lisa-handleRecordEnd')
logger.info('---lisa-handleRecordEnd')
this.stopRecording()
// 淡出高亮层
// this.setData({ overlayVisible: false })
@@ -626,7 +627,7 @@ Page<IPageData, IPageInstance>({
}
}
} catch (err) {
console.error('获取标准语音失败:', err)
logger.error('获取标准语音失败:', err)
wx.showToast({
title: '获取语音失败',
icon: 'none'
@@ -1014,7 +1015,7 @@ Page<IPageData, IPageInstance>({
// 调用API获取单词详情
this.setData({ dictLoading: true, showDictPopup: true })
const wordDetail: any = await apiManager.getWordDetail(cleanedWord);
console.log('获取到单词详情:', wordDetail);
logger.info('获取到单词详情:', wordDetail);
// 处理 Collins 数据中的 HTML 标签
const processedCollins = wordDetail['collins'] ? this.processCollinsData(wordDetail['collins']) : wordDetail['collins'];
@@ -1060,7 +1061,7 @@ Page<IPageData, IPageInstance>({
});
this.setData({ dictLoading: false })
} catch (error) {
console.error('获取单词详情失败:', error)
logger.error('获取单词详情失败:', error)
wx.showToast({
title: '获取单词详情失败',
icon: 'none'
@@ -1155,9 +1156,9 @@ Page<IPageData, IPageInstance>({
.then(imagePath => {
this.setData({ imagePath })
})
.catch(error => {
console.error('获取图片失败:', error)
})
.catch(error => {
logger.error('获取图片失败:', error)
})
.finally(() => {
this.setData({ loadingMaskVisible: false })
// try { wx.nextTick(() => { this.computeHighlightLayout() }) } catch (e) { setTimeout(() => this.computeHighlightLayout(), 0) }
@@ -1225,7 +1226,7 @@ Page<IPageData, IPageInstance>({
// this.updateCircleProgress()
})
.catch(err => {
console.error('获取图片文本和评分信息失败:', err)
logger.error('获取图片文本和评分信息失败:', err)
wx.showToast({
title: '加载失败',
icon: 'none'
@@ -1252,7 +1253,7 @@ Page<IPageData, IPageInstance>({
success: (result) => {
if (result.confirm) {
// wx.showLoading({ title: '正在解析...' })
console.log('录音文件路径:', res.tempFilePath)
logger.info('录音文件路径:', res.tempFilePath)
this.setData({ analizing: true })
apiManager.uploadFile(res.tempFilePath).then((fileId) => {
apiManager.getAssessmentResult(fileId, this.data.currentSentence.id).then((result) => {
@@ -1304,7 +1305,7 @@ Page<IPageData, IPageInstance>({
// this.updateCircleProgress()
// wx.hideLoading()
}).catch(err => {
console.error('获取评估结果失败:', err)
logger.error('获取评估结果失败:', err)
this.setData({
isRecording: false,
overlayVisible: false,
@@ -1328,7 +1329,7 @@ Page<IPageData, IPageInstance>({
})
})
}).catch(err => {
console.error('上传录音失败:', err)
logger.error('上传录音失败:', err)
this.setData({
isRecording: false,
overlayVisible: false,
@@ -1476,11 +1477,11 @@ Page<IPageData, IPageInstance>({
},
onTabsChange(event: any) {
console.log(`Change tab, tab-panel value is ${event.detail.value}.`);
logger.info(`Change tab, tab-panel value is ${event.detail.value}.`);
},
onTabsClick(event: any) {
console.log(`Click tab, tab-panel value is ${event.detail.value}.`);
logger.info(`Click tab, tab-panel value is ${event.detail.value}.`);
},
// 播放单词音频(带图标轮播)
@@ -1573,7 +1574,7 @@ Page<IPageData, IPageInstance>({
})
this.wordAudioContext.onError((res) => {
console.error('播放单词音频失败:', res)
logger.error('播放单词音频失败:', res)
wx.showToast({ title: '播放失败', icon: 'none' })
finalize()
})
@@ -1585,7 +1586,7 @@ Page<IPageData, IPageInstance>({
onScoreTap() {
if (this.data.isRecording) return
console.log('Score button tapped')
logger.info('Score button tapped')
// 当当前选中例句无评分信息时,不响应点击
if (!this.data.hasScoreInfo) {
return
@@ -1624,7 +1625,7 @@ Page<IPageData, IPageInstance>({
},
onTransTap() {
if (this.data.isRecording) return
console.log('User button tapped')
logger.info('User button tapped')
// Cycle through translation display modes
const currentMode = this.data.transDisplayMode
let nextMode: 'en' | 'en_ipa' | 'en_zh' = 'en'

View File

@@ -1,4 +1,5 @@
import apiManager from '../../utils/api'
import logger from '../../utils/logger'
Page({
data: {
@@ -8,7 +9,7 @@ Page({
vipLevel: 0
},
async onLoad(options: Record<string, string>) {
console.log('Coupon page loaded')
logger.info('Coupon page loaded')
try {
const list = await apiManager.getProductList()
const products = (list || []).map((p: any) => ({
@@ -30,7 +31,7 @@ Page({
vipLevel: lvlNum
})
} catch (err) {
console.error('加载产品列表失败', err)
logger.error('加载产品列表失败', err)
wx.showToast({ title: '加载失败', icon: 'none' })
}
},
@@ -71,7 +72,7 @@ Page({
}
},
fail: async (err) => {
console.error('支付失败', err)
logger.error('支付失败', err)
if (outTradeNo) {
await this.queryPaymentWithRetry(outTradeNo)
} else {
@@ -83,7 +84,7 @@ Page({
wx.showToast({ title: '缺少支付签名参数', icon: 'none' })
}
} catch (error) {
console.error('发起支付失败', error)
logger.error('发起支付失败', error)
wx.showToast({ title: '发起支付失败', icon: 'none' })
}
}

View File

@@ -1,7 +1,8 @@
// history.ts
import apiManager from '../../utils/api';
import { ICacheableAuditHistoryItem } from '../../types/app';
import { FILE_BASE_URL } from '../../utils/config';
import apiManager from '../../utils/api';
import { ICacheableAuditHistoryItem } from '../../types/app';
import { FILE_BASE_URL } from '../../utils/config';
import logger from '../../utils/logger'
Page({
data: {
@@ -19,14 +20,14 @@ Page({
fileBaseUrl: FILE_BASE_URL
},
onLoad() {
console.log('历史记录页面加载');
this.loadHistoryData();
},
onLoad() {
logger.info('历史记录页面加载');
this.loadHistoryData();
},
onShow() {
console.log('历史记录页面显示');
},
onShow() {
logger.info('历史记录页面显示');
},
async loadHistoryData(page: number = 1) {
try {
@@ -64,15 +65,15 @@ Page({
hasMore: newData.length < result.total,
isLoading: false,
});
} catch (error) {
console.error('加载历史记录失败:', error);
this.setData({ isLoading: false });
wx.showToast({
title: '加载失败',
icon: 'none'
});
}
},
} catch (error) {
logger.error('加载历史记录失败:', error);
this.setData({ isLoading: false });
wx.showToast({
title: '加载失败',
icon: 'none'
});
}
},
onRefresh() {
this.setData({
@@ -123,11 +124,11 @@ Page({
}
},
onChange(e: any) {
console.log('图片查看器变化:', e.detail);
},
onChange(e: any) {
logger.info('图片查看器变化:', e.detail);
},
onDelete(e: any) {
console.log('删除图片:', e.detail);
}
})
onDelete(e: any) {
logger.info('删除图片:', e.detail);
}
})

View File

@@ -1,6 +1,7 @@
// index.ts - 纯粹的登录验证页面
import apiManager from '../../utils/api'
import { USE_CLOUD, ENV } from '../../utils/config'
import logger from '../../utils/logger'
// 获取应用实例
const app = getApp<IAppOption>()
@@ -11,12 +12,12 @@ Page({
},
onLoad() {
console.log('登录验证页面加载', ENV, USE_CLOUD)
logger.info('登录验证页面加载', ENV, USE_CLOUD)
if (USE_CLOUD) {
console.log('云函数环境,直接跳转到主页')
logger.info('云函数环境,直接跳转到主页')
this.navigateToMain()
} else {
console.log('非云函数环境,开始智能登录流程')
logger.info('非云函数环境,开始智能登录流程')
this.initLoginStatus()
}
},
@@ -31,7 +32,7 @@ Page({
// 初始化登录状态
async initLoginStatus() {
try {
console.log('开始智能登录流程')
logger.info('开始智能登录流程')
// 使用智能登录优先检查本地token
const loginResult = await apiManager.smartLogin()
@@ -41,18 +42,18 @@ Page({
app.globalData.isLoggedIn = true
app.globalData.token = loginResult.access_token
console.log('智能登录成功,跳转到主页')
logger.info('智能登录成功,跳转到主页')
// 直接跳转到主页
this.navigateToMain()
} else {
// 登录失败,显示错误并重试
console.error('智能登录失败')
logger.error('智能登录失败')
this.handleLoginFailure()
}
} catch (error) {
console.error('初始化登录状态失败:', error)
logger.error('初始化登录状态失败:', error)
this.handleLoginFailure()
}
},

View File

@@ -1,4 +1,5 @@
import apiManager from '../../utils/api'
import logger from '../../utils/logger'
Page({
data: {
@@ -41,7 +42,7 @@ Page({
displayTime: this.formatTime(it.created_time),
displayAmount: this.formatAmount(it.amount_cents),
}))
console.log(items)
logger.info(items)
if (page === 1) {
this.setData({ orders: items, page, total: res.total || items.length, hasMore: page * this.data.size < (res.total || items.length), isLoading: false })
} else {

View File

@@ -1,6 +1,7 @@
// profile.ts - 个人中心页面
import apiManager from '../../utils/api'
import { IAppOption, IUserInfo } from '../../types/app'
import logger from '../../utils/logger'
const app = getApp<IAppOption>()
@@ -67,7 +68,7 @@ Page({
},
onLoad() {
console.log('个人中心页面加载')
logger.info('个人中心页面加载')
this.initPage()
this.generateAvatarSvg()
// 记录窗口高度
@@ -86,7 +87,7 @@ Page({
},
onShow() {
console.log('个人中心页面显示')
logger.info('个人中心页面显示')
const startTime = Date.now()
// 更新用户信息(快速操作)
@@ -96,13 +97,13 @@ Page({
this.loadAllDataAsync()
const endTime = Date.now()
console.log('个人中心页面显示完成,耗时:', endTime - startTime, 'ms')
logger.info('个人中心页面显示完成,耗时:', endTime - startTime, 'ms')
},
// 初始化页面
async initPage() {
try {
console.log('开始初始化个人中心页面')
logger.info('开始初始化个人中心页面')
// wx.setNavigationBarColor({
// frontColor: '#000000',
// backgroundColor: '#F5F5F5'
@@ -118,9 +119,9 @@ Page({
}
const endTime = Date.now()
console.log('个人中心页面初始化完成,耗时:', endTime - startTime, 'ms')
logger.info('个人中心页面初始化完成,耗时:', endTime - startTime, 'ms')
} catch (error) {
console.error('个人中心页面初始化失败:', error)
logger.error('个人中心页面初始化失败:', error)
this.setBasicData() // 即使失败也要显示基础界面
}
},
@@ -128,7 +129,7 @@ Page({
// 设置基础数据,避免页面空白
setBasicData() {
try {
console.log('设置基础数据')
logger.info('设置基础数据')
const basicData = {
isLoggedIn: app.globalData.isLoggedIn || false,
userInfo: app.globalData.userInfo || null,
@@ -155,16 +156,16 @@ Page({
stats: stats
})
console.log('基础数据设置完成')
logger.info('基础数据设置完成')
} catch (error) {
console.error('设置基础数据失败:', error)
logger.error('设置基础数据失败:', error)
}
},
// 异步加载所有数据,不阻塞页面显示
async loadAllDataAsync() {
try {
console.log('开始异步加载所有数据')
logger.info('开始异步加载所有数据')
const startTime = Date.now()
// 并行加载所有数据,使用异步方式避免阻塞页面显示
@@ -179,22 +180,22 @@ Page({
this.updateUserInfo()
const endTime = Date.now()
console.log('所有数据异步加载完成,耗时:', endTime - startTime, 'ms')
logger.info('所有数据异步加载完成,耗时:', endTime - startTime, 'ms')
} catch (error) {
console.error('异步加载数据失败:', error)
logger.error('异步加载数据失败:', error)
}
},
// 检查登录状态
checkLoginStatus() {
console.log('检查登录状态:', {
logger.info('检查登录状态:', {
isLoggedIn: app.globalData.isLoggedIn,
hasToken: !!app.globalData.token,
userInfo: app.globalData.userInfo
})
if (!app.globalData.isLoggedIn) {
console.log('用户未登录,准备跳转到登录页')
logger.info('用户未登录,准备跳转到登录页')
wx.showToast({
title: '请先登录',
icon: 'none'
@@ -208,7 +209,7 @@ Page({
return false
}
console.log('用户已登录,继续加载页面')
logger.info('用户已登录,继续加载页面')
return true
},
@@ -220,14 +221,14 @@ Page({
dictLevel: app.globalData.dictLevel || wx.getStorageSync('dictLevel') || 'LEVEL1'
}
console.log('更新用户信息:', userData)
logger.info('更新用户信息:', userData)
this.setData(userData)
},
// 加载用户统计信息
async loadUserStats() {
try {
console.log('开始加载用户统计信息')
logger.info('开始加载用户统计信息')
const startTime = Date.now()
// 调用API获取审核统计数据
@@ -241,10 +242,10 @@ Page({
}
const endTime = Date.now()
console.log('统计信息加载完成,耗时:', endTime - startTime, 'ms', stats)
logger.info('统计信息加载完成,耗时:', endTime - startTime, 'ms', stats)
this.setData({ stats })
} catch (error) {
console.error('加载统计信息失败:', error)
logger.error('加载统计信息失败:', error)
// 设置默认统计数据
this.setData({
stats: {
@@ -261,17 +262,17 @@ Page({
loadDictLevel() {
return new Promise<void>((resolve) => {
try {
console.log('开始加载词典等级配置')
logger.info('开始加载词典等级配置')
const startTime = Date.now()
const dictLevel = app.globalData.dictLevel || wx.getStorageSync('dictLevel') || 'LEVEL1'
const endTime = Date.now()
console.log('词典等级配置加载完成,耗时:', endTime - startTime, 'ms', dictLevel)
logger.info('词典等级配置加载完成,耗时:', endTime - startTime, 'ms', dictLevel)
this.setData({ dictLevel })
resolve()
} catch (error) {
console.error('加载词典等级配置失败:', error)
logger.error('加载词典等级配置失败:', error)
// 使用默认设置
this.setData({ dictLevel: 'LEVEL1' })
resolve()
@@ -282,7 +283,7 @@ Page({
// 加载积分数据
async loadPointsData() {
try {
console.log('开始加载积分数据')
logger.info('开始加载积分数据')
const startTime = Date.now()
// 调用API获取积分数据
@@ -292,10 +293,10 @@ Page({
const finalPointsData = pointsData || { balance: 0, expired_time: '' }
const endTime = Date.now()
console.log('积分数据加载完成,耗时:', endTime - startTime, 'ms', finalPointsData)
logger.info('积分数据加载完成,耗时:', endTime - startTime, 'ms', finalPointsData)
this.setData({ points: finalPointsData })
} catch (error) {
console.error('加载积分数据失败:', error)
logger.error('加载积分数据失败:', error)
// 设置默认积分数据
this.setData({
points: {
@@ -310,7 +311,7 @@ Page({
loadCacheStats() {
return new Promise<void>((resolve) => {
try {
console.log('开始加载缓存统计信息')
logger.info('开始加载缓存统计信息')
const startTime = Date.now()
const stats = apiManager.getCacheStats()
@@ -333,7 +334,7 @@ Page({
}
const endTime = Date.now()
console.log('缓存统计信息加载完成,耗时:', endTime - startTime, 'ms', { totalSize: formattedTotalSize, details })
logger.info('缓存统计信息加载完成,耗时:', endTime - startTime, 'ms', { totalSize: formattedTotalSize, details })
this.setData({
cacheStats: {
@@ -343,7 +344,7 @@ Page({
})
resolve()
} catch (error) {
console.error('加载缓存统计信息失败:', error)
logger.error('加载缓存统计信息失败:', error)
// 使用默认设置
this.setData({
cacheStats: {
@@ -459,7 +460,7 @@ Page({
this.loadDictLevel()
this.loadCacheStats()
} catch (error) {
console.error('清除缓存失败:', error)
logger.error('清除缓存失败:', error)
wx.showToast({
title: '清除失败',
icon: 'none'
@@ -579,7 +580,7 @@ Page({
*/
changeAvatar() {
// TODO: 实现更换头像的逻辑
console.log('更换头像方法被触发');
logger.info('更换头像方法被触发');
// 这里可以添加选择图片、上传图片等逻辑
},
@@ -687,8 +688,8 @@ Page({
}
// 检查兑换码长度假设为6位
console.log(couponCode)
console.log(couponCode.length)
logger.info(couponCode)
logger.info(couponCode.length)
if (couponCode.length !== 6) {
wx.showToast({
title: '兑换码应为6位',

View File

@@ -4,6 +4,7 @@ import apiManager from '../../utils/api'
import imageManager from '../../utils/image'
import ActionSheet, { ActionSheetTheme } from 'tdesign-miniprogram/action-sheet/index';
import { FILE_BASE_URL } from '../../utils/config'
import logger from '../../utils/logger'
const app = getApp<IAppOption>()
@@ -73,7 +74,7 @@ Page({
},
onLoad() {
console.log('主功能页面加载')
logger.info('主功能页面加载')
this.checkLoginStatus().then(() => {
// 只有登录成功后才加载历史数据
if (app.globalData.isLoggedIn) {
@@ -82,7 +83,7 @@ Page({
this.checkDayType()
}
}).catch((error) => {
console.error('登录检查失败:', error)
logger.error('登录检查失败:', error)
})
this.generateAvatarSvg()
this.generatePhotoSvg()
@@ -310,7 +311,7 @@ Page({
this.rebuildDateData();
});
} catch (error) {
console.error('加载每日摘要失败:', error);
logger.error('加载每日摘要失败:', error);
this.setData({ isLoadingHistory: false });
wx.showToast({
title: '加载失败',
@@ -359,10 +360,10 @@ Page({
this.fetchSecureTodayImageUrls();
});
console.log('今日摘要数据加载完成:', processedItems);
logger.info('今日摘要数据加载完成:', processedItems);
return processedItems;
} catch (error) {
console.error('加载今日摘要失败:', error);
logger.error('加载今日摘要失败:', error);
this.setData({ isLoadingToday: false });
wx.showToast({
title: '加载今日数据失败',
@@ -499,14 +500,14 @@ Page({
// 保存到本地存储
wx.setStorageSync(`thumbnail_cache_${fileId}`, cacheEntry);
// console.log('缩略图已缓存:', fileId, '大小:', fileSize, 'bytes');
//
},
fail: (err) => {
console.error('获取缩略图文件信息失败:', err);
logger.error('获取缩略图文件信息失败:', err);
}
});
} catch (error) {
console.error('缓存缩略图失败:', error);
logger.error('缓存缩略图失败:', error);
}
},
@@ -530,18 +531,18 @@ Page({
} else {
// 缓存过期,删除缓存条目
wx.removeStorageSync(cacheKey);
console.log('缩略图缓存已过期并已删除:', fileId);
logger.info('缩略图缓存已过期并已删除:', fileId);
}
} catch (err) {
// 文件不存在,删除缓存条目
wx.removeStorageSync(cacheKey);
console.log('缩略图文件不存在,已删除缓存条目:', fileId);
logger.info('缩略图文件不存在,已删除缓存条目:', fileId);
}
}
return null;
} catch (error) {
console.error('获取缓存缩略图失败:', error);
logger.error('获取缓存缩略图失败:', error);
return null;
}
},
@@ -568,18 +569,18 @@ Page({
// 登录成功,更新全局状态
app.globalData.isLoggedIn = true
app.globalData.token = loginResult.access_token
console.log('登录状态验证成功')
logger.info('登录状态验证成功')
return true
} else {
// 登录失败,跳转到登录页
console.log('登录状态验证失败,跳转到登录页')
logger.info('登录状态验证失败,跳转到登录页')
wx.reLaunch({
url: '/pages/index/index'
})
return false
}
} catch (error) {
console.error('检查登录状态失败:', error)
logger.error('检查登录状态失败:', error)
// 发生错误时跳转到登录页
wx.reLaunch({
url: '/pages/index/index'
@@ -621,7 +622,7 @@ Page({
})
return
}
console.log('用户选择:', index)
logger.info('用户选择:', index)
if (index === 0) {
this.handleTakePhoto();
} else if (index === 1) {
@@ -646,7 +647,7 @@ Page({
wx.hideLoading()
this.setData({ photoPath: imagePath, takePhoto: true })
console.log('拍照成功:', imagePath)
logger.info('拍照成功:', imagePath)
// try { wx.nextTick(() => { this.scheduleExpandTransform() }) } catch (err) {}
// 直接跳转到结果页面
@@ -655,7 +656,7 @@ Page({
} catch (error: any) {
wx.hideLoading()
this.setData({ isProcessing: false ,takePhoto: false})
console.error('拍照失败:', error)
logger.error('拍照失败:', error)
if (error?.message !== '用户取消选择') {
wx.showToast({
@@ -682,7 +683,7 @@ Page({
wx.hideLoading()
this.setData({ photoPath: imagePath, takePhoto: true })
console.log('选择图片成功:', imagePath)
logger.info('选择图片成功:', imagePath)
// try { wx.nextTick(() => { this.scheduleExpandTransform() }) } catch (err) {}
// 直接跳转到结果页面
@@ -691,7 +692,7 @@ Page({
} catch (error: any) {
wx.hideLoading()
this.setData({ isProcessing: false ,takePhoto: false})
console.error('选择图片失败:', error)
logger.error('选择图片失败:', error)
if (error?.message !== '用户取消选择') {
wx.showToast({
@@ -767,7 +768,7 @@ Page({
// 跳转到结果页面
async navigateToResult(imagePath: string) {
try {
console.log('跳转到结果页面:', imagePath)
logger.info('跳转到结果页面:', imagePath)
try { wx.nextTick(() => { this.scheduleExpandTransform() }) } catch (err) {}
// 跳转到结果页面并传递图片路径
@@ -792,7 +793,7 @@ Page({
}
} catch (error) {
console.error('跳转结果页面失败:', error)
logger.error('跳转结果页面失败:', error)
this.setData({ isProcessing: false })
this.resetPageState()
const msg = (error as any)?.message || ''
@@ -913,7 +914,7 @@ Page({
}
this.fetchSecureImagesForDate(selectedKey);
} catch (err) {
console.error('重建日期条失败:', err);
logger.error('重建日期条失败:', err);
}
},

View File

@@ -0,0 +1,30 @@
import { ENV } from './config'
type Level = 'log' | 'info' | 'warn' | 'error' | 'debug'
const isRelease = ENV === 'release'
function emit(level: Exclude<Level, 'debug'>, args: any[]): void {
if (isRelease && level !== 'error') return
if (level === 'log') {
console.log(...args)
} else if (level === 'info') {
console.info(...args)
} else if (level === 'warn') {
console.warn(...args)
} else {
console.error(...args)
}
}
const logger = {
log: (...args: any[]) => emit('log', args),
info: (...args: any[]) => emit('info', args),
warn: (...args: any[]) => emit('warn', args),
error: (...args: any[]) => emit('error', args),
debug: (...args: any[]) => emit('log', ['[DEBUG]', ...args]),
}
export default logger
export { logger }