统一table,成功,失败返回响应,封装模型序列化函数
This commit is contained in:
@@ -4,6 +4,7 @@ from applications.models.admin_dict import DictType, DictData
|
||||
from applications.service.admin.dict import get_dict_type, get_dict_data, save_dict_type, save_dict_data, \
|
||||
delete_type_by_id, delete_data_by_id, update_dict_type, enable_dict_type_status, disable_dict_type_status, \
|
||||
enable_dict_data_status, disable_dict_data_status, update_dict_data
|
||||
from applications.service.common.response import table_api, success_api, fail_api
|
||||
from applications.service.route_auth import authorize_and_log
|
||||
|
||||
admin_dict = Blueprint('adminDict', __name__, url_prefix='/admin/dict')
|
||||
@@ -22,13 +23,8 @@ def dictType_data():
|
||||
page = request.args.get('page', type=int)
|
||||
limit = request.args.get('limit', type=int)
|
||||
type_name = request.args.get('typeName', type=str)
|
||||
dict_data, count = get_dict_type(page=page, limit=limit, type_name=type_name)
|
||||
res = {
|
||||
"data": dict_data,
|
||||
"count": count,
|
||||
"code": 0,
|
||||
}
|
||||
return jsonify(res)
|
||||
data, count = get_dict_type(page=page, limit=limit, type_name=type_name)
|
||||
return table_api(data=data,count=count)
|
||||
|
||||
|
||||
@admin_dict.route('/dictType/add')
|
||||
@@ -38,13 +34,13 @@ def dictType_add():
|
||||
|
||||
|
||||
@admin_dict.route('/dictType/save', methods=['POST'])
|
||||
@authorize_and_log("admin:power:add")
|
||||
@authorize_and_log("admin:dict:add")
|
||||
def dictType_save():
|
||||
req_json = request.json
|
||||
res = save_dict_type(req_json=req_json)
|
||||
if res == None:
|
||||
return jsonify(success=False, msg="增加失败")
|
||||
return jsonify(success=True, msg="增加成功")
|
||||
return fail_api(msg="增加失败")
|
||||
return success_api(msg="增加成功")
|
||||
|
||||
|
||||
# 编辑字典类型
|
||||
@@ -62,7 +58,7 @@ def dictType_edit():
|
||||
def dictType_update():
|
||||
req_json = request.json
|
||||
update_dict_type(req_json)
|
||||
return jsonify(success=True, msg="更新成功")
|
||||
return success_api(msg="更新成功")
|
||||
|
||||
|
||||
# 启用字典
|
||||
@@ -70,13 +66,12 @@ def dictType_update():
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
def dictType_enable():
|
||||
id = request.json.get('id')
|
||||
print(id)
|
||||
if id:
|
||||
res = enable_dict_type_status(id)
|
||||
if not res:
|
||||
return jsonify(msg="出错啦", success=False)
|
||||
return jsonify(msg="启动成功", success=True)
|
||||
return jsonify(msg="数据错误", success=False)
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api("启动成功")
|
||||
return fail_api(msg="数据错误")
|
||||
|
||||
|
||||
# 禁用字典
|
||||
@@ -84,13 +79,12 @@ def dictType_enable():
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
def dictType_disenable():
|
||||
id = request.json.get('id')
|
||||
print(id)
|
||||
if id:
|
||||
res = disable_dict_type_status(id)
|
||||
if not res:
|
||||
return jsonify(msg="出错啦", success=False)
|
||||
return jsonify(msg="禁用成功", success=True)
|
||||
return jsonify(msg="数据错误", success=False)
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api("禁用成功")
|
||||
return fail_api(msg="数据错误")
|
||||
|
||||
|
||||
# 删除字典类型
|
||||
@@ -99,8 +93,8 @@ def dictType_disenable():
|
||||
def dictType_delete(id):
|
||||
res = delete_type_by_id(id)
|
||||
if not res:
|
||||
return jsonify(msg="删除失败", success=False)
|
||||
return jsonify(msg="删除成功", success=True)
|
||||
return fail_api(msg="删除失败")
|
||||
return success_api(msg="删除成功")
|
||||
|
||||
|
||||
@admin_dict.route('/dictData/data')
|
||||
@@ -109,18 +103,13 @@ def dictCode_data():
|
||||
page = request.args.get('page', type=int)
|
||||
limit = request.args.get('limit', type=int)
|
||||
type_code = request.args.get('typeCode', type=str)
|
||||
dict_data, count = get_dict_data(page=page, limit=limit, type_code=type_code)
|
||||
res = {
|
||||
"data": dict_data,
|
||||
"count": count,
|
||||
"code": 0,
|
||||
}
|
||||
return jsonify(res)
|
||||
data, count = get_dict_data(page=page, limit=limit, type_code=type_code)
|
||||
return table_api(data=data,count=count)
|
||||
|
||||
|
||||
# 增加字典数据
|
||||
@admin_dict.route('/dictData/add')
|
||||
# @authorize_and_log("admin:power:add")
|
||||
@authorize_and_log("admin:dict:add")
|
||||
def dictData_add():
|
||||
type_code = request.args.get('typeCode', type=str)
|
||||
return render_template('admin/dict/data/add.html', type_code=type_code)
|
||||
@@ -128,7 +117,7 @@ def dictData_add():
|
||||
|
||||
# 增加字典数据
|
||||
@admin_dict.route('/dictData/save', methods=['POST'])
|
||||
# @authorize_and_log("admin:power:main")
|
||||
@authorize_and_log("admin:dict:add")
|
||||
def dictData_save():
|
||||
req_json = request.json
|
||||
res = save_dict_data(req_json=req_json)
|
||||
@@ -152,7 +141,7 @@ def dictData_edit():
|
||||
def dictData_update():
|
||||
req_json = request.json
|
||||
update_dict_data(req_json)
|
||||
return jsonify(success=True, msg="更新成功")
|
||||
return success_api(msg="更新成功")
|
||||
|
||||
|
||||
# 启用字典数据
|
||||
@@ -160,13 +149,12 @@ def dictData_update():
|
||||
@authorize_and_log("admin:dict:edit")
|
||||
def dictData_enable():
|
||||
id = request.json.get('dataId')
|
||||
print(id)
|
||||
if id:
|
||||
res = enable_dict_data_status(id)
|
||||
if not res:
|
||||
return jsonify(msg="出错啦", success=False)
|
||||
return jsonify(msg="启动成功", success=True)
|
||||
return jsonify(msg="数据错误", success=False)
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api(msg="启动成功")
|
||||
return fail_api(msg="数据错误")
|
||||
|
||||
|
||||
# 禁用字典数据
|
||||
@@ -177,9 +165,9 @@ def dictData_disenable():
|
||||
if id:
|
||||
res = disable_dict_data_status(id)
|
||||
if not res:
|
||||
return jsonify(msg="出错啦", success=False)
|
||||
return jsonify(msg="禁用成功", success=True)
|
||||
return jsonify(msg="数据错误", success=False)
|
||||
return fail_api(msg="出错啦")
|
||||
return success_api(msg="禁用成功")
|
||||
return fail_api(msg="数据错误")
|
||||
|
||||
|
||||
# 删除字典类型
|
||||
@@ -188,5 +176,5 @@ def dictData_disenable():
|
||||
def dictData_delete(id):
|
||||
res = delete_data_by_id(id)
|
||||
if not res:
|
||||
return jsonify(msg="删除失败", success=False)
|
||||
return jsonify(msg="删除成功", success=True)
|
||||
return fail_api(msg="删除失败")
|
||||
return success_api(msg="删除成功")
|
||||
|
||||
Reference in New Issue
Block a user