配合 amis 实现前端界面显示

This commit is contained in:
shikong 2023-05-31 21:43:20 +08:00
parent 7d19573f85
commit 5bc3db60e7
20 changed files with 1759 additions and 2 deletions

197
frontend/index.html Normal file
View File

@ -0,0 +1,197 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>amis admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1"
/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<link
rel="stylesheet"
title="default"
href="https://unpkg.com/amis@beta/sdk/sdk.css"
/>
<link
rel="stylesheet"
href="https://unpkg.com/amis@beta/sdk/helper.css"
/>
<script src="https://unpkg.com/amis@beta/sdk/sdk.js"></script>
<script src="https://unpkg.com/vue@2"></script>
<script src="https://unpkg.com/history@4.10.1/umd/history.js"></script>
<style>
html,
body,
.app-wrapper {
position: relative;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="root" class="app-wrapper"></div>
<script>
(function () {
let amis = amisRequire('amis/embed');
const match = amisRequire('path-to-regexp').match;
// 如果想用 browserHistory 请切换下这处代码, 其他不用变
// const history = History.createBrowserHistory();
const history = History.createHashHistory();
const app = {
type: 'app',
brandName: 'Admin',
logo: '/public/logo.png',
header: {
type: 'tpl',
inline: false,
className: 'w-full',
tpl: '<div class="flex justify-between"><div>顶部区域左侧</div><div>顶部区域右侧</div></div>'
},
// footer: '<div class="p-2 text-center bg-light">底部区域</div>',
// asideBefore: '<div class="p-2 text-center">菜单前面区域</div>',
// asideAfter: '<div class="p-2 text-center">菜单后面区域</div>',
api: '/pages/site.json'
};
function normalizeLink(to, location = history.location) {
to = to || '';
if (to && to[0] === '#') {
to = location.pathname + location.search + to;
} else if (to && to[0] === '?') {
to = location.pathname + to;
}
const idx = to.indexOf('?');
const idx2 = to.indexOf('#');
let pathname = ~idx
? to.substring(0, idx)
: ~idx2
? to.substring(0, idx2)
: to;
let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
let hash = ~idx2 ? to.substring(idx2) : location.hash;
if (!pathname) {
pathname = location.pathname;
} else if (pathname[0] != '/' && !/^https?\:\/\//.test(pathname)) {
let relativeBase = location.pathname;
const paths = relativeBase.split('/');
paths.pop();
let m;
while ((m = /^\.\.?\//.exec(pathname))) {
if (m[0] === '../') {
paths.pop();
}
pathname = pathname.substring(m[0].length);
}
pathname = paths.concat(pathname).join('/');
}
return pathname + search + hash;
}
function isCurrentUrl(to, ctx) {
if (!to) {
return false;
}
const pathname = history.location.pathname;
const link = normalizeLink(to, {
...location,
pathname,
hash: ''
});
if (!~link.indexOf('http') && ~link.indexOf(':')) {
let strict = ctx && ctx.strict;
return match(link, {
decode: decodeURIComponent,
strict: typeof strict !== 'undefined' ? strict : true
})(pathname);
}
return decodeURI(pathname) === link;
}
let amisInstance = amis.embed(
'#root',
app,
{
location: history.location
},
{
// watchRouteChange: fn => {
// return history.listen(fn);
// },
updateLocation: (location, replace) => {
location = normalizeLink(location);
if (location === 'goBack') {
return history.goBack();
} else if (
(!/^https?\:\/\//.test(location) &&
location ===
history.location.pathname + history.location.search) ||
location === history.location.href
) {
// 目标地址和当前地址一样,不处理,免得重复刷新
return;
} else if (/^https?\:\/\//.test(location) || !history) {
return (window.location.href = location);
}
history[replace ? 'replace' : 'push'](location);
},
jumpTo: (to, action) => {
if (to === 'goBack') {
return history.goBack();
}
to = normalizeLink(to);
if (isCurrentUrl(to)) {
return;
}
if (action && action.actionType === 'url') {
action.blank === false
? (window.location.href = to)
: window.open(to, '_blank');
return;
} else if (action && action.blank) {
window.open(to, '_blank');
return;
}
if (/^https?:\/\//.test(to)) {
window.location.href = to;
} else if (
(!/^https?\:\/\//.test(to) &&
to === history.pathname + history.location.search) ||
to === history.location.href
) {
// do nothing
} else {
history.push(to);
}
},
isCurrentUrl: isCurrentUrl,
theme: 'cxd'
}
);
history.listen(state => {
amisInstance.updateProps({
location: state.location || state
});
});
})();
</script>
</body>
</html>

View File

@ -0,0 +1,152 @@
{
"type": "page",
"body": [
{
"title": "查询条件",
"type": "form",
"target": "dataTable",
"body": [
{
"type": "input-text",
"name": "keyword",
"label": "关键字:"
}
],
"submitText": "搜索"
},
{
"type": "crud",
"name": "dataTable",
"api": {
"method": "post",
"url": "/api/car/amis/list",
"data": {
"page": "${page}",
"size": "${perPage}",
"keyword": "$keyword"
}
},
"mode": "cards",
"data": {
"answerMap": [
"",
"",
"",
"",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H"
]
},
"columnsCount": 1,
"card": {
"body": [
{
"name": "id",
"label": "id",
"hidden": true
},
{
"name": "question_id",
"label": "题目id",
"hidden": true
},
{
"name": "keywords",
"label": "关键字",
"hidden": true
},
{
"name": "answer",
"label": "答案",
"type": "tpl",
"tpl": "<span><%= data.answerMap.filter((_,index)=>{return (data.answer).toString(2).split('').reverse()[index] == '1'}) %></span>"
},
{
"name": "question",
"label": "题目"
},
{
"name": "media_content",
"label": "图片",
"width": "400px",
"height": "300px",
"type": "image",
"enlargeAble": true,
"hiddenOn": "this.media_content == 'None'"
},
{
"name": "option_a",
"label": "A",
"hiddenOn": "this.option_a.length == 0"
},
{
"name": "option_b",
"label": "B",
"hiddenOn": "this.option_b.length == 0"
},
{
"name": "option_c",
"label": "C",
"hiddenOn": "this.option_c.length == 0"
},
{
"name": "option_d",
"label": "D",
"hiddenOn": "this.option_d.length == 0"
},
{
"name": "option_e",
"label": "E",
"hiddenOn": "this.option_e.length == 0"
},
{
"name": "option_f",
"label": "F",
"hiddenOn": "this.option_f.length == 0"
},
{
"name": "option_g",
"label": "G",
"hiddenOn": "this.option_g.length == 0"
},
{
"name": "option_h",
"label": "H",
"hiddenOn": "this.option_h.length == 0"
},
{
"name": "explain",
"label": "解析",
"body": "$explain"
},
{
"name": "illiteracy_explain",
"label": "相关规定"
},
{
"name": "knack",
"label": "窍门"
},
{
"name": "concise_explain",
"label": "简单解析"
},
{
"name": "wrong_rate",
"label": "错误率",
"type": "tpl",
"tpl": "${wrong_rate * 100}%"
}
]
}
}
]
}

23
frontend/pages/site.json Normal file
View File

@ -0,0 +1,23 @@
{
"status": 0,
"msg": "",
"data": {
"pages": [
{
"label": "Home",
"url": "/",
"redirect": "/index"
},
{
"label": "题库",
"children": [
{
"label": "题库",
"url": "/index",
"schemaApi": "get:/pages/question.json"
}
]
}
]
}
}

BIN
frontend/public/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -0,0 +1,5 @@
{
"type": "page",
"title": "Dashboard",
"body": "body..."
}

View File

@ -0,0 +1,274 @@
{
"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": [
{
"type": "fieldSet",
"title": "基本配置",
"controls": [
{
"type": "text",
"label": "任务名称",
"name": "title",
"size": "md",
"required": true
},
{
"type": "textarea",
"label": "任务描述",
"name": "description",
"size": "md"
},
{
"label": "任务频率",
"type": "radios",
"name": "repeat",
"inline": true,
"value": "none",
"required": true,
"options": [
{
"label": "不重复",
"value": "none"
},
{
"label": "每天",
"value": "day"
},
{
"label": "每周",
"value": "week"
},
{
"label": "每月",
"value": "month"
}
]
},
{
"label": "每天几点",
"type": "select",
"name": "time",
"multiple": true,
"required": true,
"extractValue": true,
"visibleOn": "this.repeat == \"day\"",
"inline": true,
"options": [
{"value": 0, "label": "0:00"},
{"value": 1, "label": "1:00"},
{"value": 2, "label": "2:00"},
{"value": 3, "label": "3:00"},
{"value": 4, "label": "4:00"},
{"value": 5, "label": "5:00"},
{"value": 6, "label": "6:00"},
{"value": 7, "label": "7:00"},
{"value": 8, "label": "8:00"},
{"value": 9, "label": "9:00"},
{"value": 10, "label": "10:00"},
{"value": 11, "label": "11:00"},
{"value": 12, "label": "12:00"},
{"value": 13, "label": "13:00"},
{"value": 14, "label": "14:00"},
{"value": 15, "label": "15:00"},
{"value": 16, "label": "16:00"},
{"value": 17, "label": "17:00"},
{"value": 18, "label": "18:00"},
{"value": 19, "label": "19:00"},
{"value": 20, "label": "20:00"},
{"value": 21, "label": "21:00"},
{"value": 22, "label": "22:00"},
{"value": 23, "label": "23:00"}
]
},
{
"label": "每周几执行",
"type": "button-group",
"name": "weekdays",
"size": "md",
"visibleOn": "this.repeat == \"week\"",
"clearable": true,
"multiple": true,
"required": true,
"extractValue": true,
"maxLength": 7,
"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": "monthday",
"size": "md",
"visibleOn": "this.repeat == \"month\"",
"required": true,
"maxLength": 31,
"clearable": true,
"multiple": true,
"extractValue": true,
"options": [
{"value": 0, "label": "01"},
{"value": 1, "label": "02"},
{"value": 2, "label": "03"},
{"value": 3, "label": "04"},
{"value": 4, "label": "05"},
{"value": 5, "label": "06"},
{"value": 6, "label": "07"},
{"value": 7, "label": "08"},
{"value": 8, "label": "09"},
{"value": 9, "label": "10"},
{"value": 10, "label": "11"},
{"value": 11, "label": "12"},
{"value": 12, "label": "13"},
{"value": 13, "label": "14"},
{"value": 14, "label": "15"},
{"value": 15, "label": "16"},
{"value": 16, "label": "17"},
{"value": 17, "label": "18"},
{"value": 18, "label": "19"},
{"value": 19, "label": "20"},
{"value": 20, "label": "21"},
{"value": 21, "label": "22"},
{"value": 22, "label": "23"},
{"value": 23, "label": "24"},
{"value": 24, "label": "25"},
{"value": 25, "label": "26"},
{"value": 26, "label": "27"},
{"value": 27, "label": "28"},
{"value": 28, "label": "29"},
{"value": 29, "label": "30"},
{"value": 30, "label": "31"}
]
}
]
},
{
"type": "fieldSet",
"title": "其他信息",
"collapsable": true,
"controls": [
{
"type": "combo",
"name": "admins",
"label": "用户列表",
"value": [""],
"description": "请输入用户信息,不要重复。",
"multiple": true,
"inline": true,
"controls": [
{
"type": "text",
"name": "name",
"unique": true
},
{
"type": "select",
"name": "perm",
"value": "read",
"options": [
{
"label": "可读",
"value": "read"
},
{
"label": "可写",
"value": "write"
}
]
}
]
},
{
"label": "新增一行",
"type": "button",
"actionType": "add",
"target": "thetable",
"level": "info"
},
{
"name": "thetable",
"type": "table",
"label": "任务参数",
"editable": true,
"addable": true,
"removable": true,
"columns": [
{
"label": "参数名",
"name": "key",
"quickEdit": true
},
{
"label": "参数值",
"name": "value",
"quickEdit": true
}
]
}
]
}
]
}
]
}

