user.uvue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <script setup lang='ts'>
  2. import { user } from '@/.cool'
  3. import { computed, ref, type Ref, onMounted, nextTick } from 'vue'
  4. import { config } from '@/config'
  5. import { updateUserInfo } from '@/services/user'
  6. const userInfo = computed(() => user.info.value?.userInfo)
  7. type FormData = {
  8. username: string;
  9. nickName: string;
  10. phone: string;
  11. realName: string;
  12. birthDay: string;
  13. score: number;
  14. userId: string;
  15. avatar: string;
  16. };
  17. const formData = ref<FormData>({
  18. username: "",
  19. nickName: "",
  20. phone: "",
  21. realName: "",
  22. birthDay: "",
  23. score: 0,
  24. userId: "",
  25. avatar: ""
  26. })
  27. onMounted(() => {
  28. console.log(userInfo.value)
  29. nextTick(() => {
  30. formData.value.username = userInfo.value.username
  31. formData.value.nickName = userInfo.value.nickName
  32. formData.value.phone = userInfo.value.phone
  33. formData.value.realName = userInfo.value.realName
  34. formData.value.birthDay = userInfo.value.birthDay
  35. formData.value.score = userInfo.value.score
  36. formData.value.userId = userInfo.value.userId
  37. formData.value.avatar = userInfo.value.avatar
  38. avatar.value = userInfo.value.avatar ? config.baseUrl + userInfo.value.avatar : ''
  39. })
  40. })
  41. async function handleSubmit() {
  42. console.log(formData.value)
  43. await updateUserInfo(formData.value)
  44. await user.get()
  45. uni.showToast({
  46. title: '更新成功',
  47. icon: 'success',
  48. duration: 2000
  49. })
  50. }
  51. function handleSuccess(res: any) {
  52. formData.value.avatar = res.url
  53. avatar.value = config.baseUrl + res.url
  54. }
  55. const avatar = ref('')
  56. </script>
  57. <template>
  58. <view class="w-full h-full py-[20px] pb-[30px] ">
  59. <cl-row :gutter="20" class="w-full h-full">
  60. <cl-col :span="8">
  61. <view class="w-full h-full bg-[#00A9FF] rounded-3xl flex justify-end items-center shadow">
  62. <view class="w-[88px] h-[88px] border border-[#fff] border-solid border-[4px] rounded-full z-[1]">
  63. <cl-avatar :size="80"
  64. :src="userInfo.avatar ? config.baseUrl + userInfo.avatar : 'https://oss.xiaoxiongcode.com/static/个人中心/图层 506.png'"
  65. rounded></cl-avatar>
  66. </view>
  67. <view
  68. class="bg-[#FDF6E9] hh rounded-3xl p-[10px] w-full mt-[-30px] pt-[30px] px-[20px] text-black flex flex-col justify-between ">
  69. <view>
  70. <view class="py-1 text-[14px]">
  71. 用户账号:{{ userInfo.username }}
  72. </view>
  73. <view class="py-1 text-[14px]">
  74. 昵称:{{ userInfo.nickName }}
  75. </view>
  76. <view class="py-1 text-[14px]">
  77. 积分 :{{ userInfo.score }}
  78. </view>
  79. </view>
  80. <view class="btn my-1 h-[40px] rounded-full mx-auto flex justify-center items-center text-white"
  81. @click="handleSubmit">
  82. 保存
  83. </view>
  84. </view>
  85. </view>
  86. </cl-col>
  87. <cl-col :span="16">
  88. <view class="w-full h-full bg-[#fff] shadow rounded-xl px-[10px] py-[10px] text-[#00A9FF] ">
  89. <scroll-view direction="vertical" :show-scrollbar="false" class="sidebar">
  90. <cl-form v-model="formData" labelPosition="left">
  91. <cl-form-item :pt="{ className: '!mb-4' }" label="头像" prop="avatar">
  92. <cl-upload v-model="avatar" @success="handleSuccess"></cl-upload>
  93. </cl-form-item>
  94. <cl-form-item :pt="{ className: '!mb-4' }" label="昵称" prop="nickName">
  95. <cl-input v-model="formData.nickName" placeholder="请输入昵称"></cl-input>
  96. </cl-form-item>
  97. <cl-form-item :pt="{ className: '!mb-4' }" label="手机号" prop="phone">
  98. <cl-input v-model="formData.phone" placeholder="请输入手机号"></cl-input>
  99. </cl-form-item>
  100. <cl-form-item :pt="{ className: '!mb-4' }" label="姓名" prop="realName">
  101. <cl-input v-model="formData.realName" placeholder="请输入姓名"></cl-input>
  102. </cl-form-item>
  103. <cl-form-item :pt="{ className: '!mb-4' }" label="生日" prop="birthDay">
  104. <cl-select-date v-model="formData.birthDay" type="date" label-format="YYYY年MM月DD日"
  105. value-format="YYYY-MM-DD" title="选择日期"></cl-select-date>
  106. </cl-form-item>
  107. </cl-form>
  108. </scroll-view>
  109. </view>
  110. </cl-col>
  111. </cl-row>
  112. </view>
  113. </template>
  114. <style lang="scss" scoped>
  115. .shadow {
  116. box-shadow: 3px 6px 10px 0px rgba(0, 128, 216, 0.86);
  117. }
  118. .sidebar {
  119. height: calc(80vh - 120px);
  120. max-height: calc(620px - 120px);
  121. }
  122. .hh {
  123. height: calc(100% - 80px);
  124. }
  125. .btn {
  126. width: 80%;
  127. background: linear-gradient(0deg, #34BAFF 0%, #B9EBFE 100%);
  128. }
  129. </style>