mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-03 20:48:49 +08:00
28 lines
12 KiB
JavaScript
28 lines
12 KiB
JavaScript
define('docs/getting_started.md', function(require, exports, module) {
|
||
|
||
module.exports = {
|
||
"title": "快速开始",
|
||
"html": "<p>这是一个基于 React 框架的页面渲染器,有配置就能生成页面,配置是什么样的?请前往<a href=\"/amis/docs/basic\">基本用法</a>阅读。知道怎么配置后,就可以用以下方式用于自己的项目了。</p>\n<h2><a class=\"anchor\" name=\"%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96\" href=\"#%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96\" aria-hidden=\"true\"><svg aria-hidden=\"true\" class=\"octicon octicon-link\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>安装依赖</h2><p>直接通过 npm 安装即可。</p>\n<pre><code>npm <span class=\"hljs-selector-tag\">i</span> amis\n</code></pre><h2><a class=\"anchor\" name=\"%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8-\" href=\"#%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8-\" aria-hidden=\"true\"><svg aria-hidden=\"true\" class=\"octicon octicon-link\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>如何使用?</h2><p>可以在 React Component 这么使用。</p>\n<pre><code class=\"lang-tsx\"><span class=\"hljs-keyword\">import</span> * as <span class=\"hljs-type\">React</span> from <span class=\"hljs-symbol\">'reac</span>t';\n<span class=\"hljs-keyword\">import</span> {\n render as renderAmis\n} from <span class=\"hljs-symbol\">'ami</span>s';\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">MyComponent</span> <span class=\"hljs-keyword\">extends</span> <span class=\"hljs-title\">React</span>.<span class=\"hljs-title\">Component<any</span>, <span class=\"hljs-title\">any></span> </span>{\n render() {\n <span class=\"hljs-keyword\">return</span> (\n <div>\n <p>通过 amis 渲染页面</p>\n {renderAmis({\n <span class=\"hljs-comment\">// schema</span>\n <span class=\"hljs-comment\">// 这里是 amis 的 Json 配置。</span>\n <span class=\"hljs-class\"><span class=\"hljs-keyword\">type</span></span>: <span class=\"hljs-symbol\">'pag</span>e',\n title: '简单页面',\n body: '内容'\n }, {\n <span class=\"hljs-comment\">// props</span>\n }, {\n <span class=\"hljs-comment\">// env</span>\n <span class=\"hljs-comment\">// 这些是 amis 需要的一些接口实现</span>\n <span class=\"hljs-comment\">// 可以参考本项目里面的 Demo 部分代码。</span>\n\n updateLocation: (location:string<span class=\"hljs-comment\">/*目标地址*/</span>, replace:boolean<span class=\"hljs-comment\">/*是replace,还是push?*/</span>) => {\n <span class=\"hljs-comment\">// 用来更新地址栏</span>\n },\n\n jumpTo: (location:string<span class=\"hljs-comment\">/*目标地址*/</span>) => {\n <span class=\"hljs-comment\">// 页面跳转, actionType: link、url 都会进来。</span>\n },\n\n fetcher: ({\n url,\n method,\n data,\n config\n }:{\n url:string<span class=\"hljs-comment\">/*目标地址*/</span>,\n method:<span class=\"hljs-symbol\">'ge</span>t' | <span class=\"hljs-symbol\">'pos</span>t' | <span class=\"hljs-symbol\">'pu</span>t' | <span class=\"hljs-symbol\">'delet</span>e'<span class=\"hljs-comment\">/*发送方式*/</span>,\n data: <span class=\"hljs-class\"><span class=\"hljs-keyword\">object</span> <span class=\"hljs-title\">|</span> <span class=\"hljs-title\">void/*数据*/</span>,</span>\n config: <span class=\"hljs-class\"><span class=\"hljs-keyword\">object</span><span class=\"hljs-title\">/*其他配置*/</span></span>\n }) => {\n <span class=\"hljs-comment\">// 用来发送 Ajax 请求,建议使用 axios</span>\n },\n notify: (<span class=\"hljs-class\"><span class=\"hljs-keyword\">type</span></span>:<span class=\"hljs-symbol\">'erro</span>r'|<span class=\"hljs-symbol\">'succes</span>s'<span class=\"hljs-comment\">/**/</span>, msg:string<span class=\"hljs-comment\">/*提示内容*/</span>) => {\n <span class=\"hljs-comment\">// 用来提示用户</span>\n },\n alert: (content:string<span class=\"hljs-comment\">/*提示信息*/</span>) => {\n <span class=\"hljs-comment\">// 另外一种提示,可以直接用系统框</span>\n },\n confirm: (content:string<span class=\"hljs-comment\">/*提示信息*/</span>) => {\n <span class=\"hljs-comment\">// 确认框。</span>\n }\n });}\n </div>\n );\n }\n}\n</code></pre>\n<p><code>(schema:Schema, props?:any, env?: any) => JSX.Element</code></p>\n<p>参数说明:</p>\n<ul>\n<li><code>schema</code> 即页面配置,请前往<a href=\"/amis/docs/basic\">基本用法</a>了解.</li>\n<li><p><code>props</code> 一般都用不上,如果你想传递一些数据给渲染器内部使用,可以传递 data 数据进去。如:</p>\n<pre><code class=\"lang-jsx\">() => renderAmis(<span class=\"hljs-name\">schema</span>, {\n data: {\n username: 'amis'\n }\n})\n</code></pre>\n<p>这样,内部所有组件都能拿到 <code>username</code> 这个变量的值。</p>\n</li>\n<li><p><code>env</code> 环境变量,可以理解为这个渲染器工具的配置项,需要调用者实现部分接口。</p>\n<ul>\n<li><code>session: string</code> 默认为 'global',决定 store 是否为全局共用的,如果想单占一个 store,请设置不同的值。</li>\n<li><p><code>fetcher: (config: fetcherConfig) => Promise<fetcherResult></code> 用来实现 ajax 发送。</p>\n<p>示例</p>\n<pre><code class=\"lang-js\">fetcher: ({\n url,\n method,\n <span class=\"hljs-keyword\">data</span>,\n responseType,\n config,\n headers\n}: any) => {\n config = config || {};\n config.withCredentials = <span class=\"hljs-literal\">true</span>;\n responseType && (config.responseType = responseType);\n\n <span class=\"hljs-keyword\">if</span> (config.cancelExecutor) {\n config.cancelToken = new (axios <span class=\"hljs-keyword\">as</span> any).CancelToken(config.cancelExecutor);\n }\n\n config.headers = headers || {};\n\n <span class=\"hljs-keyword\">if</span> (method !== <span class=\"hljs-string\">'post'</span> && method !== <span class=\"hljs-string\">'put'</span> && method !== <span class=\"hljs-string\">'patch'</span>) {\n <span class=\"hljs-keyword\">if</span> (<span class=\"hljs-keyword\">data</span>) {\n config.params = <span class=\"hljs-keyword\">data</span>;\n }\n\n <span class=\"hljs-keyword\">return</span> (axios <span class=\"hljs-keyword\">as</span> any)[method](url, config);\n } <span class=\"hljs-keyword\">else</span> <span class=\"hljs-keyword\">if</span> (<span class=\"hljs-keyword\">data</span> && <span class=\"hljs-keyword\">data</span> instanceof FormData) {\n <span class=\"hljs-comment\">// config.headers = config.headers || {};</span>\n <span class=\"hljs-comment\">// config.headers['Content-Type'] = 'multipart/form-data';</span>\n } <span class=\"hljs-keyword\">else</span> <span class=\"hljs-keyword\">if</span> (<span class=\"hljs-keyword\">data</span>\n && typeof <span class=\"hljs-keyword\">data</span> !== <span class=\"hljs-string\">'string'</span>\n && !(<span class=\"hljs-keyword\">data</span> instanceof Blob)\n && !(<span class=\"hljs-keyword\">data</span> instanceof ArrayBuffer)\n ) {\n <span class=\"hljs-keyword\">data</span> = JSON.stringify(<span class=\"hljs-keyword\">data</span>);\n <span class=\"hljs-comment\">// config.headers = config.headers || {};</span>\n config.headers[<span class=\"hljs-string\">'Content-Type'</span>] = <span class=\"hljs-string\">'application/json'</span>;\n }\n\n <span class=\"hljs-keyword\">return</span> (axios <span class=\"hljs-keyword\">as</span> any)[method](url, <span class=\"hljs-keyword\">data</span>, config);\n}\n</code></pre>\n</li>\n<li><p><code>isCancel: (e:error) => boolean</code> 判断 ajax 异常是否为一个 cancel 请求。</p>\n<p>示例</p>\n<pre><code class=\"lang-js\">isCancel: (<span class=\"hljs-built_in\">value</span>: <span class=\"hljs-keyword\">any</span>) => (axios <span class=\"hljs-keyword\">as</span> <span class=\"hljs-keyword\">any</span>).isCancel(<span class=\"hljs-built_in\">value</span>)\n</code></pre>\n</li>\n<li><code>notify: (type:string, msg: string) => void</code> 用来实现消息提示。</li>\n<li><code>alert: (msg:string) => void</code> 用来实现警告提示。</li>\n<li><code>confirm: (msg:string) => boolean | Promise<boolean></code> 用来实现确认框。</li>\n<li><code>jumpTo: (to:string, action?: Action, ctx?: object) => void</code> 用来实现页面跳转,因为不清楚所在环境中是否使用了 spa 模式,所以用户自己实现吧。</li>\n<li><code>updateLocation: (location:any, replace?:boolean) => void</code> 地址替换,跟 jumpTo 类似。</li>\n<li><code>isCurrentUrl: (link:string) => boolean</code> 判断目标地址是否为当前页面。</li>\n<li><code>theme: 'default' | 'cxd'</code> 目前支持两种主题。 </li>\n<li><code>copy: (contents:string, options?: {shutup: boolean}) => void</code> 用来实现,内容复制。</li>\n<li><code>getModalContainer: () => HTMLElement</code> 用来决定弹框容器。</li>\n<li><code>loadRenderer: (chema:any, path:string) => Promise<Function></code> 可以通过它懒加载自定义组件,比如: <a href=\"https://github.com/baidu/amis/blob/master/__tests__/factory.test.tsx#L64-L91。\">https://github.com/baidu/amis/blob/master/__tests__/factory.test.tsx#L64-L91。</a></li>\n<li><code>affixOffsetTop: number</code> 固顶间距,当你的有其他固顶元素时,需要设置一定的偏移量,否则会重叠。</li>\n<li><code>affixOffsetBottom: number</code> 固底间距,当你的有其他固底元素时,需要设置一定的偏移量,否则会重叠。</li>\n<li><code>richTextToken: string</code> 内置 rich-text 为 frolaEditor,想要使用,请自行购买,或者自己实现 rich-text 渲染器。</li>\n</ul>\n</li>\n</ul>\n",
|
||
"toc": {
|
||
"label": "目录",
|
||
"type": "toc",
|
||
"children": [
|
||
{
|
||
"label": "安装依赖",
|
||
"fragment": "%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96",
|
||
"fullPath": "#%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96",
|
||
"level": 2
|
||
},
|
||
{
|
||
"label": "如何使用?",
|
||
"fragment": "%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8-",
|
||
"fullPath": "#%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8-",
|
||
"level": 2
|
||
}
|
||
],
|
||
"level": 0
|
||
}
|
||
};
|
||
|
||
});
|