View File

@ -0,0 +1,64 @@
{
"type": "page",
"title": "修改 ${params.id}",
"remark": null,
"toolbar": [
{
"type": "button",
"actionType": "link",
"link": "/crud/list",
"label": "返回列表"
}
],
"body": [
{
"type": "form",
"initApi": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/${params.id}",
"api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/$id",
"redirect": "/crud/list",
"controls": [
{
"type": "text",
"name": "engine",
"label": "Engine",
"required": true
},
{
"type": "divider"
},
{
"type": "text",
"name": "browser",
"label": "Browser",
"required": true
},
{
"type": "divider"
},
{
"type": "text",
"name": "platform",
"label": "Platform(s)",
"required": true
},
{
"type": "divider"
},
{
"type": "text",
"name": "version",
"label": "Engine version"
},
{
"type": "divider"
},
{
"type": "select",
"name": "grade",
"label": "CSS grade",
"options": ["A", "B", "C", "D", "X"]
}
]
}
]
}

View File

@ -0,0 +1,149 @@
{
"type": "page",
"title": "列表",
"remark": null,
"name": "page-demo",
"toolbar": [
{
"type": "button",
"actionType": "link",
"link": "/crud/new",
"label": "新增",
"primary": true
}
],
"body": [
{
"type": "crud",
"name": "sample",
"api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample",
"filter": {
"title": "",
"mode": "inline",
"wrapWithPanel": false,
"submitText": "",
"controls": [
{
"type": "text",
"name": "keywords",
"placeholder": "通过关键字搜索",
"addOn": {
"label": "搜索",
"type": "submit",
"className": "btn-success"
},
"clearable": true
}
],
"className": "m-b-sm"
},
"bulkActions": [
{
"label": "批量修改",
"type": "button",
"actionType": "dialog",
"level": "primary",
"dialog": {
"title": "批量编辑",
"name": "sample-bulk-edit",
"body": {
"type": "form",
"api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/bulkUpdate2",
"controls": [
{
"type": "text",
"name": "engine",
"label": "Engine"
}
]
}
}
},
{
"label": "批量删除",
"type": "button",
"level": "danger",
"actionType": "ajax",
"api": "delete:https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/$ids",
"confirmText": "确定要批量删除?"
}
],
"columns": [
{
"name": "engine",
"label": "Rendering engine",
"sortable": true
},
{
"name": "id",
"label": "ID",
"width": 20,
"sortable": true
},
{
"name": "browser",
"label": "Browser",
"sortable": true
},
{
"name": "platform",
"label": "Platform(s)",
"sortable": true
},
{
"name": "version",
"label": "Engine version"
},
{
"name": "grade",
"label": "CSS grade"
},
{
"type": "operation",
"label": "操作",
"width": "",
"buttons": [
{
"type": "button-group",
"buttons": [
{
"type": "button",
"label": "查看",
"level": "primary",
"actionType": "link",
"link": "/crud/${id}"
},
{
"type": "button",
"label": "修改",
"level": "info",
"actionType": "link",
"link": "/crud/${id}/edit"
},
{
"type": "button",
"label": "删除",
"level": "danger",
"actionType": "ajax",
"confirmText": "您确认要删除?",
"api": "delete:https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/$id"
}
]
}
],
"placeholder": "-",
"fixed": "right"
}
],
"affixHeader": true,
"columnsTogglable": "auto",
"placeholder": "暂无数据",
"tableClassName": "table-db table-striped",
"headerClassName": "crud-table-header",
"footerClassName": "crud-table-footer",
"toolbarClassName": "crud-table-toolbar",
"combineNum": 0,
"bodyClassName": "panel-default"
}
]
}

