优化用户部门查询逻辑
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from .admin_user import UserOutSchema
|
|
||||||
from .admin_role import RoleOutSchema
|
from .admin_role import RoleOutSchema
|
||||||
from .admin_power import PowerOutSchema, PowerOutSchema2
|
from .admin_power import PowerOutSchema, PowerOutSchema2
|
||||||
from .admin_dict import DictDataOutSchema, DictTypeOutSchema
|
from .admin_dict import DictDataOutSchema, DictTypeOutSchema
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
from applications.extensions import ma
|
|
||||||
from marshmallow import fields
|
|
||||||
from applications.models import Dept
|
|
||||||
|
|
||||||
|
|
||||||
# 用户models的序列化类
|
|
||||||
class UserOutSchema(ma.Schema):
|
|
||||||
id = fields.Integer()
|
|
||||||
username = fields.Str()
|
|
||||||
realname = fields.Str()
|
|
||||||
enable = fields.Integer()
|
|
||||||
create_at = fields.DateTime()
|
|
||||||
update_at = fields.DateTime()
|
|
||||||
dept = fields.Method("get_dept")
|
|
||||||
|
|
||||||
def get_dept(self, obj):
|
|
||||||
if obj.dept_id != None:
|
|
||||||
return Dept.query.filter_by(id=obj.dept_id).first().dept_name
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
@@ -3,15 +3,14 @@ from flask_login import login_required, current_user
|
|||||||
from sqlalchemy import desc
|
from sqlalchemy import desc
|
||||||
|
|
||||||
from applications.common import curd
|
from applications.common import curd
|
||||||
from applications.common.curd import model_to_dicts, enable_status, disable_status
|
from applications.common.curd import enable_status, disable_status
|
||||||
from applications.common.helper import ModelFilter
|
from applications.common.helper import ModelFilter
|
||||||
from applications.common.utils.http import table_api, fail_api, success_api
|
from applications.common.utils.http import table_api, fail_api, success_api
|
||||||
from applications.common.utils.rights import authorize
|
from applications.common.utils.rights import authorize
|
||||||
from applications.common.utils.validate import xss_escape
|
from applications.common.utils.validate import xss_escape
|
||||||
from applications.extensions import db
|
from applications.extensions import db
|
||||||
from applications.models import Role
|
from applications.models import Role, Dept
|
||||||
from applications.models import User, AdminLog
|
from applications.models import User, AdminLog
|
||||||
from applications.schemas import UserOutSchema
|
|
||||||
|
|
||||||
admin_user = Blueprint('adminUser', __name__, url_prefix='/admin/user')
|
admin_user = Blueprint('adminUser', __name__, url_prefix='/admin/user')
|
||||||
|
|
||||||
@@ -39,12 +38,16 @@ def data():
|
|||||||
mf.contains(field_name="username", value=username)
|
mf.contains(field_name="username", value=username)
|
||||||
if dept_id:
|
if dept_id:
|
||||||
mf.exact(field_name="dept_id", value=dept_id)
|
mf.exact(field_name="dept_id", value=dept_id)
|
||||||
# orm查询
|
data, count = db.session.query(
|
||||||
# 使用分页获取data需要.items
|
User.id,
|
||||||
user = User.query.filter(mf.get_filter(model=User)).layui_paginate()
|
User.username,
|
||||||
count = user.total
|
User.realname,
|
||||||
# 返回api
|
User.enable,
|
||||||
return table_api(data=model_to_dicts(schema=UserOutSchema, data=user.items), count=count)
|
User.create_at,
|
||||||
|
User.update_at,
|
||||||
|
Dept.dept_name
|
||||||
|
).filter(mf.get_filter(model=User)).filter(User.dept_id==Dept.id).layui_paginate_db_json()
|
||||||
|
return table_api(data=data,count=count)
|
||||||
|
|
||||||
|
|
||||||
# 用户增加
|
# 用户增加
|
||||||
|
|||||||
@@ -121,7 +121,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{ title: '姓名', field: 'realname', align: 'center', width: 110 },
|
{ title: '姓名', field: 'realname', align: 'center', width: 110 },
|
||||||
{ title: '账号', field: 'username', align: 'center' },
|
{ title: '账号', field: 'username', align: 'center' },
|
||||||
{ title: '部门', field: 'dept', align: 'center' },
|
{ title: '部门', field: 'dept_name', align: 'center' },
|
||||||
{ title: '启用', field: 'enable', align: 'center', templet: '#user-enable', width: 120 },
|
{ title: '启用', field: 'enable', align: 'center', templet: '#user-enable', width: 120 },
|
||||||
{ title: '注册时间', field: 'create_at', templet: '#user-createTime', align: 'center' },
|
{ title: '注册时间', field: 'create_at', templet: '#user-createTime', align: 'center' },
|
||||||
{ title: '更新时间', field: 'update_at', templet: '#user-updateTime', align: 'center' },
|
{ title: '更新时间', field: 'update_at', templet: '#user-updateTime', align: 'center' },
|
||||||
|
|||||||
Reference in New Issue
Block a user