user-edit.vue 24 KB

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