feat(SendPage): 重构评估表单页面并增加多表单类型支持
重构发送页面UI,增加背景装饰和卡片式布局。新增支持发送两种不同类型的评估表单(家庭教育档案和入营测评卷),并优化了倒计时和状态管理逻辑。同时改进了企微消息发送功能,根据不同类型显示不同标题和描述。
This commit is contained in:
@@ -1,29 +1,60 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🌟 青少年心理健康评估</h1>
|
||||
<p class="subtitle">专业、科学、个性化的心理健康分析</p>
|
||||
</div>
|
||||
<div class="page-wrapper">
|
||||
<!-- 背景装饰圆点 -->
|
||||
<div class="bg-dot dot-1"></div>
|
||||
<div class="bg-dot dot-2"></div>
|
||||
|
||||
<div class="cta-section">
|
||||
<h2>开始您的专业评估之旅</h2>
|
||||
<p class="cta-description">
|
||||
只需5-10分钟,即可获得专业的家庭教育档案信息报告
|
||||
</p>
|
||||
<div class="container">
|
||||
<!-- 头部区域 -->
|
||||
<div class="header-section">
|
||||
<div class="sparkle-icon">✨</div>
|
||||
<h1 class="main-title">青少年心理健康评估</h1>
|
||||
<p class="subtitle">专业、科学、个性化的心理健康分析</p>
|
||||
</div>
|
||||
|
||||
<!-- 修改部分:按钮增加了 disabled 属性、动态 class 和动态文本 -->
|
||||
<button
|
||||
class="cta-button"
|
||||
:class="{ 'disabled': isCoolingDown }"
|
||||
@click="handleSendForm"
|
||||
:disabled="isCoolingDown"
|
||||
>
|
||||
{{ isCoolingDown ? `📝 请等待 ${countdown} 秒...` : '📝 发送评估表' }}
|
||||
</button>
|
||||
<!-- 主体操作卡片 -->
|
||||
<div class="action-card">
|
||||
<h2 class="card-headline">选择并发送评估工具</h2>
|
||||
|
||||
<p class="note">
|
||||
💡 评估完全免费,结果仅供参考,如需专业帮助请咨询心理医生
|
||||
</p>
|
||||
<div class="info-bar">
|
||||
只需 <span class="time-badge">5-10 分钟</span>,即可获得专业的评估分析报告
|
||||
</div>
|
||||
|
||||
<div class="button-list">
|
||||
<!-- 按钮 1: 家庭教育档案 -->
|
||||
<button class="nav-button" :class="{ 'is-active': activeType === 'archive', 'is-disabled': isCoolingDown }"
|
||||
@click="handleSend('archive')">
|
||||
<div class="btn-left">
|
||||
<span class="btn-icon-box">📝</span>
|
||||
<span class="btn-label">发送【家庭教育档案】</span>
|
||||
</div>
|
||||
<div class="btn-loading-ring" v-if="isCoolingDown && activeType === 'archive'"></div>
|
||||
<span class="btn-arrow" v-else>→</span>
|
||||
</button>
|
||||
|
||||
<!-- 按钮 2: 入营测评卷 -->
|
||||
<button class="nav-button" :class="{ 'is-active': activeType === 'campTest', 'is-disabled': isCoolingDown }"
|
||||
@click="handleSend('campTest')">
|
||||
<div class="btn-left">
|
||||
<span class="btn-icon-box">🎯</span>
|
||||
<span class="btn-label">发送【入营测评卷】</span>
|
||||
</div>
|
||||
<div class="btn-loading-ring" v-if="isCoolingDown && activeType === 'campTest'"></div>
|
||||
<span class="btn-arrow" v-else>→</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 倒计时提示 -->
|
||||
<div v-if="isCoolingDown" class="cooldown-text">
|
||||
已发送,请在聊天窗口查看 ({{ countdown }}s)
|
||||
</div>
|
||||
|
||||
<!-- 底部免责声明 -->
|
||||
<div class="disclaimer">
|
||||
<span class="light-bulb">💡</span>
|
||||
评估完全免费,结果仅供参考,如需专业帮助请咨询心理医生
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -32,303 +63,305 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import * as ww from '@wecom/jssdk'
|
||||
|
||||
// --- 状态定义 ---
|
||||
type FormType = 'archive' | 'campTest'
|
||||
const isCoolingDown = ref(false)
|
||||
const countdown = ref(0)
|
||||
const activeType = ref<FormType | null>(null)
|
||||
const isWWReady = ref(false)
|
||||
const errorMessage = ref<string | null>(null)
|
||||
|
||||
// --- 防重复点击逻辑 ---
|
||||
const isCoolingDown = ref(false) // 是否处于冷却期
|
||||
const countdown = ref(0) // 倒计时秒数
|
||||
|
||||
const handleSendForm = () => {
|
||||
// 如果正在冷却中,直接阻断
|
||||
if (isCoolingDown.value) return
|
||||
|
||||
// 启动10秒倒计时
|
||||
startCooldown(10)
|
||||
|
||||
// 执行业务逻辑
|
||||
GetFormUrl()
|
||||
// --- 配置表 ---
|
||||
const CONFIG = {
|
||||
archive: {
|
||||
id: 0,
|
||||
title: '家庭教育档案信息表',
|
||||
desc: '通过专业的评估工具,了解孩子的成长需求。'
|
||||
},
|
||||
campTest: {
|
||||
id: 2,
|
||||
title: '青少年入营测评卷',
|
||||
desc: '入营前专属专业测评,帮助导师全方位了解营员特质。'
|
||||
}
|
||||
}
|
||||
|
||||
// 倒计时工具函数
|
||||
const startCooldown = (seconds: number) => {
|
||||
// --- 核心逻辑 ---
|
||||
const handleSend = async (type: FormType) => {
|
||||
if (isCoolingDown.value) return
|
||||
|
||||
activeType.value = type
|
||||
startTimer(8) // 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
|
||||
}
|
||||
})
|
||||
} else {
|
||||
alert('获取链接失败:' + (res.message || '未知错误'))
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('发送流程出错:', err)
|
||||
}
|
||||
}
|
||||
|
||||
const startTimer = (seconds: number) => {
|
||||
isCoolingDown.value = true
|
||||
countdown.value = seconds
|
||||
|
||||
const timer = setInterval(() => {
|
||||
countdown.value--
|
||||
if (countdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
isCoolingDown.value = false // 倒计时结束,恢复按钮可用
|
||||
isCoolingDown.value = false
|
||||
activeType.value = null
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
// --------------------
|
||||
|
||||
async function getConfigSignature(url: string) {
|
||||
// --- 初始化企业微信SDK ---
|
||||
const initSDK = async () => {
|
||||
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 url = window.location.href.split('#')[0]
|
||||
|
||||
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 getSig = async (apiUrl: string) => {
|
||||
return await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url })
|
||||
}).then(r => r.json())
|
||||
}
|
||||
|
||||
const initWeWork = async () => {
|
||||
try {
|
||||
await ww.register({
|
||||
corpId: 'wwf72acc5a681dca93',
|
||||
agentId: 1000105,
|
||||
jsApiList: ['sendChatMessage', 'getCurExternalContact', 'getContext'],
|
||||
getConfigSignature,
|
||||
getAgentConfigSignature
|
||||
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
|
||||
} catch (error) {
|
||||
isWWReady.value = false
|
||||
errorMessage.value = '企业微信JS-SDK初始化失败,请刷新页面重试。'
|
||||
console.log('企微SDK初始化成功')
|
||||
} catch (e) {
|
||||
console.error('SDK初始化失败', e)
|
||||
}
|
||||
}
|
||||
|
||||
const getUserInfo = async () => {
|
||||
try {
|
||||
const response = await ww.getCurExternalContact()
|
||||
return response.userId
|
||||
} catch (error) {
|
||||
console.error('[getCurExternalContact] 失败', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const GetFormUrl = async () => {
|
||||
try {
|
||||
const userId = await getUserInfo()
|
||||
const response = await fetch(`https://liaison.nycjy.cn/api/v1/archive/form-url?user_id=${userId}`, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
|
||||
const formUrl = await response.json()
|
||||
console.log('[GetFormUrl]', formUrl.data)
|
||||
sendFormLink(formUrl.data.form_url)
|
||||
if (!response.ok) throw new Error('获取表单URL失败')
|
||||
} catch (error) {
|
||||
console.error('[GetFormUrl]', error)
|
||||
// 如果希望出错时允许立即重试,可以在这里取消冷却:
|
||||
// isCoolingDown.value = false
|
||||
alert('请求失败,请检查网络或稍后重试。')
|
||||
}
|
||||
}
|
||||
|
||||
const sendFormLink = async (formUrl: string) => {
|
||||
if (!isWWReady.value) {
|
||||
alert('企业微信功能尚未准备好,请稍等片刻...')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await ww.sendChatMessage({
|
||||
msgtype: 'news',
|
||||
news: {
|
||||
title: '家庭教育档案信息表',
|
||||
desc: '通过专业的评估工具,了解孩子的成长需求,为每个孩子制定个性化的成长方案',
|
||||
imgUrl: 'https://forms.nycjy.cn/favicon.ico',
|
||||
link: formUrl
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('发送消息失败:', error)
|
||||
alert('发送失败,详情请查看控制台日志。')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await initWeWork()
|
||||
})
|
||||
onMounted(() => initSDK())
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 全局基础设置 */
|
||||
.page-wrapper {
|
||||
min-height: 100vh;
|
||||
background-color: #f4f7ff;
|
||||
/* 淡蓝色背景 */
|
||||
background: linear-gradient(180deg, #f0f4ff 0%, #ffffff 100%);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.header {
|
||||
/* 装饰元素 */
|
||||
.bg-dot {
|
||||
position: absolute;
|
||||
border-radius: 50%;
|
||||
filter: blur(60px);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.dot-1 {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
background: #dce4ff;
|
||||
top: -50px;
|
||||
left: -50px;
|
||||
}
|
||||
|
||||
.dot-2 {
|
||||
width: 250px;
|
||||
height: 250px;
|
||||
background: #eef2ff;
|
||||
bottom: -50px;
|
||||
right: -50px;
|
||||
}
|
||||
|
||||
/* 头部样式 */
|
||||
.header-section {
|
||||
text-align: center;
|
||||
margin-bottom: 3rem;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 700;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
margin-bottom: 1rem;
|
||||
.sparkle-icon {
|
||||
font-size: 44px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.main-title {
|
||||
color: #5c6be5;
|
||||
/* 核心蓝紫色 */
|
||||
font-size: 26px;
|
||||
font-weight: 800;
|
||||
margin: 0 0 10px 0;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 1.2rem;
|
||||
color: #666;
|
||||
color: #8c96a8;
|
||||
font-size: 15px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 2rem;
|
||||
margin-bottom: 4rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
transition: all 0.3s ease;
|
||||
/* 主操作卡片 */
|
||||
.action-card {
|
||||
background: #ffffff;
|
||||
border-radius: 24px;
|
||||
padding: 35px 24px;
|
||||
box-shadow: 0 10px 30px rgba(92, 107, 229, 0.08);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-8px);
|
||||
box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.card.highlight {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.card-icon {
|
||||
font-size: 3rem;
|
||||
margin-bottom: 1rem;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.card h3 {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 1rem;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.card p {
|
||||
color: inherit;
|
||||
opacity: 0.9;
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.cta-section {
|
||||
text-align: center;
|
||||
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
||||
border-radius: 20px;
|
||||
padding: 3rem 2rem;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.cta-section h2 {
|
||||
font-size: 2rem;
|
||||
.card-headline {
|
||||
color: #333c4d;
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
color: #2c3e50;
|
||||
margin-bottom: 1rem;
|
||||
margin: 0 0 15px 0;
|
||||
}
|
||||
|
||||
.cta-description {
|
||||
font-size: 1.1rem;
|
||||
color: #5a6c7d;
|
||||
margin-bottom: 2rem;
|
||||
max-width: 600px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
/* 时间标签栏 */
|
||||
.info-bar {
|
||||
font-size: 14px;
|
||||
color: #64748b;
|
||||
margin-bottom: 35px;
|
||||
}
|
||||
|
||||
.cta-button {
|
||||
background: linear-gradient(135deg, #4CAF50, #45a049);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 1rem 2.5rem;
|
||||
font-size: 1.2rem;
|
||||
.time-badge {
|
||||
background: #edf0ff;
|
||||
/* 淡紫色背景 */
|
||||
color: #5c6be5;
|
||||
padding: 3px 10px;
|
||||
border-radius: 6px;
|
||||
font-weight: 600;
|
||||
border-radius: 50px;
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
/* 按钮列表 */
|
||||
.button-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.nav-button {
|
||||
background: #ffffff;
|
||||
border: 1px solid #eef0f5;
|
||||
border-radius: 16px;
|
||||
padding: 18px 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
|
||||
margin-bottom: 1.5rem;
|
||||
transition: all 0.2s ease;
|
||||
width: 100%;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
|
||||
}
|
||||
|
||||
.cta-button:hover {
|
||||
background: linear-gradient(135deg, #45a049, #3d8b40);
|
||||
transform: translateY(-3px);
|
||||
box-shadow: 0 8px 25px rgba(76, 175, 80, 0.4);
|
||||
.nav-button:active:not(.is-disabled) {
|
||||
transform: scale(0.97);
|
||||
background-color: #f8faff;
|
||||
}
|
||||
|
||||
/* 禁用状态样式 */
|
||||
.cta-button.disabled {
|
||||
background: #bdc3c7; /* 灰色背景 */
|
||||
.btn-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.btn-icon-box {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.btn-label {
|
||||
color: #5c6be5;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-arrow {
|
||||
color: #c0c7d1;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 冷却状态样式 */
|
||||
.is-disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none; /* 移除悬浮效果 */
|
||||
box-shadow: none;
|
||||
opacity: 0.8;
|
||||
background-color: #f5f7fa;
|
||||
}
|
||||
|
||||
.cta-button.disabled:hover {
|
||||
background: #bdc3c7;
|
||||
transform: none;
|
||||
.cooldown-text {
|
||||
font-size: 13px;
|
||||
color: #5c6be5;
|
||||
margin-bottom: 20px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.note {
|
||||
font-size: 0.9rem;
|
||||
color: #7f8c8d;
|
||||
margin: 0;
|
||||
font-style: italic;
|
||||
.btn-loading-ring {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: 2px solid #5c6be5;
|
||||
border-top-color: transparent;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.container {
|
||||
padding: 1rem;
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.card-grid {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 1rem;
|
||||
}
|
||||
/* 底部声明 */
|
||||
.disclaimer {
|
||||
background: #f8f9fc;
|
||||
border-radius: 12px;
|
||||
padding: 12px 16px;
|
||||
font-size: 12px;
|
||||
color: #94a3b8;
|
||||
line-height: 1.6;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.cta-section {
|
||||
padding: 2rem 1rem;
|
||||
}
|
||||
.light-bulb {
|
||||
font-size: 16px;
|
||||
filter: grayscale(0.2);
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user