mine-edit.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <view class="page mine-edit">
  3. <nav-bar back>修改我的信息</nav-bar>
  4. <uni-card :is-shadow="false" is-full :border="false">
  5. <uni-forms ref="form" :modelValue="userInfo" label-position="top" label-width="100%">
  6. <uni-forms-item name="headImage" class="avatar">
  7. <image-upload :onSuccess="onUnloadImageSuccess">
  8. <image :src="userInfo.headImageThumb" class="head-image"></image>
  9. </image-upload>
  10. </uni-forms-item>
  11. <uni-forms-item label="用户名" name="userName">
  12. <uni-easyinput type="text" v-model="userInfo.userName" :disabled="true" />
  13. </uni-forms-item>
  14. <uni-forms-item label="昵称" name="nickName">
  15. <uni-easyinput v-model="userInfo.nickName" type="text" :placeholder="userInfo.userName" />
  16. </uni-forms-item>
  17. <uni-forms-item label="性别" name="sex">
  18. <uni-data-checkbox v-model="userInfo.sex"
  19. :localdata="[{ text: '男', value: 0 }, { text: '女', value: 1 }]"></uni-data-checkbox>
  20. </uni-forms-item>
  21. <uni-forms-item label="签名" name="signature">
  22. <uni-easyinput type="textarea" v-model="userInfo.signature" placeholder="编辑个性标签,展示我的独特态度" />
  23. </uni-forms-item>
  24. </uni-forms>
  25. </uni-card>
  26. <button type="primary" class="bottom-btn" @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.userStore.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.userStore.userInfo;
  64. this.userInfo = JSON.parse(JSON.stringify(mine));
  65. }
  66. }
  67. </script>
  68. <style scoped lang="scss">
  69. .mine-edit {
  70. .head-image {
  71. width: 200rpx;
  72. height: 200rpx;
  73. }
  74. }
  75. .avatar {
  76. margin-top: -30px;
  77. }
  78. </style>