83 lines
1.8 KiB
JavaScript
83 lines
1.8 KiB
JavaScript
import {
|
|
reactive,
|
|
ref,
|
|
computed,
|
|
nextTick
|
|
} from 'vue';
|
|
import {
|
|
uploadFile
|
|
} from '@/api/common';
|
|
import {
|
|
queryCurrentUser
|
|
} from '@/api/login.js';
|
|
import common from '@/common/common';
|
|
import {
|
|
updateDfSysUserExtandInfoImageAddr
|
|
} from '@/api/user.js';
|
|
|
|
export default function useUpdateAvatar({
|
|
success = () => {}
|
|
}) {
|
|
const avatarCropperUrl = ref('');
|
|
const avatarCropperStatus = ref(true);
|
|
// 点击修改头像
|
|
const click_update_avatar = () => {
|
|
uni.chooseImage({
|
|
count: 1,
|
|
sizeType: ['compressed'],
|
|
success: (resPicture) => {
|
|
uni.getFileInfo({
|
|
filePath: resPicture.tempFilePaths[0],
|
|
success: function(resSize) {
|
|
if (resSize.size > 10 * 1024 * 1024) return common.msg(
|
|
'图片过大,请重新选择');
|
|
avatarCropperUrl.value = resPicture.tempFilePaths[0];
|
|
avatarCropperStatus.value = true;
|
|
},
|
|
fail: function(err) {
|
|
common.msg('获取图片失败,请选择其他图片');
|
|
}
|
|
});
|
|
}
|
|
});
|
|
};
|
|
// 选择头像取消
|
|
const avatarOnCancel = (value) => {
|
|
avatarCropperStatus.value = false;
|
|
};
|
|
// 选择头像确定
|
|
const avatarOnConfirm = (file) => {
|
|
avatarCropperStatus.value = false;
|
|
nextTick(async () => {
|
|
common.loading('更新头像中');
|
|
try {
|
|
const data = {
|
|
bizScen: 'S3007',
|
|
thumbnailFlag: true,
|
|
thumbImgSize: 100
|
|
};
|
|
// 上传图片
|
|
const res = await uploadFile(file.tempFilePath, data);
|
|
// 更新个人信息
|
|
await updateDfSysUserExtandInfoImageAddr({
|
|
imageAddr: res.thumbFileId
|
|
});
|
|
// 更新个人信息
|
|
const userData = await queryCurrentUser();
|
|
common.msg('修改成功');
|
|
success(userData)
|
|
|
|
} catch {
|
|
common.msg('修改失败');
|
|
}
|
|
common.hideLoading();
|
|
});
|
|
};
|
|
return {
|
|
avatarCropperUrl,
|
|
avatarCropperStatus,
|
|
click_update_avatar,
|
|
avatarOnCancel,
|
|
avatarOnConfirm,
|
|
};
|
|
} |