将数据操作全部改为迁移脚本
This commit is contained in:
@@ -4,7 +4,6 @@ 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
|
||||
@@ -16,6 +15,5 @@ def register_admin_views(app: Flask):
|
||||
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)
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
from flask import Blueprint, render_template, request, jsonify
|
||||
from applications.common.admin import power_curd
|
||||
from applications.common.utils.http import success_api, fail_api
|
||||
from applications.common.utils.rights import authorize
|
||||
|
||||
admin_power = Blueprint('adminPower', __name__, url_prefix='/admin/power')
|
||||
|
||||
|
||||
@admin_power.get('/')
|
||||
@authorize("admin:power:main", log=True)
|
||||
def index():
|
||||
return render_template('admin/power/main.html')
|
||||
|
||||
|
||||
@admin_power.get('/data')
|
||||
@authorize("admin:power:main", log=True)
|
||||
def data():
|
||||
power_data = power_curd.get_power_dict()
|
||||
res = {
|
||||
"data": power_data
|
||||
}
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
@admin_power.get('/add')
|
||||
@authorize("admin:power:add", log=True)
|
||||
def add():
|
||||
return render_template('admin/power/add.html')
|
||||
|
||||
|
||||
@admin_power.get('/selectParent')
|
||||
@authorize("admin:power:main", log=True)
|
||||
def select_parent():
|
||||
power_data = power_curd.select_parent()
|
||||
res = {
|
||||
"status": {"code": 200, "message": "默认"},
|
||||
"data": power_data
|
||||
|
||||
}
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
# 增加
|
||||
@admin_power.post('/save')
|
||||
@authorize("admin:power:add", log=True)
|
||||
def save():
|
||||
req = request.json
|
||||
power_curd.save_power(req)
|
||||
return success_api(msg="成功")
|
||||
|
||||
|
||||
# 权限编辑
|
||||
@admin_power.get('/edit/<int:_id>')
|
||||
@authorize("admin:power:edit", log=True)
|
||||
def edit(_id):
|
||||
power = power_curd.get_power_by_id(_id)
|
||||
icon = str(power.icon).split()
|
||||
if len(icon) == 2:
|
||||
icon = icon[1]
|
||||
else:
|
||||
icon = None
|
||||
return render_template('admin/power/edit.html', power=power, icon=icon)
|
||||
|
||||
|
||||
# 权限更新
|
||||
@admin_power.put('/update')
|
||||
@authorize("admin:power:edit", log=True)
|
||||
def update():
|
||||
res = power_curd.update_power(request.json)
|
||||
if not res:
|
||||
return fail_api(msg="更新权限失败")
|
||||
return success_api(msg="更新权限成功")
|
||||
|
||||
|
||||
# 启用权限
|
||||
@admin_power.put('/enable')
|
||||
@authorize("admin:power:edit", log=True)
|
||||
def enable():
|
||||
_id = request.json.get('powerId')
|
||||
if id:
|
||||
res = power_curd.enable_status(_id)
|
||||
if not res:
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api(msg="启用成功")
|
||||
return fail_api(msg="数据错误")
|
||||
|
||||
|
||||
# 禁用权限
|
||||
@admin_power.put('/disable')
|
||||
@authorize("admin:power:edit", log=True)
|
||||
def dis_enable():
|
||||
_id = request.json.get('powerId')
|
||||
if id:
|
||||
res = power_curd.disable_status(_id)
|
||||
if not res:
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api(msg="禁用成功")
|
||||
return fail_api(msg="数据错误")
|
||||
|
||||
|
||||
# 权限删除
|
||||
@admin_power.delete('/remove/<int:_id>')
|
||||
@authorize("admin:power:remove", log=True)
|
||||
def remove(_id):
|
||||
r = power_curd.remove_power(_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[]')
|
||||
power_curd.batch_remove(ids)
|
||||
return success_api(msg="批量删除成功")
|
||||
Reference in New Issue
Block a user