View File

@ -0,0 +1,69 @@
{
"type": "page",
"title": "新增",
"remark": null,
"toolbar": [
{
"type": "button",
"actionType": "link",
"link": "/crud/list",
"label": "返回列表"
}
],
"body": [
{
"title": "",
"type": "form",
"redirect": "/crud/list",
"name": "sample-edit-form",
"api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample",
"controls": [
{
"type": "text",
"name": "engine",
"label": "Engine",
"required": true,
"inline": false,
"description": "",
"descriptionClassName": "help-block",
"placeholder": "",
"addOn": null
},
{
"type": "divider"
},
{
"type": "text",
"name": "browser",
"label": "Browser",
"required": true
},
{
"type": "divider"
},
{
"type": "text",
"name": "platform",
"label": "Platform(s)",
"required": true
},
{
"type": "divider"
},
{
"type": "text",
"name": "version",
"label": "Engine version"
},
{
"type": "divider"
},
{
"type": "text",
"name": "grade",
"label": "CSS grade"
}
]
}
]
}

View File

@ -0,0 +1,65 @@
{
"type": "page",
"title": "查看详情 ${params.id}",
"remark": null,
"toolbar": [
{
"type": "button",
"actionType": "link",
"link": "/crud/list",
"label": "返回列表"
}
],
"body": [
{
"type": "form",
"initApi": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/${params.id}",
"controls": [
{
"type": "static",
"name": "engine",
"label": "Engine"
},
{
"type": "divider"
},
{
"type": "static",
"name": "browser",
"label": "Browser"
},
{
"type": "divider"
},
{
"type": "static",
"name": "platform",
"label": "Platform(s)"
},
{
"type": "divider"
},
{
"type": "static",
"name": "version",
"label": "Engine version"
},
{
"type": "divider"
},
{
"type": "static",
"name": "grade",
"label": "CSS grade"
},
{
"type": "divider"
},
{
"type": "html",
"html": "<p>添加其他 <span>Html 片段</span> 需要支持变量替换todo.</p>"
}
]
}
]
}

