国外MOSE官网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

396 lines
8.9 KiB

3 days ago
3 days ago
3 days ago
3 days ago
3 days ago
3 days ago
3 days ago
3 days ago
3 days ago
3 days ago
3 days ago
3 days ago
  1. <template>
  2. <view class="user-info-container">
  3. <!-- 自定义导航栏 -->
  4. <!-- <view class="custom-navbar">
  5. <view class="navbar-content">
  6. <view class="navbar-title">申请获取您的头像昵称</view>
  7. </view>
  8. </view> -->
  9. <!-- 内容区域 -->
  10. <view class="content">
  11. <!-- 头像区域 -->
  12. <view class="avatar-section">
  13. <view class="app-info">
  14. <image class="app-logo" src="/static/logo.png" mode="aspectFit"></image>
  15. <text class="app-name">木邻有你</text>
  16. </view>
  17. </view>
  18. <!-- 表单区域 -->
  19. <view class="form-section">
  20. <!-- 头像 -->
  21. <!-- 在模板中修改头像区域 -->
  22. <view class="form-item">
  23. <text class="form-label">头像</text>
  24. <view class="avatar-upload">
  25. <button
  26. class="avatar-button"
  27. open-type="chooseAvatar"
  28. @chooseavatar="onChooseAvatar"
  29. >
  30. <image
  31. class="avatar-image"
  32. :src="userInfo.avatar || '/static/待上传头像.png'"
  33. mode="aspectFill"
  34. ></image>
  35. </button>
  36. </view>
  37. </view>
  38. <!-- 昵称 -->
  39. <view class="form-item">
  40. <text class="form-label">昵称</text>
  41. <input
  42. class="form-input"
  43. v-model="userInfo.nickname"
  44. placeholder="请输入昵称"
  45. type="nickname"
  46. @blur="onNicknameBlur"
  47. />
  48. </view>
  49. <!-- 手机号 -->
  50. <view class="form-item">
  51. <text class="form-label">手机号</text>
  52. <view class="phone-input-container">
  53. <input
  54. class="form-input phone-input"
  55. v-model="userInfo.phone"
  56. placeholder="请输入手机号"
  57. type="number"
  58. maxlength="11"
  59. />
  60. <button
  61. class="get-phone-btn"
  62. open-type="getPhoneNumber"
  63. @getphonenumber="getPhoneNumber"
  64. >
  65. <text class="btn-text">获取手机号</text>
  66. </button>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 确定按钮 -->
  71. <view class="submit-section">
  72. <view class="submit-btn" @click="submitUserInfo">
  73. <text class="submit-text">确定</text>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. export default {
  81. name: 'UserInfo',
  82. data() {
  83. return {
  84. userInfo: {
  85. avatar: '',
  86. nickname: '',
  87. phone: ''
  88. }
  89. }
  90. },
  91. onLoad() {
  92. // 获取微信用户信息
  93. this.getWechatUserInfo();
  94. },
  95. methods: {
  96. // 获取微信用户信息
  97. getWechatUserInfo() {
  98. uni.getUserProfile({
  99. desc: '用于完善用户资料',
  100. success: (res) => {
  101. console.log('获取用户信息成功', res);
  102. this.userInfo.nickname = res.userInfo.nickName;
  103. this.userInfo.avatar = res.userInfo.avatarUrl;
  104. },
  105. fail: (err) => {
  106. console.log('获取用户信息失败', err);
  107. }
  108. });
  109. },
  110. // 选择头像
  111. // 修改方法
  112. // 选择头像 - 使用微信原生选择器
  113. onChooseAvatar(e) {
  114. console.log('选择头像回调', e);
  115. if (e.detail.avatarUrl) {
  116. this.userInfo.avatar = e.detail.avatarUrl;
  117. console.log('头像设置成功', e.detail.avatarUrl);
  118. uni.showToast({
  119. title: '头像设置成功',
  120. icon: 'success'
  121. });
  122. } else {
  123. uni.showToast({
  124. title: '头像选择失败',
  125. icon: 'none'
  126. });
  127. }
  128. },
  129. // 删除原来的 chooseAvatar 方法
  130. // chooseAvatar() {
  131. // uni.chooseMedia({
  132. // count: 1,
  133. // mediaType: ['image'],
  134. // sourceType: ['album', 'camera'],
  135. // success: (res) => {
  136. // const tempFilePath = res.tempFiles[0].tempFilePath;
  137. // this.userInfo.avatar = tempFilePath;
  138. // console.log('选择头像成功', tempFilePath);
  139. // },
  140. // fail: (err) => {
  141. // console.log('选择头像失败', err);
  142. // uni.showToast({
  143. // title: '选择头像失败',
  144. // icon: 'none'
  145. // });
  146. // }
  147. // });
  148. // },
  149. // 昵称输入失焦
  150. onNicknameBlur() {
  151. if (!this.userInfo.nickname.trim()) {
  152. uni.showToast({
  153. title: '请输入昵称',
  154. icon: 'none'
  155. });
  156. }
  157. },
  158. // 获取手机号
  159. getPhoneNumber(e) {
  160. console.log('获取手机号回调', e);
  161. if (e.detail.errMsg === 'getPhoneNumber:ok') {
  162. // 获取成功,可以通过e.detail.code发送到后端换取手机号
  163. console.log('获取手机号成功', e.detail);
  164. uni.showToast({
  165. title: '手机号获取成功',
  166. icon: 'success'
  167. });
  168. // 这里需要将e.detail.code发送到后端解密获取真实手机号
  169. // 暂时模拟设置手机号
  170. // this.userInfo.phone = '138****8888';
  171. } else {
  172. console.log('获取手机号失败', e.detail);
  173. uni.showToast({
  174. title: '获取手机号失败',
  175. icon: 'none'
  176. });
  177. }
  178. },
  179. // 提交用户信息
  180. submitUserInfo() {
  181. if (!this.userInfo.nickname.trim()) {
  182. uni.showToast({
  183. title: '请输入昵称',
  184. icon: 'none'
  185. });
  186. return;
  187. }
  188. if (!this.userInfo.phone.trim()) {
  189. uni.showToast({
  190. title: '请输入手机号',
  191. icon: 'none'
  192. });
  193. return;
  194. }
  195. if (!/^1[3-9]\d{9}$/.test(this.userInfo.phone)) {
  196. uni.showToast({
  197. title: '请输入正确的手机号',
  198. icon: 'none'
  199. });
  200. return;
  201. }
  202. console.log('提交用户信息', this.userInfo);
  203. // 这里可以调用API保存用户信息
  204. uni.showToast({
  205. title: '信息保存成功',
  206. icon: 'success'
  207. });
  208. // 跳转到首页或其他页面
  209. setTimeout(() => {
  210. uni.switchTab({
  211. url: '/pages/index/index'
  212. });
  213. }, 1500);
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. .user-info-container {
  220. min-height: 100vh;
  221. background-color: #f5f5f5;
  222. }
  223. .custom-navbar {
  224. position: fixed;
  225. top: 0;
  226. left: 0;
  227. right: 0;
  228. z-index: 1000;
  229. background-color: #1488DB;
  230. .navbar-content {
  231. height: 88rpx;
  232. display: flex;
  233. align-items: center;
  234. justify-content: center;
  235. padding-top: var(--status-bar-height, 44rpx);
  236. .navbar-title {
  237. font-size: 36rpx;
  238. font-weight: 500;
  239. color: #ffffff;
  240. }
  241. }
  242. }
  243. .content {
  244. padding-top: calc(88rpx + var(--status-bar-height, 44rpx));
  245. padding: calc(88rpx + var(--status-bar-height, 44rpx)) 40rpx 40rpx;
  246. }
  247. .avatar-section {
  248. display: flex;
  249. justify-content: center;
  250. margin-bottom: 80rpx;
  251. .app-info {
  252. display: flex;
  253. flex-direction: column;
  254. align-items: center;
  255. .app-logo {
  256. width: 160rpx;
  257. height: 160rpx;
  258. border-radius: 20rpx;
  259. border: 4rpx dashed #cccccc;
  260. margin-bottom: 20rpx;
  261. }
  262. .app-name {
  263. font-size: 32rpx;
  264. font-weight: 500;
  265. color: #333333;
  266. }
  267. }
  268. }
  269. .form-section {
  270. background-color: #ffffff;
  271. border-radius: 20rpx;
  272. padding: 40rpx;
  273. margin-bottom: 60rpx;
  274. }
  275. .form-item {
  276. display: flex;
  277. align-items: center;
  278. margin-bottom: 40rpx;
  279. &:last-child {
  280. margin-bottom: 0;
  281. }
  282. .form-label {
  283. width: 120rpx;
  284. font-size: 32rpx;
  285. color: #333333;
  286. font-weight: 500;
  287. }
  288. .form-input {
  289. flex: 3;
  290. height: 80rpx;
  291. padding: 0 20rpx;
  292. // border: 2rpx solid #e0e0e0;
  293. border-radius: 10rpx;
  294. font-size: 30rpx;
  295. color: #333333;
  296. &.phone-input {
  297. margin-right: 20rpx;
  298. }
  299. }
  300. .avatar-upload {
  301. .avatar-image {
  302. width: 120rpx;
  303. height: 120rpx;
  304. border-radius: 10rpx;
  305. border: 2rpx dashed #cccccc;
  306. }
  307. }
  308. .phone-input-container {
  309. flex: 1;
  310. display: flex;
  311. align-items: center;
  312. .get-phone-btn {
  313. flex: 2;
  314. // padding: 0rpx 0rpx;
  315. background-color: #1488DB;
  316. border-radius: 40rpx;
  317. border: none;
  318. outline: none;
  319. &::after {
  320. border: none;
  321. }
  322. .btn-text {
  323. font-size: 26rpx;
  324. color: #ffffff;
  325. }
  326. }
  327. }
  328. }
  329. .submit-section {
  330. padding: 0 40rpx;
  331. .submit-btn {
  332. width: 100%;
  333. height: 88rpx;
  334. background-color: #1488DB;
  335. border-radius: 44rpx;
  336. display: flex;
  337. align-items: center;
  338. justify-content: center;
  339. .submit-text {
  340. font-size: 32rpx;
  341. font-weight: 500;
  342. color: #ffffff;
  343. }
  344. }
  345. }
  346. // 添加按钮样式
  347. .avatar-button {
  348. padding: 0;
  349. margin: 0;
  350. background: transparent;
  351. border: none;
  352. outline: none;
  353. &::after {
  354. border: none;
  355. }
  356. }
  357. </style>