mine-edit.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view class="page mine-edit">
  3. <uni-forms ref="form" :modelValue="userInfo" label-position="top"
  4. label-width="100%">
  5. <uni-forms-item label="头像:" name="headImage">
  6. <image-upload :onSuccess="onUnloadImageSuccess">
  7. <image :src="userInfo.headImageThumb" class="head-image"></image>
  8. </image-upload>
  9. </uni-forms-item>
  10. <uni-forms-item label="用户名:" name="userName">
  11. <uni-easyinput type="text" v-model="userInfo.userName" :disabled="true" />
  12. </uni-forms-item>
  13. <uni-forms-item label="昵称:" name="nickName">
  14. <uni-easyinput v-model="userInfo.nickName" type="text" :placeholder="userInfo.userName" />
  15. </uni-forms-item>
  16. <uni-forms-item label="性别:" name="sex">
  17. <radio-group @change="onSexchange">
  18. <label class="radio"><radio value="0" :checked="userInfo.sex==0" />男</label>
  19. <label class="radio"><radio value="1" :checked="userInfo.sex==1" />女 </label>
  20. </radio-group>
  21. </uni-forms-item>
  22. <uni-forms-item label="签名:" name="signature">
  23. <uni-easyinput type="textarea" v-model="userInfo.signature" placeholder="编辑个性标签,展示我的独特态度" />
  24. </uni-forms-item>
  25. </uni-forms>
  26. <button type="primary" @click="onSubmit()">提交</button>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. userInfo: {}
  34. }
  35. },
  36. methods:{
  37. onSexchange(e){
  38. this.userInfo.sex=e.detail.value;
  39. },
  40. onUnloadImageSuccess(file, res) {
  41. this.userInfo.headImage = res.data.originUrl;
  42. this.userInfo.headImageThumb = res.data.thumbUrl;
  43. },
  44. onSubmit(){
  45. this.$http({
  46. url: "/user/update",
  47. method: "PUT",
  48. data: this.userInfo
  49. }).then(()=>{
  50. this.$store.commit("setUserInfo",this.userInfo);
  51. uni.showToast({
  52. title:"修改成功",
  53. icon: 'none'
  54. });
  55. setTimeout(()=>{
  56. uni.navigateBack();
  57. },1000);
  58. })
  59. }
  60. },
  61. onLoad() {
  62. // 深拷贝一份数据
  63. let mine = this.$store.state.userStore.userInfo;
  64. this.userInfo = JSON.parse(JSON.stringify(mine));
  65. }
  66. }
  67. </script>
  68. <style scoped lang="scss">
  69. .mine-edit {
  70. padding: 20rpx;
  71. .head-image {
  72. width: 200rpx;
  73. height: 200rpx;
  74. }
  75. }
  76. </style>