chore: normalize eol and cleanup

This commit is contained in:
zhiyun 2026-02-04 19:10:34 +08:00
parent 1ae572a083
commit 7b6bb822fa
6 changed files with 65 additions and 42 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
* text=auto
*.js text eol=lf
*.json text eol=lf
*.wxml text eol=lf
*.wxss text eol=lf
*.wxs text eol=lf
*.md text eol=lf
*.sh text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
*.xml text eol=lf
*.svg text eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.webp binary
*.ico binary

10
app.js
View File

@ -439,18 +439,18 @@ App({
async loadAuditStatus() { async loadAuditStatus() {
const localAppVersion = config.APP_VERSION || '' const localAppVersion = config.APP_VERSION || ''
try { try {
const res = await api.common.getAuditStatus() const res = await api.common.getAuditStatus()
if (res.code === 0 && res.data) { if (res.code === 0 && res.data) {
const serverAppVersion = res.data.app_version || res.data.appVersion || '' const serverAppVersion = res.data.app_version || res.data.appVersion || ''
if (localAppVersion !== serverAppVersion) { if (localAppVersion !== serverAppVersion) {
this.globalData.auditStatus = 0 this.globalData.auditStatus = 0
wx.setStorageSync('auditStatus', 0) wx.setStorageSync('auditStatus', 0)
return return
} }
const auditStatus = Number(res.data.auditStatus || 0) const auditStatus = Number(res.data.auditStatus || 0)
this.globalData.auditStatus = auditStatus this.globalData.auditStatus = auditStatus
wx.setStorageSync('auditStatus', auditStatus) wx.setStorageSync('auditStatus', auditStatus)
@ -459,13 +459,13 @@ App({
} catch (err) { } catch (err) {
console.error('获取审核状态失败', err) console.error('获取审核状态失败', err)
} }
const cachedStatus = wx.getStorageSync('auditStatus') const cachedStatus = wx.getStorageSync('auditStatus')
if (cachedStatus !== undefined) { if (cachedStatus !== undefined) {
this.globalData.auditStatus = cachedStatus this.globalData.auditStatus = cachedStatus
return return
} }
this.globalData.auditStatus = 0 this.globalData.auditStatus = 0
wx.setStorageSync('auditStatus', 0) wx.setStorageSync('auditStatus', 0)
}, },

View File

@ -43,7 +43,7 @@ Page({
// 从配置文件获取API域名 // 从配置文件获取API域名
const baseUrl = String(config.API_BASE_URL || '').replace(/\/api$/, '') const baseUrl = String(config.API_BASE_URL || '').replace(/\/api$/, '')
// 网络请求 // 网络请求
wx.request({ wx.request({
url: `${baseUrl}/api/agreements?code=${code}`, url: `${baseUrl}/api/agreements?code=${code}`,

View File

@ -22,10 +22,10 @@ Page({
data: { data: {
statusBarHeight: 44, statusBarHeight: 44,
navHeight: 96, navHeight: 96,
// 审核状态 // 审核状态
auditStatus: 0, auditStatus: 0,
// 角色信息 // 角色信息
characterId: '', characterId: '',
conversationId: '', conversationId: '',
@ -134,21 +134,21 @@ Page({
// 从本地存储读取审核状态 // 从本地存储读取审核状态
const auditStatus = wx.getStorageSync('auditStatus') || 0 const auditStatus = wx.getStorageSync('auditStatus') || 0
const { statusBarHeight, navHeight } = app.globalData const { statusBarHeight, navHeight } = app.globalData
// 初始化消息处理相关变量 // 初始化消息处理相关变量
this.pendingMessages = [] this.pendingMessages = []
this.messageTimer = null this.messageTimer = null
this.isProcessing = false this.isProcessing = false
// 获取参数 // 获取参数
const characterId = options.id || '' const characterId = options.id || ''
const conversationId = options.conversationId || '' const conversationId = options.conversationId || ''
const characterName = decodeURIComponent(options.name || '') const characterName = decodeURIComponent(options.name || '')
// 设置用户头像 // 设置用户头像
const userInfo = app.globalData.userInfo const userInfo = app.globalData.userInfo
const myAvatar = imageUrl.getAvatarUrl(userInfo?.avatar) const myAvatar = imageUrl.getAvatarUrl(userInfo?.avatar)
this.setData({ this.setData({
statusBarHeight, statusBarHeight,
navHeight, navHeight,
@ -172,7 +172,7 @@ Page({
// 从本地存储读取审核状态 // 从本地存储读取审核状态
const auditStatus = wx.getStorageSync('auditStatus') || 0 const auditStatus = wx.getStorageSync('auditStatus') || 0
this.setData({ auditStatus }) this.setData({ auditStatus })
// 每次显示页面时,刷新一次配额状态,确保免费畅聊时间等状态是最新的 // 每次显示页面时,刷新一次配额状态,确保免费畅聊时间等状态是最新的
if (!this.data.loading) { if (!this.data.loading) {
this.loadQuotaStatus() this.loadQuotaStatus()
@ -1937,31 +1937,31 @@ Page({
onVoiceTouchEnd() { onVoiceTouchEnd() {
clearInterval(this.recordingTimer) clearInterval(this.recordingTimer)
const { voiceCancelHint, recordingDuration, characterId, character, isUnlocked, remainingCount } = this.data const { voiceCancelHint, recordingDuration, characterId, character, isUnlocked, remainingCount } = this.data
this.setData({ isRecording: false }) this.setData({ isRecording: false })
if (this.recorderManager) { if (this.recorderManager) {
this.recorderManager.stop() this.recorderManager.stop()
} }
// 取消发送 // 取消发送
if (voiceCancelHint) { if (voiceCancelHint) {
util.showToast('已取消') util.showToast('已取消')
return return
} }
// 录音时间太短 // 录音时间太短
if (recordingDuration < 1) { if (recordingDuration < 1) {
util.showError('录音时间太短') util.showError('录音时间太短')
return return
} }
// 等待录音停止后再处理 // 等待录音停止后再处理
this.recorderManager.onStop(async (res) => { this.recorderManager.onStop(async (res) => {
console.log('[chat-detail] 录音完成:', res.tempFilePath, '时长:', recordingDuration) console.log('[chat-detail] 录音完成:', res.tempFilePath, '时长:', recordingDuration)
// 先显示语音消息(带识别中状态) // 先显示语音消息(带识别中状态)
const newId = util.generateId() const newId = util.generateId()
const voiceMessage = { const voiceMessage = {
@ -1974,32 +1974,32 @@ Page({
recognizing: true, recognizing: true,
recognizedText: '' recognizedText: ''
} }
this.setData({ this.setData({
messages: [...this.data.messages, voiceMessage] messages: [...this.data.messages, voiceMessage]
}, () => { }, () => {
this.scrollToBottom() this.scrollToBottom()
}) })
// 进行语音识别 // 进行语音识别
try { try {
wx.showLoading({ title: '语音识别中...' }) wx.showLoading({ title: '语音识别中...' })
const fs = wx.getFileSystemManager() const fs = wx.getFileSystemManager()
const audioData = fs.readFileSync(res.tempFilePath) const audioData = fs.readFileSync(res.tempFilePath)
const audioBase64 = wx.arrayBufferToBase64(audioData) const audioBase64 = wx.arrayBufferToBase64(audioData)
console.log('[chat-detail] 音频文件大小:', audioData.byteLength, 'bytes') console.log('[chat-detail] 音频文件大小:', audioData.byteLength, 'bytes')
console.log('[chat-detail] Base64长度:', audioBase64.length, 'chars') console.log('[chat-detail] Base64长度:', audioBase64.length, 'chars')
console.log('[chat-detail] 开始调用语音识别API...') console.log('[chat-detail] 开始调用语音识别API...')
const recognizeRes = await api.speech.recognize({ const recognizeRes = await api.speech.recognize({
audio: audioBase64, audio: audioBase64,
format: 'mp3' format: 'mp3'
}) })
console.log('[chat-detail] 语音识别响应:', JSON.stringify(recognizeRes).substring(0, 200)) console.log('[chat-detail] 语音识别响应:', JSON.stringify(recognizeRes).substring(0, 200))
wx.hideLoading() wx.hideLoading()
let recognizedText = '' let recognizedText = ''
if (recognizeRes.success && recognizeRes.data && recognizeRes.data.text) { if (recognizeRes.success && recognizeRes.data && recognizeRes.data.text) {
recognizedText = recognizeRes.data.text recognizedText = recognizeRes.data.text
@ -2020,24 +2020,24 @@ Page({
if (recognizedText && recognizedText !== '[语音消息]') { if (recognizedText && recognizedText !== '[语音消息]') {
const canChatByFreeTime = !!(this.data.freeTime && this.data.freeTime.isActive) const canChatByFreeTime = !!(this.data.freeTime && this.data.freeTime.isActive)
const canChatByVip = !!this.data.isVip const canChatByVip = !!this.data.isVip
if (!isUnlocked && !canChatByVip && !canChatByFreeTime) { if (!isUnlocked && !canChatByVip && !canChatByFreeTime) {
console.log('[chat-detail] 语音消息无聊天权限', { isUnlocked, isVip, canChatByFreeTime }) console.log('[chat-detail] 语音消息无聊天权限', { isUnlocked, isVip, canChatByFreeTime })
this.setData({ showUnlockPopup: true }) this.setData({ showUnlockPopup: true })
return return
} }
this.pendingMessages.push(recognizedText) this.pendingMessages.push(recognizedText)
if (!this.messageTimer) { if (!this.messageTimer) {
this.startMessageTimer(characterId, this.data.conversationId, character, isUnlocked, remainingCount) this.startMessageTimer(characterId, this.data.conversationId, character, isUnlocked, remainingCount)
} }
} }
} catch (err) { } catch (err) {
wx.hideLoading() wx.hideLoading()
console.error('[chat-detail] 语音识别失败:', err) console.error('[chat-detail] 语音识别失败:', err)
const messages = this.data.messages.map(msg => { const messages = this.data.messages.map(msg => {
if (msg.id === newId) { if (msg.id === newId) {
return { ...msg, recognizing: false, recognizedText: '[语音消息]' } return { ...msg, recognizing: false, recognizedText: '[语音消息]' }
@ -2053,7 +2053,7 @@ Page({
onVoiceTouchCancel() { onVoiceTouchCancel() {
clearInterval(this.recordingTimer) clearInterval(this.recordingTimer)
this.setData({ isRecording: false }) this.setData({ isRecording: false })
if (this.recorderManager) { if (this.recorderManager) {
this.recorderManager.stop() this.recorderManager.stop()
} }
@ -2064,7 +2064,7 @@ Page({
*/ */
onMessageLongPress(e) { onMessageLongPress(e) {
const item = e.currentTarget.dataset.item const item = e.currentTarget.dataset.item
wx.showActionSheet({ wx.showActionSheet({
itemList: ['复制', '删除'], itemList: ['复制', '删除'],
success: (res) => { success: (res) => {

View File

@ -37,12 +37,12 @@ Page({
// 总未读消息数 // 总未读消息数
totalUnread: 0, totalUnread: 0,
// 加载状态 // 加载状态
loading: true, loading: true,
error: null, error: null,
auditStatus: 0, auditStatus: 0,
// 免费畅聊相关 // 免费畅聊相关
freeTime: null, freeTime: null,
countdownText: '' countdownText: ''
@ -57,14 +57,14 @@ Page({
onShow() { onShow() {
wx.hideTabBar({ animation: false }) wx.hideTabBar({ animation: false })
// 从本地存储读取审核状态 // 从本地存储读取审核状态
const auditStatus = wx.getStorageSync('auditStatus') || 0 const auditStatus = wx.getStorageSync('auditStatus') || 0
this.setData({ auditStatus }) this.setData({ auditStatus })
// 检查免费畅聊时间 // 检查免费畅聊时间
this.checkFreeTime() this.checkFreeTime()
// 每次显示时刷新列表 // 每次显示时刷新列表
// 增加延迟确保标记已读API有时间完成从聊天详情页返回时 // 增加延迟确保标记已读API有时间完成从聊天详情页返回时
if (!this.data.loading) { if (!this.data.loading) {

View File

@ -32,7 +32,7 @@ Page({
const menuButton = wx.getMenuButtonBoundingClientRect() const menuButton = wx.getMenuButtonBoundingClientRect()
const navBarHeight = menuButton.height + (menuButton.top - statusBarHeight) * 2 const navBarHeight = menuButton.height + (menuButton.top - statusBarHeight) * 2
const totalNavHeight = statusBarHeight + navBarHeight const totalNavHeight = statusBarHeight + navBarHeight
this.setData({ this.setData({
statusBarHeight, statusBarHeight,
navBarHeight, navBarHeight,
@ -41,12 +41,12 @@ Page({
// 礼物商城无需登录即可访问 // 礼物商城无需登录即可访问
this.loadGifts() this.loadGifts()
// 检查登录状态并加载爱心值 // 检查登录状态并加载爱心值
const app = getApp() const app = getApp()
const isLoggedIn = app.globalData.isLoggedIn const isLoggedIn = app.globalData.isLoggedIn
this.setData({ isLoggedIn }) this.setData({ isLoggedIn })
if (isLoggedIn) { if (isLoggedIn) {
this.loadLovePoints() this.loadLovePoints()
} }
@ -55,7 +55,7 @@ Page({
onShow() { onShow() {
const app = getApp() const app = getApp()
this.setData({ isLoggedIn: app.globalData.isLoggedIn }) this.setData({ isLoggedIn: app.globalData.isLoggedIn })
// 仅在登录状态下刷新爱心值 // 仅在登录状态下刷新爱心值
if (app.globalData.isLoggedIn) { if (app.globalData.isLoggedIn) {
this.loadLovePoints() this.loadLovePoints()