View File

@ -0,0 +1,18 @@
{
"type": "page",
"title": "代码编辑器",
"subTitle": "使用的monaco-editor,用到了 worker, 如果控制台没有报错,说明一起正常。",
"body": [
{
"type": "form",
"controls": [
{
"type": "editor",
"name": "js",
"label": "Javascript",
"size": "md"
}
]
}
]
}

View File

@ -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": {
"*": "<span class=\"label label-info\">${grade}</span>"
}
}
]
}
}

View File

@ -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": "<div class='m-l-sm m-r-sm m-b-sm m-t-xs'> <div class='text-md p-b-xs b-b m-b-xs'>套餐C01</div> <div class='text-sm'>CPU2核</div> <div class='text-sm'>内存1GB</div> <div class='text-sm'>SSD盘10GB</div> </div>"
},
{
"value": 2,
"body": "<div class='m-l-sm m-r-sm m-b-sm m-t-xs'> <div class='text-md p-b-xs b-b m-b-xs'>套餐C02</div> <div class='text-sm'>CPU4核</div> <div class='text-sm'>内存4GB</div> <div class='text-sm'>SSD盘20GB</div> </div>"
},
{
"value": 3,
"disabled": true,
"body": "<div class='m-l-sm m-r-sm m-b-sm m-t-xs'> <div class='text-md p-b-xs b-b m-b-xs'>套餐C03</div> <div class='text-sm'>CPU8核</div> <div class='text-sm'>内存8GB</div> <div class='text-sm'>SSD盘50GB</div> </div>"
}
]
},
{
"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"
}
]
}
]
}

