From 47526eb6dc75eb64c740a05d9158fa1f4be206be Mon Sep 17 00:00:00 2001 From: lbw_9527443 <780139497@qq.com> Date: Mon, 16 Mar 2026 18:14:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(SendPage):=20=E9=87=8D=E6=9E=84=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=A1=B5=E9=9D=A2=E4=B8=BA=E5=A4=9A=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E5=B8=83=E5=B1=80=E5=B9=B6=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=A1=A3=E6=A1=88=E6=9F=A5=E7=9C=8B=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构发送工具页面为双标签导航布局,新增信息档案查看功能 添加评估档案详情弹窗,支持报告和原始答卷切换查看 优化表单发送逻辑和样式,增加加载状态和错误处理 --- src/components/HomePage.vue | 984 +++++++++++++----------------------- src/components/SendPage.vue | 828 ++++++++++++++++++++++++------ 2 files changed, 1029 insertions(+), 783 deletions(-) diff --git a/src/components/HomePage.vue b/src/components/HomePage.vue index 3834242..f7047d8 100644 --- a/src/components/HomePage.vue +++ b/src/components/HomePage.vue @@ -6,7 +6,6 @@ import * as ww from '@wecom/jssdk' // ------------------------------------------------------------------- // 类型定义 // ------------------------------------------------------------------- - interface CustomerInfo { name: string; child_name: string; @@ -41,93 +40,60 @@ function mapAnswersToCustomerInfo(answers: RawAnswerItem[]): CustomerInfo { }; const info: Partial = { additional_info: [] }; - answers.forEach(item => { const questionLabel = item.question_label.trim(); const answer = item.answer; const fieldName = mainFieldsMap[questionLabel]; - if (fieldName) { - (info as any)[fieldName] = answer; - } - // 无论是否匹配到主字段,都放入 additional_info 以便在列表中展示 + if (fieldName) { (info as any)[fieldName] = answer; } info.additional_info!.push({ topic: questionLabel, answer: answer }); }); - return info as CustomerInfo; } + // ------------------------------------------------------------------- // 1. 响应式状态 // ------------------------------------------------------------------- const router = useRouter() const isWWReady = ref(false) -const externalUserId = ref(localStorage.getItem('external_user_id')) const errorMessage = ref(null) -const isLoading = ref(false) +const isLoading = ref(false) // 按钮提交 loading +const isPageLoading = ref(true) // 页面初始化/切换客户时的全局 loading + +// 初始值全部设为 null,不信任任何本地缓存 +const externalUserId = ref(null) +const customerInfo = ref(null) +const secondStageInfo = ref(null) const showPhoneInput = ref(false) const phoneNumber = ref('') -const customerInfo = ref((() => { - const stored = localStorage.getItem('customer_info') - if (stored && stored !== 'undefined') { - try { - return JSON.parse(stored) as CustomerInfo - } catch (error) { - console.error('解析客户信息失败:', error) - localStorage.removeItem('customer_info') - return null - } - } - return null -})()) - -const secondStageInfo = ref((() => { - const stored = localStorage.getItem('second_stage_info') - if (stored && stored !== 'undefined') { - try { - return JSON.parse(stored) as CustomerInfo - } catch (error) { - console.error('解析二阶信息失败:', error) - localStorage.removeItem('second_stage_info') - return null - } - } - return null -})()) - // ------------------------------------------------------------------- -// 2. JS-SDK 初始化 和 签名获取 +// 2. JS-SDK 签名函数 // ------------------------------------------------------------------- - async function getConfigSignature(url: string) { - try { - const response = await fetch('https://sidebar.wx.nycjy.cn/api/v1/wecom/config-signature', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ url }) - }) - if (!response.ok) throw new Error('获取企业签名失败') - return await response.json() - } catch (error) { - console.error('[getConfigSignature]', error) - throw error - } + const response = await fetch('https://sidebar.wx.nycjy.cn/api/v1/wecom/config-signature', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ url }) + }) + if (!response.ok) throw new Error('获取Config签名失败') + return await response.json() } async function getAgentConfigSignature(url: string) { - try { - const response = await fetch('https://sidebar.wx.nycjy.cn/api/v1/wecom/agent-config-signature', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ url }) - }) - if (!response.ok) throw new Error('获取应用签名失败') - return await response.json() - } catch (error) { - console.error('[getAgentConfigSignature]', error) - throw error - } + const response = await fetch('https://sidebar.wx.nycjy.cn/api/v1/wecom/agent-config-signature', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ url }) + }) + if (!response.ok) throw new Error('获取AgentConfig签名失败') + return await response.json() } +// ------------------------------------------------------------------- +// 3. 核心业务逻辑 +// ------------------------------------------------------------------- + +// 初始化 SDK const initWeWork = async () => { try { await ww.register({ @@ -139,329 +105,193 @@ const initWeWork = async () => { }) isWWReady.value = true } catch (error) { + console.error('企微 SDK 初始化失败:', error) isWWReady.value = false - errorMessage.value = '企业微信JS-SDK初始化失败,请刷新页面重试。' + errorMessage.value = '企业微信环境初始化失败,请点击右上角刷新' + isPageLoading.value = false } } -// ------------------------------------------------------------------- -// 3. API调用函数 -// ------------------------------------------------------------------- -const checkFormExists = async (wechatEnterpriseId: string) => { - try { - const response = await fetch('https://sidebar.wx.nycjy.cn/api/v1/wecom/check-form', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ wechat_enterprise_id: wechatEnterpriseId }) - }) - return await response.json() - } catch (error) { - console.error('检查表单失败:', error) - throw error - } -} - -const checkPhoneExists = async (wechatEnterpriseId: string) => { - try { - const response = await fetch('https://sidebar.wx.nycjy.cn/api/v1/wecom/check-phone', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ wechat_enterprise_id: wechatEnterpriseId }) - }) - return await response.json() - } catch (error) { - console.error('检查手机号失败:', error) - throw error - } -} - -const updatePhone = async (wechatEnterpriseId: string, phone: string) => { - try { - const response = await fetch('https://sidebar.wx.nycjy.cn/api/v1/wecom/update-phone', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ wechat_enterprise_id: wechatEnterpriseId, phone }) - }) - return await response.json() - } catch (error) { - console.error('更新手机号失败:', error) - throw error - } -} - -// ------------------------------------------------------------------- -// 4. 核心业务逻辑 -// ------------------------------------------------------------------- - -const sendFormLink = async () => { - if (!isWWReady.value) { - alert('企业微信功能尚未准备好,请稍等片刻...') - return - } - try { - await ww.sendChatMessage({ - msgtype: 'news', - news: { - title: '青少年成长伙伴计划评估表', - desc: '通过专业的评估工具,了解孩子的成长需求,为每个孩子制定个性化的成长方案', - imgUrl: 'https://forms.nycjy.cn/favicon.ico', - link: 'https://forms.nycjy.cn?wecom_id=' + externalUserId.value + '&t=' + new Date().getTime() - } - }) - } catch (error) { - console.error('发送消息失败:', error) - alert('发送失败,详情请查看控制台日志。') - } -} - -const getUserIn = async () => { - try { - const contact = await ww.getCurExternalContact() - return contact - } catch (error) { - console.error('[getCurExternalContact]', error) - throw error - } -} - -const handleButtonClick = async (event: Event) => { - event.preventDefault() - if (!externalUserId.value) { - alert('无法获取用户信息,请重新进入页面') - return - } - isLoading.value = true - errorMessage.value = null - try { - // 获取手机号 - const phoneResponse = await fetch('https://sidebar.wx.nycjy.cn/api/v1/wecom/get-phone-by-wecom-id',{ - method:'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ wecom_id: externalUserId.value }) - }) - const phoneData = await phoneResponse.json() - console.log('获取手机号响应:', phoneData) - if (phoneData.code === 0 && phoneData.data && phoneData.data.phone) { - phoneNumber.value = phoneData.data.phone - } - console.log('手机号:', phoneNumber.value) - await ww.sendChatMessage({ - msgtype: 'news', - news: { - title: '青少年成长伙伴计划评估表', - desc: '通过专业的评估工具,了解孩子的成长需求,为每个孩子制定个性化的成长方案', - imgUrl: 'https://forms.nycjy.cn/favicon.ico', - link: 'https://forms.nycjy.cn?wecom_id=' + externalUserId.value + '&t=' + new Date().getTime() - } - }) - } catch (error) { - console.error('处理发送请求失败:', error) - errorMessage.value = '处理请求失败,请重试' - } finally { - isLoading.value = false - } -} - -const submitPhone = async () => { - if (!phoneNumber.value.trim()) { - alert('请输入手机号') - return - } - const phoneRegex = /^1[3-9]\d{9}$/ - if (!phoneRegex.test(phoneNumber.value)) { - alert('请输入正确的手机号格式') - return - } - if (!externalUserId.value) { - alert('无法获取用户信息,请重新进入页面') - return - } - isLoading.value = true - errorMessage.value = null - try { - await updatePhone(externalUserId.value, phoneNumber.value) - await sendFormLink() - showPhoneInput.value = false - phoneNumber.value = '' - } catch (error) { - console.error('提交手机号失败:', error) - errorMessage.value = '提交手机号失败,请重试' - } finally { - isLoading.value = false - } -} - -const cancelPhoneInput = () => { - showPhoneInput.value = false - phoneNumber.value = '' -} - +// 核心:获取最新客户 ID 并同步数据 const fetchAndCheckExternalContact = async () => { - if (!isWWReady.value) { - alert('JSSDK未就绪,无法获取外部联系人') - return - } + // A. 进入加载状态,清空旧数据(防止串号) + isPageLoading.value = true + externalUserId.value = null + customerInfo.value = null + secondStageInfo.value = null + errorMessage.value = null + try { + // B. 获取当前上下文和最新的外部联系人 ID const context = await ww.getContext() const allowedEntries = ['contact_profile', 'single_chat_tools'] if (!allowedEntries.includes(context.entry)) { - errorMessage.value = `当前入口 "${context.entry}" 不支持此功能。请从客户详情页或聊天工具栏进入。` + errorMessage.value = `当前入口(${context.entry})不支持,请从客户详情或聊天工具栏进入` + isPageLoading.value = false return } + const contact = await ww.getCurExternalContact() - externalUserId.value = contact.userId - localStorage.setItem('external_user_id', contact.userId) + if (!contact.userId) { + throw new Error('未获取到外部联系人ID') + } - if (externalUserId.value) { - const result = await checkFormExists(externalUserId.value) - if (result.data.code && result.data.form_content && result.data.form_content.length > 0) { - // 一阶表单 - const rawAnswers1 = result.data.form_content[0].answers as RawAnswerItem[]; - console.log('一阶原始答案:', rawAnswers1); - const mappedCustomerInfo = mapAnswersToCustomerInfo(rawAnswers1); - customerInfo.value = mappedCustomerInfo; - localStorage.setItem('customer_info', JSON.stringify(mappedCustomerInfo)); + // C. 确认为当前最新 ID,并写入缓存(同步给 analysis 页面) + const currentId = contact.userId + externalUserId.value = currentId + localStorage.setItem('external_user_id', currentId) - // 二阶表单 - if (result.data.form_content.length > 1) { - const rawAnswers2 = result.data.form_content[1].answers as RawAnswerItem[]; - console.log('二阶原始答案:', rawAnswers2); - const mappedSecondStage = mapAnswersToCustomerInfo(rawAnswers2); - secondStageInfo.value = mappedSecondStage; - localStorage.setItem('second_stage_info', JSON.stringify(mappedSecondStage)); - } else { - secondStageInfo.value = null; - localStorage.removeItem('second_stage_info'); - } + // D. 请求后端接口获取表单数据 + const response = await fetch('https://sidebar.wx.nycjy.cn/api/v1/wecom/check-form', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ wechat_enterprise_id: currentId }) + }) + const result = await response.json() + + // E. 逻辑处理:解析表单内容 + // 注意:这里检查 result.data.form_content 是否存在 + if (result.data && result.data.form_content && result.data.form_content.length > 0) { + // 解析一阶 + const raw1 = result.data.form_content[0].answers as RawAnswerItem[] + customerInfo.value = mapAnswersToCustomerInfo(raw1) + localStorage.setItem('customer_info', JSON.stringify(customerInfo.value)) + + // 解析二阶 + if (result.data.form_content.length > 1) { + const raw2 = result.data.form_content[1].answers as RawAnswerItem[] + secondStageInfo.value = mapAnswersToCustomerInfo(raw2) + localStorage.setItem('second_stage_info', JSON.stringify(secondStageInfo.value)) } else { - customerInfo.value = null - localStorage.removeItem('customer_info') - secondStageInfo.value = null localStorage.removeItem('second_stage_info') } + } else { + // 无表单记录,清空缓存 + localStorage.removeItem('customer_info') + localStorage.removeItem('second_stage_info') } } catch (error: any) { - console.error('获取外部联系人信息流程失败:', error) - errorMessage.value = `获取客户信息失败: ${error.errMsg || '未知错误'}` + console.error('获取客户信息流程失败:', error) + errorMessage.value = `获取客户信息失败: ${error.message || '网络连接异常'}` + } finally { + // F. 无论成功失败,关闭全局加载状态 + isPageLoading.value = false + } +} + +// 发送消息逻辑 +const sendFormLink = async () => { + await fetchAndCheckExternalContact() + if (!isWWReady.value || !externalUserId.value) return + isLoading.value = true + try { + await ww.sendChatMessage({ + msgtype: 'news', + news: { + title: '青少年成长伙伴计划评估表', + desc: '通过专业的评估工具,了解孩子的成长需求', + imgUrl: 'https://forms.nycjy.cn/favicon.ico', + link: `https://forms.nycjy.cn?wecom_id=${externalUserId.value}&t=${Date.now()}` + } + }) + } catch (error) { + alert('发送失败') + } finally { + isLoading.value = false + } +} + +// 提交手机号(补全信息场景) +const submitPhone = async () => { + if (!phoneNumber.value.trim() || !externalUserId.value) return + isLoading.value = true + try { + const res = await fetch('https://sidebar.wx.nycjy.cn/api/v1/wecom/update-phone', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ wechat_enterprise_id: externalUserId.value, phone: phoneNumber.value }) + }) + if (res.ok) { + await sendFormLink() + showPhoneInput.value = false + } + } catch (error) { + alert('提交手机号失败') + } finally { + isLoading.value = false } } // ------------------------------------------------------------------- -// 5. 辅助功能 +// 4. 生命周期执行 // ------------------------------------------------------------------- - onMounted(async () => { await initWeWork() - await getUserIn() if (isWWReady.value) { await fetchAndCheckExternalContact() } }) - -const handleCardHover = (event: Event, isEnter: boolean) => { - const card = event.currentTarget as HTMLElement - card.style.transform = isEnter ? 'translateY(-10px) scale(1.02)' : 'translateY(0) scale(1)' -} - -// 按钮跳转逻辑 -const goToAnalysis = () => { - if (customerInfo.value) { - sessionStorage.setItem('customerInfo', JSON.stringify(customerInfo.value)) - router.push('/analysis') - } -} - -const handleSmartReply = () => { - router.push('/smart-reply') -} diff --git a/src/components/SendPage.vue b/src/components/SendPage.vue index e1ba3c5..b02453d 100644 --- a/src/components/SendPage.vue +++ b/src/components/SendPage.vue @@ -5,57 +5,146 @@
- -
-
-

