vendor: amis 6.13.0 base (fork root)
This commit is contained in:
137
examples/app/app.tsx
Normal file
137
examples/app/app.tsx
Normal file
@@ -0,0 +1,137 @@
|
||||
export default {
|
||||
type: 'app',
|
||||
brandName: 'APP 模式',
|
||||
api: '/api/mock2/sample',
|
||||
// logo:
|
||||
// '<svg t="1610181550507" style="width: 30px; height: 30px;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2528" width="200" height="200"><path d="M217.090828 534.490224c99.683327-20.926612 86.12145-137.343041 83.128279-162.838715-4.906753-39.223327-52.112891-107.812471-116.217908-102.372575-80.693834 7.058766-92.487438 120.948653-92.487438 120.948653C80.583828 442.927855 117.654119 555.449581 217.090828 534.490224L217.090828 534.490224zM322.936505 737.004567c-2.907213 8.211009-9.413394 29.170366-3.781116 47.381124 11.123338 40.874943 51.108005 34.208103 51.108005 34.208103l56.034201 0L426.297594 706.525392l-56.034201 0C345.158622 713.864544 325.65543 728.85291 322.936505 737.004567L322.936505 737.004567zM402.144498 339.233168c55.081503 0 99.57588-61.946864 99.57588-138.461515 0-76.491115-44.494377-138.40728-99.57588-138.40728-54.974056 0-99.599416 61.916165-99.599416 138.40728C302.545082 277.286304 347.170442 339.233168 402.144498 339.233168L402.144498 339.233168zM639.288546 348.395852c73.635067 9.331529 120.925117-67.407226 130.340557-125.57195 9.582239-58.081837-37.906332-125.577067-90.024339-137.174196-52.219315-11.712763-117.390617 70.044286-123.329886 123.305327C549.187459 274.094612 565.853024 339.149257 639.288546 348.395852L639.288546 348.395852zM819.642171 690.38069c0 0-113.866351-86.12145-180.37716-179.167612-90.108251-137.176243-218.121809-81.367169-260.908288-11.604292C335.745229 569.372685 269.286608 613.477182 259.841491 625.187899c-9.552563 11.489682-137.50984 79.010495-109.128443 202.314799s135.49802 131.180691 135.49802 131.180691 66.203818-3.168156 151.517879-21.829168c85.312014-18.48705 158.833495 4.598738 158.833495 4.598738s199.320605 65.22349 253.866918-60.3546C904.897903 755.497757 819.642171 690.38069 819.642171 690.38069L819.642171 690.38069zM482.333842 874.629018 342.241176 874.629018c-55.946196-1.313925-71.552639-45.587268-74.354452-51.943023-2.777253-6.473435-18.606777-36.478819-10.226922-87.473237 24.179702-76.490092 84.613096-84.695984 84.613096-84.695984l84.053348 0L426.326247 566.464449l56.036247 0 0 308.164568L482.333842 874.629018zM706.478831 874.629018l-140.090619 0c-55.16746-2.355651-56.124252-52.927443-56.124252-52.927443l0.086981-171.2155 56.037271 0L566.388213 790.57874c3.697205 15.438621 28.016077 28.015054 28.016077 28.015054l56.037271 0L650.441561 650.486074l56.038294 0L706.479855 874.629018 706.478831 874.629018zM931.037237 446.066335c0-27.816532-23.675212-111.617124-111.395066-111.617124-87.919399 0-99.660814 79.093383-99.660814 135.016043 0 53.344952 4.592598 127.816061 113.806999 125.490086C943.00071 592.633459 931.037237 474.058876 931.037237 446.066335L931.037237 446.066335zM931.037237 446.066335" p-id="2529"></path></svg>',
|
||||
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>',
|
||||
pages: [
|
||||
{
|
||||
label: 'Home',
|
||||
url: '/',
|
||||
redirect: '/pageA'
|
||||
},
|
||||
{
|
||||
label: '示例',
|
||||
children: [
|
||||
{
|
||||
label: '页面A',
|
||||
url: 'pageA',
|
||||
schema: {
|
||||
type: 'page',
|
||||
title: '页面A',
|
||||
body: '页面A'
|
||||
},
|
||||
|
||||
children: [
|
||||
{
|
||||
label: '页面A-1',
|
||||
url: '1',
|
||||
schema: {
|
||||
type: 'page',
|
||||
title: '页面A-1',
|
||||
body: '页面A-1'
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
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: '/form',
|
||||
icon: 'fa fa-plus',
|
||||
schemaApi: '/api/mock2/service/schema?type=form'
|
||||
},
|
||||
{
|
||||
label: '列表',
|
||||
url: '/crud/list',
|
||||
icon: 'fa fa-list',
|
||||
badge: '${count}',
|
||||
badgeClassName: 'bg-info',
|
||||
schemaApi: '/api/mock2/service/schema?type=crud'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
label: '分组2',
|
||||
children: [
|
||||
{
|
||||
label: '用户管理',
|
||||
schema: {
|
||||
type: 'page',
|
||||
title: '用户管理',
|
||||
body: '页面C'
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
label: '外部链接',
|
||||
link: 'http://baidu.gitee.io/amis'
|
||||
},
|
||||
|
||||
{
|
||||
label: '部门管理',
|
||||
schemaApi: '/api/mock2/service/form?tpl=tpl3'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// {
|
||||
// label: '404',
|
||||
// visible: false,
|
||||
// isDefaultPage: true,
|
||||
// schema: {
|
||||
// type: 'page',
|
||||
// body: '自定义 404 页面,可以不配置'
|
||||
// }
|
||||
// }
|
||||
]
|
||||
};
|
||||
69
examples/app/index-vite.html
Normal file
69
examples/app/index-vite.html
Normal file
@@ -0,0 +1,69 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>amis app 模式</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<link
|
||||
type="image/x-icon"
|
||||
rel="shortcut icon"
|
||||
href="../static/favicon.png"
|
||||
/>
|
||||
<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" href="../static/iconfont.css" />
|
||||
<link rel="stylesheet" href="../static/officefont.css" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="../../node_modules/@fortawesome/fontawesome-free/css/all.css"
|
||||
/>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="../../node_modules/@fortawesome/fontawesome-free/css/v4-shims.css"
|
||||
/>
|
||||
<style>
|
||||
.app-wrapper,
|
||||
.schema-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
<script type="module">
|
||||
let theme = localStorage.getItem('amis-theme') || 'cxd';
|
||||
if (theme === 'default') {
|
||||
theme = 'cxd';
|
||||
}
|
||||
|
||||
['ang', 'cxd', 'dark', 'antd'].forEach(key => {
|
||||
const link = document.createElement('link');
|
||||
link.setAttribute('rel', 'stylesheet');
|
||||
link.setAttribute('title', key);
|
||||
if (theme !== key) {
|
||||
link.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
link.setAttribute(
|
||||
'href',
|
||||
new URL(
|
||||
`../../packages/amis-ui/scss/themes/${key}.scss`,
|
||||
import.meta.url
|
||||
).href
|
||||
);
|
||||
document.head.appendChild(link);
|
||||
});
|
||||
</script>
|
||||
<link rel="stylesheet" href="../../packages/amis-ui/scss/helper.scss" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root" class="app-wrapper"></div>
|
||||
<script type="module">
|
||||
import {bootstrap} from './index.jsx';
|
||||
const initialState = {};
|
||||
bootstrap(document.getElementById('root'), initialState);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
101
examples/app/index.html
Normal file
101
examples/app/index.html
Normal file
@@ -0,0 +1,101 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>amis app 模式</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<link
|
||||
type="image/x-icon"
|
||||
rel="shortcut icon"
|
||||
href="../static/favicon.png"
|
||||
/>
|
||||
<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" href="../static/iconfont.css" />
|
||||
<link rel="stylesheet" href="../static/officefont.css" />
|
||||
<link rel="stylesheet" href="@fortawesome/fontawesome-free/css/all.css" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="@fortawesome/fontawesome-free/css/v4-shims.css"
|
||||
/>
|
||||
<!--DEPENDENCIES_INJECT_PLACEHOLDER-->
|
||||
<!--STYLE_PLACEHOLDER-->
|
||||
<style>
|
||||
.app-wrapper,
|
||||
.schema-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
<script type="text/x-jsx">
|
||||
let theme = localStorage.getItem('amis-theme') || 'cxd';
|
||||
if (theme === 'default') {
|
||||
theme = 'cxd';
|
||||
}
|
||||
|
||||
// 非 IE 模式
|
||||
if (window.navigator.userAgent.indexOf('Trident') === -1) {
|
||||
document.write(
|
||||
`<link rel="stylesheet" title="ang" ${
|
||||
theme !== 'ang' ? 'disabled' : ''
|
||||
} href="${__uri('amis/lib/themes/ang.css')}" />`
|
||||
);
|
||||
document.write(
|
||||
`<link rel="stylesheet" title="cxd" ${
|
||||
theme !== 'cxd' ? 'disabled' : ''
|
||||
} href="${__uri('amis/lib/themes/cxd.css')}" />`
|
||||
);
|
||||
document.write(
|
||||
`<link rel="stylesheet" title="dark" ${
|
||||
theme !== 'dark' ? 'disabled' : ''
|
||||
} href="${__uri('amis/lib/themes/dark.css')}" />`
|
||||
);
|
||||
document.write(
|
||||
`<link rel="stylesheet" title="antd" ${
|
||||
theme !== 'antd' ? 'disabled' : ''
|
||||
} href="${__uri('amis/lib/themes/antd.css')}" />`
|
||||
);
|
||||
} else {
|
||||
document.write(
|
||||
`<link rel="stylesheet" title="ang" ${
|
||||
theme !== 'ang' ? 'disabled' : ''
|
||||
} href="${__uri('amis/lib/themes/ang-ie11.css')}" />`
|
||||
);
|
||||
document.write(
|
||||
`<link rel="stylesheet" title="cxd" ${
|
||||
theme !== 'cxd' ? 'disabled' : ''
|
||||
} href="${__uri('amis/lib/themes/cxd-ie11.css')}" />`
|
||||
);
|
||||
document.write(
|
||||
`<link rel="stylesheet" title="dark" ${
|
||||
theme !== 'dark' ? 'disabled' : ''
|
||||
} href="${__uri('amis/lib/themes/dark-ie11.css')}" />`
|
||||
);
|
||||
document.write(
|
||||
`<link rel="stylesheet" title="antd" ${
|
||||
theme !== 'antd' ? 'disabled' : ''
|
||||
} href="${__uri('amis/lib/themes/antd-ie11.css')}" />`
|
||||
);
|
||||
}
|
||||
</script>
|
||||
<!--ignore-->
|
||||
<link rel="stylesheet" href="amis/lib/helper.css" />
|
||||
<!--ignore-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root" class="app-wrapper"></div>
|
||||
<script src="../mod.js"></script>
|
||||
<script type="text/javascript">
|
||||
/* @require ./index.jsx 标记为同步依赖,提前加载 */
|
||||
amis.require(['./index.jsx'], function (app) {
|
||||
var initialState = {};
|
||||
app.bootstrap(document.getElementById('root'), initialState);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
147
examples/app/index.jsx
Normal file
147
examples/app/index.jsx
Normal file
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* @file app 模式示例
|
||||
*/
|
||||
|
||||
import APPSchema from './app';
|
||||
import {createHashHistory} from 'history';
|
||||
import {embed} from '../embed';
|
||||
import {match} from 'path-to-regexp';
|
||||
|
||||
const history = createHashHistory({});
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const APPENV = {
|
||||
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
|
||||
};
|
||||
|
||||
export function bootstrap(mountTo) {
|
||||
const amisInstance = embed(
|
||||
mountTo,
|
||||
APPSchema,
|
||||
{
|
||||
location: history.location,
|
||||
context: {
|
||||
amisUser: {
|
||||
id: 1,
|
||||
name: 'AMIS User'
|
||||
}
|
||||
}
|
||||
},
|
||||
APPENV
|
||||
);
|
||||
|
||||
history.listen(state => {
|
||||
amisInstance.updateProps({
|
||||
location: state.location || state
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user