mirror of
https://github.com/wahyd4/ant-design.git
synced 2026-08-27 13:46:18 +10:00
1044 lines
34 KiB
HTML
1044 lines
34 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|
<meta name="format-detection" content="telephone=no">
|
|
<meta name="description" content="一个设计&前端框架"/>
|
|
<title>
|
|
Modal 对话框 - Ant Design
|
|
</title>
|
|
<link rel="icon" href="https://t.alipayobjects.com/images/T1QUBfXo4fXXXXXXXX.png" type="image/x-icon">
|
|
<link rel="shortcut icon" href="https://t.alipayobjects.com/images/T1QUBfXo4fXXXXXXXX.png" type="image/x-icon">
|
|
|
|
<link rel="stylesheet" href="/dist/antd-0.7.1.css">
|
|
<link rel="stylesheet" href="/static/style.css">
|
|
<link rel="stylesheet" href="/static/tomorrow.css">
|
|
<script>
|
|
(function (con) {
|
|
'use strict';
|
|
var prop, method;
|
|
var empty = {};
|
|
var dummy = function () {
|
|
};
|
|
var properties = 'memory'.split(',');
|
|
var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' +
|
|
'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' +
|
|
'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',');
|
|
while (prop = properties.pop()) {
|
|
con[prop] = con[prop] || empty;
|
|
}
|
|
while (method = methods.pop()) {
|
|
con[method] = con[method] || dummy;
|
|
}
|
|
})(this.console = this.console || {});
|
|
</script>
|
|
<script src="https://a.alipayobjects.com/??bluebird/2.9.30/bluebird.js,jquery/jquery/1.11.1/jquery.js,es5-shim/4.0.5/es5-shim-debug.js,es5-shim/4.0.5/es5-sham-debug.js,html5shiv/3.7.2/src/html5shiv.js,react/0.13.3/react.js,react-router/0.13.3/ReactRouter.js"></script>
|
|
<script>
|
|
var ANT_COMPONENTS = [];
|
|
ANT_COMPONENTS.push({
|
|
title: 'Layout',
|
|
desc: '布局'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Checkbox',
|
|
desc: '多选框'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Iconfont',
|
|
desc: '字体图标'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Button',
|
|
desc: '按钮'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Radio',
|
|
desc: '单选框'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Form',
|
|
desc: '表单'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Switch',
|
|
desc: '开关'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'InputNumber',
|
|
desc: '数字输入框'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Motion',
|
|
desc: '组件动画'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Slider',
|
|
desc: '滑动输入条'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Datepicker',
|
|
desc: '日期选择框'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Select',
|
|
desc: '选择器'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Tabs',
|
|
desc: '标签页'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Steps',
|
|
desc: '步骤条'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Breadcrumb',
|
|
desc: '面包屑'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Collapse',
|
|
desc: '折叠面板'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Alert',
|
|
desc: '通知栏'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Notification',
|
|
desc: '系统通知框'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Pagination',
|
|
desc: '分页'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Tree',
|
|
desc: '树形控件'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Carousel',
|
|
desc: '走马灯'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Menu',
|
|
desc: '导航菜单'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Tag',
|
|
desc: '标签'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Affix',
|
|
desc: '固定'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Upload',
|
|
desc: '文件上传'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Modal',
|
|
desc: '对话框'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Message',
|
|
desc: '全局提示'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Dropdown',
|
|
desc: '下拉菜单'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Popover',
|
|
desc: '气泡卡片'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Popconfirm',
|
|
desc: '气泡确认框'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Tooltip',
|
|
desc: '文字提示'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Progress',
|
|
desc: '进度条'
|
|
});
|
|
ANT_COMPONENTS.push({
|
|
title: 'Table',
|
|
desc: '表格'
|
|
});
|
|
</script>
|
|
<script src="/static/script.js"></script>
|
|
<script>
|
|
window.antdVersion = {
|
|
latest: '0.7.1',
|
|
stable: '0.7.0'
|
|
};
|
|
</script>
|
|
<script src="/dist/antd-0.7.1.js"></script>
|
|
<script src="/dist/demo.js"></script>
|
|
<script>
|
|
window.require = function (path) {
|
|
var result = window;
|
|
var namespaces = path.split('/');
|
|
namespaces.forEach(function (key, i) {
|
|
if (i !== 0 && i === namespaces.length - 1) {
|
|
key = capitalizeFirstLetter(key);
|
|
}
|
|
if (key !== 'lib') {
|
|
if (result[key]) {
|
|
result = result[key];
|
|
} else {
|
|
throw 'There should not have modules here 2.';
|
|
}
|
|
}
|
|
});
|
|
function capitalizeFirstLetter(string) {
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
}
|
|
|
|
return result;
|
|
};
|
|
</script>
|
|
|
|
</head>
|
|
<body >
|
|
<header id="header">
|
|
<a class="logo" href="/">
|
|
<img width="60" src="https://t.alipayobjects.com/images/rmsweb/T1B9hfXcdvXXXXXXXX.svg">
|
|
Ant Design
|
|
</a>
|
|
<div class="search">
|
|
<div id="autoComplete"></div>
|
|
</div>
|
|
<nav class="nav">
|
|
<span class="bar"></span>
|
|
<ul>
|
|
<li class="">
|
|
<a href="/">首页</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="/docs/introduce">使用</a>
|
|
</li>
|
|
<li class="">
|
|
<a class="disabled" href="/design/">设计</a>
|
|
</li>
|
|
<li class="current">
|
|
<a href="/components">组件</a>
|
|
</li>
|
|
<li>
|
|
<a target="_blank" href="https://github.com/ant-design/ant-design">Github</a>
|
|
</li>
|
|
</ul>
|
|
</nav>
|
|
</header>
|
|
<div class="main-wrapper">
|
|
|
|
<aside class="aside-container">
|
|
<ul>
|
|
<li>
|
|
<h4>CSS</h4>
|
|
<ul class="">
|
|
<li class="">
|
|
<a href="../layout/">
|
|
Layout
|
|
<span class="chinese">布局</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../iconfont/">
|
|
Iconfont
|
|
<span class="chinese">字体图标</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../button/">
|
|
Button
|
|
<span class="chinese">按钮</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../form/">
|
|
Form
|
|
<span class="chinese">表单</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../motion/">
|
|
Motion
|
|
<span class="chinese">组件动画</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../alert/">
|
|
Alert
|
|
<span class="chinese">通知栏</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<h4>Components</h4>
|
|
<ul class="aside-list-show">
|
|
<li class="">
|
|
<a href="../checkbox/">
|
|
Checkbox
|
|
<span class="chinese">多选框</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../radio/">
|
|
Radio
|
|
<span class="chinese">单选框</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../switch/">
|
|
Switch
|
|
<span class="chinese">开关</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../slider/">
|
|
Slider
|
|
<span class="chinese">滑动输入条</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../input-number/">
|
|
InputNumber
|
|
<span class="chinese">数字输入框</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../select/">
|
|
Select
|
|
<span class="chinese">选择器</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../datepicker/">
|
|
Datepicker
|
|
<span class="chinese">日期选择框</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../tabs/">
|
|
Tabs
|
|
<span class="chinese">标签页</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../steps/">
|
|
Steps
|
|
<span class="chinese">步骤条</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../breadcrumb/">
|
|
Breadcrumb
|
|
<span class="chinese">面包屑</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../collapse/">
|
|
Collapse
|
|
<span class="chinese">折叠面板</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../affix/">
|
|
Affix
|
|
<span class="chinese">固定</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../pagination/">
|
|
Pagination
|
|
<span class="chinese">分页</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../tree/">
|
|
Tree
|
|
<span class="chinese">树形控件</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../carousel/">
|
|
Carousel
|
|
<span class="chinese">走马灯</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../menu/">
|
|
Menu
|
|
<span class="chinese">导航菜单</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../tag/">
|
|
Tag
|
|
<span class="chinese">标签</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../upload/">
|
|
Upload
|
|
<span class="chinese">文件上传</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../notification/">
|
|
Notification
|
|
<span class="chinese">系统通知框</span>
|
|
</a>
|
|
</li>
|
|
<li class="current">
|
|
<a href="./">
|
|
Modal
|
|
<span class="chinese">对话框</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../message/">
|
|
Message
|
|
<span class="chinese">全局提示</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../dropdown/">
|
|
Dropdown
|
|
<span class="chinese">下拉菜单</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../popover/">
|
|
Popover
|
|
<span class="chinese">气泡卡片</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../popconfirm/">
|
|
Popconfirm
|
|
<span class="chinese">气泡确认框</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../tooltip/">
|
|
Tooltip
|
|
<span class="chinese">文字提示</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../progress/">
|
|
Progress
|
|
<span class="chinese">进度条</span>
|
|
</a>
|
|
</li>
|
|
<li class="">
|
|
<a href="../table/">
|
|
Table
|
|
<span class="chinese">表格</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</aside>
|
|
|
|
<section class="main-container">
|
|
<article class="markdown">
|
|
<h1>
|
|
Modal 对话框
|
|
</h1>
|
|
<p>模态对话框。</p>
|
|
<h2 id="何时使用">何时使用</h2><p>需要用户处理事务,又不希望跳转页面以致打断工作流程时,可以使用 <code>Modal</code> 在当前页面正中打开一个浮层,承载相应的操作。</p>
|
|
<p>另外当需要一个简洁的确认框询问用户时,可以使用精心封装好的 <code>ant.confirm()</code> 。</p>
|
|
<h2 id="api">API</h2><table>
|
|
<thead>
|
|
<tr>
|
|
<th>参数</th>
|
|
<th>说明</th>
|
|
<th>类型</th>
|
|
<th>默认值</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>title</td>
|
|
<td>标题</td>
|
|
<td>React.Element</td>
|
|
<td>无</td>
|
|
</tr>
|
|
<tr>
|
|
<td>onOk</td>
|
|
<td>点击确定回调</td>
|
|
<td>function</td>
|
|
<td>无</td>
|
|
</tr>
|
|
<tr>
|
|
<td>onCancel</td>
|
|
<td>点击遮罩层或右上角叉或取消按钮的回调</td>
|
|
<td>function</td>
|
|
<td>无</td>
|
|
</tr>
|
|
<tr>
|
|
<td>width</td>
|
|
<td>宽度</td>
|
|
<td>String or Number</td>
|
|
<td>500</td>
|
|
</tr>
|
|
<tr>
|
|
<td>footer</td>
|
|
<td>底部内容</td>
|
|
<td>React.Element</td>
|
|
<td>确定取消按钮</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h3 id="confirm">confirm()</h3><p><code>confirm</code> 为一个方法,参数为 object,具体属性如下:</p>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>参数</th>
|
|
<th>说明</th>
|
|
<th>类型</th>
|
|
<th>默认值</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>title</td>
|
|
<td>标题</td>
|
|
<td>React.Element or String</td>
|
|
<td>无</td>
|
|
</tr>
|
|
<tr>
|
|
<td>onOk</td>
|
|
<td>点击确定回调,参数为关闭函数,返回 promise 时 resolve 后自动关闭</td>
|
|
<td>function</td>
|
|
<td>无</td>
|
|
</tr>
|
|
<tr>
|
|
<td>onCancel</td>
|
|
<td>取消回调,参数为关闭函数,返回 promise 时 resolve 后自动关闭</td>
|
|
<td>function</td>
|
|
<td>无</td>
|
|
</tr>
|
|
<tr>
|
|
<td>width</td>
|
|
<td>宽度</td>
|
|
<td>String or Number</td>
|
|
<td>375</td>
|
|
</tr>
|
|
<tr>
|
|
<td>iconClassName</td>
|
|
<td>图标样式名</td>
|
|
<td>String</td>
|
|
<td>anticon-exclamation-circle</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
</article><h2 class="component-demos">
|
|
组件演示
|
|
<i class="iconfont-home icon-all" title="展开全部代码"></i>
|
|
</h2>
|
|
<div class="code-boxes clearfix">
|
|
<div class="code-boxes-col-2-1"><div class="code-box">
|
|
<div class="code-box-demo">
|
|
<div id="components-modal-demo-basic"></div>
|
|
<script>(function(){'use strict';
|
|
|
|
var Modal = antd.Modal;
|
|
|
|
var Test = React.createClass({
|
|
displayName: 'Test',
|
|
|
|
getInitialState: function getInitialState() {
|
|
return {
|
|
visible: false
|
|
};
|
|
},
|
|
showModal: function showModal() {
|
|
this.setState({
|
|
visible: true
|
|
});
|
|
},
|
|
handleOk: function handleOk() {
|
|
console.log('点击了确定');
|
|
this.setState({
|
|
visible: false
|
|
});
|
|
},
|
|
handleCancel: function handleCancel() {
|
|
console.log('点击了取消');
|
|
this.setState({
|
|
visible: false
|
|
});
|
|
},
|
|
render: function render() {
|
|
return React.createElement(
|
|
'div',
|
|
null,
|
|
React.createElement(
|
|
'button',
|
|
{ className: "ant-btn ant-btn-primary", onClick: this.showModal },
|
|
'显示对话框'
|
|
),
|
|
React.createElement(
|
|
Modal,
|
|
{ title: "第一个 Modal",
|
|
visible: this.state.visible,
|
|
onOk: this.handleOk,
|
|
onCancel: this.handleCancel },
|
|
React.createElement(
|
|
'p',
|
|
null,
|
|
'对话框的内容'
|
|
),
|
|
React.createElement(
|
|
'p',
|
|
null,
|
|
'对话框的内容'
|
|
),
|
|
React.createElement(
|
|
'p',
|
|
null,
|
|
'对话框的内容'
|
|
)
|
|
)
|
|
);
|
|
}
|
|
});
|
|
|
|
React.render(React.createElement(Test, null), document.getElementById('components-modal-demo-basic'));})()</script><div class="highlight"><pre><code class="javascript"><span class="keyword">var</span> Modal = antd.Modal;
|
|
|
|
<span class="keyword">var</span> Test = React.createClass({
|
|
getInitialState(){
|
|
<span class="keyword">return</span>{
|
|
visible: <span class="literal">false</span>
|
|
}
|
|
},
|
|
showModal() {
|
|
<span class="keyword">this</span>.setState({
|
|
visible: <span class="literal">true</span>
|
|
});
|
|
},
|
|
handleOk() {
|
|
console.log(<span class="string">'点击了确定'</span>);
|
|
<span class="keyword">this</span>.setState({
|
|
visible: <span class="literal">false</span>
|
|
});
|
|
},
|
|
handleCancel() {
|
|
console.log(<span class="string">'点击了取消'</span>);
|
|
<span class="keyword">this</span>.setState({
|
|
visible: <span class="literal">false</span>
|
|
});
|
|
},
|
|
render() {
|
|
<span class="keyword">return</span> <span class="xml"><span class="tag"><<span class="title">div</span>></span>
|
|
<span class="tag"><<span class="title">button</span> <span class="attribute">className</span>=<span class="value">"ant-btn ant-btn-primary"</span> <span class="attribute">onClick</span>=<span class="value">{this.showModal}</span>></span>显示对话框<span class="tag"></<span class="title">button</span>></span>
|
|
<span class="tag"><<span class="title">Modal</span> <span class="attribute">title</span>=<span class="value">"第一个 Modal"</span>
|
|
<span class="attribute">visible</span>=<span class="value">{this.state.visible}</span>
|
|
<span class="attribute">onOk</span>=<span class="value">{this.handleOk}</span>
|
|
<span class="attribute">onCancel</span>=<span class="value">{this.handleCancel}</span>></span>
|
|
<span class="tag"><<span class="title">p</span>></span>对话框的内容<span class="tag"></<span class="title">p</span>></span>
|
|
<span class="tag"><<span class="title">p</span>></span>对话框的内容<span class="tag"></<span class="title">p</span>></span>
|
|
<span class="tag"><<span class="title">p</span>></span>对话框的内容<span class="tag"></<span class="title">p</span>></span>
|
|
<span class="tag"></<span class="title">Modal</span>></span>
|
|
<span class="tag"></<span class="title">div</span>></span>;</span>
|
|
}
|
|
});
|
|
|
|
React.render(<span class="xml"><span class="tag"><<span class="title">Test</span>/></span> , document.getElementById('components-modal-demo-basic'));</span></code></pre></div>
|
|
</div>
|
|
<div class="code-box-meta markdown">
|
|
<div class="code-box-title">基本</div>
|
|
<p>第一个对话框。</p>
|
|
<span class="collapse anticon anticon-circle-o-right"></span>
|
|
</div>
|
|
</div><div class="code-box">
|
|
<div class="code-box-demo">
|
|
<div id="components-modal-demo-footer"></div>
|
|
<script>(function(){"use strict";
|
|
|
|
var Modal = antd.Modal;
|
|
|
|
var Test = React.createClass({
|
|
displayName: "Test",
|
|
|
|
getInitialState: function getInitialState() {
|
|
return {
|
|
loading: false,
|
|
visible: false
|
|
};
|
|
},
|
|
showModal: function showModal() {
|
|
this.setState({ visible: true });
|
|
},
|
|
handleOk: function handleOk() {
|
|
var _this = this;
|
|
|
|
this.setState({ loading: true });
|
|
setTimeout(function () {
|
|
_this.setState({ loading: false, visible: false });
|
|
}, 3000);
|
|
},
|
|
handleCancel: function handleCancel() {
|
|
this.setState({ visible: false });
|
|
},
|
|
render: function render() {
|
|
return React.createElement(
|
|
"div",
|
|
null,
|
|
React.createElement(
|
|
"button",
|
|
{ className: "ant-btn ant-btn-primary", onClick: this.showModal },
|
|
"显示对话框"
|
|
),
|
|
React.createElement(
|
|
Modal,
|
|
{ ref: "modal",
|
|
visible: this.state.visible,
|
|
title: "对话框标题", onOk: this.handleOk, onCancel: this.handleCancel,
|
|
footer: [React.createElement(
|
|
"button",
|
|
{ key: "back", className: "ant-btn", onClick: this.handleCancel },
|
|
"返 回"
|
|
), React.createElement(
|
|
"button",
|
|
{ key: "submit", className: "ant-btn ant-btn-primary", onClick: this.handleOk },
|
|
"提 交",
|
|
React.createElement("i", { className: 'anticon anticon-loading' + (this.state.loading ? '' : 'hide') })
|
|
)] },
|
|
React.createElement(
|
|
"p",
|
|
null,
|
|
"对话框的内容"
|
|
),
|
|
React.createElement(
|
|
"p",
|
|
null,
|
|
"对话框的内容"
|
|
),
|
|
React.createElement(
|
|
"p",
|
|
null,
|
|
"对话框的内容"
|
|
),
|
|
React.createElement(
|
|
"p",
|
|
null,
|
|
"对话框的内容"
|
|
),
|
|
React.createElement(
|
|
"p",
|
|
null,
|
|
"对话框的内容"
|
|
)
|
|
)
|
|
);
|
|
}
|
|
});
|
|
|
|
React.render(React.createElement(Test, null), document.getElementById('components-modal-demo-footer'));})()</script><div class="highlight"><pre><code class="javascript"><span class="keyword">var</span> Modal = antd.Modal;
|
|
|
|
<span class="keyword">var</span> Test = React.createClass({
|
|
getInitialState: <span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
|
<span class="keyword">return</span> {
|
|
loading: <span class="literal">false</span>,
|
|
visible: <span class="literal">false</span>
|
|
};
|
|
},
|
|
showModal() {
|
|
<span class="keyword">this</span>.setState({ visible: <span class="literal">true</span> });
|
|
},
|
|
handleOk() {
|
|
<span class="keyword">this</span>.setState({ loading: <span class="literal">true</span> });
|
|
setTimeout(()=> {
|
|
<span class="keyword">this</span>.setState({ loading: <span class="literal">false</span>, visible: <span class="literal">false</span> });
|
|
}, <span class="number">3000</span>);
|
|
},
|
|
handleCancel() {
|
|
<span class="keyword">this</span>.setState({ visible: <span class="literal">false</span> });
|
|
},
|
|
render() {
|
|
<span class="keyword">return</span> <span class="xml"><span class="tag"><<span class="title">div</span>></span>
|
|
<span class="tag"><<span class="title">button</span> <span class="attribute">className</span>=<span class="value">"ant-btn ant-btn-primary"</span> <span class="attribute">onClick</span>=<span class="value">{this.showModal}</span>></span>
|
|
显示对话框
|
|
<span class="tag"></<span class="title">button</span>></span>
|
|
<span class="tag"><<span class="title">Modal</span> <span class="attribute">ref</span>=<span class="value">"modal"</span>
|
|
<span class="attribute">visible</span>=<span class="value">{this.state.visible}</span>
|
|
<span class="attribute">title</span>=<span class="value">"对话框标题"</span> <span class="attribute">onOk</span>=<span class="value">{this.handleOk}</span> <span class="attribute">onCancel</span>=<span class="value">{this.handleCancel}</span>
|
|
<span class="attribute">footer</span>=<span class="value">{[</span>
|
|
<<span class="attribute">button</span> <span class="attribute">key</span>=<span class="value">"back"</span> <span class="attribute">className</span>=<span class="value">"ant-btn"</span> <span class="attribute">onClick</span>=<span class="value">{this.handleCancel}</span>></span>返 回<span class="tag"></<span class="title">button</span>></span>,
|
|
<span class="tag"><<span class="title">button</span> <span class="attribute">key</span>=<span class="value">"submit"</span> <span class="attribute">className</span>=<span class="value">"ant-btn ant-btn-primary"</span> <span class="attribute">onClick</span>=<span class="value">{this.handleOk}</span>></span>
|
|
提 交
|
|
<span class="tag"><<span class="title">i</span> <span class="attribute">className</span>=<span class="value">{'anticon</span> <span class="attribute">anticon-loading</span>'+(<span class="attribute">this.state.loading</span>?''<span class="attribute">:</span>'<span class="attribute">hide</span>')}></span><span class="tag"></<span class="title">i</span>></span>
|
|
<span class="tag"></<span class="title">button</span>></span>
|
|
]}>
|
|
<span class="tag"><<span class="title">p</span>></span>对话框的内容<span class="tag"></<span class="title">p</span>></span>
|
|
<span class="tag"><<span class="title">p</span>></span>对话框的内容<span class="tag"></<span class="title">p</span>></span>
|
|
<span class="tag"><<span class="title">p</span>></span>对话框的内容<span class="tag"></<span class="title">p</span>></span>
|
|
<span class="tag"><<span class="title">p</span>></span>对话框的内容<span class="tag"></<span class="title">p</span>></span>
|
|
<span class="tag"><<span class="title">p</span>></span>对话框的内容<span class="tag"></<span class="title">p</span>></span>
|
|
<span class="tag"></<span class="title">Modal</span>></span>
|
|
<span class="tag"></<span class="title">div</span>></span>;</span>
|
|
}
|
|
});
|
|
|
|
React.render(<span class="xml"><span class="tag"><<span class="title">Test</span>/></span> , document.getElementById('components-modal-demo-footer'));</span></code></pre></div>
|
|
</div>
|
|
<div class="code-box-meta markdown">
|
|
<div class="code-box-title">自定义页脚</div>
|
|
<p>更复杂的例子,自定义了页脚的按钮,点击提交后进入 loading 状态,完成后关闭。</p>
|
|
<span class="collapse anticon anticon-circle-o-right"></span>
|
|
</div>
|
|
</div><div class="code-box">
|
|
<div class="code-box-demo">
|
|
<div id="components-modal-demo-confirm-promise"></div>
|
|
<script>(function(){'use strict';
|
|
|
|
var confirm = antd.confirm;
|
|
|
|
function showConfirm() {
|
|
confirm({
|
|
title: '您是否确认要删除这项内容',
|
|
content: '一些解释',
|
|
onOk: function onOk() {
|
|
alert('1 秒后关闭');
|
|
return new Promise(function (resolve) {
|
|
setTimeout(resolve, 1000);
|
|
});
|
|
},
|
|
onCancel: function onCancel() {}
|
|
});
|
|
}
|
|
|
|
React.render(React.createElement(
|
|
'button',
|
|
{ className: "ant-btn", onClick: showConfirm },
|
|
'确认对话框'
|
|
), document.getElementById('components-modal-demo-confirm-promise'));})()</script><div class="highlight"><pre><code class="javascript"><span class="keyword">var</span> confirm = antd.confirm;
|
|
|
|
<span class="function"><span class="keyword">function</span> <span class="title">showConfirm</span><span class="params">()</span>{</span>
|
|
confirm({
|
|
title: <span class="string">'您是否确认要删除这项内容'</span>,
|
|
content: <span class="string">'一些解释'</span>,
|
|
onOk: <span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
|
alert(<span class="string">'1 秒后关闭'</span>);
|
|
<span class="keyword">return</span> <span class="keyword">new</span> Promise(<span class="function"><span class="keyword">function</span><span class="params">(resolve)</span>{</span>
|
|
setTimeout(resolve,<span class="number">1000</span>);
|
|
});
|
|
},
|
|
onCancel: <span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>}
|
|
});
|
|
}
|
|
|
|
React.render(
|
|
<span class="xml"><span class="tag"><<span class="title">button</span> <span class="attribute">className</span>=<span class="value">"ant-btn"</span> <span class="attribute">onClick</span>=<span class="value">{showConfirm}</span>></span>
|
|
确认对话框
|
|
<span class="tag"></<span class="title">button</span>></span>, document.getElementById('components-modal-demo-confirm-promise'));</span></code></pre></div>
|
|
</div>
|
|
<div class="code-box-meta markdown">
|
|
<div class="code-box-title">确认对话框</div>
|
|
<p>使用 <code>confirm()</code> 可以快捷地弹出确认框。onCancel/onOk 返回 promise 可以延迟关闭</p>
|
|
<span class="collapse anticon anticon-circle-o-right"></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="code-boxes-col-2-1"><div class="code-box">
|
|
<div class="code-box-demo">
|
|
<div id="components-modal-demo-custom"></div>
|
|
<script>(function(){'use strict';
|
|
|
|
var Modal = antd.Modal;
|
|
var ModalText = '对话框的内容';
|
|
|
|
var Test = React.createClass({
|
|
displayName: 'Test',
|
|
|
|
getInitialState: function getInitialState() {
|
|
return {
|
|
ModalText: '对话框的内容',
|
|
visible: false
|
|
};
|
|
},
|
|
showModal: function showModal() {
|
|
this.setState({
|
|
visible: true
|
|
});
|
|
},
|
|
handleOk: function handleOk() {
|
|
this.setState({
|
|
ModalText: '对话框将在两秒后关闭'
|
|
});
|
|
setTimeout((function () {
|
|
this.setState({
|
|
visible: false
|
|
});
|
|
}).bind(this), 2000);
|
|
},
|
|
handleCancel: function handleCancel() {
|
|
console.log('点击了取消');
|
|
this.setState({
|
|
visible: false
|
|
});
|
|
},
|
|
render: function render() {
|
|
return React.createElement(
|
|
'div',
|
|
null,
|
|
React.createElement(
|
|
'button',
|
|
{ className: "ant-btn ant-btn-primary", onClick: this.showModal },
|
|
'显示对话框'
|
|
),
|
|
React.createElement(
|
|
Modal,
|
|
{ ref: "modal",
|
|
title: "对话框标题",
|
|
visible: this.state.visible,
|
|
onOk: this.handleOk,
|
|
onCancel: this.handleCancel },
|
|
React.createElement(
|
|
'p',
|
|
null,
|
|
this.state.ModalText
|
|
)
|
|
)
|
|
);
|
|
}
|
|
});
|
|
|
|
React.render(React.createElement(Test, null), document.getElementById('components-modal-demo-custom'));})()</script><div class="highlight"><pre><code class="javascript"><span class="keyword">var</span> Modal = antd.Modal;
|
|
<span class="keyword">var</span> ModalText = <span class="string">'对话框的内容'</span>;
|
|
|
|
<span class="keyword">var</span> Test = React.createClass({
|
|
getInitialState() {
|
|
<span class="keyword">return</span> {
|
|
ModalText: <span class="string">'对话框的内容'</span>,
|
|
visible: <span class="literal">false</span>
|
|
};
|
|
},
|
|
showModal() {
|
|
<span class="keyword">this</span>.setState({
|
|
visible: <span class="literal">true</span>
|
|
});
|
|
},
|
|
handleOk() {
|
|
<span class="keyword">this</span>.setState({
|
|
ModalText: <span class="string">'对话框将在两秒后关闭'</span>
|
|
});
|
|
setTimeout((<span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
|
<span class="keyword">this</span>.setState({
|
|
visible: <span class="literal">false</span>
|
|
});
|
|
}).bind(<span class="keyword">this</span>), <span class="number">2000</span>);
|
|
},
|
|
handleCancel() {
|
|
console.log(<span class="string">'点击了取消'</span>);
|
|
<span class="keyword">this</span>.setState({
|
|
visible: <span class="literal">false</span>
|
|
});
|
|
},
|
|
render() {
|
|
<span class="keyword">return</span> <span class="xml"><span class="tag"><<span class="title">div</span>></span>
|
|
<span class="tag"><<span class="title">button</span> <span class="attribute">className</span>=<span class="value">"ant-btn ant-btn-primary"</span> <span class="attribute">onClick</span>=<span class="value">{this.showModal}</span>></span>显示对话框<span class="tag"></<span class="title">button</span>></span>
|
|
<span class="tag"><<span class="title">Modal</span> <span class="attribute">ref</span>=<span class="value">"modal"</span>
|
|
<span class="attribute">title</span>=<span class="value">"对话框标题"</span>
|
|
<span class="attribute">visible</span>=<span class="value">{this.state.visible}</span>
|
|
<span class="attribute">onOk</span>=<span class="value">{this.handleOk}</span>
|
|
<span class="attribute">onCancel</span>=<span class="value">{this.handleCancel}</span>></span>
|
|
<span class="tag"><<span class="title">p</span>></span>{this.state.ModalText}<span class="tag"></<span class="title">p</span>></span>
|
|
<span class="tag"></<span class="title">Modal</span>></span>
|
|
<span class="tag"></<span class="title">div</span>></span>;</span>
|
|
}
|
|
});
|
|
|
|
React.render(<span class="xml"><span class="tag"><<span class="title">Test</span>/></span> , document.getElementById('components-modal-demo-custom'));</span></code></pre></div>
|
|
</div>
|
|
<div class="code-box-meta markdown">
|
|
<div class="code-box-title">异步关闭</div>
|
|
<p>点击确定后异步关闭对话框。</p>
|
|
<span class="collapse anticon anticon-circle-o-right"></span>
|
|
</div>
|
|
</div><div class="code-box">
|
|
<div class="code-box-demo">
|
|
<div id="components-modal-demo-confirm"></div>
|
|
<script>(function(){'use strict';
|
|
|
|
var confirm = antd.confirm;
|
|
|
|
function showConfirm() {
|
|
confirm({
|
|
title: '您是否确认要删除这项内容',
|
|
content: '一些解释',
|
|
onOk: function onOk() {
|
|
alert('确定');
|
|
},
|
|
onCancel: function onCancel() {}
|
|
});
|
|
}
|
|
|
|
React.render(React.createElement(
|
|
'button',
|
|
{ className: "ant-btn", onClick: showConfirm },
|
|
'确认对话框'
|
|
), document.getElementById('components-modal-demo-confirm'));})()</script><div class="highlight"><pre><code class="javascript"><span class="keyword">var</span> confirm = antd.confirm;
|
|
|
|
<span class="function"><span class="keyword">function</span> <span class="title">showConfirm</span><span class="params">()</span>{</span>
|
|
confirm({
|
|
title: <span class="string">'您是否确认要删除这项内容'</span>,
|
|
content: <span class="string">'一些解释'</span>,
|
|
onOk: <span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>
|
|
alert(<span class="string">'确定'</span>);
|
|
},
|
|
onCancel: <span class="function"><span class="keyword">function</span><span class="params">()</span> {</span>}
|
|
});
|
|
}
|
|
|
|
React.render(
|
|
<span class="xml"><span class="tag"><<span class="title">button</span> <span class="attribute">className</span>=<span class="value">"ant-btn"</span> <span class="attribute">onClick</span>=<span class="value">{showConfirm}</span>></span>
|
|
确认对话框
|
|
<span class="tag"></<span class="title">button</span>></span>, document.getElementById('components-modal-demo-confirm'));</span></code></pre></div>
|
|
</div>
|
|
<div class="code-box-meta markdown">
|
|
<div class="code-box-title">确认对话框</div>
|
|
<p>使用 <code>confirm()</code> 可以快捷地弹出确认框。</p>
|
|
<span class="collapse anticon anticon-circle-o-right"></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
</div><footer id="footer">
|
|
<ul>
|
|
<li>
|
|
<h2>GitHub</h2>
|
|
<a target="_blank "href="https://github.com/ant-design/ant-design">仓库</a>
|
|
<a target="_blank" href="https://github.com/ant-design/ant-design/tree/master/style">样式</a>
|
|
<a target="_blank" href="https://github.com/ant-design/antd-bin">开发工具</a>
|
|
</li>
|
|
<li>
|
|
<h2>关于我们</h2>
|
|
<a href="http://www.atatech.org/teams/79">博客 - Ant UED</a>
|
|
</li>
|
|
<li>
|
|
<h2>联系我们</h2>
|
|
<a target="_blank" href="https://github.com/ant-design/ant-design/issues">问题与建议 - Issues</a>
|
|
</li>
|
|
<li>
|
|
<h3>©2015 蚂蚁金服体验技术部出品</h3>
|
|
</li>
|
|
</ul>
|
|
</footer>
|
|
</body>
|
|
</html> |