敢为人鲜小程序前端代码仓库
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.

281 lines
5.2 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. <template>
  2. <view class="profile-page">
  3. <!-- 头部导航栏 -->
  4. <navbar title="资料修改" bgColor="#019245" color="#fff" leftClick @leftClick="$utils.navigateBack" />
  5. <!-- 基本资料区域 -->
  6. <view class="main-content">
  7. <view class="section-title">
  8. <view class="title-indicator"></view>
  9. <text>基本资料</text>
  10. </view>
  11. <!-- 头像选择区域 -->
  12. <view class="avatar-section">
  13. <button class="chooseAvatar" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  14. <image class="avatar-img" :src="form.headImage" mode="aspectFill"></image>
  15. </button>
  16. <text class="avatar-hint">点击更换头像</text>
  17. </view>
  18. <!-- 表单区域 -->
  19. <view class="form-section">
  20. <view class="form-item">
  21. <text class="label">昵称</text>
  22. <input class="input" type="nickname" placeholder="请输入" v-model="form.nickName" id="nickName"
  23. placeholderStyle="color: #999; text-align: right;" />
  24. </view>
  25. <view class="form-item">
  26. <text class="label">手机号</text>
  27. <input class="input" type="tel" placeholder="请输入" v-model="form.phone"
  28. placeholderStyle="color: #999; text-align: right;" />
  29. </view>
  30. </view>
  31. <!-- 保存按钮 -->
  32. <view class="save-button" @tap="submit">
  33. <text>保存</text>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { mapState } from 'vuex'
  40. import { mockUserInfo } from '@/static/js/mockUserInfo.js'
  41. import navbar from '@/components/base/navbar.vue'
  42. export default {
  43. components: {
  44. navbar
  45. },
  46. data() {
  47. return {
  48. form: {
  49. headImage: '',
  50. nickName: '',
  51. phone: ''
  52. },
  53. back: '',
  54. }
  55. },
  56. computed: {
  57. ...mapState(['userInfo']),
  58. },
  59. onLoad({ back }) {
  60. this.back = back
  61. },
  62. onShow() {
  63. this.getUserInfo()
  64. },
  65. methods: {
  66. onChooseAvatar(res) {
  67. let self = this
  68. self.$Oss.ossUpload(res.detail.avatarUrl)
  69. .then(url => {
  70. self.form.headImage = url
  71. })
  72. },
  73. getUserInfo() {
  74. // 使用mock数据
  75. this.form.headImage = mockUserInfo.avatarUrl || this.form.headImage
  76. this.form.nickName = mockUserInfo.nickName || this.form.nickName
  77. this.form.phone = '13800138000' // 模拟手机号
  78. },
  79. submit() {
  80. let self = this
  81. // 之所以手动获取dom的input值 而不是v-model 是为了保证跨平台安全生效
  82. uni.createSelectorQuery().in(this)
  83. .select("#nickName")
  84. .fields({
  85. properties: ["value"],
  86. })
  87. .exec((res) => {
  88. const nickName = res?.[0]?.value
  89. self.form.nickName = nickName
  90. if (self.$utils.verificationAll(self.form, {
  91. headImage: '请选择头像',
  92. nickName: '请填写昵称',
  93. phone: '请填写手机号'
  94. })) {
  95. return
  96. }
  97. if (!self.$utils.verificationPhone(self.form.phone)) {
  98. uni.showToast({
  99. icon: 'none',
  100. title: '请填写正确的手机号'
  101. })
  102. return
  103. }
  104. uni.showLoading({
  105. title: '保存中...'
  106. })
  107. setTimeout(() => {
  108. uni.hideLoading()
  109. uni.showToast({
  110. title: '保存成功',
  111. icon: 'success'
  112. })
  113. // 返回上一页
  114. setTimeout(() => {
  115. this.$utils.navigateBack()
  116. }, 1500)
  117. }, 1000)
  118. })
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .profile-page {
  125. min-height: 100vh;
  126. background-color: #f5f5f5;
  127. }
  128. .nav-bar {
  129. height: 180rpx;
  130. background-color: #019245;
  131. display: flex;
  132. align-items: center;
  133. justify-content: space-between;
  134. padding: 0 30rpx;
  135. padding-top: 60rpx;
  136. box-sizing: border-box;
  137. color: #fff;
  138. .back-btn {
  139. width: 60rpx;
  140. height: 60rpx;
  141. display: flex;
  142. align-items: center;
  143. }
  144. .nav-title {
  145. font-size: 36rpx;
  146. font-weight: 500;
  147. }
  148. .right-actions {
  149. display: flex;
  150. align-items: center;
  151. .icon-divider {
  152. width: 2rpx;
  153. height: 30rpx;
  154. background-color: rgba(255, 255, 255, 0.5);
  155. margin: 0 20rpx;
  156. }
  157. }
  158. }
  159. .main-content {
  160. padding: 30rpx;
  161. }
  162. .section-title {
  163. display: flex;
  164. align-items: center;
  165. margin-bottom: 30rpx;
  166. .title-indicator {
  167. width: 8rpx;
  168. height: 32rpx;
  169. background-color: $uni-color;
  170. margin-right: 15rpx;
  171. border-radius: 4rpx;
  172. }
  173. text {
  174. font-size: 32rpx;
  175. font-weight: 500;
  176. color: #333;
  177. }
  178. }
  179. .avatar-section {
  180. display: flex;
  181. flex-direction: column;
  182. align-items: center;
  183. margin: 50rpx 0;
  184. .chooseAvatar {
  185. width: 180rpx;
  186. height: 180rpx;
  187. border-radius: 50%;
  188. overflow: hidden;
  189. padding: 0;
  190. margin: 0;
  191. background: none;
  192. &::after {
  193. border: none;
  194. }
  195. .avatar-img {
  196. width: 100%;
  197. height: 100%;
  198. border-radius: 50%;
  199. }
  200. }
  201. .avatar-hint {
  202. font-size: 26rpx;
  203. color: $uni-color-third;
  204. margin-top: 20rpx;
  205. }
  206. }
  207. .form-section {
  208. background-color: #fff;
  209. border-radius: 30rpx;
  210. overflow: hidden;
  211. margin-bottom: 60rpx;
  212. .form-item {
  213. display: flex;
  214. height: 100rpx;
  215. align-items: center;
  216. padding: 0 30rpx;
  217. border-bottom: 1rpx solid #f5f5f5;
  218. &:last-child {
  219. border-bottom: none;
  220. }
  221. .label {
  222. width: 150rpx;
  223. font-size: 30rpx;
  224. color: $uni-color-third;
  225. }
  226. .input {
  227. flex: 1;
  228. height: 100%;
  229. font-size: 30rpx;
  230. color: #666;
  231. }
  232. }
  233. }
  234. .save-button {
  235. width: 90%;
  236. margin: 160rpx auto 0;
  237. height: 100rpx;
  238. background-color: $uni-color;
  239. border-radius: 45rpx;
  240. display: flex;
  241. align-items: center;
  242. justify-content: center;
  243. color: #fff;
  244. font-size: 32rpx;
  245. box-shadow: 0 6rpx 20rpx rgba(1, 146, 69, 0.3);
  246. }
  247. </style>