feat: 双端题库统一与 PDP/DISC 结果文案、测评 API 与企测上下文
1、修复了测评/结果页与个人中心展示不一致问题;废弃独立 questions.js,统一使用 questionBank;结果格式与详情解析相关问题。 2、新增了 PdpDiscResultText(PDP+DISC 双类型摘要文案)、抖音 questionBank 与 enterpriseContext;扩展 api/Test 与路由、管理端 Order 与 ExtractsTestResults。 3、优化了 resultFormat 与 questionBank 组织方式、UserDetailDialog;移除不再使用的 mbti_test_results 恢复 SQL/脚本。 Made-with: Cursor
This commit is contained in:
@@ -47,8 +47,8 @@ App({
|
||||
// 超管配置的默认企业 ID(无 scene/eid 等入口参数时回落)
|
||||
defaultEnterpriseId: null,
|
||||
// API基础地址(开发时用本地,生产环境替换为实际域名)
|
||||
apiBase: 'https://mbtiapi.quwanzhi.com',
|
||||
//apiBase: 'http://mbti.com',
|
||||
//apiBase: 'https://mbtiapi.quwanzhi.com',
|
||||
apiBase: 'http://mbti.com',
|
||||
// VIP信息
|
||||
vipInfo: null,
|
||||
// 测试次数
|
||||
|
||||
@@ -3,6 +3,17 @@ const app = getApp()
|
||||
const { getTypeOnly } = require('../../utils/resultFormat')
|
||||
const { request } = require('../../utils/request')
|
||||
|
||||
/** recent 单条:优先用 resultMeta 与结果页一致的「双项」文案 */
|
||||
function summaryFromRecentRecord(rec, testType) {
|
||||
if (!rec) return ''
|
||||
const meta = rec.resultMeta
|
||||
if (meta && typeof meta === 'object') {
|
||||
const t = getTypeOnly(meta, testType)
|
||||
if (t) return t
|
||||
}
|
||||
return String(rec.resultText || '').trim()
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
hasLogin: false,
|
||||
@@ -47,19 +58,18 @@ Page({
|
||||
permPdp: true,
|
||||
permDisc: true,
|
||||
permDistribution: true,
|
||||
/** 最新测试横滑区:仅有已出结果的卡片时才显示,避免禁权或未测评占位 */
|
||||
showLatestTestCards: false,
|
||||
/** 最新测试横滑区:有问卷/面相权限即显示;无记录时卡片灰阶占位,不隐藏 */
|
||||
showLatestTestRow: false,
|
||||
/** 用户卡片下性格标签:在「当前权限下无任何问卷结果」时显示灰色提示 */
|
||||
showEmptyPersonalityTags: true
|
||||
},
|
||||
|
||||
_computeShowLatestTestCards(d) {
|
||||
_computeShowLatestTestRow(d) {
|
||||
const rm = !!(d.reviewMode)
|
||||
if (d.permMbti && d.mbtiType) return true
|
||||
if (d.permPdp && d.pdpType) return true
|
||||
if (d.permDisc && d.discType) return true
|
||||
if (!rm && d.permFace && (d.gallupPreview || d.aiType)) return true
|
||||
return false
|
||||
if (rm) {
|
||||
return !!(d.permMbti || d.permPdp || d.permDisc)
|
||||
}
|
||||
return !!(d.permMbti || d.permPdp || d.permDisc || d.permFace)
|
||||
},
|
||||
|
||||
_computeShowEmptyPersonalityTags(d) {
|
||||
@@ -83,7 +93,7 @@ Page({
|
||||
const d = { ...this.data, ...next }
|
||||
this.setData({
|
||||
...next,
|
||||
showLatestTestCards: this._computeShowLatestTestCards(d),
|
||||
showLatestTestRow: this._computeShowLatestTestRow(d),
|
||||
showEmptyPersonalityTags: this._computeShowEmptyPersonalityTags(d)
|
||||
})
|
||||
},
|
||||
@@ -203,8 +213,7 @@ Page({
|
||||
const { records = {}, totalCount = 0 } = payload.data
|
||||
const r = records
|
||||
|
||||
// DISC resultText 后端已含「型」,type badge 只显示字母,去掉「型」
|
||||
const discType = r.disc ? r.disc.resultText.replace(/型$/, '') : ''
|
||||
const discType = summaryFromRecentRecord(r.disc, 'disc')
|
||||
|
||||
const gallupPreview = (r.ai && r.ai.gallupPreview) ? String(r.ai.gallupPreview) : ''
|
||||
const patch = {
|
||||
@@ -212,7 +221,7 @@ Page({
|
||||
hasResults: !!(r.mbti || r.disc || r.pdp || r.ai),
|
||||
mbtiType: r.mbti ? r.mbti.resultText : '',
|
||||
discType,
|
||||
pdpType: r.pdp ? r.pdp.resultText : '',
|
||||
pdpType: summaryFromRecentRecord(r.pdp, 'pdp'),
|
||||
aiType: r.ai ? r.ai.resultText : '',
|
||||
gallupPreview,
|
||||
mbtiTime: r.mbti ? r.mbti.testTime : '',
|
||||
@@ -227,7 +236,7 @@ Page({
|
||||
const d = { ...this.data, ...patch }
|
||||
this.setData({
|
||||
...patch,
|
||||
showLatestTestCards: this._computeShowLatestTestCards(d),
|
||||
showLatestTestRow: this._computeShowLatestTestRow(d),
|
||||
showEmptyPersonalityTags: this._computeShowEmptyPersonalityTags(d)
|
||||
})
|
||||
},
|
||||
@@ -303,7 +312,7 @@ Page({
|
||||
const d = { ...this.data, ...patch }
|
||||
this.setData({
|
||||
...patch,
|
||||
showLatestTestCards: this._computeShowLatestTestCards(d),
|
||||
showLatestTestRow: this._computeShowLatestTestRow(d),
|
||||
showEmptyPersonalityTags: this._computeShowEmptyPersonalityTags(d)
|
||||
})
|
||||
},
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<text class="tag-text">{{mbtiType}}</text>
|
||||
</view>
|
||||
<view class="tag tag-blue" wx:if="{{discType && permDisc}}">
|
||||
<text class="tag-text">{{discType}}型</text>
|
||||
<text class="tag-text">{{discType}}</text>
|
||||
</view>
|
||||
<view class="tag tag-orange" wx:if="{{pdpType && permPdp}}">
|
||||
<text class="tag-text">{{pdpType}}</text>
|
||||
@@ -79,56 +79,56 @@
|
||||
<text class="depth-header-chevron">›</text>
|
||||
</view>
|
||||
</view>
|
||||
<scroll-view wx:if="{{showLatestTestCards}}" scroll-x class="cards-scroll cards-scroll--in-card" enhanced show-scrollbar="{{false}}">
|
||||
<scroll-view wx:if="{{showLatestTestRow}}" scroll-x class="cards-scroll cards-scroll--in-card" enhanced show-scrollbar="{{false}}">
|
||||
<view class="cards-row cards-row--in-card">
|
||||
<view class="result-card card-purple" bindtap="viewMBTI" wx:if="{{permMbti && mbtiType}}">
|
||||
<view class="result-card card-purple {{mbtiType ? '' : 'result-card--placeholder'}}" bindtap="viewMBTI" wx:if="{{permMbti}}">
|
||||
<view class="card-deco"></view>
|
||||
<view class="card-icon-wrap card-icon-purple">
|
||||
<text class="card-icon">🧠</text>
|
||||
</view>
|
||||
<text class="card-label">MBTI性格</text>
|
||||
<text class="card-value">{{mbtiType}}</text>
|
||||
<text class="card-time">{{mbtiTime}}</text>
|
||||
<text class="card-value">{{mbtiType || '未测评'}}</text>
|
||||
<text class="card-time">{{mbtiTime || '—'}}</text>
|
||||
</view>
|
||||
<view class="result-card card-orange" bindtap="viewPDP" wx:if="{{permPdp && pdpType}}">
|
||||
<view class="result-card card-orange {{pdpType ? '' : 'result-card--placeholder'}}" bindtap="viewPDP" wx:if="{{permPdp}}">
|
||||
<view class="card-deco"></view>
|
||||
<view class="card-icon-wrap card-icon-orange">
|
||||
<text class="card-icon">🦁</text>
|
||||
</view>
|
||||
<text class="card-label">PDP行为</text>
|
||||
<text class="card-value">{{pdpType}}</text>
|
||||
<text class="card-time">{{pdpTime}}</text>
|
||||
<text class="card-value">{{pdpType || '未测评'}}</text>
|
||||
<text class="card-time">{{pdpTime || '—'}}</text>
|
||||
</view>
|
||||
<view class="result-card card-blue" bindtap="viewDISC" wx:if="{{permDisc && discType}}">
|
||||
<view class="result-card card-blue {{discType ? '' : 'result-card--placeholder'}}" bindtap="viewDISC" wx:if="{{permDisc}}">
|
||||
<view class="card-deco"></view>
|
||||
<view class="card-icon-wrap card-icon-blue">
|
||||
<text class="card-icon">📊</text>
|
||||
</view>
|
||||
<text class="card-label">DISC测评</text>
|
||||
<text class="card-value">{{discType + '型'}}</text>
|
||||
<text class="card-time">{{discTime}}</text>
|
||||
<text class="card-value">{{discType || '未测评'}}</text>
|
||||
<text class="card-time">{{discTime || '—'}}</text>
|
||||
</view>
|
||||
<view class="result-card card-teal" bindtap="viewGallup" wx:if="{{!reviewMode && permFace && (gallupPreview || aiType)}}">
|
||||
<view class="result-card card-teal {{(gallupPreview || aiType) ? '' : 'result-card--placeholder'}}" bindtap="viewGallup" wx:if="{{!reviewMode && permFace}}">
|
||||
<view class="card-deco"></view>
|
||||
<view class="card-icon-wrap card-icon-teal">
|
||||
<text class="card-icon">⭐</text>
|
||||
</view>
|
||||
<text class="card-label">盖洛普优势</text>
|
||||
<text class="card-value card-value--small">{{gallupPreview || '见面相报告'}}</text>
|
||||
<text class="card-time">{{aiTime}}</text>
|
||||
<text class="card-value card-value--small">{{gallupPreview || (aiType ? '见面相报告' : '未测评')}}</text>
|
||||
<text class="card-time">{{aiTime || '—'}}</text>
|
||||
</view>
|
||||
<view class="result-card card-rose" bindtap="viewAI" wx:if="{{!reviewMode && permFace && aiType}}">
|
||||
<view class="result-card card-rose {{aiType ? '' : 'result-card--placeholder'}}" bindtap="viewAI" wx:if="{{!reviewMode && permFace}}">
|
||||
<view class="card-deco"></view>
|
||||
<view class="card-icon-wrap card-icon-rose">
|
||||
<text class="card-icon">👁️</text>
|
||||
</view>
|
||||
<text class="card-label">面相分析</text>
|
||||
<text class="card-value">{{aiType}}</text>
|
||||
<text class="card-time">{{aiTime}}</text>
|
||||
<text class="card-value">{{aiType || '未测评'}}</text>
|
||||
<text class="card-time">{{aiTime || '—'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<view wx:if="{{showLatestTestCards}}" class="depth-empty-hint depth-empty-hint--compact">
|
||||
<view wx:if="{{showLatestTestRow}}" class="depth-empty-hint depth-empty-hint--compact">
|
||||
<text>点击卡片查看详情;右上方可查看全部测试记录。</text>
|
||||
</view>
|
||||
<view class="depth-inner-divider"></view>
|
||||
|
||||
@@ -467,6 +467,15 @@ custom-tab-bar {
|
||||
letter-spacing: -1rpx;
|
||||
}
|
||||
|
||||
/* 与 MBTI 同字号;长文案(如 PDP/DISC 双项)最多两行 */
|
||||
.result-card .card-value {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.card-purple .card-value { color: #7C3AED; }
|
||||
.card-blue .card-value { color: #2563EB; }
|
||||
.card-orange .card-value { color: #D97706; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// pages/result/disc.js - DISC结果页(支持付费墙 + 历史详情拉取)
|
||||
const app = getApp()
|
||||
const payment = require('../../utils/payment')
|
||||
const { getTypeOnly } = require('../../utils/resultFormat')
|
||||
|
||||
function toIntPercent(v) {
|
||||
if (v == null) return 0
|
||||
@@ -24,6 +25,8 @@ function withPercentagesInt(data) {
|
||||
Page({
|
||||
data: {
|
||||
result: null,
|
||||
/** 主+次高权重展示(如 S+I型),与接口摘要一致 */
|
||||
typeSummaryLine: '',
|
||||
typeList: [
|
||||
{ type: 'D', label: 'D型 - 支配型', colorClass: 'fill-d' },
|
||||
{ type: 'I', label: 'I型 - 影响型', colorClass: 'fill-i' },
|
||||
@@ -45,7 +48,8 @@ Page({
|
||||
}
|
||||
const result = wx.getStorageSync('discResult')
|
||||
if (result) {
|
||||
this.setData({ result: withPercentagesInt(result) })
|
||||
const r = withPercentagesInt(result)
|
||||
this.setData({ result: r, typeSummaryLine: getTypeOnly(result, 'disc') })
|
||||
this.initPayInfoFromRuntime('disc')
|
||||
} else {
|
||||
wx.showToast({ title: '暂无测试结果', icon: 'none' })
|
||||
@@ -71,7 +75,11 @@ Page({
|
||||
const paidAmount = payload.paidAmount != null ? Number(payload.paidAmount) : 0
|
||||
const amountYuan = payload.amountYuan != null ? Number(payload.amountYuan) : (paidAmount > 0 ? paidAmount / 100 : 0)
|
||||
const needPaymentToUnlock = payload.needPaymentToUnlock === true || (!!payload.requiresPayment && !isPaid && paidAmount > 0)
|
||||
this.setData({ result: withPercentagesInt(data) })
|
||||
const r = withPercentagesInt(data)
|
||||
this.setData({
|
||||
result: r,
|
||||
typeSummaryLine: getTypeOnly(data, 'disc')
|
||||
})
|
||||
const payInfo = {
|
||||
requiresPayment: needPaymentToUnlock,
|
||||
isPaid,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<view class="type-card">
|
||||
<view class="type-header">
|
||||
<text class="type-label">您的DISC性格类型</text>
|
||||
<text class="type-value">{{result.dominantType}}{{result.secondaryType ? ' + ' + result.secondaryType : ''}}</text>
|
||||
<text class="type-value">{{typeSummaryLine}}</text>
|
||||
<text class="type-description" wx:if="{{result.description && result.description.description}}">{{result.description.description}}</text>
|
||||
</view>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// pages/result/pdp.js - PDP结果页(支持付费墙 + 历史详情拉取)
|
||||
const app = getApp()
|
||||
const payment = require('../../utils/payment')
|
||||
const { getTypeOnly } = require('../../utils/resultFormat')
|
||||
|
||||
const PDP_KEYS = ['Tiger', 'Peacock', 'Koala', 'Owl', 'Chameleon']
|
||||
|
||||
@@ -23,6 +24,7 @@ function withPercentagesInt(data) {
|
||||
Page({
|
||||
data: {
|
||||
result: null,
|
||||
typeSummaryLine: '',
|
||||
typeList: [
|
||||
{ type: 'Tiger', emoji: '🐅', label: '老虎型', colorClass: 'fill-tiger' },
|
||||
{ type: 'Peacock', emoji: '🦚', label: '孔雀型', colorClass: 'fill-peacock' },
|
||||
@@ -45,7 +47,10 @@ Page({
|
||||
}
|
||||
const result = wx.getStorageSync('pdpResult')
|
||||
if (result) {
|
||||
this.setData({ result: withPercentagesInt(result) })
|
||||
this.setData({
|
||||
result: withPercentagesInt(result),
|
||||
typeSummaryLine: getTypeOnly(result, 'pdp')
|
||||
})
|
||||
this.initPayInfoFromRuntime('pdp')
|
||||
} else {
|
||||
wx.showToast({ title: '暂无测试结果', icon: 'none' })
|
||||
@@ -71,7 +76,10 @@ Page({
|
||||
const paidAmount = payload.paidAmount != null ? Number(payload.paidAmount) : 0
|
||||
const amountYuan = payload.amountYuan != null ? Number(payload.amountYuan) : (paidAmount > 0 ? paidAmount / 100 : 0)
|
||||
const needPaymentToUnlock = payload.needPaymentToUnlock === true || (!!payload.requiresPayment && !isPaid && paidAmount > 0)
|
||||
this.setData({ result: withPercentagesInt(data) })
|
||||
this.setData({
|
||||
result: withPercentagesInt(data),
|
||||
typeSummaryLine: getTypeOnly(data, 'pdp')
|
||||
})
|
||||
const payInfo = {
|
||||
requiresPayment: needPaymentToUnlock,
|
||||
isPaid,
|
||||
@@ -138,19 +146,19 @@ Page({
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
const result = this.data.result
|
||||
const line = this.data.typeSummaryLine || this.data.result?.description?.type || ''
|
||||
const { getSharePathByScope } = require('../../utils/share')
|
||||
return {
|
||||
title: `我的PDP类型是${result?.description?.type}${result?.description?.emoji},来测测你的吧!`,
|
||||
title: `我的PDP类型是${line},来测测你的吧!`,
|
||||
path: getSharePathByScope('/pages/index/index')
|
||||
}
|
||||
},
|
||||
|
||||
onShareTimeline() {
|
||||
const result = this.data.result
|
||||
const line = this.data.typeSummaryLine || this.data.result?.description?.type || ''
|
||||
const { buildShareQuery } = require('../../utils/share')
|
||||
return {
|
||||
title: `我的PDP类型是${result?.description?.type}${result?.description?.emoji},来测测你的吧!`,
|
||||
title: `我的PDP类型是${line},来测测你的吧!`,
|
||||
query: buildShareQuery()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<view class="type-card">
|
||||
<view class="type-header">
|
||||
<text class="type-label">PDP性格类型</text>
|
||||
<text class="type-value">{{result.description.type || result.dominantType}}{{result.description.emoji || ''}}</text>
|
||||
<text class="type-value">{{typeSummaryLine}}</text>
|
||||
<text class="type-title" wx:if="{{result.description.title}}">{{result.description.title}}</text>
|
||||
<text class="type-description" wx:if="{{result.description.description}}">{{result.description.description}}</text>
|
||||
</view>
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
// pages/test/disc.js
|
||||
const { discQuestions, shuffleQuestions } = require('../../utils/questions')
|
||||
const { loadQuestions } = require('../../utils/questionBank')
|
||||
const { discDescriptions } = require('../../utils/descriptions')
|
||||
const app = getApp()
|
||||
|
||||
const DISC_TIME_SEC = 15 * 60
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: true,
|
||||
questions: [],
|
||||
currentIndex: 0,
|
||||
currentQuestion: null,
|
||||
answers: {},
|
||||
selectedAnswer: null,
|
||||
total: discQuestions.length,
|
||||
total: 0,
|
||||
answeredCount: 0,
|
||||
progress: 0,
|
||||
timeRemaining: 15 * 60,
|
||||
timeRemaining: DISC_TIME_SEC,
|
||||
_initialSeconds: DISC_TIME_SEC,
|
||||
formatTime: '15:00',
|
||||
isSubmitting: false
|
||||
},
|
||||
@@ -21,10 +25,31 @@ Page({
|
||||
timer: null,
|
||||
|
||||
onLoad() {
|
||||
const questions = shuffleQuestions(discQuestions)
|
||||
this.setData({ questions, currentQuestion: questions[0] })
|
||||
try { require('../../utils/analytics').track('test_start', { type: 'disc', total: questions.length }) } catch (e) {}
|
||||
this.startTimer()
|
||||
loadQuestions('disc', {})
|
||||
.then((questions) => {
|
||||
if (!questions.length) {
|
||||
wx.showToast({ title: '暂无题目', icon: 'none' })
|
||||
this.setData({ loading: false })
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
loading: false,
|
||||
questions,
|
||||
currentQuestion: questions[0],
|
||||
total: questions.length,
|
||||
timeRemaining: DISC_TIME_SEC,
|
||||
_initialSeconds: DISC_TIME_SEC,
|
||||
formatTime: '15:00'
|
||||
})
|
||||
try {
|
||||
require('../../utils/analytics').track('test_start', { type: 'disc', total: questions.length })
|
||||
} catch (e) {}
|
||||
this.startTimer()
|
||||
})
|
||||
.catch((err) => {
|
||||
this.setData({ loading: false })
|
||||
wx.showToast({ title: (err && err.message) || '加载失败', icon: 'none' })
|
||||
})
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
@@ -148,7 +173,7 @@ Page({
|
||||
dominantType,
|
||||
secondaryType,
|
||||
description: discDescriptions[dominantType],
|
||||
testDuration: 15 * 60 - this.data.timeRemaining,
|
||||
testDuration: (this.data._initialSeconds || DISC_TIME_SEC) - this.data.timeRemaining,
|
||||
completedAt: new Date().toISOString(),
|
||||
// 便于后端留存完整答题过程
|
||||
answers: this.data.answers
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<!--pages/test/disc.wxml - DISC测试页面(按旧版模板重构)-->
|
||||
<view class="test-page">
|
||||
<view wx:if="{{loading}}" class="test-loading">
|
||||
<text class="test-loading-text">加载题目…</text>
|
||||
</view>
|
||||
<block wx:elif="{{currentQuestion}}">
|
||||
<view class="progress-section">
|
||||
<view class="progress-info">
|
||||
<text class="question-count">问题 {{currentIndex + 1}}/{{total}}</text>
|
||||
@@ -45,4 +49,5 @@
|
||||
<text class="submit-text">{{isSubmitting ? '计算中...' : '完成测试,查看结果'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
@@ -7,6 +7,19 @@
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.test-loading {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 80rpx;
|
||||
}
|
||||
|
||||
.test-loading-text {
|
||||
font-size: 30rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.progress-section {
|
||||
padding: 32rpx;
|
||||
border-bottom: 1rpx solid #e5e5e5;
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
// pages/test/mbti.js - MBTI测试页面逻辑
|
||||
const { mbtiQuestions, shuffleQuestions } = require('../../utils/questions')
|
||||
const { loadQuestions } = require('../../utils/questionBank')
|
||||
const { mbtiDescriptions } = require('../../utils/descriptions')
|
||||
const payment = require('../../utils/payment')
|
||||
const app = getApp()
|
||||
|
||||
const MBTI_TIME_SEC = 30 * 60 // 30 分钟
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: true,
|
||||
questions: [],
|
||||
currentIndex: 0,
|
||||
currentQuestion: null,
|
||||
answers: {},
|
||||
selectedAnswer: null,
|
||||
total: mbtiQuestions.length,
|
||||
total: 0,
|
||||
answeredCount: 0,
|
||||
progress: 0,
|
||||
timeRemaining: 30 * 60, // 30分钟
|
||||
timeRemaining: MBTI_TIME_SEC,
|
||||
_initialSeconds: MBTI_TIME_SEC,
|
||||
formatTime: '30:00',
|
||||
isSubmitting: false,
|
||||
canAccess: false
|
||||
@@ -23,17 +27,34 @@ Page({
|
||||
timer: null,
|
||||
|
||||
onLoad() {
|
||||
const questions = shuffleQuestions(mbtiQuestions)
|
||||
const total = questions.length
|
||||
this.setData({
|
||||
questions,
|
||||
currentQuestion: questions[0],
|
||||
canAccess: true,
|
||||
total,
|
||||
progress: total ? Math.round((1 / total) * 100) : 0
|
||||
})
|
||||
try { require('../../utils/analytics').track('test_start', { type: 'mbti', total }) } catch (e) {}
|
||||
this.startTimer()
|
||||
loadQuestions('mbti', {})
|
||||
.then((questions) => {
|
||||
const total = questions.length
|
||||
if (!total) {
|
||||
wx.showToast({ title: '暂无题目', icon: 'none' })
|
||||
this.setData({ loading: false })
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
loading: false,
|
||||
questions,
|
||||
currentQuestion: questions[0],
|
||||
canAccess: true,
|
||||
total,
|
||||
progress: Math.round((1 / total) * 100),
|
||||
timeRemaining: MBTI_TIME_SEC,
|
||||
_initialSeconds: MBTI_TIME_SEC,
|
||||
formatTime: '30:00'
|
||||
})
|
||||
try {
|
||||
require('../../utils/analytics').track('test_start', { type: 'mbti', total })
|
||||
} catch (e) {}
|
||||
this.startTimer()
|
||||
})
|
||||
.catch((err) => {
|
||||
this.setData({ loading: false })
|
||||
wx.showToast({ title: (err && err.message) || '加载失败', icon: 'none' })
|
||||
})
|
||||
},
|
||||
|
||||
// 检查访问权限
|
||||
@@ -197,7 +218,7 @@ Page({
|
||||
const resultData = {
|
||||
...result,
|
||||
answers: this.data.answers,
|
||||
testDuration: 30 * 60 - this.data.timeRemaining,
|
||||
testDuration: (this.data._initialSeconds || MBTI_TIME_SEC) - this.data.timeRemaining,
|
||||
completedAt: new Date().toISOString(),
|
||||
timestamp: new Date().toISOString()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<!--pages/test/mbti.wxml - MBTI测试页面(按旧版模板重构)-->
|
||||
<view class="test-page">
|
||||
<view wx:if="{{loading}}" class="test-loading">
|
||||
<text class="test-loading-text">加载题目…</text>
|
||||
</view>
|
||||
<block wx:elif="{{currentQuestion}}">
|
||||
<view class="progress-section">
|
||||
<view class="progress-info">
|
||||
<text class="question-count">问题 {{currentIndex + 1}}/{{total}}</text>
|
||||
@@ -45,4 +49,5 @@
|
||||
<text class="button-text button-text-on-primary">{{isSubmitting ? '正在生成…' : '查看结果'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
@@ -7,6 +7,19 @@
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.test-loading {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 80rpx;
|
||||
}
|
||||
|
||||
.test-loading-text {
|
||||
font-size: 30rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.progress-section {
|
||||
padding: 32rpx;
|
||||
border-bottom: 1rpx solid #e5e5e5;
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
// pages/test/pdp.js
|
||||
const { pdpQuestions, shuffleQuestions } = require('../../utils/questions')
|
||||
const { loadQuestions } = require('../../utils/questionBank')
|
||||
const { pdpDescriptions } = require('../../utils/descriptions')
|
||||
const app = getApp()
|
||||
|
||||
const PDP_TIME_SEC = 15 * 60
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: true,
|
||||
questions: [],
|
||||
currentIndex: 0,
|
||||
currentQuestion: null,
|
||||
answers: {},
|
||||
selectedAnswer: null,
|
||||
total: pdpQuestions.length,
|
||||
total: 0,
|
||||
answeredCount: 0,
|
||||
progress: 0,
|
||||
timeRemaining: 15 * 60,
|
||||
timeRemaining: PDP_TIME_SEC,
|
||||
_initialSeconds: PDP_TIME_SEC,
|
||||
formatTime: '15:00',
|
||||
isSubmitting: false
|
||||
},
|
||||
@@ -21,10 +25,31 @@ Page({
|
||||
timer: null,
|
||||
|
||||
onLoad() {
|
||||
const questions = shuffleQuestions(pdpQuestions)
|
||||
this.setData({ questions, currentQuestion: questions[0] })
|
||||
try { require('../../utils/analytics').track('test_start', { type: 'pdp', total: questions.length }) } catch (e) {}
|
||||
this.startTimer()
|
||||
loadQuestions('pdp', {})
|
||||
.then((questions) => {
|
||||
if (!questions.length) {
|
||||
wx.showToast({ title: '暂无题目', icon: 'none' })
|
||||
this.setData({ loading: false })
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
loading: false,
|
||||
questions,
|
||||
currentQuestion: questions[0],
|
||||
total: questions.length,
|
||||
timeRemaining: PDP_TIME_SEC,
|
||||
_initialSeconds: PDP_TIME_SEC,
|
||||
formatTime: '15:00'
|
||||
})
|
||||
try {
|
||||
require('../../utils/analytics').track('test_start', { type: 'pdp', total: questions.length })
|
||||
} catch (e) {}
|
||||
this.startTimer()
|
||||
})
|
||||
.catch((err) => {
|
||||
this.setData({ loading: false })
|
||||
wx.showToast({ title: (err && err.message) || '加载失败', icon: 'none' })
|
||||
})
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
@@ -151,7 +176,7 @@ Page({
|
||||
dominantType,
|
||||
secondaryType,
|
||||
description: pdpDescriptions[dominantType],
|
||||
testDuration: 15 * 60 - this.data.timeRemaining,
|
||||
testDuration: (this.data._initialSeconds || PDP_TIME_SEC) - this.data.timeRemaining,
|
||||
completedAt: new Date().toISOString(),
|
||||
// 便于后端留存完整答题过程
|
||||
answers: this.data.answers
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<!--pages/test/pdp.wxml - PDP测试页面(按旧版模板重构)-->
|
||||
<view class="test-page">
|
||||
<view wx:if="{{loading}}" class="test-loading">
|
||||
<text class="test-loading-text">加载题目…</text>
|
||||
</view>
|
||||
<block wx:elif="{{currentQuestion}}">
|
||||
<view class="progress-section">
|
||||
<view class="progress-info">
|
||||
<text class="question-count">问题 {{currentIndex + 1}}/{{total}}</text>
|
||||
@@ -45,4 +49,5 @@
|
||||
<text class="submit-text">{{isSubmitting ? '计算中...' : '完成测试,查看结果'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
@@ -7,6 +7,19 @@
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.test-loading {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 80rpx;
|
||||
}
|
||||
|
||||
.test-loading-text {
|
||||
font-size: 30rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.progress-section {
|
||||
padding: 32rpx;
|
||||
border-bottom: 1rpx solid #e5e5e5;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* 从服务端拉取启用题库,失败或为空时回落本地 questions.js;顺序由 shuffleQuestions 随机。
|
||||
* 仅从服务端拉取启用题库(/api/test/questions),无本地题目保底。
|
||||
* enterpriseId:未传时与 test/submit 一致,见 enterpriseContext.getEnterpriseIdForApiPayload()
|
||||
*/
|
||||
const { requestPromise } = require('./request')
|
||||
const { shuffleQuestions } = require('./questions')
|
||||
|
||||
function getAppSafe() {
|
||||
try {
|
||||
@@ -12,7 +12,45 @@ function getAppSafe() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 与 runtime 一致:>0 时在乱序后截取前 N 题 */
|
||||
/**
|
||||
* Fisher-Yates:打乱题目顺序,并随机每题选项顺序(深拷贝)
|
||||
* @param {Array} questions
|
||||
* @returns {Array}
|
||||
*/
|
||||
function shuffleQuestions(questions) {
|
||||
const arr = (questions || []).map(q => ({
|
||||
...q,
|
||||
options: (q.options || []).slice().sort(() => Math.random() - 0.5)
|
||||
}))
|
||||
for (let i = arr.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1))
|
||||
;[arr[i], arr[j]] = [arr[j], arr[i]]
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ enterpriseId?: number|null }} opts
|
||||
* @returns {number|null}
|
||||
*/
|
||||
function resolveEnterpriseIdForQuestionBank(opts) {
|
||||
const o = opts || {}
|
||||
if (Object.prototype.hasOwnProperty.call(o, 'enterpriseId')) {
|
||||
const v = o.enterpriseId
|
||||
if (v == null || v === '') {
|
||||
return null
|
||||
}
|
||||
const n = Number(v)
|
||||
return Number.isFinite(n) && n > 0 ? n : null
|
||||
}
|
||||
try {
|
||||
const { getEnterpriseIdForApiPayload } = require('./enterpriseContext')
|
||||
return getEnterpriseIdForApiPayload()
|
||||
} catch (e) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function getTestQuestionDrawCount() {
|
||||
const app = getAppSafe()
|
||||
const n = app && app.globalData && app.globalData.testQuestionDrawCount
|
||||
@@ -60,23 +98,21 @@ function fetchQuestionBank(type, enterpriseId) {
|
||||
|
||||
/**
|
||||
* @param {'mbti'|'disc'|'pdp'} type
|
||||
* @param {Array} localQuestions
|
||||
* @param {{ enterpriseId?: number|null }} opts
|
||||
* @returns {Promise<Array>}
|
||||
* @returns {Promise<Array>} 乱序后的题目;接口无题或失败则 reject
|
||||
*/
|
||||
function loadQuestionsWithFallback(type, localQuestions, opts = {}) {
|
||||
const { enterpriseId } = opts
|
||||
return fetchQuestionBank(type, enterpriseId)
|
||||
.then((list) => {
|
||||
if (!list.length) {
|
||||
return applyDrawCountAfterShuffle(shuffleQuestions(localQuestions))
|
||||
}
|
||||
return shuffleQuestions(list)
|
||||
})
|
||||
.catch(() => applyDrawCountAfterShuffle(shuffleQuestions(localQuestions)))
|
||||
function loadQuestions(type, opts = {}) {
|
||||
const enterpriseId = resolveEnterpriseIdForQuestionBank(opts)
|
||||
return fetchQuestionBank(type, enterpriseId).then((list) => {
|
||||
if (!list.length) {
|
||||
throw new Error('暂无启用题目')
|
||||
}
|
||||
return applyDrawCountAfterShuffle(shuffleQuestions(list))
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchQuestionBank,
|
||||
loadQuestionsWithFallback
|
||||
loadQuestions,
|
||||
shuffleQuestions
|
||||
}
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
// utils/questions.js - 测试题库
|
||||
|
||||
// MBTI测试题(精简版30题,每个维度约7-8题)
|
||||
const mbtiQuestions = [
|
||||
// E vs I 维度 (8题)
|
||||
{ id: 1, question: "在社交场合中,您通常会:", dimension: "EI", options: [{ value: "E", text: "认识新朋友,扩大社交圈" }, { value: "I", text: "与已认识的朋友交流" }] },
|
||||
{ id: 2, question: "您更喜欢:", dimension: "EI", options: [{ value: "E", text: "在团队中工作" }, { value: "I", text: "独立工作" }] },
|
||||
{ id: 3, question: "当您需要充电时,您会选择:", dimension: "EI", options: [{ value: "E", text: "与朋友聚会" }, { value: "I", text: "独处休息" }] },
|
||||
{ id: 4, question: "在会议中,您通常:", dimension: "EI", options: [{ value: "E", text: "积极发言" }, { value: "I", text: "先思考再发表" }] },
|
||||
{ id: 5, question: "您更倾向于:", dimension: "EI", options: [{ value: "E", text: "认识很多人" }, { value: "I", text: "与少数人深交" }] },
|
||||
{ id: 6, question: "面对问题时,您更倾向于:", dimension: "EI", options: [{ value: "E", text: "与他人讨论" }, { value: "I", text: "独自思考" }] },
|
||||
{ id: 7, question: "您更喜欢的休闲活动是:", dimension: "EI", options: [{ value: "E", text: "团体活动" }, { value: "I", text: "个人爱好" }] },
|
||||
{ id: 8, question: "在陌生环境中,您通常会:", dimension: "EI", options: [{ value: "E", text: "主动与人交谈" }, { value: "I", text: "观察周围环境" }] },
|
||||
|
||||
// S vs N 维度 (7题)
|
||||
{ id: 9, question: "您更关注:", dimension: "SN", options: [{ value: "S", text: "具体的细节和事实" }, { value: "N", text: "整体概念和可能性" }] },
|
||||
{ id: 10, question: "您更信任:", dimension: "SN", options: [{ value: "S", text: "实际经验" }, { value: "N", text: "直觉和灵感" }] },
|
||||
{ id: 11, question: "您更喜欢:", dimension: "SN", options: [{ value: "S", text: "按步骤执行" }, { value: "N", text: "创造性解决" }] },
|
||||
{ id: 12, question: "学习新事物时,您更喜欢:", dimension: "SN", options: [{ value: "S", text: "实际操作" }, { value: "N", text: "理论学习" }] },
|
||||
{ id: 13, question: "您更喜欢的工作类型是:", dimension: "SN", options: [{ value: "S", text: "明确的任务" }, { value: "N", text: "创新的项目" }] },
|
||||
{ id: 14, question: "您描述事物时更倾向于:", dimension: "SN", options: [{ value: "S", text: "具体描述" }, { value: "N", text: "使用比喻" }] },
|
||||
{ id: 15, question: "您更关心:", dimension: "SN", options: [{ value: "S", text: "当下的现实" }, { value: "N", text: "未来的可能" }] },
|
||||
|
||||
// T vs F 维度 (8题)
|
||||
{ id: 16, question: "做决定时,您更依赖:", dimension: "TF", options: [{ value: "T", text: "逻辑分析" }, { value: "F", text: "个人价值" }] },
|
||||
{ id: 17, question: "在争论中,您更看重:", dimension: "TF", options: [{ value: "T", text: "事实真相" }, { value: "F", text: "和谐关系" }] },
|
||||
{ id: 18, question: "给予反馈时,您更注重:", dimension: "TF", options: [{ value: "T", text: "直接指出问题" }, { value: "F", text: "考虑对方感受" }] },
|
||||
{ id: 19, question: "评估方案时,您更关注:", dimension: "TF", options: [{ value: "T", text: "效率和结果" }, { value: "F", text: "对人的影响" }] },
|
||||
{ id: 20, question: "当朋友遇到困难时,您更倾向于:", dimension: "TF", options: [{ value: "T", text: "分析问题提供建议" }, { value: "F", text: "倾听并给予支持" }] },
|
||||
{ id: 21, question: "您更欣赏的品质是:", dimension: "TF", options: [{ value: "T", text: "理性客观" }, { value: "F", text: "善解人意" }] },
|
||||
{ id: 22, question: "您认为好的决定应该:", dimension: "TF", options: [{ value: "T", text: "基于客观分析" }, { value: "F", text: "考虑各方感受" }] },
|
||||
{ id: 23, question: "当与他人意见不同时,您更倾向于:", dimension: "TF", options: [{ value: "T", text: "坚持正确观点" }, { value: "F", text: "寻求共识" }] },
|
||||
|
||||
// J vs P 维度 (7题)
|
||||
{ id: 24, question: "您更喜欢的工作方式是:", dimension: "JP", options: [{ value: "J", text: "有计划地进行" }, { value: "P", text: "随机应变" }] },
|
||||
{ id: 25, question: "对于截止日期,您通常:", dimension: "JP", options: [{ value: "J", text: "提前完成" }, { value: "P", text: "在最后完成" }] },
|
||||
{ id: 26, question: "您的生活方式更倾向于:", dimension: "JP", options: [{ value: "J", text: "有条理有规律" }, { value: "P", text: "灵活随意" }] },
|
||||
{ id: 27, question: "面对选择时,您更倾向于:", dimension: "JP", options: [{ value: "J", text: "快速做出决定" }, { value: "P", text: "保持开放选项" }] },
|
||||
{ id: 28, question: "您的桌面通常是:", dimension: "JP", options: [{ value: "J", text: "整洁有序" }, { value: "P", text: "创意性混乱" }] },
|
||||
{ id: 29, question: "计划改变时,您的反应是:", dimension: "JP", options: [{ value: "J", text: "感到不安" }, { value: "P", text: "觉得有趣" }] },
|
||||
{ id: 30, question: "您更喜欢:", dimension: "JP", options: [{ value: "J", text: "事先规划" }, { value: "P", text: "即兴发挥" }] }
|
||||
]
|
||||
|
||||
// DISC测试题 (20题)
|
||||
const discQuestions = [
|
||||
{ id: 1, question: "在团队中,您更倾向于:", options: [{ value: "D", text: "主导决策,带领团队" }, { value: "I", text: "活跃气氛,激励成员" }, { value: "S", text: "支持他人,确保和谐" }, { value: "C", text: "分析数据,确保质量" }] },
|
||||
{ id: 2, question: "面对挑战时,您的第一反应是:", options: [{ value: "D", text: "立即行动" }, { value: "I", text: "寻找支持" }, { value: "S", text: "冷静思考" }, { value: "C", text: "收集信息" }] },
|
||||
{ id: 3, question: "您在工作中最看重的是:", options: [{ value: "D", text: "成果和效率" }, { value: "I", text: "认可和赞赏" }, { value: "S", text: "稳定和安全" }, { value: "C", text: "准确和质量" }] },
|
||||
{ id: 4, question: "与他人沟通时,您通常:", options: [{ value: "D", text: "直接了当" }, { value: "I", text: "热情友好" }, { value: "S", text: "耐心倾听" }, { value: "C", text: "逻辑清晰" }] },
|
||||
{ id: 5, question: "压力之下,您会:", options: [{ value: "D", text: "更加强势" }, { value: "I", text: "寻求鼓励" }, { value: "S", text: "保持冷静" }, { value: "C", text: "更加谨慎" }] },
|
||||
{ id: 6, question: "您认为自己的优势是:", options: [{ value: "D", text: "决断力强" }, { value: "I", text: "人际关系好" }, { value: "S", text: "可靠稳定" }, { value: "C", text: "分析能力强" }] },
|
||||
{ id: 7, question: "在会议中,您通常扮演:", options: [{ value: "D", text: "主导者" }, { value: "I", text: "激励者" }, { value: "S", text: "调和者" }, { value: "C", text: "分析者" }] },
|
||||
{ id: 8, question: "您最不喜欢的工作环境是:", options: [{ value: "D", text: "进展缓慢" }, { value: "I", text: "被孤立" }, { value: "S", text: "变化太快" }, { value: "C", text: "混乱无序" }] },
|
||||
{ id: 9, question: "做决定时,您更依赖:", options: [{ value: "D", text: "直觉经验" }, { value: "I", text: "他人意见" }, { value: "S", text: "过去经验" }, { value: "C", text: "数据事实" }] },
|
||||
{ id: 10, question: "您的工作风格是:", options: [{ value: "D", text: "快速高效" }, { value: "I", text: "灵活多变" }, { value: "S", text: "稳定持续" }, { value: "C", text: "严谨细致" }] },
|
||||
{ id: 11, question: "遇到冲突时,您会:", options: [{ value: "D", text: "直面解决" }, { value: "I", text: "调解双方" }, { value: "S", text: "避免冲突" }, { value: "C", text: "分析原因" }] },
|
||||
{ id: 12, question: "您期望的领导风格是:", options: [{ value: "D", text: "给予挑战" }, { value: "I", text: "认可表扬" }, { value: "S", text: "稳定支持" }, { value: "C", text: "明确指导" }] },
|
||||
{ id: 13, question: "处理任务时,您更注重:", options: [{ value: "D", text: "速度效率" }, { value: "I", text: "创意新颖" }, { value: "S", text: "过程协作" }, { value: "C", text: "质量准确" }] },
|
||||
{ id: 14, question: "您的社交方式是:", options: [{ value: "D", text: "目的明确" }, { value: "I", text: "广泛社交" }, { value: "S", text: "深度交往" }, { value: "C", text: "选择性社交" }] },
|
||||
{ id: 15, question: "您理想的工作节奏是:", options: [{ value: "D", text: "快节奏" }, { value: "I", text: "灵活多变" }, { value: "S", text: "稳定有序" }, { value: "C", text: "有条理" }] },
|
||||
{ id: 16, question: "面对变化,您的态度是:", options: [{ value: "D", text: "主动拥抱" }, { value: "I", text: "积极适应" }, { value: "S", text: "需要时间" }, { value: "C", text: "谨慎评估" }] },
|
||||
{ id: 17, question: "您的时间管理风格是:", options: [{ value: "D", text: "高效利用" }, { value: "I", text: "灵活安排" }, { value: "S", text: "按部就班" }, { value: "C", text: "精确规划" }] },
|
||||
{ id: 18, question: "激励您的是:", options: [{ value: "D", text: "成就控制" }, { value: "I", text: "认可社交" }, { value: "S", text: "稳定归属" }, { value: "C", text: "正确标准" }] },
|
||||
{ id: 19, question: "您处理细节的方式是:", options: [{ value: "D", text: "关注大局" }, { value: "I", text: "可能忽略" }, { value: "S", text: "认真对待" }, { value: "C", text: "极度重视" }] },
|
||||
{ id: 20, question: "您对规则的态度是:", options: [{ value: "D", text: "灵活打破" }, { value: "I", text: "灵活运用" }, { value: "S", text: "遵守维护" }, { value: "C", text: "严格遵守" }] }
|
||||
]
|
||||
|
||||
// PDP测试题 (20题)
|
||||
const pdpQuestions = [
|
||||
{ id: 1, question: "面对紧急任务,您的第一反应是:", options: [{ value: "Tiger", text: "立即行动" }, { value: "Peacock", text: "召集团队" }, { value: "Koala", text: "冷静分析" }, { value: "Owl", text: "仔细规划" }, { value: "Chameleon", text: "灵活应对" }] },
|
||||
{ id: 2, question: "在社交场合,您通常会:", options: [{ value: "Tiger", text: "主导话题" }, { value: "Peacock", text: "活跃气氛" }, { value: "Koala", text: "安静倾听" }, { value: "Owl", text: "观察分析" }, { value: "Chameleon", text: "根据对象调整" }] },
|
||||
{ id: 3, question: "您最看重工作中的:", options: [{ value: "Tiger", text: "权力和成就" }, { value: "Peacock", text: "认可和赞赏" }, { value: "Koala", text: "稳定和和谐" }, { value: "Owl", text: "准确和质量" }, { value: "Chameleon", text: "平衡和适应" }] },
|
||||
{ id: 4, question: "处理冲突时,您倾向于:", options: [{ value: "Tiger", text: "直接解决" }, { value: "Peacock", text: "调解双方" }, { value: "Koala", text: "避免冲突" }, { value: "Owl", text: "理性处理" }, { value: "Chameleon", text: "视情况而定" }] },
|
||||
{ id: 5, question: "您的决策风格是:", options: [{ value: "Tiger", text: "果断迅速" }, { value: "Peacock", text: "直觉判断" }, { value: "Koala", text: "深思熟虑" }, { value: "Owl", text: "数据分析" }, { value: "Chameleon", text: "灵活决策" }] },
|
||||
{ id: 6, question: "面对压力,您会:", options: [{ value: "Tiger", text: "更加强势" }, { value: "Peacock", text: "寻求支持" }, { value: "Koala", text: "保持冷静" }, { value: "Owl", text: "更加谨慎" }, { value: "Chameleon", text: "调整策略" }] },
|
||||
{ id: 7, question: "您的领导风格是:", options: [{ value: "Tiger", text: "指挥型" }, { value: "Peacock", text: "激励型" }, { value: "Koala", text: "支持型" }, { value: "Owl", text: "专家型" }, { value: "Chameleon", text: "教练型" }] },
|
||||
{ id: 8, question: "您处理细节的方式是:", options: [{ value: "Tiger", text: "关注大局" }, { value: "Peacock", text: "可能忽略" }, { value: "Koala", text: "认真对待" }, { value: "Owl", text: "极度重视" }, { value: "Chameleon", text: "视情况决定" }] },
|
||||
{ id: 9, question: "您的沟通方式是:", options: [{ value: "Tiger", text: "直接简短" }, { value: "Peacock", text: "热情生动" }, { value: "Koala", text: "温和耐心" }, { value: "Owl", text: "逻辑清晰" }, { value: "Chameleon", text: "根据对象调整" }] },
|
||||
{ id: 10, question: "您对变化的态度是:", options: [{ value: "Tiger", text: "主动推动" }, { value: "Peacock", text: "积极拥抱" }, { value: "Koala", text: "需要适应" }, { value: "Owl", text: "谨慎评估" }, { value: "Chameleon", text: "随机应变" }] },
|
||||
{ id: 11, question: "您的时间管理风格是:", options: [{ value: "Tiger", text: "追求速度" }, { value: "Peacock", text: "灵活安排" }, { value: "Koala", text: "稳定执行" }, { value: "Owl", text: "精确规划" }, { value: "Chameleon", text: "根据情况调整" }] },
|
||||
{ id: 12, question: "您被什么激励:", options: [{ value: "Tiger", text: "成就权力" }, { value: "Peacock", text: "认可赞赏" }, { value: "Koala", text: "安全归属" }, { value: "Owl", text: "正确标准" }, { value: "Chameleon", text: "多样平衡" }] },
|
||||
{ id: 13, question: "您的学习方式是:", options: [{ value: "Tiger", text: "边做边学" }, { value: "Peacock", text: "互动讨论" }, { value: "Koala", text: "循序渐进" }, { value: "Owl", text: "深入研究" }, { value: "Chameleon", text: "多种结合" }] },
|
||||
{ id: 14, question: "您对规则的态度是:", options: [{ value: "Tiger", text: "灵活打破" }, { value: "Peacock", text: "不拘一格" }, { value: "Koala", text: "遵守维护" }, { value: "Owl", text: "严格遵守" }, { value: "Chameleon", text: "灵活处理" }] },
|
||||
{ id: 15, question: "您在团队中的角色是:", options: [{ value: "Tiger", text: "领导者" }, { value: "Peacock", text: "激励者" }, { value: "Koala", text: "协调者" }, { value: "Owl", text: "专家" }, { value: "Chameleon", text: "多面手" }] },
|
||||
{ id: 16, question: "您的工作节奏是:", options: [{ value: "Tiger", text: "快节奏" }, { value: "Peacock", text: "充满活力" }, { value: "Koala", text: "稳定有序" }, { value: "Owl", text: "有条理" }, { value: "Chameleon", text: "灵活调整" }] },
|
||||
{ id: 17, question: "您最大的优势是:", options: [{ value: "Tiger", text: "执行力" }, { value: "Peacock", text: "影响力" }, { value: "Koala", text: "可靠性" }, { value: "Owl", text: "准确性" }, { value: "Chameleon", text: "适应力" }] },
|
||||
{ id: 18, question: "您的人际关系特点是:", options: [{ value: "Tiger", text: "目标导向" }, { value: "Peacock", text: "朋友众多" }, { value: "Koala", text: "关系稳定" }, { value: "Owl", text: "志同道合" }, { value: "Chameleon", text: "灵活建立" }] },
|
||||
{ id: 19, question: "面对批评,您的反应是:", options: [{ value: "Tiger", text: "可能反驳" }, { value: "Peacock", text: "可能受伤" }, { value: "Koala", text: "接受思考" }, { value: "Owl", text: "分析合理性" }, { value: "Chameleon", text: "灵活调整" }] },
|
||||
{ id: 20, question: "您的理想工作环境是:", options: [{ value: "Tiger", text: "充满挑战" }, { value: "Peacock", text: "互动频繁" }, { value: "Koala", text: "稳定和谐" }, { value: "Owl", text: "有序规范" }, { value: "Chameleon", text: "灵活多变" }] }
|
||||
]
|
||||
|
||||
/**
|
||||
* Fisher-Yates 洗牌:随机打乱题目顺序,同时随机打乱每题的选项顺序
|
||||
* 不修改原数组,返回深拷贝后的新数组
|
||||
* @param {Array} questions - 原题目数组
|
||||
* @returns {Array} 打乱后的题目数组
|
||||
*/
|
||||
function shuffleQuestions(questions) {
|
||||
// 深拷贝,避免污染原始数组
|
||||
const arr = questions.map(q => ({
|
||||
...q,
|
||||
options: q.options.slice().sort(() => Math.random() - 0.5)
|
||||
}))
|
||||
// Fisher-Yates 打乱题目顺序
|
||||
for (let i = arr.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[arr[i], arr[j]] = [arr[j], arr[i]]
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mbtiQuestions,
|
||||
discQuestions,
|
||||
pdpQuestions,
|
||||
shuffleQuestions
|
||||
}
|
||||
@@ -8,6 +8,168 @@ function toIntPercent(value) {
|
||||
return Number.isFinite(n) ? Math.round(n) : 0
|
||||
}
|
||||
|
||||
const PDP_EN_TO_CN = {
|
||||
Tiger: '老虎型',
|
||||
Peacock: '孔雀型',
|
||||
Koala: '考拉型',
|
||||
Owl: '猫头鹰型',
|
||||
Chameleon: '变色龙型'
|
||||
}
|
||||
|
||||
function pdpOrderedFromScores(scores) {
|
||||
if (!scores || typeof scores !== 'object') return ['', '']
|
||||
const pairs = []
|
||||
for (const k of Object.keys(scores)) {
|
||||
if (!PDP_EN_TO_CN[k]) continue
|
||||
pairs.push([k, Number(scores[k]) || 0])
|
||||
}
|
||||
pairs.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
||||
return [pairs[0] ? pairs[0][0] : '', pairs[1] ? pairs[1][0] : '']
|
||||
}
|
||||
|
||||
function discOrderedFromScores(scores) {
|
||||
if (!scores || typeof scores !== 'object') return ['', '']
|
||||
const allow = { D: 1, I: 1, S: 1, C: 1 }
|
||||
const pairs = []
|
||||
for (const k of Object.keys(scores)) {
|
||||
const u = String(k).trim().toUpperCase().charAt(0)
|
||||
if (!allow[u]) continue
|
||||
pairs.push([u, Number(scores[k]) || 0])
|
||||
}
|
||||
pairs.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
||||
return [pairs[0] ? pairs[0][0] : '', pairs[1] ? pairs[1][0] : '']
|
||||
}
|
||||
|
||||
/** 与 scores 相同维度;DISC 接口常以 percentages 存四维而无 scores */
|
||||
function discOrderedFromPercentages(pct) {
|
||||
return discOrderedFromScores(pct)
|
||||
}
|
||||
|
||||
/** DISC:「S+I型」,仅最后一项带「型」 */
|
||||
function discPrimaryLetter(data) {
|
||||
if (!data || typeof data !== 'object') return ''
|
||||
const dType = data.description && data.description.type
|
||||
if (typeof dType === 'string' && dType) {
|
||||
const noXing = String(dType).trim().replace(/型$/, '')
|
||||
if (noXing.length === 1) {
|
||||
const u = noXing.toUpperCase()
|
||||
if (['D', 'I', 'S', 'C'].includes(u)) return u
|
||||
}
|
||||
}
|
||||
if (data.dominantType) {
|
||||
const u = String(data.dominantType).trim().toUpperCase().charAt(0)
|
||||
if (['D', 'I', 'S', 'C'].includes(u)) return u
|
||||
}
|
||||
if (data.disc) {
|
||||
const noXing = String(data.disc).trim().replace(/型$/, '')
|
||||
if (noXing.length === 1) {
|
||||
const u = noXing.toUpperCase()
|
||||
if (['D', 'I', 'S', 'C'].includes(u)) return u
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
function discResolveTwoLetters(data) {
|
||||
let f = discPrimaryLetter(data)
|
||||
let s = ''
|
||||
if (data.secondaryType) {
|
||||
const u = String(data.secondaryType).trim().toUpperCase().charAt(0)
|
||||
if (['D', 'I', 'S', 'C'].includes(u)) s = u
|
||||
}
|
||||
let a0 = ''
|
||||
let b = ''
|
||||
if (data.scores && typeof data.scores === 'object') {
|
||||
const ord = discOrderedFromScores(data.scores)
|
||||
a0 = ord[0] || ''
|
||||
b = ord[1] || ''
|
||||
}
|
||||
if (!a0 && !b && data.percentages && typeof data.percentages === 'object') {
|
||||
const ord = discOrderedFromPercentages(data.percentages)
|
||||
a0 = ord[0] || ''
|
||||
b = ord[1] || ''
|
||||
}
|
||||
if (!f && a0) f = a0
|
||||
if (!s || s === f) {
|
||||
if (b && b !== f) s = b
|
||||
else s = ''
|
||||
}
|
||||
return [f, s]
|
||||
}
|
||||
|
||||
/** 旧接口/库存:「S型 + I型」「S型+I型」→ S+I型 */
|
||||
function discNormalizeLegacyDualType(desc) {
|
||||
if (typeof desc !== 'string' || !desc) return ''
|
||||
const t = desc.replace(/\s+/g, '').replace(/\uFF0B/g, '+')
|
||||
let m = t.match(/^([DISC])型\+([DISC])型$/i)
|
||||
if (m) return m[1].toUpperCase() + '+' + m[2].toUpperCase() + '型'
|
||||
m = t.match(/^([DISC])型$/i)
|
||||
if (m) return m[1].toUpperCase() + '型'
|
||||
return ''
|
||||
}
|
||||
|
||||
function discTopTwoLabel(data) {
|
||||
if (!data || typeof data !== 'object') return ''
|
||||
const [fL, sL] = discResolveTwoLetters(data)
|
||||
if (fL || sL) {
|
||||
if (!fL) return sL ? sL + '型' : ''
|
||||
if (!sL || sL === fL) return fL + '型'
|
||||
return fL + '+' + sL + '型'
|
||||
}
|
||||
return discNormalizeLegacyDualType(data.description && data.description.type)
|
||||
}
|
||||
|
||||
function pdpPrimaryFull(data) {
|
||||
if (!data || typeof data !== 'object') return ''
|
||||
const desc = data.description && data.description.type
|
||||
if (typeof desc === 'string' && desc) return desc.trim()
|
||||
if (data.dominantType) {
|
||||
const key = String(data.dominantType).trim()
|
||||
return PDP_EN_TO_CN[key] || key
|
||||
}
|
||||
if (data.pdp) return String(data.pdp).trim()
|
||||
return ''
|
||||
}
|
||||
|
||||
function pdpResolveTwoFull(data) {
|
||||
let f = pdpPrimaryFull(data)
|
||||
let s = ''
|
||||
if (data.secondaryType) {
|
||||
const k = String(data.secondaryType).trim()
|
||||
s = PDP_EN_TO_CN[k] || k
|
||||
}
|
||||
let aEn = ''
|
||||
let bEn = ''
|
||||
if (data.scores && typeof data.scores === 'object') {
|
||||
const ord = pdpOrderedFromScores(data.scores)
|
||||
aEn = ord[0] || ''
|
||||
bEn = ord[1] || ''
|
||||
}
|
||||
if (!aEn && !bEn && data.percentages && typeof data.percentages === 'object') {
|
||||
const ord = pdpOrderedFromScores(data.percentages)
|
||||
aEn = ord[0] || ''
|
||||
bEn = ord[1] || ''
|
||||
}
|
||||
if (!f && aEn) f = PDP_EN_TO_CN[aEn] || aEn
|
||||
if (!s || s === f) {
|
||||
if (bEn) {
|
||||
const cand = PDP_EN_TO_CN[bEn] || bEn
|
||||
if (cand !== f) s = cand
|
||||
}
|
||||
}
|
||||
return [f, s]
|
||||
}
|
||||
|
||||
/** PDP:「孔雀+老虎型」,仅最后一项带「型」 */
|
||||
function pdpTopTwoLabel(data) {
|
||||
if (!data || typeof data !== 'object') return ''
|
||||
const [ff, sf] = pdpResolveTwoFull(data)
|
||||
if (!ff) return sf || ''
|
||||
if (!sf || sf === ff) return ff
|
||||
const short = String(ff).replace(/型$/, '')
|
||||
return short + '+' + sf
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据测试类型和原始结果,生成带整数百分比的摘要文案
|
||||
* @param {object} data - 单条测试结果(mbtiResult / discResult / pdpResult)
|
||||
@@ -34,8 +196,9 @@ function formatTestSummary(data, testType) {
|
||||
}
|
||||
|
||||
if (t === 'disc') {
|
||||
const two = discTopTwoLabel(data)
|
||||
const desc = data.description && data.description.type
|
||||
const label = (typeof desc === 'string' && desc) ? desc : ((data.dominantType ? data.dominantType + '型' : '') || (data.disc || ''))
|
||||
const label = two || ((typeof desc === 'string' && desc) ? desc : ((data.dominantType ? data.dominantType + '型' : '') || (data.disc || '')))
|
||||
const pct = data.percentages
|
||||
if (pct && typeof pct === 'object') {
|
||||
const d = toIntPercent(pct.D != null ? pct.D : pct.d)
|
||||
@@ -48,8 +211,9 @@ function formatTestSummary(data, testType) {
|
||||
}
|
||||
|
||||
if (t === 'pdp') {
|
||||
const two = pdpTopTwoLabel(data)
|
||||
const desc = data.description && data.description.type
|
||||
const label = (typeof desc === 'string' && desc) ? desc : (data.dominantType || data.pdp || '')
|
||||
const label = two || ((typeof desc === 'string' && desc) ? desc : (data.dominantType || data.pdp || ''))
|
||||
const pct = data.percentages
|
||||
if (pct && typeof pct === 'object') {
|
||||
const names = { Tiger: '老虎', Peacock: '孔雀', Owl: '猫头鹰', Koala: '考拉', Chameleon: '变色龙' }
|
||||
@@ -74,15 +238,22 @@ function getTypeOnly(data, testType) {
|
||||
const t = (testType || '').toLowerCase()
|
||||
if (t === 'mbti') return String(data.mbtiType ?? data.type ?? data.result ?? '')
|
||||
if (t === 'disc') {
|
||||
const two = discTopTwoLabel(data)
|
||||
if (two) return two
|
||||
const desc = data.description?.type
|
||||
if (typeof desc === 'string' && desc) return desc
|
||||
if (data.dominantType) return String(data.dominantType) + '型'
|
||||
return String(data.disc ?? '')
|
||||
}
|
||||
if (t === 'pdp') {
|
||||
const two = pdpTopTwoLabel(data)
|
||||
if (two) return two
|
||||
const desc = data.description?.type
|
||||
if (typeof desc === 'string' && desc) return desc
|
||||
if (data.dominantType) return String(data.dominantType)
|
||||
if (data.dominantType) {
|
||||
const k = String(data.dominantType).trim()
|
||||
return PDP_EN_TO_CN[k] || k
|
||||
}
|
||||
return String(data.pdp ?? '')
|
||||
}
|
||||
return ''
|
||||
@@ -91,5 +262,7 @@ function getTypeOnly(data, testType) {
|
||||
module.exports = {
|
||||
toIntPercent,
|
||||
formatTestSummary,
|
||||
getTypeOnly
|
||||
getTypeOnly,
|
||||
discTopTwoLabel,
|
||||
pdpTopTwoLabel
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user