- Description:
- Source:
UI工具方法
Methods
(static) dialog(context, type, title, content) → {Promise}
- Description:
- Source:
Example
export function didMount() {
dialog(this, "confirm", "操作确认", "确认删除此项数据?").then(() => {
console.log("点击确认");
}).catch(() => {
console.log("点击取消");
});
// content参数也可以传入jsx
dialog(this, "alert", "警告", <p color={{ color: "red" }}>数据将被清除,此操作不可撤销</p>)
}
Parameters:
| Name |
Type |
Description |
context |
Object
|
this上下文 |
type |
"alert"
|
"confirm"
|
"show"
|
对话框类型,可选'alert', 'confirm', 'show' |
title |
string
|
对话框标题 |
content |
string
|
jsx
|
对话框内容,支持传入jsx |
Returns:
点击确认则Promise被resolve,点击取消被reject
-
Type
-
Promise
(static) hijackSubmit(context)
- Description:
- 劫持提交按钮,会在表单提交按钮上方放置一个遮罩,当点击时会调用宜搭JS中export的名为
beforeBeforeSubmit的方法。方法执行完成后会模拟点击提交按钮进行正式提交。
⚠️慎用,一旦宜搭UI变更此方法可能会失效
- Source:
Example
export function didMount() {
hijackSubmit(this);
}
// 当点击提交时会执行此方法
export function beforeBeforeSubmit() {
console.log("before before submit");
}
Parameters:
| Name |
Type |
Description |
context |
Object
|
this上下文 |
(static) loading(context, title, size, hasMask) → {function}
- Description:
- Source:
Example
export async function onFieldChange({ value }) {
const closeLoading = loading(this, "", "large", true);
// 处理耗时任务
await doSomething(value);
// 任务处理完之后关闭
closeLoading();
}
Parameters:
| Name |
Type |
Default |
Description |
context |
Object
|
|
this上下文 |
title |
string
|
|
提示文本 |
size |
string
|
|
toast尺寸,可选'medium', 'large' |
hasMask |
boolean
|
false
|
是否显示遮罩层,一个遮盖整个页面的半透明黑色背景,可防止用户进行其他操作 |
Returns:
一个函数,调用可关闭加载动画
-
Type
-
function