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

311 lines
6.8 KiB

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