个人信息完成

pull/1/head
李强 2021-02-27 20:38:44 +08:00
parent b65a5bdf6d
commit 9398339e0e
10 changed files with 185 additions and 106 deletions

View File

@ -24,7 +24,12 @@ urlpatterns = [
re_path('user/changeStatus/', UserProfileModelViewSet.as_view({'put': 'change_status'})),
# 获取用户详情
re_path('user/details/', UserProfileModelViewSet.as_view({'get': 'get_user_details'})),
# 后台重置密码
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

View File

@ -1,3 +1,4 @@
from django.contrib.auth import authenticate
from rest_framework.request import Request
from rest_framework.views import APIView
@ -8,7 +9,7 @@ from apps.permission.serializers import UserProfileSerializer, MenuSerializer, R
MenuCreateUpdateSerializer, DeptSerializer, DeptCreateUpdateSerializer, PostSerializer, PostCreateUpdateSerializer, \
RoleCreateUpdateSerializer, DeptTreeSerializer, MenuTreeSerializer, UserProfileCreateUpdateSerializer, \
PostSimpleSerializer, RoleSimpleSerializer
from utils.response import SuccessResponse
from utils.response import SuccessResponse, ErrorResponse
class GetUserProfileView(APIView):
@ -279,3 +280,56 @@ class UserProfileModelViewSet(CustomModelViewSet):
if hasattr(self, 'handle_logging'):
self.handle_logging(request, instance=instance, *args, **kwargs)
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)

View File

@ -90,7 +90,7 @@ export function getUserProfile() {
// 修改用户个人信息
export function updateUserProfile(data) {
return request({
url: '/permission/user/profile',
url: '/permission/user/profile/',
method: 'put',
data: data
})
@ -105,7 +105,7 @@ export function updateUserPwd(oldPassword, newPassword) {
return request({
url: '/permission/user/profile/updatePwd/',
method: 'put',
params: data
data: data
})
}

View File

@ -225,7 +225,7 @@
</el-col>
<el-col :span="12">
<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 :span="12">
<el-form-item label="cron表达式">{{ form.cronExpression }}</el-form-item>
@ -485,4 +485,4 @@ export default {
}
}
};
</script>
</script>

View File

@ -104,9 +104,9 @@
<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="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">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ parseTime(scope.row.create_datetime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
@ -140,7 +140,7 @@
</el-col>
<el-col :span="12">
<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 :span="24">
<el-form-item label="调用方法:">{{ form.invokeTarget }}</el-form-item>
@ -296,4 +296,4 @@ export default {
}
}
};
</script>
</script>

View File

@ -88,9 +88,9 @@
<el-table-column label="岗位名称" align="center" prop="postName" />
<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="createTime" width="180">
<el-table-column label="创建时间" align="center" prop="create_datetime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ parseTime(scope.row.create_datetime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">

View File

@ -118,9 +118,9 @@
></el-switch>
</template>
</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">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ parseTime(scope.row.create_datetime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">

View File

@ -153,7 +153,7 @@
></el-switch>
</template>
</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">
<span>{{ parseTime(scope.row.create_datetime) }}</span>
</template>

View File

@ -8,32 +8,38 @@
</div>
<div>
<div class="text-center">
<userAvatar :user="user" />
<userAvatar :user="user"/>
</div>
<ul class="list-group list-group-striped">
<li class="list-group-item">
<svg-icon icon-class="user" />用户名称
<div class="pull-right">{{ user.userName }}</div>
<svg-icon icon-class="user"/>
用户名称
<div class="pull-right">{{ user.username }}</div>
</li>
<li class="list-group-item">
<svg-icon icon-class="phone" />手机号码
<div class="pull-right">{{ user.phonenumber }}</div>
<svg-icon icon-class="phone"/>
手机号码
<div class="pull-right">{{ user.mobile }}</div>
</li>
<li class="list-group-item">
<svg-icon icon-class="email" />用户邮箱
<svg-icon icon-class="email"/>
用户邮箱
<div class="pull-right">{{ user.email }}</div>
</li>
<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>
</li>
<li class="list-group-item">
<svg-icon icon-class="peoples" />所属角色
<svg-icon icon-class="peoples"/>
所属角色
<div class="pull-right">{{ roleGroup }}</div>
</li>
<li class="list-group-item">
<svg-icon icon-class="date" />创建日期
<div class="pull-right">{{ user.createTime }}</div>
<svg-icon icon-class="date"/>
创建日期
<div class="pull-right">{{ user.create_datetime }}</div>
</li>
</ul>
</div>
@ -46,10 +52,10 @@
</div>
<el-tabs v-model="activeTab">
<el-tab-pane label="基本资料" name="userinfo">
<userInfo :user="user" />
<userInfo :user="user"/>
</el-tab-pane>
<el-tab-pane label="修改密码" name="resetPwd">
<resetPwd :user="user" />
<resetPwd :user="user"/>
</el-tab-pane>
</el-tabs>
</el-card>
@ -59,33 +65,37 @@
</template>
<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile } from "@/api/permission/user";
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import {getUserProfile} from "@/api/permission/user";
export default {
name: "Profile",
components: { userAvatar, userInfo, resetPwd },
data() {
return {
user: {},
roleGroup: {},
postGroup: {},
activeTab: "userinfo"
};
},
created() {
this.getUser();
},
methods: {
getUser() {
getUserProfile().then(response => {
this.user = response.data;
this.roleGroup = response.roleGroup;
this.postGroup = response.postGroup;
});
export default {
name: "Profile",
components: {userAvatar, userInfo, resetPwd},
data() {
return {
user: {},
roleGroup: {},
postGroup: {},
activeTab: "userinfo"
};
},
created() {
this.getUser();
},
methods: {
getUser() {
getUserProfile().then(response => {
this.user = response.data;
this.roleGroup = response.data.role.map(val => {
return val.roleName
}).toString();
this.postGroup = response.data.post.map(val => {
return val.postName
}).toString();
});
}
}
}
};
};
</script>

View File

@ -1,18 +1,21 @@
<template>
<el-form ref="form" :model="user" :rules="rules" label-width="80px">
<el-form-item label="用户昵称" prop="nickName">
<el-input v-model="user.nickName" />
<el-form-item label="用户昵称" prop="username">
<el-input v-model="user.username"/>
</el-form-item>
<el-form-item label="手机号码" prop="phonenumber">
<el-input v-model="user.phonenumber" maxlength="11" />
<el-form-item label="手机号码" prop="mobile">
<el-input v-model="user.mobile" maxlength="11"/>
</el-form-item>
<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 label="性别">
<el-radio-group v-model="user.sex">
<el-radio label="0"></el-radio>
<el-radio label="1"></el-radio>
<el-radio-group v-model="user.gender">
<el-radio
v-for="dict in sexOptions"
:label="dict.dictValue"
>{{dict.dictLabel}}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item>
@ -23,54 +26,61 @@
</template>
<script>
import { updateUserProfile } from "@/api/permission/user";
import {updateUserProfile} from "@/api/permission/user";
export default {
props: {
user: {
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"
}
]
export default {
props: {
user: {
type: Object
}
};
},
methods: {
submit() {
this.$refs["form"].validate(valid => {
if (valid) {
updateUserProfile(this.user).then(response => {
this.msgSuccess("修改成功");
});
}
},
data() {
return {
//
rules: {
username: [
{required: true, message: "用户昵称不能为空", trigger: "blur"}
],
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() {
this.$store.dispatch("tagsView/delView", this.$route);
this.$router.push({ path: "/index" });
methods: {
submit() {
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>