'wip(semantic):调整模板api接口'
This commit is contained in:
@@ -49,7 +49,7 @@ class Departments(Resource):
|
|||||||
db.session.add(dept)
|
db.session.add(dept)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return success_api(msg="成功")
|
return success_api(message="成功")
|
||||||
|
|
||||||
|
|
||||||
class Department(Resource):
|
class Department(Resource):
|
||||||
@@ -67,7 +67,7 @@ class Department(Resource):
|
|||||||
'address': dept.address,
|
'address': dept.address,
|
||||||
}
|
}
|
||||||
# return make_response(render_template('department/edit.html', dept=dept))
|
# return make_response(render_template('department/edit.html', dept=dept))
|
||||||
return jsonify(success=True, msg='ok', dept=dept_data)
|
return dict(success=True, message='ok', dept=dept_data)
|
||||||
|
|
||||||
@authorize("admin:dept:edit", log=True)
|
@authorize("admin:dept:edit", log=True)
|
||||||
def put(self, dept_id):
|
def put(self, dept_id):
|
||||||
@@ -92,9 +92,9 @@ class Department(Resource):
|
|||||||
}
|
}
|
||||||
res = CompanyDepartment.query.filter_by(id=dept_id).update(data)
|
res = CompanyDepartment.query.filter_by(id=dept_id).update(data)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="更新失败")
|
return fail_api(message="更新失败")
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return success_api(msg="更新成功")
|
return success_api(message="更新成功")
|
||||||
|
|
||||||
@authorize("admin:dept:remove", log=True)
|
@authorize("admin:dept:remove", log=True)
|
||||||
def delete(self, dept_id):
|
def delete(self, dept_id):
|
||||||
@@ -102,8 +102,8 @@ class Department(Resource):
|
|||||||
CompanyUser.query.filter_by(dept_id=dept_id).update({"dept_id": None})
|
CompanyUser.query.filter_by(dept_id=dept_id).update({"dept_id": None})
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if ret:
|
if ret:
|
||||||
return success_api(msg="删除成功")
|
return success_api(message="删除成功")
|
||||||
return fail_api(msg="删除失败")
|
return fail_api(message="删除失败")
|
||||||
|
|
||||||
|
|
||||||
class DeptEnable(Resource):
|
class DeptEnable(Resource):
|
||||||
@@ -114,5 +114,5 @@ class DeptEnable(Resource):
|
|||||||
d.status = not d.status
|
d.status = not d.status
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
message = '修改成功'
|
message = '修改成功'
|
||||||
return success_api(msg=message)
|
return success_api(message=message)
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(message="出错啦")
|
||||||
|
|||||||
@@ -166,13 +166,13 @@ class RightRights(Resource):
|
|||||||
"data": power_data
|
"data": power_data
|
||||||
|
|
||||||
}
|
}
|
||||||
return jsonify(res)
|
return res
|
||||||
|
|
||||||
@authorize("admin:power:remove", log=True)
|
@authorize("admin:power:remove", log=True)
|
||||||
def delete(self):
|
def delete(self):
|
||||||
ids = request.form.getlist('ids[]')
|
ids = request.form.getlist('ids[]')
|
||||||
batch_remove_power(ids)
|
batch_remove_power(ids)
|
||||||
return success_api(msg="批量删除成功")
|
return success_api(message="批量删除成功")
|
||||||
|
|
||||||
|
|
||||||
class RightPower(Resource):
|
class RightPower(Resource):
|
||||||
@@ -196,9 +196,9 @@ class RightPower(Resource):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return fail_api(msg='数据提交失败')
|
return fail_api(message='数据提交失败')
|
||||||
|
|
||||||
return success_api(msg="成功")
|
return success_api(message="成功")
|
||||||
|
|
||||||
@authorize("admin:power:remove", log=True)
|
@authorize("admin:power:remove", log=True)
|
||||||
def delete(self, power_id):
|
def delete(self, power_id):
|
||||||
@@ -215,9 +215,9 @@ class RightPower(Resource):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
if r:
|
if r:
|
||||||
return success_api(msg="删除成功")
|
return success_api(message="删除成功")
|
||||||
else:
|
else:
|
||||||
return fail_api(msg="删除失败")
|
return fail_api(message="删除失败")
|
||||||
|
|
||||||
@authorize("admin:power:edit", log=True)
|
@authorize("admin:power:edit", log=True)
|
||||||
def put(self, power_id):
|
def put(self, power_id):
|
||||||
@@ -237,8 +237,8 @@ class RightPower(Resource):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
if not power:
|
if not power:
|
||||||
return fail_api(msg="更新权限失败")
|
return fail_api(message="更新权限失败")
|
||||||
return success_api(msg="更新权限成功")
|
return success_api(message="更新权限成功")
|
||||||
|
|
||||||
|
|
||||||
class RightPowerEnable(Resource):
|
class RightPowerEnable(Resource):
|
||||||
@@ -250,9 +250,9 @@ class RightPowerEnable(Resource):
|
|||||||
power.enable = not power.enable
|
power.enable = not power.enable
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
message = "修改成功"
|
message = "修改成功"
|
||||||
return success_api(msg=message)
|
return success_api(message=message)
|
||||||
else:
|
else:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(message="出错啦")
|
||||||
|
|
||||||
|
|
||||||
class AdminConfigs(Resource):
|
class AdminConfigs(Resource):
|
||||||
|
|||||||
@@ -57,18 +57,16 @@ class RoleRoles(Resource):
|
|||||||
|
|
||||||
paginate = RightsRole.query.filter(*filters).paginate(page=res.page, per_page=res.limit, error_out=False)
|
paginate = RightsRole.query.filter(*filters).paginate(page=res.page, per_page=res.limit, error_out=False)
|
||||||
|
|
||||||
return table_api(data=[
|
return table_api(result={'items': [{'id': item.id,
|
||||||
{
|
|
||||||
'id': item.id,
|
|
||||||
'roleName': item.name,
|
'roleName': item.name,
|
||||||
'roleCode': item.code,
|
'roleCode': item.code,
|
||||||
'enable': item.enable,
|
'enable': item.enable,
|
||||||
'remark': item.remark,
|
'remark': item.remark,
|
||||||
'details': item.details,
|
'details': item.details,
|
||||||
'sort': item.sort,
|
'sort': item.sort,
|
||||||
'create_at': item.create_at,
|
'create_at': str(item.create_at), } for item in paginate.items],
|
||||||
} for item in paginate.items
|
'total': paginate.total}
|
||||||
], count=paginate.total, code=0)
|
, code=0)
|
||||||
|
|
||||||
@authorize("admin:role:remove", log=True)
|
@authorize("admin:role:remove", log=True)
|
||||||
@login_required
|
@login_required
|
||||||
@@ -79,7 +77,7 @@ class RoleRoles(Resource):
|
|||||||
res = parser.parse_args()
|
res = parser.parse_args()
|
||||||
|
|
||||||
batch_remove_role(res.ids)
|
batch_remove_role(res.ids)
|
||||||
return success_api(msg="批量删除成功")
|
return success_api(message="批量删除成功")
|
||||||
|
|
||||||
|
|
||||||
class RoleRole(Resource):
|
class RoleRole(Resource):
|
||||||
@@ -104,7 +102,7 @@ class RoleRole(Resource):
|
|||||||
)
|
)
|
||||||
db.session.add(role)
|
db.session.add(role)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return success_api(msg="成功")
|
return success_api(message="成功")
|
||||||
|
|
||||||
# 更新角色
|
# 更新角色
|
||||||
@authorize("admin:role:edit", log=True)
|
@authorize("admin:role:edit", log=True)
|
||||||
@@ -130,8 +128,8 @@ class RoleRole(Resource):
|
|||||||
role = RightsRole.query.filter_by(id=role_id).update(data)
|
role = RightsRole.query.filter_by(id=role_id).update(data)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if not role:
|
if not role:
|
||||||
return fail_api(msg="更新角色失败")
|
return fail_api(message="更新角色失败")
|
||||||
return success_api(msg="更新角色成功")
|
return success_api(message="更新角色成功")
|
||||||
|
|
||||||
|
|
||||||
class RoleEnable(Resource):
|
class RoleEnable(Resource):
|
||||||
@@ -145,8 +143,8 @@ class RoleEnable(Resource):
|
|||||||
|
|
||||||
message = "修改成功"
|
message = "修改成功"
|
||||||
if not ret:
|
if not ret:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(message="出错啦")
|
||||||
return success_api(msg=message)
|
return success_api(message=message)
|
||||||
|
|
||||||
|
|
||||||
class RolePower(Resource):
|
class RolePower(Resource):
|
||||||
@@ -158,20 +156,16 @@ class RolePower(Resource):
|
|||||||
# 获取权限列表的 id
|
# 获取权限列表的 id
|
||||||
check_powers_list = [rp.id for rp in role.power]
|
check_powers_list = [rp.id for rp in role.power]
|
||||||
powers = RightsPower.query.all() # 获取所有的权限
|
powers = RightsPower.query.all() # 获取所有的权限
|
||||||
# power_schema = PowerSchema2(many=True) # 用已继承 ma.ModelSchema 类的自定制类生成序列化类
|
|
||||||
# 将所有的权限生产可序列化对象 json
|
|
||||||
# powers = power_schema.dump(powers) # 生成可序列化对象
|
|
||||||
powers = marshal(powers, power_fields)
|
powers = marshal(powers, power_fields)
|
||||||
for i in powers:
|
for i in powers:
|
||||||
if int(i.get("powerId")) in check_powers_list:
|
if int(i.get("powerId")) in check_powers_list:
|
||||||
i["checkArr"] = "1"
|
i["checkArr"] = "1"
|
||||||
else:
|
else:
|
||||||
i["checkArr"] = "0"
|
i["checkArr"] = "0"
|
||||||
res = {
|
return {
|
||||||
"data": powers,
|
"data": powers,
|
||||||
"status": {"code": 200, "message": "默认"}
|
"status": {"code": 200, "message": "默认"}
|
||||||
}
|
}
|
||||||
return jsonify(res)
|
|
||||||
|
|
||||||
# 保存角色权限
|
# 保存角色权限
|
||||||
@authorize("admin:role:edit", log=True)
|
@authorize("admin:role:edit", log=True)
|
||||||
@@ -195,7 +189,7 @@ class RolePower(Resource):
|
|||||||
for p in powers:
|
for p in powers:
|
||||||
role.power.append(p)
|
role.power.append(p)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return success_api(msg="授权成功")
|
return success_api(message="授权成功")
|
||||||
|
|
||||||
# 角色删除
|
# 角色删除
|
||||||
@authorize("admin:role:remove", log=True)
|
@authorize("admin:role:remove", log=True)
|
||||||
@@ -204,5 +198,5 @@ class RolePower(Resource):
|
|||||||
res = remove_role(role_id)
|
res = remove_role(role_id)
|
||||||
print(res)
|
print(res)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="角色删除失败")
|
return fail_api(message="角色删除失败")
|
||||||
return success_api(msg="角色删除成功")
|
return success_api(message="角色删除成功")
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ class FilePhotos(Resource):
|
|||||||
photo_paginate = FilePhoto.query.order_by(desc(FilePhoto.create_at)).paginate(page=page, per_page=limit,
|
photo_paginate = FilePhoto.query.order_by(desc(FilePhoto.create_at)).paginate(page=page, per_page=limit,
|
||||||
error_out=False)
|
error_out=False)
|
||||||
data = marshal(photo_paginate.items, photo_fields)
|
data = marshal(photo_paginate.items, photo_fields)
|
||||||
return table_api(data=data, count=photo_paginate.total, code=0)
|
return table_api(result={'items': data,
|
||||||
|
'total': photo_paginate.total, },
|
||||||
|
code=0)
|
||||||
|
|
||||||
@authorize("admin:file:add", log=True)
|
@authorize("admin:file:add", log=True)
|
||||||
def post(self):
|
def post(self):
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ class Login(Resource):
|
|||||||
def get(self):
|
def get(self):
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
return redirect(url_for('admin.index'))
|
return redirect(url_for('admin.index'))
|
||||||
# TODO 分离视图操作 最终实现接口登录与视图登录两套逻辑
|
|
||||||
return make_response(render_template('index/login.html'))
|
return make_response(render_template('index/login.html'))
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
@@ -28,14 +27,14 @@ class Login(Resource):
|
|||||||
s_code = session.get("code", None)
|
s_code = session.get("code", None)
|
||||||
|
|
||||||
if req.captcha != s_code:
|
if req.captcha != s_code:
|
||||||
return fail_api(msg="验证码错误")
|
return fail_api(message="验证码错误")
|
||||||
user = CompanyUser.query.filter_by(username=req.username).first()
|
user = CompanyUser.query.filter_by(username=req.username).first()
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
return fail_api(msg="不存在的用户")
|
return fail_api(message="不存在的用户")
|
||||||
|
|
||||||
if user.enable == 0:
|
if user.enable == 0:
|
||||||
return fail_api(msg="用户被暂停使用")
|
return fail_api(message="用户被暂停使用")
|
||||||
|
|
||||||
if user.validate_password(req.password):
|
if user.validate_password(req.password):
|
||||||
# 登录
|
# 登录
|
||||||
@@ -45,6 +44,6 @@ class Login(Resource):
|
|||||||
|
|
||||||
# 存入权限
|
# 存入权限
|
||||||
add_auth_session()
|
add_auth_session()
|
||||||
return success_api(msg="登录成功")
|
return success_api(message="登录成功")
|
||||||
record_logging()
|
record_logging()
|
||||||
return fail_api(msg="用户名或密码错误")
|
return fail_api(message="用户名或密码错误")
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ class UserStatus(Resource):
|
|||||||
if res.operate == 1:
|
if res.operate == 1:
|
||||||
user = CompanyUser.query.get(user_id)
|
user = CompanyUser.query.get(user_id)
|
||||||
user.enable = res.operate
|
user.enable = res.operate
|
||||||
message = success_api(msg="启动成功")
|
message = success_api(message="启动成功")
|
||||||
else:
|
else:
|
||||||
user = CompanyUser.query.filter_by(id=res.user_id).update({"enable": res.operate})
|
user = CompanyUser.query.filter_by(id=res.user_id).update({"enable": res.operate})
|
||||||
message = success_api(msg="禁用成功")
|
message = success_api(message="禁用成功")
|
||||||
if user:
|
if user:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
else:
|
else:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(message="出错啦")
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ class UserAvatar(Resource):
|
|||||||
ret.avatar = url
|
ret.avatar = url
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if not ret:
|
if not ret:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(message="出错啦")
|
||||||
return success_api(msg="修改成功")
|
return success_api(message="修改成功")
|
||||||
|
|
||||||
|
|
||||||
class UserInfo(Resource):
|
class UserInfo(Resource):
|
||||||
@@ -63,8 +63,8 @@ class UserInfo(Resource):
|
|||||||
ret.remark = res.details
|
ret.remark = res.details
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if not ret:
|
if not ret:
|
||||||
return fail_api(msg="出错啦")
|
return fail_api(message="出错啦")
|
||||||
return success_api(msg="更新成功")
|
return success_api(message="更新成功")
|
||||||
|
|
||||||
|
|
||||||
class UserPassword(Resource):
|
class UserPassword(Resource):
|
||||||
@@ -80,15 +80,15 @@ class UserPassword(Resource):
|
|||||||
res = parser.parse_args()
|
res = parser.parse_args()
|
||||||
|
|
||||||
if res.newPassword != res.confirmPassword:
|
if res.newPassword != res.confirmPassword:
|
||||||
return fail_api(msg='确认密码不一致')
|
return fail_api(message='确认密码不一致')
|
||||||
|
|
||||||
""" 修改当前用户密码 """
|
""" 修改当前用户密码 """
|
||||||
user = CompanyUser.query.get(user_id)
|
user = CompanyUser.query.get(user_id)
|
||||||
is_right = user.validate_password(res.oldPassword)
|
is_right = user.validate_password(res.oldPassword)
|
||||||
if not is_right:
|
if not is_right:
|
||||||
return jsonify(success=False, msg="旧密码错误")
|
return jsonify(success=False, message="旧密码错误")
|
||||||
user.set_password(res.newPassword)
|
user.set_password(res.newPassword)
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return jsonify(success=True, msg="更改成功")
|
return jsonify(success=True, message="更改成功")
|
||||||
|
|||||||
@@ -90,12 +90,13 @@ class UserUsers(Resource):
|
|||||||
'username': item.username,
|
'username': item.username,
|
||||||
'realname': item.realname,
|
'realname': item.realname,
|
||||||
'enable': item.enable,
|
'enable': item.enable,
|
||||||
'create_at': item.create_at,
|
'create_at': str(item.create_at),
|
||||||
'update_at': item.update_at,
|
'update_at': str(item.update_at),
|
||||||
'dept': dept_name(item.dept_id),
|
'dept': dept_name(item.dept_id),
|
||||||
} for item in paginate.items]
|
} for item in paginate.items]
|
||||||
|
return table_api(result={'items': user_data,
|
||||||
return table_api(data=user_data, count=paginate.total, code=0)
|
'total': paginate.total}
|
||||||
|
, code=0)
|
||||||
|
|
||||||
@authorize("admin:user:add", log=True)
|
@authorize("admin:user:add", log=True)
|
||||||
def post(self):
|
def post(self):
|
||||||
@@ -111,7 +112,7 @@ class UserUsers(Resource):
|
|||||||
role_ids = res.role_ids.split(',')
|
role_ids = res.role_ids.split(',')
|
||||||
|
|
||||||
if is_user_exists(res.username):
|
if is_user_exists(res.username):
|
||||||
return fail_api(msg="用户已经存在")
|
return fail_api(message="用户已经存在")
|
||||||
|
|
||||||
user = CompanyUser()
|
user = CompanyUser()
|
||||||
user.username = res.username
|
user.username = res.username
|
||||||
@@ -127,14 +128,14 @@ class UserUsers(Resource):
|
|||||||
user.role.append(r)
|
user.role.append(r)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return success_api(msg="增加成功", code=0)
|
return success_api(message="增加成功", code=0)
|
||||||
|
|
||||||
@authorize("admin:user:remove", log=True)
|
@authorize("admin:user:remove", log=True)
|
||||||
def delete(self):
|
def delete(self):
|
||||||
"""批量删除"""
|
"""批量删除"""
|
||||||
ids = request.form.getlist('ids[]')
|
ids = request.form.getlist('ids[]')
|
||||||
batch_remove(ids)
|
batch_remove(ids)
|
||||||
return success_api(msg="批量删除成功")
|
return success_api(message="批量删除成功")
|
||||||
|
|
||||||
|
|
||||||
class UserUser(Resource):
|
class UserUser(Resource):
|
||||||
@@ -154,7 +155,7 @@ class UserUser(Resource):
|
|||||||
role_ids = res.role_ids.split(',')
|
role_ids = res.role_ids.split(',')
|
||||||
|
|
||||||
if is_user_exists(res.username):
|
if is_user_exists(res.username):
|
||||||
return fail_api(msg="用户已经存在")
|
return fail_api(message="用户已经存在")
|
||||||
|
|
||||||
user = CompanyUser()
|
user = CompanyUser()
|
||||||
user.username = res.username
|
user.username = res.username
|
||||||
@@ -170,15 +171,15 @@ class UserUser(Resource):
|
|||||||
user.role.append(r)
|
user.role.append(r)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return success_api(msg="增加成功", code=0)
|
return success_api(message="增加成功", code=0)
|
||||||
|
|
||||||
@authorize("admin:user:remove", log=True)
|
@authorize("admin:user:remove", log=True)
|
||||||
def delete(self, user_id):
|
def delete(self, user_id):
|
||||||
# 删除用户
|
# 删除用户
|
||||||
res = delete_by_id(user_id)
|
res = delete_by_id(user_id)
|
||||||
if not res:
|
if not res:
|
||||||
return fail_api(msg="删除失败")
|
return fail_api(message="删除失败")
|
||||||
return success_api(msg="删除成功")
|
return success_api(message="删除成功")
|
||||||
|
|
||||||
|
|
||||||
class UserRole(Resource):
|
class UserRole(Resource):
|
||||||
@@ -202,4 +203,4 @@ class UserRole(Resource):
|
|||||||
|
|
||||||
update_user_role(user_id, role_ids)
|
update_user_role(user_id, role_ids)
|
||||||
|
|
||||||
return success_api(msg="更新成功")
|
return success_api(message="更新成功")
|
||||||
|
|||||||
@@ -1,32 +1,36 @@
|
|||||||
from flask import jsonify
|
import typing as t
|
||||||
|
|
||||||
|
|
||||||
|
def success_api(message: str = "成功", code: int = 200) -> t.Dict:
|
||||||
|
""" 成功响应 默认值”成功“ """
|
||||||
|
return dict(success=True, message=message, code=code)
|
||||||
|
|
||||||
|
|
||||||
|
def fail_api(message: str = "失败", code: int = 404) -> t.Dict:
|
||||||
|
""" 失败响应 默认值“失败” """
|
||||||
|
return dict(success=False, message=message, code=code)
|
||||||
|
|
||||||
|
|
||||||
|
def table_api(success: bool = True,
|
||||||
|
message: str = "",
|
||||||
|
result: t.Union[dict, list] = None,
|
||||||
|
code: int = 0) -> t.Dict:
|
||||||
"""
|
"""
|
||||||
|
动态表格渲染响应
|
||||||
|
此方法返回数据给前端
|
||||||
{
|
{
|
||||||
'success': True,
|
'success': True,
|
||||||
'code': 10002,
|
'code': 10002,
|
||||||
'msg': '提示消息',
|
'message': '提示消息',
|
||||||
'data':[] or {}
|
'result':{'items':[],'total': 100}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
注:lay_ui 表格数据需要指定 code=0
|
||||||
"""
|
"""
|
||||||
|
ret = {
|
||||||
|
'success': success,
|
||||||
def success_api(msg: str = "成功", code=200):
|
'message': message,
|
||||||
""" 成功响应 默认值”成功“ """
|
|
||||||
return jsonify(success=True, msg=msg, code=200)
|
|
||||||
|
|
||||||
|
|
||||||
def fail_api(msg: str = "失败", code=404):
|
|
||||||
""" 失败响应 默认值“失败” """
|
|
||||||
return jsonify(success=False, msg=msg, code=404)
|
|
||||||
|
|
||||||
|
|
||||||
def table_api(msg: str = "", count=0, data=None, limit=10, code=200):
|
|
||||||
""" 动态表格渲染响应 """
|
|
||||||
res = {
|
|
||||||
'msg': msg,
|
|
||||||
'code': code,
|
'code': code,
|
||||||
'data': data,
|
'result': result,
|
||||||
'count': count,
|
|
||||||
'limit': limit
|
|
||||||
}
|
}
|
||||||
return jsonify(res)
|
return ret
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ def login_log():
|
|||||||
page=page, per_page=limit, error_out=False)
|
page=page, per_page=limit, error_out=False)
|
||||||
data = marshal(log_paginate.items, log_fields)
|
data = marshal(log_paginate.items, log_fields)
|
||||||
|
|
||||||
return table_api(data=data, count=log_paginate.total, code=0)
|
return table_api(result={'items': data,
|
||||||
|
'total': log_paginate.total, },
|
||||||
|
code=0)
|
||||||
|
|
||||||
|
|
||||||
@logs_bp.get('/access_log')
|
@logs_bp.get('/access_log')
|
||||||
@@ -40,4 +42,6 @@ def operate_log():
|
|||||||
desc(LoggingModel.create_at)).paginate(
|
desc(LoggingModel.create_at)).paginate(
|
||||||
page=page, per_page=limit, error_out=False)
|
page=page, per_page=limit, error_out=False)
|
||||||
data = marshal(log_paginate.items, log_fields)
|
data = marshal(log_paginate.items, log_fields)
|
||||||
return table_api(data=data, count=log_paginate.total, code=0)
|
return table_api(result={'items': data,
|
||||||
|
'total': log_paginate.total, },
|
||||||
|
code=0)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ def get_captcha():
|
|||||||
def logout():
|
def logout():
|
||||||
logout_user()
|
logout_user()
|
||||||
session.pop('permissions')
|
session.pop('permissions')
|
||||||
return success_api(msg="注销成功")
|
return success_api(message="注销成功")
|
||||||
|
|
||||||
|
|
||||||
@index_bp.get('/passport/login')
|
@index_bp.get('/passport/login')
|
||||||
|
|||||||
+17
-8
@@ -14,7 +14,7 @@ class Department {
|
|||||||
this.DEPARTMENT_API = {
|
this.DEPARTMENT_API = {
|
||||||
'DEPARTMENTS': () => `${this.DEPARTMENT_PATH}/departments`,
|
'DEPARTMENTS': () => `${this.DEPARTMENT_PATH}/departments`,
|
||||||
'DEPARTMENT': (dept_id) => `${this.DEPARTMENT_PATH}/department/${dept_id}`,
|
'DEPARTMENT': (dept_id) => `${this.DEPARTMENT_PATH}/department/${dept_id}`,
|
||||||
'DEPARTMENT_STATUS': (dept_id) => `${this.DEPARTMENT_PATH}/department/${dept_id}/status`
|
'DEPARTMENT_STATUS': (dept_id) => `${this.DEPARTMENT_PATH}/department/${dept_id}/status`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ class Rights {
|
|||||||
this.RIGHTS_API = {
|
this.RIGHTS_API = {
|
||||||
'RIGHTS': () => `${this.DEPARTMENT_PATH}/rights`,
|
'RIGHTS': () => `${this.DEPARTMENT_PATH}/rights`,
|
||||||
'POWER': (power_id) => `${this.DEPARTMENT_PATH}/power/${power_id}`,
|
'POWER': (power_id) => `${this.DEPARTMENT_PATH}/power/${power_id}`,
|
||||||
'POWER_STATUS': (power_id) => `${this.DEPARTMENT_PATH}/power/${power_id}/status`
|
'POWER_STATUS': (power_id) => `${this.DEPARTMENT_PATH}/power/${power_id}/status`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,16 +37,14 @@ class Role {
|
|||||||
'ROLES': () => `${this.ROLE_PATH}/roles`,
|
'ROLES': () => `${this.ROLE_PATH}/roles`,
|
||||||
'ROLE': (role_id) => `${this.ROLE_PATH}/role/${role_id}`,
|
'ROLE': (role_id) => `${this.ROLE_PATH}/role/${role_id}`,
|
||||||
'ROLE_STATUS': (role_id) => `${this.ROLE_PATH}/role/${role_id}/status`,
|
'ROLE_STATUS': (role_id) => `${this.ROLE_PATH}/role/${role_id}/status`,
|
||||||
'ROLE_POWER': (role_id) => `${this.ROLE_PATH}/role_power/${role_id}`
|
'ROLE_POWER': (role_id) => `${this.ROLE_PATH}/role_power/${role_id}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async get_roles () {
|
async get_roles () {
|
||||||
return fetch(this.ROLE_API.ROLES())
|
return fetch(this.ROLE_API.ROLES()).then(function (response) {
|
||||||
.then(function (response) {
|
|
||||||
return response.json()
|
return response.json()
|
||||||
})
|
}).then(function (myJson) {
|
||||||
.then(function (myJson) {
|
|
||||||
return myJson
|
return myJson
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -83,5 +81,16 @@ export {
|
|||||||
DEPARTMENT_API,
|
DEPARTMENT_API,
|
||||||
RIGHTS, RIGHTS_API,
|
RIGHTS, RIGHTS_API,
|
||||||
ROLE, ROLE_API,
|
ROLE, ROLE_API,
|
||||||
USER, USER_API
|
USER, USER_API,
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************数据解析********************************/
|
||||||
|
export function parserTableData (res) { //res 即为原始返回的数据
|
||||||
|
console.log('parserTableData', res)
|
||||||
|
return {
|
||||||
|
'code': res.code, //解析接口状态
|
||||||
|
'msg': res.message, //解析提示文本
|
||||||
|
'count': res.result.total, //解析数据长度
|
||||||
|
'data': res.result.items, //解析数据列表
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -39,15 +39,15 @@
|
|||||||
|
|
||||||
|
|
||||||
{#表格工具栏,需要在表格中绑定,且需要自定义事件#}
|
{#表格工具栏,需要在表格中绑定,且需要自定义事件#}
|
||||||
<script type="text/html" id="toolbaes">
|
<script type="text/html" id="toolbar">
|
||||||
{% if authorize("admin:dept:edit") %}
|
{% if authorize("admin:dept:edit") %}
|
||||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add_toggle">
|
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="toolbar-add">
|
||||||
<i class="layui-icon layui-icon-add-1"></i>
|
<i class="layui-icon layui-icon-add-1"></i>
|
||||||
新增
|
新增
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if authorize("admin:dept:remove") %}
|
{% if authorize("admin:dept:remove") %}
|
||||||
<button class="pear-btn pear-btn-md" lay-event="batch_remove">
|
<button class="pear-btn pear-btn-md" lay-event="toolbar-remove">
|
||||||
<i class="layui-icon layui-icon-delete"></i>
|
<i class="layui-icon layui-icon-delete"></i>
|
||||||
删除
|
删除
|
||||||
</button>
|
</button>
|
||||||
@@ -88,6 +88,19 @@
|
|||||||
let popup = layui.popup
|
let popup = layui.popup
|
||||||
|
|
||||||
let MODULE_PATH = '/dept/'
|
let MODULE_PATH = '/dept/'
|
||||||
|
const get_columns = () => [
|
||||||
|
[
|
||||||
|
{ type: 'checkbox' },
|
||||||
|
{ field: 'deptName', minWidth: 200, title: '部门名称' },
|
||||||
|
{ field: 'leader', title: '负责人' },
|
||||||
|
{ field: 'phone', title: '联系方式' },
|
||||||
|
{ field: 'email', title: '邮箱' },
|
||||||
|
{ field: 'address', title: '详细地址' },
|
||||||
|
{ field: 'status', title: '状态', templet: '#dept-status' },
|
||||||
|
{ field: 'sort', title: '排序', width: 100 },
|
||||||
|
{ title: '操作', templet: '#tool', width: 120, align: 'center' },
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
{#定义表格渲染函数#}
|
{#定义表格渲染函数#}
|
||||||
window.render = function () {
|
window.render = function () {
|
||||||
@@ -100,23 +113,11 @@
|
|||||||
skin: 'line',
|
skin: 'line',
|
||||||
method: 'post', /**/
|
method: 'post', /**/
|
||||||
treeDefaultClose: false,
|
treeDefaultClose: false,
|
||||||
toolbar: '#toolbaes', /*表格的工具栏*/
|
toolbar: '#toolbar', /*表格的工具栏*/
|
||||||
elem: '#tables', /*表格挂载的对象*/
|
elem: '#tables', /*表格挂载的对象*/
|
||||||
url: DEPARTMENT_API.DEPARTMENTS(), /*数据来源接口*/
|
url: DEPARTMENT_API.DEPARTMENTS(), /*数据来源接口*/
|
||||||
page: false,
|
page: false,
|
||||||
cols: [
|
cols: get_columns(),/*表格渲染的数据*/
|
||||||
[
|
|
||||||
{ type: 'checkbox' },
|
|
||||||
{ field: 'deptName', minWidth: 200, title: '部门名称' },
|
|
||||||
{ field: 'leader', title: '负责人' },
|
|
||||||
{ field: 'phone', title: '联系方式' },
|
|
||||||
{ field: 'email', title: '邮箱' },
|
|
||||||
{ field: 'address', title: '详细地址' },
|
|
||||||
{ field: 'status', title: '状态', templet: '#dept-status' },
|
|
||||||
{ field: 'sort', title: '排序', width: 100 },
|
|
||||||
{ title: '操作', templet: '#tool', width: 120, align: 'center' }
|
|
||||||
]
|
|
||||||
]/*表格渲染的数据*/
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,12 +168,12 @@
|
|||||||
/*表格的工具栏*/
|
/*表格的工具栏*/
|
||||||
table.on('toolbar(tables)', function (obj) {
|
table.on('toolbar(tables)', function (obj) {
|
||||||
{#console.log(obj)#}
|
{#console.log(obj)#}
|
||||||
if (obj.event === 'add_toggle') {
|
if (obj.event === 'toolbar-add') {
|
||||||
window.add_toggle()
|
window.toolbar_add()
|
||||||
} else if (obj.event === 'refresh') {
|
} else if (obj.event === 'refresh') {
|
||||||
window.refresh()
|
window.refresh()
|
||||||
} else if (obj.event === 'batch_remove') {
|
} else if (obj.event === 'toolbar-remove') {
|
||||||
{#window.batch_remove(obj)#}
|
{#window.toolbar_remove(obj)#}
|
||||||
layer.msg('禁止批量删除')
|
layer.msg('禁止批量删除')
|
||||||
return false
|
return false
|
||||||
{#console.log(table.checkStatus(obj.config.id).data)#}
|
{#console.log(table.checkStatus(obj.config.id).data)#}
|
||||||
@@ -197,21 +198,21 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg)
|
popup.success(result.message)
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
popup.failure(result.message)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
window.add_toggle = function () {
|
window.toolbar_add = function () {
|
||||||
layer.open({
|
layer.open({
|
||||||
type: 2,
|
type: 2,
|
||||||
title: '新增',
|
title: '新增',
|
||||||
shade: 0.1,
|
shade: 0.1,
|
||||||
area: ['450px', '500px'], /*新增窗口的大小*/
|
area: ['450px', '500px'], /*新增窗口的大小*/
|
||||||
content: '/dept/add' /*新增窗口从那里来*/
|
content: '/dept/add', /*新增窗口从那里来*/
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +223,7 @@
|
|||||||
title: '修改',
|
title: '修改',
|
||||||
shade: 0.1,
|
shade: 0.1,
|
||||||
area: ['450px', '500px'],
|
area: ['450px', '500px'],
|
||||||
content: MODULE_PATH + 'edit?deptId=' + obj.data['deptId'] /*编辑修改窗口从那里来*/
|
content: MODULE_PATH + 'edit?deptId=' + obj.data['deptId'], /*编辑修改窗口从那里来*/
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -238,13 +239,13 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.message, function () {
|
||||||
obj.del()
|
obj.del()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
popup.failure(result.message)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,12 +111,12 @@
|
|||||||
type: 'post',
|
type: 'post',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name))
|
parent.layer.close(parent.layer.getFrameIndex(window.name))
|
||||||
parent.render()
|
parent.render()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -111,12 +111,12 @@
|
|||||||
type: 'put',
|
type: 'put',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
||||||
parent.render()
|
parent.render()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { FILE_API } from '/static/api/http.js'
|
import { FILE_API, parserTableData as parseData } from '/static/api/http.js'
|
||||||
|
|
||||||
layui.use(['table', 'form', 'jquery', 'element', 'form', 'upload'], function () {
|
layui.use(['table', 'form', 'jquery', 'element', 'form', 'upload'], function () {
|
||||||
let table = layui.table
|
let table = layui.table
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
let $ = layui.jquery
|
let $ = layui.jquery
|
||||||
let upload = layui.upload
|
let upload = layui.upload
|
||||||
|
|
||||||
let cols = [
|
const get_columns = () => [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
@@ -98,10 +98,11 @@
|
|||||||
]
|
]
|
||||||
|
|
||||||
table.render({
|
table.render({
|
||||||
|
parseData,
|
||||||
elem: '#tables',
|
elem: '#tables',
|
||||||
url: FILE_API.PHOTOS(),
|
url: FILE_API.PHOTOS(),
|
||||||
page: true,
|
page: true,
|
||||||
cols: cols,
|
cols: get_columns(),
|
||||||
skin: 'line',
|
skin: 'line',
|
||||||
toolbar: '#toolbar',
|
toolbar: '#toolbar',
|
||||||
defaultToolbar: [
|
defaultToolbar: [
|
||||||
|
|||||||
@@ -51,12 +51,12 @@
|
|||||||
, bindAction: '#logo-upload-button'
|
, bindAction: '#logo-upload-button'
|
||||||
, done: function (res) {
|
, done: function (res) {
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
layer.msg(res.msg, { icon: 1, time: 500 }, function () {
|
layer.msg(res.message, { icon: 1, time: 500 }, function () {
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
||||||
window.parent.location.reload()
|
window.parent.location.reload()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(res.msg, { icon: 2 })
|
layer.msg(res.message, { icon: 2 })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -40,14 +40,16 @@
|
|||||||
{{# } }}'|safe }}
|
{{# } }}'|safe }}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script type="module">
|
||||||
|
import { parserTableData as parseData } from '/static/api/http.js'
|
||||||
|
|
||||||
layui.use(['table', 'form', 'jquery', 'element', 'util'], function () {
|
layui.use(['table', 'form', 'jquery', 'element', 'util'], function () {
|
||||||
let table = layui.table
|
let table = layui.table
|
||||||
let form = layui.form
|
let form = layui.form
|
||||||
|
|
||||||
let MODULE_PATH = '/logs/'
|
let MODULE_PATH = '/logs/'
|
||||||
|
|
||||||
let cols = [
|
const get_columns = () => [
|
||||||
[
|
[
|
||||||
{ title: 'ID', field: 'id', align: 'center' },
|
{ title: 'ID', field: 'id', align: 'center' },
|
||||||
{ title: '请求方式', field: 'method', align: 'center' },
|
{ title: '请求方式', field: 'method', align: 'center' },
|
||||||
@@ -62,19 +64,21 @@
|
|||||||
]
|
]
|
||||||
|
|
||||||
table.render({
|
table.render({
|
||||||
|
parseData,
|
||||||
elem: '#log-access-table',
|
elem: '#log-access-table',
|
||||||
url: MODULE_PATH + 'access_log',
|
url: MODULE_PATH + 'access_log',
|
||||||
page: true,
|
page: true,
|
||||||
cols: cols,
|
cols: get_columns(),
|
||||||
skin: 'line',
|
skin: 'line',
|
||||||
toolbar: false,
|
toolbar: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
table.render({
|
table.render({
|
||||||
|
parseData,
|
||||||
elem: '#log-login-table',
|
elem: '#log-login-table',
|
||||||
url: MODULE_PATH + 'login_log',
|
url: MODULE_PATH + 'login_log',
|
||||||
page: true,
|
page: true,
|
||||||
cols: cols,
|
cols: get_columns(),
|
||||||
skin: 'line',
|
skin: 'line',
|
||||||
toolbar: false,
|
toolbar: false,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { RIGHTS_API } from '/static/api/http.js'
|
import { RIGHTS_API, parserTableData as parseData } from '/static/api/http.js'
|
||||||
|
|
||||||
layui.use(['table', 'form', 'jquery', 'treetable', 'popup', 'dtree', 'iconPicker'], function () {
|
layui.use(['table', 'form', 'jquery', 'treetable', 'popup', 'dtree', 'iconPicker'], function () {
|
||||||
let table = layui.table
|
let table = layui.table
|
||||||
@@ -65,20 +65,7 @@
|
|||||||
let iconPicker = layui.iconPicker
|
let iconPicker = layui.iconPicker
|
||||||
let dtree = layui.dtree
|
let dtree = layui.dtree
|
||||||
|
|
||||||
window.render = function () {
|
const get_columns = () => [
|
||||||
treetable.render({
|
|
||||||
treeColIndex: 1,
|
|
||||||
treeSpid: 0,
|
|
||||||
treeIdName: 'powerId',
|
|
||||||
treePidName: 'parentId',
|
|
||||||
skin: 'line',
|
|
||||||
method: 'post',
|
|
||||||
treeDefaultClose: true,
|
|
||||||
toolbar: '#toolbar',
|
|
||||||
elem: '#tables',
|
|
||||||
url: RIGHTS_API.RIGHTS(),
|
|
||||||
page: false,
|
|
||||||
cols: [
|
|
||||||
[
|
[
|
||||||
{ type: 'checkbox' },
|
{ type: 'checkbox' },
|
||||||
{ field: 'powerName', minWidth: 200, title: '权限名称' },
|
{ field: 'powerName', minWidth: 200, title: '权限名称' },
|
||||||
@@ -104,11 +91,22 @@
|
|||||||
{ field: 'sort', title: '排序' },
|
{ field: 'sort', title: '排序' },
|
||||||
{ title: '操作', templet: '#tool', width: 150, align: 'center' },
|
{ title: '操作', templet: '#tool', width: 150, align: 'center' },
|
||||||
],
|
],
|
||||||
],
|
]
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
render()
|
treetable.render({
|
||||||
|
treeColIndex: 1,
|
||||||
|
treeSpid: 0,
|
||||||
|
treeIdName: 'powerId',
|
||||||
|
treePidName: 'parentId',
|
||||||
|
skin: 'line',
|
||||||
|
method: 'post',
|
||||||
|
treeDefaultClose: true,
|
||||||
|
toolbar: '#toolbar',
|
||||||
|
elem: '#tables',
|
||||||
|
url: RIGHTS_API.RIGHTS(),
|
||||||
|
page: false,
|
||||||
|
cols: get_columns(),
|
||||||
|
})
|
||||||
|
|
||||||
form.on('submit(power_query)', function (data) {
|
form.on('submit(power_query)', function (data) {
|
||||||
var keyword = data.field.powerName
|
var keyword = data.field.powerName
|
||||||
@@ -173,9 +171,9 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg)
|
popup.success(result.message)
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
popup.failure(result.message)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -211,12 +209,12 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.message, function () {
|
||||||
console.log(obj)
|
console.log(obj)
|
||||||
obj.del()
|
obj.del()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
popup.failure(result.message)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -138,12 +138,12 @@
|
|||||||
type: 'post',
|
type: 'post',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
||||||
parent.render()
|
parent.render()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -153,12 +153,12 @@
|
|||||||
type: 'put',
|
type: 'put',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
||||||
parent.render()
|
parent.render()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { ROLE_API } from '/static/api/http.js'
|
import { ROLE_API, parserTableData as parseData } from '/static/api/http.js'
|
||||||
|
|
||||||
layui.use(['table', 'form', 'jquery', 'popup', 'common'], function () {
|
layui.use(['table', 'form', 'jquery', 'popup', 'common'], function () {
|
||||||
let table = layui.table
|
let table = layui.table
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
let $ = layui.jquery
|
let $ = layui.jquery
|
||||||
let popup = layui.popup
|
let popup = layui.popup
|
||||||
|
|
||||||
let cols = [
|
const get_columns = () => [
|
||||||
[
|
[
|
||||||
{ type: 'checkbox' },
|
{ type: 'checkbox' },
|
||||||
{ title: '角色名', field: 'roleName', align: 'center', width: 100 },
|
{ title: '角色名', field: 'roleName', align: 'center', width: 100 },
|
||||||
@@ -85,10 +85,11 @@
|
|||||||
]
|
]
|
||||||
|
|
||||||
table.render({
|
table.render({
|
||||||
|
parseData,
|
||||||
elem: '#tables',
|
elem: '#tables',
|
||||||
url: ROLE_API.ROLES(),
|
url: ROLE_API.ROLES(),
|
||||||
page: true,
|
page: true,
|
||||||
cols: cols,
|
cols: get_columns(),
|
||||||
skin: 'line',
|
skin: 'line',
|
||||||
toolbar: '#toolbar',
|
toolbar: '#toolbar',
|
||||||
defaultToolbar: [
|
defaultToolbar: [
|
||||||
@@ -140,9 +141,9 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 })
|
layer.msg(result.message, { icon: 1, time: 1000 })
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -189,11 +190,11 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
||||||
obj.del()
|
obj.del()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -233,11 +234,11 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.message, function () {
|
||||||
table.reload('tables')
|
table.reload('tables')
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
popup.failure(result.message)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -76,12 +76,12 @@
|
|||||||
type: 'post',
|
type: 'post',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
||||||
parent.layui.table.reload('role-table')
|
parent.layui.table.reload('tables')
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -91,12 +91,12 @@
|
|||||||
type: 'put',
|
type: 'put',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
||||||
parent.layui.table.reload('role-table')
|
parent.layui.table.reload('role-table')
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -68,11 +68,11 @@
|
|||||||
type: 'put',
|
type: 'put',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name))
|
parent.layer.close(parent.layer.getFrameIndex(window.name))
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -300,12 +300,12 @@
|
|||||||
type: 'put',
|
type: 'put',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.message, function () {
|
||||||
// TODO 关闭修改密码成之后的窗口
|
// TODO 关闭修改密码成之后的窗口
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name))
|
parent.layer.close(parent.layer.getFrameIndex(window.name))
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
popup.failure(result.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -94,7 +94,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { USER_API, ROLE } from '/static/api/http.js'
|
import { USER_API, ROLE, parserTableData as parseData } from '/static/api/http.js'
|
||||||
|
|
||||||
layui.use(['table', 'dtree', 'form', 'jquery', 'popup', 'common'], function () {
|
layui.use(['table', 'dtree', 'form', 'jquery', 'popup', 'common'], function () {
|
||||||
let table = layui.table
|
let table = layui.table
|
||||||
@@ -105,7 +105,7 @@
|
|||||||
let common = layui.common
|
let common = layui.common
|
||||||
|
|
||||||
// 表格数据
|
// 表格数据
|
||||||
let cols = [
|
const get_columns = () => [
|
||||||
[
|
[
|
||||||
{ type: 'checkbox' },
|
{ type: 'checkbox' },
|
||||||
{ title: '姓名', field: 'realname', align: 'center', width: 110 },
|
{ title: '姓名', field: 'realname', align: 'center', width: 110 },
|
||||||
@@ -120,10 +120,11 @@
|
|||||||
|
|
||||||
// 渲染表格数据
|
// 渲染表格数据
|
||||||
table.render({
|
table.render({
|
||||||
|
parseData,
|
||||||
elem: '#tables',
|
elem: '#tables',
|
||||||
url: USER_API.USERS(),
|
url: USER_API.USERS(),
|
||||||
page: true,
|
page: true,
|
||||||
cols: cols,
|
cols: get_columns(),
|
||||||
skin: 'line',
|
skin: 'line',
|
||||||
height: 'full-148',
|
height: 'full-148',
|
||||||
toolbar: '#toolbar', /*工具栏*/
|
toolbar: '#toolbar', /*工具栏*/
|
||||||
@@ -214,9 +215,9 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg)
|
popup.success(result.message)
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
popup.failure(result.message)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -264,11 +265,11 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.message, function () {
|
||||||
table.reload('role-table')
|
table.reload('role-table')
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
popup.failure(result.message)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -289,11 +290,11 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.message, function () {
|
||||||
obj.del()
|
obj.del()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg)
|
popup.failure(result.message)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -82,12 +82,12 @@
|
|||||||
type: 'post',
|
type: 'post',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
|
||||||
parent.layui.table.reload('user-table')
|
parent.layui.table.reload('tables')
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -105,12 +105,12 @@
|
|||||||
type: 'put',
|
type: 'put',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
|
layer.msg(result.message, { icon: 1, time: 1000 }, function () {
|
||||||
parent.layer.close(parent.layer.getFrameIndex(window.name)) //关闭当前页
|
parent.layer.close(parent.layer.getFrameIndex(window.name)) //关闭当前页
|
||||||
parent.layui.table.reload('user-table')
|
parent.layui.table.reload('tables')
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
layer.msg(result.msg, { icon: 2, time: 1000 })
|
layer.msg(result.message, { icon: 2, time: 1000 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -104,7 +104,7 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
layer.close(loading)
|
layer.close(loading)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.message, function () {
|
||||||
location.href = '/admin'
|
location.href = '/admin'
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -61,11 +61,11 @@
|
|||||||
layer.close(loader) // 关闭加载按钮
|
layer.close(loader) // 关闭加载按钮
|
||||||
btn.stop(function () {
|
btn.stop(function () {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.message, function () {
|
||||||
location.href = '/admin'
|
location.href = '/admin'
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg, function () {
|
popup.failure(result.success, function () {
|
||||||
document.getElementById('captchaImage').src = captchaPath + '?' + Math.random()
|
document.getElementById('captchaImage').src = captchaPath + '?' + Math.random()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user