diff --git a/.flaskenv b/.flaskenv index d270931..cf560b9 100644 --- a/.flaskenv +++ b/.flaskenv @@ -1,3 +1,5 @@ FLASK_APP=main.py FLASK_ENV=development -FLASK_DEBUG=1 \ No newline at end of file +FLASK_DEBUG=1 +FLASK_RUN_HOST = 127.0.0.1 +FLASK_RUN_PORT = 5000 \ No newline at end of file diff --git a/applications/models/admin_dept.py b/applications/models/admin_dept.py new file mode 100644 index 0000000..c0929a3 --- /dev/null +++ b/applications/models/admin_dept.py @@ -0,0 +1,31 @@ +import datetime +from applications.models import db, ma +from marshmallow import fields + + +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='创建时间') + + +class DeptSchema(ma.Schema): # 序列化类 + deptId = fields.Integer(attribute="id") + parentId = fields.Integer(attribute="parent_id") + deptName = fields.Str(attribute="dept_name") + leader = fields.Str() + phone = fields.Str() + email = fields.Str() + address = fields.Str() + status = fields.Str() + sort = fields.Str() diff --git a/applications/models/admin_user.py b/applications/models/admin_user.py index fd50aa6..4a8b3e2 100644 --- a/applications/models/admin_user.py +++ b/applications/models/admin_user.py @@ -4,6 +4,7 @@ from werkzeug.security import generate_password_hash, check_password_hash from applications.models import db, ma from marshmallow import fields from applications.models import admin_user_role +from applications.models.admin_dept import Dept class User(db.Model, UserMixin): @@ -15,6 +16,7 @@ class User(db.Model, UserMixin): remark = db.Column(db.String(255), comment='备注') password_hash = db.Column(db.String(128), comment='哈希密码') enable = db.Column(db.Integer, default=0, comment='启用') + dept_id = db.Column(db.Integer, comment='部门id') 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='创建时间') role = db.relationship('Role', secondary="admin_user_role", backref=db.backref('user'), lazy='dynamic') @@ -34,3 +36,11 @@ class UserSchema(ma.Schema): enable = fields.Integer() create_at = fields.DateTime() update_at = fields.DateTime() + dept = fields.Method("get_dept") + + def get_dept(self, obj): + if obj.dept_id != None: + return Dept.query.filter_by(id=obj.dept_id).first().dept_name + else: + return None + diff --git a/applications/service/admin/dept.py b/applications/service/admin/dept.py new file mode 100644 index 0000000..f3207c9 --- /dev/null +++ b/applications/service/admin/dept.py @@ -0,0 +1,92 @@ +from markupsafe import escape, Markup + +from applications.models import db +from applications.models.admin_dept import Dept, DeptSchema +from applications.models.admin_user import User +from applications.service.common.curd import model_to_dicts + + +def get_dept_dict(): + dept = Dept.query.order_by(Dept.sort).all() + res = model_to_dicts(Schema=DeptSchema, model=dept) + return res + + +def save_dept(req): + address = req.get("address") + deptName = req.get("deptName") + email = req.get("email") + leader = req.get("leader") + parentId = req.get("parentId") + parentName = req.get("parentName") + phone = req.get("phone") + selectParent_select_input = req.get("selectParent_select_input") + sort = req.get("sort") + status = req.get("status") + dept = Dept( + parent_id=parentId, + dept_name=deptName, + sort=sort, + leader=leader, + phone=phone, + email=email, + status=status, + address=address + ) + r = db.session.add(dept) + db.session.commit() + return r + + +def get_dept_by_id(id): + d = Dept.query.filter_by(id=id).first() + return d + + +# 启动权限 +def enable_status(id): + enable = 1 + d = Dept.query.filter_by(id=id).update({"status": enable}) + if d: + db.session.commit() + return True + print('0') + return False + + +# 停用权限 +def disable_status(id): + enable = 0 + d = Dept.query.filter_by(id=id).update({"status": enable}) + if d: + db.session.commit() + return True + return False + + +def update_dept(json): + id = json.get("deptId"), + print(str(Markup(json.get("leader")))) + data = { + "dept_name": json.get("deptName"), + "sort": json.get("sort"), + "leader": json.get("leader"), + "phone": json.get("phone"), + "email": json.get("email"), + "status": json.get("status"), + "address": json.get("address") + } + d = Dept.query.filter_by(id=id).update(data) + if not d: + return False + db.session.commit() + return True + + +def remove_dept(id): + d = Dept.query.filter_by(id=id).delete() + if not d: + return False + User.query.filter_by(dept_id=id).update({"dept_id": None}) + db.session.commit() + return True diff --git a/applications/service/admin/power.py b/applications/service/admin/power.py index 9eb3ca8..402e8eb 100644 --- a/applications/service/admin/power.py +++ b/applications/service/admin/power.py @@ -1,22 +1,20 @@ from applications.models import db from applications.models.admin_power import Power, PowerSchema2 from applications.models.admin_role import Role +from applications.service.common.curd import model_to_dicts def get_power_dict(): power = Power.query.all() - power_schema = PowerSchema2(many=True) - power_dict = power_schema.dump(power) - return power_dict - + res = model_to_dicts(Schema=PowerSchema2, model=power) + return res # 选择父节点 def select_parent(): power = Power.query.all() - power_schema = PowerSchema2(many=True) - power_dict = power_schema.dump(power) - power_dict.append({"powerId": 0, "powerName": "顶级权限", "parentId": -1}) - return power_dict + res = model_to_dicts(Schema=PowerSchema2, model=power) + res.append({"powerId": 0, "powerName": "顶级权限", "parentId": -1}) + return res # 增加权限 diff --git a/applications/service/admin/user.py b/applications/service/admin/user.py index f9958e6..8ab8ed2 100644 --- a/applications/service/admin/user.py +++ b/applications/service/admin/user.py @@ -11,8 +11,13 @@ from applications.models.admin_log import AdminLog from applications.service.common.curd import model_to_dicts -def get_user_data(page, limit, filters): - user = User.query.filter(and_(*[getattr(User, k).like(v) for k, v in filters.items()])).paginate(page=page, +def get_user_data(page, limit, filters,deptId): + if deptId: + user = User.query.filter_by(dept_id=deptId).filter(and_(*[getattr(User, k).like(v) for k, v in filters.items()])).paginate(page=page, + per_page=limit, + error_out=False) + else: + user = User.query.filter(and_(*[getattr(User, k).like(v) for k, v in filters.items()])).paginate(page=page, per_page=limit, error_out=False) count = User.query.count() @@ -20,8 +25,8 @@ def get_user_data(page, limit, filters): # 获取用户的dict数据分页器 -def get_user_data_dict(page, limit, filters): - user, count = get_user_data(page, limit, filters) +def get_user_data_dict(page, limit, filters,deptId): + user, count = get_user_data(page, limit, filters,deptId) data = model_to_dicts(Schema=UserSchema,model=user.items) return data, count @@ -70,8 +75,8 @@ def update_avatar(url): # 更新用户信息 -def update_user(id, username, realname): - user = User.query.filter_by(id=id).update({'username': username, 'realname': realname}) +def update_user(id, username, realname, deptId): + user = User.query.filter_by(id=id).update({'username': username, 'realname': realname,'dept_id':deptId}) db.session.commit() return user diff --git a/applications/views/admin/__init__.py b/applications/views/admin/__init__.py index dd7a4d7..5d82634 100644 --- a/applications/views/admin/__init__.py +++ b/applications/views/admin/__init__.py @@ -1,3 +1,4 @@ +from applications.views.admin.dept import admin_dept from applications.views.admin.index import admin_index from applications.views.admin.user import admin_user from applications.views.admin.file import admin_file @@ -6,14 +7,10 @@ from applications.views.admin.admin_log import admin_log from applications.views.admin.power import admin_power from applications.views.admin.role import admin_role from applications.views.admin.dict import admin_dict -""" - 初始化蓝图 - - """ +# 初始化蓝图 def init_adminViews(app): - app.register_blueprint(admin_index) app.register_blueprint(admin_user) app.register_blueprint(admin_file) @@ -22,4 +19,4 @@ def init_adminViews(app): app.register_blueprint(admin_power) app.register_blueprint(admin_role) app.register_blueprint(admin_dict) - + app.register_blueprint(admin_dept) diff --git a/applications/views/admin/dept.py b/applications/views/admin/dept.py new file mode 100644 index 0000000..6420a45 --- /dev/null +++ b/applications/views/admin/dept.py @@ -0,0 +1,101 @@ +from flask import Blueprint, render_template, request, jsonify +from applications.service.admin import dept as dept_curd +from applications.service.common.response import table_api, success_api, fail_api +from applications.service.route_auth import authorize_and_log, authorize + +admin_dept = Blueprint('adminDept', __name__, url_prefix='/admin/dept') + + +@admin_dept.route('/') +@authorize_and_log("admin:dept:main") +def main(): + return render_template('admin/dept/main.html') + + +@admin_dept.route('/data') +@authorize_and_log("admin:dept:main") +def data(): + power_data = dept_curd.get_dept_dict() + res = { + "data": power_data + } + return jsonify(res) + + +@admin_dept.route('/add') +@authorize_and_log("admin:dept:add") +def add(): + return render_template('admin/dept/add.html') + + +@admin_dept.route('/tree') +@authorize_and_log("admin:dept:main") +def tree(): + power_data = dept_curd.get_dept_dict() + res = { + "status": {"code": 200, "message": "默认"}, + "data": power_data + + } + return jsonify(res) + + +@admin_dept.route('/save', methods=['POST']) +@authorize_and_log("admin:dept:edit") +def save(): + req = request.json + dept_curd.save_dept(req) + return success_api(msg="成功") + + +@admin_dept.route('/edit', methods=['GET', 'POST']) +@authorize_and_log("admin:dept:edit") +def edit(): + id = request.args.get("deptId") + dept = dept_curd.get_dept_by_id(id) + return render_template('admin/dept/edit.html', dept=dept) + + +# 启用 +@admin_dept.route('/enable', methods=['PUT']) +@authorize_and_log("admin:dept:edit") +def enable(): + id = request.json.get('deptId') + if id: + res = dept_curd.enable_status(id) + if not res: + return fail_api(msg="出错啦") + return success_api(msg="启用成功") + return fail_api(msg="数据错误") + + +# 禁用 +@admin_dept.route('/disable', methods=['PUT']) +@authorize_and_log("admin:dept:edit") +def disenable(): + id = request.json.get('deptId') + if id: + res = dept_curd.disable_status(id) + if not res: + return fail_api(msg="出错啦") + return success_api(msg="禁用成功") + return fail_api(msg="数据错误") + + +@admin_dept.route('/update', methods=['PUT']) +@authorize_and_log("admin:dept:edit") +def update(): + res = dept_curd.update_dept(request.json) + if not res: + return fail_api(msg="更新失败") + return success_api(msg="更新成功") + + +@admin_dept.route('/remove/', methods=['DELETE']) +@authorize_and_log("admin:dept:remove") +def remove(id): + res = dept_curd.remove_dept(id) + if res: + return success_api(msg="删除成功") + else: + return fail_api(msg="删除失败") diff --git a/applications/views/admin/power.py b/applications/views/admin/power.py index d3552ae..682c11a 100644 --- a/applications/views/admin/power.py +++ b/applications/views/admin/power.py @@ -73,7 +73,7 @@ def update(): return success_api(msg="更新权限成功") -# 启用用户 +# 启用权限 @admin_power.route('/enable', methods=['PUT']) @authorize_and_log("admin:power:edit") def enable(): @@ -83,11 +83,11 @@ def enable(): res = enable_status(id) if not res: return fail_api(msg="出错啦") - return success_api(msg="启动成功") + return success_api(msg="启用成功") return fail_api(msg="数据错误") -# 禁用用户 +# 禁用权限 @admin_power.route('/disable', methods=['PUT']) @authorize_and_log("admin:power:edit") def disenable(): diff --git a/applications/views/admin/user.py b/applications/views/admin/user.py index 47a959a..e2f9c0f 100644 --- a/applications/views/admin/user.py +++ b/applications/views/admin/user.py @@ -26,12 +26,13 @@ def data(): limit = request.args.get('limit', type=int) realName = request.args.get('realName', type=str) username = request.args.get('username', type=str) + deptId = request.args.get('deptId', type=int) filters = {} if realName: filters["realname"] = ('%' + realName + '%') if username: filters["username"] = ('%' + username + '%') - user_data, count = get_user_data_dict(page=page, limit=limit, filters=filters) + user_data, count = get_user_data_dict(page=page, limit=limit, filters=filters,deptId=deptId) return table_api(data=user_data, count=count) @@ -96,8 +97,9 @@ def update(): id = req_json.get("userId") username = req_json.get('username') realName = req_json.get('realName') + deptId = req_json.get('deptId') role_ids = a.split(',') - update_user(id, username, realName) + update_user(id, username, realName,deptId) update_user_role(id, role_ids) return success_api(msg="更新成功") @@ -158,7 +160,6 @@ def edit_password_put(): @authorize_and_log("admin:user:edit") def enable(): id = request.json.get('userId') - print(id) if id: res = enable_status(id) if not res: diff --git a/dev/pear.sql b/dev/pear.sql index 4b99651..518d907 100644 --- a/dev/pear.sql +++ b/dev/pear.sql @@ -11,7 +11,7 @@ Target Server Version : 50726 File Encoding : 65001 - Date: 27/04/2021 11:57:13 + Date: 01/06/2021 17:50:18 */ SET NAMES utf8mb4; @@ -32,12 +32,41 @@ CREATE TABLE `admin_admin_log` ( `create_time` datetime(0) NULL DEFAULT NULL, `success` int(11) NULL DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1267 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; +) ENGINE = InnoDB AUTO_INCREMENT = 546 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of admin_admin_log -- ---------------------------- +-- ---------------------------- +-- Table structure for admin_dept +-- ---------------------------- +DROP TABLE IF EXISTS `admin_dept`; +CREATE TABLE `admin_dept` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '部门ID', + `parent_id` int(11) NULL DEFAULT NULL COMMENT '父级编号', + `dept_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '部门名称', + `sort` int(11) NULL DEFAULT NULL COMMENT '排序', + `leader` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '负责人', + `phone` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '联系方式', + `email` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '邮箱', + `status` int(11) NULL DEFAULT NULL COMMENT '状态(1开启,0关闭)', + `remark` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '备注', + `address` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '详细地址', + `create_at` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', + `update_at` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of admin_dept +-- ---------------------------- +INSERT INTO `admin_dept` VALUES (1, 0, '总公司', 1, '就眠仪式', '12312345679', '123qq.com', 1, NULL, '这是总公司', NULL, '2021-06-01 17:23:20'); +INSERT INTO `admin_dept` VALUES (4, 1, '济南分公司', 2, '就眠仪式', '12312345678', '1234qq.com', 1, NULL, '这是济南', '2021-06-01 17:24:33', '2021-06-01 17:25:19'); +INSERT INTO `admin_dept` VALUES (5, 1, '唐山分公司', 4, 'mkg', '12312345678', '123@qq.com', 1, NULL, '这是唐山', '2021-06-01 17:25:15', '2021-06-01 17:25:20'); +INSERT INTO `admin_dept` VALUES (7, 4, '济南分公司开发部', 5, '就眠仪式', '12312345678', '123@qq.com', 1, NULL, '测试', '2021-06-01 17:27:39', '2021-06-01 17:27:39'); +INSERT INTO `admin_dept` VALUES (8, 5, '唐山测试部', 6, 'mkg', '12312345678', '123@qq.com', 1, NULL, '测试部', '2021-06-01 17:28:27', '2021-06-01 17:28:27'); + -- ---------------------------- -- Table structure for admin_dict_data -- ---------------------------- @@ -74,7 +103,7 @@ CREATE TABLE `admin_dict_type` ( `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 12 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of admin_dict_type @@ -119,7 +148,7 @@ CREATE TABLE `admin_power` ( `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间', `enable` int(11) NULL DEFAULT NULL COMMENT '是否开启', PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 48 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; +) ENGINE = InnoDB AUTO_INCREMENT = 52 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of admin_power @@ -148,6 +177,10 @@ INSERT INTO `admin_power` VALUES (44, '数据字典', '1', 'admin:dict:main', '/ INSERT INTO `admin_power` VALUES (45, '字典增加', '2', 'admin:dict:add', '', '', '44', 'layui-icon ', 1, '2021-04-16 14:00:59', '2021-04-16 14:00:59', 1); INSERT INTO `admin_power` VALUES (46, '字典修改', '2', 'admin:dict:edit', '', '', '44', 'layui-icon ', 2, '2021-04-16 14:01:33', '2021-04-16 14:01:33', 1); INSERT INTO `admin_power` VALUES (47, '字典删除', '2', 'admin:dict:remove', '', '', '44', 'layui-icon ', 3, '2021-04-16 14:02:06', '2021-04-16 14:02:06', 1); +INSERT INTO `admin_power` VALUES (48, '部门管理', '1', 'admin:dept:main', '/admin/dept', '_iframe', '1', 'layui-icon layui-icon-group', 3, '2021-06-01 16:22:11', '2021-06-01 16:22:11', 1); +INSERT INTO `admin_power` VALUES (49, '部门增加', '2', 'admin:dept:add', '', '', '48', 'layui-icon None', 1, '2021-06-01 17:35:52', '2021-06-01 17:36:15', 1); +INSERT INTO `admin_power` VALUES (50, '部门编辑', '2', 'admin:dept:edit', '', '', '48', 'layui-icon ', 2, '2021-06-01 17:36:41', '2021-06-01 17:36:41', 1); +INSERT INTO `admin_power` VALUES (51, '部门删除', '2', 'admin:dept:remove', '', '', '48', 'layui-icon None', 3, '2021-06-01 17:37:15', '2021-06-01 17:37:26', 1); -- ---------------------------- -- Table structure for admin_role @@ -185,43 +218,49 @@ CREATE TABLE `admin_role_power` ( INDEX `role_id`(`role_id`) USING BTREE, CONSTRAINT `admin_role_power_ibfk_1` FOREIGN KEY (`power_id`) REFERENCES `admin_power` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT `admin_role_power_ibfk_2` FOREIGN KEY (`role_id`) REFERENCES `admin_role` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT -) ENGINE = InnoDB AUTO_INCREMENT = 212 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; +) ENGINE = InnoDB AUTO_INCREMENT = 275 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of admin_role_power -- ---------------------------- -INSERT INTO `admin_role_power` VALUES (159, 1, 2); -INSERT INTO `admin_role_power` VALUES (160, 3, 2); -INSERT INTO `admin_role_power` VALUES (161, 4, 2); -INSERT INTO `admin_role_power` VALUES (162, 9, 2); -INSERT INTO `admin_role_power` VALUES (163, 12, 2); -INSERT INTO `admin_role_power` VALUES (164, 13, 2); -INSERT INTO `admin_role_power` VALUES (165, 17, 2); -INSERT INTO `admin_role_power` VALUES (166, 18, 2); -INSERT INTO `admin_role_power` VALUES (188, 1, 1); -INSERT INTO `admin_role_power` VALUES (189, 3, 1); -INSERT INTO `admin_role_power` VALUES (190, 4, 1); -INSERT INTO `admin_role_power` VALUES (191, 9, 1); -INSERT INTO `admin_role_power` VALUES (192, 12, 1); -INSERT INTO `admin_role_power` VALUES (193, 13, 1); -INSERT INTO `admin_role_power` VALUES (194, 17, 1); -INSERT INTO `admin_role_power` VALUES (195, 18, 1); -INSERT INTO `admin_role_power` VALUES (196, 21, 1); -INSERT INTO `admin_role_power` VALUES (197, 22, 1); -INSERT INTO `admin_role_power` VALUES (198, 23, 1); -INSERT INTO `admin_role_power` VALUES (199, 24, 1); -INSERT INTO `admin_role_power` VALUES (200, 25, 1); -INSERT INTO `admin_role_power` VALUES (201, 26, 1); -INSERT INTO `admin_role_power` VALUES (202, 27, 1); -INSERT INTO `admin_role_power` VALUES (203, 28, 1); -INSERT INTO `admin_role_power` VALUES (204, 29, 1); -INSERT INTO `admin_role_power` VALUES (205, 30, 1); -INSERT INTO `admin_role_power` VALUES (206, 31, 1); -INSERT INTO `admin_role_power` VALUES (207, 32, 1); -INSERT INTO `admin_role_power` VALUES (208, 44, 1); -INSERT INTO `admin_role_power` VALUES (209, 45, 1); -INSERT INTO `admin_role_power` VALUES (210, 46, 1); -INSERT INTO `admin_role_power` VALUES (211, 47, 1); +INSERT INTO `admin_role_power` VALUES (237, 1, 1); +INSERT INTO `admin_role_power` VALUES (238, 3, 1); +INSERT INTO `admin_role_power` VALUES (239, 4, 1); +INSERT INTO `admin_role_power` VALUES (240, 9, 1); +INSERT INTO `admin_role_power` VALUES (241, 12, 1); +INSERT INTO `admin_role_power` VALUES (242, 13, 1); +INSERT INTO `admin_role_power` VALUES (243, 17, 1); +INSERT INTO `admin_role_power` VALUES (244, 18, 1); +INSERT INTO `admin_role_power` VALUES (245, 21, 1); +INSERT INTO `admin_role_power` VALUES (246, 22, 1); +INSERT INTO `admin_role_power` VALUES (247, 23, 1); +INSERT INTO `admin_role_power` VALUES (248, 24, 1); +INSERT INTO `admin_role_power` VALUES (249, 25, 1); +INSERT INTO `admin_role_power` VALUES (250, 26, 1); +INSERT INTO `admin_role_power` VALUES (251, 27, 1); +INSERT INTO `admin_role_power` VALUES (252, 28, 1); +INSERT INTO `admin_role_power` VALUES (253, 29, 1); +INSERT INTO `admin_role_power` VALUES (254, 30, 1); +INSERT INTO `admin_role_power` VALUES (255, 31, 1); +INSERT INTO `admin_role_power` VALUES (256, 32, 1); +INSERT INTO `admin_role_power` VALUES (257, 44, 1); +INSERT INTO `admin_role_power` VALUES (258, 45, 1); +INSERT INTO `admin_role_power` VALUES (259, 46, 1); +INSERT INTO `admin_role_power` VALUES (260, 47, 1); +INSERT INTO `admin_role_power` VALUES (261, 48, 1); +INSERT INTO `admin_role_power` VALUES (262, 49, 1); +INSERT INTO `admin_role_power` VALUES (263, 50, 1); +INSERT INTO `admin_role_power` VALUES (264, 51, 1); +INSERT INTO `admin_role_power` VALUES (265, 1, 2); +INSERT INTO `admin_role_power` VALUES (266, 3, 2); +INSERT INTO `admin_role_power` VALUES (267, 4, 2); +INSERT INTO `admin_role_power` VALUES (268, 9, 2); +INSERT INTO `admin_role_power` VALUES (269, 12, 2); +INSERT INTO `admin_role_power` VALUES (270, 13, 2); +INSERT INTO `admin_role_power` VALUES (271, 17, 2); +INSERT INTO `admin_role_power` VALUES (272, 18, 2); +INSERT INTO `admin_role_power` VALUES (273, 44, 2); +INSERT INTO `admin_role_power` VALUES (274, 48, 2); -- ---------------------------- -- Table structure for admin_user @@ -237,14 +276,16 @@ CREATE TABLE `admin_user` ( `realname` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '真实名字', `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '备注', `avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '头像', + `dept_id` int(11) NULL DEFAULT NULL COMMENT '部门id', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of admin_user -- ---------------------------- -INSERT INTO `admin_user` VALUES (1, 'admin', 'pbkdf2:sha256:150000$raM7mDSr$58fe069c3eac01531fc8af85e6fc200655dd2588090530084d182e6ec9d52c85', NULL, '2021-04-01 23:39:41', 1, '超级管理', '要是不能把握时机,就要终身蹭蹬,一事无成!', 'http://127.0.0.1:5000/_uploads/photos/1617291580000.jpg'); -INSERT INTO `admin_user` VALUES (7, 'test', 'pbkdf2:sha256:150000$cRS8bYNh$adb57e64d929863cf159f924f74d0634f1fecc46dba749f1bfaca03da6d2e3ac', '2021-03-22 20:03:42', '2021-04-01 23:37:39', 1, '超级管理', '要是不能把握时机,就要终身蹭蹬,一事无成', '/static/admin/admin/images/avatar.jpg'); +INSERT INTO `admin_user` VALUES (1, 'admin', 'pbkdf2:sha256:150000$raM7mDSr$58fe069c3eac01531fc8af85e6fc200655dd2588090530084d182e6ec9d52c85', NULL, '2021-06-01 17:28:55', 1, '超级管理', '要是不能把握时机,就要终身蹭蹬,一事无成!', 'http://127.0.0.1:5000/_uploads/photos/1617291580000.jpg', 1); +INSERT INTO `admin_user` VALUES (7, 'test', 'pbkdf2:sha256:150000$cRS8bYNh$adb57e64d929863cf159f924f74d0634f1fecc46dba749f1bfaca03da6d2e3ac', '2021-03-22 20:03:42', '2021-06-01 17:29:47', 1, '超级管理', '要是不能把握时机,就要终身蹭蹬,一事无成', '/static/admin/admin/images/avatar.jpg', 1); +INSERT INTO `admin_user` VALUES (8, 'wind', 'pbkdf2:sha256:150000$skME1obT$6a2c20cd29f89d7d2f21d9e373a7e3445f70ebce3ef1c3a555e42a7d17170b37', '2021-06-01 17:30:39', '2021-06-01 17:30:52', 1, '风', NULL, '/static/admin/admin/images/avatar.jpg', 7); -- ---------------------------- -- Table structure for admin_user_role @@ -259,13 +300,14 @@ CREATE TABLE `admin_user_role` ( INDEX `user_id`(`user_id`) USING BTREE, CONSTRAINT `admin_user_role_ibfk_1` FOREIGN KEY (`role_id`) REFERENCES `admin_role` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT `admin_user_role_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `admin_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT -) ENGINE = InnoDB AUTO_INCREMENT = 18 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; +) ENGINE = InnoDB AUTO_INCREMENT = 25 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of admin_user_role -- ---------------------------- -INSERT INTO `admin_user_role` VALUES (14, 1, 1); -INSERT INTO `admin_user_role` VALUES (17, 7, 2); +INSERT INTO `admin_user_role` VALUES (21, 1, 1); +INSERT INTO `admin_user_role` VALUES (22, 7, 2); +INSERT INTO `admin_user_role` VALUES (24, 8, 2); -- ---------------------------- -- Table structure for alembic_version @@ -279,6 +321,6 @@ CREATE TABLE `alembic_version` ( -- ---------------------------- -- Records of alembic_version -- ---------------------------- -INSERT INTO `alembic_version` VALUES ('ec21e19825ff'); +INSERT INTO `alembic_version` VALUES ('7634e028e338'); SET FOREIGN_KEY_CHECKS = 1; diff --git a/migrations/versions/7634e028e338_.py b/migrations/versions/7634e028e338_.py new file mode 100644 index 0000000..53491e4 --- /dev/null +++ b/migrations/versions/7634e028e338_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: 7634e028e338 +Revises: 8b664608a7c7 +Create Date: 2021-06-01 16:43:50.853692 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '7634e028e338' +down_revision = '8b664608a7c7' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('admin_user', sa.Column('dept_id', sa.Integer(), nullable=True, comment='部门id')) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('admin_user', 'dept_id') + # ### end Alembic commands ### diff --git a/migrations/versions/8b664608a7c7_.py b/migrations/versions/8b664608a7c7_.py new file mode 100644 index 0000000..1917956 --- /dev/null +++ b/migrations/versions/8b664608a7c7_.py @@ -0,0 +1,42 @@ +"""empty message + +Revision ID: 8b664608a7c7 +Revises: ec21e19825ff +Create Date: 2021-06-01 14:37:20.327189 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '8b664608a7c7' +down_revision = 'ec21e19825ff' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('admin_dept', + sa.Column('id', sa.Integer(), nullable=False, comment='部门ID'), + sa.Column('parent_id', sa.Integer(), nullable=True, comment='父级编号'), + sa.Column('dept_name', sa.String(length=50), nullable=True, comment='部门名称'), + sa.Column('sort', sa.Integer(), nullable=True, comment='排序'), + sa.Column('leader', sa.String(length=50), nullable=True, comment='负责人'), + sa.Column('phone', sa.String(length=20), nullable=True, comment='联系方式'), + sa.Column('email', sa.String(length=50), nullable=True, comment='邮箱'), + sa.Column('status', sa.Integer(), nullable=True, comment='状态(1开启,0关闭)'), + sa.Column('remark', sa.Text(), nullable=True, comment='备注'), + sa.Column('address', sa.String(length=255), nullable=True, comment='详细地址'), + sa.Column('create_at', sa.DateTime(), nullable=True, comment='创建时间'), + sa.Column('update_at', sa.DateTime(), nullable=True, comment='创建时间'), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('admin_dept') + # ### end Alembic commands ### diff --git a/static/admin/admin/css/other/user.css b/static/admin/admin/css/other/user.css new file mode 100644 index 0000000..63ec985 --- /dev/null +++ b/static/admin/admin/css/other/user.css @@ -0,0 +1,58 @@ +.dept-tree { + width: 100%; + height: -webkit-calc(100vh - 247px); + height: -moz-calc(100vh - 247px); + height: calc(100vh - 247px); + margin-top: 20px; +} +.dtree-laySimple-item-this{ + background-color: transparent!important; +} +.dtree-nav-div:hover{ + background-color: transparent!important; +} +.button{ + margin-top: 10px; + width: 94%; + margin-left: 3%; + display: block; + height: 40px; + line-height: 40px; + padding: 0 15px; + white-space: nowrap; + text-align: center; + font-size: 14.5px; + border: none; + cursor: pointer; + box-sizing: border-box; + display:inline-block; + outline: 0; + border-radius: 2px; + -webkit-appearance: none; + box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.15); +} +.button-primary{ + background-color: #5FB878; + color: white; +} +.button-default{ + color: #2f495e; + background-color: #edf2f7; +} +.user-main{ + width: calc(100% - 312px); + float: right; +} +.user-left{ + width: 300px; + float: left; +} +.user-collasped.user-main{ + width: 100%; +} +.user-collasped.user-left{ + width: 0px; +} +.user-collasped.user-left .user-group{ + display: none; +} \ No newline at end of file diff --git a/templates/admin/common/footer.html b/templates/admin/common/footer.html new file mode 100644 index 0000000..ca8ea7c --- /dev/null +++ b/templates/admin/common/footer.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/templates/admin/common/header.html b/templates/admin/common/header.html new file mode 100644 index 0000000..50bee36 --- /dev/null +++ b/templates/admin/common/header.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/templates/admin/dept/add.html b/templates/admin/dept/add.html new file mode 100644 index 0000000..94acf47 --- /dev/null +++ b/templates/admin/dept/add.html @@ -0,0 +1,125 @@ + + + + 部门管理 + {% include 'admin/common/header.html' %} + + +
+
+
+
+
+ +
+
    +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +{% include 'admin/common/footer.html' %} + + + + \ No newline at end of file diff --git a/templates/admin/dept/edit.html b/templates/admin/dept/edit.html new file mode 100644 index 0000000..6d56b5c --- /dev/null +++ b/templates/admin/dept/edit.html @@ -0,0 +1,119 @@ + + + + 部门修改 + {% include 'admin/common/header.html' %} + + +
    +
    +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + + + + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +{% include 'admin/common/footer.html' %} + + + + \ No newline at end of file diff --git a/templates/admin/dept/main.html b/templates/admin/dept/main.html new file mode 100644 index 0000000..65ae48e --- /dev/null +++ b/templates/admin/dept/main.html @@ -0,0 +1,225 @@ + + + + 部门新增 + {% include 'admin/common/header.html' %} + + +
    +
    +
    +
    + +
    + +
    + + +
    +
    +
    +
    + +
    +
    +
    +
    +
    + + + + + + + + + +{% include 'admin/common/footer.html' %} + + + \ No newline at end of file diff --git a/templates/admin/user/add.html b/templates/admin/user/add.html index ea4e685..574ec75 100644 --- a/templates/admin/user/add.html +++ b/templates/admin/user/add.html @@ -1,5 +1,5 @@ - + 用户管理 diff --git a/templates/admin/user/edit.html b/templates/admin/user/edit.html index 4a4e799..507ebb2 100644 --- a/templates/admin/user/edit.html +++ b/templates/admin/user/edit.html @@ -33,6 +33,12 @@ class="layui-input"> +
    + +
    +
      +
      +
      @@ -67,9 +73,21 @@