合并 智慧就业第一版
This commit is contained in:
@@ -20,7 +20,16 @@ export function useColumnCount(onChange = () => {}) {
|
||||
// }
|
||||
// }
|
||||
const calcColumn = () => {
|
||||
const width = uni.getSystemInfoSync().windowWidth
|
||||
// 使用新的API替代已废弃的getSystemInfoSync
|
||||
let width
|
||||
// #ifdef MP-WEIXIN
|
||||
const mpSystemInfo = uni.getWindowInfo()
|
||||
width = mpSystemInfo.windowWidth
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
const otherSystemInfo = uni.getSystemInfoSync()
|
||||
width = otherSystemInfo.windowWidth
|
||||
// #endif
|
||||
|
||||
let count = 2
|
||||
if (width >= 1000) {
|
||||
@@ -46,15 +55,20 @@ export function useColumnCount(onChange = () => {}) {
|
||||
onMounted(() => {
|
||||
columnCount.value = 2
|
||||
calcColumn()
|
||||
// if (process.client) {
|
||||
window.addEventListener('resize', calcColumn)
|
||||
// }
|
||||
// 只在H5环境下添加resize监听器
|
||||
// #ifdef H5
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('resize', calcColumn)
|
||||
}
|
||||
// #endif
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
// if (process.client) {
|
||||
window.removeEventListener('resize', calcColumn)
|
||||
// }
|
||||
// #ifdef H5
|
||||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('resize', calcColumn)
|
||||
}
|
||||
// #endif
|
||||
})
|
||||
|
||||
// 列数变化时执行回调
|
||||
|
||||
@@ -149,7 +149,19 @@ export function useAudioRecorder() {
|
||||
|
||||
const startRecording = async () => {
|
||||
if (isRecording.value) return
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
$api.msg('小程序暂不支持语音识别功能');
|
||||
return;
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
try {
|
||||
if (typeof navigator === 'undefined' || !navigator.mediaDevices) {
|
||||
$api.msg('当前环境不支持录音功能');
|
||||
return;
|
||||
}
|
||||
|
||||
recognizedText.value = ''
|
||||
lastFinalText.value = ''
|
||||
await connectWebSocket()
|
||||
@@ -191,6 +203,7 @@ export function useAudioRecorder() {
|
||||
console.error('启动失败:', err)
|
||||
cleanup()
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
const stopRecording = () => {
|
||||
|
||||
@@ -4,39 +4,69 @@ import {
|
||||
|
||||
export function useScrollDirection(options = {}) {
|
||||
const {
|
||||
threshold = 200, // 滚动偏移阈值
|
||||
throttleTime = 100, // 节流时间(毫秒)
|
||||
onChange = null // 滚动方向变化的回调
|
||||
threshold = 50, // 滚动偏移阈值,降低以更敏感
|
||||
throttleTime = 16, // 节流时间(毫秒),约60fps
|
||||
onChange = null, // 滚动方向变化的回调
|
||||
hideThreshold = 100, // 隐藏区域的滚动阈值
|
||||
enablePerformanceMode = true // 启用性能优化模式
|
||||
} = options
|
||||
|
||||
const lastScrollTop = ref(0)
|
||||
const accumulatedScroll = ref(0)
|
||||
const isScrollingDown = ref(false)
|
||||
const shouldHideTop = ref(false) // 控制顶部区域隐藏
|
||||
const shouldStickyFilter = ref(false) // 控制筛选区域吸顶
|
||||
let lastInvoke = 0
|
||||
|
||||
function handleScroll(e) {
|
||||
const now = Date.now()
|
||||
if (now - lastInvoke < throttleTime) return
|
||||
if (enablePerformanceMode && now - lastInvoke < throttleTime) return
|
||||
lastInvoke = now
|
||||
|
||||
const scrollTop = e.detail.scrollTop
|
||||
const delta = scrollTop - lastScrollTop.value
|
||||
accumulatedScroll.value += delta
|
||||
|
||||
if (accumulatedScroll.value > threshold) {
|
||||
if (!isScrollingDown.value) {
|
||||
isScrollingDown.value = true
|
||||
onChange?.(true) // 通知变更为向下
|
||||
// 控制顶部区域隐藏
|
||||
if (scrollTop > hideThreshold) {
|
||||
if (!shouldHideTop.value) {
|
||||
shouldHideTop.value = true
|
||||
}
|
||||
} else {
|
||||
if (shouldHideTop.value) {
|
||||
shouldHideTop.value = false
|
||||
}
|
||||
accumulatedScroll.value = 0
|
||||
}
|
||||
|
||||
if (accumulatedScroll.value < -threshold) {
|
||||
if (isScrollingDown.value) {
|
||||
isScrollingDown.value = false
|
||||
onChange?.(false) // 通知变更为向上
|
||||
// 控制筛选区域吸顶(当顶部区域隐藏时)
|
||||
if (scrollTop > hideThreshold + 50) { // 稍微延迟吸顶
|
||||
if (!shouldStickyFilter.value) {
|
||||
shouldStickyFilter.value = true
|
||||
}
|
||||
} else {
|
||||
if (shouldStickyFilter.value) {
|
||||
shouldStickyFilter.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 滚动方向检测(仅在性能模式下使用阈值)
|
||||
if (!enablePerformanceMode || Math.abs(accumulatedScroll.value) > threshold) {
|
||||
if (accumulatedScroll.value > 0) {
|
||||
// 向下滚动
|
||||
if (!isScrollingDown.value) {
|
||||
isScrollingDown.value = true
|
||||
onChange?.(true) // 通知变更为向下
|
||||
}
|
||||
} else {
|
||||
// 向上滚动
|
||||
if (isScrollingDown.value) {
|
||||
isScrollingDown.value = false
|
||||
onChange?.(false) // 通知变更为向上
|
||||
}
|
||||
}
|
||||
if (enablePerformanceMode) {
|
||||
accumulatedScroll.value = 0
|
||||
}
|
||||
accumulatedScroll.value = 0
|
||||
}
|
||||
|
||||
lastScrollTop.value = scrollTop
|
||||
@@ -44,6 +74,8 @@ export function useScrollDirection(options = {}) {
|
||||
|
||||
return {
|
||||
isScrollingDown,
|
||||
shouldHideTop,
|
||||
shouldStickyFilter,
|
||||
handleScroll
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,17 @@ export function useTTSPlayer(wsUrl) {
|
||||
const isPaused = ref(false)
|
||||
const isComplete = ref(false)
|
||||
|
||||
const audioContext = new(window.AudioContext || window.webkitAudioContext)()
|
||||
let playTime = audioContext.currentTime
|
||||
// #ifdef H5
|
||||
const audioContext = typeof window !== 'undefined' && (window.AudioContext || window.webkitAudioContext)
|
||||
? new(window.AudioContext || window.webkitAudioContext)()
|
||||
: null
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
const audioContext = null // 微信小程序不支持 AudioContext
|
||||
// #endif
|
||||
|
||||
let playTime = audioContext ? audioContext.currentTime : 0
|
||||
let sourceNodes = []
|
||||
let socket = null
|
||||
let sampleRate = 16000
|
||||
@@ -28,6 +37,11 @@ export function useTTSPlayer(wsUrl) {
|
||||
let activePlayId = 0
|
||||
|
||||
const speak = (text) => {
|
||||
if (!audioContext) {
|
||||
console.warn('⚠️ TTS not supported in current environment');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('🎤 TTS speak function called');
|
||||
console.log('📝 Text to synthesize:', text ? text.substring(0, 100) + '...' : 'No text');
|
||||
console.log('🔗 WebSocket URL:', wsUrl);
|
||||
@@ -44,6 +58,11 @@ export function useTTSPlayer(wsUrl) {
|
||||
}
|
||||
|
||||
const pause = () => {
|
||||
if (!audioContext) {
|
||||
console.warn('⚠️ TTS not supported in current environment');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('⏸️ TTS pause called');
|
||||
console.log('🔊 AudioContext state:', audioContext.state);
|
||||
console.log('🔊 Is speaking before pause:', isSpeaking.value);
|
||||
@@ -63,6 +82,11 @@ export function useTTSPlayer(wsUrl) {
|
||||
}
|
||||
|
||||
const resume = () => {
|
||||
if (!audioContext) {
|
||||
console.warn('⚠️ TTS not supported in current environment');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('▶️ TTS resume called');
|
||||
console.log('🔊 AudioContext state:', audioContext.state);
|
||||
console.log('🔊 Is speaking before resume:', isSpeaking.value);
|
||||
@@ -89,7 +113,7 @@ export function useTTSPlayer(wsUrl) {
|
||||
isSpeaking.value = false
|
||||
isPaused.value = false
|
||||
isComplete.value = false
|
||||
playTime = audioContext.currentTime
|
||||
playTime = audioContext ? audioContext.currentTime : 0
|
||||
|
||||
sourceNodes.forEach(node => {
|
||||
try {
|
||||
@@ -113,11 +137,16 @@ export function useTTSPlayer(wsUrl) {
|
||||
isSpeaking.value = false
|
||||
isPaused.value = false
|
||||
isComplete.value = false
|
||||
playTime = audioContext.currentTime
|
||||
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);
|
||||
@@ -167,7 +196,7 @@ export function useTTSPlayer(wsUrl) {
|
||||
console.log('✅ TTS synthesis completed');
|
||||
isComplete.value = true
|
||||
// 计算剩余播放时间,确保播放完整
|
||||
const remainingTime = Math.max(0, (playTime - audioContext.currentTime) * 1000);
|
||||
const remainingTime = audioContext ? Math.max(0, (playTime - audioContext.currentTime) * 1000) : 0;
|
||||
console.log('⏱️ Remaining play time:', remainingTime + 'ms');
|
||||
setTimeout(() => {
|
||||
if (thisPlayId === activePlayId) {
|
||||
@@ -205,6 +234,8 @@ export function useTTSPlayer(wsUrl) {
|
||||
}
|
||||
|
||||
const pcmToAudioBuffer = (pcm, sampleRate, numChannels) => {
|
||||
if (!audioContext) return null;
|
||||
|
||||
const length = pcm.length / numChannels
|
||||
const audioBuffer = audioContext.createBuffer(numChannels, length, sampleRate)
|
||||
for (let ch = 0; ch < numChannels; ch++) {
|
||||
@@ -218,6 +249,8 @@ export function useTTSPlayer(wsUrl) {
|
||||
}
|
||||
|
||||
const playBuffer = (audioBuffer) => {
|
||||
if (!audioContext || !audioBuffer) return;
|
||||
|
||||
console.log('🎵 playBuffer called, duration:', audioBuffer.duration + 's');
|
||||
if (!isSpeaking.value) {
|
||||
playTime = audioContext.currentTime
|
||||
@@ -259,7 +292,10 @@ export function useTTSPlayer(wsUrl) {
|
||||
onHide(cancelAudio)
|
||||
onUnload(cancelAudio)
|
||||
|
||||
initWebSocket()
|
||||
// 只在支持 AudioContext 的环境中初始化 WebSocket
|
||||
if (audioContext) {
|
||||
initWebSocket()
|
||||
}
|
||||
|
||||
return {
|
||||
speak,
|
||||
|
||||
Reference in New Issue
Block a user