diff --git a/README.md b/README.md index d10ba53..a68c3d7 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,87 @@ * test: 测试分支 ## 测试环境服务启动 -1. 前端启动: +1. nginx添加配置: +``` + server { + listen 80; + server_name localhost; + + #charset koi8-r; + + #access_log logs/host.access.log main; + + location / { + proxy_pass http://127.0.0.1:8080/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + + # api + location /api/ { + proxy_pass http://127.0.0.1:8000; + client_max_body_size 100m; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + #proxy_pass http://127.0.0.1:4523/mock/412521/api/; + } + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + + } + +``` +2. 前端启动: ``` 进入www页面,执行:npm run serve ``` -2. 后端启动 +3. 后端启动 ``` uvicorn server.main:app --reload ``` +## 生产环境部署 +1. 前端执行打包命令 +``` +npm run build +``` +2. 添加nginx配置 +``` +server { + listen 80; + location / { + root /opt/www; #打包后前端放置目录 + index index.html; + try_files $uri $uri/ /index.html; + } + + location /api/ { + proxy_pass http://127.0.0.1:8000; + client_max_body_size 100m; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + #proxy_pass http://127.0.0.1:4523/mock/412521/api/; + } +} +``` +3. 启动后端服务 +生产环境使用,建议通过gunicorn启动服务 +``` +nohup gunicorn server.main:app -b 127.0.0.1:8000 -w 4 -k uvicorn.workers.UvicornWorker >gunicorn.log 2>&1& +``` + ## 约束 1. 后端数据库对于布尔值的传递统一数据库设置为tinyint,0为假,1为真 2. 前端所有bool都0为假,1为真 diff --git a/server/crud/base.py b/server/crud/base.py index 5a2472e..c298eec 100644 --- a/server/crud/base.py +++ b/server/crud/base.py @@ -99,7 +99,7 @@ def search(self, session: Session, search: Pagination, filter_type: Optional[Dic else: subquery = subquery.order_by(getattr(self.model, order_col)) subquery = subquery.offset( - (search.page - 1) * search.page_size).limit(1).subquery() + (search.page - 1) * search.page_size).limit(1).scalar_subquery() if search.model == 'desc': sql = sql.where(getattr(self.model, order_col) <= subquery).order_by(desc(getattr(self.model, order_col))).limit( search.page_size) diff --git a/server/crud/internal/dictonary.py b/server/crud/internal/dictonary.py index 24f741a..d31f43e 100644 --- a/server/crud/internal/dictonary.py +++ b/server/crud/internal/dictonary.py @@ -12,7 +12,7 @@ class CRUDDict(CRUDBase[DataDict]): class CRUDItem(CRUDBase[DictItem]): def get_items_by_code(self, db: Session, code: str): - dict_id = select(DataDict.id).where(DataDict.code == code).subquery() + dict_id = select(DataDict.id).where(DataDict.code == code).scalar_subquery() sql = select(self.model).where(self.model.dict_id == dict_id).where(self.model.enable == 1).order_by( self.model.sort) return db.exec(sql).all() diff --git a/www/src/components/MenuList.vue b/www/src/components/MenuList.vue index 2002a35..1da1221 100644 --- a/www/src/components/MenuList.vue +++ b/www/src/components/MenuList.vue @@ -2,6 +2,7 @@ 首页 @@ -35,25 +36,24 @@ - diff --git a/www/src/views/system/dictonary/index.vue b/www/src/views/system/dictonary/index.vue index 4007ef3..7c5ba6d 100644 --- a/www/src/views/system/dictonary/index.vue +++ b/www/src/views/system/dictonary/index.vue @@ -60,6 +60,12 @@ + +