Compare commits

..

9 Commits

Author SHA1 Message Date
a45b247496 = 职业规划推荐 2026-01-23 15:43:53 +08:00
francis_fh
ebb6bc6e33 bug修复 2026-01-23 13:10:40 +08:00
francis_fh
7bfc765a73 Revert "音频问题解决"
This reverts commit 34cad2543d.
2026-01-23 12:36:27 +08:00
francis_fh
34cad2543d 音频问题解决 2026-01-23 12:34:04 +08:00
francis_fh
134c900946 音频bug修复 2026-01-23 12:12:51 +08:00
francis_fh
5bf94a6223 Merge branch 'main' of http://124.243.245.42:3000/sdz/ks-app-employment-service 2026-01-22 18:58:20 +08:00
francis_fh
b92e3b8adb AI模块联调 2026-01-22 18:58:19 +08:00
xuchao
292b8ae33c 培训评价公告添加审核通过过滤条件 2026-01-22 16:58:19 +08:00
e0efa9c1cf = 职业规划推荐 2026-01-22 16:46:45 +08:00
30 changed files with 1015 additions and 596 deletions

View File

@@ -7,9 +7,19 @@
import request from '@/utilsRc/request'
// 获取技能信息
export function getSkill(query) {
export function getCareerPath(query) {
return request({
url: '/jobSkillDet/getJobSkillWeight',
url: '/jobPath/getJobPathJobList',
method: 'get',
params: query,
baseUrlType: 'zytp'
})
}
// 获取技能信息
export function getSkillResult(query) {
return request({
url: '/jobDimScore/getJobDimScoreList',
method: 'get',
params: query,
baseUrlType: 'zytp'

View File

@@ -72,18 +72,18 @@ export const navTo = function(url, {
const pages = getCurrentPages();
if (pages.length >= 10) {
uni.redirectTo({
url: '/pages/complete-info/complete-info',
url: '/packageA/pages/complete-info/complete-info',
fail: (err) => {
console.error('页面跳转失败:', err);
}
});
} else {
uni.navigateTo({
url: '/pages/complete-info/complete-info',
url: '/packageA/pages/complete-info/complete-info',
fail: (err) => {
console.error('页面跳转失败:', err);
uni.redirectTo({
url: '/pages/complete-info/complete-info',
url: '/packageA/pages/complete-info/complete-info',
fail: (err2) => {
console.error('redirectTo也失败:', err2);
}

View File

@@ -104,7 +104,7 @@ const generateTabbarList = () => {
baseItems.splice(1, 0, {
id: 1,
text: '发布岗位',
path: '/pages/job/publishJob',
path: '/packageA/pages/job/publishJob',
iconPath: '/static/tabbar/post.png',
selectedIconPath: '/static/tabbar/posted.png',
centerItem: false,
@@ -173,7 +173,7 @@ const switchTab = (item, index) => {
// 检查是否为需要登录的页面
const loginRequiredPages = [
'/pages/job/publishJob',
'/packageA/pages/job/publishJob',
'/pages/mine/mine',
'/pages/mine/company-mine'
];
@@ -190,7 +190,7 @@ const switchTab = (item, index) => {
}
// 已登录,处理特定页面的逻辑
if (item.path === '/pages/job/publishJob') {
if (item.path === '/packageA/pages/job/publishJob') {
// 检查企业信息是否完整
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
const storeUserInfo = userInfo.value || {};
@@ -200,12 +200,12 @@ const switchTab = (item, index) => {
if (!currentUserInfo.company || currentUserInfo.company === null) {
// 企业信息为空,跳转到企业信息补全页面
uni.navigateTo({
url: '/pages/complete-info/company-info',
url: '/packageA/pages/complete-info/company-info',
});
} else {
// 企业信息完整,跳转到发布岗位页面
uni.navigateTo({
url: '/pages/job/publishJob',
url: '/packageA/pages/job/publishJob',
});
}

View File

@@ -110,7 +110,7 @@ const generateTabbarList = () => {
baseItems.splice(1, 0, {
id: 1,
text: '发布岗位',
path: '/pages/job/publishJob',
path: '/packageA/pages/job/publishJob',
iconPath: '../../static/tabbar/post.png',
selectedIconPath: '../../static/tabbar/posted.png',
centerItem: false,

View File

@@ -188,12 +188,12 @@ const getPhoneNumber = (e) => {
if (userType.value === 1 && !resData.idCard) {
// 求职者跳转到个人信息补全页面
uni.navigateTo({
url: '/pages/complete-info/complete-info?step=1'
url: '/packageA/pages/complete-info/complete-info?step=1'
});
} else if (userType.value === 0 && !resData.idCard) {
// 招聘者跳转到企业信息补全页面
uni.navigateTo({
url: '/pages/complete-info/company-info'
url: '/packageA/pages/complete-info/company-info'
});
}
}
@@ -271,12 +271,12 @@ const wxLogin = () => {
if (userType.value === 1) {
// 求职者跳转到个人信息补全页面
uni.navigateTo({
url: '/pages/complete-info/complete-info?step=1'
url: '/packageA/pages/complete-info/complete-info?step=1'
});
} else if (userType.value === 0) {
// 招聘者跳转到企业信息补全页面
uni.navigateTo({
url: '/pages/complete-info/company-info'
url: '/packageA/pages/complete-info/company-info'
});
}
}
@@ -325,12 +325,12 @@ const testLogin = () => {
if (userType.value === 1) {
// 求职者跳转到个人信息补全页面
uni.navigateTo({
url: '/pages/complete-info/complete-info?step=1'
url: '/packageA/pages/complete-info/complete-info?step=1'
});
} else if (userType.value === 0) {
// 招聘者跳转到企业信息补全页面
uni.navigateTo({
url: '/pages/complete-info/company-info'
url: '/packageA/pages/complete-info/company-info'
});
}
}

View File

@@ -8,101 +8,428 @@ import {
onHide,
onUnload
} from '@dcloudio/uni-app'
import WavDecoder from '@/lib/wav-decoder@1.3.0.js'
export function useTTSPlayer(wsUrl) {
export function useTTSPlayer(httpUrl) {
const isSpeaking = ref(false)
const isPaused = ref(false)
const isComplete = ref(false)
// #ifdef H5
const audioContext = typeof window !== 'undefined' && (window.AudioContext || window.webkitAudioContext)
? new(window.AudioContext || window.webkitAudioContext)()
: null
// H5环境使用 AudioContext
// 初始化时不立即创建,而是在需要时创建,确保在用户交互后创建
let audioContext = null
// #endif
// #ifdef MP-WEIXIN
const audioContext = null // 微信小程序不支持 AudioContext
let innerAudioContext = null // 微信小程序音频上下文
let backgroundAudioManager = null // 微信小程序背景音频管理器
// #endif
let playTime = audioContext ? audioContext.currentTime : 0
let sourceNodes = []
let socket = null
let sampleRate = 16000
let numChannels = 1
let isHeaderDecoded = false
let pendingText = null
let currentAudioBuffer = null
let currentSource = null
let playTimeOffset = 0
let currentPlayId = 0
let activePlayId = 0
// 初始化微信小程序音频上下文
// #ifdef MP-WEIXIN
const initAudioManager = () => {
try {
console.log('📱 微信小程序:创建背景音频管理器')
backgroundAudioManager = uni.getBackgroundAudioManager()
const speak = (text) => {
// 设置默认配置
backgroundAudioManager.title = 'AI语音播报'
backgroundAudioManager.singer = 'KS AI'
backgroundAudioManager.coverImgUrl = '/static/icon/logo.png'
backgroundAudioManager.volume = 1.0
backgroundAudioManager.onPlay(() => {
console.log('🎵 微信小程序背景音频播放开始')
isSpeaking.value = true
isPaused.value = false
})
backgroundAudioManager.onPause(() => {
console.log('⏸️ 微信小程序背景音频播放暂停')
isPaused.value = true
})
backgroundAudioManager.onStop(() => {
console.log('⏹️ 微信小程序背景音频播放停止')
isSpeaking.value = false
isComplete.value = true
})
backgroundAudioManager.onEnded(() => {
console.log('🎵 微信小程序背景音频播放结束')
isSpeaking.value = false
isComplete.value = true
})
backgroundAudioManager.onError((res) => {
console.error('❌ 微信小程序背景音频播放错误:', res.errMsg, '错误码:', res.errCode)
isSpeaking.value = false
isComplete.value = false
})
backgroundAudioManager.onCanplay(() => {
console.log('🎵 微信小程序背景音频可以播放了')
})
backgroundAudioManager.onWaiting(() => {
console.log('⏳ 微信小程序背景音频加载中...')
})
console.log('✅ 微信小程序背景音频管理器初始化成功')
return true
} catch (e) {
console.error('❌ 微信小程序背景音频管理器初始化失败:', e)
// 降级使用InnerAudioContext
console.log('🔄 微信小程序背景音频不可用降级使用InnerAudioContext')
if (!innerAudioContext) {
innerAudioContext = uni.createInnerAudioContext()
innerAudioContext.autoplay = false
innerAudioContext.obeyMuteSwitch = false
innerAudioContext.onPlay(() => {
console.log('🎵 微信小程序InnerAudioContext播放开始')
isSpeaking.value = true
isPaused.value = false
})
innerAudioContext.onPause(() => {
console.log('⏸️ 微信小程序InnerAudioContext播放暂停')
isPaused.value = true
})
innerAudioContext.onStop(() => {
console.log('⏹️ 微信小程序InnerAudioContext播放停止')
isSpeaking.value = false
isComplete.value = true
})
innerAudioContext.onEnded(() => {
console.log('🎵 微信小程序InnerAudioContext播放结束')
isSpeaking.value = false
isComplete.value = true
})
innerAudioContext.onError((res) => {
console.error('❌ 微信小程序InnerAudioContext错误:', res.errMsg, '错误码:', res.errCode)
isSpeaking.value = false
isComplete.value = false
})
innerAudioContext.onCanplay(() => {
console.log('🎵 微信小程序InnerAudioContext可以播放了')
if (isSpeaking.value && !isPaused.value) {
innerAudioContext.play()
}
})
}
return false
}
}
// #endif
const speak = async (text) => {
// 停止当前播放
stop()
try {
// 提取要合成的文本
const speechText = extractSpeechText(text)
console.log('📤 Sending text to TTS server via GET:', speechText.substring(0, 100) + '...');
// 构建GET请求URL
const url = `${httpUrl}?text=${encodeURIComponent(speechText)}`
console.log('🔗 Final GET URL:', url);
// #ifdef MP-WEIXIN
// 微信小程序环境,使用背景音频管理器
const isBackgroundAudioAvailable = initAudioManager()
// 重置音频状态
isSpeaking.value = true
isPaused.value = false
isComplete.value = false
if (isBackgroundAudioAvailable && backgroundAudioManager) {
console.log('🎵 微信小程序使用背景音频管理器播放URL:', url);
// 设置背景音频参数
backgroundAudioManager.title = 'AI语音播报'
backgroundAudioManager.singer = 'KS AI'
backgroundAudioManager.coverImgUrl = '/static/icon/logo.png'
// 直接设置src并播放
backgroundAudioManager.src = url
console.log('🎵 微信小程序背景音频开始播放');
} else {
// 降级方案使用InnerAudioContext
console.log('🔄 微信小程序背景音频不可用降级使用InnerAudioContext');
// 如果已有音频上下文,先销毁再重新创建
if (innerAudioContext) {
innerAudioContext.destroy()
innerAudioContext = null
}
innerAudioContext = uni.createInnerAudioContext()
innerAudioContext.autoplay = false
innerAudioContext.obeyMuteSwitch = false
innerAudioContext.volume = 1.0
innerAudioContext.onPlay(() => {
console.log('🎵 微信小程序InnerAudioContext播放开始')
isSpeaking.value = true
isPaused.value = false
})
innerAudioContext.onPause(() => {
console.log('⏸️ 微信小程序InnerAudioContext播放暂停')
isPaused.value = true
})
innerAudioContext.onStop(() => {
console.log('⏹️ 微信小程序InnerAudioContext播放停止')
isSpeaking.value = false
isComplete.value = true
})
innerAudioContext.onEnded(() => {
console.log('🎵 微信小程序InnerAudioContext播放结束')
isSpeaking.value = false
isComplete.value = true
})
innerAudioContext.onError((res) => {
console.error('❌ 微信小程序InnerAudioContext错误:', res.errMsg, '错误码:', res.errCode)
isSpeaking.value = false
isComplete.value = false
})
innerAudioContext.onCanplay(() => {
console.log('🎵 微信小程序InnerAudioContext可以播放了')
if (isSpeaking.value && !isPaused.value) {
innerAudioContext.play()
}
})
innerAudioContext.src = url
console.log('🎵 微信小程序InnerAudioContext开始播放');
}
// #endif
// #ifdef H5
// H5环境使用 AudioContext
try {
// 确保AudioContext已创建
if (!audioContext) {
console.warn('⚠️ TTS not supported in current environment');
return;
console.log('🎵 H5: 创建新的AudioContext');
audioContext = new (window.AudioContext || window.webkitAudioContext)();
}
console.log('🎤 TTS speak function called');
console.log('📝 Text to synthesize:', text ? text.substring(0, 100) + '...' : 'No text');
console.log('🔗 WebSocket URL:', wsUrl);
currentPlayId++
const myPlayId = currentPlayId
console.log('🆔 Play ID:', myPlayId);
reset()
pendingText = text
activePlayId = myPlayId
console.log('✅ Speak function setup complete');
// 检查并恢复AudioContext状态浏览器安全策略要求用户交互后才能播放音频
if (audioContext.state === 'suspended') {
console.log('🎵 H5: 恢复挂起的AudioContext');
await audioContext.resume();
console.log('✅ H5: AudioContext已恢复状态:', audioContext.state);
}
// 发送GET请求获取语音数据
const response = await fetch(url)
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
// 获取二进制数据
const arrayBuffer = await response.arrayBuffer()
console.log('✅ H5: Received audio data, size:', arrayBuffer.byteLength + ' bytes');
try {
// 直接使用 audioContext.decodeAudioData 解码,不依赖外部库
const decoded = await audioContext.decodeAudioData(arrayBuffer)
console.log('✅ H5: Audio decoded, sampleRate:', decoded.sampleRate, 'channels:', decoded.numberOfChannels);
// 播放音频
playDecodedAudio(decoded)
} catch (decodeError) {
console.error('❌ H5: AudioContext decodeAudioData failed:', decodeError);
// 降级处理:创建一个简单的音频缓冲区
createFallbackAudio(arrayBuffer)
}
} catch (h5Error) {
console.error('❌ H5: Audio playback failed:', h5Error);
// 尝试使用HTML5 Audio元素作为最终降级方案
try {
console.log('🔄 H5: 尝试使用HTML5 Audio元素播放');
const audio = new Audio(url);
audio.play();
console.log('✅ H5: HTML5 Audio元素开始播放');
// 设置音频状态
isSpeaking.value = true;
isPaused.value = false;
isComplete.value = false;
// 监听播放结束
audio.onended = () => {
console.log('🎵 H5: HTML5 Audio播放结束');
isSpeaking.value = false;
isComplete.value = true;
};
// 监听播放错误
audio.onerror = (error) => {
console.error('❌ H5: HTML5 Audio播放错误:', error);
isSpeaking.value = false;
isComplete.value = false;
};
} catch (audioError) {
console.error('❌ H5: HTML5 Audio播放也失败了:', audioError);
isSpeaking.value = false;
isComplete.value = false;
}
}
// #endif
} catch (error) {
console.error('❌ TTS synthesis failed:', error);
isSpeaking.value = false
isComplete.value = false
}
}
// #ifdef H5
const playDecodedAudio = (decoded) => {
if (!audioContext) return;
// 创建音频源
currentSource = audioContext.createBufferSource()
currentSource.buffer = decoded
currentSource.connect(audioContext.destination)
// 监听播放结束
currentSource.onended = () => {
console.log('🎵 Audio playback completed');
isSpeaking.value = false
isComplete.value = true
}
// 开始播放
currentSource.start()
isSpeaking.value = true
isPaused.value = false
isComplete.value = false
console.log('🎵 Audio playback started');
}
// 降级处理:创建一个简单的音频缓冲区
const createFallbackAudio = (arrayBuffer) => {
console.log('🔄 使用降级方案创建音频');
// 创建一个简单的音频缓冲区,生成提示音
const sampleRate = 44100
const duration = 1 // 1秒
const frameCount = sampleRate * duration
const audioBuffer = audioContext.createBuffer(1, frameCount, sampleRate)
const channelData = audioBuffer.getChannelData(0)
// 生成一个简单的提示音(正弦波)
for (let i = 0; i < frameCount; i++) {
const t = i / sampleRate
channelData[i] = Math.sin(2 * Math.PI * 440 * t) * 0.1 // 440Hz正弦波音量0.1
}
playDecodedAudio(audioBuffer)
}
// #endif
const pause = () => {
if (!audioContext) {
console.warn('⚠️ TTS not supported in current environment');
return;
console.log('⏸️ TTS pause called');
// #ifdef MP-WEIXIN
// 优先使用背景音频管理器
if (backgroundAudioManager) {
try {
backgroundAudioManager.pause()
console.log('⏸️ 微信小程序背景音频暂停');
return
} catch (e) {
console.error('❌ 微信小程序背景音频暂停失败:', e);
}
}
console.log('⏸️ TTS pause called');
console.log('🔊 AudioContext state:', audioContext.state);
console.log('🔊 Is speaking before pause:', isSpeaking.value);
console.log('⏸️ Is paused before pause:', isPaused.value);
// 降级使用InnerAudioContext
if (innerAudioContext && isSpeaking.value && !isPaused.value) {
try {
innerAudioContext.pause()
console.log('⏸️ 微信小程序InnerAudioContext暂停');
return
} catch (e) {
console.error('❌ 微信小程序InnerAudioContext暂停失败:', e);
}
}
// #endif
// #ifdef H5
if (audioContext && !isSpeaking.value || isPaused.value) {
console.warn('⚠️ Cannot pause TTS playback');
return;
}
if (audioContext.state === 'running') {
audioContext.suspend()
isPaused.value = true
// 不要设置 isSpeaking.value = false保持当前状态
console.log('✅ Audio paused successfully');
} else {
console.log('⚠️ AudioContext is not running, cannot pause');
// 保存当前播放位置
playTimeOffset = audioContext.currentTime
console.log('✅ H5 Audio paused successfully');
}
console.log('🔊 Is speaking after pause:', isSpeaking.value);
console.log('⏸️ Is paused after pause:', isPaused.value);
// #endif
}
const resume = () => {
if (!audioContext) {
console.warn('⚠️ TTS not supported in current environment');
return;
console.log('▶️ TTS resume called');
// #ifdef MP-WEIXIN
// 优先使用背景音频管理器
if (backgroundAudioManager) {
try {
backgroundAudioManager.play()
console.log('▶️ 微信小程序背景音频恢复播放');
return
} catch (e) {
console.error('❌ 微信小程序背景音频恢复失败:', e);
}
}
console.log('▶️ TTS resume called');
console.log('🔊 AudioContext state:', audioContext.state);
console.log('🔊 Is speaking before resume:', isSpeaking.value);
console.log('⏸️ Is paused before resume:', isPaused.value);
// 降级使用InnerAudioContext
if (innerAudioContext && isSpeaking.value && isPaused.value) {
try {
innerAudioContext.play()
console.log('▶️ 微信小程序InnerAudioContext恢复播放');
return
} catch (e) {
console.error('❌ 微信小程序InnerAudioContext恢复失败:', e);
}
}
// #endif
// #ifdef H5
if (audioContext && !isSpeaking.value || !isPaused.value) {
console.warn('⚠️ Cannot resume TTS playback');
return;
}
if (audioContext.state === 'suspended') {
audioContext.resume()
isPaused.value = false
isSpeaking.value = true
console.log('✅ Audio resumed successfully');
} else {
console.log('⚠️ AudioContext is not suspended, cannot resume');
console.log('✅ H5 Audio resumed successfully');
}
console.log('🔊 Is speaking after resume:', isSpeaking.value);
console.log('⏸️ Is paused after resume:', isPaused.value);
// #endif
}
const cancelAudio = () => {
@@ -110,165 +437,59 @@ export function useTTSPlayer(wsUrl) {
}
const stop = () => {
isSpeaking.value = false
isPaused.value = false
isComplete.value = false
playTime = audioContext ? audioContext.currentTime : 0
console.log('⏹️ TTS stop called');
sourceNodes.forEach(node => {
// #ifdef MP-WEIXIN
// 优先使用背景音频管理器
if (backgroundAudioManager) {
try {
node.stop()
node.disconnect()
} catch (e) {}
})
sourceNodes = []
if (socket) {
socket.close()
socket = null
}
isHeaderDecoded = false
pendingText = null
}
const reset = () => {
stop()
isSpeaking.value = false
isPaused.value = false
isComplete.value = false
playTime = audioContext ? audioContext.currentTime : 0
initWebSocket()
}
const initWebSocket = () => {
if (!audioContext) {
console.warn('⚠️ WebSocket TTS not supported in current environment');
return;
}
const thisPlayId = currentPlayId
console.log('🔌 Initializing WebSocket connection');
console.log('🔗 WebSocket URL:', wsUrl);
console.log('🆔 This play ID:', thisPlayId);
socket = new WebSocket(wsUrl)
socket.binaryType = 'arraybuffer'
// 设置心跳检测,避免超时
const heartbeatInterval = setInterval(() => {
if (socket && socket.readyState === WebSocket.OPEN) {
socket.send(JSON.stringify({ type: 'ping' }));
}
}, 30000); // 每30秒发送一次心跳
socket.onopen = () => {
console.log('✅ WebSocket connection opened');
if (pendingText && thisPlayId === activePlayId) {
const seepdText = extractSpeechText(pendingText)
console.log('📤 Sending text to TTS server:', seepdText.substring(0, 100) + '...');
socket.send(seepdText)
pendingText = null
} else {
console.log('❌ No pending text or play ID mismatch');
console.log('📝 Pending text exists:', !!pendingText);
console.log('🆔 Play ID match:', thisPlayId === activePlayId);
}
}
socket.onerror = (error) => {
console.error('❌ WebSocket error:', error);
}
socket.onclose = (event) => {
console.log('🔌 WebSocket connection closed:', event.code, event.reason);
clearInterval(heartbeatInterval);
}
socket.onmessage = async (e) => {
if (thisPlayId !== activePlayId) return // 忽略旧播放的消息
if (typeof e.data === 'string') {
try {
const msg = JSON.parse(e.data)
console.log('📨 TTS server message:', msg);
if (msg.status === 'complete') {
console.log('✅ TTS synthesis completed');
isComplete.value = true
// 计算剩余播放时间,确保播放完整
const remainingTime = audioContext ? Math.max(0, (playTime - audioContext.currentTime) * 1000) : 0;
console.log('⏱️ Remaining play time:', remainingTime + 'ms');
setTimeout(() => {
if (thisPlayId === activePlayId) {
console.log('🔇 TTS playback finished, setting isSpeaking to false');
isSpeaking.value = false
}
}, remainingTime + 500) // 额外500ms缓冲时间
}
backgroundAudioManager.stop()
console.log('✅ 微信小程序背景音频停止');
} catch (e) {
console.log('[TTSPlayer] 文本消息:', e.data)
console.error('❌ 微信小程序背景音频停止失败:', e);
}
} else if (e.data instanceof ArrayBuffer) {
if (!isHeaderDecoded) {
}
// 降级使用InnerAudioContext
if (innerAudioContext) {
try {
const decoded = await WavDecoder.decode(e.data)
sampleRate = decoded.sampleRate
numChannels = decoded.channelData.length
decoded.channelData.forEach((channel, i) => {
const audioBuffer = audioContext.createBuffer(1, channel.length,
sampleRate)
audioBuffer.copyToChannel(channel, 0)
playBuffer(audioBuffer)
})
isHeaderDecoded = true
} catch (err) {
console.error('WAV 解码失败:', err)
}
} else {
const pcm = new Int16Array(e.data)
const audioBuffer = pcmToAudioBuffer(pcm, sampleRate, numChannels)
playBuffer(audioBuffer)
innerAudioContext.stop()
console.log('✅ 微信小程序InnerAudioContext停止');
innerAudioContext.destroy()
innerAudioContext = null
} catch (e) {
console.error('❌ 微信小程序InnerAudioContext停止错误:', e);
}
}
// #endif
// #ifdef H5
if (currentSource) {
try {
currentSource.stop()
currentSource.disconnect()
} catch (e) {
console.error('❌ Error stopping H5 audio source:', e);
}
currentSource = null
}
const pcmToAudioBuffer = (pcm, sampleRate, numChannels) => {
if (!audioContext) return null;
if (audioContext && audioContext.state === 'running') {
try {
audioContext.suspend()
} catch (e) {
console.error('❌ Error suspending H5 audio context:', e);
}
}
// #endif
const length = pcm.length / numChannels
const audioBuffer = audioContext.createBuffer(numChannels, length, sampleRate)
for (let ch = 0; ch < numChannels; ch++) {
const channelData = audioBuffer.getChannelData(ch)
for (let i = 0; i < length; i++) {
const sample = pcm[i * numChannels + ch]
channelData[i] = sample / 32768
}
}
return audioBuffer
}
isSpeaking.value = false
isPaused.value = false
isComplete.value = false
currentAudioBuffer = null
playTimeOffset = 0
const playBuffer = (audioBuffer) => {
if (!audioContext || !audioBuffer) return;
console.log('🎵 playBuffer called, duration:', audioBuffer.duration + 's');
if (!isSpeaking.value) {
playTime = audioContext.currentTime
console.log('🎵 Starting new audio playback at time:', playTime);
}
const source = audioContext.createBufferSource()
source.buffer = audioBuffer
source.connect(audioContext.destination)
source.start(playTime)
sourceNodes.push(source)
playTime += audioBuffer.duration
isSpeaking.value = true
console.log('🎵 Audio scheduled, new playTime:', playTime);
// 添加音频播放结束监听
source.onended = () => {
console.log('🎵 Audio buffer finished playing');
}
console.log('✅ TTS playback stopped');
}
onUnmounted(() => {

16
main.js
View File

@@ -14,15 +14,7 @@ import AppLayout from './components/AppLayout/AppLayout.vue';
import Empty from './components/empty/empty.vue';
import NoBouncePage from '@/components/NoBouncePage/NoBouncePage.vue'
import MsgTips from '@/components/MsgTips/MsgTips.vue'
import SelectPopup from '@/components/selectPopup/selectPopup.vue'
import SelectPopupPlugin from '@/components/selectPopup/selectPopupPlugin';
import RenderJobs from '@/components/renderJobs/renderJobs.vue';
import RenderCompanys from '@/components/renderCompanys/renderCompanys.vue';
import uniIcons from './uni_modules/uni-icons/components/uni-icons/uni-icons.vue'
import uniPopup from './uni_modules/uni-popup/components/uni-popup/uni-popup.vue'
import uniDataSelect from './uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue'
import uniSwipeAction from './uni_modules/uni-swipe-action/components/uni-swipe-action/uni-swipe-action.vue'
import uniSwipeActionItem from './uni_modules/uni-swipe-action/components/uni-swipe-action-item/uni-swipe-action-item.vue'
import storeRc from './utilsRc/store/index.js'
import {processFileUrl,} from '@/utilsRc/common.js'
// iconfont.css 已在 App.vue 中通过 @import 引入,无需在此处重复引入
@@ -48,14 +40,6 @@ export function createApp() {
app.component('Empty', Empty)
app.component('NoBouncePage', NoBouncePage)
app.component('MsgTips', MsgTips)
app.component('SelectPopup', SelectPopup)
app.component('RenderJobs', RenderJobs)
app.component('RenderCompanys', RenderCompanys)
app.component('uni-icons', uniIcons)
app.component('uni-popup', uniPopup)
app.component('uni-data-select', uniDataSelect)
app.component('uni-swipe-action', uniSwipeAction)
app.component('uni-swipe-action-item', uniSwipeActionItem)
app.config.globalProperties.$processFileUrl = processFileUrl;

View File

@@ -364,7 +364,7 @@ const changeSkillName = (index) => {
state.currentEditingSkillIndex = index;
//
uni.navigateTo({
url: `/pages/complete-info/skill-search?selected=${encodeURIComponent(JSON.stringify([]))}`
url: `/packageA/pages/complete-info/skill-search?selected=${encodeURIComponent(JSON.stringify([]))}`
});
};

View File

@@ -472,7 +472,7 @@ function changeSkillName(index) {
// 将当前已选中的技能名称传递给查询页面
const selectedSkills = state.skills.map(skill => skill.name).filter(name => name);
uni.navigateTo({
url: `/pages/complete-info/skill-search?selected=${encodeURIComponent(JSON.stringify(selectedSkills))}`
url: `/packageA/pages/complete-info/skill-search?selected=${encodeURIComponent(JSON.stringify(selectedSkills))}`
});
}

View File

@@ -81,7 +81,8 @@ function getPolicyData(type = 'add',currentTab='train') {
params={
pageSize:pageSize.value,
pageNum:pageNum.value,
type:current.value
type:current.value,
shenhe: '1',
}
$api.myRequest('/train/public/announcement/list', params).then((resData) => {
if(resData.code==200){
@@ -99,7 +100,8 @@ function getPolicyData(type = 'add',currentTab='train') {
params={
pageSize:pageSize.value,
pageNum:pageNum.value,
type:current.value
type:current.value,
shenhe: '1',
}
$api.myRequest('/train/public/announcement/list', params).then((resData) => {
if(resData.code==200){

View File

@@ -70,7 +70,7 @@
</view>
<view class="company-grid">
<view class="company-item press-button" @click="navTo('/pages/job/publishJob')">
<view class="company-item press-button" @click="navTo('/packageA/pages/job/publishJob')">
<view class="company-icon company-icon-1">
<uni-icons type="plus-filled" size="32" color="#FFFFFF"></uni-icons>
</view>
@@ -731,7 +731,7 @@ const handleLoginSuccess = () => {
// 处理附近工作点击
const handleNearbyClick = () => {
if (checkLogin()) {
navTo("/pages/nearby/nearby");
navTo("/packageA/pages/nearby/nearby");
}
};

View File

@@ -31,50 +31,9 @@
}
},
{
"path": "pages/complete-info/complete-info",
"path": "pages/search/search",
"style": {
"navigationBarTitleText": "补全信息"
}
},
{
"path": "pages/complete-info/company-info",
"style": {
"navigationBarTitleText": "企业信息"
}
},
{
"path": "pages/complete-info/components/map-location-picker",
"style": {
"navigationBarTitleText": "选择地址"
}
},
{
"path": "pages/complete-info/skill-search",
"style": {
"navigationBarTitleText": "技能查询"
}
},
{
"path": "pages/nearby/nearby",
"style": {
"navigationBarTitleText": "附近",
"navigationBarBackgroundColor": "#4778EC",
"navigationBarTextStyle": "white"
}
},
{
"path": "pages/job/publishJob",
"style": {
"navigationBarTitleText": "发布岗位"
}
},
{
"path": "pages/job/companySearch",
"style": {
"navigationBarTitleText": "选择企业",
"disableScroll": false,
"enablePullDownRefresh": false,
"backgroundColor": "#f5f5f5"
"navigationBarTitleText": "搜索职位"
}
},
{
@@ -86,12 +45,6 @@
"enablePullDownRefresh": false
}
},
{
"path": "pages/search/search",
"style": {
"navigationBarTitleText": "搜索职位"
}
},
{
"path": "pages/service/career-planning",
"style": {
@@ -161,6 +114,53 @@
{
"root": "packageA",
"pages": [
{
"path": "pages/complete-info/complete-info",
"style": {
"navigationBarTitleText": "补全信息"
}
},
{
"path": "pages/complete-info/company-info",
"style": {
"navigationBarTitleText": "企业信息"
}
},
{
"path": "pages/complete-info/components/map-location-picker",
"style": {
"navigationBarTitleText": "选择地址"
}
},
{
"path": "pages/complete-info/skill-search",
"style": {
"navigationBarTitleText": "技能查询"
}
},
{
"path": "pages/nearby/nearby",
"style": {
"navigationBarTitleText": "附近",
"navigationBarBackgroundColor": "#4778EC",
"navigationBarTextStyle": "white"
}
},
{
"path": "pages/job/publishJob",
"style": {
"navigationBarTitleText": "发布岗位"
}
},
{
"path": "pages/job/companySearch",
"style": {
"navigationBarTitleText": "选择企业",
"disableScroll": false,
"enablePullDownRefresh": false,
"backgroundColor": "#f5f5f5"
}
},
{
"path": "pages/addWorkExperience/addWorkExperience",
"style": {

View File

@@ -135,14 +135,14 @@
</view>
<view v-if="isTyping" class="self">
<view class="message msg-loading">
<div class="loading-content">
<span class="ai-loading">
<span></span>
<span></span>
<span></span>
</span>
<view class="loading-content">
<view class="ai-loading">
<view></view>
<view></view>
<view></view>
</view>
<text class="loading-text">AI正在思考中...</text>
</div>
</view>
</view>
</view>
</view>
@@ -283,7 +283,7 @@ import {
getCurrentInstance,
} from 'vue';
import { storeToRefs } from 'pinia';
// import config from '@/config.js';
// 移除重复导入使用从globalFunction注入的config
import useChatGroupDBStore from '@/stores/userChatGroupStore';
import MdRender from '@/components/md-render/md-render.vue';
import CollapseTransition from '@/components/CollapseTransition/CollapseTransition.vue';
@@ -1299,7 +1299,7 @@ image-margin-top = 40rpx
}
/* 三个点的样式 - 使用标准CSS语法不使用嵌套 */
.ai-loading span {
.ai-loading view {
display: inline-block;
width: 12rpx;
height: 12rpx;
@@ -1311,15 +1311,15 @@ image-margin-top = 40rpx
}
/* 为每个点设置不同的动画延迟 */
.ai-loading span:nth-child(1) {
.ai-loading view:nth-child(1) {
animation-delay: -0.32s;
}
.ai-loading span:nth-child(2) {
.ai-loading view:nth-child(2) {
animation-delay: -0.16s;
}
.ai-loading span:nth-child(3) {
.ai-loading view:nth-child(3) {
animation-delay: 0s;
}
</style>

View File

@@ -197,7 +197,7 @@
</view>
<view class="company-grid">
<view class="company-item press-button" @click="navTo('/pages/job/publishJob')">
<view class="company-item press-button" @click="navTo('/packageA/pages/job/publishJob')">
<view class="company-icon company-icon-1">
<uni-icons type="plus-filled" size="32" color="#FFFFFF"></uni-icons>
</view>
@@ -744,7 +744,7 @@ onMounted(() => {
console.log('收到citySelected事件选择的城市:', city);
selectedCity.value = city;
// 可以在这里添加根据城市筛选职位的逻辑
conditionSearch.value.jobLocationAreaCode = city.code;
conditionSearch.value.regionCode = city.code;
getJobRecommend('refresh');
});
@@ -807,13 +807,13 @@ onLoad(() => {
const handleNearbyClick = (options ) => {
// #ifdef MP-WEIXIN
if (checkLogin()) {
navTo('/pages/nearby/nearby');
navTo('/packageA/pages/nearby/nearby');
}
// #endif
// #ifdef H5
const token = options.token || uni.getStorageSync('zkr-token');
if (token) {
navTo('/pages/nearby/nearby');
navTo('/packageA/pages/nearby/nearby');
}
// #endif
};

View File

@@ -201,7 +201,7 @@ function seeDetail() {
function goToJobHelper() {
// 跳转到求职者信息补全页面
navTo('/pages/complete-info/complete-info');
navTo('/packageA/pages/complete-info/complete-info');
}
// 跳转到素质测评
function goCa(){

View File

@@ -43,31 +43,49 @@ const store = useSkillDevelopmentStore();
</button>
</div>
</div>
<div class="content-section career-section">
<div class="section-title">
<span class="title-text">职业路径</span>
</div>
<div class="">
<scroll-view scroll-x>
<div class="career-paths">
<template v-for="(item, index) in store.careerPaths" :key="item.label">
<div
:class="{ 'career-active': store.currentCareer && store.currentCareer.value === item.value }"
class="career-path-item"
@click="store.eventResult(item)"
>
<div
class="career-index"
:class="[index === 0 ? 'font-size-18' : 'font-size-24']"
>
{{ index === 0 ? '起点' : index }}
</div>
<div class="career-label">{{ item.label }}</div>
</div>
</template>
</div>
</scroll-view>
</div>
</div>
<div class="content-section">
<div class="section-title">
<uni-icons color="#000000" size="18" type="person-filled"></uni-icons>
<span class="title-text">技能发展路径</span>
<span class="title-text">{{ store.currentCareerLabel }}技能</span>
</div>
<div class="intro-text">
基于您的当前职业和目标职业,以下是您需要重点发展的技能:
</div>
<div class="skill-list">
<div v-if="store.result.length === 0" class="empty-text">暂无数据</div>
<div v-for="(skill, index) in store.result" v-else :key="index" class="skill-item">
<div class="skill-header">
<span class="skill-name">{{ skill.name }}</span>
<div class="skill-info">
<span class="skill-score">技能分数: {{ skill.score }}</span>
<span class="skill-weight">权重: {{ skill.weight }}</span>
<div v-for="(item, index) in store.result" :key="index" class="font-weight-700 font-size-18 skill-card">
<div class="margin-bottom-10 skill-label">{{ item.label }}</div>
<div class="d-flex flex-column gap-15 skill-detail">
<div v-for="d in item.children" :key="d.label" class="d-flex justify-content-between align-items-center padding-10 border-radius-3 skill-detail-item">
<div class="skill-detail-item-label">{{ d.label }}</div>
<div class="d-flex justify-content-between align-items-center width-320">
<div>技能得分{{ d.value }}</div>
<div>权重{{ d.weight }}</div>
</div>
</div>
<div v-if="skill.tags && skill.tags.length > 0" class="skill-tags">
<div v-for="(tag, tagIndex) in skill.tags" :key="tagIndex" class="skill-tag">
{{ tag }}
</div>
</div>
</div>
</div>
@@ -190,73 +208,96 @@ button::after {
position: relative;
}
.skill-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16rpx;
width: 100%;
box-sizing: border-box;
.career-paths {
grid-auto-flow: column;
.career-index {
background: #6c64e7;
border: 3px solid #fff;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
}
.career-label {
color: #6c64e7;
}
.career-active {
.career-index {
background: #22c55e;
}
.career-label {
color: #000;
}
}
}
.skill-name {
font-size: 32rpx;
line-height: 46rpx;
color: rgb(16, 16, 16);
text-align: left;
font-family: 'PingFangSC-Bold', 'PingFang SC', 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', sans-serif;
font-weight: 600;
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
.skill-label {
color: #94a3b8;
}
.skill-info {
display: flex;
align-items: center;
gap: 12rpx;
flex-shrink: 0;
margin-left: 16rpx;
.skill-detail-item {
background: #c1d2ea;
}
.skill-score {
font-size: 24rpx;
line-height: 34rpx;
border-radius: 10rpx;
background-color: rgba(49, 100, 239, 0.1);
color: rgba(44, 101, 247, 1);
text-align: center;
padding: 6rpx 12rpx;
white-space: nowrap;
.skill-detail-item-label {
color: #334155;
& + div {
color: #4f46e5;
}
}
</style>
<style lang="scss" scoped>
.career-paths {
display: grid;
grid-auto-flow: column;
gap: 40px;
width: fit-content;
padding-bottom: 10px;
.career-path-item {
display: flex;
flex-direction: column;
align-items: center;
padding: 5px;
font-weight: 700;
cursor: pointer;
}
.career-index {
display: flex;
justify-content: center;
align-items: center;
width: 64px;
height: 64px;
background: #6c64e7;
border: 3px solid #fff;
font-size: 18px;
color: #fff;
border-radius: 50%;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
}
.career-label {
margin-top: 10px;
text-wrap: nowrap;
color: #6c64e7;
}
.career-active {
.career-index {
background: #22c55e;
}
.career-label {
color: #000;
}
}
}
.skill-weight {
font-size: 24rpx;
line-height: 34rpx;
border-radius: 10rpx;
background-color: rgba(49, 100, 239, 0.1);
color: rgba(44, 101, 247, 1);
text-align: center;
padding: 6rpx 12rpx;
white-space: nowrap;
}
.skill-tags {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
}
.skill-tag {
background-color: rgba(49, 100, 239, 0.1);
color: rgba(44, 101, 247, 1);
padding: 6rpx 12rpx;
border-radius: 8rpx;
font-size: 24rpx;
line-height: 34rpx;
text-align: center;
white-space: nowrap;
}
</style>

View File

@@ -71,7 +71,10 @@ export const useCareerPathStore = defineStore('career-path', () => {
try {
const { code, msg, data } = await getCurrentPosition();
if (code !== 0) {
$emitter.emit('error-message', msg);
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (!data) {
@@ -92,7 +95,10 @@ export const useCareerPathStore = defineStore('career-path', () => {
try {
const { code, msg, data } = await getPath();
if (code !== 0) {
$emitter.emit('error-message', msg);
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (!data) {
@@ -122,7 +128,10 @@ export const useCareerPathStore = defineStore('career-path', () => {
try {
const { code, msg, data } = await getPathDetail(params);
if (code !== 0) {
$emitter.emit('error-message', msg);
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (!data) {
@@ -143,23 +152,23 @@ export const useCareerPathStore = defineStore('career-path', () => {
const eventSearch = () => {
if (pathsRef.value.length === 0) {
ElMessage.warning({
message: '当前职业暂无发展路径,敬请期待!',
duration: 5000
uni.showToast({
title: '当前职业暂无发展路径,敬请期待!',
icon: 'none'
});
return;
}
if (!profession.value) {
ElMessage.warning({
message: '请选择当前职位!',
duration: 5000
uni.showToast({
title: '请选择当前职位!',
icon: 'none'
});
return;
}
if (!targetCareer.value) {
ElMessage.warning({
message: '请选择目标职业!',
duration: 5000
uni.showToast({
title: '请选择目标职业!',
icon: 'none'
});
return;
}

View File

@@ -69,7 +69,10 @@ export const useCareerRecommendationStore = defineStore('career-recommendation',
try {
const { code, msg, data } = await getProfessions();
if (code !== 0) {
$emitter.emit('error-message', msg);
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (!data) {
@@ -93,7 +96,10 @@ export const useCareerRecommendationStore = defineStore('career-recommendation',
try {
const { code, msg, data } = await getSkillTags(params);
if (code !== 0) {
$emitter.emit('error-message', msg);
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (typeof data !== 'undefined' && Array.isArray(data) && data.length > 0 && data[ 0 ]) {
@@ -111,7 +117,10 @@ export const useCareerRecommendationStore = defineStore('career-recommendation',
try {
const { code, msg, data } = await getRecommend(params);
if (code !== 0) {
$emitter.emit('error-message', msg);
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (!data) {

View File

@@ -1,7 +1,7 @@
import { computed, ref, watch } from 'vue';
import { defineStore } from 'pinia';
import { getCurrentPosition, getPath } from '@/apiRc/service/careerPath';
import { getSkill } from '@/apiRc/service/skillDevelopment';
import { getCareerPath, getSkillResult } from '@/apiRc/service/skillDevelopment';
export const useSkillDevelopmentStore = defineStore('skill-development', () => {
@@ -66,13 +66,25 @@ export const useSkillDevelopmentStore = defineStore('skill-development', () => {
});
});
const careerPaths = ref([]);
const currentCareer = ref(null);
const currentCareerLabel = computed(() => {
if (!currentCareer.value) {
return '';
}
return currentCareer.value.label;
});
const result = ref([]);
const fetchData = async () => {
try {
const { code, msg, data } = await getCurrentPosition();
if (code !== 0) {
$emitter.emit('error-message', msg);
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (!data) {
@@ -93,7 +105,10 @@ export const useSkillDevelopmentStore = defineStore('skill-development', () => {
try {
const { code, msg, data } = await getPath();
if (code !== 0) {
$emitter.emit('error-message', msg);
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (!data) {
@@ -111,39 +126,72 @@ export const useSkillDevelopmentStore = defineStore('skill-development', () => {
}
};
const fetchResult = async () => {
const fetchCareerPaths = async () => {
if (!targetCareer.value) {
return;
}
const current = professionsRef.value.find((d) => d.value === profession.value);
const target = pathsRef.value.find((d) => d.value === targetCareer.value);
if (!current || !target) {
return;
}
const [startJobId, endJobId] = targetCareer.value.split('-');
const params = {
currentJobName: current.label,
targetJobName: target.label
startJobId,
endJobId
};
try {
const { code, msg, data } = await getSkill(params);
const { code, msg, data } = await getCareerPath(params);
if (code !== 0) {
$emitter.emit('error-message', msg);
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (typeof data !== 'undefined' && Array.isArray(data) && data.length > 0 && data[ 0 ]) {
const excludes = data[ 0 ].currentSkillDetList.map((d) => d.skillId);
result.value = data[ 0 ].targetSkillDetList
.filter((d) => !excludes.includes(d.skillId))
.map((d) => {
if (!data) {
return;
}
careerPaths.value = data.map((d) => {
return {
type: d.skillType,
title: d.skillName,
name: d.skillName,
weight: d.skillWeight,
score: d.skillScore
label: d.name,
value: d.jobId
};
});
if (careerPaths.value[0]) {
void eventResult(careerPaths.value[0]);
}
} catch (e) {
console.warn(e);
careerPaths.value = [];
}
};
const eventResult = async (path) => {
currentCareer.value = path;
const params = {
jobId: path.value
};
try {
const { code, msg, data } = await $AxiosHttp.useAxiosRequest(getSkillResult, params);
if (code !== 0) {
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (!data) {
return;
}
result.value = data.map((d) => {
return {
label: d.secDimName,
value: d.secDimId,
children: d.skillDetList.map((d) => {
return {
label: d.skillName,
value: d.skillScore,
weight: d.skillWeight
};
})
};
});
} catch (e) {
console.warn(e);
}
@@ -151,27 +199,27 @@ export const useSkillDevelopmentStore = defineStore('skill-development', () => {
const eventSearch = () => {
if (pathsRef.value.length === 0) {
ElMessage.warning({
message: '当前职业暂无发展路径,敬请期待!',
duration: 5000
uni.showToast({
title: '当前职业暂无发展路径,敬请期待!',
icon: 'none'
});
return;
}
if (!profession.value) {
ElMessage.warning({
message: '请选择当前职位!',
duration: 5000
uni.showToast({
title: '请选择当前职位!',
icon: 'none'
});
return;
}
if (!targetCareer.value) {
ElMessage.warning({
message: '请选择目标职业!',
duration: 5000
uni.showToast({
title: '请选择目标职业!',
icon: 'none'
});
return;
}
void fetchResult();
void fetchCareerPaths();
};
const eventProfession = (e) => {
@@ -181,6 +229,7 @@ export const useSkillDevelopmentStore = defineStore('skill-development', () => {
professionLabel.value = item.label;
targetCareer.value = '';
targetCareerLabel.value = '';
careerPaths.value = [];
result.value = [];
};
@@ -189,6 +238,7 @@ export const useSkillDevelopmentStore = defineStore('skill-development', () => {
const item = pathsRef.value[ e.detail.value ];
targetCareer.value = item.value;
targetCareerLabel.value = item.label;
careerPaths.value = [];
result.value = [];
};
@@ -214,9 +264,13 @@ export const useSkillDevelopmentStore = defineStore('skill-development', () => {
targetCareer,
targetCareerLabel,
pathsRef,
careerPaths,
currentCareer,
currentCareerLabel,
result,
eventProfession,
eventTargetCareer,
eventSearch
eventSearch,
eventResult
};
});

View File

@@ -51,11 +51,100 @@ function StreamRequestMiniProgram(url, data = {}, onDataReceived, onError, onCom
}
});
// UTF-8解码函数用于微信小程序真机环境
function utf8Decode(uint8Array) {
let result = '';
let i = 0;
const len = uint8Array.length;
while (i < len) {
const byte1 = uint8Array[i];
// 1字节字符 (0xxxxxxx)
if (byte1 < 0x80) {
result += String.fromCharCode(byte1);
i++;
}
// 2字节字符 (110xxxxx 10xxxxxx)
else if (byte1 >= 0xC0 && byte1 < 0xE0) {
if (i + 1 < len) {
const byte2 = uint8Array[i + 1];
if (byte2 >= 0x80 && byte2 < 0xC0) {
const codePoint = ((byte1 & 0x1F) << 6) | (byte2 & 0x3F);
result += String.fromCharCode(codePoint);
i += 2;
continue;
}
}
// 无效的UTF-8序列跳过
result += '<27>';
i++;
}
// 3字节字符 (1110xxxx 10xxxxxx 10xxxxxx)
else if (byte1 >= 0xE0 && byte1 < 0xF0) {
if (i + 2 < len) {
const byte2 = uint8Array[i + 1];
const byte3 = uint8Array[i + 2];
if ((byte2 >= 0x80 && byte2 < 0xC0) && (byte3 >= 0x80 && byte3 < 0xC0)) {
const codePoint = ((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);
result += String.fromCharCode(codePoint);
i += 3;
continue;
}
}
// 无效的UTF-8序列跳过
result += '<27>';
i++;
}
// 4字节字符 (11110xxx 10xxxxxx 10xxxxxx 10xxxxxx)
else if (byte1 >= 0xF0 && byte1 < 0xF8) {
if (i + 3 < len) {
const byte2 = uint8Array[i + 1];
const byte3 = uint8Array[i + 2];
const byte4 = uint8Array[i + 3];
if ((byte2 >= 0x80 && byte2 < 0xC0) && (byte3 >= 0x80 && byte3 < 0xC0) && (byte4 >= 0x80 && byte4 < 0xC0)) {
let codePoint = ((byte1 & 0x07) << 18) | ((byte2 & 0x3F) << 12) | ((byte3 & 0x3F) << 6) | (byte4 & 0x3F);
// 处理UTF-16代理对
if (codePoint >= 0x10000) {
codePoint -= 0x10000;
const highSurrogate = (codePoint >> 10) + 0xD800;
const lowSurrogate = (codePoint & 0x3FF) + 0xDC00;
result += String.fromCharCode(highSurrogate, lowSurrogate);
} else {
result += String.fromCharCode(codePoint);
}
i += 4;
continue;
}
}
// 无效的UTF-8序列跳过
result += '<27>';
i++;
}
// 无效的UTF-8序列跳过
else {
result += '<27>';
i++;
}
}
return result;
}
// 监听分块数据
requestTask.onChunkReceived((res) => {
try {
// 微信小程序兼容处理微信小程序不支持TextDecoder使用自定义UTF-8解码
let chunk = '';
if (typeof TextDecoder !== 'undefined') {
// 支持TextDecoder的环境如开发者工具
const decoder = new TextDecoder('utf-8');
const chunk = decoder.decode(new Uint8Array(res.data));
chunk = decoder.decode(new Uint8Array(res.data));
} else {
// 微信小程序真机环境使用自定义UTF-8解码函数
const uint8Array = new Uint8Array(res.data);
chunk = utf8Decode(uint8Array);
}
console.log('📦 收到分块数据:', chunk);
buffer += chunk;