index.vue 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976
  1. <template>
  2. <view class="profile-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-btn" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <text class="header-title">基本资料</text>
  9. <view class="edit-btn" @click="enableEdit">
  10. <text class="edit-text">{{ isEditing ? '保存' : '编辑' }}</text>
  11. </view>
  12. </view>
  13. <!-- 头像和基本信息 -->
  14. <view class="avatar-section">
  15. <view class="avatar-wrapper" @click="chooseAvatar">
  16. <image class="avatar" :src="profile.avatar || defaultAvatar" mode="aspectFill"></image>
  17. <view class="avatar-badge" v-if="profile.isVip">
  18. <text class="vip-icon">👑</text>
  19. </view>
  20. <view class="avatar-edit-hint">
  21. <text class="edit-hint-icon">📷</text>
  22. </view>
  23. </view>
  24. <text class="nickname">{{ profile.realName || profile.nickname || '未设置' }}</text>
  25. <text class="user-id">ID: {{ profile.userId || '未知' }}</text>
  26. </view>
  27. <!-- 编辑提示 -->
  28. <view class="edit-tip" v-if="!isEditing">
  29. <text class="tip-text">💡 点击任意字段即可编辑</text>
  30. </view>
  31. <scroll-view scroll-y class="content-scroll">
  32. <!-- 个人信息 -->
  33. <view class="section">
  34. <view class="section-title">个人信息</view>
  35. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  36. <text class="label">真实姓名</text>
  37. <input v-if="isEditing" class="input" v-model="profile.realName" placeholder="请输入真实姓名" />
  38. <text v-else class="value">{{ profile.realName || '未设置' }}</text>
  39. </view>
  40. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  41. <text class="label">身份证号</text>
  42. <input v-if="isEditing" class="input" v-model="profile.idCard" placeholder="请输入身份证号" />
  43. <text v-else class="value">{{ formatIdCard(profile.idCard) }}</text>
  44. <text class="verify-status verified" v-if="profile.idCard && profile.isRealNameVerified">✓已认证</text>
  45. <text class="verify-status unverified" v-else-if="!profile.idCard">未认证</text>
  46. </view>
  47. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  48. <text class="label">性别</text>
  49. <picker v-if="isEditing" :range="genderOptions" range-key="label" :value="getGenderIndex()" @change="onGenderChange">
  50. <view class="picker-value">{{ getGenderText() }}</view>
  51. </picker>
  52. <text v-else class="value">{{ getGenderText() }}</text>
  53. </view>
  54. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  55. <text class="label">出生日期</text>
  56. <picker v-if="isEditing" mode="date" :value="profile.birthDate" @change="onBirthDateChange">
  57. <view class="picker-value">{{ profile.birthDate || '请选择' }}</view>
  58. </picker>
  59. <text v-else class="value">{{ profile.birthDate || '未设置' }}</text>
  60. </view>
  61. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  62. <text class="label">身高</text>
  63. <input v-if="isEditing" class="input" type="number" v-model="profile.height" placeholder="请输入身高(cm)" />
  64. <text v-else class="value">{{ profile.height ? profile.height + ' cm' : '未设置' }}</text>
  65. </view>
  66. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  67. <text class="label">体重</text>
  68. <input v-if="isEditing" class="input" type="number" v-model="profile.weight" placeholder="请输入体重(kg)" />
  69. <text v-else class="value">{{ profile.weight ? profile.weight + ' kg' : '未设置' }}</text>
  70. </view>
  71. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  72. <text class="label">星座</text>
  73. <picker v-if="isEditing" :range="starOptions" @change="onStarChange">
  74. <view class="picker-value">{{ profile.star || '请选择' }}</view>
  75. </picker>
  76. <text v-else class="value">{{ profile.star || '未设置' }}</text>
  77. </view>
  78. <view class="info-item" :class="{ editing: isEditing }">
  79. <text class="label">生肖</text>
  80. <text class="value">{{ profile.animal || '未设置' }}</text>
  81. </view>
  82. <view class="info-item" :class="{ editing: isEditing }" @click="handleAreaClick">
  83. <text class="label">地区</text>
  84. <picker v-if="isEditing" mode="multiSelector" :range="multiAreaData" range-key="name" :value="multiAreaIndex" @change="onAreaChange" @columnchange="onAreaColumnChange">
  85. <view class="picker-value">{{ getAreaText() }}</view>
  86. </picker>
  87. <text v-else class="value">{{ getAreaText() }}</text>
  88. </view>
  89. </view>
  90. <!-- 学业与工作 -->
  91. <view class="section">
  92. <view class="section-title">学业与工作</view>
  93. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  94. <text class="label">学历</text>
  95. <picker v-if="isEditing" :range="educationOptions" :value="getEducationIndex()" @change="onEducationChange">
  96. <view class="picker-value">{{ getEducationText() }}</view>
  97. </picker>
  98. <text v-else class="value">{{ getEducationText() }}</text>
  99. <text class="verify-status verified" v-if="profile.educationLevel && profile.isEducationVerified">✓已认证</text>
  100. <text class="verify-status unverified" v-else-if="!profile.educationLevel">未认证</text>
  101. </view>
  102. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  103. <text class="label">学校名称</text>
  104. <input v-if="isEditing" class="input" v-model="profile.schoolName" placeholder="请输入学校名称" />
  105. <text v-else class="value">{{ profile.schoolName || '未设置' }}</text>
  106. </view>
  107. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  108. <text class="label">工作单位</text>
  109. <input v-if="isEditing" class="input" v-model="profile.company" placeholder="请输入工作单位" />
  110. <text v-else class="value">{{ profile.company || '未设置' }}</text>
  111. <text class="verify-status verified" v-if="profile.company && profile.isWorkVerified">✓已认证</text>
  112. <text class="verify-status unverified" v-else-if="!profile.company">未认证</text>
  113. </view>
  114. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  115. <text class="label">职位</text>
  116. <input v-if="isEditing" class="input" v-model="profile.jobTitle" placeholder="请输入职位" />
  117. <text v-else class="value">{{ profile.jobTitle || '未设置' }}</text>
  118. </view>
  119. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  120. <text class="label">薪资范围</text>
  121. <picker v-if="isEditing" :range="salaryOptions" :value="getSalaryIndex()" @change="onSalaryChange">
  122. <view class="picker-value">{{ getSalaryText() }}</view>
  123. </picker>
  124. <text v-else class="value">{{ getSalaryText() }}</text>
  125. </view>
  126. </view>
  127. <!-- 婚姻与住房 -->
  128. <view class="section">
  129. <view class="section-title">婚姻与住房</view>
  130. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  131. <text class="label">婚姻状况</text>
  132. <picker v-if="isEditing" :range="maritalOptions" :value="getMaritalIndex()" @change="onMaritalChange">
  133. <view class="picker-value">{{ getMaritalText() }}</view>
  134. </picker>
  135. <text v-else class="value">{{ getMaritalText() }}</text>
  136. <text class="verify-status verified" v-if="profile.maritalStatus !== null && profile.maritalStatus !== undefined && profile.isMaritalVerified">✓已认证</text>
  137. <text class="verify-status unverified" v-else-if="profile.maritalStatus === null || profile.maritalStatus === undefined">未认证</text>
  138. </view>
  139. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  140. <text class="label">房产</text>
  141. <picker v-if="isEditing" :range="houseOptions" range-key="label" :value="getHouseIndex()" @change="onHouseChange">
  142. <view class="picker-value">{{ getHouseText() }}</view>
  143. </picker>
  144. <text v-else class="value">{{ getHouseText() }}</text>
  145. </view>
  146. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  147. <text class="label">车辆</text>
  148. <picker v-if="isEditing" :range="carOptions" range-key="label" :value="getCarIndex()" @change="onCarChange">
  149. <view class="picker-value">{{ getCarText() }}</view>
  150. </picker>
  151. <text v-else class="value">{{ getCarText() }}</text>
  152. </view>
  153. </view>
  154. <!-- 兴趣爱好 -->
  155. <view class="section">
  156. <view class="section-title">兴趣爱好</view>
  157. <view class="info-item column" @click="startEdit">
  158. <text class="label">兴趣爱好标签</text>
  159. <view class="hobby-tags">
  160. <view class="hobby-tag"
  161. v-for="(hobby, index) in hobbyList"
  162. :key="index"
  163. @click.stop="isEditing ? removeHobbyTag(index) : null"
  164. :class="{ deletable: isEditing }"
  165. >
  166. {{ hobby }}
  167. <text class="delete-icon" v-if="isEditing">×</text>
  168. </view>
  169. <view class="hobby-tag add" v-if="isEditing" @click.stop="addHobby">
  170. + 添加
  171. </view>
  172. <view class="hobby-empty" v-if="hobbyList.length === 0 && !isEditing">
  173. <text class="empty-text">暂无标签</text>
  174. </view>
  175. </view>
  176. </view>
  177. </view>
  178. <!-- 隐私设置 -->
  179. <view class="section">
  180. <view class="section-title">隐私设置</view>
  181. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  182. <text class="label">薪资公开</text>
  183. <switch :checked="profile.privacySalary === 1" @change="onPrivacySalaryChange" :disabled="!isEditing" />
  184. </view>
  185. <view class="info-item" :class="{ editing: isEditing }" @click="startEdit">
  186. <text class="label">手机号公开</text>
  187. <switch :checked="profile.privacyPhone === 1" @change="onPrivacyPhoneChange" :disabled="!isEditing" />
  188. </view>
  189. </view>
  190. <!-- 真实度评分 -->
  191. <view class="section">
  192. <view class="section-title">真实度评分</view>
  193. <view class="authenticity-score">
  194. <view class="score-circle">
  195. <text class="score-number">{{ profile.authenticityScore || 0 }}</text>
  196. <text class="score-total">/100</text>
  197. </view>
  198. <view class="score-tips">
  199. <text class="tip-text">完善资料并通过认证可提升真实度评分</text>
  200. </view>
  201. </view>
  202. </view>
  203. <!-- 底部占位 -->
  204. <view class="bottom-placeholder"></view>
  205. </scroll-view>
  206. <!-- 标签选择弹窗 -->
  207. <view class="hobby-modal" v-if="showHobbyModal" @click="closeHobbyModal">
  208. <view class="modal-content" @click.stop>
  209. <view class="modal-header">
  210. <text class="modal-title">选择兴趣爱好标签</text>
  211. <text class="close-btn" @click="closeHobbyModal">×</text>
  212. </view>
  213. <scroll-view scroll-y class="modal-body">
  214. <!-- 预设标签分类 -->
  215. <view class="hobby-category" v-for="(category, index) in hobbyCategories" :key="index">
  216. <view class="category-title">
  217. <text class="category-icon">{{ category.icon }}</text>
  218. <text class="category-name">{{ category.name }}</text>
  219. </view>
  220. <view class="category-tags">
  221. <view class="preset-tag"
  222. v-for="(tag, tagIndex) in category.tags"
  223. :key="tagIndex"
  224. @click="selectPresetTag(tag)"
  225. :class="{ selected: hobbyList.includes(tag) }"
  226. >
  227. {{ tag }}
  228. <text class="check-icon" v-if="hobbyList.includes(tag)">✓</text>
  229. </view>
  230. </view>
  231. </view>
  232. <!-- 自定义输入 -->
  233. <view class="custom-input-section">
  234. <view class="category-title">
  235. <text class="category-icon">✏️</text>
  236. <text class="category-name">自定义标签</text>
  237. </view>
  238. <view class="input-wrapper">
  239. <input
  240. class="custom-input"
  241. v-model="customHobbyInput"
  242. placeholder="输入自定义标签"
  243. @confirm="addCustomTag"
  244. />
  245. <view class="add-custom-btn" @click="addCustomTag">
  246. <text class="add-text">添加</text>
  247. </view>
  248. </view>
  249. </view>
  250. </scroll-view>
  251. <view class="modal-footer">
  252. <text class="selected-count">已选择 {{ hobbyList.length }}/10 个标签</text>
  253. <view class="done-btn" @click="closeHobbyModal">
  254. <text class="done-text">完成</text>
  255. </view>
  256. </view>
  257. </view>
  258. </view>
  259. </view>
  260. </template>
  261. <script>
  262. import userAuth from '@/utils/userAuth.js'
  263. import { getZodiacByBirthday } from '@/utils/zodiac.js'
  264. import api from '@/utils/api.js'
  265. export default {
  266. data() {
  267. return {
  268. gatewayURL: 'https://api.zhongruanke.cn',
  269. currentUserId: null,
  270. isEditing: false,
  271. defaultAvatar: 'https://via.placeholder.com/150',
  272. // 用户资料数据
  273. profile: {
  274. userId: null,
  275. avatar: uni.getStorageSync("userInfo").avatarUrl,
  276. nickname: '',
  277. realName: '',
  278. idCard: '',
  279. gender: null,
  280. birthDate: '',
  281. height: null,
  282. weight: null,
  283. star: '',
  284. animal: '',
  285. educationLevel: null,
  286. schoolName: '',
  287. company: '',
  288. jobTitle: '',
  289. salaryRange: null,
  290. maritalStatus: null,
  291. house: null,
  292. car: null,
  293. hobby: '',
  294. privacySalary: 0,
  295. privacyPhone: 0,
  296. authenticityScore: 0,
  297. isVip: false,
  298. isRealNameVerified: false,
  299. isEducationVerified: false,
  300. isWorkVerified: false,
  301. isMaritalVerified: false,
  302. provinceId: null,
  303. cityId: null,
  304. areaId: null
  305. },
  306. // 选项列表
  307. genderOptions: [
  308. { value: 1, label: '男' },
  309. { value: 2, label: '女' }
  310. ],
  311. starOptions: ['白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座',
  312. '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座'],
  313. animalOptions: ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪'],
  314. educationOptions: ['高中', '专科', '本科', '硕士', '博士', '无'],
  315. salaryOptions: ['1-5k', '5-10k', '10-20k', '20-50k', '50k+'],
  316. maritalOptions: ['未婚', '离异', '丧偶'],
  317. houseOptions: [
  318. { value: 0, label: '无' },
  319. { value: 1, label: '有' }
  320. ],
  321. carOptions: [
  322. { value: 0, label: '无' },
  323. { value: 1, label: '有' }
  324. ],
  325. // 标签选择弹窗
  326. showHobbyModal: false,
  327. hobbyCategories: [
  328. {
  329. name: '运动健身',
  330. icon: '🏃',
  331. tags: ['运动', '健身', '瑜伽', '爬山', '游泳', '篮球', '足球', '网球']
  332. },
  333. {
  334. name: '文艺休闲',
  335. icon: '🎨',
  336. tags: ['旅游', '阅读', '音乐', '电影', '摄影', '绘画', '舞蹈', '唱歌']
  337. },
  338. {
  339. name: '技能爱好',
  340. icon: '🎹',
  341. tags: ['钢琴', '吉他', '书法', '茶艺', '烹饪', '园艺', '手工', '收藏']
  342. },
  343. {
  344. name: '生活方式',
  345. icon: '🌟',
  346. tags: ['美食', '游戏', '宠物', '时尚', '购物', '化妆']
  347. }
  348. ],
  349. customHobbyInput: '',
  350. // 省市区数据
  351. provinceList: [],
  352. cityList: [],
  353. areaList: [],
  354. multiAreaData: [[], [], []], // 三级联动数据
  355. multiAreaIndex: [0, 0, 0] // 三级联动索引
  356. }
  357. },
  358. computed: {
  359. hobbyList() {
  360. if (!this.profile.hobby) return []
  361. try {
  362. return JSON.parse(this.profile.hobby)
  363. } catch (e) {
  364. return this.profile.hobby.split(',').filter(item => item)
  365. }
  366. }
  367. },
  368. onLoad() {
  369. // 获取登录用户ID - 使用userAuth工具类
  370. this.currentUserId = userAuth.getUserId()
  371. // 检查是否已登录(userId为1也是合法的测试用户)
  372. if (this.currentUserId === null || this.currentUserId === undefined || this.currentUserId === 0) {
  373. this.checkLoginStatus()
  374. } else {
  375. // 加载省市区数据
  376. this.loadAreaData()
  377. // 加载用户资料
  378. this.loadProfile()
  379. }
  380. },
  381. methods: {
  382. // 选择并上传头像
  383. chooseAvatar() {
  384. uni.showActionSheet({
  385. itemList: ['从相册选择', '拍照'],
  386. success: (res) => {
  387. if (res.tapIndex === 0) {
  388. // 从相册选择
  389. this.selectImage('album')
  390. } else if (res.tapIndex === 1) {
  391. // 拍照
  392. this.selectImage('camera')
  393. }
  394. }
  395. })
  396. },
  397. // 选择图片
  398. selectImage(sourceType) {
  399. uni.chooseImage({
  400. count: 1,
  401. sizeType: ['compressed'], // 使用压缩图
  402. sourceType: [sourceType],
  403. success: (res) => {
  404. const tempFilePath = res.tempFilePaths[0]
  405. // 上传图片
  406. this.uploadAvatar(tempFilePath)
  407. },
  408. fail: (err) => {
  409. console.error('选择图片失败:', err)
  410. uni.showToast({
  411. title: '选择图片失败',
  412. icon: 'none'
  413. })
  414. }
  415. })
  416. },
  417. // 上传头像
  418. uploadAvatar(filePath) {
  419. uni.showLoading({
  420. title: '上传中...',
  421. mask: true
  422. })
  423. // 使用 uni.uploadFile 上传到服务器
  424. const uploadTask = uni.uploadFile({
  425. url: this.gatewayURL + '/api/avatar/upload',
  426. filePath: filePath,
  427. name: 'file',
  428. timeout: 60000, // 设置超时时间为60秒
  429. formData: {
  430. userId: this.currentUserId
  431. },
  432. success: (uploadRes) => {
  433. uni.hideLoading()
  434. // 检查HTTP状态码
  435. if (uploadRes.statusCode !== 200) {
  436. console.error('HTTP错误:', uploadRes.statusCode)
  437. uni.showToast({
  438. title: `服务器错误: ${uploadRes.statusCode}`,
  439. icon: 'none',
  440. duration: 3000
  441. })
  442. return
  443. }
  444. try {
  445. const result = JSON.parse(uploadRes.data)
  446. if (result.code === 200) {
  447. // 更新头像URL
  448. this.profile.avatar = result.data
  449. // 更新本地存储的用户信息
  450. const userInfo = uni.getStorageSync('userInfo')
  451. if (userInfo) {
  452. userInfo.avatarUrl = result.data
  453. uni.setStorageSync('userInfo', userInfo)
  454. }
  455. uni.showToast({
  456. title: '头像上传成功',
  457. icon: 'success',
  458. duration: 2000
  459. })
  460. // 刷新页面数据
  461. setTimeout(() => {
  462. this.loadProfile()
  463. }, 500)
  464. } else {
  465. console.error('❌ 业务错误:', result.message)
  466. uni.showToast({
  467. title: result.message || '上传失败',
  468. icon: 'none',
  469. duration: 3000
  470. })
  471. }
  472. } catch (e) {
  473. console.error('❌ 解析响应失败:', e)
  474. console.error('原始响应数据:', uploadRes.data)
  475. uni.showToast({
  476. title: '服务器响应格式错误',
  477. icon: 'none',
  478. duration: 3000
  479. })
  480. }
  481. },
  482. fail: (err) => {
  483. uni.hideLoading()
  484. console.error('❌ 上传失败:', err)
  485. let errorMsg = '上传失败'
  486. if (err.errMsg) {
  487. if (err.errMsg.includes('timeout')) {
  488. errorMsg = '上传超时,请检查网络连接'
  489. } else if (err.errMsg.includes('fail')) {
  490. errorMsg = '网络连接失败'
  491. } else {
  492. errorMsg = err.errMsg
  493. }
  494. }
  495. uni.showToast({
  496. title: errorMsg,
  497. icon: 'none',
  498. duration: 3000
  499. })
  500. }
  501. })
  502. // 监听上传进度
  503. uploadTask.onProgressUpdate((res) => {
  504. if (res.progress % 20 === 0 || res.progress > 90) {
  505. }
  506. })
  507. },
  508. // 检查登录状态
  509. checkLoginStatus() {
  510. const token = uni.getStorageSync('token')
  511. const userInfo = uni.getStorageSync('userInfo')
  512. if (!token || !userInfo) {
  513. // 没有登录信息,跳转到登录页
  514. uni.showModal({
  515. title: '需要登录',
  516. content: '请先登录后查看个人资料',
  517. showCancel: false,
  518. confirmText: '去登录',
  519. success: () => {
  520. uni.navigateTo({
  521. url: '/pages/page3/page3?redirect=' + encodeURIComponent('/pages/profile/index')
  522. })
  523. }
  524. })
  525. return false
  526. }
  527. if (this.currentUserId === null || this.currentUserId === undefined || this.currentUserId === 0) {
  528. // 有登录信息但无法获取用户ID - 登录信息异常
  529. uni.showModal({
  530. title: '登录信息异常',
  531. content: '登录信息不完整,请重新登录',
  532. showCancel: false,
  533. confirmText: '重新登录',
  534. success: () => {
  535. // 清除异常的登录信息
  536. uni.clearStorageSync()
  537. uni.navigateTo({
  538. url: '/pages/page3/page3?redirect=' + encodeURIComponent('/pages/profile/index')
  539. })
  540. }
  541. })
  542. return false
  543. }
  544. return true
  545. },
  546. // 加载用户资料
  547. loadProfile() {
  548. uni.showLoading({
  549. title: '加载中...'
  550. })
  551. uni.request({
  552. url: this.gatewayURL + '/api/user/profile?userId=' + this.currentUserId,
  553. method: 'GET',
  554. success: async (res) => {
  555. uni.hideLoading()
  556. if (res.data && res.data.code === 200) {
  557. // 确保省市区ID正确赋值(处理可能的字段名不匹配)
  558. const profileData = { ...res.data.data }
  559. // 如果字段名是下划线格式,转换为驼峰格式
  560. if (profileData.province_id !== undefined && profileData.provinceId === undefined) {
  561. profileData.provinceId = profileData.province_id
  562. }
  563. if (profileData.city_id !== undefined && profileData.cityId === undefined) {
  564. profileData.cityId = profileData.city_id
  565. }
  566. if (profileData.area_id !== undefined && profileData.areaId === undefined) {
  567. profileData.areaId = profileData.area_id
  568. }
  569. this.profile = { ...this.profile, ...profileData }
  570. // 先加载省市区数据,然后再初始化索引和显示
  571. await this.loadAreaData()
  572. // 如果有省市区ID,加载对应的城市和区域数据,并初始化选择器索引
  573. if (this.profile.provinceId || this.profile.cityId || this.profile.areaId) {
  574. // 先加载省份对应的城市
  575. if (this.profile.provinceId) {
  576. await this.loadCitiesForProvince(this.profile.provinceId)
  577. }
  578. // 再加载城市对应的区域
  579. if (this.profile.cityId) {
  580. await this.loadAreasForCity(this.profile.cityId)
  581. }
  582. // 最后初始化选择器索引
  583. setTimeout(() => {
  584. this.initAreaIndex()
  585. }, 300)
  586. }
  587. } else {
  588. uni.showToast({
  589. title: res.data?.message || '加载失败',
  590. icon: 'none'
  591. })
  592. }
  593. },
  594. fail: (err) => {
  595. uni.hideLoading()
  596. console.error('加载用户资料失败:', err)
  597. uni.showToast({
  598. title: '网络请求失败',
  599. icon: 'none'
  600. })
  601. }
  602. })
  603. },
  604. // 格式化身份证号(隐藏中间部分)
  605. formatIdCard(idCard) {
  606. if (!idCard) return '未设置'
  607. if (idCard.length < 8) return idCard
  608. return idCard.substring(0, 6) + '********' + idCard.substring(idCard.length - 4)
  609. },
  610. // 获取性别文本
  611. getGenderText() {
  612. const option = this.genderOptions.find(item => item.value === this.profile.gender)
  613. return option ? option.label : '未设置'
  614. },
  615. // 获取学历文本
  616. getEducationText() {
  617. if (this.profile.educationLevel === null || this.profile.educationLevel === undefined) return '未设置'
  618. const index = this.profile.educationLevel - 1
  619. return this.educationOptions[index] || '未设置'
  620. },
  621. // 获取薪资文本
  622. getSalaryText() {
  623. if (this.profile.salaryRange === null || this.profile.salaryRange === undefined) return '未设置'
  624. const index = this.profile.salaryRange - 1
  625. return this.salaryOptions[index] || '未设置'
  626. },
  627. // 获取薪资选择器的索引
  628. getSalaryIndex() {
  629. if (this.profile.salaryRange === null || this.profile.salaryRange === undefined) {
  630. return 0 // 默认选择第一项
  631. }
  632. const index = this.profile.salaryRange - 1
  633. // 确保索引在有效范围内
  634. return Math.max(0, Math.min(index, this.salaryOptions.length - 1))
  635. },
  636. // 获取性别选择器的索引
  637. getGenderIndex() {
  638. const option = this.genderOptions.findIndex(item => item.value === this.profile.gender)
  639. return Math.max(0, option)
  640. },
  641. // 获取学历选择器的索引
  642. getEducationIndex() {
  643. if (this.profile.educationLevel === null || this.profile.educationLevel === undefined) {
  644. return 0
  645. }
  646. const index = this.profile.educationLevel - 1
  647. return Math.max(0, Math.min(index, this.educationOptions.length - 1))
  648. },
  649. // 获取婚姻状况选择器的索引
  650. getMaritalIndex() {
  651. if (this.profile.maritalStatus === null || this.profile.maritalStatus === undefined) {
  652. return 0
  653. }
  654. return Math.max(0, Math.min(this.profile.maritalStatus, this.maritalOptions.length - 1))
  655. },
  656. // 获取房产选择器的索引
  657. getHouseIndex() {
  658. const option = this.houseOptions.findIndex(item => item.value === this.profile.house)
  659. return Math.max(0, option)
  660. },
  661. // 获取车辆选择器的索引
  662. getCarIndex() {
  663. const option = this.carOptions.findIndex(item => item.value === this.profile.car)
  664. return Math.max(0, option)
  665. },
  666. // 获取婚姻状况文本
  667. getMaritalText() {
  668. if (this.profile.maritalStatus === null || this.profile.maritalStatus === undefined) return '未设置'
  669. const index = this.profile.maritalStatus
  670. return this.maritalOptions[index] || '未设置'
  671. },
  672. // 获取房产文本
  673. getHouseText() {
  674. const option = this.houseOptions.find(item => item.value === this.profile.house)
  675. return option ? option.label : '未设置'
  676. },
  677. // 获取车辆文本
  678. getCarText() {
  679. const option = this.carOptions.find(item => item.value === this.profile.car)
  680. return option ? option.label : '未设置'
  681. },
  682. // 选择器改变事件
  683. onGenderChange(e) {
  684. this.profile.gender = this.genderOptions[parseInt(e.detail.value)].value
  685. },
  686. onBirthDateChange(e) {
  687. this.profile.birthDate = e.detail.value
  688. // 自动计算并设置生肖
  689. if (this.profile.birthDate) {
  690. const zodiac = getZodiacByBirthday(this.profile.birthDate)
  691. this.profile.animal = zodiac
  692. }
  693. },
  694. onStarChange(e) {
  695. this.profile.star = this.starOptions[parseInt(e.detail.value)]
  696. },
  697. onAnimalChange(e) {
  698. this.profile.animal = this.animalOptions[parseInt(e.detail.value)]
  699. },
  700. onEducationChange(e) {
  701. // 将字符串转换为数字
  702. this.profile.educationLevel = parseInt(e.detail.value) + 1
  703. },
  704. onSalaryChange(e) {
  705. // 将字符串转换为数字,避免字符串拼接问题
  706. this.profile.salaryRange = parseInt(e.detail.value) + 1
  707. },
  708. onMaritalChange(e) {
  709. // 将字符串转换为数字
  710. this.profile.maritalStatus = parseInt(e.detail.value)
  711. },
  712. onHouseChange(e) {
  713. this.profile.house = this.houseOptions[parseInt(e.detail.value)].value
  714. },
  715. onCarChange(e) {
  716. this.profile.car = this.carOptions[parseInt(e.detail.value)].value
  717. },
  718. onPrivacySalaryChange(e) {
  719. this.profile.privacySalary = e.detail.value ? 1 : 0
  720. },
  721. onPrivacyPhoneChange(e) {
  722. this.profile.privacyPhone = e.detail.value ? 1 : 0
  723. },
  724. // 省市区相关方法
  725. // 加载省市区数据
  726. async loadAreaData() {
  727. try {
  728. // 加载省份列表
  729. const provinceRes = await api.area.getProvinces()
  730. // api.js 已经处理了数据格式,直接使用返回的数组
  731. if (Array.isArray(provinceRes)) {
  732. this.provinceList = provinceRes
  733. } else if (provinceRes && provinceRes.data) {
  734. this.provinceList = provinceRes.data
  735. } else if (provinceRes && provinceRes.code === 200 && provinceRes.data) {
  736. this.provinceList = provinceRes.data
  737. } else {
  738. this.provinceList = []
  739. }
  740. this.multiAreaData[0] = this.provinceList
  741. // 如果有已选择的省份,加载对应的城市
  742. if (this.profile.provinceId) {
  743. await this.loadCitiesForProvince(this.profile.provinceId)
  744. } else if (this.provinceList.length > 0) {
  745. // 默认加载第一个省份的城市
  746. await this.loadCitiesForProvince(this.provinceList[0].id)
  747. }
  748. } catch (e) {
  749. console.error('加载省份失败:', e)
  750. uni.showToast({
  751. title: '加载省份数据失败',
  752. icon: 'none'
  753. })
  754. }
  755. },
  756. // 根据省份ID加载城市
  757. async loadCitiesForProvince(provinceId) {
  758. if (!provinceId) return
  759. try {
  760. const cityRes = await api.area.getCities(provinceId)
  761. // api.js 已经处理了数据格式,直接使用返回的数组
  762. if (Array.isArray(cityRes)) {
  763. this.cityList = cityRes
  764. } else if (cityRes && cityRes.data) {
  765. this.cityList = cityRes.data
  766. } else if (cityRes && cityRes.code === 200 && cityRes.data) {
  767. this.cityList = cityRes.data
  768. } else {
  769. this.cityList = []
  770. }
  771. this.multiAreaData[1] = this.cityList
  772. // 如果有已选择的城市,加载对应的区域
  773. if (this.profile.cityId) {
  774. await this.loadAreasForCity(this.profile.cityId)
  775. } else if (this.cityList.length > 0) {
  776. // 默认加载第一个城市的区域
  777. await this.loadAreasForCity(this.cityList[0].id)
  778. } else {
  779. this.multiAreaData[2] = []
  780. this.areaList = []
  781. }
  782. } catch (e) {
  783. console.error('加载城市失败:', e)
  784. this.cityList = []
  785. this.multiAreaData[1] = []
  786. this.multiAreaData[2] = []
  787. this.areaList = []
  788. }
  789. },
  790. // 根据城市ID加载区域
  791. async loadAreasForCity(cityId) {
  792. if (!cityId) return
  793. try {
  794. const areaRes = await api.area.getAreas(cityId)
  795. // api.js 已经处理了数据格式,直接使用返回的数组
  796. if (Array.isArray(areaRes)) {
  797. this.areaList = areaRes
  798. } else if (areaRes && areaRes.data) {
  799. this.areaList = areaRes.data
  800. } else if (areaRes && areaRes.code === 200 && areaRes.data) {
  801. this.areaList = areaRes.data
  802. } else {
  803. this.areaList = []
  804. }
  805. this.multiAreaData[2] = this.areaList
  806. } catch (e) {
  807. console.error('加载区域失败:', e)
  808. this.areaList = []
  809. this.multiAreaData[2] = []
  810. }
  811. },
  812. // 省市区选择器列变化事件
  813. async onAreaColumnChange(e) {
  814. const column = e.detail.column // 列索引:0-省,1-市,2-区
  815. const row = e.detail.value // 选中的行索引
  816. if (column === 0) {
  817. // 选择了省份
  818. const province = this.provinceList[row]
  819. if (province && province.id) {
  820. this.multiAreaIndex[0] = row
  821. this.multiAreaIndex[1] = 0
  822. this.multiAreaIndex[2] = 0
  823. // 加载该省份的城市
  824. await this.loadCitiesForProvince(province.id)
  825. }
  826. } else if (column === 1) {
  827. // 选择了城市
  828. const city = this.cityList[row]
  829. if (city && city.id) {
  830. this.multiAreaIndex[1] = row
  831. this.multiAreaIndex[2] = 0
  832. // 加载该城市的区域
  833. await this.loadAreasForCity(city.id)
  834. }
  835. } else if (column === 2) {
  836. // 选择了区域
  837. this.multiAreaIndex[2] = row
  838. }
  839. },
  840. // 省市区选择器确认事件
  841. onAreaChange(e) {
  842. const values = e.detail.value
  843. this.multiAreaIndex = values
  844. // 设置选中的省市区ID
  845. if (this.provinceList[values[0]]) {
  846. this.profile.provinceId = this.provinceList[values[0]].id
  847. }
  848. if (this.cityList[values[1]]) {
  849. this.profile.cityId = this.cityList[values[1]].id
  850. }
  851. if (this.areaList[values[2]]) {
  852. this.profile.areaId = this.areaList[values[2]].id
  853. }
  854. },
  855. // 获取地区显示文本
  856. getAreaText() {
  857. // 如果没有省市区ID,返回未设置
  858. if (!this.profile.provinceId && !this.profile.cityId && !this.profile.areaId) {
  859. return '未设置'
  860. }
  861. let text = ''
  862. let hasText = false
  863. // 查找省份名称
  864. if (this.profile.provinceId) {
  865. if (this.provinceList.length > 0) {
  866. const province = this.provinceList.find(p => p.id === this.profile.provinceId)
  867. if (province) {
  868. text += province.name
  869. hasText = true
  870. }
  871. } else {
  872. // 如果省份列表还没加载,触发加载
  873. if (this.provinceList.length === 0) {
  874. this.loadAreaData()
  875. }
  876. return '加载中...'
  877. }
  878. }
  879. // 查找城市名称
  880. if (this.profile.cityId) {
  881. if (this.cityList.length > 0) {
  882. const city = this.cityList.find(c => c.id === this.profile.cityId)
  883. if (city) {
  884. text += (hasText ? ' ' : '') + city.name
  885. hasText = true
  886. }
  887. } else if (this.profile.provinceId) {
  888. // 如果城市列表还没加载但有省份ID,加载城市数据
  889. this.loadCitiesForProvince(this.profile.provinceId)
  890. return hasText ? text + ' 加载中...' : '加载中...'
  891. }
  892. }
  893. // 查找区域名称
  894. if (this.profile.areaId) {
  895. if (this.areaList.length > 0) {
  896. const area = this.areaList.find(a => a.id === this.profile.areaId)
  897. if (area) {
  898. text += (hasText ? ' ' : '') + area.name
  899. hasText = true
  900. }
  901. } else if (this.profile.cityId) {
  902. // 如果区域列表还没加载但有城市ID,加载区域数据
  903. this.loadAreasForCity(this.profile.cityId)
  904. return hasText ? text + ' 加载中...' : '加载中...'
  905. }
  906. }
  907. return text || '未设置'
  908. },
  909. // 初始化省市区选择器索引(根据已保存的ID)
  910. async initAreaIndex() {
  911. if (!this.profile.provinceId) {
  912. return
  913. }
  914. // 如果省份列表还没加载,先加载
  915. if (this.provinceList.length === 0) {
  916. await this.loadAreaData()
  917. }
  918. // 查找省份索引
  919. const provinceIndex = this.provinceList.findIndex(p => p.id === this.profile.provinceId)
  920. if (provinceIndex >= 0) {
  921. this.multiAreaIndex[0] = provinceIndex
  922. // 加载该省份的城市
  923. await this.loadCitiesForProvince(this.profile.provinceId)
  924. // 等待城市加载完成后再查找城市索引
  925. await new Promise(resolve => setTimeout(resolve, 300))
  926. if (this.profile.cityId) {
  927. const cityIndex = this.cityList.findIndex(c => c.id === this.profile.cityId)
  928. if (cityIndex >= 0) {
  929. this.multiAreaIndex[1] = cityIndex
  930. // 加载该城市的区域
  931. await this.loadAreasForCity(this.profile.cityId)
  932. // 等待区域加载完成后再查找区域索引
  933. await new Promise(resolve => setTimeout(resolve, 300))
  934. if (this.profile.areaId) {
  935. const areaIndex = this.areaList.findIndex(a => a.id === this.profile.areaId)
  936. if (areaIndex >= 0) {
  937. this.multiAreaIndex[2] = areaIndex
  938. }
  939. }
  940. }
  941. }
  942. // 强制更新视图
  943. this.$forceUpdate()
  944. } else {
  945. console.warn('未找到省份索引,省份ID:', this.profile.provinceId)
  946. }
  947. },
  948. // 显示标签选择弹窗
  949. addHobby() {
  950. this.showHobbyModal = true
  951. },
  952. // 关闭标签选择弹窗
  953. closeHobbyModal() {
  954. this.showHobbyModal = false
  955. this.customHobbyInput = ''
  956. },
  957. // 选择预设标签
  958. selectPresetTag(tag) {
  959. if (this.hobbyList.includes(tag)) {
  960. // 如果已选中,则移除
  961. this.removeHobbyTag(this.hobbyList.indexOf(tag))
  962. } else {
  963. // 如果未选中,则添加
  964. this.addHobbyTag(tag)
  965. }
  966. },
  967. // 添加自定义标签
  968. addCustomTag() {
  969. const customTag = this.customHobbyInput.trim()
  970. if (customTag) {
  971. this.addHobbyTag(customTag)
  972. this.customHobbyInput = ''
  973. } else {
  974. uni.showToast({
  975. title: '请输入标签内容',
  976. icon: 'none'
  977. })
  978. }
  979. },
  980. // 添加标签到列表
  981. addHobbyTag(hobbyText) {
  982. let currentHobbies = this.hobbyList.slice()
  983. // 检查是否已存在
  984. if (currentHobbies.includes(hobbyText)) {
  985. uni.showToast({
  986. title: '标签已存在',
  987. icon: 'none'
  988. })
  989. return
  990. }
  991. // 限制标签数量
  992. if (currentHobbies.length >= 10) {
  993. uni.showToast({
  994. title: '最多只能添加10个标签',
  995. icon: 'none'
  996. })
  997. return
  998. }
  999. // 添加新标签
  1000. currentHobbies.push(hobbyText)
  1001. // 更新hobby字段(转为JSON格式)
  1002. this.profile.hobby = JSON.stringify(currentHobbies)
  1003. uni.showToast({
  1004. title: '标签添加成功',
  1005. icon: 'success'
  1006. })
  1007. },
  1008. // 移除标签
  1009. removeHobbyTag(index) {
  1010. uni.showModal({
  1011. title: '确认删除',
  1012. content: '确定要删除这个标签吗?',
  1013. success: (res) => {
  1014. if (res.confirm) {
  1015. let currentHobbies = this.hobbyList.slice()
  1016. currentHobbies.splice(index, 1)
  1017. // 更新hobby字段
  1018. this.profile.hobby = currentHobbies.length > 0 ? JSON.stringify(currentHobbies) : ''
  1019. uni.showToast({
  1020. title: '标签删除成功',
  1021. icon: 'success'
  1022. })
  1023. }
  1024. }
  1025. })
  1026. },
  1027. // 点击字段进入编辑模式
  1028. startEdit() {
  1029. if (!this.isEditing) {
  1030. this.isEditing = true
  1031. // 提示用户已进入编辑模式
  1032. uni.showToast({
  1033. title: '已进入编辑模式',
  1034. icon: 'none',
  1035. duration: 1000
  1036. })
  1037. }
  1038. },
  1039. // 处理地区点击事件
  1040. handleAreaClick() {
  1041. if (!this.isEditing) {
  1042. this.startEdit()
  1043. }
  1044. // 如果数据还没加载,立即加载
  1045. if (this.provinceList.length === 0) {
  1046. this.loadAreaData()
  1047. }
  1048. },
  1049. // 启用编辑/保存
  1050. enableEdit() {
  1051. if (this.isEditing) {
  1052. // 保存
  1053. this.saveProfile()
  1054. } else {
  1055. // 进入编辑模式
  1056. this.isEditing = true
  1057. }
  1058. },
  1059. // 保存资料
  1060. saveProfile(needGoBack = false) {
  1061. uni.showLoading({
  1062. title: '保存中...'
  1063. })
  1064. // 准备提交的数据(只包含扩展信息字段)
  1065. const submitData = {
  1066. userId: this.currentUserId,
  1067. realName: this.profile.realName,
  1068. idCard: this.profile.idCard,
  1069. height: this.profile.height,
  1070. weight: this.profile.weight,
  1071. gender: this.profile.gender,
  1072. birthDate: this.profile.birthDate,
  1073. star: this.profile.star,
  1074. animal: this.profile.animal,
  1075. educationLevel: this.profile.educationLevel,
  1076. schoolName: this.profile.schoolName,
  1077. company: this.profile.company,
  1078. jobTitle: this.profile.jobTitle,
  1079. salaryRange: this.profile.salaryRange,
  1080. maritalStatus: this.profile.maritalStatus,
  1081. house: this.profile.house,
  1082. car: this.profile.car,
  1083. hobby: this.profile.hobby,
  1084. privacySalary: this.profile.privacySalary,
  1085. privacyPhone: this.profile.privacyPhone,
  1086. provinceId: this.profile.provinceId || null,
  1087. cityId: this.profile.cityId || null,
  1088. areaId: this.profile.areaId || null
  1089. }
  1090. uni.request({
  1091. url: this.gatewayURL + '/api/user/profile',
  1092. method: 'PUT',
  1093. data: submitData,
  1094. success: (res) => {
  1095. uni.hideLoading()
  1096. if (res.data && res.data.code === 200) {
  1097. uni.showToast({
  1098. title: '保存成功',
  1099. icon: 'success',
  1100. duration: 1500
  1101. })
  1102. this.isEditing = false
  1103. // 更新 storage 中的 userInfo,特别是性别信息
  1104. const storedUserInfo = uni.getStorageSync('userInfo');
  1105. if (storedUserInfo) {
  1106. // 更新性别信息
  1107. if (submitData.gender !== undefined && submitData.gender !== null) {
  1108. storedUserInfo.gender = submitData.gender;
  1109. }
  1110. // 更新其他可能变化的字段
  1111. if (submitData.birthDate) {
  1112. storedUserInfo.birthDate = submitData.birthDate;
  1113. }
  1114. uni.setStorageSync('userInfo', storedUserInfo);
  1115. }
  1116. // 重新加载资料
  1117. this.loadProfile()
  1118. // 如果需要返回,延迟执行返回操作
  1119. if (needGoBack) {
  1120. setTimeout(() => {
  1121. this.performGoBack()
  1122. }, 1000)
  1123. }
  1124. } else {
  1125. uni.showToast({
  1126. title: res.data?.message || '保存失败',
  1127. icon: 'none'
  1128. })
  1129. }
  1130. },
  1131. fail: (err) => {
  1132. uni.hideLoading()
  1133. console.error('保存失败:', err)
  1134. uni.showToast({
  1135. title: '网络请求失败',
  1136. icon: 'none'
  1137. })
  1138. }
  1139. })
  1140. },
  1141. // 返回上一页
  1142. goBack() {
  1143. try {
  1144. // 如果正在编辑,先提醒保存
  1145. if (this.isEditing) {
  1146. uni.showModal({
  1147. title: '提示',
  1148. content: '您正在编辑资料,是否保存后返回?',
  1149. showCancel: true,
  1150. cancelText: '直接返回',
  1151. confirmText: '保存并返回',
  1152. success: (res) => {
  1153. if (res.confirm) {
  1154. // 保存后返回
  1155. this.saveProfile(true)
  1156. } else {
  1157. // 直接返回
  1158. this.performGoBack()
  1159. }
  1160. }
  1161. })
  1162. } else {
  1163. // 直接返回
  1164. this.performGoBack()
  1165. }
  1166. } catch (error) {
  1167. console.error('返回操作异常:', error)
  1168. // 异常时直接跳转到我的页面
  1169. uni.navigateTo({
  1170. url: '/pages/mine/index'
  1171. })
  1172. }
  1173. },
  1174. // 执行返回操作
  1175. performGoBack() {
  1176. // 检查页面栈
  1177. const pages = getCurrentPages()
  1178. if (pages.length > 1) {
  1179. // 有上一页,正常返回
  1180. uni.navigateBack({
  1181. delta: 1,
  1182. success: () => {
  1183. },
  1184. fail: (err) => {
  1185. console.error('返回失败:', err)
  1186. // 返回失败时,提示用户并提供选择
  1187. uni.showModal({
  1188. title: '返回失败',
  1189. content: '无法返回上一页,是否跳转到我的页面?',
  1190. showCancel: true,
  1191. cancelText: '留在此页',
  1192. confirmText: '去我的页面',
  1193. success: (modalRes) => {
  1194. if (modalRes.confirm) {
  1195. uni.navigateTo({
  1196. url: '/pages/mine/index'
  1197. })
  1198. }
  1199. }
  1200. })
  1201. }
  1202. })
  1203. } else {
  1204. // 没有上一页,直接跳转到我的页面
  1205. uni.navigateTo({
  1206. url: '/pages/mine/index'
  1207. })
  1208. }
  1209. }
  1210. }
  1211. }
  1212. </script>
  1213. <style lang="scss" scoped>
  1214. .profile-page {
  1215. min-height: 100vh;
  1216. background: linear-gradient(180deg, #FF8A9B 0%, #FFB4C0 25%, #FFF0F2 50%, #F8F8F8 100%);
  1217. display: flex;
  1218. flex-direction: column;
  1219. }
  1220. /* 顶部导航栏 */
  1221. .header {
  1222. position: relative;
  1223. display: flex;
  1224. align-items: center;
  1225. justify-content: center;
  1226. padding: 25rpx 30rpx;
  1227. padding-top: calc(25rpx + env(safe-area-inset-top));
  1228. background: linear-gradient(135deg, #FF8A9B 0%, #FFB4C0 100%);
  1229. box-shadow: 0 4rpx 20rpx rgba(255, 138, 155, 0.2);
  1230. .back-btn {
  1231. position: absolute;
  1232. left: 30rpx;
  1233. width: 70rpx;
  1234. height: 70rpx;
  1235. display: flex;
  1236. align-items: center;
  1237. justify-content: center;
  1238. background: rgba(255, 255, 255, 0.2);
  1239. border-radius: 50%;
  1240. .back-icon {
  1241. font-size: 44rpx;
  1242. color: #FFFFFF;
  1243. font-weight: bold;
  1244. }
  1245. }
  1246. .header-title {
  1247. font-size: 38rpx;
  1248. font-weight: bold;
  1249. color: #FFFFFF;
  1250. letter-spacing: 2rpx;
  1251. }
  1252. .edit-btn {
  1253. position: absolute;
  1254. right: 30rpx;
  1255. padding: 12rpx 30rpx;
  1256. background: rgba(255, 255, 255, 0.3);
  1257. border-radius: 35rpx;
  1258. min-width: 100rpx;
  1259. display: flex;
  1260. align-items: center;
  1261. justify-content: center;
  1262. .edit-text {
  1263. font-size: 28rpx;
  1264. color: #FFFFFF;
  1265. font-weight: 500;
  1266. }
  1267. }
  1268. }
  1269. /* 头像区域 */
  1270. .avatar-section {
  1271. display: flex;
  1272. flex-direction: column;
  1273. align-items: center;
  1274. padding: 50rpx 0 40rpx;
  1275. .avatar-wrapper {
  1276. position: relative;
  1277. margin-bottom: 25rpx;
  1278. cursor: pointer;
  1279. .avatar {
  1280. width: 180rpx;
  1281. height: 180rpx;
  1282. border-radius: 90rpx;
  1283. border: 6rpx solid #FFFFFF;
  1284. box-shadow: 0 8rpx 30rpx rgba(255, 138, 155, 0.3);
  1285. }
  1286. .avatar-badge {
  1287. position: absolute;
  1288. bottom: 5rpx;
  1289. right: 5rpx;
  1290. width: 50rpx;
  1291. height: 50rpx;
  1292. background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
  1293. border-radius: 25rpx;
  1294. display: flex;
  1295. align-items: center;
  1296. justify-content: center;
  1297. border: 4rpx solid #FFFFFF;
  1298. box-shadow: 0 4rpx 15rpx rgba(255, 215, 0, 0.4);
  1299. .vip-icon {
  1300. font-size: 28rpx;
  1301. }
  1302. }
  1303. .avatar-edit-hint {
  1304. position: absolute;
  1305. bottom: 0;
  1306. left: 0;
  1307. right: 0;
  1308. height: 60rpx;
  1309. background: rgba(0, 0, 0, 0.5);
  1310. border-radius: 0 0 90rpx 90rpx;
  1311. display: flex;
  1312. align-items: center;
  1313. justify-content: center;
  1314. .edit-hint-icon {
  1315. font-size: 32rpx;
  1316. color: #FFFFFF;
  1317. }
  1318. }
  1319. }
  1320. .nickname {
  1321. font-size: 40rpx;
  1322. font-weight: bold;
  1323. color: #333333;
  1324. margin-bottom: 12rpx;
  1325. }
  1326. .user-id {
  1327. font-size: 26rpx;
  1328. color: #999999;
  1329. background: rgba(255, 255, 255, 0.8);
  1330. padding: 8rpx 30rpx;
  1331. border-radius: 30rpx;
  1332. }
  1333. }
  1334. /* 编辑提示 */
  1335. .edit-tip {
  1336. margin: 0 30rpx;
  1337. background: linear-gradient(135deg, #E8F5E8 0%, #D4EDDA 100%);
  1338. border-radius: 15rpx;
  1339. padding: 20rpx 25rpx;
  1340. text-align: center;
  1341. border-left: 6rpx solid #28A745;
  1342. .tip-text {
  1343. font-size: 26rpx;
  1344. color: #28A745;
  1345. font-weight: 500;
  1346. }
  1347. }
  1348. /* 滚动内容区域 */
  1349. .content-scroll {
  1350. flex: 1;
  1351. padding: 20rpx 30rpx 0 30rpx;
  1352. box-sizing: border-box;
  1353. }
  1354. /* 各个section */
  1355. .section {
  1356. background-color: #FFFFFF;
  1357. border-radius: 20rpx;
  1358. padding: 30rpx 25rpx;
  1359. margin-bottom: 25rpx;
  1360. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  1361. width: 100%;
  1362. box-sizing: border-box;
  1363. .section-title {
  1364. font-size: 34rpx;
  1365. font-weight: bold;
  1366. color: #333333;
  1367. margin-bottom: 30rpx;
  1368. padding-bottom: 20rpx;
  1369. padding-left: 30rpx;
  1370. border-bottom: 3rpx solid #F0F0F0;
  1371. display: flex;
  1372. align-items: center;
  1373. position: relative;
  1374. &::before {
  1375. content: '';
  1376. position: absolute;
  1377. left: 5rpx;
  1378. width: 8rpx;
  1379. height: 32rpx;
  1380. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  1381. border-radius: 4rpx;
  1382. }
  1383. }
  1384. .info-item {
  1385. display: flex;
  1386. align-items: center;
  1387. justify-content: space-between;
  1388. padding: 30rpx 0;
  1389. padding-left: 30rpx;
  1390. border-bottom: 1rpx solid #F5F5F5;
  1391. min-height: 80rpx;
  1392. position: relative;
  1393. transition: background-color 0.2s;
  1394. &:active {
  1395. background-color: #F8F8F8;
  1396. }
  1397. &:last-child {
  1398. border-bottom: none;
  1399. }
  1400. &.column {
  1401. flex-direction: column;
  1402. align-items: flex-start;
  1403. }
  1404. .label {
  1405. font-size: 30rpx;
  1406. color: #333333;
  1407. flex-shrink: 0;
  1408. width: 180rpx;
  1409. font-weight: 500;
  1410. }
  1411. .value {
  1412. flex: 1;
  1413. text-align: right;
  1414. font-size: 30rpx;
  1415. color: #666666;
  1416. padding-left: 20rpx;
  1417. }
  1418. .input {
  1419. flex: 1;
  1420. text-align: right;
  1421. font-size: 30rpx;
  1422. color: #333333;
  1423. padding-left: 20rpx;
  1424. }
  1425. .picker-value {
  1426. flex: 1;
  1427. text-align: right;
  1428. font-size: 30rpx;
  1429. color: #666666;
  1430. padding-left: 20rpx;
  1431. }
  1432. .verify-status {
  1433. margin-left: 15rpx;
  1434. font-size: 22rpx;
  1435. flex-shrink: 0;
  1436. &.verified {
  1437. color: #4CAF50;
  1438. }
  1439. &.unverified {
  1440. color: #999999;
  1441. }
  1442. }
  1443. switch {
  1444. flex-shrink: 0;
  1445. }
  1446. }
  1447. }
  1448. /* 爱好标签 */
  1449. .hobby-tags {
  1450. display: flex;
  1451. flex-wrap: wrap;
  1452. gap: 18rpx;
  1453. margin-top: 20rpx;
  1454. width: 100%;
  1455. .hobby-tag {
  1456. padding: 15rpx 30rpx;
  1457. background: linear-gradient(135deg, #FFE5EC 0%, #FFD0DC 100%);
  1458. border-radius: 35rpx;
  1459. font-size: 26rpx;
  1460. color: #FF6B8A;
  1461. font-weight: 500;
  1462. position: relative;
  1463. display: flex;
  1464. align-items: center;
  1465. transition: all 0.3s;
  1466. &.add {
  1467. border: 2rpx dashed #FF8A9B;
  1468. background: transparent;
  1469. color: #FF8A9B;
  1470. justify-content: center;
  1471. }
  1472. &.deletable {
  1473. padding-right: 50rpx;
  1474. &:active {
  1475. background: linear-gradient(135deg, #FFB8C5 0%, #FFA3B3 100%);
  1476. transform: scale(0.95);
  1477. }
  1478. }
  1479. .delete-icon {
  1480. position: absolute;
  1481. right: 15rpx;
  1482. top: 50%;
  1483. transform: translateY(-50%);
  1484. width: 30rpx;
  1485. height: 30rpx;
  1486. background: rgba(255, 255, 255, 0.8);
  1487. border-radius: 50%;
  1488. display: flex;
  1489. align-items: center;
  1490. justify-content: center;
  1491. font-size: 24rpx;
  1492. color: #FF6B8A;
  1493. font-weight: bold;
  1494. }
  1495. }
  1496. .hobby-empty {
  1497. width: 100%;
  1498. text-align: center;
  1499. padding: 40rpx 0;
  1500. .empty-text {
  1501. font-size: 26rpx;
  1502. color: #999999;
  1503. }
  1504. }
  1505. }
  1506. /* 真实度评分 */
  1507. .authenticity-score {
  1508. display: flex;
  1509. flex-direction: column;
  1510. align-items: center;
  1511. padding: 40rpx 0 20rpx;
  1512. .score-circle {
  1513. width: 200rpx;
  1514. height: 200rpx;
  1515. border-radius: 100rpx;
  1516. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  1517. display: flex;
  1518. flex-direction: column;
  1519. align-items: center;
  1520. justify-content: center;
  1521. margin-bottom: 30rpx;
  1522. box-shadow: 0 10rpx 40rpx rgba(255, 107, 138, 0.4);
  1523. position: relative;
  1524. &::before {
  1525. content: '';
  1526. position: absolute;
  1527. width: 220rpx;
  1528. height: 220rpx;
  1529. border-radius: 110rpx;
  1530. border: 2rpx solid rgba(255, 138, 155, 0.3);
  1531. top: -10rpx;
  1532. left: -10rpx;
  1533. }
  1534. .score-number {
  1535. font-size: 68rpx;
  1536. font-weight: bold;
  1537. color: #FFFFFF;
  1538. line-height: 1;
  1539. }
  1540. .score-total {
  1541. font-size: 26rpx;
  1542. color: rgba(255, 255, 255, 0.95);
  1543. margin-top: 5rpx;
  1544. }
  1545. }
  1546. .score-tips {
  1547. background: rgba(255, 138, 155, 0.1);
  1548. padding: 15rpx 30rpx;
  1549. border-radius: 30rpx;
  1550. .tip-text {
  1551. font-size: 24rpx;
  1552. color: #FF6B8A;
  1553. text-align: center;
  1554. }
  1555. }
  1556. }
  1557. .bottom-placeholder {
  1558. height: 80rpx;
  1559. }
  1560. /* 标签选择弹窗 */
  1561. .hobby-modal {
  1562. position: fixed;
  1563. top: 0;
  1564. left: 0;
  1565. right: 0;
  1566. bottom: 0;
  1567. background: rgba(0, 0, 0, 0.6);
  1568. display: flex;
  1569. align-items: center;
  1570. justify-content: center;
  1571. z-index: 9999;
  1572. .modal-content {
  1573. width: 90%;
  1574. max-height: 80vh;
  1575. background: #FFFFFF;
  1576. border-radius: 30rpx;
  1577. overflow: hidden;
  1578. display: flex;
  1579. flex-direction: column;
  1580. }
  1581. .modal-header {
  1582. display: flex;
  1583. align-items: center;
  1584. justify-content: space-between;
  1585. padding: 40rpx 30rpx 20rpx;
  1586. background: linear-gradient(135deg, #FF8A9B 0%, #FFB4C0 100%);
  1587. .modal-title {
  1588. font-size: 32rpx;
  1589. font-weight: bold;
  1590. color: #FFFFFF;
  1591. }
  1592. .close-btn {
  1593. width: 60rpx;
  1594. height: 60rpx;
  1595. display: flex;
  1596. align-items: center;
  1597. justify-content: center;
  1598. font-size: 40rpx;
  1599. color: #FFFFFF;
  1600. background: rgba(255, 255, 255, 0.2);
  1601. border-radius: 30rpx;
  1602. }
  1603. }
  1604. .modal-body {
  1605. flex: 1;
  1606. padding: 30rpx;
  1607. max-height: 60vh;
  1608. }
  1609. .hobby-category {
  1610. margin-bottom: 40rpx;
  1611. &:last-child {
  1612. margin-bottom: 0;
  1613. }
  1614. .category-title {
  1615. display: flex;
  1616. align-items: center;
  1617. margin-bottom: 20rpx;
  1618. .category-icon {
  1619. font-size: 36rpx;
  1620. margin-right: 15rpx;
  1621. }
  1622. .category-name {
  1623. font-size: 28rpx;
  1624. font-weight: bold;
  1625. color: #333333;
  1626. }
  1627. }
  1628. .category-tags {
  1629. display: flex;
  1630. flex-wrap: wrap;
  1631. gap: 15rpx;
  1632. .preset-tag {
  1633. padding: 12rpx 25rpx;
  1634. background: #F5F5F5;
  1635. border-radius: 30rpx;
  1636. font-size: 26rpx;
  1637. color: #666666;
  1638. position: relative;
  1639. transition: all 0.3s;
  1640. &.selected {
  1641. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  1642. color: #FFFFFF;
  1643. padding-right: 45rpx;
  1644. }
  1645. &:active {
  1646. transform: scale(0.95);
  1647. }
  1648. .check-icon {
  1649. position: absolute;
  1650. right: 10rpx;
  1651. top: 50%;
  1652. transform: translateY(-50%);
  1653. font-size: 20rpx;
  1654. font-weight: bold;
  1655. }
  1656. }
  1657. }
  1658. }
  1659. .custom-input-section {
  1660. margin-top: 20rpx;
  1661. padding-top: 30rpx;
  1662. border-top: 1rpx solid #F0F0F0;
  1663. .input-wrapper {
  1664. display: flex;
  1665. align-items: center;
  1666. gap: 20rpx;
  1667. .custom-input {
  1668. flex: 1;
  1669. padding: 20rpx 25rpx;
  1670. background: #F8F8F8;
  1671. border-radius: 25rpx;
  1672. font-size: 26rpx;
  1673. border: 2rpx solid transparent;
  1674. &:focus {
  1675. border-color: #FF8A9B;
  1676. background: #FFFFFF;
  1677. }
  1678. }
  1679. .add-custom-btn {
  1680. padding: 20rpx 30rpx;
  1681. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  1682. border-radius: 25rpx;
  1683. .add-text {
  1684. font-size: 26rpx;
  1685. color: #FFFFFF;
  1686. font-weight: 500;
  1687. }
  1688. }
  1689. }
  1690. }
  1691. .modal-footer {
  1692. display: flex;
  1693. align-items: center;
  1694. justify-content: space-between;
  1695. padding: 30rpx;
  1696. background: #F8F8F8;
  1697. .selected-count {
  1698. font-size: 26rpx;
  1699. color: #666666;
  1700. }
  1701. .done-btn {
  1702. padding: 20rpx 40rpx;
  1703. background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
  1704. border-radius: 30rpx;
  1705. .done-text {
  1706. font-size: 28rpx;
  1707. color: #FFFFFF;
  1708. font-weight: bold;
  1709. }
  1710. }
  1711. }
  1712. }
  1713. </style>