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

256 lines
5.3 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.signature" />
  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. },
  72. methods: {
  73. onChooseAvatar(res) {
  74. this.$Oss.ossUpload(res.target.avatarUrl)
  75. .then(url => {
  76. this.userInfoForm.headImage = url
  77. })
  78. },
  79. getPhone(e) {
  80. this.$api('bindPhone', {
  81. code: e.detail.code
  82. }, res => {
  83. if (res.code == 200) {
  84. let phoneObj = JSON.parse(res.result)
  85. if (phoneObj.errmsg == 'ok') {
  86. this.userInfoForm.phone = phoneObj.phone_info.phoneNumber
  87. } else {
  88. // uni.showModal({
  89. // title: phoneObj.errmsg
  90. // })
  91. }
  92. }
  93. })
  94. },
  95. submit() {
  96. let self = this
  97. uni.createSelectorQuery().in(this)
  98. .select("#nickName")
  99. .fields({
  100. properties: ["value"],
  101. })
  102. .exec((res) => {
  103. const nickName = res?.[0]?.value
  104. self.userInfoForm.nickName = nickName
  105. if (self.$utils.verificationAll(self.userInfoForm, {
  106. headImage: '请选择头像',
  107. nickName: '请填写昵称',
  108. phone: '请填写手机号',
  109. })) {
  110. return
  111. }
  112. self.$api('updateInfo', {
  113. avatarUrl: self.userInfoForm.headImage,
  114. nickName: self.userInfoForm.nickName,
  115. phone: self.userInfoForm.phone,
  116. }, res => {
  117. if (res.code == 200) {
  118. // uni.reLaunch({
  119. // url: '/pages/index/index'
  120. // })
  121. uni.showToast({
  122. title: '修改成功',
  123. icon: 'none',
  124. success() {
  125. uni.navigateBack(-1)
  126. }
  127. })
  128. }
  129. })
  130. })
  131. },
  132. }
  133. }
  134. </script>
  135. <style scoped>
  136. .modify-info-page {
  137. min-height: 100vh;
  138. background: #f8f8f8;
  139. display: flex;
  140. flex-direction: column;
  141. }
  142. .back-arrow-fix {
  143. position: absolute;
  144. top: 60rpx;
  145. left: 32rpx;
  146. z-index: 1000;
  147. }
  148. .header {
  149. display: flex;
  150. flex-direction: column;
  151. align-items: center;
  152. margin-top: 120rpx;
  153. margin-bottom: 24rpx;
  154. position: relative;
  155. }
  156. .avatar-upload {
  157. display: flex;
  158. flex-direction: column;
  159. align-items: center;
  160. position: relative;
  161. width: 120rpx;
  162. height: 120rpx;
  163. }
  164. .avatar-main {
  165. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
  166. }
  167. .avatar-upload-btn {
  168. position: absolute;
  169. bottom: 0;
  170. right: 0;
  171. width: 48rpx;
  172. height: 48rpx;
  173. background: #0a226b;
  174. border-radius: 50%;
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  179. border: 2rpx solid #fff;
  180. }
  181. .card {
  182. background: #fff;
  183. border-radius: 24rpx;
  184. margin: 0 24rpx 32rpx 24rpx;
  185. padding: 32rpx 28rpx 8rpx 28rpx;
  186. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.02);
  187. text-align: left;
  188. }
  189. .card-title {
  190. font-size: 28rpx;
  191. font-weight: bold;
  192. color: #222;
  193. margin-bottom: 18rpx;
  194. margin-top: 18rpx;
  195. }
  196. .form-item {
  197. margin-bottom: 8rpx;
  198. margin-top: 18rpx;
  199. }
  200. .form-label {
  201. font-size: 22rpx;
  202. color: #888;
  203. margin-bottom: 4rpx;
  204. display: flex;
  205. align-items: center;
  206. }
  207. .star {
  208. color: #f44;
  209. font-size: 22rpx;
  210. margin-right: 4rpx;
  211. margin-top: 18rpx;
  212. }
  213. .form-value {
  214. font-size: 26rpx;
  215. color: #222;
  216. font-weight: 500;
  217. margin-bottom: 2rpx;
  218. }
  219. .divider {
  220. height: 1px;
  221. background: #f0f0f0;
  222. margin: 8rpx 0 8rpx 0;
  223. }
  224. .footer {
  225. position: fixed;
  226. left: 0;
  227. right: 0;
  228. bottom: 90rpx;
  229. margin: 0 24rpx;
  230. }
  231. </style>