mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:39:05 +08:00
feat: 事件动作-打开页面优化,新增内容区打开、浏览器当前页打开、浏览器新开页打开 (#9273)
* feat: 打开页面支持页面跳转、浏览器跳转 * 修改时处理 * feat: 打开页面支持页面跳转、浏览器跳转 * feat: 打开页面支持页面跳转、浏览器跳转-删除无用代码 * test: 打开页面-补充文档、测试用例 * test: 打开页面-补充文档、测试用例 * test: 打开页面动作修改字段linkType为targetType * 遗漏文件提交 --------- Co-authored-by: zhaojianhui <zhaojianhui@baidu.com>
This commit is contained in:
parent
fa34337b13
commit
3e08ea7b0e
@ -1034,10 +1034,11 @@ run action ajax
|
||||
|
||||
> `< 1.8.0 及以下版本`,以下属性与 args 同级。
|
||||
|
||||
| 属性名 | 类型 | 默认值 | 说明 |
|
||||
| ------ | -------- | ------ | ----------------------------------------------------------------------------------------------------------------- |
|
||||
| link | `string` | `link` | 用来指定跳转地址,跟 url 不同的是,这是单页跳转方式,不会渲染浏览器,请指定 amis 平台内的页面。可用 `${xxx}` 取值 |
|
||||
| params | `object` | - | 页面参数`{key:value}`,支持数据映射,`> 1.9.0 及以上版本` |
|
||||
| 属性名 | 类型 | 默认值 | 说明 |
|
||||
| ---------- | -------- | ------ | ----------------------------------------------------------------------------------------------------------------------------- |
|
||||
| link | `string` | `link` | 用来指定跳转地址,跟 url 不同的是,这是单页跳转方式,不会渲染浏览器,请指定 amis 平台内的页面。可用 `${xxx}` 取值 |
|
||||
| params | `object` | - | 页面参数`{key:value}`,支持数据映射,`> 1.9.0 及以上版本` |
|
||||
| targetType | `string` | `page` | 默认为内容区打开`page`,可设置为新窗口打开`blank`,当前页签打开`self`,`blank\|self` 方式会重新渲染浏览器`> 6.1.0 及以上版本` |
|
||||
|
||||
### 浏览器回退
|
||||
|
||||
|
@ -38,16 +38,23 @@ export class LinkAction implements RendererAction {
|
||||
throw new Error('env.jumpTo is required!');
|
||||
}
|
||||
|
||||
let apiParams = {
|
||||
...(action.args?.params ?? {}),
|
||||
...(action.data ?? {})
|
||||
};
|
||||
|
||||
if (action?.actionType === 'link' && apiParams?.targetType) {
|
||||
// link动作新增打开方式targetType,buildApi不需要该参数
|
||||
delete apiParams.targetType;
|
||||
}
|
||||
|
||||
// 通过buildApi兼容较复杂的url情况
|
||||
let urlObj = buildApi(
|
||||
{
|
||||
url: (action.args?.url || action.args?.link) as string,
|
||||
method: 'get'
|
||||
},
|
||||
{
|
||||
...(action.args?.params ?? {}),
|
||||
...(action.data ?? {})
|
||||
},
|
||||
apiParams,
|
||||
{
|
||||
autoAppend: true
|
||||
}
|
||||
|
@ -294,6 +294,20 @@ export const defaultOptions: RenderOptions = {
|
||||
action.blank === false ? (window.location.href = to) : window.open(to);
|
||||
return;
|
||||
}
|
||||
// link动作新增了targetType属性,默认是内容区打开(page),在新窗口打开(blank);在当前页签打开(self)
|
||||
if (
|
||||
action?.actionType === 'link' &&
|
||||
['blank', 'self'].includes(action?.targetType)
|
||||
) {
|
||||
if (action.targetType === 'self') {
|
||||
// 当前页签打开,需要刷新页面
|
||||
window.history.pushState(null, '', to);
|
||||
location.reload();
|
||||
} else {
|
||||
window.open(to);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (/^https?:\/\//.test(to)) {
|
||||
window.location.replace(to);
|
||||
} else {
|
||||
|
@ -40,6 +40,33 @@ test('EventAction:url & link', async () => {
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开',
|
||||
level: 'primary',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'link',
|
||||
args: {
|
||||
link: './expression',
|
||||
targetType: 'page',
|
||||
params: {
|
||||
name: 'jack',
|
||||
jon: '${myjon}'
|
||||
}
|
||||
},
|
||||
data: {
|
||||
name: '${myname}',
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -51,6 +78,7 @@ test('EventAction:url & link', async () => {
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('跳转'));
|
||||
fireEvent.click(getByText('打开'));
|
||||
await waitFor(() => {
|
||||
expect(jumpTo).toHaveBeenCalled();
|
||||
});
|
||||
@ -71,4 +99,7 @@ test('EventAction:url & link', async () => {
|
||||
age: 18,
|
||||
name: 'lvxj'
|
||||
});
|
||||
expect(jumpTo.mock.calls[1][0]).toEqual(
|
||||
'./expression?name=lvxj&jon=player&age=18'
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user