From 6bcce6440894649ba588670789cf69dd68126d05 Mon Sep 17 00:00:00 2001 From: zpc Date: Thu, 19 Mar 2026 06:51:46 +0800 Subject: [PATCH] 21 --- uniapp/pages/assessment/result/index.vue | 1305 +++------------------- 1 file changed, 145 insertions(+), 1160 deletions(-) diff --git a/uniapp/pages/assessment/result/index.vue b/uniapp/pages/assessment/result/index.vue index 18351cd..06b59b9 100644 --- a/uniapp/pages/assessment/result/index.vue +++ b/uniapp/pages/assessment/result/index.vue @@ -3,15 +3,12 @@ * 测评结果页面 * * 功能: - * - 自定义导航栏,顶部"保存到本地"按钮 - * - 基本信息展示 - * - 八大智能分析展示 - * - 个人特质分析展示 - * - 40项细分能力展示 - * - 其他分析模块展示(先天学习类型、学习关键能力、科学大脑类型、性格类型、未来关键发展能力) + * - 进入页面自动下载并打开PDF报告 + * - 提供"保存到本地"按钮手动触发 + * - 如果PDF未生成,显示提示 */ -import { ref, computed, onMounted } from 'vue' +import { ref } from 'vue' import { onLoad } from '@dcloudio/uni-app' import { useUserStore } from '@/store/user.js' import { getResult } from '@/api/assessment.js' @@ -26,310 +23,93 @@ const reportUrl = ref('') // 页面状态 const pageLoading = ref(true) const saving = ref(false) - -// 测评结果数据 -const resultData = ref(null) - -// 基本信息 -const basicInfo = computed(() => resultData.value?.basicInfo || {}) - -// 八大智能数据 -const intelligences = computed(() => resultData.value?.intelligences || []) - -// 八大智能排名(最高2名和最低2名) -const topIntelligences = computed(() => { - const sorted = [...intelligences.value].sort((a, b) => b.score - a.score) - return sorted.slice(0, 2) -}) - -const bottomIntelligences = computed(() => { - const sorted = [...intelligences.value].sort((a, b) => a.score - b.score) - return sorted.slice(0, 2) -}) - -// 个人特质数据 -const traits = computed(() => resultData.value?.traits || []) - -// 最高特质 -const topTrait = computed(() => { - if (traits.value.length === 0) return null - return [...traits.value].sort((a, b) => b.percentage - a.percentage)[0] -}) - -// 40项细分能力 -const abilities = computed(() => resultData.value?.abilities || []) - -// 细分能力排名(最高10名和最低10名) -const topAbilities = computed(() => { - const sorted = [...abilities.value].sort((a, b) => b.score - a.score) - return sorted.slice(0, 10) -}) - -const bottomAbilities = computed(() => { - const sorted = [...abilities.value].sort((a, b) => a.score - b.score) - return sorted.slice(0, 10) -}) - -// 按智能分类的细分能力 -const abilitiesByIntelligence = computed(() => { - const grouped = {} - abilities.value.forEach(ability => { - const category = ability.intelligenceCategory || '其他' - if (!grouped[category]) { - grouped[category] = [] - } - grouped[category].push(ability) - }) - return grouped -}) - -// 额外5类型分析 -const extraTypes = computed(() => resultData.value?.extraTypes || []) +const errorMsg = ref('') /** - * 加载测评结果 + * 下载并打开PDF + */ +async function openPdf(url) { + if (!url) { + errorMsg.value = 'PDF报告暂未生成' + return + } + + saving.value = true + + try { + uni.showLoading({ title: '正在打开报告...' }) + + const downloadRes = await new Promise((resolve, reject) => { + uni.downloadFile({ + url, + success: resolve, + fail: reject + }) + }) + + uni.hideLoading() + + if (downloadRes.statusCode === 200) { + uni.openDocument({ + filePath: downloadRes.tempFilePath, + fileType: 'pdf', + showMenu: true, + fail: (err) => { + console.error('打开PDF失败:', err) + uni.showToast({ title: '打开失败,请重试', icon: 'none' }) + } + }) + } else { + uni.showToast({ title: '下载失败,请重试', icon: 'none' }) + } + } catch (error) { + uni.hideLoading() + console.error('下载PDF失败:', error) + uni.showToast({ title: '下载失败,请重试', icon: 'none' }) + } finally { + saving.value = false + } +} + +/** + * 加载测评结果(仅获取reportUrl,不自动打开) */ async function loadResult() { if (!recordId.value) { - uni.showToast({ - title: '缺少测评记录', - icon: 'none' - }) + errorMsg.value = '缺少测评记录' + pageLoading.value = false return } - + pageLoading.value = true - + errorMsg.value = '' + try { const res = await getResult(recordId.value) - + if (res && res.code === 0 && res.data) { - resultData.value = res.data - // 从接口获取 reportUrl(优先级高于页面参数) if (res.data.reportUrl) { reportUrl.value = res.data.reportUrl + } else { + errorMsg.value = 'PDF报告暂未生成,请稍后再试' } } else { - // 使用模拟数据进行开发测试 - resultData.value = generateMockData() + errorMsg.value = '获取报告失败,请稍后再试' } } catch (error) { console.error('加载测评结果失败:', error) - // 使用模拟数据 - resultData.value = generateMockData() + errorMsg.value = '加载失败,请稍后再试' } finally { pageLoading.value = false } } /** - * 生成模拟数据(开发测试用) + * 手动点击保存到本地 */ -function generateMockData() { - return { - basicInfo: { - name: '张三', - age: 15, - gender: '男', - educationStage: '高中', - phone: '138****8888', - location: '北京市朝阳区', - testDate: '2025-02-10', - testType: '多元智能测评' - }, - intelligences: [ - { id: 1, name: '逻辑数学智能', score: 85, maxScore: 100, rank: 1, level: '最强五星', description: '您在逻辑推理、数学运算方面表现出色,善于分析问题和解决复杂问题。' }, - { id: 2, name: '语言智能', score: 78, maxScore: 100, rank: 2, level: '较强五星', description: '您具有良好的语言表达能力,善于用文字和语言表达思想。' }, - { id: 3, name: '视觉空间智能', score: 72, maxScore: 100, rank: 3, level: '中等', description: '您对空间、色彩有一定的感知能力。' }, - { id: 4, name: '肢体运动智能', score: 68, maxScore: 100, rank: 4, level: '中等', description: '您的身体协调能力处于中等水平。' }, - { id: 5, name: '音乐智能', score: 65, maxScore: 100, rank: 5, level: '中等', description: '您对音乐有一定的感知和欣赏能力。' }, - { id: 6, name: '人际交际智能', score: 60, maxScore: 100, rank: 6, level: '中等', description: '您的人际交往能力处于中等水平。' }, - { id: 7, name: '自我察觉智能', score: 55, maxScore: 100, rank: 7, level: '相对较弱', description: '建议加强自我认知和情绪管理能力的培养。' }, - { id: 8, name: '自然探索智能', score: 50, maxScore: 100, rank: 8, level: '相对较弱', description: '建议多接触自然,培养对自然现象的观察和探索兴趣。' } - ], - traits: [ - { id: 1, name: '视觉型特质', percentage: 35, description: '您倾向于通过视觉方式学习和理解信息。' }, - { id: 2, name: '听觉型特质', percentage: 28, description: '您对声音和语言有较好的感知能力。' }, - { id: 3, name: '手脚并用型特质', percentage: 22, description: '您喜欢通过动手实践来学习。' }, - { id: 4, name: '自我察觉型特质', percentage: 15, description: '您具有一定的自我反思能力。' } - ], - abilities: generateMockAbilities(), - extraTypes: [ - { - id: 1, - name: '先天学习类型', - items: [ - { name: '视觉学习型', score: 85, stars: 5, rank: 1 }, - { name: '听觉学习型', score: 72, stars: 4, rank: 2 }, - { name: '动觉学习型', score: 65, stars: 3, rank: 3 } - ], - topConclusion: '您是视觉学习型,建议通过图表、图像、视频等方式学习效果更佳。', - bottomConclusion: '动觉学习方面相对较弱,可以适当增加动手实践的机会。' - }, - { - id: 2, - name: '学习的关键能力', - items: [ - { name: '专注力', score: 78, stars: 4, rank: 1 }, - { name: '记忆力', score: 75, stars: 4, rank: 2 }, - { name: '理解力', score: 70, stars: 4, rank: 3 }, - { name: '创造力', score: 65, stars: 3, rank: 4 } - ], - bottomConclusion: '创造力方面有提升空间,建议多进行发散性思维训练。' - }, - { - id: 3, - name: '科学大脑类型', - items: [ - { name: '左脑型', score: 72, stars: 4, rank: 1 }, - { name: '右脑型', score: 68, stars: 3, rank: 2 }, - { name: '全脑型', score: 60, stars: 3, rank: 3 } - ], - topConclusion: '您偏向左脑型思维,擅长逻辑分析和理性思考。', - bottomConclusion: '建议加强右脑训练,提升创意和直觉能力。' - }, - { - id: 4, - name: '性格类型', - items: [ - { name: '外向型', score: 65, stars: 3, rank: 1 }, - { name: '内向型', score: 55, stars: 3, rank: 2 }, - { name: '中间型', score: 80, stars: 4, rank: 3 } - ], - topConclusion: '您的性格较为平衡,能够在不同场合灵活调整自己的状态。' - }, - { - id: 5, - name: '未来关键发展能力', - items: [ - { name: '批判性思维', score: 80, stars: 4, rank: 1 }, - { name: '沟通协作', score: 75, stars: 4, rank: 2 }, - { name: '创新能力', score: 70, stars: 4, rank: 3 }, - { name: '数字素养', score: 68, stars: 3, rank: 4 } - ], - topConclusion: '您的批判性思维能力较强,善于独立思考和分析问题。', - bottomConclusion: '数字素养方面可以进一步提升,建议多接触数字化工具和技术。' - } - ] - } -} - -/** - * 生成模拟细分能力数据 - */ -function generateMockAbilities() { - const intelligenceCategories = [ - '逻辑数学智能', '语言智能', '视觉空间智能', '肢体运动智能', - '音乐智能', '人际交际智能', '自我察觉智能', '自然探索智能' - ] - - const abilityNames = [ - '逻辑推理', '数学运算', '问题分析', '模式识别', '抽象思维', - '口语表达', '书面表达', '阅读理解', '词汇运用', '语言组织', - '空间想象', '图形识别', '色彩感知', '方向感', '视觉记忆', - '身体协调', '精细动作', '运动技能', '反应速度', '平衡能力', - '节奏感', '音调辨别', '音乐记忆', '乐器演奏', '音乐创作', - '社交能力', '团队协作', '领导能力', '同理心', '沟通技巧', - '自我认知', '情绪管理', '目标设定', '自我激励', '反思能力', - '自然观察', '分类能力', '环境感知', '生态意识', '探索精神' - ] - - return abilityNames.map((name, index) => ({ - id: index + 1, - name: name, - score: Math.floor(Math.random() * 40) + 60, - maxScore: 100, - stars: Math.floor(Math.random() * 3) + 3, - intelligenceCategory: intelligenceCategories[Math.floor(index / 5)], - rank: index + 1 - })) -} - -/** - * 获取星级显示 - */ -function getStars(count) { - return '★'.repeat(count) + '☆'.repeat(5 - count) -} - -/** - * 获取进度条颜色 - */ -function getProgressColor(score) { - if (score >= 80) return '#52C41A' - if (score >= 60) return '#4A90E2' - if (score >= 40) return '#FAAD14' - return '#FF4D4F' -} - -/** - * 保存到本地(下载PDF报告) - */ -async function handleSaveToLocal() { +function handleSaveToLocal() { if (saving.value) return - - if (!reportUrl.value) { - uni.showToast({ - title: 'PDF报告暂未生成', - icon: 'none' - }) - return - } - - saving.value = true - - try { - uni.showLoading({ - title: '正在下载PDF...' - }) - - // 下载PDF文件 - const downloadRes = await new Promise((resolve, reject) => { - uni.downloadFile({ - url: reportUrl.value, - success: resolve, - fail: reject - }) - }) - - uni.hideLoading() - - if (downloadRes.statusCode === 200) { - // 使用 openDocument 打开PDF(用户可在预览界面保存) - uni.openDocument({ - filePath: downloadRes.tempFilePath, - fileType: 'pdf', - showMenu: true, - success: () => { - uni.showToast({ - title: '打开成功', - icon: 'success' - }) - }, - fail: (err) => { - console.error('打开PDF失败:', err) - uni.showToast({ - title: '打开失败,请重试', - icon: 'none' - }) - } - }) - } else { - uni.showToast({ - title: '下载失败,请重试', - icon: 'none' - }) - } - } catch (error) { - uni.hideLoading() - console.error('下载PDF失败:', error) - uni.showToast({ - title: '下载失败,请重试', - icon: 'none' - }) - } finally { - saving.value = false - } + openPdf(reportUrl.value) } /** @@ -337,15 +117,15 @@ async function handleSaveToLocal() { */ onLoad((options) => { recordId.value = options.recordId || '' - + // 从 loading 页面传递的 reportUrl if (options.reportUrl) { reportUrl.value = decodeURIComponent(options.reportUrl) } - + // 恢复用户登录状态 userStore.restoreFromStorage() - + loadResult() }) @@ -353,300 +133,27 @@ onLoad((options) => {