fix log
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
// assessment.ts
|
// assessment.ts
|
||||||
import apiManager from '../../utils/api'
|
import apiManager from '../../utils/api'
|
||||||
|
import logger from '../../utils/logger'
|
||||||
const recorderManager = wx.getRecorderManager()
|
const recorderManager = wx.getRecorderManager()
|
||||||
let recorderHandlersBound = false
|
let recorderHandlersBound = false
|
||||||
|
|
||||||
@@ -580,7 +581,7 @@ Page<IPageData, IPageInstance>({
|
|||||||
|
|
||||||
// 松开结束录音
|
// 松开结束录音
|
||||||
handleRecordEnd() {
|
handleRecordEnd() {
|
||||||
console.log('---lisa-handleRecordEnd')
|
logger.info('---lisa-handleRecordEnd')
|
||||||
this.stopRecording()
|
this.stopRecording()
|
||||||
// 淡出高亮层
|
// 淡出高亮层
|
||||||
// this.setData({ overlayVisible: false })
|
// this.setData({ overlayVisible: false })
|
||||||
@@ -626,7 +627,7 @@ Page<IPageData, IPageInstance>({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('获取标准语音失败:', err)
|
logger.error('获取标准语音失败:', err)
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '获取语音失败',
|
title: '获取语音失败',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@@ -1014,7 +1015,7 @@ Page<IPageData, IPageInstance>({
|
|||||||
// 调用API获取单词详情
|
// 调用API获取单词详情
|
||||||
this.setData({ dictLoading: true, showDictPopup: true })
|
this.setData({ dictLoading: true, showDictPopup: true })
|
||||||
const wordDetail: any = await apiManager.getWordDetail(cleanedWord);
|
const wordDetail: any = await apiManager.getWordDetail(cleanedWord);
|
||||||
console.log('获取到单词详情:', wordDetail);
|
logger.info('获取到单词详情:', wordDetail);
|
||||||
|
|
||||||
// 处理 Collins 数据中的 HTML 标签
|
// 处理 Collins 数据中的 HTML 标签
|
||||||
const processedCollins = wordDetail['collins'] ? this.processCollinsData(wordDetail['collins']) : wordDetail['collins'];
|
const processedCollins = wordDetail['collins'] ? this.processCollinsData(wordDetail['collins']) : wordDetail['collins'];
|
||||||
@@ -1060,7 +1061,7 @@ Page<IPageData, IPageInstance>({
|
|||||||
});
|
});
|
||||||
this.setData({ dictLoading: false })
|
this.setData({ dictLoading: false })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取单词详情失败:', error)
|
logger.error('获取单词详情失败:', error)
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '获取单词详情失败',
|
title: '获取单词详情失败',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@@ -1155,9 +1156,9 @@ Page<IPageData, IPageInstance>({
|
|||||||
.then(imagePath => {
|
.then(imagePath => {
|
||||||
this.setData({ imagePath })
|
this.setData({ imagePath })
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('获取图片失败:', error)
|
logger.error('获取图片失败:', error)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.setData({ loadingMaskVisible: false })
|
this.setData({ loadingMaskVisible: false })
|
||||||
// try { wx.nextTick(() => { this.computeHighlightLayout() }) } catch (e) { setTimeout(() => this.computeHighlightLayout(), 0) }
|
// try { wx.nextTick(() => { this.computeHighlightLayout() }) } catch (e) { setTimeout(() => this.computeHighlightLayout(), 0) }
|
||||||
@@ -1225,7 +1226,7 @@ Page<IPageData, IPageInstance>({
|
|||||||
// this.updateCircleProgress()
|
// this.updateCircleProgress()
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error('获取图片文本和评分信息失败:', err)
|
logger.error('获取图片文本和评分信息失败:', err)
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '加载失败',
|
title: '加载失败',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@@ -1252,7 +1253,7 @@ Page<IPageData, IPageInstance>({
|
|||||||
success: (result) => {
|
success: (result) => {
|
||||||
if (result.confirm) {
|
if (result.confirm) {
|
||||||
// wx.showLoading({ title: '正在解析...' })
|
// wx.showLoading({ title: '正在解析...' })
|
||||||
console.log('录音文件路径:', res.tempFilePath)
|
logger.info('录音文件路径:', res.tempFilePath)
|
||||||
this.setData({ analizing: true })
|
this.setData({ analizing: true })
|
||||||
apiManager.uploadFile(res.tempFilePath).then((fileId) => {
|
apiManager.uploadFile(res.tempFilePath).then((fileId) => {
|
||||||
apiManager.getAssessmentResult(fileId, this.data.currentSentence.id).then((result) => {
|
apiManager.getAssessmentResult(fileId, this.data.currentSentence.id).then((result) => {
|
||||||
@@ -1304,7 +1305,7 @@ Page<IPageData, IPageInstance>({
|
|||||||
// this.updateCircleProgress()
|
// this.updateCircleProgress()
|
||||||
// wx.hideLoading()
|
// wx.hideLoading()
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('获取评估结果失败:', err)
|
logger.error('获取评估结果失败:', err)
|
||||||
this.setData({
|
this.setData({
|
||||||
isRecording: false,
|
isRecording: false,
|
||||||
overlayVisible: false,
|
overlayVisible: false,
|
||||||
@@ -1328,7 +1329,7 @@ Page<IPageData, IPageInstance>({
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('上传录音失败:', err)
|
logger.error('上传录音失败:', err)
|
||||||
this.setData({
|
this.setData({
|
||||||
isRecording: false,
|
isRecording: false,
|
||||||
overlayVisible: false,
|
overlayVisible: false,
|
||||||
@@ -1476,11 +1477,11 @@ Page<IPageData, IPageInstance>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onTabsChange(event: any) {
|
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) {
|
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) => {
|
this.wordAudioContext.onError((res) => {
|
||||||
console.error('播放单词音频失败:', res)
|
logger.error('播放单词音频失败:', res)
|
||||||
wx.showToast({ title: '播放失败', icon: 'none' })
|
wx.showToast({ title: '播放失败', icon: 'none' })
|
||||||
finalize()
|
finalize()
|
||||||
})
|
})
|
||||||
@@ -1585,7 +1586,7 @@ Page<IPageData, IPageInstance>({
|
|||||||
|
|
||||||
onScoreTap() {
|
onScoreTap() {
|
||||||
if (this.data.isRecording) return
|
if (this.data.isRecording) return
|
||||||
console.log('Score button tapped')
|
logger.info('Score button tapped')
|
||||||
// 当当前选中例句无评分信息时,不响应点击
|
// 当当前选中例句无评分信息时,不响应点击
|
||||||
if (!this.data.hasScoreInfo) {
|
if (!this.data.hasScoreInfo) {
|
||||||
return
|
return
|
||||||
@@ -1624,7 +1625,7 @@ Page<IPageData, IPageInstance>({
|
|||||||
},
|
},
|
||||||
onTransTap() {
|
onTransTap() {
|
||||||
if (this.data.isRecording) return
|
if (this.data.isRecording) return
|
||||||
console.log('User button tapped')
|
logger.info('User button tapped')
|
||||||
// Cycle through translation display modes
|
// Cycle through translation display modes
|
||||||
const currentMode = this.data.transDisplayMode
|
const currentMode = this.data.transDisplayMode
|
||||||
let nextMode: 'en' | 'en_ipa' | 'en_zh' = 'en'
|
let nextMode: 'en' | 'en_ipa' | 'en_zh' = 'en'
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import apiManager from '../../utils/api'
|
import apiManager from '../../utils/api'
|
||||||
|
import logger from '../../utils/logger'
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
@@ -8,7 +9,7 @@ Page({
|
|||||||
vipLevel: 0
|
vipLevel: 0
|
||||||
},
|
},
|
||||||
async onLoad(options: Record<string, string>) {
|
async onLoad(options: Record<string, string>) {
|
||||||
console.log('Coupon page loaded')
|
logger.info('Coupon page loaded')
|
||||||
try {
|
try {
|
||||||
const list = await apiManager.getProductList()
|
const list = await apiManager.getProductList()
|
||||||
const products = (list || []).map((p: any) => ({
|
const products = (list || []).map((p: any) => ({
|
||||||
@@ -30,7 +31,7 @@ Page({
|
|||||||
vipLevel: lvlNum
|
vipLevel: lvlNum
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('加载产品列表失败', err)
|
logger.error('加载产品列表失败', err)
|
||||||
wx.showToast({ title: '加载失败', icon: 'none' })
|
wx.showToast({ title: '加载失败', icon: 'none' })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -71,7 +72,7 @@ Page({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: async (err) => {
|
fail: async (err) => {
|
||||||
console.error('支付失败', err)
|
logger.error('支付失败', err)
|
||||||
if (outTradeNo) {
|
if (outTradeNo) {
|
||||||
await this.queryPaymentWithRetry(outTradeNo)
|
await this.queryPaymentWithRetry(outTradeNo)
|
||||||
} else {
|
} else {
|
||||||
@@ -83,7 +84,7 @@ Page({
|
|||||||
wx.showToast({ title: '缺少支付签名参数', icon: 'none' })
|
wx.showToast({ title: '缺少支付签名参数', icon: 'none' })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('发起支付失败', error)
|
logger.error('发起支付失败', error)
|
||||||
wx.showToast({ title: '发起支付失败', icon: 'none' })
|
wx.showToast({ title: '发起支付失败', icon: 'none' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
// history.ts
|
// history.ts
|
||||||
import apiManager from '../../utils/api';
|
import apiManager from '../../utils/api';
|
||||||
import { ICacheableAuditHistoryItem } from '../../types/app';
|
import { ICacheableAuditHistoryItem } from '../../types/app';
|
||||||
import { FILE_BASE_URL } from '../../utils/config';
|
import { FILE_BASE_URL } from '../../utils/config';
|
||||||
|
import logger from '../../utils/logger'
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
@@ -19,14 +20,14 @@ Page({
|
|||||||
fileBaseUrl: FILE_BASE_URL
|
fileBaseUrl: FILE_BASE_URL
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
console.log('历史记录页面加载');
|
logger.info('历史记录页面加载');
|
||||||
this.loadHistoryData();
|
this.loadHistoryData();
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
console.log('历史记录页面显示');
|
logger.info('历史记录页面显示');
|
||||||
},
|
},
|
||||||
|
|
||||||
async loadHistoryData(page: number = 1) {
|
async loadHistoryData(page: number = 1) {
|
||||||
try {
|
try {
|
||||||
@@ -64,15 +65,15 @@ Page({
|
|||||||
hasMore: newData.length < result.total,
|
hasMore: newData.length < result.total,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载历史记录失败:', error);
|
logger.error('加载历史记录失败:', error);
|
||||||
this.setData({ isLoading: false });
|
this.setData({ isLoading: false });
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '加载失败',
|
title: '加载失败',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onRefresh() {
|
onRefresh() {
|
||||||
this.setData({
|
this.setData({
|
||||||
@@ -123,11 +124,11 @@ Page({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(e: any) {
|
onChange(e: any) {
|
||||||
console.log('图片查看器变化:', e.detail);
|
logger.info('图片查看器变化:', e.detail);
|
||||||
},
|
},
|
||||||
|
|
||||||
onDelete(e: any) {
|
onDelete(e: any) {
|
||||||
console.log('删除图片:', e.detail);
|
logger.info('删除图片:', e.detail);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// index.ts - 纯粹的登录验证页面
|
// index.ts - 纯粹的登录验证页面
|
||||||
import apiManager from '../../utils/api'
|
import apiManager from '../../utils/api'
|
||||||
import { USE_CLOUD, ENV } from '../../utils/config'
|
import { USE_CLOUD, ENV } from '../../utils/config'
|
||||||
|
import logger from '../../utils/logger'
|
||||||
|
|
||||||
// 获取应用实例
|
// 获取应用实例
|
||||||
const app = getApp<IAppOption>()
|
const app = getApp<IAppOption>()
|
||||||
@@ -11,12 +12,12 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
console.log('登录验证页面加载', ENV, USE_CLOUD)
|
logger.info('登录验证页面加载', ENV, USE_CLOUD)
|
||||||
if (USE_CLOUD) {
|
if (USE_CLOUD) {
|
||||||
console.log('云函数环境,直接跳转到主页')
|
logger.info('云函数环境,直接跳转到主页')
|
||||||
this.navigateToMain()
|
this.navigateToMain()
|
||||||
} else {
|
} else {
|
||||||
console.log('非云函数环境,开始智能登录流程')
|
logger.info('非云函数环境,开始智能登录流程')
|
||||||
this.initLoginStatus()
|
this.initLoginStatus()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -31,7 +32,7 @@ Page({
|
|||||||
// 初始化登录状态
|
// 初始化登录状态
|
||||||
async initLoginStatus() {
|
async initLoginStatus() {
|
||||||
try {
|
try {
|
||||||
console.log('开始智能登录流程')
|
logger.info('开始智能登录流程')
|
||||||
|
|
||||||
// 使用智能登录,优先检查本地token
|
// 使用智能登录,优先检查本地token
|
||||||
const loginResult = await apiManager.smartLogin()
|
const loginResult = await apiManager.smartLogin()
|
||||||
@@ -41,18 +42,18 @@ Page({
|
|||||||
app.globalData.isLoggedIn = true
|
app.globalData.isLoggedIn = true
|
||||||
app.globalData.token = loginResult.access_token
|
app.globalData.token = loginResult.access_token
|
||||||
|
|
||||||
console.log('智能登录成功,跳转到主页')
|
logger.info('智能登录成功,跳转到主页')
|
||||||
|
|
||||||
// 直接跳转到主页
|
// 直接跳转到主页
|
||||||
this.navigateToMain()
|
this.navigateToMain()
|
||||||
} else {
|
} else {
|
||||||
// 登录失败,显示错误并重试
|
// 登录失败,显示错误并重试
|
||||||
console.error('智能登录失败')
|
logger.error('智能登录失败')
|
||||||
this.handleLoginFailure()
|
this.handleLoginFailure()
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('初始化登录状态失败:', error)
|
logger.error('初始化登录状态失败:', error)
|
||||||
this.handleLoginFailure()
|
this.handleLoginFailure()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import apiManager from '../../utils/api'
|
import apiManager from '../../utils/api'
|
||||||
|
import logger from '../../utils/logger'
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
@@ -41,7 +42,7 @@ Page({
|
|||||||
displayTime: this.formatTime(it.created_time),
|
displayTime: this.formatTime(it.created_time),
|
||||||
displayAmount: this.formatAmount(it.amount_cents),
|
displayAmount: this.formatAmount(it.amount_cents),
|
||||||
}))
|
}))
|
||||||
console.log(items)
|
logger.info(items)
|
||||||
if (page === 1) {
|
if (page === 1) {
|
||||||
this.setData({ orders: items, page, total: res.total || items.length, hasMore: page * this.data.size < (res.total || items.length), isLoading: false })
|
this.setData({ orders: items, page, total: res.total || items.length, hasMore: page * this.data.size < (res.total || items.length), isLoading: false })
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// profile.ts - 个人中心页面
|
// profile.ts - 个人中心页面
|
||||||
import apiManager from '../../utils/api'
|
import apiManager from '../../utils/api'
|
||||||
import { IAppOption, IUserInfo } from '../../types/app'
|
import { IAppOption, IUserInfo } from '../../types/app'
|
||||||
|
import logger from '../../utils/logger'
|
||||||
|
|
||||||
const app = getApp<IAppOption>()
|
const app = getApp<IAppOption>()
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
console.log('个人中心页面加载')
|
logger.info('个人中心页面加载')
|
||||||
this.initPage()
|
this.initPage()
|
||||||
this.generateAvatarSvg()
|
this.generateAvatarSvg()
|
||||||
// 记录窗口高度
|
// 记录窗口高度
|
||||||
@@ -86,7 +87,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
console.log('个人中心页面显示')
|
logger.info('个人中心页面显示')
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
|
|
||||||
// 更新用户信息(快速操作)
|
// 更新用户信息(快速操作)
|
||||||
@@ -96,13 +97,13 @@ Page({
|
|||||||
this.loadAllDataAsync()
|
this.loadAllDataAsync()
|
||||||
|
|
||||||
const endTime = Date.now()
|
const endTime = Date.now()
|
||||||
console.log('个人中心页面显示完成,耗时:', endTime - startTime, 'ms')
|
logger.info('个人中心页面显示完成,耗时:', endTime - startTime, 'ms')
|
||||||
},
|
},
|
||||||
|
|
||||||
// 初始化页面
|
// 初始化页面
|
||||||
async initPage() {
|
async initPage() {
|
||||||
try {
|
try {
|
||||||
console.log('开始初始化个人中心页面')
|
logger.info('开始初始化个人中心页面')
|
||||||
// wx.setNavigationBarColor({
|
// wx.setNavigationBarColor({
|
||||||
// frontColor: '#000000',
|
// frontColor: '#000000',
|
||||||
// backgroundColor: '#F5F5F5'
|
// backgroundColor: '#F5F5F5'
|
||||||
@@ -118,9 +119,9 @@ Page({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const endTime = Date.now()
|
const endTime = Date.now()
|
||||||
console.log('个人中心页面初始化完成,耗时:', endTime - startTime, 'ms')
|
logger.info('个人中心页面初始化完成,耗时:', endTime - startTime, 'ms')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('个人中心页面初始化失败:', error)
|
logger.error('个人中心页面初始化失败:', error)
|
||||||
this.setBasicData() // 即使失败也要显示基础界面
|
this.setBasicData() // 即使失败也要显示基础界面
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -128,7 +129,7 @@ Page({
|
|||||||
// 设置基础数据,避免页面空白
|
// 设置基础数据,避免页面空白
|
||||||
setBasicData() {
|
setBasicData() {
|
||||||
try {
|
try {
|
||||||
console.log('设置基础数据')
|
logger.info('设置基础数据')
|
||||||
const basicData = {
|
const basicData = {
|
||||||
isLoggedIn: app.globalData.isLoggedIn || false,
|
isLoggedIn: app.globalData.isLoggedIn || false,
|
||||||
userInfo: app.globalData.userInfo || null,
|
userInfo: app.globalData.userInfo || null,
|
||||||
@@ -155,16 +156,16 @@ Page({
|
|||||||
stats: stats
|
stats: stats
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('基础数据设置完成')
|
logger.info('基础数据设置完成')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('设置基础数据失败:', error)
|
logger.error('设置基础数据失败:', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 异步加载所有数据,不阻塞页面显示
|
// 异步加载所有数据,不阻塞页面显示
|
||||||
async loadAllDataAsync() {
|
async loadAllDataAsync() {
|
||||||
try {
|
try {
|
||||||
console.log('开始异步加载所有数据')
|
logger.info('开始异步加载所有数据')
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
|
|
||||||
// 并行加载所有数据,使用异步方式避免阻塞页面显示
|
// 并行加载所有数据,使用异步方式避免阻塞页面显示
|
||||||
@@ -179,22 +180,22 @@ Page({
|
|||||||
this.updateUserInfo()
|
this.updateUserInfo()
|
||||||
|
|
||||||
const endTime = Date.now()
|
const endTime = Date.now()
|
||||||
console.log('所有数据异步加载完成,耗时:', endTime - startTime, 'ms')
|
logger.info('所有数据异步加载完成,耗时:', endTime - startTime, 'ms')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('异步加载数据失败:', error)
|
logger.error('异步加载数据失败:', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 检查登录状态
|
// 检查登录状态
|
||||||
checkLoginStatus() {
|
checkLoginStatus() {
|
||||||
console.log('检查登录状态:', {
|
logger.info('检查登录状态:', {
|
||||||
isLoggedIn: app.globalData.isLoggedIn,
|
isLoggedIn: app.globalData.isLoggedIn,
|
||||||
hasToken: !!app.globalData.token,
|
hasToken: !!app.globalData.token,
|
||||||
userInfo: app.globalData.userInfo
|
userInfo: app.globalData.userInfo
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!app.globalData.isLoggedIn) {
|
if (!app.globalData.isLoggedIn) {
|
||||||
console.log('用户未登录,准备跳转到登录页')
|
logger.info('用户未登录,准备跳转到登录页')
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '请先登录',
|
title: '请先登录',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@@ -208,7 +209,7 @@ Page({
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('用户已登录,继续加载页面')
|
logger.info('用户已登录,继续加载页面')
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -220,14 +221,14 @@ Page({
|
|||||||
dictLevel: app.globalData.dictLevel || wx.getStorageSync('dictLevel') || 'LEVEL1'
|
dictLevel: app.globalData.dictLevel || wx.getStorageSync('dictLevel') || 'LEVEL1'
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('更新用户信息:', userData)
|
logger.info('更新用户信息:', userData)
|
||||||
this.setData(userData)
|
this.setData(userData)
|
||||||
},
|
},
|
||||||
|
|
||||||
// 加载用户统计信息
|
// 加载用户统计信息
|
||||||
async loadUserStats() {
|
async loadUserStats() {
|
||||||
try {
|
try {
|
||||||
console.log('开始加载用户统计信息')
|
logger.info('开始加载用户统计信息')
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
|
|
||||||
// 调用API获取审核统计数据
|
// 调用API获取审核统计数据
|
||||||
@@ -241,10 +242,10 @@ Page({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const endTime = Date.now()
|
const endTime = Date.now()
|
||||||
console.log('统计信息加载完成,耗时:', endTime - startTime, 'ms', stats)
|
logger.info('统计信息加载完成,耗时:', endTime - startTime, 'ms', stats)
|
||||||
this.setData({ stats })
|
this.setData({ stats })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载统计信息失败:', error)
|
logger.error('加载统计信息失败:', error)
|
||||||
// 设置默认统计数据
|
// 设置默认统计数据
|
||||||
this.setData({
|
this.setData({
|
||||||
stats: {
|
stats: {
|
||||||
@@ -261,17 +262,17 @@ Page({
|
|||||||
loadDictLevel() {
|
loadDictLevel() {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
try {
|
try {
|
||||||
console.log('开始加载词典等级配置')
|
logger.info('开始加载词典等级配置')
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
|
|
||||||
const dictLevel = app.globalData.dictLevel || wx.getStorageSync('dictLevel') || 'LEVEL1'
|
const dictLevel = app.globalData.dictLevel || wx.getStorageSync('dictLevel') || 'LEVEL1'
|
||||||
|
|
||||||
const endTime = Date.now()
|
const endTime = Date.now()
|
||||||
console.log('词典等级配置加载完成,耗时:', endTime - startTime, 'ms', dictLevel)
|
logger.info('词典等级配置加载完成,耗时:', endTime - startTime, 'ms', dictLevel)
|
||||||
this.setData({ dictLevel })
|
this.setData({ dictLevel })
|
||||||
resolve()
|
resolve()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载词典等级配置失败:', error)
|
logger.error('加载词典等级配置失败:', error)
|
||||||
// 使用默认设置
|
// 使用默认设置
|
||||||
this.setData({ dictLevel: 'LEVEL1' })
|
this.setData({ dictLevel: 'LEVEL1' })
|
||||||
resolve()
|
resolve()
|
||||||
@@ -282,7 +283,7 @@ Page({
|
|||||||
// 加载积分数据
|
// 加载积分数据
|
||||||
async loadPointsData() {
|
async loadPointsData() {
|
||||||
try {
|
try {
|
||||||
console.log('开始加载积分数据')
|
logger.info('开始加载积分数据')
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
|
|
||||||
// 调用API获取积分数据
|
// 调用API获取积分数据
|
||||||
@@ -292,10 +293,10 @@ Page({
|
|||||||
const finalPointsData = pointsData || { balance: 0, expired_time: '' }
|
const finalPointsData = pointsData || { balance: 0, expired_time: '' }
|
||||||
|
|
||||||
const endTime = Date.now()
|
const endTime = Date.now()
|
||||||
console.log('积分数据加载完成,耗时:', endTime - startTime, 'ms', finalPointsData)
|
logger.info('积分数据加载完成,耗时:', endTime - startTime, 'ms', finalPointsData)
|
||||||
this.setData({ points: finalPointsData })
|
this.setData({ points: finalPointsData })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载积分数据失败:', error)
|
logger.error('加载积分数据失败:', error)
|
||||||
// 设置默认积分数据
|
// 设置默认积分数据
|
||||||
this.setData({
|
this.setData({
|
||||||
points: {
|
points: {
|
||||||
@@ -310,7 +311,7 @@ Page({
|
|||||||
loadCacheStats() {
|
loadCacheStats() {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
try {
|
try {
|
||||||
console.log('开始加载缓存统计信息')
|
logger.info('开始加载缓存统计信息')
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
|
|
||||||
const stats = apiManager.getCacheStats()
|
const stats = apiManager.getCacheStats()
|
||||||
@@ -333,7 +334,7 @@ Page({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const endTime = Date.now()
|
const endTime = Date.now()
|
||||||
console.log('缓存统计信息加载完成,耗时:', endTime - startTime, 'ms', { totalSize: formattedTotalSize, details })
|
logger.info('缓存统计信息加载完成,耗时:', endTime - startTime, 'ms', { totalSize: formattedTotalSize, details })
|
||||||
|
|
||||||
this.setData({
|
this.setData({
|
||||||
cacheStats: {
|
cacheStats: {
|
||||||
@@ -343,7 +344,7 @@ Page({
|
|||||||
})
|
})
|
||||||
resolve()
|
resolve()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载缓存统计信息失败:', error)
|
logger.error('加载缓存统计信息失败:', error)
|
||||||
// 使用默认设置
|
// 使用默认设置
|
||||||
this.setData({
|
this.setData({
|
||||||
cacheStats: {
|
cacheStats: {
|
||||||
@@ -459,7 +460,7 @@ Page({
|
|||||||
this.loadDictLevel()
|
this.loadDictLevel()
|
||||||
this.loadCacheStats()
|
this.loadCacheStats()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('清除缓存失败:', error)
|
logger.error('清除缓存失败:', error)
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '清除失败',
|
title: '清除失败',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@@ -579,7 +580,7 @@ Page({
|
|||||||
*/
|
*/
|
||||||
changeAvatar() {
|
changeAvatar() {
|
||||||
// TODO: 实现更换头像的逻辑
|
// TODO: 实现更换头像的逻辑
|
||||||
console.log('更换头像方法被触发');
|
logger.info('更换头像方法被触发');
|
||||||
// 这里可以添加选择图片、上传图片等逻辑
|
// 这里可以添加选择图片、上传图片等逻辑
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -687,8 +688,8 @@ Page({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查兑换码长度(假设为6位)
|
// 检查兑换码长度(假设为6位)
|
||||||
console.log(couponCode)
|
logger.info(couponCode)
|
||||||
console.log(couponCode.length)
|
logger.info(couponCode.length)
|
||||||
if (couponCode.length !== 6) {
|
if (couponCode.length !== 6) {
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '兑换码应为6位',
|
title: '兑换码应为6位',
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import apiManager from '../../utils/api'
|
|||||||
import imageManager from '../../utils/image'
|
import imageManager from '../../utils/image'
|
||||||
import ActionSheet, { ActionSheetTheme } from 'tdesign-miniprogram/action-sheet/index';
|
import ActionSheet, { ActionSheetTheme } from 'tdesign-miniprogram/action-sheet/index';
|
||||||
import { FILE_BASE_URL } from '../../utils/config'
|
import { FILE_BASE_URL } from '../../utils/config'
|
||||||
|
import logger from '../../utils/logger'
|
||||||
|
|
||||||
const app = getApp<IAppOption>()
|
const app = getApp<IAppOption>()
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
console.log('主功能页面加载')
|
logger.info('主功能页面加载')
|
||||||
this.checkLoginStatus().then(() => {
|
this.checkLoginStatus().then(() => {
|
||||||
// 只有登录成功后才加载历史数据
|
// 只有登录成功后才加载历史数据
|
||||||
if (app.globalData.isLoggedIn) {
|
if (app.globalData.isLoggedIn) {
|
||||||
@@ -82,7 +83,7 @@ Page({
|
|||||||
this.checkDayType()
|
this.checkDayType()
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error('登录检查失败:', error)
|
logger.error('登录检查失败:', error)
|
||||||
})
|
})
|
||||||
this.generateAvatarSvg()
|
this.generateAvatarSvg()
|
||||||
this.generatePhotoSvg()
|
this.generatePhotoSvg()
|
||||||
@@ -310,7 +311,7 @@ Page({
|
|||||||
this.rebuildDateData();
|
this.rebuildDateData();
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载每日摘要失败:', error);
|
logger.error('加载每日摘要失败:', error);
|
||||||
this.setData({ isLoadingHistory: false });
|
this.setData({ isLoadingHistory: false });
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '加载失败',
|
title: '加载失败',
|
||||||
@@ -359,10 +360,10 @@ Page({
|
|||||||
this.fetchSecureTodayImageUrls();
|
this.fetchSecureTodayImageUrls();
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('今日摘要数据加载完成:', processedItems);
|
logger.info('今日摘要数据加载完成:', processedItems);
|
||||||
return processedItems;
|
return processedItems;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载今日摘要失败:', error);
|
logger.error('加载今日摘要失败:', error);
|
||||||
this.setData({ isLoadingToday: false });
|
this.setData({ isLoadingToday: false });
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '加载今日数据失败',
|
title: '加载今日数据失败',
|
||||||
@@ -499,14 +500,14 @@ Page({
|
|||||||
|
|
||||||
// 保存到本地存储
|
// 保存到本地存储
|
||||||
wx.setStorageSync(`thumbnail_cache_${fileId}`, cacheEntry);
|
wx.setStorageSync(`thumbnail_cache_${fileId}`, cacheEntry);
|
||||||
// console.log('缩略图已缓存:', fileId, '大小:', fileSize, 'bytes');
|
//
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.error('获取缩略图文件信息失败:', err);
|
logger.error('获取缩略图文件信息失败:', err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('缓存缩略图失败:', error);
|
logger.error('缓存缩略图失败:', error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -530,18 +531,18 @@ Page({
|
|||||||
} else {
|
} else {
|
||||||
// 缓存过期,删除缓存条目
|
// 缓存过期,删除缓存条目
|
||||||
wx.removeStorageSync(cacheKey);
|
wx.removeStorageSync(cacheKey);
|
||||||
console.log('缩略图缓存已过期并已删除:', fileId);
|
logger.info('缩略图缓存已过期并已删除:', fileId);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// 文件不存在,删除缓存条目
|
// 文件不存在,删除缓存条目
|
||||||
wx.removeStorageSync(cacheKey);
|
wx.removeStorageSync(cacheKey);
|
||||||
console.log('缩略图文件不存在,已删除缓存条目:', fileId);
|
logger.info('缩略图文件不存在,已删除缓存条目:', fileId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取缓存缩略图失败:', error);
|
logger.error('获取缓存缩略图失败:', error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -568,18 +569,18 @@ Page({
|
|||||||
// 登录成功,更新全局状态
|
// 登录成功,更新全局状态
|
||||||
app.globalData.isLoggedIn = true
|
app.globalData.isLoggedIn = true
|
||||||
app.globalData.token = loginResult.access_token
|
app.globalData.token = loginResult.access_token
|
||||||
console.log('登录状态验证成功')
|
logger.info('登录状态验证成功')
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
// 登录失败,跳转到登录页
|
// 登录失败,跳转到登录页
|
||||||
console.log('登录状态验证失败,跳转到登录页')
|
logger.info('登录状态验证失败,跳转到登录页')
|
||||||
wx.reLaunch({
|
wx.reLaunch({
|
||||||
url: '/pages/index/index'
|
url: '/pages/index/index'
|
||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('检查登录状态失败:', error)
|
logger.error('检查登录状态失败:', error)
|
||||||
// 发生错误时跳转到登录页
|
// 发生错误时跳转到登录页
|
||||||
wx.reLaunch({
|
wx.reLaunch({
|
||||||
url: '/pages/index/index'
|
url: '/pages/index/index'
|
||||||
@@ -621,7 +622,7 @@ Page({
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('用户选择:', index)
|
logger.info('用户选择:', index)
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
this.handleTakePhoto();
|
this.handleTakePhoto();
|
||||||
} else if (index === 1) {
|
} else if (index === 1) {
|
||||||
@@ -646,7 +647,7 @@ Page({
|
|||||||
|
|
||||||
wx.hideLoading()
|
wx.hideLoading()
|
||||||
this.setData({ photoPath: imagePath, takePhoto: true })
|
this.setData({ photoPath: imagePath, takePhoto: true })
|
||||||
console.log('拍照成功:', imagePath)
|
logger.info('拍照成功:', imagePath)
|
||||||
// try { wx.nextTick(() => { this.scheduleExpandTransform() }) } catch (err) {}
|
// try { wx.nextTick(() => { this.scheduleExpandTransform() }) } catch (err) {}
|
||||||
|
|
||||||
// 直接跳转到结果页面
|
// 直接跳转到结果页面
|
||||||
@@ -655,7 +656,7 @@ Page({
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
wx.hideLoading()
|
wx.hideLoading()
|
||||||
this.setData({ isProcessing: false ,takePhoto: false})
|
this.setData({ isProcessing: false ,takePhoto: false})
|
||||||
console.error('拍照失败:', error)
|
logger.error('拍照失败:', error)
|
||||||
|
|
||||||
if (error?.message !== '用户取消选择') {
|
if (error?.message !== '用户取消选择') {
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
@@ -682,7 +683,7 @@ Page({
|
|||||||
wx.hideLoading()
|
wx.hideLoading()
|
||||||
this.setData({ photoPath: imagePath, takePhoto: true })
|
this.setData({ photoPath: imagePath, takePhoto: true })
|
||||||
|
|
||||||
console.log('选择图片成功:', imagePath)
|
logger.info('选择图片成功:', imagePath)
|
||||||
// try { wx.nextTick(() => { this.scheduleExpandTransform() }) } catch (err) {}
|
// try { wx.nextTick(() => { this.scheduleExpandTransform() }) } catch (err) {}
|
||||||
|
|
||||||
// 直接跳转到结果页面
|
// 直接跳转到结果页面
|
||||||
@@ -691,7 +692,7 @@ Page({
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
wx.hideLoading()
|
wx.hideLoading()
|
||||||
this.setData({ isProcessing: false ,takePhoto: false})
|
this.setData({ isProcessing: false ,takePhoto: false})
|
||||||
console.error('选择图片失败:', error)
|
logger.error('选择图片失败:', error)
|
||||||
|
|
||||||
if (error?.message !== '用户取消选择') {
|
if (error?.message !== '用户取消选择') {
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
@@ -767,7 +768,7 @@ Page({
|
|||||||
// 跳转到结果页面
|
// 跳转到结果页面
|
||||||
async navigateToResult(imagePath: string) {
|
async navigateToResult(imagePath: string) {
|
||||||
try {
|
try {
|
||||||
console.log('跳转到结果页面:', imagePath)
|
logger.info('跳转到结果页面:', imagePath)
|
||||||
try { wx.nextTick(() => { this.scheduleExpandTransform() }) } catch (err) {}
|
try { wx.nextTick(() => { this.scheduleExpandTransform() }) } catch (err) {}
|
||||||
|
|
||||||
// 跳转到结果页面并传递图片路径
|
// 跳转到结果页面并传递图片路径
|
||||||
@@ -792,7 +793,7 @@ Page({
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('跳转结果页面失败:', error)
|
logger.error('跳转结果页面失败:', error)
|
||||||
this.setData({ isProcessing: false })
|
this.setData({ isProcessing: false })
|
||||||
this.resetPageState()
|
this.resetPageState()
|
||||||
const msg = (error as any)?.message || ''
|
const msg = (error as any)?.message || ''
|
||||||
@@ -913,7 +914,7 @@ Page({
|
|||||||
}
|
}
|
||||||
this.fetchSecureImagesForDate(selectedKey);
|
this.fetchSecureImagesForDate(selectedKey);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('重建日期条失败:', err);
|
logger.error('重建日期条失败:', err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
30
miniprogram/utils/logger.ts
Normal file
30
miniprogram/utils/logger.ts
Normal 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 }
|
||||||
|
|
||||||
Reference in New Issue
Block a user