diff --git a/src/hooks/auth.ts b/src/hooks/auth.ts index 3a7dcd16..4e866e5c 100644 --- a/src/hooks/auth.ts +++ b/src/hooks/auth.ts @@ -29,6 +29,18 @@ export const useAuth = () => { } } +export const useAuthProfile = () => { + const $store = useStore() + + const isLogin = computed(() => !!$store.state.Auth.user) + + const profile = computed(() => + isLogin.value ? $store.state.Auth.user.profile : null + ) + + return profile +} + export const useLogin = () => { const $store = useStore() return (info: any) => $store.commit('Auth/LOGIN', info) @@ -48,6 +60,24 @@ export const useLogout = () => { } } +export const useUpdateProfile = () => { + const $store = useStore() + + return (value: any) => { + if (!$store.getters['Auth/isLogin']) { + return + } + try { + $store.commit('Auth/UPDATE_USER', { + key: 'profile', + value + }) + } catch (e) { + Toast(e.message) + } + } +} + export const useLoadProfile = () => { const $store = useStore() diff --git a/src/layout/container.less b/src/layout/container.less index ee8ddb5f..f5a1e52e 100644 --- a/src/layout/container.less +++ b/src/layout/container.less @@ -1,6 +1,7 @@ @import '~@/config/style.config.less'; .container { + position: relative; display: grid; grid-template-rows: 60px minmax(360px, calc(100% - 120px)) 80px; grid-template-columns: 100%; diff --git a/src/pages/userinfo/api.ts b/src/pages/userinfo/api.ts index a18770c2..06f2bcae 100644 --- a/src/pages/userinfo/api.ts +++ b/src/pages/userinfo/api.ts @@ -24,3 +24,27 @@ export const getFansList = (uid: string) => uid } }) + +export const uploadAvatar = (file: any) => { + const data = new FormData() + data.append('imgFile', file) + return http.post(`/api/avatar/upload?imgSize=1024`, data, { + headers: { + ['Content-Type']: 'multipart/form-data' + } + }) +} + +interface ProfileData { + gender: number + signature: string + city: string + province: string + nickname: string + birthday: number +} + +export const updateProfile = (params: ProfileData) => + http.get('/api/user/update', { + params + }) diff --git a/src/pages/userinfo/component/upload-avatar/UploadWrapper.tsx b/src/pages/userinfo/component/upload-avatar/UploadWrapper.tsx new file mode 100644 index 00000000..e511d22f --- /dev/null +++ b/src/pages/userinfo/component/upload-avatar/UploadWrapper.tsx @@ -0,0 +1,34 @@ +/** + * Created by buddy on 2021/2/21. + */ +import { defineComponent, ref } from 'vue' + +export const UploadWrapper = defineComponent({ + name: 'UploadWrapper', + props: ['onFile'], + emits: ['file'], + setup() { + const input = ref() + + return function(this: any) { + return ( +