From 63466f47d297da2b71c385a4a6ca91faf70b2ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=A4=9A=E7=9B=8A?= Date: Thu, 1 Jul 2021 00:45:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20nav=20=E7=9A=84=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=20target=20(#2177)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh-CN/components/nav.md | 40 ++++++++++++++++------------ examples/components/Play.jsx | 5 ++++ examples/components/SchemaRender.jsx | 4 +++ examples/embed.tsx | 6 +++++ src/renderers/Nav.tsx | 3 +++ 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/docs/zh-CN/components/nav.md b/docs/zh-CN/components/nav.md index 163fe8924..9086df98f 100755 --- a/docs/zh-CN/components/nav.md +++ b/docs/zh-CN/components/nav.md @@ -31,6 +31,11 @@ order: 58 { "label": "Nav 3", "to": "/docs/renderers" + }, + { + "label": "外部地址", + "to": "http://www.baidu.com/", + "target": "_blank" } ] } @@ -115,20 +120,21 @@ order: 58 ## 属性表 -| 属性名 | 类型 | 默认值 | 说明 | -| ----------------- | ---------------------------------------- | ------- | ---------------------------------------------------------------- | -| type | `string` | `"nav"` | 指定为 Nav 渲染器 | -| className | `string` | | 外层 Dom 的类名 | -| stacked | `boolean` | `true` | 设置成 false 可以以 tabs 的形式展示 | -| source | `string` 或 [API](../../docs/types/api) | | 可以通过变量或 API 接口动态创建导航 | -| deferApi | [API](../../docs/types/api) | | 用来延时加载选项详情的接口,可以不配置,不配置公用 source 接口。 | -| links | `Array` | | 链接集合 | -| links[x].label | `string` | | 名称 | -| links[x].to | [模板](../../docs/concepts/template) | | 链接地址 | -| links[x].icon | `string` | | 图标 | -| links[x].children | `Array` | | 子链接 | -| links[x].unfolded | `boolean` | | 初始是否展开 | -| links[x].active | `boolean` | | 是否高亮 | -| links[x].activeOn | [表达式](../../docs/concepts/expression) | | 是否高亮的条件,留空将自动分析链接地址 | -| links[x].defer | `boolean` | | 标记是否为懒加载项 | -| links[x].deferApi | [API](../../docs/types/api) | | 可以不配置,如果配置优先级更高 | +| 属性名 | 类型 | 默认值 | 说明 | +| ----------------- | ---------------------------------------- | -------- | ---------------------------------------------------------------- | +| type | `string` | `"nav"` | 指定为 Nav 渲染器 | +| className | `string` | | 外层 Dom 的类名 | +| stacked | `boolean` | `true` | 设置成 false 可以以 tabs 的形式展示 | +| source | `string` 或 [API](../../docs/types/api) | | 可以通过变量或 API 接口动态创建导航 | +| deferApi | [API](../../docs/types/api) | | 用来延时加载选项详情的接口,可以不配置,不配置公用 source 接口。 | +| links | `Array` | | 链接集合 | +| links[x].label | `string` | | 名称 | +| links[x].to | [模板](../../docs/concepts/template) | | 链接地址 | +| links[x].target | `string` | 链接关系 | | +| links[x].icon | `string` | | 图标 | +| links[x].children | `Array` | | 子链接 | +| links[x].unfolded | `boolean` | | 初始是否展开 | +| links[x].active | `boolean` | | 是否高亮 | +| links[x].activeOn | [表达式](../../docs/concepts/expression) | | 是否高亮的条件,留空将自动分析链接地址 | +| links[x].defer | `boolean` | | 标记是否为懒加载项 | +| links[x].deferApi | [API](../../docs/types/api) | | 可以不配置,如果配置优先级更高 | diff --git a/examples/components/Play.jsx b/examples/components/Play.jsx index c745d2b7a..763250f1a 100644 --- a/examples/components/Play.jsx +++ b/examples/components/Play.jsx @@ -131,6 +131,11 @@ export default class PlayGround extends React.Component { return; } + if (action && to && action.target) { + window.open(to, action.target); + return; + } + if (/^https?:\/\//.test(to)) { window.location.replace(to); } else { diff --git a/examples/components/SchemaRender.jsx b/examples/components/SchemaRender.jsx index d8f413512..fe5329615 100644 --- a/examples/components/SchemaRender.jsx +++ b/examples/components/SchemaRender.jsx @@ -62,6 +62,10 @@ export default function (schema, showCode, envOverrides) { : window.open(to); return; } + if (action && to && action.target) { + window.open(to, action.target); + return; + } if (/^https?:\/\//.test(to)) { window.location.replace(to); } else { diff --git a/examples/embed.tsx b/examples/embed.tsx index 2fe13b70a..1a60a7b4b 100644 --- a/examples/embed.tsx +++ b/examples/embed.tsx @@ -226,6 +226,12 @@ export function embed( return; } + // 主要是支持 nav 中的跳转 + if (action && to && action.target) { + window.open(to, action.target); + return; + } + if (/^https?:\/\//.test(to)) { window.location.replace(to); } else { diff --git a/src/renderers/Nav.tsx b/src/renderers/Nav.tsx index 8cf6d2317..0a1b8b49c 100644 --- a/src/renderers/Nav.tsx +++ b/src/renderers/Nav.tsx @@ -36,6 +36,8 @@ export type NavItemSchema = { to?: SchemaUrlPath; + target?: string; + unfolded?: boolean; active?: boolean; @@ -85,6 +87,7 @@ export interface Link { className?: string; label?: string; to?: string; + target?: string; icon?: string; active?: boolean; activeOn?: string;