From b6f769b259ef25cef68a9d9877caf824ae4e5069 Mon Sep 17 00:00:00 2001 From: smock Date: Sat, 17 Jun 2023 16:50:15 +0800 Subject: [PATCH 1/2] delete dept --- applications/common/script/admin.py | 138 ++++----- applications/config.py | 14 +- applications/models/__init__.py | 2 +- applications/models/admin_dept.py | 32 +- applications/view/__init__.py | 4 +- applications/view/admin/user.py | 30 +- applications/view/department/__init__.py | 288 +++++++++--------- .../templates/helloworld_index.html | 2 +- .../templates/replacePage_index.html | 2 +- static/admin/admin/data/menu.json | 1 - templates/admin/index.html | 7 +- templates/admin/user/edit.html | 26 +- templates/admin/user/main.html | 38 +-- templates/index/index.html | 41 +-- 14 files changed, 301 insertions(+), 324 deletions(-) diff --git a/applications/common/script/admin.py b/applications/common/script/admin.py index 2cf3941..eb09484 100644 --- a/applications/common/script/admin.py +++ b/applications/common/script/admin.py @@ -3,7 +3,7 @@ import datetime from flask.cli import AppGroup from applications.extensions import db -from applications.models import User, Role, Dept, Power +from applications.models import User, Role, Power admin_cli = AppGroup("admin") @@ -63,72 +63,72 @@ roledata = [ create_time=now_time, ) ] -deptdata = [ - Dept( - id=1, - parent_id=0, - dept_name='总公司', - sort=1, - leader='就眠仪式', - phone='12312345679', - email='123qq.com', - status=1, - remark='这是总公司', - create_at=now_time - ), - Dept( - id=4, - parent_id=1, - dept_name='济南分公司', - sort=2, - leader='就眠仪式', - phone='12312345679', - email='123qq.com', - status=1, - remark='这是济南', - create_at=now_time - - ), - Dept( - id=5, - parent_id=1, - dept_name='唐山分公司', - sort=4, - leader='mkg', - phone='12312345679', - email='123qq.com', - status=1, - remark='这是唐山', - create_at=now_time - - ), - Dept( - id=7, - parent_id=4, - dept_name='济南分公司开发部', - sort=5, - leader='就眠仪式', - phone='12312345679', - email='123qq.com', - status=1, - remark='测试', - create_at=now_time - - ), - Dept( - id=8, - parent_id=5, - dept_name='唐山测试部', - sort=5, - leader='mkg', - phone='12312345679', - email='123qq.com', - status=1, - remark='测试部', - create_at=now_time - - ) -] +# deptdata = [ +# Dept( +# id=1, +# parent_id=0, +# dept_name='总公司', +# sort=1, +# leader='就眠仪式', +# phone='12312345679', +# email='123qq.com', +# status=1, +# remark='这是总公司', +# create_at=now_time +# ), +# Dept( +# id=4, +# parent_id=1, +# dept_name='济南分公司', +# sort=2, +# leader='就眠仪式', +# phone='12312345679', +# email='123qq.com', +# status=1, +# remark='这是济南', +# create_at=now_time + +# ), +# Dept( +# id=5, +# parent_id=1, +# dept_name='唐山分公司', +# sort=4, +# leader='mkg', +# phone='12312345679', +# email='123qq.com', +# status=1, +# remark='这是唐山', +# create_at=now_time + +# ), +# Dept( +# id=7, +# parent_id=4, +# dept_name='济南分公司开发部', +# sort=5, +# leader='就眠仪式', +# phone='12312345679', +# email='123qq.com', +# status=1, +# remark='测试', +# create_at=now_time + +# ), +# Dept( +# id=8, +# parent_id=5, +# dept_name='唐山测试部', +# sort=5, +# leader='mkg', +# phone='12312345679', +# email='123qq.com', +# status=1, +# remark='测试部', +# create_at=now_time + +# ) +# ] powerdata = [ Power( id=1, @@ -562,8 +562,8 @@ def init_db(): print("加载系统必须用户数据") db.session.add_all(roledata) print("加载系统必须角色数据") - db.session.add_all(deptdata) - print("加载系统必须部门数据") + # db.session.add_all(deptdata) + # print("加载系统必须部门数据") db.session.add_all(powerdata) print("加载系统必须权限数据") db.session.commit() diff --git a/applications/config.py b/applications/config.py index 387bbaf..3b511dc 100644 --- a/applications/config.py +++ b/applications/config.py @@ -5,23 +5,23 @@ from urllib.parse import quote_plus as urlquote class BaseConfig: SUPERADMIN = 'admin' - SYSTEM_NAME = 'Pear Admin' + SYSTEM_NAME = 'hml admin' # 主题面板的链接列表配置 SYSTEM_PANEL_LINKS = [ { "icon": "layui-icon layui-icon-auz", "title": "官方网站", - "href": "http://www.pearadmin.com" + "href": "/" }, { "icon": "layui-icon layui-icon-auz", "title": "开发文档", - "href": "http://www.pearadmin.com" + "href": "/" }, { "icon": "layui-icon layui-icon-auz", "title": "开源地址", - "href": "https://gitee.com/Jmysy/Pear-Admin-Layui" + "href": "/" } ] @@ -32,12 +32,12 @@ class BaseConfig: # JSON配置 JSON_AS_ASCII = False - SECRET_KEY = "pear-admin-flask" + SECRET_KEY = "hml-session-sec-key" # mysql 配置 MYSQL_USERNAME = "root" - MYSQL_PASSWORD = "123456" - MYSQL_HOST = "127.0.0.1" + MYSQL_PASSWORD = "Brr0qZo6uo#6" + MYSQL_HOST = "121.5.62.78" MYSQL_PORT = 3306 MYSQL_DATABASE = "PearAdminFlask" diff --git a/applications/models/__init__.py b/applications/models/__init__.py index d94b265..c2b6fc4 100644 --- a/applications/models/__init__.py +++ b/applications/models/__init__.py @@ -1,4 +1,4 @@ -from .admin_dept import Dept +# from .admin_dept import Dept from .admin_dict import DictType, DictData from .admin_log import AdminLog from .admin_photo import Photo diff --git a/applications/models/admin_dept.py b/applications/models/admin_dept.py index 7ecb516..fedf528 100644 --- a/applications/models/admin_dept.py +++ b/applications/models/admin_dept.py @@ -1,18 +1,18 @@ -import datetime -from applications.extensions import db +# import datetime +# from applications.extensions import db -class Dept(db.Model): - __tablename__ = 'admin_dept' - id = db.Column(db.Integer, primary_key=True, comment="部门ID") - parent_id = db.Column(db.Integer, comment="父级编号") - dept_name = db.Column(db.String(50), comment="部门名称") - sort = db.Column(db.Integer, comment="排序") - leader = db.Column(db.String(50), comment="负责人") - phone = db.Column(db.String(20), comment="联系方式") - email = db.Column(db.String(50), comment="邮箱") - status = db.Column(db.Integer, comment='状态(1开启,0关闭)') - remark = db.Column(db.Text, comment="备注") - address = db.Column(db.String(255), comment="详细地址") - create_at = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间') - update_at = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='创建时间') \ No newline at end of file +# class Dept(db.Model): +# __tablename__ = 'admin_dept' +# id = db.Column(db.Integer, primary_key=True, comment="部门ID") +# parent_id = db.Column(db.Integer, comment="父级编号") +# dept_name = db.Column(db.String(50), comment="部门名称") +# sort = db.Column(db.Integer, comment="排序") +# leader = db.Column(db.String(50), comment="负责人") +# phone = db.Column(db.String(20), comment="联系方式") +# email = db.Column(db.String(50), comment="邮箱") +# status = db.Column(db.Integer, comment='状态(1开启,0关闭)') +# remark = db.Column(db.Text, comment="备注") +# address = db.Column(db.String(255), comment="详细地址") +# create_at = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间') +# update_at = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='创建时间') \ No newline at end of file diff --git a/applications/view/__init__.py b/applications/view/__init__.py index 6b5cf78..e0dbf66 100644 --- a/applications/view/__init__.py +++ b/applications/view/__init__.py @@ -2,7 +2,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.department import register_dept_views from applications.view.plugin import register_plugin_views def init_view(app): @@ -10,5 +10,5 @@ def init_view(app): register_index_views(app) register_rights_view(app) register_passport_views(app) - register_dept_views(app) + # register_dept_views(app) register_plugin_views(app) diff --git a/applications/view/admin/user.py b/applications/view/admin/user.py index 30a6bd1..64ff195 100644 --- a/applications/view/admin/user.py +++ b/applications/view/admin/user.py @@ -8,7 +8,7 @@ from applications.common.utils.http import table_api, fail_api, success_api from applications.common.utils.rights import authorize from applications.common.utils.validate import str_escape from applications.extensions import db -from applications.models import Role, Dept +from applications.models import Role from applications.models import User, AdminLog admin_user = Blueprint('adminUser', __name__, url_prefix='/admin/user') @@ -29,21 +29,24 @@ def data(): 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) + # dept_id = request.args.get('deptId', type=int) filters = [] if real_name: filters.append(User.realname.contains(real_name)) if username: filters.append(User.realname.contains(username)) - if dept_id: - filters.append(User.realname == dept_id) + # if dept_id: + # filters.append(User.realname == dept_id) # print(*filters) + # query = db.session.query( + # User, + # Dept + # ).filter(*filters).outerjoin(Dept, User.dept_id == Dept.id).layui_paginate() query = db.session.query( - User, - Dept - ).filter(*filters).outerjoin(Dept, User.dept_id == Dept.id).layui_paginate() + User + ).filter(*filters).layui_paginate() return table_api( data=[{ @@ -52,14 +55,11 @@ def data(): 'realname': user.realname, 'enable': user.enable, 'create_at': user.create_at, - 'update_at': user.update_at, - 'dept_name': dept.dept_name if dept else None - } for user, dept in query.items], + 'update_at': user.update_at + } for user in query.items], count=query.total) - # 用户增加 - - +# 用户增加 @admin_user.get('/add') @authorize("admin:user:add", log=True) def add(): @@ -127,9 +127,9 @@ def update(): id = str_escape(req_json.get("userId")) username = str_escape(req_json.get('username')) real_name = str_escape(req_json.get('realName')) - dept_id = str_escape(req_json.get('deptId')) + # dept_id = str_escape(req_json.get('deptId')) role_ids = a.split(',') - User.query.filter_by(id=id).update({'username': username, 'realname': real_name, 'dept_id': dept_id}) + User.query.filter_by(id=id).update({'username': username, 'realname': real_name}) u = User.query.filter_by(id=id).first() roles = Role.query.filter(Role.id.in_(role_ids)).all() diff --git a/applications/view/department/__init__.py b/applications/view/department/__init__.py index 82abac3..a1c2cbf 100644 --- a/applications/view/department/__init__.py +++ b/applications/view/department/__init__.py @@ -1,144 +1,144 @@ -from flask import Blueprint, render_template, request, jsonify - -from applications.common import curd -from applications.common.utils import validate -from applications.common.utils.http import success_api, fail_api -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 - -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) -def main(): - return render_template('admin/dept/main.html') - - -@dept_bp.post('/data') -@authorize("admin:dept:main", log=True) -def data(): - dept = Dept.query.order_by(Dept.sort).all() - power_data = curd.model_to_dicts(schema=DeptOutSchema, data=dept) - res = { - "data": power_data - } - return jsonify(res) - - -@dept_bp.get('/add') -@authorize("admin:dept:add", log=True) -def add(): - return render_template('admin/dept/add.html') - - -@dept_bp.get('/tree') -@authorize("admin:dept:main", log=True) -def tree(): - dept = Dept.query.order_by(Dept.sort).all() - power_data = curd.model_to_dicts(schema=DeptOutSchema, data=dept) - res = { - "status": {"code": 200, "message": "默认"}, - "data": power_data - - } - return jsonify(res) - - -@dept_bp.post('/save') -@authorize("admin:dept:add", log=True) -def save(): - req_json = request.get_json(force=True) - dept = Dept( - parent_id=req_json.get('parentId'), - dept_name=str_escape(req_json.get('deptName')), - sort=str_escape(req_json.get('sort')), - leader=str_escape(req_json.get('leader')), - phone=str_escape(req_json.get('phone')), - email=str_escape(req_json.get('email')), - status=str_escape(req_json.get('status')), - address=str_escape(req_json.get('address')) - ) - r = db.session.add(dept) - db.session.commit() - return success_api(msg="成功") - - -@dept_bp.get('/edit') -@authorize("admin: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) - - -# 启用 -@dept_bp.put('/enable') -@authorize("admin:dept:edit", log=True) -def enable(): - id = request.get_json(force=True).get('deptId') - if id: - enable = 1 - d = Dept.query.filter_by(id=id).update({"status": enable}) - if d: - db.session.commit() - return success_api(msg="启用成功") - return fail_api(msg="出错啦") - return fail_api(msg="数据错误") - - -# 禁用 -@dept_bp.put('/disable') -@authorize("admin:dept:edit", log=True) -def dis_enable(): - id = request.get_json(force=True).get('deptId') - if id: - enable = 0 - d = Dept.query.filter_by(id=id).update({"status": enable}) - if d: - db.session.commit() - return success_api(msg="禁用成功") - return fail_api(msg="出错啦") - return fail_api(msg="数据错误") - - -@dept_bp.put('/update') -@authorize("admin:dept:edit", log=True) -def update(): - json = request.get_json(force=True) - id = json.get("deptId"), - data = { - "dept_name": validate.str_escape(json.get("deptName")), - "sort": validate.str_escape(json.get("sort")), - "leader": validate.str_escape(json.get("leader")), - "phone": validate.str_escape(json.get("phone")), - "email": validate.str_escape(json.get("email")), - "status": validate.str_escape(json.get("status")), - "address": validate.str_escape(json.get("address")) - } - d = Dept.query.filter_by(id=id).update(data) - if not d: - return fail_api(msg="更新失败") - db.session.commit() - return success_api(msg="更新成功") - - -@dept_bp.delete('/remove/') -@authorize("admin:dept:remove", log=True) -def remove(_id): - d = Dept.query.filter_by(id=_id).delete() - if not d: - return fail_api(msg="删除失败") - res = User.query.filter_by(dept_id=_id).update({"dept_id": None}) - db.session.commit() - if res: - return success_api(msg="删除成功") - else: - return fail_api(msg="删除失败") +# from flask import Blueprint, render_template, request, jsonify + +# from applications.common import curd +# from applications.common.utils import validate +# from applications.common.utils.http import success_api, fail_api +# 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 + +# 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) +# def main(): +# return render_template('admin/dept/main.html') + + +# @dept_bp.post('/data') +# @authorize("admin:dept:main", log=True) +# def data(): +# dept = Dept.query.order_by(Dept.sort).all() +# power_data = curd.model_to_dicts(schema=DeptOutSchema, data=dept) +# res = { +# "data": power_data +# } +# return jsonify(res) + + +# @dept_bp.get('/add') +# @authorize("admin:dept:add", log=True) +# def add(): +# return render_template('admin/dept/add.html') + + +# @dept_bp.get('/tree') +# @authorize("admin:dept:main", log=True) +# def tree(): +# dept = Dept.query.order_by(Dept.sort).all() +# power_data = curd.model_to_dicts(schema=DeptOutSchema, data=dept) +# res = { +# "status": {"code": 200, "message": "默认"}, +# "data": power_data + +# } +# return jsonify(res) + + +# @dept_bp.post('/save') +# @authorize("admin:dept:add", log=True) +# def save(): +# req_json = request.get_json(force=True) +# dept = Dept( +# parent_id=req_json.get('parentId'), +# dept_name=str_escape(req_json.get('deptName')), +# sort=str_escape(req_json.get('sort')), +# leader=str_escape(req_json.get('leader')), +# phone=str_escape(req_json.get('phone')), +# email=str_escape(req_json.get('email')), +# status=str_escape(req_json.get('status')), +# address=str_escape(req_json.get('address')) +# ) +# r = db.session.add(dept) +# db.session.commit() +# return success_api(msg="成功") + + +# @dept_bp.get('/edit') +# @authorize("admin: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) + + +# # 启用 +# @dept_bp.put('/enable') +# @authorize("admin:dept:edit", log=True) +# def enable(): +# id = request.get_json(force=True).get('deptId') +# if id: +# enable = 1 +# d = Dept.query.filter_by(id=id).update({"status": enable}) +# if d: +# db.session.commit() +# return success_api(msg="启用成功") +# return fail_api(msg="出错啦") +# return fail_api(msg="数据错误") + + +# # 禁用 +# @dept_bp.put('/disable') +# @authorize("admin:dept:edit", log=True) +# def dis_enable(): +# id = request.get_json(force=True).get('deptId') +# if id: +# enable = 0 +# d = Dept.query.filter_by(id=id).update({"status": enable}) +# if d: +# db.session.commit() +# return success_api(msg="禁用成功") +# return fail_api(msg="出错啦") +# return fail_api(msg="数据错误") + + +# @dept_bp.put('/update') +# @authorize("admin:dept:edit", log=True) +# def update(): +# json = request.get_json(force=True) +# id = json.get("deptId"), +# data = { +# "dept_name": validate.str_escape(json.get("deptName")), +# "sort": validate.str_escape(json.get("sort")), +# "leader": validate.str_escape(json.get("leader")), +# "phone": validate.str_escape(json.get("phone")), +# "email": validate.str_escape(json.get("email")), +# "status": validate.str_escape(json.get("status")), +# "address": validate.str_escape(json.get("address")) +# } +# d = Dept.query.filter_by(id=id).update(data) +# if not d: +# return fail_api(msg="更新失败") +# db.session.commit() +# return success_api(msg="更新成功") + + +# @dept_bp.delete('/remove/') +# @authorize("admin:dept:remove", log=True) +# def remove(_id): +# d = Dept.query.filter_by(id=_id).delete() +# if not d: +# return fail_api(msg="删除失败") +# res = User.query.filter_by(dept_id=_id).update({"dept_id": None}) +# db.session.commit() +# if res: +# return success_api(msg="删除成功") +# else: +# return fail_api(msg="删除失败") diff --git a/plugins/helloworld/templates/helloworld_index.html b/plugins/helloworld/templates/helloworld_index.html index 0982b24..67cdff6 100644 --- a/plugins/helloworld/templates/helloworld_index.html +++ b/plugins/helloworld/templates/helloworld_index.html @@ -3,7 +3,7 @@ pear-admin-flask - + {% include 'admin/common/header.html' %} diff --git a/plugins/replacePage/templates/replacePage_index.html b/plugins/replacePage/templates/replacePage_index.html index 06d8e06..ca3e036 100644 --- a/plugins/replacePage/templates/replacePage_index.html +++ b/plugins/replacePage/templates/replacePage_index.html @@ -3,7 +3,7 @@ pear-admin-flask - + {% include 'admin/common/header.html' %} diff --git a/static/admin/admin/data/menu.json b/static/admin/admin/data/menu.json index 3a20b6e..1d7bd09 100644 --- a/static/admin/admin/data/menu.json +++ b/static/admin/admin/data/menu.json @@ -356,7 +356,6 @@ "openType": "_iframe", "href": "view/system/power.html" }, - { "id": 604, "title": "部门管理", diff --git a/templates/admin/index.html b/templates/admin/index.html index 94fff38..3ede583 100644 --- a/templates/admin/index.html +++ b/templates/admin/index.html @@ -2,7 +2,7 @@ {% include 'admin/common/header.html' %} - Pear Admin Flask + hml admin @@ -31,7 +31,6 @@
  • -
  • @@ -69,8 +68,8 @@ -
    +
    @@ -71,21 +71,21 @@ {% include 'admin/common/footer.html' %}