12
frontend/x-pages/jsonp.js Normal file
View File

@ -0,0 +1,12 @@
(function() {
const response = {
data: {
type: "page",
title: "标题",
body: "this result is from jsonp"
},
status: 0
}
window.jsonpCallback && window.jsonpCallback(response);
})();

177
frontend/x-pages/pageA.json Normal file
View File

@ -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
}
]
}
]
}
}
]
}
]
}
]
}

126
frontend/x-pages/site.json Normal file
View File

@ -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"
}
]
}
]
}
}

View File

@ -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"
}
]
}
]
}
]
}

View File

@ -5,7 +5,7 @@ import logger
from db.mysql import database from db.mysql import database
from model.car.dto.list import ListDto from model.car.dto.list import ListDto
from orm.jiakaobaodian import JiaKaoBaoDian from orm.jiakaobaodian import JiaKaoBaoDian
from utils.common import response from utils.common import response, amis_response
from utils.model import model_list from utils.model import model_list
router = APIRouter(tags=["Car"], prefix="/api/car") router = APIRouter(tags=["Car"], prefix="/api/car")
@ -36,3 +36,15 @@ def get_list(dto: ListDto, db: Session = Depends(database)):
"size": size, "size": size,
"total": total "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']
})

View File

@ -1,7 +1,10 @@
import os.path
import logger import logger
import uvicorn import uvicorn
from fastapi import FastAPI, APIRouter from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from handler import car, health from handler import car, health
# 禁用 redoc # 禁用 redoc
@ -18,6 +21,9 @@ app.add_middleware(
app.include_router(health.router) app.include_router(health.router)
app.include_router(car.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") @app.on_event("startup")
async def startup(): async def startup():

View File

@ -19,3 +19,15 @@ def response(data: any, code=200, msg="OK"):
"data": data, "data": data,
"msg": msg, "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'])