小说小程序前端代码仓库(小程序)
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.

261 lines
5.5 KiB

  1. <template>
  2. <view class="modify-info-page">
  3. <navbar title="修改信息" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="header">
  5. <button open-type="chooseAvatar"
  6. class="share"
  7. @chooseavatar="onChooseAvatar">
  8. <view class="avatar-upload">
  9. <uv-avatar :src="userInfoForm.headImage" size="88" shape="circle" class="avatar-main" />
  10. <view class="avatar-upload-btn">
  11. <uv-icon name="camera-fill" size="28" color="#fff" />
  12. </view>
  13. </view>
  14. </button>
  15. </view>
  16. <view class="card">
  17. <view class="card-title">个人信息</view>
  18. <view class="form-item">
  19. <view class="form-label"><text class="star">*</text> 昵称</view>
  20. <view class="form-value">
  21. <input type="nickname" placeholder="请输入昵称" id="nickName"
  22. v-model="userInfoForm.nickName" />
  23. </view>
  24. </view>
  25. <view class="divider"></view>
  26. <view class="form-item">
  27. <view class="form-label"><text class="star">*</text> 个性签名</view>
  28. <view class="form-value">
  29. <input placeholder="请输入个性签名" v-model="userInfoForm.details" />
  30. </view>
  31. </view>
  32. <view class="divider"></view>
  33. </view>
  34. <button
  35. class="share"
  36. open-type="getPhoneNumber" @getphonenumber="getPhone">
  37. <view class="card">
  38. <view class="card-title">手机号</view>
  39. <view class="form-item">
  40. <view class="form-label"><text class="star">*</text> 手机号</view>
  41. <view class="form-value">{{ userInfoForm.phone }}</view>
  42. </view>
  43. <view class="divider"></view>
  44. </view>
  45. </button>
  46. <view class="footer">
  47. <uv-button type="primary" text="确认" shape="circle" size="large" @click="submit"
  48. customStyle="width:100%;height:44px;font-size:18px;background:#0a226b;" />
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. components: {},
  55. data() {
  56. return {
  57. avatarUrl: '',
  58. fileList: [],
  59. showUpload: false,
  60. userInfoForm: {
  61. headImage: '',
  62. nickName: '',
  63. phone: '',
  64. },
  65. }
  66. },
  67. onLoad() {
  68. this.userInfoForm.phone = this.userInfo.phone || ''
  69. this.userInfoForm.nickName = this.userInfo.nickName || ''
  70. this.userInfoForm.headImage = this.userInfo.headImage || ''
  71. this.userInfoForm.details = this.userInfo.details || ''
  72. },
  73. methods: {
  74. onChooseAvatar(res) {
  75. this.$Oss.ossUpload(res.target.avatarUrl)
  76. .then(url => {
  77. this.userInfoForm.headImage = url
  78. })
  79. },
  80. getPhone(e) {
  81. this.$api('bindPhone', {
  82. code: e.detail.code
  83. }, res => {
  84. if (res.code == 200) {
  85. let phoneObj = JSON.parse(res.result)
  86. if (phoneObj.errmsg == 'ok') {
  87. this.userInfoForm.phone = phoneObj.phone_info.phoneNumber
  88. } else {
  89. // uni.showModal({
  90. // title: phoneObj.errmsg
  91. // })
  92. }
  93. }
  94. })
  95. },
  96. submit() {
  97. let self = this
  98. uni.createSelectorQuery().in(this)
  99. .select("#nickName")
  100. .fields({
  101. properties: ["value"],
  102. })
  103. .exec((res) => {
  104. const nickName = res?.[0]?.value
  105. self.userInfoForm.nickName = nickName
  106. if (self.$utils.verificationAll(self.userInfoForm, {
  107. headImage: '请选择头像',
  108. nickName: '请填写昵称',
  109. phone: '请填写手机号',
  110. details : '请填写个性签名',
  111. })) {
  112. return
  113. }
  114. self.$api('updateInfo', {
  115. avatarUrl: self.userInfoForm.headImage,
  116. nickName: self.userInfoForm.nickName,
  117. phone: self.userInfoForm.phone,
  118. details: self.userInfoForm.details,
  119. }, res => {
  120. if (res.code == 200) {
  121. // uni.reLaunch({
  122. // url: '/pages/index/index'
  123. // })
  124. this.$store.commit('getUserInfo')
  125. uni.showToast({
  126. title: '修改成功',
  127. icon: 'none',
  128. success() {
  129. uni.navigateBack(-1)
  130. }
  131. })
  132. }
  133. })
  134. })
  135. },
  136. }
  137. }
  138. </script>
  139. <style scoped>
  140. .modify-info-page {
  141. min-height: 100vh;
  142. background: #f8f8f8;
  143. display: flex;
  144. flex-direction: column;
  145. }
  146. .back-arrow-fix {
  147. position: absolute;
  148. top: 60rpx;
  149. left: 32rpx;
  150. z-index: 1000;
  151. }
  152. .header {
  153. display: flex;
  154. flex-direction: column;
  155. align-items: center;
  156. margin-top: 120rpx;
  157. margin-bottom: 24rpx;
  158. position: relative;
  159. }
  160. .avatar-upload {
  161. display: flex;
  162. flex-direction: column;
  163. align-items: center;
  164. position: relative;
  165. width: 120rpx;
  166. height: 120rpx;
  167. }
  168. .avatar-main {
  169. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
  170. }
  171. .avatar-upload-btn {
  172. position: absolute;
  173. bottom: 0;
  174. right: 0;
  175. width: 48rpx;
  176. height: 48rpx;
  177. background: #0a226b;
  178. border-radius: 50%;
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  183. border: 2rpx solid #fff;
  184. }
  185. .card {
  186. background: #fff;
  187. border-radius: 24rpx;
  188. margin: 0 24rpx 32rpx 24rpx;
  189. padding: 32rpx 28rpx 8rpx 28rpx;
  190. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.02);
  191. text-align: left;
  192. }
  193. .card-title {
  194. font-size: 28rpx;
  195. font-weight: bold;
  196. color: #222;
  197. margin-bottom: 18rpx;
  198. margin-top: 18rpx;
  199. }
  200. .form-item {
  201. margin-bottom: 8rpx;
  202. margin-top: 18rpx;
  203. }
  204. .form-label {
  205. font-size: 22rpx;
  206. color: #888;
  207. margin-bottom: 4rpx;
  208. display: flex;
  209. align-items: center;
  210. }
  211. .star {
  212. color: #f44;
  213. font-size: 22rpx;
  214. margin-right: 4rpx;
  215. margin-top: 18rpx;
  216. }
  217. .form-value {
  218. font-size: 26rpx;
  219. color: #222;
  220. font-weight: 500;
  221. margin-bottom: 2rpx;
  222. }
  223. .divider {
  224. height: 1px;
  225. background: #f0f0f0;
  226. margin: 8rpx 0 8rpx 0;
  227. }
  228. .footer {
  229. position: fixed;
  230. left: 0;
  231. right: 0;
  232. bottom: 90rpx;
  233. margin: 0 24rpx;
  234. }
  235. </style>