userInfo.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <fs-form ref="formRef" :model="userInfo">
  3. <view class="text-center">
  4. <button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="handleUpload">
  5. <fs-avatar size="140rpx" bgColor="#EBEFF5" :src="userInfo.photo">
  6. <fs-icon type="icon-photo" size="50rpx"></fs-icon>
  7. </fs-avatar>
  8. </button>
  9. </view>
  10. <fs-form-item required label="姓名">
  11. <fs-field placeholder="请输入姓名" v-model="userInfo.name"></fs-field>
  12. </fs-form-item>
  13. <fs-form-item required label="手机号">
  14. <fs-field placeholder="请输入手机号" v-model="userInfo.mobile"></fs-field>
  15. </fs-form-item>
  16. <fs-form-item label="性别">
  17. <fs-radio-group inline v-model="userInfo.sex">
  18. <fs-radio value="1">男</fs-radio>
  19. <fs-radio value="2">女</fs-radio>
  20. </fs-radio-group>
  21. </fs-form-item>
  22. <fs-gutter height="100rpx"></fs-gutter>
  23. <fs-button block round @click="handleSave">保存</fs-button>
  24. </fs-form>
  25. </template>
  26. <script setup>
  27. import useForm from '@/hooks/useForm'
  28. import useValidator from '@/hooks/useValidator'
  29. import { useUserStore } from '@/stores/user'
  30. import utils from '@/utils/utils'
  31. const user = useUserStore()
  32. const userInfo = computed(() => user.userInfo)
  33. const validator = useValidator()
  34. const rules = {
  35. name: {
  36. required: true,
  37. message: '请输入姓名'
  38. },
  39. mobile: { validator: validator.mobile }
  40. }
  41. const formRef = ref(null)
  42. const form = useForm(rules, 'formRef')
  43. const { proxy } = getCurrentInstance()
  44. const handleUpload = e => {
  45. wx.editImage({
  46. src: e.detail.avatarUrl,
  47. success: res => {
  48. utils
  49. .uploadFile({
  50. filePath: res.tempFilePath,
  51. url: proxy.$uploadUrl
  52. })
  53. .then(res => {
  54. userInfo.value.photo = res
  55. })
  56. }
  57. })
  58. }
  59. const handleSave = () => {
  60. form.validate().then(() => {
  61. user.setUserInfo(userInfo.value)
  62. uni.switchTab({
  63. url: '/pages/my/my'
  64. })
  65. })
  66. }
  67. </script>
  68. <style lang="scss" scoped>
  69. .avatar-wrapper {
  70. margin: 30rpx;
  71. width: 140rpx;
  72. height: 140rpx;
  73. border-radius: 50%;
  74. border: none;
  75. padding: 0;
  76. display: inline-block;
  77. background-color: transparent;
  78. &::after {
  79. border: none;
  80. }
  81. }
  82. </style>