diff --git a/docs/zh-CN/components/action.md b/docs/zh-CN/components/action.md index 9fa0b9ab5..841b44c0c 100755 --- a/docs/zh-CN/components/action.md +++ b/docs/zh-CN/components/action.md @@ -389,6 +389,49 @@ icon 也可以是 url 地址,比如 | url | `string` | - | 按钮点击后,会打开指定页面。可用 `${xxx}` 取值。 | | blank | `boolean` | `false` | 如果为 `true` 将在新 tab 页面打开。 | +## 发送邮件 + +```schema: scope="body" +{ + "label": "发送邮件", + "type": "button", + "actionType": "email", + "to": "amis@baidu.com", + "cc": "baidu@baidu.com", + "subject": "这是邮件主题", + "body": "这是邮件正文" +} +``` + +### 异步获取数据 + +```schema: scope="body" +{ + "type": "page", + "initApi": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/mail/mailInfo", + "body": { + "label": "发送邮件", + "type": "button", + "actionType": "email", + "to": "${to}", + "cc": "${cc}", + "subject": "${subject}", + "body": "${body}" + } +} +``` + +**属性表** + +| 属性名 | 类型 | 默认值 | 说明 | +| ---------- | -------- | ------- | -------------------------------- | +| actionType | `string` | `email` | 点击后显示一个弹出框 | +| to | `string` | - | 收件人邮箱,可用 ${xxx} 取值。 | +| cc | `string` | - | 抄送邮箱,可用 ${xxx} 取值。 | +| bcc | `string` | - | 匿名抄送邮箱,可用 ${xxx} 取值。 | +| subject | `string` | - | 邮件主题,可用 ${xxx} 取值。 | +| body | `string` | - | 邮件正文,可用 ${xxx} 取值。 | + ## 弹框 ```schema: scope="body" diff --git a/src/RootRenderer.tsx b/src/RootRenderer.tsx index 5e7c7b7a5..3999ab8d5 100644 --- a/src/RootRenderer.tsx +++ b/src/RootRenderer.tsx @@ -8,6 +8,9 @@ import {IRootStore, RootStore} from './store/root'; import {Action} from './types'; import {bulkBindFunctions, guid, isVisible} from './utils/helper'; import {filter} from './utils/tpl'; +import qs from 'qs'; +import pick from 'lodash/pick'; +import mapValues from 'lodash/mapValues'; export interface RootRendererProps extends RootProps { location?: any; @@ -111,6 +114,14 @@ export class RootRenderer extends React.Component { action, ctx ); + } else if (action.actionType === 'email') { + const mailTo = filter(action.to, ctx); + const mailInfo = mapValues(pick(action, 'to', 'cc', 'bcc', 'subject', 'body'), val => filter(val, ctx)); + const mailStr = qs.stringify(mailInfo); + const mailto = `mailto:${mailTo}?${mailStr}`; + + window.open(mailto); + } else if (action.actionType === 'dialog') { store.setCurrentAction(action); store.openDialog(ctx); diff --git a/src/renderers/Action.tsx b/src/renderers/Action.tsx index a13b4d917..5d54b7ca9 100644 --- a/src/renderers/Action.tsx +++ b/src/renderers/Action.tsx @@ -222,6 +222,38 @@ export interface ReloadActionSchema extends ButtonSchema { target?: SchemaReload; } +export interface EmailActionSchema extends ButtonSchema { + /** + * 指定为打开邮箱行为 + */ + actionType: 'email'; + + /** + * 收件人邮箱 + */ + to: string; + + /** + * 抄送邮箱 + */ + cc?: string; + + /** + * 匿名抄送邮箱 + */ + bcc?: string; + + /** + * 邮件主题 + */ + subject?: string; + + /** + * 邮件正文 + */ + body?: string; +} + export interface OtherActionSchema extends ButtonSchema { actionType: | 'prev' @@ -252,6 +284,7 @@ export type ActionSchema = | DrawerActionSchema | CopyActionSchema | ReloadActionSchema + | EmailActionSchema | OtherActionSchema | VanillaAction; @@ -274,6 +307,10 @@ const ActionProps = [ 'blank', 'tooltipPlacement', 'to', + 'cc', + 'bcc', + 'subject', + 'body', 'content', 'required', 'type', @@ -319,6 +356,7 @@ export interface ActionProps Omit, Omit, Omit, + Omit, Omit { actionType: any; onAction?: ( diff --git a/src/types.ts b/src/types.ts index 682f9a291..46e3f8616 100644 --- a/src/types.ts +++ b/src/types.ts @@ -85,6 +85,7 @@ export interface Action extends Button { | 'jump' | 'link' | 'url' + | 'email' | 'close' | 'confirm' | 'add' @@ -106,6 +107,10 @@ export interface Action extends Button { target?: string; link?: string; url?: string; + cc?: string; + bcc?: string; + subject?: string; + body?: string; mergeData?: boolean; reload?: string; messages?: {