| | |
| | | from datetime import datetime |
| | | from typing import Optional |
| | | |
| | | from pydantic import BaseModel |
| | | from sqlalchemy import Column, Integer, String, DateTime, Table, ForeignKey |
| | | from sqlalchemy.orm import relationship, backref |
| | | |
| | | from app.config.const import RESOURCE_STATUS_DELETE |
| | | from app.models.base_model import Base |
| | | |
| | | class ResourceModel(Base): |
| | |
| | | resource_id = Column(String(36), ForeignKey('resource.id')) |
| | | parent = relationship('ResourceModel', remote_side=[id], backref='resources', uselist=False) |
| | | children = relationship('ResourceModel') |
| | | status = Column(String(10)) |
| | | status = Column(String(10), default="1") |
| | | hidden = Column(Integer, default=0) |
| | | def get_id(self): |
| | | return str(self.ID) |
| | |
| | | 'menuId': self.id, |
| | | 'menuName': self.name, |
| | | 'menuType': self.resource_type_id, |
| | | 'children': [res.to_tree_select_json() for res in self.children] |
| | | 'parentId': self.get_pid(), |
| | | 'status': self.status, |
| | | 'parentName': self.get_pName(), |
| | | 'children': [res.to_tree_select_json() for res in self.children if res if res.status != RESOURCE_STATUS_DELETE] |
| | | } |
| | | |
| | | def to_router_json(self): |
| | |
| | | router['component'] = 'Layout' |
| | | |
| | | return router |
| | | |
| | | |
| | | def to_router_dict(self): |
| | | router = { |
| | | 'id': self.id, |
| | | 'name': self.path.capitalize() if self.path else '', |
| | | # 'name': self.name, |
| | | 'path': self.path, |
| | | 'hidden': bool(self.hidden), |
| | | 'redirect': 'noRedirect', |
| | | 'component': self.url, |
| | | 'alwaysShow': True, |
| | | 'perms': self.perms, |
| | | 'resourceType': self.get_type_json(), |
| | | 'seq': self.seq, |
| | | 'meta': { |
| | | 'title': self.name, |
| | | 'icon': self.icon, |
| | | 'noCache': False, |
| | | 'link': '' |
| | | }, |
| | | 'parentId': self.get_pid(), |
| | | } |
| | | |
| | | if not router['component']: |
| | | router['component'] = 'Layout' |
| | | return router |
| | | |
| | | |
| | | def to_menu_json(self): |
| | | return { |
| | |
| | | def to_json(self): |
| | | return { |
| | | 'id': self.id, |
| | | 'createdatetime': self.created_at, |
| | | 'updatedatetime': self.updated_at, |
| | | # 'createdatetime': self.created_at, |
| | | # 'updatedatetime': self.updated_at, |
| | | 'name': self.name, |
| | | 'description': self.description |
| | | } |
| | | |
| | | def __repr__(self): |
| | | return '<ResourceTypeModel %r>\n' %(self.name) |
| | | return '<ResourceTypeModel %r>\n' %(self.name) |
| | | |
| | | class MenuInfo(BaseModel): |
| | | menuId: Optional[str] = "" |
| | | menuName: Optional[str] = "" |
| | | component: Optional[str] = "" |
| | | path: Optional[str] = "" |
| | | orderNum: int |
| | | perms: Optional[str] = "" |
| | | menuType: Optional[str] = "" |
| | | description: Optional[str] = "" |
| | | icon: Optional[str] = "" |
| | | parentId: str |
| | | status: str |
| | | # roles: list |
| | | # groups: Optional[list] = [] |
| | | |
| | | |
| | | class MenuStatus(BaseModel): |
| | | menuId: str |
| | | status: str |