青少年心理健康评估

-

专业、科学、个性化的心理健康分析

+ + +
+ +
- -
-

选择并发送评估工具

+ + -
- 只需 5-10 分钟,即可获得专业的评估分析报告 -
+ +
+
+
+

青少年心理健康评估

+

专业、科学、个性化的心理健康分析

+
-
- - - - + +
-
- - + +
+ 已发送,请在聊天窗口查看 ({{ countdown }}s) +
+
- -
- 已发送,请在聊天窗口查看 ({{ countdown }}s) + +
+ +
+

客户评估档案

+

全面掌握客户的心理与家庭状况

+
+ +
+
+
+ 正在获取综合评估数据... +
+ +
+ 📭 + 客户暂未填写任何表单 +
+ +
+ +
+
+ {{ item.title }} + {{ item.status }} +
+
+

填表主体:{{ item.targetName }}

+

提交时间:{{ item.submitTime }}

+

综合得分:{{ + item.totalScore }} 分

+
+ +
+
+
- -
- 💡 - 评估完全免费,结果仅供参考,如需专业帮助请咨询心理医生 -
+ + + +
+ 💡 + 评估完全免费,结果仅供参考,如需专业帮助请咨询心理医生
+ + + + +
@@ -63,118 +152,196 @@ import { ref, onMounted } from 'vue' import * as ww from '@wecom/jssdk' -// --- 状态定义 --- type FormType = 'archive' | 'campTest' +type TabType = 'send' | 'data' +type ModalViewType = 'qa' | 'report' + +interface QuestionItem { + question_id: string; + question_name: string; + answer: string; + storage_key: string; +} + +interface FormDataItem { + id: string | number; + type: FormType; + title: string; + status: string; + targetName: string; + submitTime?: string; + totalScore?: number; + rawData: QuestionItem[]; + reportMarkdown?: string; +} + +const isWWReady = ref(false) +const activeTab = ref('send') // 全局导航状态 + const isCoolingDown = ref(false) const countdown = ref(0) -const activeType = ref(null) -const isWWReady = ref(false) +const activeSendType = ref(null) + +const isLoadingData = ref(false) +const formDataList = ref([]) + +const showModal = ref(false) +const currentItem = ref(null) +const modalView = ref('qa') -// --- 配置表 --- const CONFIG = { - archive: { - id: 0, - title: '家庭教育档案信息表', - desc: '通过专业的评估工具,了解孩子的成长需求。' - }, - campTest: { - id: 2, - title: '向阳营入营量表', - desc: '入营前专属专业测评,帮助导师全方位了解营员特质。' + archive: { id: 0, title: '家庭教育档案信息表', desc: '通过专业的评估工具,了解孩子的成长需求。' }, + campTest: { id: 2, title: '向阳营入营量表', desc: '入营前专属专业测评,帮助导师全方位了解营员特质。' } +} + +const formatAnswer = (val: string) => { + if (!val) return '未填写' + const dict: Record = { + 'male': '男', 'female': '女', 'yes': '是 / 有', 'no': '否 / 无', + 'excellent': '优秀', 'good': '良好', 'average': '一般', 'poor': '较差', + 'fully_agree': '完全符合 / 同意', 'partially_agree': '部分符合 / 偶尔', 'disagree': '不符合 / 不同意', + 'depression': '情绪低落 / 抑郁', 'anxiety': '焦虑紧张', 'rebellion': '叛逆对抗' + } + return dict[val.toLowerCase()] || val +} + +const parseMarkdown = (mdText: string) => { + if (!mdText) return '' + return mdText + .replace(/^### (.*$)/gim, '

