上传头像功能
parent
8075c55859
commit
29993485bb
|
@ -28,6 +28,8 @@ urlpatterns = [
|
||||||
re_path('user/resetPwd/', UserProfileModelViewSet.as_view({'put': 'reset_pwd'})),
|
re_path('user/resetPwd/', UserProfileModelViewSet.as_view({'put': 'reset_pwd'})),
|
||||||
# 用户自己重置密码
|
# 用户自己重置密码
|
||||||
re_path('user/profile/updatePwd/', UserProfileModelViewSet.as_view({'put': 'update_pwd'})),
|
re_path('user/profile/updatePwd/', UserProfileModelViewSet.as_view({'put': 'update_pwd'})),
|
||||||
|
# 更新用户头像
|
||||||
|
re_path('user/profile/avatar/', UserProfileModelViewSet.as_view({'put': 'put_avatar'})),
|
||||||
# 获取、更新用户个人信息
|
# 获取、更新用户个人信息
|
||||||
re_path('user/profile/', UserProfileModelViewSet.as_view({'get': 'profile', 'put': 'put_profile'})),
|
re_path('user/profile/', UserProfileModelViewSet.as_view({'get': 'profile', 'put': 'put_profile'})),
|
||||||
# 导出用户
|
# 导出用户
|
||||||
|
|
|
@ -359,6 +359,22 @@ class UserProfileModelViewSet(CustomModelViewSet):
|
||||||
self.handle_logging(request, instance=instance, *args, **kwargs)
|
self.handle_logging(request, instance=instance, *args, **kwargs)
|
||||||
return SuccessResponse(serializer.data)
|
return SuccessResponse(serializer.data)
|
||||||
|
|
||||||
|
def put_avatar(self, request: Request, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
更新用户头像
|
||||||
|
:param request:
|
||||||
|
:param args:
|
||||||
|
:param kwargs:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
instance = self.queryset.get(id=request.user.id)
|
||||||
|
instance.avatar = request.data.get('avatar_url', None)
|
||||||
|
instance.save()
|
||||||
|
serializer = self.get_serializer(instance)
|
||||||
|
if hasattr(self, 'handle_logging'):
|
||||||
|
self.handle_logging(request, instance=instance, *args, **kwargs)
|
||||||
|
return SuccessResponse(serializer.data)
|
||||||
|
|
||||||
def update_pwd(self, request: Request, *args, **kwargs):
|
def update_pwd(self, request: Request, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
个人修改密码
|
个人修改密码
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from django.db.models import CharField, BooleanField
|
from django.db.models import CharField, BooleanField, TextField
|
||||||
|
|
||||||
from ...op_drf.models import CoreModel
|
from ...op_drf.models import CoreModel
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ class LoginInfor(CoreModel):
|
||||||
browser = CharField(max_length=64, verbose_name="浏览器")
|
browser = CharField(max_length=64, verbose_name="浏览器")
|
||||||
ipaddr = CharField(max_length=32, verbose_name="ip地址", null=True, blank=True)
|
ipaddr = CharField(max_length=32, verbose_name="ip地址", null=True, blank=True)
|
||||||
loginLocation = CharField(max_length=64, verbose_name="登录位置", null=True, blank=True)
|
loginLocation = CharField(max_length=64, verbose_name="登录位置", null=True, blank=True)
|
||||||
msg = CharField(max_length=64, verbose_name="操作信息", null=True, blank=True)
|
msg = TextField(verbose_name="操作信息", null=True, blank=True)
|
||||||
os = CharField(max_length=64, verbose_name="操作系统", null=True, blank=True)
|
os = CharField(max_length=64, verbose_name="操作系统", null=True, blank=True)
|
||||||
status = BooleanField(default=False, verbose_name="登录状态")
|
status = BooleanField(default=False, verbose_name="登录状态")
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ export function updateUserPwd(oldPassword, newPassword) {
|
||||||
export function uploadAvatar(data) {
|
export function uploadAvatar(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/admin/permission/user/profile/avatar/',
|
url: '/admin/permission/user/profile/avatar/',
|
||||||
method: 'post',
|
method: 'put',
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
import { VueCropper } from "vue-cropper";
|
import { VueCropper } from "vue-cropper";
|
||||||
import { uploadAvatar } from "@/api/vadmin/permission/user";
|
import { uploadAvatar } from "@/api/vadmin/permission/user";
|
||||||
|
import {addSaveFile} from "@/api/vadmin/system/savefile";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { VueCropper },
|
components: { VueCropper },
|
||||||
|
@ -123,13 +124,15 @@ export default {
|
||||||
uploadImg() {
|
uploadImg() {
|
||||||
this.$refs.cropper.getCropBlob(data => {
|
this.$refs.cropper.getCropBlob(data => {
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append("avatarfile", data);
|
formData.append("file", data);
|
||||||
uploadAvatar(formData).then(response => {
|
addSaveFile(formData).then(res => {
|
||||||
this.open = false;
|
uploadAvatar({avatar_url:res.data.file_url}).then(response => {
|
||||||
this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
|
this.open = false;
|
||||||
store.commit('SET_AVATAR', this.options.img);
|
this.options.img = process.env.VUE_APP_BASE_API + response.data.avatar;
|
||||||
this.msgSuccess("修改成功");
|
store.commit('SET_AVATAR', this.options.img);
|
||||||
this.visible = false;
|
this.msgSuccess("修改成功");
|
||||||
|
this.visible = false;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue