Browse Source

feat(app): 个人设置修改头像

EvilDragon 5 months ago
parent
commit
3130d1fc88

+ 2 - 1
packages/app/src/core/libs/requests.ts

@@ -1,4 +1,4 @@
-import { httpGet, httpPost } from '../../utils/http'
+import { httpGet, httpPost, httpPut } from '../../utils/http'
 import { Schedule } from '../models/schedule'
 import { DictType, MaterialDealer, MaterialDealerRes, Moment } from '../models/moment'
 import dayjs from 'dayjs'
@@ -115,6 +115,7 @@ export const weixinMiniAppLogin = (phoneCode: string, loginCode: string, state:
     state,
   })
 export const getMemberUserInfo = () => httpGet<any>('/app-api/member/user/get')
+export const updateMemberUserInfo = (data = {}) => httpPut<any>('/app-api/member/user/update', data)
 export const getByDictType = (
   type: string | 'member_channel_source' | 'member_spatial_expertise_type' | DictType,
 ) =>

+ 38 - 8
packages/app/src/pages/mine/setting/index.vue

@@ -3,23 +3,53 @@
 </route>
 <script setup lang="ts">
 import SectionHeading from '@/components/section-heading.vue'
+import { useUserStore } from '../../../store'
+import { storeToRefs } from 'pinia'
+import { updateMemberUserInfo } from '../../../core/libs/requests'
+
+const userStore = useUserStore()
+const { userInfo } = storeToRefs(userStore)
+const handleChooseAvatar = async ({ detail: { avatarUrl } }) => {
+  console.log(avatarUrl)
+  const { code, msg } = await updateMemberUserInfo({ avatar: avatarUrl })
+  code !== 0 &&
+    uni.showToast({
+      title: msg,
+      icon: 'none',
+      mask: true,
+    })
+}
 </script>
 <template>
   <div class="flex-grow bg-white flex flex-col p-4.5 gap-8">
-    <div class="flex justify-center">
-      <img
-        class="w-[97px] h-[97px] rounded-full border border-white"
-        src="https://via.placeholder.com/97x97"
-      />
+    <div class="flex flex-col items-center">
+      <button
+        class="p-0 leading-0 bg-transparent"
+        open-type="chooseAvatar"
+        @chooseavatar="handleChooseAvatar"
+      >
+        <wd-img
+          round
+          width="97"
+          height="97"
+          :src="
+            (userInfo.avatar ?? '' === '') ? 'https://via.placeholder.com/97x97' : userInfo.avatar
+          "
+          custom-class="border border-white border-solid"
+        ></wd-img>
+      </button>
+      <div class="text-center text-black/40 text-xs font-normal font-['PingFang SC'] leading-none">
+        更换头像
+      </div>
     </div>
-    <SectionHeading title="姓名" size="sm" end-text="sss" end-arrow></SectionHeading>
+    <SectionHeading title="姓名" size="sm" :end-text="userInfo.nickname" end-arrow></SectionHeading>
     <SectionHeading title="性别" size="sm" end-text="设置" end-arrow></SectionHeading>
     <SectionHeading title="生日" size="sm" end-text="设置" end-arrow></SectionHeading>
 
-    <SectionHeading title="手机号" size="sm"></SectionHeading>
+    <!-- <SectionHeading title="手机号" size="sm" :end-text="''" end-arrow></SectionHeading>
     <SectionHeading title="公司" size="sm"></SectionHeading>
     <SectionHeading title="推荐人" size="sm"></SectionHeading>
-    <SectionHeading title="经纪人" size="sm"></SectionHeading>
+    <SectionHeading title="经纪人" size="sm"></SectionHeading> -->
     <div class="flex-1"></div>
     <div><wd-button block :round="false">退出登录</wd-button></div>
   </div>

+ 7 - 0
packages/app/src/utils/http.ts

@@ -110,6 +110,13 @@ export const httpPost = <T>(
     method: 'POST',
   })
 }
+export const httpPut = <T>(url: string, data?: Record<string, any>) =>
+  http<T>({
+    url,
+    query: {},
+    data,
+    method: 'PUT',
+  })
 
 http.get = httpGet
 http.post = httpPost