mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-05 05:28:37 +08:00
34 lines
21 KiB
JavaScript
34 lines
21 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<p>如果你不会 React 也没关系可以看看 <a href=\"#jssdk\">JSSDK 用法</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><span class=\"hljs-built_in\">npm</span> i 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<h2><a class=\"anchor\" name=\"jssdk\" href=\"#jssdk\" 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>JSSDK</h2><p>如果你没有组件定制需求直接使用,而且不想折腾 React 相关的,我建议你直接用这种方式。</p>\n<p>首先请引用一下 CSS 和 JS。</p>\n<ul>\n<li>JS 地址: <a href=\"https://houtai.baidu.com/v2/jssdk\">https://houtai.baidu.com/v2/jssdk</a></li>\n<li>CSS 地址: <a href=\"https://houtai.baidu.com/v2/csssdk\">https://houtai.baidu.com/v2/csssdk</a></li>\n</ul>\n<p>然后执行以下代码就能渲染了。</p>\n<pre><code class=\"lang-js\">(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\"></span>) </span>{\n <span class=\"hljs-keyword\">var</span> amis = amisRequire(<span class=\"hljs-string\">'amis/embed'</span>);\n amis.embed(<span class=\"hljs-string\">'#container'</span>, {\n <span class=\"hljs-attr\">type</span>: <span class=\"hljs-string\">'page'</span>,\n <span class=\"hljs-attr\">title</span>: <span class=\"hljs-string\">'AMIS Demo'</span>,\n <span class=\"hljs-attr\">body</span>: <span class=\"hljs-string\">'This is a simple amis page.'</span>\n }, {\n <span class=\"hljs-comment\">// props 一般不用传。</span>\n }, {\n <span class=\"hljs-comment\">// env</span>\n fetcher: <span class=\"hljs-function\"><span class=\"hljs-params\">()</span> =></span> {\n <span class=\"hljs-comment\">// 可以不传,用来实现 ajax 请求</span>\n },\n\n <span class=\"hljs-attr\">jumpTo</span>: <span class=\"hljs-function\"><span class=\"hljs-params\">()</span> =></span> {\n <span class=\"hljs-comment\">// 可以不传,用来实现页面跳转</span>\n },\n\n <span class=\"hljs-attr\">updateLocation</span>: <span class=\"hljs-function\"><span class=\"hljs-params\">()</span> =></span> {\n <span class=\"hljs-comment\">// 可以不传,用来实现地址栏更新</span>\n },\n\n <span class=\"hljs-attr\">isCurrentUrl</span>: <span class=\"hljs-function\"><span class=\"hljs-params\">()</span> =></span> {\n <span class=\"hljs-comment\">// 可以不传,用来判断是否目标地址当前地址。</span>\n },\n\n <span class=\"hljs-attr\">copy</span>: <span class=\"hljs-function\"><span class=\"hljs-params\">()</span> =></span> {\n <span class=\"hljs-comment\">// 可以不传,用来实现复制到剪切板</span>\n },\n\n <span class=\"hljs-attr\">notify</span>: <span class=\"hljs-function\"><span class=\"hljs-params\">()</span> =></span> {\n <span class=\"hljs-comment\">// 可以不传,用来实现通知</span>\n },\n\n <span class=\"hljs-attr\">alert</span>: <span class=\"hljs-function\"><span class=\"hljs-params\">()</span> =></span> {\n <span class=\"hljs-comment\">// 可以不传,用来实现提示</span>\n },\n\n <span class=\"hljs-attr\">confirm</span>: <span class=\"hljs-function\"><span class=\"hljs-params\">()</span> =></span> {\n <span class=\"hljs-comment\">// 可以不传,用来实现确认框。</span>\n }\n });\n})();\n</code></pre>\n<p>注意:以上的 SDK 地址是一个页面跳转,会跳转到一个 CDN 地址,而且每次跳转都是最新的版本,随着 amis 的升级这个地址会一直变动,如果你的页面已经完成功能回归,请直接使用某个固定地址,这样才不会因为 amis 升级而导致你的页面不可用。</p>\n<p>另外,sdk 代码也伴随 npm 一起发布了,不使用 CDN 版本,直接替换成npm包里面的 <code>amis/sdk/sdk.js</code> 和 <code>amis/sdk/sdk.css</code> 即可。</p>\n<p>示例:</p>\n<pre><code class=\"lang-html\"><span class=\"hljs-meta\"><!DOCTYPE <span class=\"hljs-meta-keyword\">html</span>></span>\n<span class=\"hljs-tag\"><<span class=\"hljs-name\">html</span> <span class=\"hljs-attr\">lang</span>=<span class=\"hljs-string\">\"zh\"</span>></span>\n<span class=\"hljs-tag\"><<span class=\"hljs-name\">head</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">meta</span> <span class=\"hljs-attr\">charset</span>=<span class=\"hljs-string\">\"UTF-8\"</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">title</span>></span>AMIS Demo<span class=\"hljs-tag\"></<span class=\"hljs-name\">title</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">meta</span> <span class=\"hljs-attr\">http-equiv</span>=<span class=\"hljs-string\">\"Content-Type\"</span> <span class=\"hljs-attr\">content</span>=<span class=\"hljs-string\">\"text/html; charset=utf-8\"</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">meta</span> <span class=\"hljs-attr\">name</span>=<span class=\"hljs-string\">\"viewport\"</span>\n <span class=\"hljs-attr\">content</span>=<span class=\"hljs-string\">\"width=device-width, initial-scale=1, maximum-scale=1\"</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">meta</span> <span class=\"hljs-attr\">http-equiv</span>=<span class=\"hljs-string\">\"X-UA-Compatible\"</span> <span class=\"hljs-attr\">content</span>=<span class=\"hljs-string\">\"IE=Edge\"</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">link</span> <span class=\"hljs-attr\">rel</span>=<span class=\"hljs-string\">\"stylesheet\"</span> \n <span class=\"hljs-attr\">href</span>=<span class=\"hljs-string\">\"https://houtai.baidu.com/v2/csssdk\"</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">style</span>></span><span class=\"css\">\n <span class=\"hljs-selector-tag\">html</span>, <span class=\"hljs-selector-tag\">body</span>, <span class=\"hljs-selector-class\">.app-wrapper</span> {\n <span class=\"hljs-attribute\">position</span>: relative;\n <span class=\"hljs-attribute\">width</span>: <span class=\"hljs-number\">100%</span>;\n <span class=\"hljs-attribute\">height</span>: <span class=\"hljs-number\">100%</span>;\n <span class=\"hljs-attribute\">margin</span>: <span class=\"hljs-number\">0</span>;\n <span class=\"hljs-attribute\">padding</span>: <span class=\"hljs-number\">0</span>;\n }\n </span><span class=\"hljs-tag\"></<span class=\"hljs-name\">style</span>></span>\n<span class=\"hljs-tag\"></<span class=\"hljs-name\">head</span>></span>\n<span class=\"hljs-tag\"><<span class=\"hljs-name\">body</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">div</span> <span class=\"hljs-attr\">id</span>=<span class=\"hljs-string\">\"root\"</span> <span class=\"hljs-attr\">class</span>=<span class=\"hljs-string\">\"app-wrapper\"</span>></span><span class=\"hljs-tag\"></<span class=\"hljs-name\">div</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">script</span> <span class=\"hljs-attr\">src</span>=<span class=\"hljs-string\">\"https://houtai.baidu.com/v2/jssdk\"</span>></span><span class=\"hljs-tag\"></<span class=\"hljs-name\">script</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">script</span> <span class=\"hljs-attr\">type</span>=<span class=\"hljs-string\">\"text/javascript\"</span>></span><span class=\"actionscript\">\n (<span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span><span class=\"hljs-params\">()</span> </span>{\n <span class=\"hljs-keyword\">var</span> amis = amisRequire(<span class=\"hljs-string\">'amis/embed'</span>);\n amis.embed(<span class=\"hljs-string\">'#root'</span>, {\n type: <span class=\"hljs-string\">'page'</span>,\n title: <span class=\"hljs-string\">'AMIS Demo'</span>,\n body: <span class=\"hljs-string\">'hello world'</span>\n });\n })();\n </span><span class=\"hljs-tag\"></<span class=\"hljs-name\">script</span>></span>\n<span class=\"hljs-tag\"></<span class=\"hljs-name\">body</span>></span>\n<span class=\"hljs-tag\"></<span class=\"hljs-name\">html</span>></span>\n</code></pre>\n\n\n<div class=\"m-t-lg b-l b-info b-3x wrapper bg-light dk\">文档内容有误?欢迎大家一起来编写,文档地址:<i class=\"fa fa-github\"></i><a href=\"https://github.com/baidu/amis/tree/master/docs/getting_started.md\">/docs/getting_started.md</a>。</div>",
|
||
"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
|
||
},
|
||
{
|
||
"label": "JSSDK",
|
||
"fragment": "jssdk",
|
||
"fullPath": "#jssdk",
|
||
"level": 2
|
||
}
|
||
],
|
||
"level": 0
|
||
}
|
||
};
|
||
|
||
});
|