index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <view class="page-register" :class="themeClass">
  3. <view class="header">
  4. <text class="title">完善个人资料</text>
  5. <text class="subtitle">填写以下信息以开启完整体验</text>
  6. </view>
  7. <view class="form">
  8. <!-- Avatar -->
  9. <view class="form-item avatar-item" @click="chooseAvatar">
  10. <image class="avatar" :src="form.avatarUrl || '/static/default-avatar.png'" mode="aspectFill" />
  11. <text class="avatar-hint">点击更换头像</text>
  12. </view>
  13. <!-- Nickname -->
  14. <view class="form-item">
  15. <text class="label">昵称</text>
  16. <input class="input" v-model="form.nickname" placeholder="输入昵称" maxlength="20" />
  17. </view>
  18. <!-- Gender -->
  19. <view class="form-item">
  20. <text class="label">性别</text>
  21. <view class="radio-group">
  22. <text class="radio" :class="{ active: form.gender === 1 }" @click="form.gender = 1">男</text>
  23. <text class="radio" :class="{ active: form.gender === 2 }" @click="form.gender = 2">女</text>
  24. </view>
  25. </view>
  26. <!-- Birth date -->
  27. <view class="form-item">
  28. <text class="label">出生日期</text>
  29. <picker mode="date" :value="form.birthDate" @change="onBirthDateChange" class="picker">
  30. <text class="picker-text" :class="{ muted: !form.birthDate }">
  31. {{ form.birthDate || '请选择出生日期' }}
  32. </text>
  33. </picker>
  34. </view>
  35. <!-- Bio -->
  36. <view class="form-item">
  37. <text class="label">个人简介</text>
  38. <textarea class="textarea" v-model="form.bio" placeholder="简单介绍一下自己(选填)" maxlength="100" />
  39. <text class="char-counter">{{ form.bio.length }}/100</text>
  40. </view>
  41. <!-- City -->
  42. <view class="form-item">
  43. <text class="label">所在城市</text>
  44. <input class="input" v-model="form.city" placeholder="输入城市(选填)" maxlength="50" />
  45. </view>
  46. <!-- Interest tags -->
  47. <view class="form-item">
  48. <text class="label">兴趣标签</text>
  49. <view class="tag-grid">
  50. <text
  51. v-for="tag in interestOptions"
  52. :key="tag"
  53. class="tag-item"
  54. :class="{ active: selectedTags.includes(tag) }"
  55. @click="toggleTag(tag)"
  56. >{{ tag }}</text>
  57. </view>
  58. </view>
  59. <!-- Looking for -->
  60. <view class="form-item">
  61. <text class="label">想认识</text>
  62. <view class="radio-group">
  63. <text
  64. v-for="opt in lookingOptions"
  65. :key="opt.value"
  66. class="radio"
  67. :class="{ active: form.lookingFor === opt.value }"
  68. @click="form.lookingFor = opt.value"
  69. >{{ opt.label }}</text>
  70. </view>
  71. </view>
  72. <!-- Submit -->
  73. <button class="submit-btn" @click="handleSubmit" :disabled="submitting">
  74. {{ submitting ? '提交中...' : '提交' }}
  75. </button>
  76. </view>
  77. </view>
  78. </template>
  79. <script setup>
  80. import { ref, reactive, computed } from 'vue'
  81. import { useUserStore } from '@/stores/user'
  82. import { profileApi } from '@/utils/api'
  83. import { useTheme } from '@/composables/useThemeStyle'
  84. const { themeClass } = useTheme()
  85. const userStore = useUserStore()
  86. const submitting = ref(false)
  87. const interestOptions = ['读书', '运动', '音乐', '旅行', '禅修', '创业', '心理学', '玄学']
  88. const lookingOptions = [
  89. { value: 0, label: '不限' },
  90. { value: 1, label: '朋友' },
  91. { value: 2, label: '导师' },
  92. { value: 3, label: '同修' }
  93. ]
  94. const form = reactive({
  95. avatarUrl: userStore.avatarUrl || '',
  96. nickname: userStore.nickname || '',
  97. gender: 0,
  98. birthDate: '',
  99. bio: '',
  100. city: '',
  101. tags: '',
  102. lookingFor: 0
  103. })
  104. const selectedTags = ref([])
  105. function toggleTag(tag) {
  106. const idx = selectedTags.value.indexOf(tag)
  107. if (idx >= 0) {
  108. selectedTags.value.splice(idx, 1)
  109. } else {
  110. selectedTags.value.push(tag)
  111. }
  112. form.tags = selectedTags.value.join(',')
  113. }
  114. function onBirthDateChange(e) {
  115. form.birthDate = e.detail.value
  116. }
  117. function chooseAvatar() {
  118. uni.chooseImage({
  119. count: 1,
  120. success: (res) => {
  121. const tempPath = res.tempFilePaths[0]
  122. // For now just use the temp path; real upload to server would happen via uni.uploadFile
  123. form.avatarUrl = tempPath
  124. // In production, upload to server and set form.avatarUrl to returned URL
  125. uploadAvatar(tempPath)
  126. }
  127. })
  128. }
  129. async function uploadAvatar(tempPath) {
  130. // Upload avatar to server (simplified - just uses temp path for now)
  131. // In production: uni.uploadFile to /api/upload/avatar
  132. uni.showToast({ title: '头像已选择', icon: 'success' })
  133. }
  134. async function handleSubmit() {
  135. if (!form.nickname.trim()) {
  136. uni.showToast({ title: '请输入昵称', icon: 'none' })
  137. return
  138. }
  139. if (form.gender === 0) {
  140. uni.showToast({ title: '请选择性别', icon: 'none' })
  141. return
  142. }
  143. if (!form.birthDate) {
  144. uni.showToast({ title: '请选择出生日期', icon: 'none' })
  145. return
  146. }
  147. submitting.value = true
  148. try {
  149. await profileApi.complete({
  150. nickname: form.nickname.trim(),
  151. avatarUrl: form.avatarUrl,
  152. gender: form.gender,
  153. birthDate: form.birthDate,
  154. bio: form.bio.trim(),
  155. city: form.city.trim(),
  156. tags: form.tags,
  157. lookingFor: form.lookingFor
  158. })
  159. // Refresh profile in store
  160. await userStore.fetchProfile()
  161. userStore.profileIncomplete = false
  162. uni.showToast({ title: '资料已完善', icon: 'success' })
  163. setTimeout(() => {
  164. uni.switchTab({ url: '/pages/index/index' })
  165. }, 500)
  166. } catch (e) {
  167. uni.showToast({ title: e.message || '提交失败', icon: 'none' })
  168. } finally {
  169. submitting.value = false
  170. }
  171. }
  172. </script>
  173. <style scoped lang="scss">
  174. .page-register {
  175. min-height: 100vh;
  176. background: linear-gradient(180deg, #F8F9FF 0%, #EEF2FF 100%);
  177. padding: 20px 24px 40px;
  178. }
  179. .header {
  180. text-align: center;
  181. padding: 24px 0 32px;
  182. }
  183. .title {
  184. font-size: 22px;
  185. font-weight: 700;
  186. color: #1F2937;
  187. display: block;
  188. }
  189. .subtitle {
  190. font-size: 14px;
  191. color: #9CA3AF;
  192. display: block;
  193. margin-top: 6px;
  194. }
  195. .form {
  196. background: #fff;
  197. border-radius: 16px;
  198. padding: 24px 20px;
  199. box-shadow: 0 2px 12px rgba(0,0,0,0.04);
  200. }
  201. .form-item {
  202. margin-bottom: 20px;
  203. }
  204. .label {
  205. font-size: 14px;
  206. font-weight: 600;
  207. color: #374151;
  208. display: block;
  209. margin-bottom: 8px;
  210. }
  211. .input {
  212. width: 100%;
  213. height: 44px;
  214. border: 1px solid #E5E7EB;
  215. border-radius: 10px;
  216. padding: 0 14px;
  217. font-size: 15px;
  218. color: #1F2937;
  219. background: #F9FAFB;
  220. box-sizing: border-box;
  221. }
  222. .textarea {
  223. width: 100%;
  224. height: 88px;
  225. border: 1px solid #E5E7EB;
  226. border-radius: 10px;
  227. padding: 10px 14px;
  228. font-size: 15px;
  229. color: #1F2937;
  230. background: #F9FAFB;
  231. box-sizing: border-box;
  232. resize: none;
  233. }
  234. .char-counter {
  235. display: block;
  236. text-align: right;
  237. font-size: 12px;
  238. color: #9CA3AF;
  239. margin-top: 4px;
  240. }
  241. /* Avatar */
  242. .avatar-item {
  243. display: flex;
  244. flex-direction: column;
  245. align-items: center;
  246. margin-bottom: 28px;
  247. }
  248. .avatar {
  249. width: 80px;
  250. height: 80px;
  251. border-radius: 50%;
  252. border: 3px solid #E5E7EB;
  253. }
  254. .avatar-hint {
  255. font-size: 12px;
  256. color: #9CA3AF;
  257. margin-top: 6px;
  258. }
  259. /* Radio group */
  260. .radio-group {
  261. display: flex;
  262. gap: 12px;
  263. }
  264. .radio {
  265. flex: 1;
  266. height: 44px;
  267. border: 1px solid #E5E7EB;
  268. border-radius: 10px;
  269. display: flex;
  270. align-items: center;
  271. justify-content: center;
  272. font-size: 15px;
  273. color: #6B7280;
  274. background: #F9FAFB;
  275. }
  276. .radio.active {
  277. border-color: #4A148C;
  278. color: #4A148C;
  279. background: #F3EEFF;
  280. }
  281. /* Picker */
  282. .picker {
  283. width: 100%;
  284. }
  285. .picker-text {
  286. display: block;
  287. width: 100%;
  288. height: 44px;
  289. line-height: 44px;
  290. border: 1px solid #E5E7EB;
  291. border-radius: 10px;
  292. padding: 0 14px;
  293. font-size: 15px;
  294. color: #1F2937;
  295. background: #F9FAFB;
  296. box-sizing: border-box;
  297. }
  298. .picker-text.muted {
  299. color: #9CA3AF;
  300. }
  301. /* Tags */
  302. .tag-grid {
  303. display: flex;
  304. flex-wrap: wrap;
  305. gap: 8px;
  306. }
  307. .tag-item {
  308. padding: 6px 16px;
  309. border-radius: 20px;
  310. font-size: 13px;
  311. color: #6B7280;
  312. background: var(--color-bg-input);
  313. border: 1px solid transparent;
  314. }
  315. .tag-item.active {
  316. color: #4A148C;
  317. background: #F3EEFF;
  318. border-color: #4A148C;
  319. }
  320. /* Submit */
  321. .submit-btn {
  322. width: 100%;
  323. height: 48px;
  324. background: linear-gradient(135deg, #4A148C, #7B2DC8);
  325. color: #fff;
  326. border: none;
  327. border-radius: 12px;
  328. font-size: 17px;
  329. font-weight: 600;
  330. margin-top: 8px;
  331. }
  332. .submit-btn[disabled] {
  333. opacity: 0.5;
  334. }
  335. </style>