去除首页面,优化命名,优化schema
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
from applications.view.admin import register_admin_views
|
||||
from applications.view.index import register_index_views
|
||||
from applications.view.passport import register_passport_views
|
||||
from applications.view.rights import register_rights_view
|
||||
from applications.view.department import register_dept_views
|
||||
from applications.view.system import register_system_bps
|
||||
from applications.view.plugin import register_plugin_views
|
||||
|
||||
def init_view(app):
|
||||
register_admin_views(app)
|
||||
register_index_views(app)
|
||||
register_rights_view(app)
|
||||
register_passport_views(app)
|
||||
register_dept_views(app)
|
||||
|
||||
def init_bps(app):
|
||||
register_system_bps(app)
|
||||
register_plugin_views(app)
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
from flask import Flask
|
||||
|
||||
from applications.view.admin.admin_log import admin_log
|
||||
from applications.view.admin.dict import admin_dict
|
||||
from applications.view.admin.index import admin_bp
|
||||
from applications.view.admin.file import admin_file
|
||||
from applications.view.admin.power import admin_power
|
||||
from applications.view.admin.role import admin_role
|
||||
from applications.view.admin.user import admin_user
|
||||
from applications.view.admin.monitor import admin_monitor_bp
|
||||
from applications.view.admin.mail import admin_mail
|
||||
|
||||
|
||||
def register_admin_views(app: Flask):
|
||||
app.register_blueprint(admin_bp)
|
||||
app.register_blueprint(admin_user)
|
||||
app.register_blueprint(admin_file)
|
||||
app.register_blueprint(admin_monitor_bp)
|
||||
app.register_blueprint(admin_log)
|
||||
app.register_blueprint(admin_power)
|
||||
app.register_blueprint(admin_role)
|
||||
app.register_blueprint(admin_dict)
|
||||
app.register_blueprint(admin_mail)
|
||||
@@ -1,19 +0,0 @@
|
||||
from flask import Blueprint, render_template
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
admin_bp = Blueprint('admin', __name__, url_prefix='/admin')
|
||||
|
||||
|
||||
# 首页
|
||||
@admin_bp.get('/')
|
||||
@login_required
|
||||
def index():
|
||||
user = current_user
|
||||
return render_template('admin/index.html', user=user)
|
||||
|
||||
|
||||
# 控制台页面
|
||||
@admin_bp.get('/welcome')
|
||||
@login_required
|
||||
def welcome():
|
||||
return render_template('admin/console/console.html')
|
||||
@@ -1,12 +0,0 @@
|
||||
from applications.view.index.index import index_bp
|
||||
|
||||
from . import index
|
||||
|
||||
|
||||
def register_index_views(app):
|
||||
"""
|
||||
初始化蓝图
|
||||
|
||||
"""
|
||||
|
||||
app.register_blueprint(index_bp)
|
||||
@@ -1,8 +0,0 @@
|
||||
from flask import render_template, Blueprint
|
||||
|
||||
index_bp = Blueprint('Index', __name__, url_prefix='/')
|
||||
|
||||
|
||||
@index_bp.route('/')
|
||||
def index():
|
||||
return render_template('index/index.html')
|
||||
@@ -17,7 +17,7 @@ def configs():
|
||||
# 网站名称
|
||||
"title": current_app.config.get("SYSTEM_NAME"),
|
||||
# 网站图标
|
||||
"image": "/static/admin/admin/images/logo.png"
|
||||
"image": "/static/system/system/images/logo.png"
|
||||
# 菜单配置
|
||||
}, menu={
|
||||
# 菜单数据来源
|
||||
@@ -47,7 +47,7 @@ def configs():
|
||||
# 标识 ID , 建议与菜单项中的 ID 一致
|
||||
"id": "10",
|
||||
# 页面地址
|
||||
"href": "/admin/welcome",
|
||||
"href": "/system/welcome",
|
||||
# 标题
|
||||
"title": "首页"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
from flask import Flask, Blueprint
|
||||
|
||||
from applications.view.system.dict import bp as dict_bp
|
||||
from applications.view.system.file import bp as file_bp
|
||||
from applications.view.system.index import bp as index_bp
|
||||
from applications.view.system.log import bp as log_bp
|
||||
from applications.view.system.mail import bp as mail_bp
|
||||
from applications.view.system.monitor import bp as monitor_bp
|
||||
from applications.view.system.passport import bp as passport_bp
|
||||
from applications.view.system.power import bp as power_bp
|
||||
from applications.view.system.rights import bp as right_bp
|
||||
from applications.view.system.role import bp as role_bp
|
||||
from applications.view.system.user import bp as user_bp
|
||||
from applications.view.system.dept import bp as dept_bp
|
||||
|
||||
# 创建sys
|
||||
system_bp = Blueprint('system', __name__, url_prefix='/system')
|
||||
|
||||
|
||||
def register_system_bps(app: Flask):
|
||||
# 在admin_bp下注册子蓝图
|
||||
system_bp.register_blueprint(user_bp)
|
||||
system_bp.register_blueprint(file_bp)
|
||||
system_bp.register_blueprint(monitor_bp)
|
||||
system_bp.register_blueprint(log_bp)
|
||||
system_bp.register_blueprint(power_bp)
|
||||
system_bp.register_blueprint(role_bp)
|
||||
system_bp.register_blueprint(dict_bp)
|
||||
system_bp.register_blueprint(mail_bp)
|
||||
system_bp.register_blueprint(passport_bp)
|
||||
system_bp.register_blueprint(right_bp)
|
||||
system_bp.register_blueprint(dept_bp)
|
||||
app.register_blueprint(index_bp)
|
||||
app.register_blueprint(system_bp)
|
||||
@@ -7,43 +7,38 @@ from applications.common.utils.rights import authorize
|
||||
from applications.common.utils.validate import str_escape
|
||||
from applications.extensions import db
|
||||
from applications.models import Dept, User
|
||||
from applications.schemas import DeptOutSchema
|
||||
from applications.schemas import DeptSchema
|
||||
|
||||
dept_bp = Blueprint('dept', __name__, url_prefix='/dept')
|
||||
bp = Blueprint('dept', __name__, url_prefix='/dept')
|
||||
|
||||
|
||||
def register_dept_views(app):
|
||||
app.register_blueprint(dept_bp)
|
||||
|
||||
|
||||
@dept_bp.get('/')
|
||||
@authorize("admin:dept:main", log=True)
|
||||
@bp.get('/')
|
||||
@authorize("system:dept:main", log=True)
|
||||
def main():
|
||||
return render_template('admin/dept/main.html')
|
||||
return render_template('system/dept/main.html')
|
||||
|
||||
|
||||
@dept_bp.post('/data')
|
||||
@authorize("admin:dept:main", log=True)
|
||||
@bp.post('/data')
|
||||
@authorize("system:dept:main", log=True)
|
||||
def data():
|
||||
dept = Dept.query.order_by(Dept.sort).all()
|
||||
power_data = curd.model_to_dicts(schema=DeptOutSchema, data=dept)
|
||||
data = Dept.query.order_by(Dept.sort).all()
|
||||
res = {
|
||||
"data": power_data
|
||||
"data": DeptSchema(many=True).dump(data)
|
||||
}
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
@dept_bp.get('/add')
|
||||
@authorize("admin:dept:add", log=True)
|
||||
@bp.get('/add')
|
||||
@authorize("system:dept:add", log=True)
|
||||
def add():
|
||||
return render_template('admin/dept/add.html')
|
||||
return render_template('system/dept/add.html')
|
||||
|
||||
|
||||
@dept_bp.get('/tree')
|
||||
@authorize("admin:dept:main", log=True)
|
||||
@bp.get('/tree')
|
||||
@authorize("system:dept:main", log=True)
|
||||
def tree():
|
||||
dept = Dept.query.order_by(Dept.sort).all()
|
||||
power_data = curd.model_to_dicts(schema=DeptOutSchema, data=dept)
|
||||
power_data = curd.model_to_dicts(schema=DeptSchema, data=dept)
|
||||
res = {
|
||||
"status": {"code": 200, "message": "默认"},
|
||||
"data": power_data
|
||||
@@ -52,8 +47,8 @@ def tree():
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
@dept_bp.post('/save')
|
||||
@authorize("admin:dept:add", log=True)
|
||||
@bp.post('/save')
|
||||
@authorize("system:dept:add", log=True)
|
||||
def save():
|
||||
req_json = request.get_json(force=True)
|
||||
dept = Dept(
|
||||
@@ -71,17 +66,17 @@ def save():
|
||||
return success_api(msg="成功")
|
||||
|
||||
|
||||
@dept_bp.get('/edit')
|
||||
@authorize("admin:dept:edit", log=True)
|
||||
@bp.get('/edit')
|
||||
@authorize("system:dept:edit", log=True)
|
||||
def edit():
|
||||
_id = request.args.get("deptId")
|
||||
dept = curd.get_one_by_id(model=Dept, id=_id)
|
||||
return render_template('admin/dept/edit.html', dept=dept)
|
||||
return render_template('system/dept/edit.html', dept=dept)
|
||||
|
||||
|
||||
# 启用
|
||||
@dept_bp.put('/enable')
|
||||
@authorize("admin:dept:edit", log=True)
|
||||
@bp.put('/enable')
|
||||
@authorize("system:dept:edit", log=True)
|
||||
def enable():
|
||||
id = request.get_json(force=True).get('deptId')
|
||||
if id:
|
||||
@@ -95,8 +90,8 @@ def enable():
|
||||
|
||||
|
||||
# 禁用
|
||||
@dept_bp.put('/disable')
|
||||
@authorize("admin:dept:edit", log=True)
|
||||
@bp.put('/disable')
|
||||
@authorize("system:dept:edit", log=True)
|
||||
def dis_enable():
|
||||
id = request.get_json(force=True).get('deptId')
|
||||
if id:
|
||||
@@ -109,8 +104,8 @@ def dis_enable():
|
||||
return fail_api(msg="数据错误")
|
||||
|
||||
|
||||
@dept_bp.put('/update')
|
||||
@authorize("admin:dept:edit", log=True)
|
||||
@bp.put('/update')
|
||||
@authorize("system:dept:edit", log=True)
|
||||
def update():
|
||||
json = request.get_json(force=True)
|
||||
id = json.get("deptId"),
|
||||
@@ -130,8 +125,8 @@ def update():
|
||||
return success_api(msg="更新成功")
|
||||
|
||||
|
||||
@dept_bp.delete('/remove/<int:_id>')
|
||||
@authorize("admin:dept:remove", log=True)
|
||||
@bp.delete('/remove/<int:_id>')
|
||||
@authorize("system:dept:remove", log=True)
|
||||
def remove(_id):
|
||||
d = Dept.query.filter_by(id=_id).delete()
|
||||
if not d:
|
||||
@@ -9,18 +9,18 @@ from applications.extensions import db
|
||||
from applications.models import DictType, DictData
|
||||
from applications.schemas import DictTypeOutSchema, DictDataOutSchema
|
||||
|
||||
admin_dict = Blueprint('adminDict', __name__, url_prefix='/admin/dict')
|
||||
bp = Blueprint('dict', __name__, url_prefix='/dict')
|
||||
|
||||
|
||||
# 数据字典
|
||||
@admin_dict.get('/')
|
||||
@authorize("admin:dict:main")
|
||||
@bp.get('/')
|
||||
@authorize("system:dict:main")
|
||||
def main():
|
||||
return render_template('admin/dict/main.html')
|
||||
return render_template('system/dict/main.html')
|
||||
|
||||
|
||||
@admin_dict.get('/dictType/data')
|
||||
@authorize("admin:dict:main")
|
||||
@bp.get('/dictType/data')
|
||||
@authorize("system:dict:main")
|
||||
def dict_type_data():
|
||||
# 获取请求参数
|
||||
type_name = str_escape(request.args.get('typeName', type=str))
|
||||
@@ -36,14 +36,14 @@ def dict_type_data():
|
||||
return table_api(data=data, count=count)
|
||||
|
||||
|
||||
@admin_dict.get('/dictType/add')
|
||||
@authorize("admin:dict:add", log=True)
|
||||
@bp.get('/dictType/add')
|
||||
@authorize("system:dict:add", log=True)
|
||||
def dict_type_add():
|
||||
return render_template('admin/dict/add.html')
|
||||
return render_template('system/dict/add.html')
|
||||
|
||||
|
||||
@admin_dict.post('/dictType/save')
|
||||
@authorize("admin:dict:add", log=True)
|
||||
@bp.post('/dictType/save')
|
||||
@authorize("system:dict:add", log=True)
|
||||
def dict_type_save():
|
||||
req_json = request.get_json(force=True)
|
||||
description = str_escape(req_json.get("description"))
|
||||
@@ -59,17 +59,17 @@ def dict_type_save():
|
||||
|
||||
|
||||
# 编辑字典类型
|
||||
@admin_dict.get('/dictType/edit')
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
@bp.get('/dictType/edit')
|
||||
@authorize("system:dict:edit", log=True)
|
||||
def dict_type_edit():
|
||||
_id = request.args.get('dictTypeId', type=int)
|
||||
dict_type = DictType.query.filter_by(id=_id).first()
|
||||
return render_template('admin/dict/edit.html', dict_type=dict_type)
|
||||
return render_template('system/dict/edit.html', dict_type=dict_type)
|
||||
|
||||
|
||||
# 编辑字典类型
|
||||
@admin_dict.put('/dictType/update')
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
@bp.put('/dictType/update')
|
||||
@authorize("system:dict:edit", log=True)
|
||||
def dict_type_update():
|
||||
req_json = request.get_json(force=True)
|
||||
id = str_escape(req_json.get("id"))
|
||||
@@ -88,8 +88,8 @@ def dict_type_update():
|
||||
|
||||
|
||||
# 启用字典
|
||||
@admin_dict.put('/dictType/enable')
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
@bp.put('/dictType/enable')
|
||||
@authorize("system:dict:edit", log=True)
|
||||
def dict_type_enable():
|
||||
_id = request.get_json(force=True).get('id')
|
||||
if id:
|
||||
@@ -101,8 +101,8 @@ def dict_type_enable():
|
||||
|
||||
|
||||
# 禁用字典
|
||||
@admin_dict.put('/dictType/disable')
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
@bp.put('/dictType/disable')
|
||||
@authorize("system:dict:edit", log=True)
|
||||
def dict_type_dis_enable():
|
||||
_id = request.get_json(force=True).get('id')
|
||||
if id:
|
||||
@@ -114,8 +114,8 @@ def dict_type_dis_enable():
|
||||
|
||||
|
||||
# 删除字典类型
|
||||
@admin_dict.delete('/dictType/remove/<int:_id>')
|
||||
@authorize("admin:dict:remove", log=True)
|
||||
@bp.delete('/dictType/remove/<int:_id>')
|
||||
@authorize("system:dict:remove", log=True)
|
||||
def dict_type_delete(_id):
|
||||
res = curd.delete_one_by_id(DictType,_id)
|
||||
if not res:
|
||||
@@ -123,8 +123,8 @@ def dict_type_delete(_id):
|
||||
return success_api(msg="删除成功")
|
||||
|
||||
|
||||
@admin_dict.get('/dictData/data')
|
||||
@authorize("admin:dict:main", log=True)
|
||||
@bp.get('/dictData/data')
|
||||
@authorize("system:dict:main", log=True)
|
||||
def dict_code_data():
|
||||
type_code = str_escape(request.args.get('typeCode', type=str))
|
||||
dict_data = DictData.query.filter_by(type_code=type_code).layui_paginate()
|
||||
@@ -134,16 +134,16 @@ def dict_code_data():
|
||||
|
||||
|
||||
# 增加字典数据
|
||||
@admin_dict.get('/dictData/add')
|
||||
@authorize("admin:dict:add", log=True)
|
||||
@bp.get('/dictData/add')
|
||||
@authorize("system:dict:add", log=True)
|
||||
def dict_data_add():
|
||||
type_code = request.args.get('typeCode', type=str)
|
||||
return render_template('admin/dict/data/add.html', type_code=type_code)
|
||||
return render_template('system/dict/data/add.html', type_code=type_code)
|
||||
|
||||
|
||||
# 增加字典数据
|
||||
@admin_dict.post('/dictData/save')
|
||||
@authorize("admin:dict:add", log=True)
|
||||
@bp.post('/dictData/save')
|
||||
@authorize("system:dict:add", log=True)
|
||||
def dict_data_save():
|
||||
req_json = request.get_json(force=True)
|
||||
data_label = str_escape(req_json.get("dataLabel"))
|
||||
@@ -160,17 +160,17 @@ def dict_data_save():
|
||||
|
||||
|
||||
# 编辑字典数据
|
||||
@admin_dict.get('/dictData/edit')
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
@bp.get('/dictData/edit')
|
||||
@authorize("system:dict:edit", log=True)
|
||||
def dict_data_edit():
|
||||
_id = request.args.get('dataId', type=str)
|
||||
dict_data = curd.get_one_by_id(DictData, _id)
|
||||
return render_template('admin/dict/data/edit.html', dict_data=dict_data)
|
||||
return render_template('system/dict/data/edit.html', dict_data=dict_data)
|
||||
|
||||
|
||||
# 编辑字典数据
|
||||
@admin_dict.put('/dictData/update')
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
@bp.put('/dictData/update')
|
||||
@authorize("system:dict:edit", log=True)
|
||||
def dict_data_update():
|
||||
req_json = request.get_json(force=True)
|
||||
id = req_json.get("dataId")
|
||||
@@ -186,8 +186,8 @@ def dict_data_update():
|
||||
|
||||
|
||||
# 启用字典数据
|
||||
@admin_dict.put('/dictData/enable')
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
@bp.put('/dictData/enable')
|
||||
@authorize("system:dict:edit", log=True)
|
||||
def dict_data_enable():
|
||||
_id = request.get_json(force=True).get('dataId')
|
||||
if _id:
|
||||
@@ -199,8 +199,8 @@ def dict_data_enable():
|
||||
|
||||
|
||||
# 禁用字典数据
|
||||
@admin_dict.put('/dictData/disable')
|
||||
@authorize("admin:dict:edit", log=True)
|
||||
@bp.put('/dictData/disable')
|
||||
@authorize("system:dict:edit", log=True)
|
||||
def dict_data_disenable():
|
||||
_id = request.get_json(force=True).get('dataId')
|
||||
if _id:
|
||||
@@ -212,8 +212,8 @@ def dict_data_disenable():
|
||||
|
||||
|
||||
# 删除字典类型
|
||||
@admin_dict.delete('dictData/remove/<int:id>')
|
||||
@authorize("admin:dict:remove", log=True)
|
||||
@bp.delete('dictData/remove/<int:id>')
|
||||
@authorize("system:dict:remove", log=True)
|
||||
def dict_data_delete(id):
|
||||
res = curd.delete_one_by_id(model=DictData, id=id)
|
||||
if not res:
|
||||
@@ -7,19 +7,19 @@ from applications.extensions import db
|
||||
from applications.models import Photo
|
||||
from applications.common.utils import upload as upload_curd
|
||||
|
||||
admin_file = Blueprint('adminFile', __name__, url_prefix='/admin/file')
|
||||
bp = Blueprint('adminFile', __name__, url_prefix='/file')
|
||||
|
||||
|
||||
# 图片管理
|
||||
@admin_file.get('/')
|
||||
@authorize("admin:file:main")
|
||||
@bp.get('/')
|
||||
@authorize("system:file:main")
|
||||
def index():
|
||||
return render_template('admin/photo/photo.html')
|
||||
return render_template('system/photo/photo.html')
|
||||
|
||||
|
||||
# 图片数据
|
||||
@admin_file.get('/table')
|
||||
@authorize("admin:file:main")
|
||||
@bp.get('/table')
|
||||
@authorize("system:file:main")
|
||||
def table():
|
||||
page = request.args.get('page', type=int)
|
||||
limit = request.args.get('limit', type=int)
|
||||
@@ -28,15 +28,15 @@ def table():
|
||||
|
||||
|
||||
# 上传
|
||||
@admin_file.get('/upload')
|
||||
@authorize("admin:file:add", log=True)
|
||||
@bp.get('/upload')
|
||||
@authorize("system:file:add", log=True)
|
||||
def upload():
|
||||
return render_template('admin/photo/photo_add.html')
|
||||
return render_template('system/photo/photo_add.html')
|
||||
|
||||
|
||||
# 上传接口
|
||||
@admin_file.post('/upload')
|
||||
@authorize("admin:file:add", log=True)
|
||||
@bp.post('/upload')
|
||||
@authorize("system:file:add", log=True)
|
||||
def upload_api():
|
||||
if 'file' in request.files:
|
||||
photo = request.files['file']
|
||||
@@ -55,8 +55,8 @@ def upload_api():
|
||||
|
||||
|
||||
# 图片删除
|
||||
@admin_file.route('/delete', methods=['GET', 'POST'])
|
||||
@authorize("admin:file:delete", log=True)
|
||||
@bp.route('/delete', methods=['GET', 'POST'])
|
||||
@authorize("system:file:delete", log=True)
|
||||
def delete():
|
||||
_id = request.form.get('id')
|
||||
res = upload_curd.delete_photo_by_id(_id)
|
||||
@@ -67,8 +67,8 @@ def delete():
|
||||
|
||||
|
||||
# 图片批量删除
|
||||
@admin_file.route('/batchRemove', methods=['GET', 'POST'])
|
||||
@authorize("admin:file:delete", log=True)
|
||||
@bp.route('/batchRemove', methods=['GET', 'POST'])
|
||||
@authorize("system:file:delete", log=True)
|
||||
def batch_remove():
|
||||
ids = request.form.getlist('ids[]')
|
||||
photo_name = Photo.query.filter(Photo.id.in_(ids)).all()
|
||||
@@ -0,0 +1,14 @@
|
||||
from flask import Blueprint, render_template
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
bp = Blueprint('index', __name__, url_prefix='/')
|
||||
|
||||
|
||||
# 首页
|
||||
@bp.get('/')
|
||||
@login_required
|
||||
def index():
|
||||
user = current_user
|
||||
return render_template('system/index.html', user=user)
|
||||
|
||||
|
||||
@@ -6,21 +6,19 @@ from applications.models import AdminLog
|
||||
from applications.schemas import LogOutSchema
|
||||
from applications.common.curd import model_to_dicts
|
||||
|
||||
admin_log = Blueprint('adminLog', __name__, url_prefix='/admin/log')
|
||||
bp = Blueprint('log', __name__, url_prefix='/log')
|
||||
|
||||
|
||||
# 日志管理
|
||||
@admin_log.get('/')
|
||||
@authorize("admin:log:main")
|
||||
@bp.get('/')
|
||||
@authorize("system:log:main")
|
||||
def index():
|
||||
from markupsafe import escape
|
||||
escape
|
||||
return render_template('admin/admin_log/main.html')
|
||||
return render_template('system/admin_log/main.html')
|
||||
|
||||
|
||||
# 登录日志
|
||||
@admin_log.get('/loginLog')
|
||||
@authorize("admin:log:main")
|
||||
@bp.get('/loginLog')
|
||||
@authorize("system:log:main")
|
||||
def login_log():
|
||||
# orm查询
|
||||
# 使用分页获取data需要.items
|
||||
@@ -30,8 +28,8 @@ def login_log():
|
||||
|
||||
|
||||
# 操作日志
|
||||
@admin_log.get('/operateLog')
|
||||
@authorize("admin:log:main")
|
||||
@bp.get('/operateLog')
|
||||
@authorize("system:log:main")
|
||||
def operate_log():
|
||||
# orm查询
|
||||
# 使用分页获取data需要.items
|
||||
@@ -10,19 +10,19 @@ from applications.extensions import db, flask_mail
|
||||
from applications.models import Mail
|
||||
from applications.schemas import MailOutSchema
|
||||
|
||||
admin_mail = Blueprint('adminMail', __name__, url_prefix='/admin/mail')
|
||||
bp = Blueprint('adminMail', __name__, url_prefix='/mail')
|
||||
|
||||
|
||||
# 用户管理
|
||||
@admin_mail.get('/')
|
||||
@authorize("admin:mail:main")
|
||||
@bp.get('/')
|
||||
@authorize("system:mail:main")
|
||||
def main():
|
||||
return render_template('admin/mail/main.html')
|
||||
return render_template('system/mail/main.html')
|
||||
|
||||
|
||||
# 用户分页查询
|
||||
@admin_mail.get('/data')
|
||||
@authorize("admin:mail:main")
|
||||
@bp.get('/data')
|
||||
@authorize("system:mail:main")
|
||||
def data():
|
||||
# 获取请求参数
|
||||
receiver = str_escape(request.args.get("receiver"))
|
||||
@@ -45,14 +45,14 @@ def data():
|
||||
|
||||
|
||||
# 用户增加
|
||||
@admin_mail.get('/add')
|
||||
@authorize("admin:mail:add", log=True)
|
||||
@bp.get('/add')
|
||||
@authorize("system:mail:add", log=True)
|
||||
def add():
|
||||
return render_template('admin/mail/add.html')
|
||||
return render_template('system/mail/add.html')
|
||||
|
||||
|
||||
@admin_mail.post('/save')
|
||||
@authorize("admin:mail:add", log=True)
|
||||
@bp.post('/save')
|
||||
@authorize("system:mail:add", log=True)
|
||||
def save():
|
||||
req_json = request.get_json(force=True)
|
||||
receiver = str_escape(req_json.get("receiver"))
|
||||
@@ -75,8 +75,8 @@ def save():
|
||||
|
||||
|
||||
# 删除用户
|
||||
@admin_mail.delete('/remove/<int:id>')
|
||||
@authorize("admin:mail:remove", log=True)
|
||||
@bp.delete('/remove/<int:id>')
|
||||
@authorize("system:mail:remove", log=True)
|
||||
def delete(id):
|
||||
res = Mail.query.filter_by(id=id).delete()
|
||||
if not res:
|
||||
@@ -86,8 +86,8 @@ def delete(id):
|
||||
|
||||
|
||||
# 批量删除
|
||||
@admin_mail.delete('/batchRemove')
|
||||
@authorize("admin:mail:remove", log=True)
|
||||
@bp.delete('/batchRemove')
|
||||
@authorize("system:mail:remove", log=True)
|
||||
def batch_remove():
|
||||
ids = request.form.getlist('ids[]')
|
||||
for id in ids:
|
||||
@@ -8,12 +8,12 @@ from datetime import datetime
|
||||
from flask import Blueprint, render_template, jsonify
|
||||
from applications.common.utils.rights import authorize
|
||||
|
||||
admin_monitor_bp = Blueprint('adminMonitor', __name__, url_prefix='/admin/monitor')
|
||||
bp = Blueprint('adminMonitor', __name__, url_prefix='/monitor')
|
||||
|
||||
|
||||
# 系统监控
|
||||
@admin_monitor_bp.get('/')
|
||||
@authorize("admin:monitor:main")
|
||||
@bp.get('/')
|
||||
@authorize("system:monitor:main")
|
||||
def main():
|
||||
# 主机名称
|
||||
hostname = platform.node()
|
||||
@@ -58,7 +58,7 @@ def main():
|
||||
|
||||
# 当前时间
|
||||
time_now = time.strftime('%H:%M:%S ', time.localtime(time.time()))
|
||||
return render_template('admin/monitor.html',
|
||||
return render_template('system/monitor.html',
|
||||
hostname=hostname,
|
||||
system_version=system_version,
|
||||
python_version=python_version,
|
||||
@@ -77,8 +77,8 @@ def main():
|
||||
|
||||
|
||||
# 图表 api
|
||||
@admin_monitor_bp.get('/polling')
|
||||
@authorize("admin:monitor:main")
|
||||
@bp.get('/polling')
|
||||
@authorize("system:monitor:main")
|
||||
def ajax_polling():
|
||||
# 获取cpu使用率
|
||||
cpus_percent = psutil.cpu_percent(interval=0.1, percpu=False) # percpu 获取主使用率
|
||||
@@ -88,11 +88,12 @@ def ajax_polling():
|
||||
time_now = time.strftime('%H:%M:%S ', time.localtime(time.time()))
|
||||
return jsonify(cups_percent=cpus_percent, memory_used=memory_usage, time_now=time_now)
|
||||
|
||||
|
||||
# 关闭程序
|
||||
@admin_monitor_bp.get('/kill')
|
||||
@authorize("admin:monitor:main")
|
||||
@bp.get('/kill')
|
||||
@authorize("system:monitor:main")
|
||||
def kill():
|
||||
for proc in psutil.process_iter():
|
||||
if proc.pid == os.getpid():
|
||||
proc.kill()
|
||||
sys.exit(1)
|
||||
sys.exit(1)
|
||||
@@ -6,15 +6,13 @@ from applications.common.admin_log import login_log
|
||||
from applications.common.utils.http import fail_api, success_api
|
||||
from applications.models import User
|
||||
|
||||
passport_bp = Blueprint('passport', __name__, url_prefix='/passport')
|
||||
bp = Blueprint('passport', __name__, url_prefix='/passport')
|
||||
|
||||
|
||||
def register_passport_views(app):
|
||||
app.register_blueprint(passport_bp)
|
||||
|
||||
|
||||
# 获取验证码
|
||||
@passport_bp.get('/getCaptcha')
|
||||
@bp.get('/getCaptcha')
|
||||
def get_captcha():
|
||||
resp, code = index_curd.get_captcha()
|
||||
session["code"] = code
|
||||
@@ -22,15 +20,15 @@ def get_captcha():
|
||||
|
||||
|
||||
# 登录
|
||||
@passport_bp.get('/login')
|
||||
@bp.get('/login')
|
||||
def login():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for('admin.index'))
|
||||
return render_template('admin/login.html')
|
||||
return redirect(url_for('system.index'))
|
||||
return render_template('system/login.html')
|
||||
|
||||
|
||||
# 登录
|
||||
@passport_bp.post('/login')
|
||||
@bp.post('/login')
|
||||
def login_post():
|
||||
req = request.form
|
||||
username = req.get('username')
|
||||
@@ -83,7 +81,7 @@ def login_post():
|
||||
|
||||
|
||||
# 退出登录
|
||||
@passport_bp.post('/logout')
|
||||
@bp.post('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
@@ -7,34 +7,35 @@ from applications.common.utils.validate import str_escape
|
||||
from applications.extensions import db
|
||||
from applications.models import Power
|
||||
from applications.schemas import PowerOutSchema2
|
||||
from applications.schemas.admin_power import PowerSchema
|
||||
|
||||
admin_power = Blueprint('adminPower', __name__, url_prefix='/admin/power')
|
||||
bp = Blueprint('power', __name__, url_prefix='/power')
|
||||
|
||||
|
||||
@admin_power.get('/')
|
||||
@authorize("admin:power:main")
|
||||
@bp.get('/')
|
||||
@authorize("system:power:main")
|
||||
def index():
|
||||
return render_template('admin/power/main.html')
|
||||
return render_template('system/power/main.html')
|
||||
|
||||
|
||||
@admin_power.post('/data')
|
||||
@authorize("admin:power:main")
|
||||
@bp.post('/data')
|
||||
@authorize("system:power:main")
|
||||
def data():
|
||||
power = Power.query.all()
|
||||
res = {
|
||||
"data": curd.model_to_dicts(schema=PowerOutSchema2, data=power)
|
||||
"data": PowerSchema(many=True).dump(power)
|
||||
}
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
@admin_power.get('/add')
|
||||
@authorize("admin:power:add", log=True)
|
||||
@bp.get('/add')
|
||||
@authorize("system:power:add", log=True)
|
||||
def add():
|
||||
return render_template('admin/power/add.html')
|
||||
return render_template('system/power/add.html')
|
||||
|
||||
|
||||
@admin_power.get('/selectParent')
|
||||
@authorize("admin:power:main", log=True)
|
||||
@bp.get('/selectParent')
|
||||
@authorize("system:power:main", log=True)
|
||||
def select_parent():
|
||||
power = Power.query.all()
|
||||
res = curd.model_to_dicts(schema=PowerOutSchema2, data=power)
|
||||
@@ -48,8 +49,8 @@ def select_parent():
|
||||
|
||||
|
||||
# 增加
|
||||
@admin_power.post('/save')
|
||||
@authorize("admin:power:add", log=True)
|
||||
@bp.post('/save')
|
||||
@authorize("system:power:add", log=True)
|
||||
def save():
|
||||
req = request.get_json(force=True)
|
||||
icon = str_escape(req.get("icon"))
|
||||
@@ -77,8 +78,8 @@ def save():
|
||||
|
||||
|
||||
# 权限编辑
|
||||
@admin_power.get('/edit/<int:_id>')
|
||||
@authorize("admin:power:edit", log=True)
|
||||
@bp.get('/edit/<int:_id>')
|
||||
@authorize("system:power:edit", log=True)
|
||||
def edit(_id):
|
||||
power = curd.get_one_by_id(Power, _id)
|
||||
icon = str(power.icon).split()
|
||||
@@ -86,12 +87,12 @@ def edit(_id):
|
||||
icon = icon[1]
|
||||
else:
|
||||
icon = None
|
||||
return render_template('admin/power/edit.html', power=power, icon=icon)
|
||||
return render_template('system/power/edit.html', power=power, icon=icon)
|
||||
|
||||
|
||||
# 权限更新
|
||||
@admin_power.put('/update')
|
||||
@authorize("admin:power:edit", log=True)
|
||||
@bp.put('/update')
|
||||
@authorize("system:power:edit", log=True)
|
||||
def update():
|
||||
req_json = request.get_json(force=True)
|
||||
id = request.get_json(force=True).get("powerId")
|
||||
@@ -113,8 +114,8 @@ def update():
|
||||
|
||||
|
||||
# 启用权限
|
||||
@admin_power.put('/enable')
|
||||
@authorize("admin:power:edit", log=True)
|
||||
@bp.put('/enable')
|
||||
@authorize("system:power:edit", log=True)
|
||||
def enable():
|
||||
_id = request.get_json(force=True).get('powerId')
|
||||
if id:
|
||||
@@ -126,8 +127,8 @@ def enable():
|
||||
|
||||
|
||||
# 禁用权限
|
||||
@admin_power.put('/disable')
|
||||
@authorize("admin:power:edit", log=True)
|
||||
@bp.put('/disable')
|
||||
@authorize("system:power:edit", log=True)
|
||||
def dis_enable():
|
||||
_id = request.get_json(force=True).get('powerId')
|
||||
if id:
|
||||
@@ -139,8 +140,8 @@ def dis_enable():
|
||||
|
||||
|
||||
# 权限删除
|
||||
@admin_power.delete('/remove/<int:id>')
|
||||
@authorize("admin:power:remove", log=True)
|
||||
@bp.delete('/remove/<int:id>')
|
||||
@authorize("system:power:remove", log=True)
|
||||
def remove(id):
|
||||
power = Power.query.filter_by(id=id).first()
|
||||
power.role = []
|
||||
@@ -150,18 +151,4 @@ def remove(id):
|
||||
if r:
|
||||
return success_api(msg="删除成功")
|
||||
else:
|
||||
return fail_api(msg="删除失败")
|
||||
|
||||
|
||||
# 批量删除
|
||||
@admin_power.delete('/batchRemove')
|
||||
@authorize("admin:power:remove", log=True)
|
||||
def batch_remove():
|
||||
ids = request.form.getlist('ids[]')
|
||||
for id in ids:
|
||||
power = Power.query.filter_by(id=id).first()
|
||||
power.role = []
|
||||
|
||||
r = Power.query.filter_by(id=id).delete()
|
||||
db.session.commit()
|
||||
return success_api(msg="批量删除成功")
|
||||
return fail_api(msg="删除失败")
|
||||
@@ -0,0 +1,154 @@
|
||||
import copy
|
||||
from collections import OrderedDict
|
||||
|
||||
from flask import jsonify, current_app, Blueprint, render_template
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
from ...models import Power
|
||||
from ...schemas import PowerOutSchema
|
||||
|
||||
bp = Blueprint('rights', __name__, url_prefix='/rights')
|
||||
|
||||
|
||||
# 渲染配置
|
||||
@bp.get('/configs')
|
||||
@login_required
|
||||
def configs():
|
||||
# 网站配置
|
||||
config = dict(logo={
|
||||
# 网站名称
|
||||
"title": current_app.config.get("SYSTEM_NAME"),
|
||||
# 网站图标
|
||||
"image": "/static/system/admin/images/logo.png"
|
||||
# 菜单配置
|
||||
}, menu={
|
||||
# 菜单数据来源
|
||||
"data": "/system/rights/menu",
|
||||
"collaspe": False,
|
||||
# 是否同时只打开一个菜单目录
|
||||
"accordion": True,
|
||||
"method": "GET",
|
||||
# 是否开启多系统菜单模式
|
||||
"control": False,
|
||||
# 顶部菜单宽度 PX
|
||||
"controlWidth": 500,
|
||||
# 默认选中的菜单项
|
||||
"select": "0",
|
||||
# 是否开启异步菜单,false 时 data 属性设置为菜单数据,false 时为 json 文件或后端接口
|
||||
"async": True
|
||||
}, tab={
|
||||
# 是否开启多选项卡
|
||||
"enable": True,
|
||||
# 切换选项卡时,是否刷新页面状态
|
||||
"keepState": True,
|
||||
# 是否开启 Tab 记忆
|
||||
"session": True,
|
||||
# 最大可打开的选项卡数量
|
||||
"max": 30,
|
||||
"index": {
|
||||
# 标识 ID , 建议与菜单项中的 ID 一致
|
||||
"id": "10",
|
||||
# 页面地址
|
||||
"href": "/system/rights/welcome",
|
||||
# 标题
|
||||
"title": "首页"
|
||||
}
|
||||
}, theme={
|
||||
# 默认主题色,对应 colors 配置中的 ID 标识
|
||||
"defaultColor": "2",
|
||||
# 默认的菜单主题 dark-theme 黑 / light-theme 白
|
||||
"defaultMenu": "dark-theme",
|
||||
# 是否允许用户切换主题,false 时关闭自定义主题面板
|
||||
"allowCustom": True
|
||||
}, colors=[{
|
||||
"id": "1",
|
||||
"color": "#2d8cf0"
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"color": "#5FB878"
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"color": "#1E9FFF"
|
||||
}, {
|
||||
"id": "4",
|
||||
"color": "#FFB800"
|
||||
}, {
|
||||
"id": "5",
|
||||
"color": "darkgray"
|
||||
}
|
||||
], links=current_app.config.get("SYSTEM_PANEL_LINKS"), other={
|
||||
# 主页动画时长
|
||||
"keepLoad": 0,
|
||||
# 布局顶部主题
|
||||
"autoHead": False
|
||||
}, header=False)
|
||||
return jsonify(config)
|
||||
|
||||
|
||||
# 菜单
|
||||
@bp.get('/menu')
|
||||
@login_required
|
||||
def menu():
|
||||
if current_user.username != current_app.config.get("SUPERADMIN"):
|
||||
role = current_user.role
|
||||
powers = []
|
||||
for i in role:
|
||||
# 如果角色没有被启用就直接跳过
|
||||
if i.enable == 0:
|
||||
continue
|
||||
# 变量角色用户的权限
|
||||
for p in i.power:
|
||||
# 如果权限关闭了就直接跳过
|
||||
if p.enable == 0:
|
||||
continue
|
||||
# 一二级菜单
|
||||
if int(p.type) in [0, 1] and p not in powers:
|
||||
powers.append(p)
|
||||
|
||||
power_schema = PowerOutSchema(many=True) # 用已继承 ma.ModelSchema 类的自定制类生成序列化类
|
||||
power_dict = power_schema.dump(powers) # 生成可序列化对象
|
||||
power_dict.sort(key=lambda x: (x['parent_id'], x['id']), reverse=True)
|
||||
|
||||
menu_dict = OrderedDict()
|
||||
for _dict in power_dict:
|
||||
if _dict['id'] in menu_dict:
|
||||
# 当前节点添加子节点
|
||||
_dict['children'] = copy.deepcopy(menu_dict[_dict['id']])
|
||||
_dict['children'].sort(key=lambda item: item['sort'])
|
||||
# 删除子节点
|
||||
del menu_dict[_dict['id']]
|
||||
|
||||
if _dict['parent_id'] not in menu_dict:
|
||||
|
||||
menu_dict[_dict['parent_id']] = [_dict]
|
||||
else:
|
||||
menu_dict[_dict['parent_id']].append(_dict)
|
||||
return jsonify(sorted(menu_dict.get(0), key=lambda item: item['sort']))
|
||||
else:
|
||||
powers = Power.query.all()
|
||||
power_schema = PowerOutSchema(many=True) # 用已继承 ma.ModelSchema 类的自定制类生成序列化类
|
||||
power_dict = power_schema.dump(powers) # 生成可序列化对象
|
||||
power_dict.sort(key=lambda x: (x['parent_id'], x['id']), reverse=True)
|
||||
|
||||
menu_dict = OrderedDict()
|
||||
for _dict in power_dict:
|
||||
if _dict['id'] in menu_dict:
|
||||
# 当前节点添加子节点
|
||||
_dict['children'] = copy.deepcopy(menu_dict[_dict['id']])
|
||||
_dict['children'].sort(key=lambda item: item['sort'])
|
||||
# 删除子节点
|
||||
del menu_dict[_dict['id']]
|
||||
|
||||
if _dict['parent_id'] not in menu_dict:
|
||||
menu_dict[_dict['parent_id']] = [_dict]
|
||||
else:
|
||||
menu_dict[_dict['parent_id']].append(_dict)
|
||||
return jsonify(sorted(menu_dict.get(0), key=lambda item: item['sort']))
|
||||
|
||||
# 控制台页面
|
||||
@bp.get('/welcome')
|
||||
@login_required
|
||||
def welcome():
|
||||
return render_template('system/console/console.html')
|
||||
@@ -8,19 +8,19 @@ from applications.common.utils.validate import str_escape
|
||||
from applications.extensions import db
|
||||
from applications.models import Role, Power, User
|
||||
from applications.schemas import RoleOutSchema, PowerOutSchema2
|
||||
admin_role = Blueprint('adminRole', __name__, url_prefix='/admin/role')
|
||||
|
||||
bp = Blueprint('role', __name__, url_prefix='/role')
|
||||
|
||||
# 用户管理
|
||||
@admin_role.get('/')
|
||||
@authorize("admin:role:main")
|
||||
@bp.get('/')
|
||||
@authorize("system:role:main")
|
||||
def main():
|
||||
return render_template('admin/role/main.html')
|
||||
return render_template('system/role/main.html')
|
||||
|
||||
|
||||
# 表格数据
|
||||
@admin_role.get('/data')
|
||||
@authorize("admin:role:main")
|
||||
@bp.get('/data')
|
||||
@authorize("system:role:main")
|
||||
def table():
|
||||
role_name = str_escape(request.args.get('roleName', type=str))
|
||||
role_code = str_escape(request.args.get('roleCode', type=str))
|
||||
@@ -30,19 +30,19 @@ def table():
|
||||
if role_code:
|
||||
filters.append(Role.code.contains(role_code))
|
||||
roles = Role.query.filter(*filters).layui_paginate()
|
||||
return table_api(data=model_to_dicts(schema=RoleOutSchema, data=roles.items), count=roles.total)
|
||||
return table_api(data=RoleOutSchema(many=True).dump(roles), count=roles.total)
|
||||
|
||||
|
||||
# 角色增加
|
||||
@admin_role.get('/add')
|
||||
@authorize("admin:role:add", log=True)
|
||||
@bp.get('/add')
|
||||
@authorize("system:role:add", log=True)
|
||||
def add():
|
||||
return render_template('admin/role/add.html')
|
||||
return render_template('system/role/add.html')
|
||||
|
||||
|
||||
# 角色增加
|
||||
@admin_role.post('/save')
|
||||
@authorize("admin:role:add", log=True)
|
||||
@bp.post('/save')
|
||||
@authorize("system:role:add", log=True)
|
||||
def save():
|
||||
req = request.get_json(force=True)
|
||||
details = str_escape(req.get("details"))
|
||||
@@ -63,15 +63,15 @@ def save():
|
||||
|
||||
|
||||
# 角色授权
|
||||
@admin_role.get('/power/<int:_id>')
|
||||
@authorize("admin:role:power", log=True)
|
||||
@bp.get('/power/<int:_id>')
|
||||
@authorize("system:role:power", log=True)
|
||||
def power(_id):
|
||||
return render_template('admin/role/power.html', id=_id)
|
||||
return render_template('system/role/power.html', id=_id)
|
||||
|
||||
|
||||
# 获取角色权限
|
||||
@admin_role.get('/getRolePower/<int:id>')
|
||||
@authorize("admin:role:main", log=True)
|
||||
@bp.get('/getRolePower/<int:id>')
|
||||
@authorize("system:role:main", log=True)
|
||||
def get_role_power(id):
|
||||
role = Role.query.filter_by(id=id).first()
|
||||
check_powers = role.power
|
||||
@@ -94,8 +94,8 @@ def get_role_power(id):
|
||||
|
||||
|
||||
# 保存角色权限
|
||||
@admin_role.put('/saveRolePower')
|
||||
@authorize("admin:role:edit", log=True)
|
||||
@bp.put('/saveRolePower')
|
||||
@authorize("system:role:edit", log=True)
|
||||
def save_role_power():
|
||||
req_form = request.form
|
||||
power_ids = req_form.get("powerIds")
|
||||
@@ -111,16 +111,16 @@ def save_role_power():
|
||||
|
||||
|
||||
# 角色编辑
|
||||
@admin_role.get('/edit/<int:id>')
|
||||
@authorize("admin:role:edit", log=True)
|
||||
@bp.get('/edit/<int:id>')
|
||||
@authorize("system:role:edit", log=True)
|
||||
def edit(id):
|
||||
r = get_one_by_id(model=Role, id=id)
|
||||
return render_template('admin/role/edit.html', role=r)
|
||||
return render_template('system/role/edit.html', role=r)
|
||||
|
||||
|
||||
# 更新角色
|
||||
@admin_role.put('/update')
|
||||
@authorize("admin:role:edit", log=True)
|
||||
@bp.put('/update')
|
||||
@authorize("system:role:edit", log=True)
|
||||
def update():
|
||||
req_json = request.get_json(force=True)
|
||||
id = req_json.get("roleId")
|
||||
@@ -139,8 +139,8 @@ def update():
|
||||
|
||||
|
||||
# 启用用户
|
||||
@admin_role.put('/enable')
|
||||
@authorize("admin:role:edit", log=True)
|
||||
@bp.put('/enable')
|
||||
@authorize("system:role:edit", log=True)
|
||||
def enable():
|
||||
id = request.get_json(force=True).get('roleId')
|
||||
if id:
|
||||
@@ -152,8 +152,8 @@ def enable():
|
||||
|
||||
|
||||
# 禁用用户
|
||||
@admin_role.put('/disable')
|
||||
@authorize("admin:role:edit", log=True)
|
||||
@bp.put('/disable')
|
||||
@authorize("system:role:edit", log=True)
|
||||
def dis_enable():
|
||||
_id = request.get_json(force=True).get('roleId')
|
||||
if _id:
|
||||
@@ -165,8 +165,8 @@ def dis_enable():
|
||||
|
||||
|
||||
# 角色删除
|
||||
@admin_role.delete('/remove/<int:id>')
|
||||
@authorize("admin:role:remove", log=True)
|
||||
@bp.delete('/remove/<int:id>')
|
||||
@authorize("system:role:remove", log=True)
|
||||
def remove(id):
|
||||
role = Role.query.filter_by(id=id).first()
|
||||
# 删除该角色的权限和用户
|
||||
@@ -178,19 +178,3 @@ def remove(id):
|
||||
if not r:
|
||||
return fail_api(msg="角色删除失败")
|
||||
return success_api(msg="角色删除成功")
|
||||
|
||||
|
||||
# 批量删除
|
||||
@admin_role.delete('/batchRemove')
|
||||
@authorize("admin:role:remove", log=True)
|
||||
def batch_remove():
|
||||
ids = request.form.getlist('ids[]')
|
||||
for id in ids:
|
||||
role = Role.query.filter_by(id=id).first()
|
||||
# 删除该角色的权限和用户
|
||||
role.power = []
|
||||
role.user = []
|
||||
|
||||
r = Role.query.filter_by(id=id).delete()
|
||||
db.session.commit()
|
||||
return success_api(msg="批量删除成功")
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import Blueprint, render_template, request, session
|
||||
from flask import Blueprint, render_template, request
|
||||
from flask_login import login_required, current_user
|
||||
from sqlalchemy import desc
|
||||
|
||||
@@ -11,22 +11,22 @@ from applications.extensions import db
|
||||
from applications.models import Role, Dept
|
||||
from applications.models import User, AdminLog
|
||||
|
||||
admin_user = Blueprint('adminUser', __name__, url_prefix='/admin/user')
|
||||
bp = Blueprint('user', __name__, url_prefix='/user')
|
||||
|
||||
|
||||
# 用户管理
|
||||
@admin_user.get('/')
|
||||
@authorize("admin:user:main")
|
||||
@bp.get('/')
|
||||
@authorize("system:user:main")
|
||||
def main():
|
||||
return render_template('admin/user/main.html')
|
||||
return render_template('system/user/main.html')
|
||||
|
||||
|
||||
# 用户分页查询
|
||||
@admin_user.get('/data')
|
||||
@authorize("admin:user:main")
|
||||
@bp.get('/data')
|
||||
@authorize("system:user:main")
|
||||
def data():
|
||||
# 获取请求参数
|
||||
real_name = str_escape(request.args.get('realName', type=str))
|
||||
real_name = str_escape(request.args.get('realname', type=str))
|
||||
|
||||
username = str_escape(request.args.get('username', type=str))
|
||||
dept_id = request.args.get('deptId', type=int)
|
||||
@@ -35,9 +35,9 @@ def data():
|
||||
if real_name:
|
||||
filters.append(User.realname.contains(real_name))
|
||||
if username:
|
||||
filters.append(User.realname.contains(username))
|
||||
filters.append(User.username.contains(username))
|
||||
if dept_id:
|
||||
filters.append(User.realname == dept_id)
|
||||
filters.append(User.dept_id == dept_id)
|
||||
|
||||
# print(*filters)
|
||||
query = db.session.query(
|
||||
@@ -60,15 +60,15 @@ def data():
|
||||
# 用户增加
|
||||
|
||||
|
||||
@admin_user.get('/add')
|
||||
@authorize("admin:user:add", log=True)
|
||||
@bp.get('/add')
|
||||
@authorize("system:user:add", log=True)
|
||||
def add():
|
||||
roles = Role.query.all()
|
||||
return render_template('admin/user/add.html', roles=roles)
|
||||
return render_template('system/user/add.html', roles=roles)
|
||||
|
||||
|
||||
@admin_user.post('/save')
|
||||
@authorize("admin:user:add", log=True)
|
||||
@bp.post('/save')
|
||||
@authorize("system:user:add", log=True)
|
||||
def save():
|
||||
req_json = request.get_json(force=True)
|
||||
a = req_json.get("roleIds")
|
||||
@@ -82,7 +82,7 @@ def save():
|
||||
|
||||
if bool(User.query.filter_by(username=username).count()):
|
||||
return fail_api(msg="用户已经存在")
|
||||
user = User(username=username, realname=real_name)
|
||||
user = User(username=username, realname=real_name,enable=1)
|
||||
user.set_password(password)
|
||||
db.session.add(user)
|
||||
roles = Role.query.filter(Role.id.in_(role_ids)).all()
|
||||
@@ -93,8 +93,8 @@ def save():
|
||||
|
||||
|
||||
# 删除用户
|
||||
@admin_user.delete('/remove/<int:id>')
|
||||
@authorize("admin:user:remove", log=True)
|
||||
@bp.delete('/remove/<int:id>')
|
||||
@authorize("system:user:remove", log=True)
|
||||
def delete(id):
|
||||
user = User.query.filter_by(id=id).first()
|
||||
user.role = []
|
||||
@@ -107,20 +107,20 @@ def delete(id):
|
||||
|
||||
|
||||
# 编辑用户
|
||||
@admin_user.get('/edit/<int:id>')
|
||||
@authorize("admin:user:edit", log=True)
|
||||
@bp.get('/edit/<int:id>')
|
||||
@authorize("system:user:edit", log=True)
|
||||
def edit(id):
|
||||
user = curd.get_one_by_id(User, id)
|
||||
roles = Role.query.all()
|
||||
checked_roles = []
|
||||
for r in user.role:
|
||||
checked_roles.append(r.id)
|
||||
return render_template('admin/user/edit.html', user=user, roles=roles, checked_roles=checked_roles)
|
||||
return render_template('system/user/edit.html', user=user, roles=roles, checked_roles=checked_roles)
|
||||
|
||||
|
||||
# 编辑用户
|
||||
@admin_user.put('/update')
|
||||
@authorize("admin:user:edit", log=True)
|
||||
@bp.put('/update')
|
||||
@authorize("system:user:edit", log=True)
|
||||
def update():
|
||||
req_json = request.get_json(force=True)
|
||||
a = str_escape(req_json.get("roleIds"))
|
||||
@@ -140,24 +140,24 @@ def update():
|
||||
|
||||
|
||||
# 个人中心
|
||||
@admin_user.get('/center')
|
||||
@bp.get('/center')
|
||||
@login_required
|
||||
def center():
|
||||
user_info = current_user
|
||||
user_logs = AdminLog.query.filter_by(url='/passport/login').filter_by(uid=current_user.id).order_by(
|
||||
desc(AdminLog.create_time)).limit(10)
|
||||
return render_template('admin/user/center.html', user_info=user_info, user_logs=user_logs)
|
||||
return render_template('system/user/center.html', user_info=user_info, user_logs=user_logs)
|
||||
|
||||
|
||||
# 修改头像
|
||||
@admin_user.get('/profile')
|
||||
@bp.get('/profile')
|
||||
@login_required
|
||||
def profile():
|
||||
return render_template('admin/user/profile.html')
|
||||
return render_template('system/user/profile.html')
|
||||
|
||||
|
||||
# 修改头像
|
||||
@admin_user.put('/updateAvatar')
|
||||
@bp.put('/updateAvatar')
|
||||
@login_required
|
||||
def update_avatar():
|
||||
url = request.get_json(force=True).get("avatar").get("src")
|
||||
@@ -169,7 +169,7 @@ def update_avatar():
|
||||
|
||||
|
||||
# 修改当前用户信息
|
||||
@admin_user.put('/updateInfo')
|
||||
@bp.put('/updateInfo')
|
||||
@login_required
|
||||
def update_info():
|
||||
req_json = request.get_json(force=True)
|
||||
@@ -182,14 +182,14 @@ def update_info():
|
||||
|
||||
|
||||
# 修改当前用户密码
|
||||
@admin_user.get('/editPassword')
|
||||
@bp.get('/editPassword')
|
||||
@login_required
|
||||
def edit_password():
|
||||
return render_template('admin/user/edit_password.html')
|
||||
return render_template('system/user/edit_password.html')
|
||||
|
||||
|
||||
# 修改当前用户密码
|
||||
@admin_user.put('/editPassword')
|
||||
@bp.put('/editPassword')
|
||||
@login_required
|
||||
def edit_password_put():
|
||||
res_json = request.get_json(force=True)
|
||||
@@ -208,8 +208,8 @@ def edit_password_put():
|
||||
|
||||
|
||||
# 启用用户
|
||||
@admin_user.put('/enable')
|
||||
@authorize("admin:user:edit", log=True)
|
||||
@bp.put('/enable')
|
||||
@authorize("system:user:edit", log=True)
|
||||
def enable():
|
||||
_id = request.get_json(force=True).get('userId')
|
||||
if _id:
|
||||
@@ -221,8 +221,8 @@ def enable():
|
||||
|
||||
|
||||
# 禁用用户
|
||||
@admin_user.put('/disable')
|
||||
@authorize("admin:user:edit", log=True)
|
||||
@bp.put('/disable')
|
||||
@authorize("system:user:edit", log=True)
|
||||
def dis_enable():
|
||||
_id = request.get_json(force=True).get('userId')
|
||||
if _id:
|
||||
@@ -231,24 +231,3 @@ def dis_enable():
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api(msg="禁用成功")
|
||||
return fail_api(msg="数据错误")
|
||||
|
||||
|
||||
# 批量删除
|
||||
@admin_user.delete('/batchRemove')
|
||||
@authorize("admin:user:remove", log=True)
|
||||
def batch_remove():
|
||||
ids = request.form.getlist('ids[]')
|
||||
for id in ids:
|
||||
user = User.query.filter_by(id=id).first()
|
||||
user.role = []
|
||||
|
||||
res = User.query.filter_by(id=id).delete()
|
||||
db.session.commit()
|
||||
return success_api(msg="批量删除成功")
|
||||
|
||||
|
||||
@admin_user.get("test")
|
||||
def test():
|
||||
print(session)
|
||||
print(session.get('role')[0])
|
||||
return '6'
|
||||
Reference in New Issue
Block a user