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

322 lines
7.1 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. // #ifdef H5
  162. // H5端需要验证手机号格式
  163. if (!self.$utils.verificationPhone(self.userInfoForm.phone)) {
  164. uni.showToast({
  165. title: '请输入正确的手机号格式',
  166. icon: 'none'
  167. })
  168. return
  169. }
  170. // #endif
  171. self.$api('updateInfo', {
  172. avatarUrl: self.userInfoForm.headImage,
  173. nickName: self.userInfoForm.nickName,
  174. phone: self.userInfoForm.phone,
  175. details: self.userInfoForm.details,
  176. }, res => {
  177. if (res.code == 200) {
  178. // uni.reLaunch({
  179. // url: '/pages/index/index'
  180. // })
  181. this.$store.commit('getUserInfo')
  182. uni.showToast({
  183. title: '修改成功',
  184. icon: 'none',
  185. success() {
  186. uni.navigateBack(-1)
  187. }
  188. })
  189. }
  190. })
  191. })
  192. },
  193. }
  194. }
  195. </script>
  196. <style scoped>
  197. .modify-info-page {
  198. min-height: 100vh;
  199. background: #f8f8f8;
  200. display: flex;
  201. flex-direction: column;
  202. }
  203. .back-arrow-fix {
  204. position: absolute;
  205. top: 60rpx;
  206. left: 32rpx;
  207. z-index: 1000;
  208. }
  209. .header {
  210. display: flex;
  211. flex-direction: column;
  212. align-items: center;
  213. margin-top: 120rpx;
  214. margin-bottom: 24rpx;
  215. position: relative;
  216. }
  217. .avatar-upload {
  218. display: flex;
  219. flex-direction: column;
  220. align-items: center;
  221. position: relative;
  222. width: 120rpx;
  223. height: 120rpx;
  224. }
  225. .avatar-main {
  226. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
  227. }
  228. .avatar-upload-btn {
  229. position: absolute;
  230. bottom: 0;
  231. right: 0;
  232. width: 48rpx;
  233. height: 48rpx;
  234. background: #0a226b;
  235. border-radius: 50%;
  236. display: flex;
  237. align-items: center;
  238. justify-content: center;
  239. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  240. border: 2rpx solid #fff;
  241. }
  242. .card {
  243. background: #fff;
  244. border-radius: 24rpx;
  245. margin: 0 24rpx 32rpx 24rpx;
  246. padding: 32rpx 28rpx 8rpx 28rpx;
  247. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.02);
  248. text-align: left;
  249. }
  250. .card-title {
  251. font-size: 28rpx;
  252. font-weight: bold;
  253. color: #222;
  254. margin-bottom: 18rpx;
  255. margin-top: 18rpx;
  256. }
  257. .form-item {
  258. margin-bottom: 8rpx;
  259. margin-top: 18rpx;
  260. }
  261. .form-label {
  262. font-size: 22rpx;
  263. color: #888;
  264. margin-bottom: 4rpx;
  265. display: flex;
  266. align-items: center;
  267. }
  268. .star {
  269. color: #f44;
  270. font-size: 22rpx;
  271. margin-right: 4rpx;
  272. margin-top: 18rpx;
  273. }
  274. .form-value {
  275. font-size: 26rpx;
  276. color: #222;
  277. font-weight: 500;
  278. margin-bottom: 2rpx;
  279. }
  280. .divider {
  281. height: 1px;
  282. background: #f0f0f0;
  283. margin: 8rpx 0 8rpx 0;
  284. }
  285. .footer {
  286. position: fixed;
  287. left: 0;
  288. right: 0;
  289. bottom: 90rpx;
  290. margin: 0 24rpx;
  291. }
  292. </style>