fix(dictionary): dictionary data init & user password reset

pull/56/head
Angelo 2022-05-11 13:45:39 +08:00
parent f88b90388c
commit 0e7678d3d1
9 changed files with 231 additions and 181 deletions

View File

@ -148,10 +148,21 @@ button_data = [
"dept_belong_id": 1,
"update_datetime": datetime.datetime.now(),
"create_datetime": datetime.datetime.now(),
"name": "密码",
"name": "密码",
"value": "ResetPassword",
"creator_id": 1,
},
{
"id": 10,
"description": None,
"modifier": "1",
"dept_belong_id": 1,
"update_datetime": datetime.datetime.now(),
"create_datetime": datetime.datetime.now(),
"name": "重置密码",
"value": "DefaultPassword",
"creator_id": 1,
},
]
menu_data = [
@ -1250,7 +1261,7 @@ menu_button_data = [
"dept_belong_id": 1,
"update_datetime": datetime.datetime.now(),
"create_datetime": datetime.datetime.now(),
"name": "密码",
"name": "密码",
"value": "ResetPassword",
"api": "/api/system/user/reset_password/{id}/",
"method": 2,
@ -1261,6 +1272,20 @@ menu_button_data = [
"id": 54,
"description": None,
"modifier": "1",
"dept_belong_id": 1,
"update_datetime": datetime.datetime.now(),
"create_datetime": datetime.datetime.now(),
"name": "重置密码",
"value": "DefaultPassword",
"api": "/api/system/user/reset_to_default_password/{id}/",
"method": 2,
"creator_id": 1,
"menu_id": 3,
},
{
"id": 55,
"description": None,
"modifier": "1",
"dept_belong_id": "1",
"update_datetime": datetime.datetime.now(),
"create_datetime": datetime.datetime.now(),
@ -1272,7 +1297,7 @@ menu_button_data = [
"menu_id": 20,
},
{
"id": 55,
"id": 56,
"description": None,
"modifier": "1",
"dept_belong_id": "1",
@ -1286,7 +1311,7 @@ menu_button_data = [
"menu_id": 20,
},
{
"id": 56,
"id": 57,
"description": None,
"modifier": "1",
"dept_belong_id": 1,
@ -1388,7 +1413,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": None,
"is_value": 0,
"type": 0
"type": 0,
},
{
"id": 2,
@ -1405,7 +1430,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 1,
"is_value": 1,
"type": 6
"type": 6,
},
{
"id": 5,
@ -1422,7 +1447,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": None,
"is_value": 0,
"type": 0
"type": 0,
},
{
"id": 6,
@ -1439,7 +1464,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 1,
"is_value": 1,
"type": 6
"type": 6,
},
{
"id": 7,
@ -1456,7 +1481,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": None,
"is_value": 0,
"type": 0
"type": 0,
},
{
"id": 8,
@ -1473,7 +1498,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 7,
"is_value": 1,
"type": 1
"type": 1,
},
{
"id": 9,
@ -1490,7 +1515,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 7,
"is_value": 1,
"type": 1
"type": 1,
},
{
"id": 10,
@ -1507,7 +1532,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": None,
"is_value": 0,
"type": 0
"type": 0,
},
{
"id": 11,
@ -1524,7 +1549,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 5,
"is_value": 1,
"type": 6
"type": 6,
},
{
"id": 12,
@ -1541,7 +1566,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 5,
"is_value": 1,
"type": 6
"type": 6,
},
{
"id": 13,
@ -1558,7 +1583,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 10,
"is_value": 1,
"type": 1
"type": 1,
},
{
"id": 14,
@ -1575,7 +1600,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 10,
"is_value": 1,
"type": 1
"type": 1,
},
{
"id": 15,
@ -1592,7 +1617,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": None,
"is_value": 0,
"type": 0
"type": 0,
},
{
"id": 16,
@ -1609,7 +1634,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 15,
"is_value": 1,
"type": 1
"type": 1,
},
{
"id": 17,
@ -1626,7 +1651,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 15,
"is_value": 1,
"type": 1
"type": 1,
},
{
"id": 18,
@ -1643,7 +1668,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": None,
"is_value": 0,
"type": 0
"type": 0,
},
{
"id": 19,
@ -1660,7 +1685,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 18,
"is_value": 1,
"type": 1
"type": 1,
},
{
"id": 20,
@ -1677,7 +1702,7 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 18,
"is_value": 1,
"type": 1
"type": 1,
},
{
"id": 21,
@ -1694,6 +1719,6 @@ dictionary_data = [
"creator_id": 1,
"parent_id": 18,
"is_value": 1,
"type": 1
}
"type": 1,
},
]

View File

@ -15,6 +15,7 @@ from dvadmin.system.models import (
MenuButton,
Role,
Users,
Dictionary,
)
from .init_data import (
@ -78,7 +79,7 @@ class Initialize(CoreInitialize):
初始化字典表
"""
data = dictionary_data
self.save(Users, data, "字典表", no_reset=False)
self.save(Dictionary, data, "字典表", no_reset=False)
def run(self):
self.init_dept()
@ -87,6 +88,7 @@ class Initialize(CoreInitialize):
self.init_menu_button()
self.init_role()
self.init_users()
self.init_dictionary()
# 项目init 初始化,默认会执行 main 方法进行初始化

View File

@ -1,11 +1,3 @@
# -*- coding: utf-8 -*-
"""
@author: 猿小天
@contact: QQ:1638245306
@Created on: 2021/6/1 001 23:05
@Remark: 系统管理的路由文件
"""
from django.urls import path
from rest_framework import routers
@ -42,6 +34,7 @@ urlpatterns = [
path('menu/web_router/', MenuViewSet.as_view({'get': 'web_router'})),
path('user/user_info/', UserViewSet.as_view({'get': 'user_info', 'put': 'update_user_info'})),
path('user/change_password/<int:pk>/', UserViewSet.as_view({'put': 'change_password'})),
path('user/reset_to_default_password/<int:pk>/', UserViewSet.as_view({'put': 'reset_to_default_password'})),
path('user/reset_password/<int:pk>/', UserViewSet.as_view({'put': 'reset_password'})),
path('user/export/', UserViewSet.as_view({'post': 'export_data', })),
path('user/import/', UserViewSet.as_view({'get': 'import_data', 'post': 'import_data'})),

View File

@ -241,16 +241,16 @@ class UserViewSet(CustomModelViewSet):
else:
return ErrorResponse(msg="未获取到用户")
# @action(methods=["PUT"], detail=True, permission_classes=[IsAuthenticated])
# def reset_password(self, request, *args, **kwargs):
# """重置密码"""
# instance = Users.objects.filter(id=kwargs.get("pk")).first()
# if instance:
# instance.set_password(settings.DEFAULT_PASSWORD)
# instance.save()
# return DetailResponse(data=None, msg="密码重置成功")
# else:
# return ErrorResponse(msg="未获取到用户")
@action(methods=["PUT"], detail=True, permission_classes=[IsAuthenticated])
def reset_to_default_password(self, request, *args, **kwargs):
"""恢复默认密码"""
instance = Users.objects.filter(id=kwargs.get("pk")).first()
if instance:
instance.set_password(settings.DEFAULT_PASSWORD)
instance.save()
return DetailResponse(data=None, msg="密码重置成功")
else:
return ErrorResponse(msg="未获取到用户")
@action(methods=["PUT"], detail=True)
def reset_password(self, request, pk):

View File

@ -1,7 +1,5 @@
<template>
<div class="page-login">
</div>
<div class="page-login"></div>
</template>
<script>
@ -14,8 +12,10 @@ export default {
computed: {
...mapState('d2admin', {
siteName: (state) => state.settings.siteName, //
siteLogo: (state) => state.settings.siteLogo || require('./image/dvadmin.png'), // logo
loginBackground: (state) => state.settings.loginBackground || require('./image/bg.jpg'), //
siteLogo: (state) =>
state.settings.siteLogo || require('./image/dvadmin.png'), // logo
loginBackground: (state) =>
state.settings.loginBackground || require('./image/bg.jpg'), //
copyright: (state) => state.settings.copyright, //
keepRecord: (state) => state.settings.keepRecord, //
helpUrl: (state) => state.settings.helpUrl, //
@ -33,8 +33,8 @@ export default {
backgroundImage: 'url(' + this.loginBackground + ')',
//
formLogin: {
username: '',
password: '',
username: 'superadmin',
password: 'admin123456',
captcha: ''
},
//
@ -65,15 +65,13 @@ export default {
image_base: null
}
},
mounted () {
},
beforeDestroy () {
},
mounted () {},
beforeDestroy () {},
methods: {
...mapActions('d2admin/account', ['login']),
/**
* 获取验证码
*/
* 获取验证码
*/
getCaptcha () {
api.getCaptcha().then((ret) => {
this.formLogin.captcha = null
@ -82,8 +80,8 @@ export default {
})
},
/**
* @description 提交表单
*/
* @description 提交表单
*/
//
submit () {
const that = this
@ -120,107 +118,107 @@ export default {
</script>
<style lang="scss" scoped>
// ----
.page-login {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-image: url(./image/bg.jpg);
background-position: center 0;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
-webkit-background-size: cover; /* 兼容Webkit内核浏览器如Chrome和Safari */
-o-background-size: cover; /* 兼容Opera */
zoom: 1;
}
// ----
.page-login {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-image: url(./image/bg.jpg);
background-position: center 0;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
-webkit-background-size: cover; /* 兼容Webkit内核浏览器如Chrome和Safari */
-o-background-size: cover; /* 兼容Opera */
zoom: 1;
}
::v-deep .el-card__body {
height: 100%;
padding: 0;
}
::v-deep .el-card__body {
height: 100%;
padding: 0;
}
.card {
height: 100%;
width: 100%;
border-radius: 30px;
padding: 0;
margin-top: 12%;
}
.card {
height: 100%;
width: 100%;
border-radius: 30px;
padding: 0;
margin-top: 12%;
}
.right-card {
float: right;
.right-card {
float: right;
text-align: center;
width: 50%;
height: 100%;
}
.right-card h1 {
color: #098dee;
margin-bottom: 40px;
margin-top: 40px;
}
.button-login {
width: 100%;
margin-top: 30px;
}
::v-deep .el-input-group__append {
padding: 0;
}
// footer
.page-login--content-footer {
margin-top: 10%;
padding: 1em 0;
.page-login--content-footer-locales {
padding: 0px;
margin: 0px;
margin-bottom: 15px;
font-size: 12px;
line-height: 12px;
text-align: center;
width: 50%;
height: 100%;
}
color: $color-text-normal;
.right-card h1 {
color: #098dee;
margin-bottom: 40px;
margin-top: 40px;
}
.button-login {
width: 100%;
margin-top: 30px;
}
::v-deep .el-input-group__append {
padding: 0;
}
// footer
.page-login--content-footer {
margin-top: 10%;
padding: 1em 0;
.page-login--content-footer-locales {
padding: 0px;
margin: 0px;
margin-bottom: 15px;
font-size: 12px;
line-height: 12px;
text-align: center;
a {
color: $color-text-normal;
margin: 0 0.5em;
a {
color: $color-text-normal;
margin: 0 0.5em;
&:hover {
color: $color-text-main;
}
}
}
.page-login--content-footer-copyright {
padding: 0px;
margin: 0px;
margin-bottom: 10px;
font-size: 12px;
line-height: 12px;
text-align: center;
color: $color-text-normal;
a {
color: $color-text-normal;
}
}
.page-login--content-footer-options {
padding: 0px;
margin: 0px;
font-size: 12px;
line-height: 12px;
text-align: center;
a {
color: $color-text-normal;
margin: 0 1em;
&:hover {
color: $color-text-main;
}
}
}
.page-login--content-footer-copyright {
padding: 0px;
margin: 0px;
margin-bottom: 10px;
font-size: 12px;
line-height: 12px;
text-align: center;
color: $color-text-normal;
a {
color: $color-text-normal;
}
}
.page-login--content-footer-options {
padding: 0px;
margin: 0px;
font-size: 12px;
line-height: 12px;
text-align: center;
a {
color: $color-text-normal;
margin: 0 1em;
}
}
}
</style>

View File

@ -1,18 +1,28 @@
<template>
<div class="w3l-signinform" :style="{background: 'url('+ (loginBackground || require('./image/bg.jpg')) + ') no-repeat center'}">
<div
class="w3l-signinform"
:style="{
background:
'url(' +
(loginBackground || require('./image/bg.jpg')) +
') no-repeat center'
}"
>
<!-- container -->
<div class="wrapper">
<!-- main content -->
<div class="w3l-form-info">
<!-- logo -->
<img class="page-login--logo" :src="siteLogo" width="300"/>
<img class="page-login--logo" :src="siteLogo" width="300" />
<div class="w3_info">
<h2 style="text-align: center;">{{siteName || processTitle}}</h2>
<h2 style="text-align: center">{{ siteName || processTitle }}</h2>
<el-card shadow="always" class="card">
<el-tabs v-model="activeName">
<el-tab-pane label="账号密码登录" name="first" stretch>
<span slot="label"><span style="margin: 30px;">账号密码登录</span></span>
<br>
<span slot="label"
><span style="margin: 30px">账号密码登录</span></span
>
<br />
<el-form
ref="loginForm"
label-position="top"
@ -58,17 +68,22 @@
</template>
</el-input>
</el-form-item>
<button class="btn btn-primary btn-block" @click="submit"></button>
<button class="btn btn-primary btn-block" @click="submit">
登录
</button>
</el-form>
</el-tab-pane>
</el-tabs>
</el-card>
<!-- footer -->
<div class="footer">
<p>Copyright &copy; {{copyright}}</p>
<p>Copyright &copy; {{ copyright }}</p>
<p>
<a href="https://beian.miit.gov.cn" target="_blank">{{keepRecord}}</a> |
<a :href="helpUrl || '#'" target="_blank">帮助</a> |
<a href="https://beian.miit.gov.cn" target="_blank">{{
keepRecord
}}</a>
| <a :href="helpUrl || '#'" target="_blank">帮助</a> |
<a :href="privacyUrl || '#'" target="_blank">隐私</a> |
<a :href="clauseUrl || '#'" target="_blank">条款</a>
</p>
@ -92,23 +107,20 @@ export default {
activeName: 'first'
}
},
created () {
},
mounted () {
},
created () {},
mounted () {},
methods: {}
}
</script>
<style lang="scss" scoped>
@import './css/style.css';
@import './css/style.css';
.copyrights {
text-indent: -9999px;
height: 0;
line-height: 0;
font-size: 0;
overflow: hidden;
}
.copyrights {
text-indent: -9999px;
height: 0;
line-height: 0;
font-size: 0;
overflow: hidden;
}
</style>

View File

@ -55,3 +55,11 @@ export function ResetPwd (obj) {
data: obj
})
}
export function ResetPwd2Default (obj) {
return request({
url: urlPrefix + 'reset_to_default_password/' + obj.id + '/',
method: 'put',
data: obj
})
}

View File

@ -12,7 +12,7 @@ export const crudOptions = (vm) => {
rowKey: true // 必须设置true or false
},
rowHandle: {
width: 230,
width: 270,
fixed: 'right',
view: {
thin: true,
@ -37,16 +37,27 @@ export const crudOptions = (vm) => {
},
custom: [
{
thin: true,
text: '',
size: 'small',
type: 'warning',
icon: 'el-icon-refresh-left',
show () {
return vm.hasPermissions('ResetPassword')
},
emit: 'resetPassword'
},
{
show () {
return vm.hasPermissions('DefaultPassword')
},
disabled () {
return !vm.hasPermissions('ResetPassword')
return !vm.hasPermissions('DefaultPassword')
},
text: '重置密码',
type: 'warning',
size: 'small',
emit: 'resetPassword'
emit: 'defaultPassword'
}
]
},

View File

@ -5,6 +5,7 @@
v-bind="_crudProps"
v-on="_crudListeners"
@resetPassword="resetPassword"
@defaultPassword="defaultPassword"
>
<div slot="header">
<crud-search
@ -131,11 +132,11 @@ export default {
delRequest (row) {
return api.DelObj(row.id)
},
// resetPassword (scope) {
// api.ResetPwd(scope.row).then((res) => {
// this.$message.success('')
// })
// }
defaultPassword (scope) {
api.ResetPwd2Default(scope.row).then((res) => {
this.$message.success('密码重置成功')
})
},
//
resetPassword ({ row }) {
this.dialogFormVisible = true