代码提交
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { useMainStore } from "@/store/store";
|
||||
import { useInterface } from "@/hooks/useInterface";
|
||||
import { updateAvatar, updateUserInfo } from "@/api/user";
|
||||
import { upload } from "@/api/api";
|
||||
|
||||
export function useRequest() {
|
||||
const {loading, hideLoading, toast} = useInterface()
|
||||
@ -12,12 +13,15 @@ export function useRequest() {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function doUpdateAvatar(file) {
|
||||
let data = new FormData()
|
||||
data.append('avatarFile', file)
|
||||
loading({title: '上传中...'})
|
||||
await updateAvatar(data)
|
||||
await userStore.getUserInfo()
|
||||
hideLoading()
|
||||
try {
|
||||
await upload({
|
||||
filePath: file.url,
|
||||
name: 'avatarFile'
|
||||
});
|
||||
await userStore.getUserInfo()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function doUpdateUserInfo() {
|
||||
|
@ -44,8 +44,7 @@ const modelRef = ref()
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function afterChooseFile(event) {
|
||||
const imgObj = await objectURLToBlob(event.file.url)
|
||||
await doUpdateAvatar(new File([imgObj], '', {type: imgObj.type}))
|
||||
await doUpdateAvatar(event.file)
|
||||
}
|
||||
|
||||
function sexChange(event) {
|
||||
|
Reference in New Issue
Block a user