$1

') + .replace(/^## (.*$)/gim, '

$1

') + .replace(/^# (.*$)/gim, '

$1

') + .replace(/^\> (.*$)/gim, '
$1
') + .replace(/\*\*(.*?)\*\*/gim, '$1') + .replace(/^- (.*$)/gim, '
• $1
') + .replace(/\n\n/g, '
') + .replace(/\n/g, '
') +} + +// 切换全局页面 +const switchTab = (tab: TabType) => { + if (activeTab.value === tab) return + activeTab.value = tab + if (tab === 'data' && formDataList.value.length === 0) { + fetchFormData() } } -// --- 核心逻辑 --- +const fetchFormData = async () => { + isLoadingData.value = true + try { + let userId = 'wmcr-ECwAA3wT4EQ1xgCtTQDZVnEIAvg' + if (isWWReady.value) { + const contact = await ww.getCurExternalContact() + userId = contact.userId + } + + const urlArchive = `https://liaison.nycjy.cn/api/v1/archive/archive-information?wecom_id=${userId}` + const urlCampTest = `https://liaison.nycjy.cn/api/v1/archive/parent-entry-assessment?wecom_id=${userId}` + + const [archiveRes, campRes] = await Promise.allSettled([ + fetch(urlArchive).then(r => r.json()), + fetch(urlCampTest).then(r => r.json()) + ]) + + const list: FormDataItem[] = [] + + if (archiveRes.status === 'fulfilled' && archiveRes.value.code === 200) { + const archives = archiveRes.value.data?.archive_informations || [] + archives.forEach((submission: QuestionItem[], index: number) => { + const childNameItem = submission.find(q => q.storage_key === 'child_name') + list.push({ + id: `archive_${index}`, type: 'archive', title: '家庭教育档案信息表', status: '已收录', + targetName: childNameItem?.answer ? `${childNameItem.answer} (孩子)` : '未知姓名', + rawData: submission + }) + }) + } + + if (campRes.status === 'fulfilled' && campRes.value.code === 200) { + const campData = campRes.value.data?.parent_entry_assessment + if (campData) { + const answers = campData.archive_information || [] + const parentNameItem = answers.find((q: QuestionItem) => q.storage_key === 'parent_name') + const formattedDate = campData.createdAt ? campData.createdAt.replace('T', ' ').substring(0, 16) : '' + list.push({ + id: campData.form_id || 'camp_test', type: 'campTest', title: campData.form_title || '向阳营家长入营测试量表', + status: '已出报告', targetName: parentNameItem?.answer ? `${parentNameItem.answer} (家长)` : '家长答卷', + submitTime: formattedDate, totalScore: campData.total_score, + rawData: answers, reportMarkdown: campData.result_ana + }) + } + } + formDataList.value = list.reverse() + } catch (err) { + console.error('获取数据失败:', err) + } finally { + isLoadingData.value = false + } +} + +const openDetailModal = (item: FormDataItem) => { + currentItem.value = item + modalView.value = item.type === 'campTest' ? 'report' : 'qa' + showModal.value = true +} + +const closeModal = () => { + showModal.value = false + setTimeout(() => { currentItem.value = null }, 300) +} + const handleSend = async (type: FormType) => { if (isCoolingDown.value) return - - activeType.value = type - startTimer(8) // 8秒冷却 - + activeSendType.value = type + startTimer(8) try { - // 1. 获取外部联系人ID const contact = await ww.getCurExternalContact() const userId = contact.userId - - // 2. 请求后端获取表单URL const apiUrl = `https://liaison.nycjy.cn/api/v1/archive/form-url?user_id=${userId}&form_id=${CONFIG[type].id}` const res = await fetch(apiUrl).then(r => r.json()) if (res.code === 200 && res.data?.form_url) { - // 3. 调用企微原生接口发送消息卡片 await ww.sendChatMessage({ msgtype: 'news', - news: { - title: CONFIG[type].title, - desc: CONFIG[type].desc, - imgUrl: 'https://forms.nycjy.cn/favicon.ico', - link: res.data.form_url - } + news: { title: CONFIG[type].title, desc: CONFIG[type].desc, imgUrl: 'https://forms.nycjy.cn/favicon.ico', link: res.data.form_url } }) - } else { - alert('获取链接失败:' + (res.message || '未知错误')) - } - } catch (err) { - console.error('发送流程出错:', err) - } + } else alert('获取链接失败:' + (res.message || '未知错误')) + } catch (err) { console.error('发送流程出错:', err) } } const startTimer = (seconds: number) => { - isCoolingDown.value = true - countdown.value = seconds + isCoolingDown.value = true; countdown.value = seconds const timer = setInterval(() => { - countdown.value-- - if (countdown.value <= 0) { - clearInterval(timer) - isCoolingDown.value = false - activeType.value = null - } + countdown.value--; if (countdown.value <= 0) { clearInterval(timer); isCoolingDown.value = false; activeSendType.value = null } }, 1000) } -// --- 初始化企业微信SDK --- const initSDK = async () => { try { const url = window.location.href.split('#')[0] - - // 签名函数 (对应你后端接口) - const getSig = async (apiUrl: string) => { - return await fetch(apiUrl, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ url }) - }).then(r => r.json()) - } + const getSig = async (apiUrl: string) => await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url }) }).then(r => r.json()) await ww.register({ - corpId: 'wwf72acc5a681dca93', - agentId: 1000105, - jsApiList: ['sendChatMessage', 'getCurExternalContact', 'getContext'], - getConfigSignature: () => getSig('https://sidebar.wx.nycjy.cn/api/v1/wecom/config-signature'), - getAgentConfigSignature: () => getSig('https://sidebar.wx.nycjy.cn/api/v1/wecom/agent-config-signature') + corpId: 'wwf72acc5a681dca93', agentId: 1000105, jsApiList: ['sendChatMessage', 'getCurExternalContact', 'getContext'], + getConfigSignature: () => getSig('https://sidebar.wx.nycjy.cn/api/v1/wecom/config-signature'), getAgentConfigSignature: () => getSig('https://sidebar.wx.nycjy.cn/api/v1/wecom/agent-config-signature') }) isWWReady.value = true - console.log('企微SDK初始化成功') - } catch (e) { - console.error('SDK初始化失败', e) - } + } catch (e) { console.error('SDK初始化失败', e) } } - onMounted(() => initSDK())