user-edit.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. <template>
  2. <view class="user-edit-container">
  3. <view class="header">
  4. <text class="title">{{ isEdit ? '完善个人信息' : '选择角色' }}</text>
  5. <text class="subtitle">{{ isEdit ? '以下信息可帮助您更好地使用服务' : '请选择您的身份类型' }}</text>
  6. </view>
  7. <!-- 角色选择(新用户首次登录时显示) -->
  8. <view class="role-select-section" v-if="!isEdit && showRoleSelect">
  9. <view
  10. class="role-card"
  11. :class="{ active: form.role === 'parent' }"
  12. @click="selectRole('parent')"
  13. >
  14. <text class="role-icon">👨‍👩‍👧</text>
  15. <text class="role-name">家长</text>
  16. <text class="role-desc">管理孩子任务、审核奖励</text>
  17. </view>
  18. <view
  19. class="role-card"
  20. :class="{ active: form.role === 'child' }"
  21. @click="selectRole('child')"
  22. >
  23. <text class="role-icon">👶</text>
  24. <text class="role-name">孩子</text>
  25. <text class="role-desc">执行任务、赚取积分</text>
  26. </view>
  27. <view
  28. class="role-card"
  29. :class="{ active: form.role === 'teacher' }"
  30. @click="selectRole('teacher')"
  31. >
  32. <text class="role-icon">👨‍🏫</text>
  33. <text class="role-name">成长规划师</text>
  34. <text class="role-desc">DAN测评、制定成长方案</text>
  35. </view>
  36. <button class="btn-next" @click="confirmRole" :disabled="!form.role">
  37. 下一步
  38. </button>
  39. </view>
  40. <!-- 详细信息填写(选择角色后显示) -->
  41. <view class="form-section" v-if="isEdit">
  42. <!-- 头像 -->
  43. <view class="form-item avatar-item">
  44. <text class="label">头像</text>
  45. <view class="avatar-upload" @click="chooseAvatar">
  46. <image v-if="form.avatar" :src="form.avatar" class="avatar-preview"></image>
  47. <view v-else class="avatar-placeholder">
  48. <text class="iconfont icon-plus">+</text>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 昵称 -->
  53. <view class="form-item">
  54. <text class="label">昵称 <text class="required">*</text></text>
  55. <input type="text" v-model="form.nickname" placeholder="请输入昵称" class="input" maxlength="20" />
  56. </view>
  57. <!-- 真实姓名 -->
  58. <view class="form-item">
  59. <text class="label">真实姓名</text>
  60. <input type="text" v-model="form.realName" placeholder="选填,用于家庭管理" class="input" maxlength="20" />
  61. </view>
  62. <!-- 性别(成长规划师必填) -->
  63. <view class="form-item">
  64. <text class="label">性别 <text class="required" v-if="form.role === 'teacher'">*</text></text>
  65. <radio-group class="role-select" @change="onGenderChange">
  66. <label class="role-option">
  67. <radio value="male" :checked="form.gender === 'male'" />
  68. <text>男</text>
  69. </label>
  70. <label class="role-option">
  71. <radio value="female" :checked="form.gender === 'female'" />
  72. <text>女</text>
  73. </label>
  74. </radio-group>
  75. </view>
  76. <!-- 身份证号(成长规划师必填) -->
  77. <view class="form-item">
  78. <text class="label">身份证号 <text class="required" v-if="form.role === 'teacher'">*</text></text>
  79. <input type="idcard" v-model="form.idCard" placeholder="选填,填写后自动生成生日" class="input" maxlength="18" @input="onIdCardInput" />
  80. </view>
  81. <!-- 生日 -->
  82. <view class="form-item">
  83. <text class="label">生日</text>
  84. <picker mode="date" :value="form.birthday" @change="onBirthdayChange">
  85. <view class="picker-input">{{ form.birthday || '请选择生日' }}</view>
  86. </picker>
  87. </view>
  88. <!-- 出生时辰 -->
  89. <view class="form-item">
  90. <text class="label">出生时辰</text>
  91. <picker mode="selector" :range="birthHourOptions" :value="birthHourIndex" @change="onBirthHourChange">
  92. <view class="picker-input">{{ form.birthHour || '请选择出生时辰' }}</view>
  93. </picker>
  94. </view>
  95. <!-- 民族 -->
  96. <view class="form-item">
  97. <text class="label">民族</text>
  98. <picker mode="selector" :range="ethnicityOptions" :value="ethnicityIndex" @change="onEthnicityChange">
  99. <view class="picker-input">{{ form.ethnicity || '请选择民族' }}</view>
  100. </picker>
  101. </view>
  102. <!-- 血型 -->
  103. <view class="form-item">
  104. <text class="label">血型</text>
  105. <picker mode="selector" :range="bloodTypeOptions" :value="bloodTypeIndex" @change="onBloodTypeChange">
  106. <view class="picker-input">{{ form.bloodType || '请选择血型' }}</view>
  107. </picker>
  108. </view>
  109. <!-- 最高学历 -->
  110. <view class="form-item">
  111. <text class="label">最高学历</text>
  112. <picker mode="selector" :range="educationOptions" :value="educationIndex" @change="onEducationChange">
  113. <view class="picker-input">{{ form.highestEducation || '请选择最高学历' }}</view>
  114. </picker>
  115. </view>
  116. <!-- 婚姻状态 -->
  117. <view class="form-item">
  118. <text class="label">婚姻状态</text>
  119. <picker mode="selector" :range="maritalOptions" :value="maritalIndex" @change="onMaritalChange">
  120. <view class="picker-input">{{ form.maritalStatus || '请选择婚姻状态' }}</view>
  121. </picker>
  122. </view>
  123. <!-- 兴趣爱好 -->
  124. <view class="form-item">
  125. <text class="label">兴趣爱好</text>
  126. <input type="text" v-model="form.hobbies" placeholder="如: 阅读、运动、音乐" class="input" maxlength="200" />
  127. </view>
  128. <!-- 饮食偏好 -->
  129. <view class="form-item">
  130. <text class="label">饮食偏好</text>
  131. <input type="text" v-model="form.dietPreferences" placeholder="如: 清淡、无辣、低糖" class="input" maxlength="200" />
  132. </view>
  133. <!-- 成长规划师额外字段 -->
  134. <view class="form-section-title" v-if="form.role === 'teacher'">成长规划师信息</view>
  135. <!-- 成长规划师证书号(成长规划师必填) -->
  136. <view class="form-item" v-if="form.role === 'teacher'">
  137. <text class="label">成长规划师证书号 <text class="required">*</text></text>
  138. <input type="text" v-model="form.teacherNo" placeholder="请输入成长规划师证书号" class="input" maxlength="50" />
  139. </view>
  140. <!-- 成长规划师照片(成长规划师必填) -->
  141. <view class="form-item" v-if="form.role === 'teacher'">
  142. <text class="label">成长规划师照片 <text class="required">*</text></text>
  143. <view class="photo-upload" @click="chooseTeacherPhoto">
  144. <image v-if="form.teacherPhoto" :src="form.teacherPhoto" class="photo-preview" mode="aspectFill"></image>
  145. <view v-else class="photo-placeholder">
  146. <text class="plus-icon">+</text>
  147. <text class="placeholder-text">上传照片</text>
  148. </view>
  149. </view>
  150. </view>
  151. <!-- 成长规划师证书照片(成长规划师必填) -->
  152. <view class="form-item" v-if="form.role === 'teacher'">
  153. <text class="label">成长规划师证书 <text class="required">*</text></text>
  154. <view class="photo-upload" @click="chooseCertificate">
  155. <image v-if="form.certificateImage" :src="form.certificateImage" class="photo-preview" mode="aspectFill"></image>
  156. <view v-else class="photo-placeholder">
  157. <text class="plus-icon">+</text>
  158. <text class="placeholder-text">上传证书</text>
  159. </view>
  160. </view>
  161. </view>
  162. </view>
  163. <!-- AI助手选择(新用户注册或编辑资料时显示) -->
  164. <view class="family-section" v-if="isEdit">
  165. <view class="section-title">🤖 选择AI助手</view>
  166. <view class="mascot-cards">
  167. <view class="mascot-card" :class="{ active: form.mascot === 'xibao' }" @click="selectMascot('xibao')">
  168. <view class="mascot-card-icon xibao-bg">🌟</view>
  169. <view class="mascot-card-info">
  170. <text class="mascot-card-name">浠宝</text>
  171. <text class="mascot-card-desc">温柔活泼的阳光女孩</text>
  172. </view>
  173. </view>
  174. <view class="mascot-card" :class="{ active: form.mascot === 'fubao' }" @click="selectMascot('fubao')">
  175. <view class="mascot-card-icon fubao-bg">💪</view>
  176. <view class="mascot-card-info">
  177. <text class="mascot-card-name">福宝</text>
  178. <text class="mascot-card-desc">开朗自信的阳光男孩</text>
  179. </view>
  180. </view>
  181. </view>
  182. </view>
  183. <!-- 家庭绑定(新用户注册时显示) -->
  184. <view class="family-section" v-if="isEdit && form.role !== 'teacher' && isNewUserFlow">
  185. <view class="section-title">家庭绑定</view>
  186. <!-- 邀请码输入 -->
  187. <view class="form-item">
  188. <text class="label">家庭邀请码</text>
  189. <input type="text" v-model="form.inviteCode" placeholder="选填,如有邀请码请输入" class="input" maxlength="8" />
  190. </view>
  191. <view class="family-actions">
  192. <button v-if="form.inviteCode" class="btn btn-primary" @click="joinFamilyAction" :loading="loading">
  193. 加入家庭
  194. </button>
  195. <button v-else class="btn btn-primary" @click="createFamilyAction" :loading="loading">
  196. 创建新家庭
  197. </button>
  198. <button class="btn btn-skip" @click="skip">
  199. 跳过
  200. </button>
  201. </view>
  202. </view>
  203. <!-- 修改个人资料保存按钮(非新用户流程时显示) -->
  204. <view class="family-section" v-if="isEdit && !isNewUserFlow && form.role !== 'teacher'">
  205. <view class="family-actions">
  206. <button class="btn btn-primary" @click="saveUserInfo" :loading="loading">
  207. 保存修改
  208. </button>
  209. </view>
  210. </view>
  211. <!-- 成长规划师提交按钮 -->
  212. <view class="family-section" v-if="isEdit && form.role === 'teacher' && isNewUserFlow">
  213. <view class="family-actions">
  214. <button class="btn btn-primary" @click="submitTeacherInfo" :loading="loading">
  215. 提交申请
  216. </button>
  217. </view>
  218. </view>
  219. </view>
  220. </template>
  221. <script>
  222. import { updateUserInfo, joinFamily, createFamily, directRegister, getUserInfo } from '../../utils/api.js'
  223. export default {
  224. data() {
  225. return {
  226. isEdit: false,
  227. showRoleSelect: true,
  228. isNewUserFlow: false, // 是否是新用户注册流程
  229. form: {
  230. role: '',
  231. avatar: '',
  232. nickname: '',
  233. realName: '',
  234. gender: '',
  235. idCard: '',
  236. birthday: '',
  237. birthHour: '',
  238. inviteCode: '',
  239. mascot: '',
  240. phone: '',
  241. teacherNo: '',
  242. teacherPhoto: '',
  243. certificateImage: '',
  244. ethnicity: '',
  245. bloodType: '',
  246. highestEducation: '',
  247. maritalStatus: '',
  248. hobbies: '',
  249. dietPreferences: ''
  250. },
  251. ethnicityOptions: ['汉族','蒙古族','回族','藏族','维吾尔族','苗族','彝族','壮族','布依族','朝鲜族','满族','侗族','瑶族','白族','土家族','哈尼族','哈萨克族','傣族','黎族','其他'],
  252. bloodTypeOptions: ['A','B','AB','O','未知'],
  253. birthHourOptions: ['子时(23-01)','丑时(01-03)','寅时(03-05)','卯时(05-07)','辰时(07-09)','巳时(09-11)','午时(11-13)','未时(13-15)','申时(15-17)','酉时(17-19)','戌时(19-21)','亥时(21-23)'],
  254. birthHourValues: ['子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥'],
  255. educationOptions: ['小学','初中','高中','中专','大专','本科','硕士','博士'],
  256. maritalOptions: ['未婚','已婚','离异','丧偶'],
  257. loading: false,
  258. userId: '',
  259. token: ''
  260. }
  261. },
  262. computed: {
  263. ethnicityIndex() {
  264. return this.ethnicityOptions.indexOf(this.form.ethnicity)
  265. },
  266. bloodTypeIndex() {
  267. return this.bloodTypeOptions.indexOf(this.form.bloodType)
  268. },
  269. birthHourIndex() {
  270. return this.birthHourValues.indexOf(this.form.birthHour)
  271. },
  272. educationIndex() {
  273. return this.educationOptions.indexOf(this.form.highestEducation)
  274. },
  275. maritalIndex() {
  276. return this.maritalOptions.indexOf(this.form.maritalStatus)
  277. },
  278. },
  279. onLoad(options) {
  280. if (options.token && options.userId) {
  281. this.token = options.token
  282. this.userId = options.userId
  283. // 检查是否需要选择角色(新用户)- 只有明确传递 needsRoleSelect=true 才显示选择
  284. this.showRoleSelect = options.needsRoleSelect === 'true'
  285. this.isEdit = !this.showRoleSelect
  286. this.isNewUserFlow = options.needsRoleSelect === 'true'
  287. } else if (options.phone && options.needsRoleSelect === 'true') {
  288. // 测试环境:没有token,只有手机号,是新用户注册流程
  289. this.showRoleSelect = true
  290. this.isEdit = false
  291. this.isNewUserFlow = true
  292. // 将手机号传递给表单
  293. this.form.phone = options.phone
  294. } else {
  295. // 其他情况:默认进入编辑模式(如从"我的"页面进入)
  296. this.showRoleSelect = false
  297. this.isEdit = true
  298. this.isNewUserFlow = false
  299. }
  300. // 非新用户流程时,加载已有用户信息
  301. if (this.isEdit && !this.isNewUserFlow) {
  302. this.loadUserInfo()
  303. }
  304. },
  305. methods: {
  306. selectRole(role) {
  307. this.form.role = role
  308. },
  309. confirmRole() {
  310. if (!this.form.role) {
  311. uni.showToast({ title: '请选择角色', icon: 'none' })
  312. return
  313. }
  314. this.showRoleSelect = false
  315. this.isEdit = true
  316. // 测试环境:直接注册用户(不需要验证码)
  317. if (!this.token && this.form.phone) {
  318. // 自动进入家庭绑定流程
  319. }
  320. },
  321. chooseAvatar() {
  322. uni.chooseImage({
  323. count: 1,
  324. success: (res) => {
  325. this.form.avatar = res.tempFilePaths[0]
  326. }
  327. })
  328. },
  329. chooseTeacherPhoto() {
  330. uni.chooseImage({
  331. count: 1,
  332. success: (res) => {
  333. this.form.teacherPhoto = res.tempFilePaths[0]
  334. }
  335. })
  336. },
  337. chooseCertificate() {
  338. uni.chooseImage({
  339. count: 1,
  340. success: (res) => {
  341. this.form.certificateImage = res.tempFilePaths[0]
  342. }
  343. })
  344. },
  345. onGenderChange(e) {
  346. this.form.gender = e.detail.value
  347. },
  348. onIdCardInput(e) {
  349. const idCard = e.detail.value
  350. if (idCard.length === 18) {
  351. // 根据身份证号自动提取生日
  352. const year = idCard.substring(6, 10)
  353. const month = idCard.substring(10, 12)
  354. const day = idCard.substring(12, 14)
  355. this.form.birthday = `${year}-${month}-${day}`
  356. }
  357. },
  358. onBirthdayChange(e) {
  359. this.form.birthday = e.detail.value
  360. },
  361. onEthnicityChange(e) {
  362. this.form.ethnicity = this.ethnicityOptions[e.detail.value]
  363. },
  364. onBloodTypeChange(e) {
  365. this.form.bloodType = this.bloodTypeOptions[e.detail.value]
  366. },
  367. onBirthHourChange(e) {
  368. this.form.birthHour = this.birthHourValues[e.detail.value]
  369. },
  370. onEducationChange(e) {
  371. this.form.highestEducation = this.educationOptions[e.detail.value]
  372. },
  373. onMaritalChange(e) {
  374. this.form.maritalStatus = this.maritalOptions[e.detail.value]
  375. },
  376. selectMascot(code) {
  377. this.form.mascot = code
  378. },
  379. // 加载已有用户信息
  380. async loadUserInfo() {
  381. try {
  382. const res = await getUserInfo()
  383. if (res.code === 200 && res.data) {
  384. const userData = res.data
  385. this.form.nickname = userData.nickname || ''
  386. this.form.realName = userData.realName || ''
  387. this.form.gender = userData.gender || ''
  388. this.form.idCard = userData.idCard || ''
  389. // 生日只取日期部分,去掉时间和 ISO 格式的 T 分隔符
  390. this.form.birthday = userData.birthday ? String(userData.birthday).split(/[T ]/)[0] : ''
  391. this.form.avatar = userData.avatar || ''
  392. this.form.role = userData.role || ''
  393. this.form.phone = userData.phone || ''
  394. this.form.ethnicity = userData.ethnicity || ''
  395. this.form.bloodType = userData.bloodType || ''
  396. this.form.highestEducation = userData.highestEducation || ''
  397. this.form.maritalStatus = userData.maritalStatus || ''
  398. this.form.hobbies = userData.hobbies || ''
  399. this.form.dietPreferences = userData.dietPreferences || ''
  400. this.form.mascot = userData.mascot || ''
  401. }
  402. } catch (e) {
  403. console.error('加载用户信息失败', e)
  404. }
  405. },
  406. // 保存修改
  407. async saveUserInfo() {
  408. if (!this.form.nickname) {
  409. uni.showToast({ title: '请输入昵称', icon: 'none' })
  410. return
  411. }
  412. this.loading = true
  413. try {
  414. await updateUserInfo({
  415. nickname: this.form.nickname,
  416. realName: this.form.realName,
  417. gender: this.form.gender,
  418. idCard: this.form.idCard,
  419. birthday: this.form.birthday,
  420. avatar: this.form.avatar,
  421. mascot: this.form.mascot,
  422. ethnicity: this.form.ethnicity,
  423. bloodType: this.form.bloodType,
  424. highestEducation: this.form.highestEducation,
  425. maritalStatus: this.form.maritalStatus,
  426. hobbies: this.form.hobbies,
  427. dietPreferences: this.form.dietPreferences
  428. })
  429. uni.showToast({ title: '保存成功', icon: 'success' })
  430. setTimeout(() => {
  431. uni.navigateBack()
  432. }, 1500)
  433. } catch (e) {
  434. uni.showToast({ title: '保存失败', icon: 'none' })
  435. } finally {
  436. this.loading = false
  437. }
  438. },
  439. async submitTeacherInfo() {
  440. // 验证必填字段
  441. if (!this.form.nickname) {
  442. uni.showToast({ title: '请输入昵称', icon: 'none' })
  443. return
  444. }
  445. if (!this.form.gender) {
  446. uni.showToast({ title: '请选择性别', icon: 'none' })
  447. return
  448. }
  449. if (!this.form.idCard) {
  450. uni.showToast({ title: '请输入身份证号', icon: 'none' })
  451. return
  452. }
  453. if (!this.form.teacherNo) {
  454. uni.showToast({ title: '请输入成长规划师证书号', icon: 'none' })
  455. return
  456. }
  457. if (!this.form.teacherPhoto) {
  458. uni.showToast({ title: '请上传成长规划师照片', icon: 'none' })
  459. return
  460. }
  461. if (!this.form.certificateImage) {
  462. uni.showToast({ title: '请上传成长规划师证书', icon: 'none' })
  463. return
  464. }
  465. this.loading = true
  466. try {
  467. await updateUserInfo({
  468. ...this.form,
  469. roles: this.form.role
  470. })
  471. uni.showToast({ title: '提交成功,请等待审核' })
  472. setTimeout(() => {
  473. uni.switchTab({
  474. url: '/pages/index/parent-index'
  475. })
  476. }, 1500)
  477. } catch (e) {
  478. uni.showToast({ title: '提交失败', icon: 'none' })
  479. } finally {
  480. this.loading = false
  481. }
  482. },
  483. async joinFamilyAction() {
  484. if (!this.form.inviteCode) {
  485. uni.showToast({ title: '请输入邀请码', icon: 'none' })
  486. return
  487. }
  488. if (!this.form.nickname) {
  489. uni.showToast({ title: '请输入昵称', icon: 'none' })
  490. return
  491. }
  492. this.loading = true
  493. try {
  494. let userId = this.userId
  495. // 测试环境:没有token,需要先注册用户
  496. if (!this.token && this.form.phone) {
  497. const regRes = await directRegister({
  498. phone: this.form.phone,
  499. nickname: this.form.nickname,
  500. avatar: this.form.avatar,
  501. role: this.form.role,
  502. mascot: this.form.mascot,
  503. birthday: this.form.birthday,
  504. gender: this.form.gender,
  505. inviteCode: this.form.inviteCode
  506. })
  507. userId = regRes.data.userId
  508. // 保存登录信息
  509. uni.setStorageSync('token', regRes.data.token)
  510. uni.setStorageSync('userId', userId)
  511. uni.setStorageSync('role', regRes.data.role)
  512. uni.setStorageSync('familyId', regRes.data.familyId)
  513. } else {
  514. await updateUserInfo(this.form)
  515. await joinFamily(this.form.inviteCode)
  516. }
  517. uni.showToast({ title: '加入成功' })
  518. setTimeout(() => {
  519. this.navigateToHome()
  520. }, 1500)
  521. } catch (e) {
  522. uni.showToast({ title: e.message || '加入失败', icon: 'none' })
  523. } finally {
  524. this.loading = false
  525. }
  526. },
  527. async createFamilyAction() {
  528. if (!this.form.nickname) {
  529. uni.showToast({ title: '请输入昵称', icon: 'none' })
  530. return
  531. }
  532. this.loading = true
  533. try {
  534. let userId = this.userId
  535. // 测试环境:没有token,需要先注册用户
  536. if (!this.token && this.form.phone) {
  537. const regRes = await directRegister({
  538. phone: this.form.phone,
  539. nickname: this.form.nickname,
  540. avatar: this.form.avatar,
  541. role: this.form.role,
  542. mascot: this.form.mascot,
  543. birthday: this.form.birthday,
  544. gender: this.form.gender
  545. })
  546. userId = regRes.data.userId
  547. // 保存登录信息
  548. uni.setStorageSync('token', regRes.data.token)
  549. uni.setStorageSync('userId', userId)
  550. uni.setStorageSync('role', regRes.data.role)
  551. uni.setStorageSync('familyId', regRes.data.familyId)
  552. } else {
  553. await updateUserInfo(this.form)
  554. await createFamily(this.form.nickname + '的家庭')
  555. }
  556. uni.showToast({ title: '创建成功' })
  557. setTimeout(() => {
  558. this.navigateToHome()
  559. }, 1500)
  560. } catch (e) {
  561. uni.showToast({ title: e.message || '创建失败', icon: 'none' })
  562. } finally {
  563. this.loading = false
  564. }
  565. },
  566. skip() {
  567. this.navigateToHome()
  568. },
  569. navigateToHome() {
  570. // 保存 mascot 到 userInfo 存储,供 AI 聊天页读取
  571. if (this.form.mascot) {
  572. try {
  573. const userInfo = uni.getStorageSync('userInfo') || {}
  574. userInfo.mascot = this.form.mascot
  575. uni.setStorageSync('userInfo', userInfo)
  576. } catch (e) {
  577. console.error('保存 mascot 失败', e)
  578. }
  579. }
  580. const role = this.form.role || 'parent'
  581. if (role === 'parent') {
  582. uni.switchTab({ url: '/pages/index/parent-index' })
  583. } else if (role === 'child') {
  584. uni.switchTab({ url: '/pages/index/child-index' })
  585. } else if (role === 'teacher') {
  586. uni.switchTab({ url: '/pages/teacher/index' })
  587. }
  588. }
  589. }
  590. }
  591. </script>
  592. <style scoped>
  593. .user-edit-container {
  594. min-height: 100vh;
  595. background: #f5f5f5;
  596. padding: 30rpx;
  597. }
  598. .header {
  599. margin-bottom: 40rpx;
  600. text-align: center;
  601. }
  602. .title {
  603. font-size: 40rpx;
  604. font-weight: bold;
  605. color: #333;
  606. display: block;
  607. margin-bottom: 10rpx;
  608. }
  609. .subtitle {
  610. font-size: 28rpx;
  611. color: #999;
  612. }
  613. /* 角色选择 */
  614. .role-select-section {
  615. margin-bottom: 40rpx;
  616. }
  617. .role-card {
  618. background: #fff;
  619. border-radius: 16rpx;
  620. padding: 40rpx;
  621. margin-bottom: 20rpx;
  622. display: flex;
  623. flex-direction: column;
  624. align-items: center;
  625. border: 2rpx solid transparent;
  626. transition: all 0.3s;
  627. }
  628. .role-card.active {
  629. border-color: #4CAF50;
  630. background: #f8fdf8;
  631. }
  632. .role-icon {
  633. font-size: 80rpx;
  634. margin-bottom: 16rpx;
  635. }
  636. .role-name {
  637. font-size: 32rpx;
  638. font-weight: bold;
  639. color: #333;
  640. margin-bottom: 8rpx;
  641. }
  642. .role-desc {
  643. font-size: 24rpx;
  644. color: #999;
  645. }
  646. .btn-next {
  647. background: #4CAF50;
  648. color: #fff;
  649. border-radius: 40rpx;
  650. margin-top: 20rpx;
  651. }
  652. /* 表单 */
  653. .form-section {
  654. background: #fff;
  655. border-radius: 16rpx;
  656. padding: 30rpx;
  657. margin-bottom: 30rpx;
  658. }
  659. .form-section-title {
  660. font-size: 30rpx;
  661. font-weight: bold;
  662. color: #333;
  663. margin-bottom: 20rpx;
  664. padding-bottom: 16rpx;
  665. border-bottom: 1rpx solid #f0f0f0;
  666. }
  667. .form-item {
  668. margin-bottom: 30rpx;
  669. }
  670. .label {
  671. display: block;
  672. font-size: 28rpx;
  673. color: #333;
  674. margin-bottom: 16rpx;
  675. }
  676. .required {
  677. color: #f44336;
  678. }
  679. .input, .picker-input {
  680. padding: 20rpx;
  681. background: #f5f5f5;
  682. border-radius: 12rpx;
  683. font-size: 28rpx;
  684. }
  685. .role-select {
  686. display: flex;
  687. gap: 40rpx;
  688. }
  689. .role-option {
  690. display: flex;
  691. align-items: center;
  692. gap: 8rpx;
  693. }
  694. /* 头像上传 */
  695. .avatar-upload {
  696. width: 150rpx;
  697. height: 150rpx;
  698. }
  699. .avatar-preview {
  700. width: 150rpx;
  701. height: 150rpx;
  702. border-radius: 50%;
  703. }
  704. .avatar-placeholder {
  705. width: 150rpx;
  706. height: 150rpx;
  707. background: #f5f5f5;
  708. border-radius: 50%;
  709. display: flex;
  710. align-items: center;
  711. justify-content: center;
  712. font-size: 60rpx;
  713. color: #ccc;
  714. }
  715. /* 照片上传 */
  716. .photo-upload {
  717. width: 300rpx;
  718. height: 200rpx;
  719. }
  720. .photo-preview {
  721. width: 300rpx;
  722. height: 200rpx;
  723. border-radius: 12rpx;
  724. }
  725. .photo-placeholder {
  726. width: 300rpx;
  727. height: 200rpx;
  728. background: #f5f5f5;
  729. border-radius: 12rpx;
  730. display: flex;
  731. flex-direction: column;
  732. align-items: center;
  733. justify-content: center;
  734. }
  735. .plus-icon {
  736. font-size: 60rpx;
  737. color: #ccc;
  738. }
  739. .placeholder-text {
  740. font-size: 24rpx;
  741. color: #999;
  742. margin-top: 8rpx;
  743. }
  744. /* AI助手选择 */
  745. .mascot-cards {
  746. display: flex;
  747. gap: 20rpx;
  748. margin-top: 16rpx;
  749. }
  750. .mascot-card {
  751. flex: 1;
  752. background: #f8f8f8;
  753. border-radius: 16rpx;
  754. padding: 24rpx;
  755. display: flex;
  756. align-items: center;
  757. gap: 16rpx;
  758. border: 2rpx solid transparent;
  759. transition: all 0.3s;
  760. }
  761. .mascot-card.active {
  762. border-color: #4CAF50;
  763. background: #f0fdf4;
  764. }
  765. .mascot-card-icon {
  766. width: 72rpx;
  767. height: 72rpx;
  768. border-radius: 50%;
  769. display: flex;
  770. align-items: center;
  771. justify-content: center;
  772. font-size: 36rpx;
  773. flex-shrink: 0;
  774. }
  775. .xibao-bg {
  776. background: linear-gradient(135deg, #FFF0DB, #FFD6A5);
  777. }
  778. .fubao-bg {
  779. background: linear-gradient(135deg, #FFF8E1, #FCD34D);
  780. }
  781. .mascot-card-info {
  782. display: flex;
  783. flex-direction: column;
  784. gap: 4rpx;
  785. }
  786. .mascot-card-name {
  787. font-size: 30rpx;
  788. font-weight: bold;
  789. color: #333;
  790. }
  791. .mascot-card-desc {
  792. font-size: 22rpx;
  793. color: #999;
  794. }
  795. /* 家庭绑定 */
  796. .family-section {
  797. background: #fff;
  798. border-radius: 16rpx;
  799. padding: 30rpx;
  800. }
  801. .section-title {
  802. font-size: 30rpx;
  803. font-weight: bold;
  804. color: #333;
  805. margin-bottom: 20rpx;
  806. }
  807. .family-actions {
  808. display: flex;
  809. flex-direction: column;
  810. gap: 20rpx;
  811. margin-top: 30rpx;
  812. }
  813. .btn {
  814. border-radius: 40rpx;
  815. font-size: 30rpx;
  816. }
  817. .btn-primary {
  818. background: #4CAF50;
  819. color: #fff;
  820. }
  821. .btn-skip {
  822. background: #f5f5f5;
  823. color: #999;
  824. }
  825. </style>