fix: 🐛 修复添加用户bug

This commit is contained in:
H0nGzA1
2023-04-12 00:25:36 +08:00
parent 38494edea5
commit 0668cb087f
3 changed files with 43 additions and 42 deletions

View File

@@ -41,6 +41,7 @@ class UserSerializer(CustomModelSerializer):
exclude = ["password"] exclude = ["password"]
extra_kwargs = { extra_kwargs = {
"post": {"required": False}, "post": {"required": False},
"mobile": {"required": False},
} }
def get_dept_name_all(self, instance): def get_dept_name_all(self, instance):
@@ -60,9 +61,6 @@ class UserSerializer(CustomModelSerializer):
return serializer.data return serializer.data
class UserCreateSerializer(CustomModelSerializer): class UserCreateSerializer(CustomModelSerializer):
""" """
用户新增-序列化器 用户新增-序列化器
@@ -82,10 +80,10 @@ class UserCreateSerializer(CustomModelSerializer):
""" """
对密码进行验证 对密码进行验证
""" """
password = self.initial_data.get("password") md5 = hashlib.md5()
if password: md5.update(value.encode('utf-8'))
return make_password(value) md5_password = md5.hexdigest()
return value return make_password(md5_password)
def save(self, **kwargs): def save(self, **kwargs):
data = super().save(**kwargs) data = super().save(**kwargs)
@@ -100,6 +98,7 @@ class UserCreateSerializer(CustomModelSerializer):
read_only_fields = ["id"] read_only_fields = ["id"]
extra_kwargs = { extra_kwargs = {
"post": {"required": False}, "post": {"required": False},
"mobile": {"required": False},
} }
@@ -114,14 +113,15 @@ class UserUpdateSerializer(CustomModelSerializer):
CustomUniqueValidator(queryset=Users.objects.all(), message="账号必须唯一") CustomUniqueValidator(queryset=Users.objects.all(), message="账号必须唯一")
], ],
) )
# password = serializers.CharField(required=False, allow_blank=True) # password = serializers.CharField(required=False, allow_blank=True)
mobile = serializers.CharField( # mobile = serializers.CharField(
max_length=50, # max_length=50,
validators=[ # validators=[
CustomUniqueValidator(queryset=Users.objects.all(), message="手机号必须唯一") # CustomUniqueValidator(queryset=Users.objects.all(), message="手机号必须唯一")
], # ],
allow_blank=True # allow_blank=True
) # )
def save(self, **kwargs): def save(self, **kwargs):
data = super().save(**kwargs) data = super().save(**kwargs)
@@ -136,6 +136,7 @@ class UserUpdateSerializer(CustomModelSerializer):
fields = "__all__" fields = "__all__"
extra_kwargs = { extra_kwargs = {
"post": {"required": False, "read_only": True}, "post": {"required": False, "read_only": True},
"mobile": {"required": False},
} }
@@ -159,6 +160,7 @@ class UserInfoUpdateSerializer(CustomModelSerializer):
fields = ['email', 'mobile', 'avatar', 'name', 'gender'] fields = ['email', 'mobile', 'avatar', 'name', 'gender']
extra_kwargs = { extra_kwargs = {
"post": {"required": False, "read_only": True}, "post": {"required": False, "read_only": True},
"mobile": {"required": False},
} }

View File

@@ -20,8 +20,7 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
}; };
//权限判定 //权限判定
const hasPermissions = inject("$hasPermissions") const hasPermissions = inject('$hasPermissions');
return { return {
crudOptions: { crudOptions: {
@@ -41,17 +40,17 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
edit: { edit: {
iconRight: 'Edit', iconRight: 'Edit',
type: 'text', type: 'text',
show:hasPermissions('dictonary:Update') show: hasPermissions('dictionary:Update'),
}, },
remove: { remove: {
iconRight: 'Delete', iconRight: 'Delete',
type: 'text', type: 'text',
show:hasPermissions('dictonary:Delete') show: hasPermissions('dictionary:Delete'),
}, },
custom: { custom: {
text: '字典配置', text: '字典配置',
type: 'text', type: 'text',
show:hasPermissions('dictonary:Update'), show: hasPermissions('dictionary:Update'),
tooltip: { tooltip: {
placement: 'top', placement: 'top',
content: '字典配置', content: '字典配置',

View File

@@ -3,7 +3,7 @@ import { dict, PageQuery, AddReq, DelReq, EditReq, CrudExpose, CrudOptions, comp
import { request } from '/@/utils/service'; import { request } from '/@/utils/service';
import { dictionary } from '/@/utils/dictionary'; import { dictionary } from '/@/utils/dictionary';
import { successMessage } from '/@/utils/message'; import { successMessage } from '/@/utils/message';
import {inject} from "vue"; import { inject } from 'vue';
interface CreateCrudOptionsTypes { interface CreateCrudOptionsTypes {
crudOptions: CrudOptions; crudOptions: CrudOptions;
} }
@@ -24,7 +24,7 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp
}; };
//权限判定 //权限判定
const hasPermissions = inject("$hasPermissions") const hasPermissions = inject('$hasPermissions');
return { return {
crudOptions: { crudOptions: {
@@ -45,12 +45,12 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp
edit: { edit: {
iconRight: 'Edit', iconRight: 'Edit',
type: 'text', type: 'text',
show:hasPermissions('user:Update') show: hasPermissions('user:Update'),
}, },
remove: { remove: {
iconRight: 'Delete', iconRight: 'Delete',
type: 'text', type: 'text',
show:hasPermissions('user:Delete') show: hasPermissions('user:Delete'),
}, },
}, },
}, },
@@ -72,7 +72,7 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp
}, },
type: 'input', type: 'input',
column: { column: {
minWidth: 100 //最小列宽 minWidth: 100, //最小列宽
}, },
form: { form: {
rules: [ rules: [
@@ -124,7 +124,7 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp
}, },
type: 'input', type: 'input',
column: { column: {
minWidth: 100 //最小列宽 minWidth: 100, //最小列宽
}, },
form: { form: {
rules: [ rules: [
@@ -160,7 +160,7 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp
}, },
}), }),
column: { column: {
minWidth: 150 //最小列宽 minWidth: 150, //最小列宽
}, },
form: { form: {
rules: [ rules: [
@@ -206,7 +206,7 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp
}, },
}), }),
column: { column: {
minWidth: 100 //最小列宽 minWidth: 100, //最小列宽
}, },
form: { form: {
rules: [ rules: [
@@ -230,7 +230,7 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp
}, },
type: 'input', type: 'input',
column: { column: {
minWidth: 120 //最小列宽 minWidth: 120, //最小列宽
}, },
form: { form: {
rules: [ rules: [
@@ -269,7 +269,7 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp
}, },
gender: { gender: {
title: '性别', title: '性别',
type: 'dict-radio', type: 'dict-select',
dict: dict({ dict: dict({
data: dictionary('gender'), data: dictionary('gender'),
}), }),
@@ -291,7 +291,7 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp
data: dictionary('user_type'), data: dictionary('user_type'),
}), }),
column: { column: {
minWidth: 100 //最小列宽 minWidth: 100, //最小列宽
}, },
form: { form: {
show: false, show: false,
@@ -302,7 +302,7 @@ export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExp
}, },
}, },
is_active: { is_active: {
title: '状态', title: '锁定',
search: { search: {
show: true, show: true,
}, },