代码提交
This commit is contained in:
32
pages/userInfo/index.utlis.js
Normal file
32
pages/userInfo/index.utlis.js
Normal file
@ -0,0 +1,32 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user