From 5bc3db60e7fe513873b0e8dd81b8ae9019a907ee Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Wed, 31 May 2023 21:43:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E5=90=88=20amis=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E7=95=8C=E9=9D=A2=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/index.html | 197 +++++++++++++++++++++ frontend/pages/question.json | 152 ++++++++++++++++ frontend/pages/site.json | 23 +++ frontend/public/logo.png | Bin 0 -> 6242 bytes frontend/x-pages/console.json | 5 + frontend/x-pages/crud-advance.json | 274 +++++++++++++++++++++++++++++ frontend/x-pages/crud-edit.json | 64 +++++++ frontend/x-pages/crud-list.json | 149 ++++++++++++++++ frontend/x-pages/crud-new.json | 69 ++++++++ frontend/x-pages/crud-view.json | 65 +++++++ frontend/x-pages/editor.json | 18 ++ frontend/x-pages/excel.json | 50 ++++++ frontend/x-pages/form-basic.json | 241 +++++++++++++++++++++++++ frontend/x-pages/jsonp.js | 12 ++ frontend/x-pages/pageA.json | 177 +++++++++++++++++++ frontend/x-pages/site.json | 126 +++++++++++++ frontend/x-pages/wizard.json | 105 +++++++++++ handler/car.py | 14 +- main.py | 8 +- utils/common.py | 12 ++ 20 files changed, 1759 insertions(+), 2 deletions(-) create mode 100644 frontend/index.html create mode 100644 frontend/pages/question.json create mode 100644 frontend/pages/site.json create mode 100644 frontend/public/logo.png create mode 100644 frontend/x-pages/console.json create mode 100644 frontend/x-pages/crud-advance.json create mode 100644 frontend/x-pages/crud-edit.json create mode 100644 frontend/x-pages/crud-list.json create mode 100644 frontend/x-pages/crud-new.json create mode 100644 frontend/x-pages/crud-view.json create mode 100644 frontend/x-pages/editor.json create mode 100644 frontend/x-pages/excel.json create mode 100644 frontend/x-pages/form-basic.json create mode 100644 frontend/x-pages/jsonp.js create mode 100644 frontend/x-pages/pageA.json create mode 100644 frontend/x-pages/site.json create mode 100644 frontend/x-pages/wizard.json diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..ebac447 --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,197 @@ + + +
+ +%R=^~w;^Q0Ss-LOu>e9bbVWD{#81cmA z1wT@r8HVFV6`DJz{YKl&>7!TxXfNeBISw`3Ux8zVBMiB~K%>@?B+bnmp?MWBq?$Z+ zqpyN{5o^%~$}`}{v)-n`HA>s+^AvQ{6$m95NUT}3FW-^Zxn=_)bxk4;N;tl| z!LTT3K`(>I?_C#_Q5|2!^DPe%xKby#kYo!%rS2%+v%{ G<8Fc`Z#Mlxhf~{&^yY!l~&vdU=h??v<;FZRR`M84M_RpYcRr`htX0)$+Qxt4m zfwwe!h4%A1h)EKIyT%uHyh9v{4md{6rG91g{&YXnwz`3}A8licT6}_l_!eb0qhfQXuzg-=f7F&pI7BNMDFs z-?8hk2pvSW(*^#_e+`ik9g-9A{nQKD-6KM4njVos0CO>$O&{uNuEvyWg?7 添加其他 Html 片段 需要支持变量替换(todo)." + } + ] + } + ] +} diff --git a/frontend/x-pages/editor.json b/frontend/x-pages/editor.json new file mode 100644 index 0000000..a6bb29c --- /dev/null +++ b/frontend/x-pages/editor.json @@ -0,0 +1,18 @@ +{ + "type": "page", + "title": "代码编辑器", + "subTitle": "使用的monaco-editor,用到了 worker, 如果控制台没有报错,说明一起正常。", + "body": [ + { + "type": "form", + "controls": [ + { + "type": "editor", + "name": "js", + "label": "Javascript", + "size": "md" + } + ] + } + ] +} diff --git a/frontend/x-pages/excel.json b/frontend/x-pages/excel.json new file mode 100644 index 0000000..bd1cbf6 --- /dev/null +++ b/frontend/x-pages/excel.json @@ -0,0 +1,50 @@ +{ + "type": "page", + "body": { + "type": "crud", + "syncLocation": false, + "api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample", + "headerToolbar": [ + { + "type": "export-csv", + "label": "全量导出 CSV", + "api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample" + }, + { + "type": "export-excel", + "label": "全量导出 Excel", + "api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample" + } + ], + "columns": [ + { + "name": "id", + "label": "ID" + }, + { + "name": "engine", + "label": "Rendering engine" + }, + { + "name": "browser", + "label": "Browser" + }, + { + "name": "platform", + "label": "Platform(s)" + }, + { + "name": "version", + "label": "Engine version" + }, + { + "name": "grade", + "label": "CSS grade", + "type": "mapping", + "map": { + "*": "${grade}" + } + } + ] + } +} \ No newline at end of file diff --git a/frontend/x-pages/form-basic.json b/frontend/x-pages/form-basic.json new file mode 100644 index 0000000..7040b9c --- /dev/null +++ b/frontend/x-pages/form-basic.json @@ -0,0 +1,241 @@ +{ + "type": "page", + "title": "基础表单", + "subTitle": "展示一些常规的表单,包括验证、提示等等", + "body": [ + { + "type": "form", + "mode": "horizontal", + "title": "常规表单示例", + "affixFooter": true, + "api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/form/save", + "actions": [ + { + "label": "保存", + "type": "submit", + "level": "success" + } + ], + "controls": [ + { + "label": " 标题", + "type": "text", + "placeholder": "请输入标题", + "description": "请输入一个能吸引眼球的标题", + "name": "title", + "size": "md" + }, + + { + "label": "编号", + "required": true, + "type": "text", + "placeholder": "请输入编号", + "name": "b", + "size": "md", + "validations": { + "matchRegexp": "/^\\w{4}-\\w{4}-\\w{4}$/" + }, + "validationErrors": { + "matchRegexp": "您输入的内容格式不对,请按提示输入!" + }, + "hint": "输入范例:xxxx-xxxx-xxxx" + }, + + { + "label": "置顶", + "type": "switch", + "name": "c", + "inline": true, + "labelRemark": "开启后将置顶这条数据!" + }, + + { + "label": "活动时间", + "type": "date-range", + "name": "range", + "size": "md", + "remark": "这是一个字段时间范围" + }, + + { + "label": "日期范围", + "type": "group", + "controls": [ + { + "type": "date", + "size": "md", + "name": "start", + "mode": "inline", + "maxDate": "${end}" + }, + + { + "label": "到", + "type": "date", + "size": "md", + "name": "end", + "inputClassName": "m-l-sm", + "mode": "inline", + "minDate": "${start}", + "remark": "这是两个字段的时间范围" + } + ] + }, + + { + "label": "浏览器", + "type": "button-group", + "name": "browser", + "value": "chrome", + "options": [ + { + "label": "Chrome", + "value": "chrome" + }, + + { + "label": "火狐", + "value": "firefox" + }, + + { + "label": "IE", + "value": "ie" + } + ] + }, + + { + "type": "list", + "name": "taocan", + "label": "套餐选择", + "options": [ + { + "value": 1, + "body": " " + }, + { + "value": 2, + "body": "套餐:C01CPU:2核内存:1GBSSD盘:10GB" + }, + { + "value": 3, + "disabled": true, + "body": "套餐:C02CPU:4核内存:4GBSSD盘:20GB" + } + ] + }, + + { + "label": "最爱周几", + "type": "select", + "name": "select", + "size": "md", + "clearable": true, + "options": [ + { + "label": "周一", + "value": "0" + }, + + { + "label": "周二", + "value": "1" + }, + + { + "label": "周三", + "value": "2" + }, + + { + "label": "周四", + "value": "3" + }, + + { + "label": "周五", + "value": "4" + }, + + { + "label": "周六", + "value": "5" + }, + + { + "label": "周日", + "value": "6" + } + ] + }, + + { + "label": "休息日", + "type": "list", + "name": "freeday", + "value": ["5", "6"], + "multiple": true, + "extractValue": true, + "options": [ + { + "label": "周一", + "value": "0" + }, + + { + "label": "周二", + "value": "1" + }, + + { + "label": "周三", + "value": "2" + }, + + { + "label": "周四", + "value": "3" + }, + + { + "label": "周五", + "value": "4" + }, + + { + "label": "周六", + "value": "5" + }, + + { + "label": "周日", + "value": "6" + } + ] + }, + + { + "label": "人数", + "type": "number", + "name": "num", + "size": "md", + "value": 10 + }, + + { + "label": "比率", + "type": "range", + "name": "percent" + }, + + { + "label": "简介", + "type": "textarea", + "name": "textarea" + } + ] + } + ] +} diff --git a/frontend/x-pages/jsonp.js b/frontend/x-pages/jsonp.js new file mode 100644 index 0000000..9612fb8 --- /dev/null +++ b/frontend/x-pages/jsonp.js @@ -0,0 +1,12 @@ +(function() { + const response = { + data: { + type: "page", + title: "标题", + body: "this result is from jsonp" + }, + status: 0 + } + + window.jsonpCallback && window.jsonpCallback(response); +})(); diff --git a/frontend/x-pages/pageA.json b/frontend/x-pages/pageA.json new file mode 100644 index 0000000..f2921c5 --- /dev/null +++ b/frontend/x-pages/pageA.json @@ -0,0 +1,177 @@ +{ + "type": "page", + "toolbar": [ + { + "type": "form", + "panelClassName": "mb-0", + "title": "", + "body": [ + { + "type": "select", + "label": "区域", + "name": "businessLineId", + "selectFirst": true, + "mode": "inline", + "options": [ + "北京", + "上海" + ], + "checkAll": false + }, + { + "label": "时间范围", + "type": "input-date-range", + "name": "dateRange", + "inline": true, + "value": "-1month,+0month", + "inputFormat": "YYYY-MM-DD", + "format": "YYYY-MM-DD", + "closeOnSelect": true, + "clearable": false + } + ], + "actions": [], + "mode": "inline", + "target": "mainPage", + "submitOnChange": true, + "submitOnInit": true + } + ], + "body": [ + { + "type": "table", + "title": "表格1", + "source": "$rows", + "columns": [ + { + "name": "engine", + "label": "Engine" + }, + { + "name": "version", + "label": "Version" + } + ] + }, + { + "type": "grid", + "columns": [ + { + "type": "panel", + "className": "h-full", + "body": { + "type": "tabs", + "tabs": [ + { + "title": "消费趋势", + "tab": [ + { + "type": "chart", + "config": { + "title": { + "text": "消费趋势" + }, + "tooltip": {}, + "xAxis": { + "type": "category", + "boundaryGap": false, + "data": [ + "一月", + "二月", + "三月", + "四月", + "五月", + "六月" + ] + }, + "yAxis": {}, + "series": [ + { + "name": "销量", + "type": "line", + "areaStyle": { + "color": { + "type": "linear", + "x": 0, + "y": 0, + "x2": 0, + "y2": 1, + "colorStops": [ + { + "offset": 0, + "color": "rgba(84, 112, 197, 1)" + }, + { + "offset": 1, + "color": "rgba(84, 112, 197, 0)" + } + ], + "global": false + } + }, + "data": [ + 5, + 20, + 36, + 10, + 10, + 20 + ] + } + ] + } + } + ] + }, + { + "title": "账户余额", + "tab": "0" + } + ] + } + }, + { + "type": "panel", + "className": "h-full", + "body": [ + { + "type": "chart", + "config": { + "title": { + "text": "使用资源占比" + }, + "series": [ + { + "type": "pie", + "data": [ + { + "name": "BOS", + "value": 70 + }, + { + "name": "CDN", + "value": 68 + }, + { + "name": "BCC", + "value": 48 + }, + { + "name": "DCC", + "value": 40 + }, + { + "name": "RDS", + "value": 32 + } + ] + } + ] + } + } + ] + } + ] + } + ] + } \ No newline at end of file diff --git a/frontend/x-pages/site.json b/frontend/x-pages/site.json new file mode 100644 index 0000000..f853737 --- /dev/null +++ b/frontend/x-pages/site.json @@ -0,0 +1,126 @@ +{ + "status": 0, + "msg": "", + "data": { + "pages": [ + { + "label": "Home", + "url": "/", + "redirect": "/index/1" + }, + { + "label": "示例", + "children": [ + { + "label": "表格", + "schemaApi": "get:/pages/excel.json" + }, + { + "label": "页面A", + "url": "index", + "schema": { + "type": "page", + "title": "页面A", + "body": "页面A" + }, + "children": [ + { + "label": "页面A-1", + "schemaApi": "get:/pages/pageA.json" + }, + { + "label": "页面A-2", + "url": "2", + "schema": { + "type": "page", + "title": "页面A-2", + "body": "页面A-2" + } + }, + { + "label": "页面A-3", + "url": "3", + "schema": { + "type": "page", + "title": "页面A-3", + "body": "页面A-3" + } + } + ] + }, + { + "label": "页面B", + "schema": { + "type": "page", + "title": "页面B", + "body": "页面B" + } + }, + { + "label": "页面C", + "schema": { + "type": "page", + "title": "页面C", + "body": "页面C" + } + }, + { + "label": "列表示例", + "url": "/crud", + "rewrite": "/crud/list", + "icon": "fa fa-cube", + "children": [ + { + "label": "列表", + "url": "/crud/list", + "icon": "fa fa-list", + "schemaApi": "get:/pages/crud-list.json" + }, + { + "label": "新增", + "url": "/crud/new", + "icon": "fa fa-plus", + "schemaApi": "get:/pages/crud-new.json" + }, + { + "label": "查看", + "url": "/crud/:id", + "schemaApi": "get:/pages/crud-view.json" + }, + { + "label": "修改", + "url": "/crud/:id/edit", + "schemaApi": "get:/pages/crud-edit.json" + } + ] + } + ] + }, + { + "label": "分组2", + "children": [ + { + "label": "用户管理", + "schema": { + "type": "page", + "title": "用户管理", + "body": "页面C" + } + }, + { + "label": "外部链接", + "link": "http://baidu.gitee.io/amis" + }, + { + "label": "部门管理", + "schemaApi": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/service/form?tpl=tpl3" + }, + { + "label": "jsonp 返回示例", + "schemaApi": "jsonp:/pages/jsonp.js?callback=jsonpCallback" + } + ] + } + ] + } +} diff --git a/frontend/x-pages/wizard.json b/frontend/x-pages/wizard.json new file mode 100644 index 0000000..11ed771 --- /dev/null +++ b/frontend/x-pages/wizard.json @@ -0,0 +1,105 @@ +{ + "type": "page", + "title": "表单向导", + "subTitle": "可以通过表单向导,将一个超长的表单页面拆分成多个步骤,一步一步指引用户完成。", + "body": [ + { + "type": "wizard", + "actionFinishLabel": "确认", + "api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/saveWizard", + "steps": [ + { + "title": "填写活动信息", + "controls": [ + { + "type": "text", + "name": "title", + "label": "活动标题", + "required": true, + "size": "md" + }, + + { + "type": "date", + "name": "date", + "label": "举办时间", + "size": "md" + }, + + { + "type": "number", + "name": "num", + "label": "参与人数", + "value": 10, + "size": "md" + } + ] + }, + + { + "title": "填写赞助商信息", + "controls": [ + { + "type": "text", + "name": "company", + "label": "公司名称", + "required": true, + "size": "md" + }, + + { + "type": "text", + "name": "money", + "label": "赞助金额", + "addOn": { + "type": "text", + "label": "¥" + }, + "size": "md" + } + ] + }, + + { + "title": "确认", + "mode": "horizontal", + "horizontal": { + "leftFixed": "sm" + }, + "controls": [ + { + "type": "static", + "name": "company", + "label": "活动标题", + "labelClassName": "text-muted" + }, + { + "type": "static-date", + "name": "date", + "label": "举办时间", + "labelClassName": "text-muted" + }, + { + "type": "static", + "name": "num", + "label": "参与人数", + "labelClassName": "text-muted" + }, + { + "type": "static", + "name": "company", + "label": "公司名称", + "labelClassName": "text-muted" + }, + { + "type": "static", + "name": "money", + "label": "赞助金额", + "labelClassName": "text-muted" + } + ] + } + ] + } + ] +} diff --git a/handler/car.py b/handler/car.py index 32ea668..75aa63d 100644 --- a/handler/car.py +++ b/handler/car.py @@ -5,7 +5,7 @@ import logger from db.mysql import database from model.car.dto.list import ListDto from orm.jiakaobaodian import JiaKaoBaoDian -from utils.common import response +from utils.common import response, amis_response from utils.model import model_list router = APIRouter(tags=["Car"], prefix="/api/car") @@ -36,3 +36,15 @@ def get_list(dto: ListDto, db: Session = Depends(database)): "size": size, "total": total }) + + +@router.post("/amis/list", summary="amis 题目列表") +def amis_get_list(dto: ListDto, db: Session = Depends(database)): + result = get_list(dto, db)['data'] + + return amis_response({ + "rows": result['data'], + "page": result['page'], + "size": result['size'], + "total": result['total'] + }) diff --git a/main.py b/main.py index 5d7e1f4..7ed0526 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,10 @@ +import os.path + import logger import uvicorn -from fastapi import FastAPI, APIRouter +from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware +from fastapi.staticfiles import StaticFiles from handler import car, health # 禁用 redoc @@ -18,6 +21,9 @@ app.add_middleware( app.include_router(health.router) app.include_router(car.router) +frontend = os.path.join(os.path.dirname(__file__), "frontend") +app.mount("/", StaticFiles(directory=frontend, html=True)) + @app.on_event("startup") async def startup(): diff --git a/utils/common.py b/utils/common.py index 624f68b..c5276d0 100644 --- a/utils/common.py +++ b/utils/common.py @@ -19,3 +19,15 @@ def response(data: any, code=200, msg="OK"): "data": data, "msg": msg, } + + +def amis_response(data: any, code=0, msg="OK"): + return { + "status": code, + "data": data, + "msg": msg, + } + + +def response_to_amis_response(_response): + return amis_response(_response['data'], 0 if _response['code'] == 200 else _response['code'], _response['msg'])套餐:C03CPU:8核内存:8GBSSD盘:50GB