个人信息完成
parent
b65a5bdf6d
commit
9398339e0e
|
@ -24,7 +24,12 @@ urlpatterns = [
|
||||||
re_path('user/changeStatus/', UserProfileModelViewSet.as_view({'put': 'change_status'})),
|
re_path('user/changeStatus/', UserProfileModelViewSet.as_view({'put': 'change_status'})),
|
||||||
# 获取用户详情
|
# 获取用户详情
|
||||||
re_path('user/details/', UserProfileModelViewSet.as_view({'get': 'get_user_details'})),
|
re_path('user/details/', UserProfileModelViewSet.as_view({'get': 'get_user_details'})),
|
||||||
|
# 后台重置密码
|
||||||
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/', UserProfileModelViewSet.as_view({'get': 'profile','put': 'put_profile'})),
|
||||||
|
|
||||||
]
|
]
|
||||||
urlpatterns += router.urls
|
urlpatterns += router.urls
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from django.contrib.auth import authenticate
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
@ -8,7 +9,7 @@ from apps.permission.serializers import UserProfileSerializer, MenuSerializer, R
|
||||||
MenuCreateUpdateSerializer, DeptSerializer, DeptCreateUpdateSerializer, PostSerializer, PostCreateUpdateSerializer, \
|
MenuCreateUpdateSerializer, DeptSerializer, DeptCreateUpdateSerializer, PostSerializer, PostCreateUpdateSerializer, \
|
||||||
RoleCreateUpdateSerializer, DeptTreeSerializer, MenuTreeSerializer, UserProfileCreateUpdateSerializer, \
|
RoleCreateUpdateSerializer, DeptTreeSerializer, MenuTreeSerializer, UserProfileCreateUpdateSerializer, \
|
||||||
PostSimpleSerializer, RoleSimpleSerializer
|
PostSimpleSerializer, RoleSimpleSerializer
|
||||||
from utils.response import SuccessResponse
|
from utils.response import SuccessResponse, ErrorResponse
|
||||||
|
|
||||||
|
|
||||||
class GetUserProfileView(APIView):
|
class GetUserProfileView(APIView):
|
||||||
|
@ -279,3 +280,56 @@ class UserProfileModelViewSet(CustomModelViewSet):
|
||||||
if hasattr(self, 'handle_logging'):
|
if hasattr(self, 'handle_logging'):
|
||||||
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 profile(self, request: Request, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
获取用户个人信息
|
||||||
|
:param request:
|
||||||
|
:param args:
|
||||||
|
:param kwargs:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
instance = self.queryset.get(id=request.user.id)
|
||||||
|
serializer = self.get_serializer(instance)
|
||||||
|
if hasattr(self, 'handle_logging'):
|
||||||
|
self.handle_logging(request, instance=instance, *args, **kwargs)
|
||||||
|
return SuccessResponse(serializer.data)
|
||||||
|
|
||||||
|
def put_profile(self, request: Request, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
更新用户个人信息
|
||||||
|
:param request:
|
||||||
|
:param args:
|
||||||
|
:param kwargs:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
instance = self.queryset.get(id=request.user.id)
|
||||||
|
instance.name = request.data.get('name',None)
|
||||||
|
instance.mobile = request.data.get('mobile',None)
|
||||||
|
instance.email = request.data.get('email',None)
|
||||||
|
instance.gender = request.data.get('gender',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):
|
||||||
|
"""
|
||||||
|
个人修改密码
|
||||||
|
:param request:
|
||||||
|
:param args:
|
||||||
|
:param kwargs:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
instance = self.queryset.get(id=request.user.id)
|
||||||
|
instance.mobile = request.data.get('newPassword',None)
|
||||||
|
if not authenticate(username=request.user.username, password=request.data.get('oldPassword',None)):
|
||||||
|
return ErrorResponse(msg='旧密码不正确!')
|
||||||
|
instance.set_password(request.data.get('newPassword'))
|
||||||
|
instance.save()
|
||||||
|
serializer = self.get_serializer(instance)
|
||||||
|
if hasattr(self, 'handle_logging'):
|
||||||
|
self.handle_logging(request, instance=instance, *args, **kwargs)
|
||||||
|
return SuccessResponse(serializer.data)
|
||||||
|
|
|
@ -90,7 +90,7 @@ export function getUserProfile() {
|
||||||
// 修改用户个人信息
|
// 修改用户个人信息
|
||||||
export function updateUserProfile(data) {
|
export function updateUserProfile(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/permission/user/profile',
|
url: '/permission/user/profile/',
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
|
@ -105,7 +105,7 @@ export function updateUserPwd(oldPassword, newPassword) {
|
||||||
return request({
|
return request({
|
||||||
url: '/permission/user/profile/updatePwd/',
|
url: '/permission/user/profile/updatePwd/',
|
||||||
method: 'put',
|
method: 'put',
|
||||||
params: data
|
data: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,7 @@
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
<el-form-item label="任务分组:">{{ jobGroupFormat(form) }}</el-form-item>
|
<el-form-item label="任务分组:">{{ jobGroupFormat(form) }}</el-form-item>
|
||||||
<el-form-item label="创建时间:">{{ form.createTime }}</el-form-item>
|
<el-form-item label="创建时间:">{{ form.create_datetime }}</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
<el-form-item label="cron表达式:">{{ form.cronExpression }}</el-form-item>
|
<el-form-item label="cron表达式:">{{ form.cronExpression }}</el-form-item>
|
||||||
|
@ -485,4 +485,4 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -104,9 +104,9 @@
|
||||||
<el-table-column label="调用目标字符串" align="center" prop="invokeTarget" :show-overflow-tooltip="true" />
|
<el-table-column label="调用目标字符串" align="center" prop="invokeTarget" :show-overflow-tooltip="true" />
|
||||||
<el-table-column label="日志信息" align="center" prop="jobMessage" :show-overflow-tooltip="true" />
|
<el-table-column label="日志信息" align="center" prop="jobMessage" :show-overflow-tooltip="true" />
|
||||||
<el-table-column label="执行状态" align="center" prop="status" :formatter="statusFormat" />
|
<el-table-column label="执行状态" align="center" prop="status" :formatter="statusFormat" />
|
||||||
<el-table-column label="执行时间" align="center" prop="createTime" width="180">
|
<el-table-column label="执行时间" align="center" prop="create_datetime" width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.create_datetime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
@ -140,7 +140,7 @@
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
<el-form-item label="任务分组:">{{ form.jobGroup }}</el-form-item>
|
<el-form-item label="任务分组:">{{ form.jobGroup }}</el-form-item>
|
||||||
<el-form-item label="执行时间:">{{ form.createTime }}</el-form-item>
|
<el-form-item label="执行时间:">{{ form.create_datetime }}</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="24">
|
<el-col :span="24">
|
||||||
<el-form-item label="调用方法:">{{ form.invokeTarget }}</el-form-item>
|
<el-form-item label="调用方法:">{{ form.invokeTarget }}</el-form-item>
|
||||||
|
@ -296,4 +296,4 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -88,9 +88,9 @@
|
||||||
<el-table-column label="岗位名称" align="center" prop="postName" />
|
<el-table-column label="岗位名称" align="center" prop="postName" />
|
||||||
<el-table-column label="岗位排序" align="center" prop="postSort" />
|
<el-table-column label="岗位排序" align="center" prop="postSort" />
|
||||||
<el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
|
<el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
<el-table-column label="创建时间" align="center" prop="create_datetime" width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.create_datetime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
|
|
@ -118,9 +118,9 @@
|
||||||
></el-switch>
|
></el-switch>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
<el-table-column label="创建时间" align="center" prop="create_datetime" width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.create_datetime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
|
|
@ -153,7 +153,7 @@
|
||||||
></el-switch>
|
></el-switch>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[6].visible" width="160">
|
<el-table-column label="创建时间" align="center" prop="create_datetime" v-if="columns[6].visible" width="160">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.create_datetime) }}</span>
|
<span>{{ parseTime(scope.row.create_datetime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -8,32 +8,38 @@
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<userAvatar :user="user" />
|
<userAvatar :user="user"/>
|
||||||
</div>
|
</div>
|
||||||
<ul class="list-group list-group-striped">
|
<ul class="list-group list-group-striped">
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<svg-icon icon-class="user" />用户名称
|
<svg-icon icon-class="user"/>
|
||||||
<div class="pull-right">{{ user.userName }}</div>
|
用户名称
|
||||||
|
<div class="pull-right">{{ user.username }}</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<svg-icon icon-class="phone" />手机号码
|
<svg-icon icon-class="phone"/>
|
||||||
<div class="pull-right">{{ user.phonenumber }}</div>
|
手机号码
|
||||||
|
<div class="pull-right">{{ user.mobile }}</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<svg-icon icon-class="email" />用户邮箱
|
<svg-icon icon-class="email"/>
|
||||||
|
用户邮箱
|
||||||
<div class="pull-right">{{ user.email }}</div>
|
<div class="pull-right">{{ user.email }}</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<svg-icon icon-class="tree" />所属部门
|
<svg-icon icon-class="tree"/>
|
||||||
|
所属部门
|
||||||
<div class="pull-right" v-if="user.dept">{{ user.dept.deptName }} / {{ postGroup }}</div>
|
<div class="pull-right" v-if="user.dept">{{ user.dept.deptName }} / {{ postGroup }}</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<svg-icon icon-class="peoples" />所属角色
|
<svg-icon icon-class="peoples"/>
|
||||||
|
所属角色
|
||||||
<div class="pull-right">{{ roleGroup }}</div>
|
<div class="pull-right">{{ roleGroup }}</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<svg-icon icon-class="date" />创建日期
|
<svg-icon icon-class="date"/>
|
||||||
<div class="pull-right">{{ user.createTime }}</div>
|
创建日期
|
||||||
|
<div class="pull-right">{{ user.create_datetime }}</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -46,10 +52,10 @@
|
||||||
</div>
|
</div>
|
||||||
<el-tabs v-model="activeTab">
|
<el-tabs v-model="activeTab">
|
||||||
<el-tab-pane label="基本资料" name="userinfo">
|
<el-tab-pane label="基本资料" name="userinfo">
|
||||||
<userInfo :user="user" />
|
<userInfo :user="user"/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane label="修改密码" name="resetPwd">
|
<el-tab-pane label="修改密码" name="resetPwd">
|
||||||
<resetPwd :user="user" />
|
<resetPwd :user="user"/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
</el-tabs>
|
</el-tabs>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
@ -59,33 +65,37 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import userAvatar from "./userAvatar";
|
import userAvatar from "./userAvatar";
|
||||||
import userInfo from "./userInfo";
|
import userInfo from "./userInfo";
|
||||||
import resetPwd from "./resetPwd";
|
import resetPwd from "./resetPwd";
|
||||||
import { getUserProfile } from "@/api/permission/user";
|
import {getUserProfile} from "@/api/permission/user";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Profile",
|
name: "Profile",
|
||||||
components: { userAvatar, userInfo, resetPwd },
|
components: {userAvatar, userInfo, resetPwd},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
user: {},
|
user: {},
|
||||||
roleGroup: {},
|
roleGroup: {},
|
||||||
postGroup: {},
|
postGroup: {},
|
||||||
activeTab: "userinfo"
|
activeTab: "userinfo"
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getUser();
|
this.getUser();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getUser() {
|
getUser() {
|
||||||
getUserProfile().then(response => {
|
getUserProfile().then(response => {
|
||||||
this.user = response.data;
|
this.user = response.data;
|
||||||
this.roleGroup = response.roleGroup;
|
this.roleGroup = response.data.role.map(val => {
|
||||||
this.postGroup = response.postGroup;
|
return val.roleName
|
||||||
});
|
}).toString();
|
||||||
|
this.postGroup = response.data.post.map(val => {
|
||||||
|
return val.postName
|
||||||
|
}).toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
<template>
|
<template>
|
||||||
<el-form ref="form" :model="user" :rules="rules" label-width="80px">
|
<el-form ref="form" :model="user" :rules="rules" label-width="80px">
|
||||||
<el-form-item label="用户昵称" prop="nickName">
|
<el-form-item label="用户昵称" prop="username">
|
||||||
<el-input v-model="user.nickName" />
|
<el-input v-model="user.username"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="手机号码" prop="phonenumber">
|
<el-form-item label="手机号码" prop="mobile">
|
||||||
<el-input v-model="user.phonenumber" maxlength="11" />
|
<el-input v-model="user.mobile" maxlength="11"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="邮箱" prop="email">
|
<el-form-item label="邮箱" prop="email">
|
||||||
<el-input v-model="user.email" maxlength="50" />
|
<el-input v-model="user.email" maxlength="50"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="性别">
|
<el-form-item label="性别">
|
||||||
<el-radio-group v-model="user.sex">
|
<el-radio-group v-model="user.gender">
|
||||||
<el-radio label="0">男</el-radio>
|
<el-radio
|
||||||
<el-radio label="1">女</el-radio>
|
v-for="dict in sexOptions"
|
||||||
|
:label="dict.dictValue"
|
||||||
|
>{{dict.dictLabel}}
|
||||||
|
</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
|
@ -23,54 +26,61 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { updateUserProfile } from "@/api/permission/user";
|
import {updateUserProfile} from "@/api/permission/user";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
user: {
|
user: {
|
||||||
type: Object
|
type: Object
|
||||||
}
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
// 表单校验
|
|
||||||
rules: {
|
|
||||||
nickName: [
|
|
||||||
{ required: true, message: "用户昵称不能为空", trigger: "blur" }
|
|
||||||
],
|
|
||||||
email: [
|
|
||||||
{ required: true, message: "邮箱地址不能为空", trigger: "blur" },
|
|
||||||
{
|
|
||||||
type: "email",
|
|
||||||
message: "'请输入正确的邮箱地址",
|
|
||||||
trigger: ["blur", "change"]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
phonenumber: [
|
|
||||||
{ required: true, message: "手机号码不能为空", trigger: "blur" },
|
|
||||||
{
|
|
||||||
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
|
|
||||||
message: "请输入正确的手机号码",
|
|
||||||
trigger: "blur"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
},
|
data() {
|
||||||
methods: {
|
return {
|
||||||
submit() {
|
// 表单校验
|
||||||
this.$refs["form"].validate(valid => {
|
rules: {
|
||||||
if (valid) {
|
username: [
|
||||||
updateUserProfile(this.user).then(response => {
|
{required: true, message: "用户昵称不能为空", trigger: "blur"}
|
||||||
this.msgSuccess("修改成功");
|
],
|
||||||
});
|
email: [
|
||||||
}
|
{required: true, message: "邮箱地址不能为空", trigger: "blur"},
|
||||||
|
{
|
||||||
|
type: "email",
|
||||||
|
message: "'请输入正确的邮箱地址",
|
||||||
|
trigger: ["blur", "change"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
mobile: [
|
||||||
|
{required: true, message: "手机号码不能为空", trigger: "blur"},
|
||||||
|
{
|
||||||
|
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
|
||||||
|
message: "请输入正确的手机号码",
|
||||||
|
trigger: "blur"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
// 性别状态字典
|
||||||
|
sexOptions: [],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.getDicts("sys_user_sex").then(response => {
|
||||||
|
this.sexOptions = response.data;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
close() {
|
methods: {
|
||||||
this.$store.dispatch("tagsView/delView", this.$route);
|
submit() {
|
||||||
this.$router.push({ path: "/index" });
|
this.$refs["form"].validate(valid => {
|
||||||
|
if (valid) {
|
||||||
|
updateUserProfile(this.user).then(response => {
|
||||||
|
this.msgSuccess("修改成功");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.$store.dispatch("tagsView/delView", this.$route);
|
||||||
|
this.$router.push({path: "/index"});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue