From f78a0b84d8e9e24353a87566d2eb1ab6d9f59fe4 Mon Sep 17 00:00:00 2001 From: xiebing Date: Mon, 29 Dec 2025 10:41:42 +0800 Subject: [PATCH] =?UTF-8?q?fix=20:=20=E4=BF=AE=E6=AD=A3=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=B7=A5=E5=85=B7,=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E7=BB=8F=E9=AA=8C=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hook/useAudioSpeak.js | 124 ++++++++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 48 deletions(-) diff --git a/hook/useAudioSpeak.js b/hook/useAudioSpeak.js index 5678937..e793cef 100644 --- a/hook/useAudioSpeak.js +++ b/hook/useAudioSpeak.js @@ -46,62 +46,90 @@ export const useAudioSpeak = (config = {}) => { // 文本提取工具函数 function extractSpeechText(markdown) { - if (!markdown || markdown.indexOf('job-json') === -1) { - return markdown; - } - const jobRegex = /``` job-json\s*({[\s\S]*?})\s*```/g; - const jobs = []; - let match; - let lastJobEndIndex = 0; - let firstJobStartIndex = -1; + if (!markdown || markdown.indexOf('job-json') === -1) { + return markdown; + } + const jobRegex = /``` job-json\s*({[\s\S]*?})\s*```/g; + const jobs = []; + let match; + let lastJobEndIndex = 0; + let firstJobStartIndex = -1; - while ((match = jobRegex.exec(markdown)) !== null) { - const jobStr = match[1]; - try { - const job = JSON.parse(jobStr); - jobs.push(job); - if (firstJobStartIndex === -1) { - firstJobStartIndex = match.index; - } - lastJobEndIndex = jobRegex.lastIndex; - } catch (e) { - console.warn('JSON 解析失败', e); + while ((match = jobRegex.exec(markdown)) !== null) { + const jobStr = match[1]; + try { + const job = JSON.parse(jobStr); + jobs.push(job); + if (firstJobStartIndex === -1) { + firstJobStartIndex = match.index; } + lastJobEndIndex = jobRegex.lastIndex; + } catch (e) { + console.warn('JSON 解析失败', e); + } + } + + const guideText = firstJobStartIndex > 0 ? + markdown.slice(0, firstJobStartIndex).trim() : ''; + const endingText = lastJobEndIndex < markdown.length ? + markdown.slice(lastJobEndIndex).trim() : ''; + + const jobTexts = jobs.map((job, index) => { + // 处理薪资格式 + let salaryText = job.salary; + if (salaryText) { + // 匹配 "XXXXX-XXXXX元/月" 格式 + const rangeMatch = salaryText.match(/(\d+)-(\d+)元\/月/); + if (rangeMatch) { + const minSalary = parseInt(rangeMatch[1], 10); + const maxSalary = parseInt(rangeMatch[2], 10); + + // 转换为千位单位 + const minK = Math.round(minSalary / 1000); + const maxK = Math.round(maxSalary / 1000); + + salaryText = `${minK}千到${maxK}千每月`; + } + // 如果不是 "XXXXX-XXXXX元/月" 格式,保持原样 } - const guideText = firstJobStartIndex > 0 ? - markdown.slice(0, firstJobStartIndex).trim() : ''; - const endingText = lastJobEndIndex < markdown.length ? - markdown.slice(lastJobEndIndex).trim() : ''; - - const jobTexts = jobs.map((job, index) => { - // 处理薪资格式 - let salaryText = job.salary; - if (salaryText) { - // 匹配 "XXXXX-XXXXX元/月" 格式 - const rangeMatch = salaryText.match(/(\d+)-(\d+)元\/月/); - if (rangeMatch) { - const minSalary = parseInt(rangeMatch[1], 10); - const maxSalary = parseInt(rangeMatch[2], 10); - - // 转换为千位单位 - const minK = Math.round(minSalary / 1000); - const maxK = Math.round(maxSalary / 1000); - - salaryText = `${minK}千到${maxK}千每月`; - } - // 如果不是 "XXXXX-XXXXX元/月" 格式,保持原样 + // 处理经验要求格式 + let experienceText = job.experience; + if (experienceText) { + // 匹配 "X-X年" 格式,如 "1-3年"、"5-10年" + const expRangeMatch = experienceText.match(/(\d+)-(\d+)年/); + if (expRangeMatch) { + const minExp = parseInt(expRangeMatch[1], 10); + const maxExp = parseInt(expRangeMatch[2], 10); + experienceText = `${minExp}到${maxExp}年`; } + + // 还可以处理其他常见格式 + else if (experienceText.includes('年以下')) { + // 如 "3年以下" + experienceText = experienceText.replace('年以下', '年以下'); + } else if (experienceText.includes('年以上')) { + // 如 "5年以上" + experienceText = experienceText.replace('年以上', '年以上'); + } else if (experienceText === '不限' || experienceText === '无经验要求') { + experienceText = '经验不限'; + } + // 其他格式保持原样 + } - return `第 ${index + 1} 个岗位,岗位名称是:${job.jobTitle},公司是:${job.companyName},薪资:${salaryText},地点:${job.location},学历要求:${job.education},经验要求:${job.experience}。`; - }); + // 同样可以处理学历要求(如果需要的话) + let educationText = job.education; + // 这里可以添加学历格式的转换逻辑 - const finalTextParts = []; - if (guideText) finalTextParts.push(guideText); - finalTextParts.push(...jobTexts); - if (endingText) finalTextParts.push(endingText); + return `第 ${index + 1} 个岗位,岗位名称是:${job.jobTitle},公司是:${job.companyName},薪资:${salaryText},地点:${job.location},学历要求:${educationText},经验要求:${experienceText}。`; + }); - return finalTextParts.join('\n'); + const finalTextParts = []; + if (guideText) finalTextParts.push(guideText); + finalTextParts.push(...jobTexts); + if (endingText) finalTextParts.push(endingText); + + return finalTextParts.join('\n'); } /**