diff --git a/.kiro/settings/mcp.json b/.kiro/settings/mcp.json
index 1cbd4f7..fb0fbc2 100644
--- a/.kiro/settings/mcp.json
+++ b/.kiro/settings/mcp.json
@@ -50,6 +50,21 @@
"autoApprove": [
"execute_sql"
]
+ },
+ "lanhu": {
+ "url": "http://localhost:8000/mcp?role=开发&name=developer",
+ "disabled": false,
+ "autoApprove": [
+ "lanhu_get_pages",
+ "lanhu_get_designs",
+ "lanhu_get_design_slices",
+ "lanhu_get_ai_analyze_page_result",
+ "lanhu_get_ai_analyze_design_result",
+ "lanhu_resolve_invite_link",
+ "lanhu_say_list",
+ "lanhu_say_detail",
+ "lanhu_get_members"
+ ]
}
}
}
\ No newline at end of file
diff --git a/uniapp/pages/assessment/info/index.vue b/uniapp/pages/assessment/info/index.vue
index 739748c..a7c4989 100644
--- a/uniapp/pages/assessment/info/index.vue
+++ b/uniapp/pages/assessment/info/index.vue
@@ -3,14 +3,14 @@
* 测评信息填写页面
*
* 功能:
- * - 顶部测评介绍区域
+ * - 顶部 banner 插画区域
* - 表单填写:姓名、手机号、性别、年龄、学业阶段、省市区
* - 支付测评和邀请码免费测评两个入口
* - 邀请码验证弹窗
*/
-import { ref, computed, onMounted } from 'vue'
-import { onLoad } from '@dcloudio/uni-app'
+import { ref, computed, watch } from 'vue'
+import { onLoad, onUnload } from '@dcloudio/uni-app'
import { useUserStore } from '@/store/user.js'
import { useAuth } from '@/composables/useAuth.js'
import { usePayment } from '@/composables/usePayment.js'
@@ -53,17 +53,11 @@ const educationOptions = ['小学及以下', '初中', '高中', '大专', '本
/**
* 学业阶段文本转数值
- * @param {string} label - 学业阶段文本
- * @returns {number} 学段值:1小学 2初中 3高中 4大学
*/
function getEducationStageValue(label) {
const map = {
- '小学及以下': 1,
- '初中': 2,
- '高中': 3,
- '大专': 4,
- '本科': 4,
- '研究生及以上': 4
+ '小学及以下': 1, '初中': 2, '高中': 3,
+ '大专': 4, '本科': 4, '研究生及以上': 4
}
return map[label] || 1
}
@@ -84,6 +78,68 @@ const inviteLoading = ref(false)
// 页面加载状态
const pageLoading = ref(true)
+// 本地缓存 key
+const STORAGE_KEY = 'assessment_info_form'
+
+/**
+ * 保存表单数据到本地
+ */
+function saveFormToStorage() {
+ const data = {
+ ...formData.value,
+ genderIndex: genderIndex.value,
+ ageIndex: ageIndex.value,
+ educationIndex: educationIndex.value,
+ regionValue: regionValue.value
+ }
+ try {
+ uni.setStorageSync(STORAGE_KEY, JSON.stringify(data))
+ } catch (e) {
+ console.error('保存表单数据失败:', e)
+ }
+}
+
+/**
+ * 从本地还原表单数据
+ */
+function restoreFormFromStorage() {
+ try {
+ const raw = uni.getStorageSync(STORAGE_KEY)
+ if (!raw) return
+ const data = JSON.parse(raw)
+ formData.value.name = data.name || ''
+ formData.value.phone = data.phone || ''
+ formData.value.gender = data.gender || ''
+ formData.value.age = data.age || ''
+ formData.value.educationStage = data.educationStage || ''
+ formData.value.province = data.province || ''
+ formData.value.city = data.city || ''
+ formData.value.district = data.district || ''
+ genderIndex.value = data.genderIndex ?? -1
+ ageIndex.value = data.ageIndex ?? -1
+ educationIndex.value = data.educationIndex ?? -1
+ regionValue.value = data.regionValue || []
+ } catch (e) {
+ console.error('还原表单数据失败:', e)
+ }
+}
+
+/**
+ * 提交成功后清除缓存
+ */
+function clearFormStorage() {
+ try {
+ uni.removeStorageSync(STORAGE_KEY)
+ } catch (e) {
+ // ignore
+ }
+}
+
+// 监听表单变化,自动保存
+watch(formData, () => {
+ saveFormToStorage()
+}, { deep: true })
+
/**
* 表单是否填写完整
*/
@@ -122,33 +178,25 @@ async function loadIntro() {
}
}
-/**
- * 性别选择
- */
+/** 性别选择 */
function onGenderChange(e) {
genderIndex.value = e.detail.value
formData.value.gender = genderOptions[e.detail.value]
}
-/**
- * 年龄选择
- */
+/** 年龄选择 */
function onAgeChange(e) {
ageIndex.value = e.detail.value
formData.value.age = ageOptions[e.detail.value]
}
-/**
- * 学业阶段选择
- */
+/** 学业阶段选择 */
function onEducationChange(e) {
educationIndex.value = e.detail.value
formData.value.educationStage = educationOptions[e.detail.value]
}
-/**
- * 省市区选择
- */
+/** 省市区选择 */
function onRegionChange(e) {
const value = e.detail.value
regionValue.value = value
@@ -157,51 +205,44 @@ function onRegionChange(e) {
formData.value.district = value[2] || ''
}
-/**
- * 验证表单
- */
+/** 验证表单 */
function validateForm() {
- // 验证手机号格式
+ if (!formData.value.name.trim()) {
+ uni.showToast({ title: '请输入姓名', icon: 'none' })
+ return false
+ }
if (!isPhone(formData.value.phone)) {
- uni.showModal({
- title: '提示',
- content: '手机号格式有误',
- showCancel: false
- })
+ uni.showToast({ title: '手机号格式有误', icon: 'none' })
+ return false
+ }
+ if (!formData.value.gender) {
+ uni.showToast({ title: '请选择性别', icon: 'none' })
+ return false
+ }
+ if (!formData.value.age) {
+ uni.showToast({ title: '请选择年龄', icon: 'none' })
+ return false
+ }
+ if (!formData.value.educationStage) {
+ uni.showToast({ title: '请选择学业阶段', icon: 'none' })
return false
}
-
- // 验证区县是否选择
if (!formData.value.district) {
- uni.showModal({
- title: '提示',
- content: '请选择所在城市区县',
- showCancel: false
- })
+ uni.showToast({ title: '请选择所在城市', icon: 'none' })
return false
}
-
return true
}
-/**
- * 支付测评
- */
+/** 支付测评 */
async function handlePayAssessment() {
- if (!isFormComplete.value) return
-
- // 检查登录
if (!checkLogin()) return
-
- // 验证表单
if (!validateForm()) return
-
+
try {
uni.showLoading({ title: '创建订单中...' })
-
- // 发起支付
const result = await processPayment({
- orderType: 1, // 测评订单
+ orderType: 1,
productId: typeId.value,
assessmentInfo: {
name: formData.value.name,
@@ -214,312 +255,222 @@ async function handlePayAssessment() {
district: formData.value.district
}
})
-
uni.hideLoading()
-
+
if (result.success) {
- // 支付成功,跳转到答题页
+ clearFormStorage()
uni.redirectTo({
url: `/pages/assessment/questions/index?typeId=${typeId.value}&orderId=${result.orderId}`
})
} else if (result.error) {
- uni.showToast({
- title: result.error,
- icon: 'none'
- })
+ uni.showToast({ title: result.error, icon: 'none' })
}
} catch (error) {
uni.hideLoading()
console.error('支付失败:', error)
- uni.showToast({
- title: '支付失败,请重试',
- icon: 'none'
- })
+ uni.showToast({ title: '支付失败,请重试', icon: 'none' })
}
}
-/**
- * 打开邀请码弹窗
- */
+/** 打开邀请码弹窗 */
function openInvitePopup() {
- if (!isFormComplete.value) return
-
- // 检查登录
if (!checkLogin()) return
-
- // 验证表单
if (!validateForm()) return
-
inviteCode.value = ''
showInvitePopup.value = true
}
-/**
- * 关闭邀请码弹窗
- */
+/** 关闭邀请码弹窗 */
function closeInvitePopup() {
showInvitePopup.value = false
inviteCode.value = ''
}
-/**
- * 邀请码输入处理(自动转大写)
- */
+/** 邀请码输入处理 */
function onInviteCodeInput(e) {
inviteCode.value = e.detail.value.toUpperCase()
}
-/**
- * 提交邀请码
- */
+/** 提交邀请码 */
async function submitInviteCode() {
if (!inviteCode.value.trim()) {
- uni.showToast({
- title: '请输入邀请码',
- icon: 'none'
- })
+ uni.showToast({ title: '请输入邀请码', icon: 'none' })
return
}
-
+
inviteLoading.value = true
-
try {
const res = await verifyInviteCode(inviteCode.value.trim())
-
- if (res && res.code === 0) {
- // 检查邀请码是否有效
- if (res.data && res.data.isValid) {
- // 验证成功,关闭弹窗并跳转到答题页
- closeInvitePopup()
- uni.redirectTo({
- url: `/pages/assessment/questions/index?typeId=${typeId.value}&inviteCode=${inviteCode.value}`
- })
- } else {
- // 邀请码无效
- const errorMsg = res.data?.errorMessage || '邀请码有误,请重新输入'
- uni.showToast({
- title: errorMsg,
- icon: 'none'
- })
- }
+ if (res && res.code === 0 && res.data && res.data.isValid) {
+ closeInvitePopup()
+ clearFormStorage()
+ uni.redirectTo({
+ url: `/pages/assessment/questions/index?typeId=${typeId.value}&inviteCode=${inviteCode.value}`
+ })
} else {
- // 接口调用失败
- const errorMsg = res?.message || '验证失败,请重试'
uni.showToast({
- title: errorMsg,
+ title: res?.data?.errorMessage || res?.message || '邀请码有误,请重新输入',
icon: 'none'
})
}
} catch (error) {
console.error('验证邀请码失败:', error)
- uni.showToast({
- title: '验证失败,请重试',
- icon: 'none'
- })
+ uni.showToast({ title: '验证失败,请重试', icon: 'none' })
} finally {
inviteLoading.value = false
}
}
-/**
- * 页面加载
- */
+/** 页面加载 */
onLoad((options) => {
typeId.value = Number(options.typeId) || 1
typeName.value = decodeURIComponent(options.typeName || '')
-
- // 恢复用户登录状态
userStore.restoreFromStorage()
-
- // 如果已登录,预填手机号
- if (userStore.isLoggedIn && userStore.phone) {
+
+ // 还原本地缓存的表单数据
+ restoreFormFromStorage()
+
+ // 如果已登录且手机号为空,预填手机号
+ if (userStore.isLoggedIn && userStore.phone && !formData.value.phone) {
formData.value.phone = userStore.phone
}
-
+
loadIntro()
})
+
+/** 页面卸载时保存 */
+onUnload(() => {
+ saveFormToStorage()
+})
-
-
-
-
-
-
-
-
- {{ introData.title }}
- {{ introData.description }}
-
-
-
-
-
-
-
-
-
-
-
- *
- 姓名
-
-
-
-
-
-
-
-
-
- *
- 手机号
-
-
-
-
-
-
-
-
-
- *
- 性别
-
-
-
-
- {{ formData.gender || '请选择' }}
-
-
-
-
-
-
-
-
-
- *
- 年龄
-
-
-
-
- {{ formData.age || '请选择' }}
-
-
-
-
-
-
-
-
-
- *
- 学业阶段
-
-
-
-
- {{ formData.educationStage || '请选择' }}
-
-
-
-
-
-
-
-
-
- *
- 所在城市
-
-
-
-
-
- {{ formData.province || '省' }}
-
-
-
-
-
- {{ formData.city || '市' }}
-
-
-
-
-
- {{ formData.district || '区/县' }}
-
-
-
-
-
-
-
-
-
-
-
-
-
- 邀请码免费测评
-
-
-
-
- 支付¥{{ introData.price || 0 }}元开始测评
-
-
+
+
+
+
+
+
+
-
+
+
+
+ 正式测评前,请先填写您的基本信息
+
+
+
+ *姓名
+
+
+
+
+
+
+
+ *手机号
+
+
+
+
+
+
+
+ *姓别
+
+
+
+ {{ formData.gender || '请选择' }}
+
+
+
+
+
+
+
+
+ *年龄
+
+
+
+ {{ formData.age || '请选择' }}
+
+
+
+
+
+
+
+
+ *学业阶段
+
+
+
+ {{ formData.educationStage || '请选择' }}
+
+
+
+
+
+
+
+
+ *所在城市
+
+
+
+
+ {{ formData.province || '省' }}
+
+
+
+
+
+ {{ formData.city || '市' }}
+
+
+
+
+
+ {{ formData.district || '区/县' }}
+
+
+
+
+
+
+
+
+
+
+
+ 邀请码免费测评
+
+
+ 支付¥{{ introData.price || 20 }}元开始测评
+
+
+
-
- {
maxlength="5"
/>
-
-