index.vue 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. <template>
  2. <view class="basic-info-page">
  3. <!-- 自定义头部 -->
  4. <view class="custom-header" :style="{ paddingTop: statusBarHeight + 'px' }">
  5. <view class="header-content">
  6. <view class="back-btn" @click="handleBack">
  7. <text class="back-icon">‹</text>
  8. </view>
  9. <text class="header-title">{{ t('pagesContent.my.info.title') }}</text>
  10. <view class="placeholder"></view>
  11. </view>
  12. </view>
  13. <!-- 页面内容 -->
  14. <view class="page-body">
  15. <!-- 加载状态 -->
  16. <view v-if="loading" class="loading-state">
  17. <text class="loading-text">{{ t('pagesContent.my.info.loading') }}</text>
  18. </view>
  19. <!-- 信息列表 -->
  20. <view v-else class="info-list">
  21. <!-- 头像 -->
  22. <view class="info-item avatar-item">
  23. <text class="item-label">{{ t('pagesContent.my.info.avatar') }}</text>
  24. <view class="avatar-wrapper">
  25. <image
  26. class="avatar-image"
  27. :src="basicInfo.avatar || '/static/default-avatar.svg'"
  28. mode="aspectFill"
  29. />
  30. <view class="edit-btn" @click="handleEditAvatar">
  31. <text class="edit-btn-text">修改</text>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 昵称 -->
  36. <view class="info-item">
  37. <text class="item-label">{{ t('pagesContent.my.info.nickname') }}</text>
  38. <view class="value-wrapper">
  39. <text class="item-value">{{ basicInfo.nickname || '-' }}</text>
  40. <view class="edit-btn" @click="handleEditNickname">
  41. <text class="edit-btn-text">修改</text>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 手机号 -->
  46. <view class="info-item">
  47. <text class="item-label">{{ t('pagesContent.my.info.phoneNumber') }}</text>
  48. <text class="item-value">{{ basicInfo.phoneNumber || '-' }}</text>
  49. </view>
  50. <!-- 性别 -->
  51. <view class="info-item">
  52. <text class="item-label">{{ t('pagesContent.my.info.gender') }}</text>
  53. <view class="value-wrapper">
  54. <view class="gender-value">
  55. <text class="item-value" :class="genderClass">{{ genderDisplay }}</text>
  56. </view>
  57. <view class="edit-btn" @click="handleEditGender">
  58. <text class="edit-btn-text">修改</text>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 修改密码按钮 -->
  64. <view class="password-btn-wrapper">
  65. <view class="password-btn" @click="handleEditPassword">
  66. <text class="password-btn-text">修改密码</text>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 修改头像弹窗 -->
  71. <view v-if="showAvatarModal" class="modal-overlay" @click="closeAvatarModal">
  72. <view class="modal-content" @click.stop>
  73. <view class="modal-header">
  74. <text class="modal-title">修改头像</text>
  75. <view class="modal-close" @click="closeAvatarModal">
  76. <text class="close-icon">×</text>
  77. </view>
  78. </view>
  79. <view class="modal-body">
  80. <view class="upload-area" @click="handleSelectImage">
  81. <image
  82. v-if="tempAvatar"
  83. class="preview-image"
  84. :src="tempAvatar"
  85. mode="aspectFill"
  86. />
  87. <view v-else class="upload-placeholder">
  88. <text class="placeholder-text">点击选择图片</text>
  89. </view>
  90. </view>
  91. <view class="modal-actions">
  92. <view class="action-btn cancel-btn" @click="closeAvatarModal">
  93. <text class="btn-text">取消</text>
  94. </view>
  95. <view class="action-btn confirm-btn" @click="confirmUpdateAvatar">
  96. <text class="btn-text">确认</text>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. </view>
  102. <!-- 修改昵称弹窗 -->
  103. <view v-if="showNicknameModal" class="modal-overlay" @click="closeNicknameModal">
  104. <view class="modal-content" @click.stop>
  105. <view class="modal-header">
  106. <text class="modal-title">修改昵称</text>
  107. <view class="modal-close" @click="closeNicknameModal">
  108. <text class="close-icon">×</text>
  109. </view>
  110. </view>
  111. <view class="modal-body">
  112. <input
  113. class="modal-input"
  114. v-model="tempNickname"
  115. placeholder="请输入昵称"
  116. maxlength="20"
  117. />
  118. <view class="modal-actions">
  119. <view class="action-btn cancel-btn" @click="closeNicknameModal">
  120. <text class="btn-text">取消</text>
  121. </view>
  122. <view class="action-btn confirm-btn" @click="confirmUpdateNickname">
  123. <text class="btn-text">确认</text>
  124. </view>
  125. </view>
  126. </view>
  127. </view>
  128. </view>
  129. <!-- 修改性别弹窗 -->
  130. <view v-if="showGenderModal" class="modal-overlay" @click="closeGenderModal">
  131. <view class="modal-content" @click.stop>
  132. <view class="modal-header">
  133. <text class="modal-title">修改性别</text>
  134. <view class="modal-close" @click="closeGenderModal">
  135. <text class="close-icon">×</text>
  136. </view>
  137. </view>
  138. <view class="modal-body">
  139. <picker
  140. mode="selector"
  141. :range="genderDictListWithLabel"
  142. range-key="displayLabel"
  143. :value="selectedGenderIndex"
  144. @change="handleGenderChange"
  145. >
  146. <view class="picker-value">
  147. <text class="value-text">{{ selectedGenderLabel || '请选择性别' }}</text>
  148. <text class="arrow-icon">▼</text>
  149. </view>
  150. </picker>
  151. <view class="modal-actions">
  152. <view class="action-btn cancel-btn" @click="closeGenderModal">
  153. <text class="btn-text">取消</text>
  154. </view>
  155. <view class="action-btn confirm-btn" @click="confirmUpdateGender">
  156. <text class="btn-text">确认</text>
  157. </view>
  158. </view>
  159. </view>
  160. </view>
  161. </view>
  162. <!-- 修改密码弹窗 -->
  163. <view v-if="showPasswordModal" class="modal-overlay" @click="closePasswordModal">
  164. <view class="modal-content" @click.stop>
  165. <view class="modal-header">
  166. <text class="modal-title">修改密码</text>
  167. <view class="modal-close" @click="closePasswordModal">
  168. <text class="close-icon">×</text>
  169. </view>
  170. </view>
  171. <view class="modal-body">
  172. <view class="password-input-wrapper">
  173. <input
  174. class="modal-input"
  175. v-model="tempOldPassword"
  176. :password="!showOldPassword"
  177. placeholder="请输入旧密码"
  178. maxlength="20"
  179. />
  180. <text
  181. class="toggle-password"
  182. @click="showOldPassword = !showOldPassword"
  183. >
  184. {{ showOldPassword ? '👁' : '👁‍🗨' }}
  185. </text>
  186. </view>
  187. <view class="password-input-wrapper">
  188. <input
  189. class="modal-input"
  190. v-model="tempNewPassword"
  191. :password="!showNewPassword"
  192. placeholder="请输入新密码(至少6位)"
  193. maxlength="20"
  194. />
  195. <text
  196. class="toggle-password"
  197. @click="showNewPassword = !showNewPassword"
  198. >
  199. {{ showNewPassword ? '👁' : '👁‍🗨' }}
  200. </text>
  201. </view>
  202. <view class="password-input-wrapper">
  203. <input
  204. class="modal-input"
  205. v-model="tempConfirmPassword"
  206. :password="!showConfirmPassword"
  207. placeholder="请再次输入新密码"
  208. maxlength="20"
  209. />
  210. <text
  211. class="toggle-password"
  212. @click="showConfirmPassword = !showConfirmPassword"
  213. >
  214. {{ showConfirmPassword ? '👁' : '👁‍🗨' }}
  215. </text>
  216. </view>
  217. <view class="modal-actions">
  218. <view class="action-btn cancel-btn" @click="closePasswordModal">
  219. <text class="btn-text">取消</text>
  220. </view>
  221. <view class="action-btn confirm-btn" @click="confirmUpdatePassword">
  222. <text class="btn-text">确认</text>
  223. </view>
  224. </view>
  225. </view>
  226. </view>
  227. </view>
  228. </view>
  229. </template>
  230. <script setup>
  231. import { ref, computed, onMounted } from 'vue'
  232. import { useI18n } from 'vue-i18n'
  233. import { getBasicInfo, updateAvatar, updateNickname, updateGender, updatePassword, logout, uploadToOss } from '@/apis/auth'
  234. import { getDictDataByType } from '@/apis/dict'
  235. const { t, locale } = useI18n()
  236. // 定义事件
  237. const emit = defineEmits(['back'])
  238. // 状态栏高度
  239. const statusBarHeight = ref(0)
  240. // 基本信息
  241. const basicInfo = ref({
  242. nickname: '',
  243. phoneNumber: '',
  244. avatar: '',
  245. gender: ''
  246. })
  247. // 加载状态
  248. const loading = ref(false)
  249. // 性别字典数据
  250. const genderDictList = ref([])
  251. // 弹窗状态
  252. const showAvatarModal = ref(false)
  253. const showNicknameModal = ref(false)
  254. const showGenderModal = ref(false)
  255. const showPasswordModal = ref(false)
  256. // 临时数据
  257. const tempAvatar = ref('')
  258. const tempAvatarOssId = ref('')
  259. const tempNickname = ref('')
  260. const tempGender = ref('')
  261. const tempOldPassword = ref('')
  262. const tempNewPassword = ref('')
  263. const tempConfirmPassword = ref('')
  264. const showOldPassword = ref(false)
  265. const showNewPassword = ref(false)
  266. const showConfirmPassword = ref(false)
  267. // 性别显示(为字典项添加displayLabel属性)
  268. const genderDictListWithLabel = computed(() => {
  269. return genderDictList.value.map(item => {
  270. try {
  271. const labelObj = JSON.parse(item.dictLabel)
  272. const localeKey = locale.value.replace('-', '_')
  273. return {
  274. ...item,
  275. displayLabel: labelObj[localeKey] || labelObj['zh_CN'] || item.dictLabel
  276. }
  277. } catch (error) {
  278. return {
  279. ...item,
  280. displayLabel: item.dictLabel
  281. }
  282. }
  283. })
  284. })
  285. // 选中的性别索引
  286. const selectedGenderIndex = computed(() => {
  287. if (!tempGender.value) return 0
  288. return genderDictListWithLabel.value.findIndex(item =>
  289. String(item.dictValue) === String(tempGender.value)
  290. )
  291. })
  292. // 选中的性别标签
  293. const selectedGenderLabel = computed(() => {
  294. if (!tempGender.value) return ''
  295. const item = genderDictListWithLabel.value.find(item =>
  296. String(item.dictValue) === String(tempGender.value)
  297. )
  298. return item?.displayLabel || ''
  299. })
  300. // 性别显示
  301. const genderDisplay = computed(() => {
  302. if (basicInfo.value.gender === null || basicInfo.value.gender === undefined || basicInfo.value.gender === '') return '-'
  303. // 从字典数据中查找匹配的项,使用dictValue匹配gender
  304. const genderItem = genderDictList.value.find(item =>
  305. String(item.dictValue) === String(basicInfo.value.gender)
  306. )
  307. if (!genderItem) return '-'
  308. // 解析dictLabel的JSON字符串
  309. try {
  310. const labelObj = JSON.parse(genderItem.dictLabel)
  311. // 将locale格式从 zh-CN 转换为 zh_CN
  312. const localeKey = locale.value.replace('-', '_')
  313. // 根据当前语言返回对应的标签
  314. return labelObj[localeKey] || labelObj['zh_CN'] || genderItem.dictLabel
  315. } catch (error) {
  316. // 如果解析失败,直接返回dictLabel
  317. return genderItem.dictLabel
  318. }
  319. })
  320. // 性别样式类
  321. const genderClass = computed(() => {
  322. if (basicInfo.value.gender === null || basicInfo.value.gender === undefined || basicInfo.value.gender === '') return ''
  323. const genderItem = genderDictList.value.find(item =>
  324. String(item.dictValue) === String(basicInfo.value.gender)
  325. )
  326. return genderItem?.listClass || ''
  327. })
  328. onMounted(() => {
  329. // 获取系统信息
  330. const windowInfo = uni.getWindowInfo()
  331. statusBarHeight.value = windowInfo.statusBarHeight || 0
  332. // 获取字典数据
  333. fetchGenderDict()
  334. // 获取基本信息
  335. fetchBasicInfo()
  336. })
  337. // 获取性别字典数据
  338. const fetchGenderDict = async () => {
  339. try {
  340. const response = await getDictDataByType('sys_user_sex')
  341. if (response && response.data) {
  342. genderDictList.value = response.data
  343. }
  344. } catch (error) {
  345. console.error('获取性别字典失败:', error)
  346. }
  347. }
  348. // 打开修改头像弹窗
  349. const handleEditAvatar = () => {
  350. tempAvatar.value = basicInfo.value.avatar || ''
  351. tempAvatarOssId.value = ''
  352. showAvatarModal.value = true
  353. }
  354. // 关闭修改头像弹窗
  355. const closeAvatarModal = () => {
  356. showAvatarModal.value = false
  357. tempAvatar.value = ''
  358. tempAvatarOssId.value = ''
  359. }
  360. // 选择图片
  361. const handleSelectImage = () => {
  362. uni.chooseImage({
  363. count: 1,
  364. sizeType: ['compressed'],
  365. sourceType: ['album', 'camera'],
  366. success: async (res) => {
  367. tempAvatar.value = res.tempFilePaths[0]
  368. }
  369. })
  370. }
  371. // 确认修改头像
  372. const confirmUpdateAvatar = async () => {
  373. if (!tempAvatar.value) {
  374. uni.showToast({
  375. title: '请选择图片',
  376. icon: 'none'
  377. })
  378. return
  379. }
  380. try {
  381. uni.showLoading({
  382. title: '上传中...',
  383. mask: true
  384. })
  385. // 先上传图片到OSS
  386. const uploadResponse = await uploadToOss(tempAvatar.value)
  387. if (uploadResponse && uploadResponse.code === 200 && uploadResponse.data) {
  388. // 使用返回的ossId更新头像
  389. const updateResponse = await updateAvatar({
  390. avatar: uploadResponse.data.ossId
  391. })
  392. uni.hideLoading()
  393. if (updateResponse && updateResponse.code === 200) {
  394. uni.showToast({
  395. title: '修改成功',
  396. icon: 'success'
  397. })
  398. closeAvatarModal()
  399. // 重新获取基本信息
  400. fetchBasicInfo()
  401. } else {
  402. uni.showToast({
  403. title: updateResponse.msg || '修改失败',
  404. icon: 'none'
  405. })
  406. }
  407. } else {
  408. uni.hideLoading()
  409. uni.showToast({
  410. title: uploadResponse.msg || '上传失败',
  411. icon: 'none'
  412. })
  413. }
  414. } catch (error) {
  415. uni.hideLoading()
  416. console.error('修改头像失败:', error)
  417. uni.showToast({
  418. title: '修改失败',
  419. icon: 'none'
  420. })
  421. }
  422. }
  423. // 打开修改昵称弹窗
  424. const handleEditNickname = () => {
  425. tempNickname.value = basicInfo.value.nickname || ''
  426. showNicknameModal.value = true
  427. }
  428. // 关闭修改昵称弹窗
  429. const closeNicknameModal = () => {
  430. showNicknameModal.value = false
  431. tempNickname.value = ''
  432. }
  433. // 确认修改昵称
  434. const confirmUpdateNickname = async () => {
  435. if (!tempNickname.value || !tempNickname.value.trim()) {
  436. uni.showToast({
  437. title: '请输入昵称',
  438. icon: 'none'
  439. })
  440. return
  441. }
  442. try {
  443. uni.showLoading({
  444. title: '修改中...',
  445. mask: true
  446. })
  447. const response = await updateNickname({
  448. nickname: tempNickname.value.trim()
  449. })
  450. uni.hideLoading()
  451. if (response && response.code === 200) {
  452. uni.showToast({
  453. title: '修改成功',
  454. icon: 'success'
  455. })
  456. closeNicknameModal()
  457. // 重新获取基本信息
  458. fetchBasicInfo()
  459. } else {
  460. uni.showToast({
  461. title: response.msg || '修改失败',
  462. icon: 'none'
  463. })
  464. }
  465. } catch (error) {
  466. uni.hideLoading()
  467. console.error('修改昵称失败:', error)
  468. uni.showToast({
  469. title: '修改失败',
  470. icon: 'none'
  471. })
  472. }
  473. }
  474. // 打开修改性别弹窗
  475. const handleEditGender = () => {
  476. tempGender.value = basicInfo.value.gender || ''
  477. showGenderModal.value = true
  478. }
  479. // 关闭修改性别弹窗
  480. const closeGenderModal = () => {
  481. showGenderModal.value = false
  482. tempGender.value = ''
  483. }
  484. // 性别选择变化
  485. const handleGenderChange = (e) => {
  486. const index = e.detail.value
  487. tempGender.value = genderDictListWithLabel.value[index].dictValue
  488. }
  489. // 确认修改性别
  490. const confirmUpdateGender = async () => {
  491. if (!tempGender.value && tempGender.value !== 0) {
  492. uni.showToast({
  493. title: '请选择性别',
  494. icon: 'none'
  495. })
  496. return
  497. }
  498. try {
  499. uni.showLoading({
  500. title: '修改中...',
  501. mask: true
  502. })
  503. const response = await updateGender({
  504. gender: tempGender.value
  505. })
  506. uni.hideLoading()
  507. if (response && response.code === 200) {
  508. uni.showToast({
  509. title: '修改成功',
  510. icon: 'success'
  511. })
  512. closeGenderModal()
  513. // 重新获取基本信息
  514. fetchBasicInfo()
  515. } else {
  516. uni.showToast({
  517. title: response.msg || '修改失败',
  518. icon: 'none'
  519. })
  520. }
  521. } catch (error) {
  522. uni.hideLoading()
  523. console.error('修改性别失败:', error)
  524. uni.showToast({
  525. title: '修改失败',
  526. icon: 'none'
  527. })
  528. }
  529. }
  530. // 打开修改密码弹窗
  531. const handleEditPassword = () => {
  532. tempOldPassword.value = ''
  533. tempNewPassword.value = ''
  534. tempConfirmPassword.value = ''
  535. showOldPassword.value = false
  536. showNewPassword.value = false
  537. showConfirmPassword.value = false
  538. showPasswordModal.value = true
  539. }
  540. // 关闭修改密码弹窗
  541. const closePasswordModal = () => {
  542. showPasswordModal.value = false
  543. tempOldPassword.value = ''
  544. tempNewPassword.value = ''
  545. tempConfirmPassword.value = ''
  546. showOldPassword.value = false
  547. showNewPassword.value = false
  548. showConfirmPassword.value = false
  549. }
  550. // 确认修改密码
  551. const confirmUpdatePassword = async () => {
  552. // 验证旧密码
  553. if (!tempOldPassword.value || !tempOldPassword.value.trim()) {
  554. uni.showToast({
  555. title: '请输入旧密码',
  556. icon: 'none'
  557. })
  558. return
  559. }
  560. // 验证新密码
  561. if (!tempNewPassword.value || !tempNewPassword.value.trim()) {
  562. uni.showToast({
  563. title: '请输入新密码',
  564. icon: 'none'
  565. })
  566. return
  567. }
  568. // 验证新密码长度
  569. if (tempNewPassword.value.length < 6) {
  570. uni.showToast({
  571. title: '新密码至少6位',
  572. icon: 'none'
  573. })
  574. return
  575. }
  576. // 验证确认密码
  577. if (!tempConfirmPassword.value || !tempConfirmPassword.value.trim()) {
  578. uni.showToast({
  579. title: '请输入确认密码',
  580. icon: 'none'
  581. })
  582. return
  583. }
  584. // 验证两次密码是否一致
  585. if (tempNewPassword.value !== tempConfirmPassword.value) {
  586. uni.showToast({
  587. title: '两次密码不一致',
  588. icon: 'none'
  589. })
  590. return
  591. }
  592. try {
  593. uni.showLoading({
  594. title: '修改中...',
  595. mask: true
  596. })
  597. const response = await updatePassword({
  598. oldPassword: tempOldPassword.value.trim(),
  599. newPassword: tempNewPassword.value.trim()
  600. })
  601. uni.hideLoading()
  602. if (response && response.code === 200) {
  603. uni.showToast({
  604. title: '修改成功',
  605. icon: 'success',
  606. duration: 2000
  607. })
  608. closePasswordModal()
  609. // 修改密码成功后,先调用退出登录接口,然后提示用户重新登录
  610. setTimeout(async () => {
  611. try {
  612. // 调用退出登录接口
  613. await logout()
  614. } catch (error) {
  615. console.error('退出登录失败:', error)
  616. // 即使退出登录接口失败,也继续清除本地token
  617. } finally {
  618. // 清除本地token
  619. uni.removeStorageSync('token')
  620. // 提示用户重新登录
  621. uni.showModal({
  622. title: '提示',
  623. content: '密码修改成功,请重新登录',
  624. showCancel: false,
  625. success: () => {
  626. // 跳转到登录页
  627. uni.reLaunch({
  628. url: '/pages/login/login'
  629. })
  630. }
  631. })
  632. }
  633. }, 2000)
  634. } else {
  635. // 使用弹出框显示具体错误信息
  636. uni.showModal({
  637. title: '修改失败',
  638. content: response.msg || '修改密码失败,请稍后重试',
  639. showCancel: false,
  640. confirmText: '确定'
  641. })
  642. }
  643. } catch (error) {
  644. uni.hideLoading()
  645. console.error('修改密码失败:', error)
  646. // 使用弹出框显示错误信息
  647. uni.showModal({
  648. title: '修改失败',
  649. content: error.msg || error.message || '网络错误,请稍后重试',
  650. showCancel: false,
  651. confirmText: '确定'
  652. })
  653. }
  654. }
  655. // 获取基本信息
  656. const fetchBasicInfo = async () => {
  657. try {
  658. loading.value = true
  659. const response = await getBasicInfo()
  660. if (response && response.data) {
  661. basicInfo.value = response.data
  662. }
  663. } catch (error) {
  664. console.error('获取基本信息失败:', error)
  665. uni.showToast({
  666. title: t('pagesContent.my.info.loadFailed'),
  667. icon: 'none',
  668. duration: 2000
  669. })
  670. } finally {
  671. loading.value = false
  672. }
  673. }
  674. // 返回
  675. const handleBack = () => {
  676. uni.navigateBack({
  677. fail: () => {
  678. // 如果返回失败(比如没有上一页),则跳转到我的页面
  679. uni.reLaunch({
  680. url: '/pages/my/index'
  681. })
  682. }
  683. })
  684. }
  685. </script>
  686. <style lang="scss" scoped>
  687. .basic-info-page {
  688. width: 100%;
  689. min-height: 100vh;
  690. display: flex;
  691. flex-direction: column;
  692. background: linear-gradient(180deg, #f8fcff 0%, #ffffff 100%);
  693. // 自定义头部
  694. .custom-header {
  695. position: fixed;
  696. top: 0;
  697. left: 0;
  698. right: 0;
  699. background-color: #ffffff;
  700. border-bottom: 1rpx solid #e5e5e5;
  701. z-index: 100;
  702. .header-content {
  703. height: 88rpx;
  704. display: flex;
  705. align-items: center;
  706. justify-content: space-between;
  707. padding: 0 32rpx;
  708. .back-btn {
  709. width: 60rpx;
  710. height: 60rpx;
  711. display: flex;
  712. align-items: center;
  713. justify-content: center;
  714. .back-icon {
  715. font-size: 56rpx;
  716. color: #333333;
  717. font-weight: 300;
  718. }
  719. }
  720. .header-title {
  721. flex: 1;
  722. text-align: center;
  723. font-size: 32rpx;
  724. font-weight: 500;
  725. color: #000000;
  726. }
  727. .placeholder {
  728. width: 60rpx;
  729. }
  730. }
  731. }
  732. // 页面内容
  733. .page-body {
  734. flex: 1;
  735. margin-top: 88rpx;
  736. padding: 40rpx;
  737. // 加载状态
  738. .loading-state {
  739. display: flex;
  740. align-items: center;
  741. justify-content: center;
  742. padding: 120rpx 0;
  743. .loading-text {
  744. font-size: 28rpx;
  745. color: #999999;
  746. }
  747. }
  748. // 信息列表
  749. .info-list {
  750. margin-top: 100rpx;
  751. background-color: #ffffff;
  752. border-radius: 20rpx;
  753. overflow: hidden;
  754. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  755. .info-item {
  756. display: flex;
  757. align-items: center;
  758. justify-content: space-between;
  759. padding: 36rpx 40rpx;
  760. border-bottom: 1rpx solid #f0f0f0;
  761. &:last-child {
  762. border-bottom: none;
  763. }
  764. &.avatar-item {
  765. .avatar-wrapper {
  766. display: flex;
  767. align-items: center;
  768. gap: 24rpx;
  769. .avatar-image {
  770. width: 100rpx;
  771. height: 100rpx;
  772. border-radius: 50rpx;
  773. border: 4rpx solid #6ec7f5;
  774. }
  775. }
  776. }
  777. .value-wrapper {
  778. display: flex;
  779. align-items: center;
  780. gap: 16rpx;
  781. }
  782. .edit-btn {
  783. padding: 10rpx 24rpx;
  784. background: linear-gradient(135deg, #1ec9c9 0%, #17b3b3 100%);
  785. border-radius: 20rpx;
  786. &:active {
  787. opacity: 0.8;
  788. }
  789. .edit-btn-text {
  790. font-size: 24rpx;
  791. color: #ffffff;
  792. font-weight: 500;
  793. white-space: nowrap;
  794. }
  795. }
  796. .item-label {
  797. font-size: 30rpx;
  798. color: #666666;
  799. font-weight: 500;
  800. }
  801. .gender-value {
  802. display: flex;
  803. align-items: center;
  804. }
  805. .item-value {
  806. font-size: 30rpx;
  807. color: #333333;
  808. font-weight: 500;
  809. // 字典listClass样式
  810. &.default {
  811. color: #909399;
  812. }
  813. &.primary {
  814. color: #6ec7f5;
  815. }
  816. &.success {
  817. color: #67c23a;
  818. }
  819. &.info {
  820. color: #909399;
  821. }
  822. &.warning {
  823. color: #e6a23c;
  824. }
  825. &.danger {
  826. color: #f56c6c;
  827. }
  828. }
  829. }
  830. }
  831. // 修改密码按钮
  832. .password-btn-wrapper {
  833. margin-top: 40rpx;
  834. padding: 0 40rpx;
  835. .password-btn {
  836. width: 100%;
  837. height: 96rpx;
  838. background: linear-gradient(135deg, #1ec9c9 0%, #17b3b3 100%);
  839. border-radius: 48rpx;
  840. display: flex;
  841. align-items: center;
  842. justify-content: center;
  843. box-shadow: 0 6rpx 20rpx rgba(30, 201, 201, 0.3);
  844. transition: all 0.3s;
  845. &:active {
  846. transform: scale(0.98);
  847. box-shadow: 0 4rpx 16rpx rgba(30, 201, 201, 0.3);
  848. }
  849. .password-btn-text {
  850. font-size: 32rpx;
  851. font-weight: 600;
  852. color: #ffffff;
  853. letter-spacing: 2rpx;
  854. }
  855. }
  856. }
  857. }
  858. // 弹窗样式
  859. .modal-overlay {
  860. position: fixed;
  861. top: 0;
  862. left: 0;
  863. right: 0;
  864. bottom: 0;
  865. background: rgba(0, 0, 0, 0.6);
  866. display: flex;
  867. align-items: center;
  868. justify-content: center;
  869. z-index: 1000;
  870. backdrop-filter: blur(4rpx);
  871. .modal-content {
  872. width: 620rpx;
  873. max-width: 90%;
  874. background: #ffffff;
  875. border-radius: 24rpx;
  876. overflow: hidden;
  877. box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.15);
  878. animation: modalSlideIn 0.3s ease-out;
  879. @keyframes modalSlideIn {
  880. from {
  881. opacity: 0;
  882. transform: translateY(-40rpx) scale(0.95);
  883. }
  884. to {
  885. opacity: 1;
  886. transform: translateY(0) scale(1);
  887. }
  888. }
  889. .modal-header {
  890. padding: 40rpx 32rpx 24rpx;
  891. display: flex;
  892. align-items: center;
  893. justify-content: space-between;
  894. background: linear-gradient(135deg, #f8fcff 0%, #ffffff 100%);
  895. .modal-title {
  896. font-size: 34rpx;
  897. font-weight: 600;
  898. color: #1a1a1a;
  899. letter-spacing: 1rpx;
  900. }
  901. .modal-close {
  902. width: 56rpx;
  903. height: 56rpx;
  904. display: flex;
  905. align-items: center;
  906. justify-content: center;
  907. border-radius: 50%;
  908. background: rgba(0, 0, 0, 0.04);
  909. transition: all 0.2s;
  910. &:active {
  911. background: rgba(0, 0, 0, 0.08);
  912. transform: scale(0.9);
  913. }
  914. .close-icon {
  915. font-size: 44rpx;
  916. color: #666666;
  917. line-height: 1;
  918. font-weight: 300;
  919. }
  920. }
  921. }
  922. .modal-body {
  923. padding: 32rpx;
  924. .upload-area {
  925. width: 100%;
  926. height: 420rpx;
  927. border: 3rpx dashed #d9d9d9;
  928. border-radius: 16rpx;
  929. display: flex;
  930. align-items: center;
  931. justify-content: center;
  932. overflow: hidden;
  933. margin-bottom: 32rpx;
  934. background: #fafafa;
  935. transition: all 0.3s;
  936. position: relative;
  937. &:active {
  938. border-color: #1ec9c9;
  939. background: #f0fffe;
  940. }
  941. .preview-image {
  942. width: 100%;
  943. height: 100%;
  944. object-fit: cover;
  945. }
  946. .upload-placeholder {
  947. display: flex;
  948. flex-direction: column;
  949. align-items: center;
  950. justify-content: center;
  951. gap: 16rpx;
  952. &::before {
  953. content: '+';
  954. font-size: 80rpx;
  955. color: #1ec9c9;
  956. font-weight: 300;
  957. line-height: 1;
  958. }
  959. .placeholder-text {
  960. font-size: 28rpx;
  961. color: #999999;
  962. }
  963. }
  964. }
  965. .modal-input {
  966. width: 100%;
  967. padding: 28rpx 24rpx;
  968. border: 2rpx solid #e8e8e8;
  969. border-radius: 16rpx;
  970. font-size: 30rpx;
  971. color: #333333;
  972. margin-bottom: 32rpx;
  973. box-sizing: border-box;
  974. background: #fafafa;
  975. transition: all 0.3s;
  976. line-height: 1.5;
  977. min-height: 88rpx;
  978. &:focus {
  979. border-color: #1ec9c9;
  980. background: #ffffff;
  981. box-shadow: 0 0 0 4rpx rgba(30, 201, 201, 0.1);
  982. }
  983. }
  984. .password-input-wrapper {
  985. position: relative;
  986. margin-bottom: 32rpx;
  987. .modal-input {
  988. margin-bottom: 0;
  989. padding-right: 80rpx;
  990. }
  991. .toggle-password {
  992. position: absolute;
  993. right: 24rpx;
  994. top: 50%;
  995. transform: translateY(-50%);
  996. font-size: 40rpx;
  997. cursor: pointer;
  998. padding: 8rpx;
  999. z-index: 10;
  1000. }
  1001. }
  1002. .picker-value {
  1003. width: 100%;
  1004. padding: 28rpx 24rpx;
  1005. border: 2rpx solid #e8e8e8;
  1006. border-radius: 16rpx;
  1007. display: flex;
  1008. align-items: center;
  1009. justify-content: space-between;
  1010. margin-bottom: 32rpx;
  1011. background: #fafafa;
  1012. transition: all 0.2s;
  1013. box-sizing: border-box;
  1014. min-height: 88rpx;
  1015. &:active {
  1016. background: #f0f0f0;
  1017. }
  1018. .value-text {
  1019. font-size: 30rpx;
  1020. color: #333333;
  1021. flex: 1;
  1022. overflow: hidden;
  1023. text-overflow: ellipsis;
  1024. white-space: nowrap;
  1025. }
  1026. .arrow-icon {
  1027. font-size: 24rpx;
  1028. color: #999999;
  1029. transition: transform 0.3s;
  1030. margin-left: 16rpx;
  1031. flex-shrink: 0;
  1032. }
  1033. }
  1034. .modal-actions {
  1035. display: flex;
  1036. gap: 20rpx;
  1037. margin-top: 8rpx;
  1038. .action-btn {
  1039. flex: 1;
  1040. padding: 28rpx;
  1041. border-radius: 16rpx;
  1042. display: flex;
  1043. align-items: center;
  1044. justify-content: center;
  1045. transition: all 0.2s;
  1046. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  1047. &:active {
  1048. transform: scale(0.98);
  1049. }
  1050. .btn-text {
  1051. font-size: 30rpx;
  1052. font-weight: 500;
  1053. letter-spacing: 1rpx;
  1054. }
  1055. &.cancel-btn {
  1056. background: #f5f5f5;
  1057. box-shadow: none;
  1058. &:active {
  1059. background: #e8e8e8;
  1060. }
  1061. .btn-text {
  1062. color: #666666;
  1063. }
  1064. }
  1065. &.confirm-btn {
  1066. background: linear-gradient(135deg, #1ec9c9 0%, #17b3b3 100%);
  1067. box-shadow: 0 4rpx 16rpx rgba(30, 201, 201, 0.3);
  1068. &:active {
  1069. box-shadow: 0 2rpx 8rpx rgba(30, 201, 201, 0.3);
  1070. }
  1071. .btn-text {
  1072. color: #ffffff;
  1073. }
  1074. }
  1075. }
  1076. }
  1077. }
  1078. }
  1079. }
  1080. }
  1081. </style>