Files

33 lines
841 B
JavaScript
Raw Normal View History

2023-11-14 17:21:03 +08:00
import { useMainStore } from "@/store/store";
import { useInterface } from "@/hooks/useInterface";
import { updateAvatar, updateUserInfo } from "@/api/user";
export function useRequest() {
const {loading, hideLoading, toast} = useInterface()
const userStore = useMainStore()
/**
* 请求修改用户头像
* @param file
* @returns {Promise<void>}
*/
async function doUpdateAvatar(file) {
let data = new FormData()
data.append('avatarFile', file)
loading({title: '上传中...'})
await updateAvatar(data)
await userStore.getUserInfo()
hideLoading()
}
async function doUpdateUserInfo() {
await updateUserInfo(userStore.user)
await userStore.getUserInfo()
}
return {
doUpdateAvatar,
doUpdateUserInfo
}
}