小组件
事件

小组件的view支持点击事件,您可以在view的events属性中添加widgetClick事件。

注意: 事件在Preview中不会生效,请在桌面上点击小部件查看效果。

OPEN_URI

支持点击时打开一个链接,您需要在data中传入uri参数,uri可以为网址(https://google.com) 或者某应用内的deeplink(app://deeplink),示例代码如下所示:

$widget.setView({
    type: "column",
    props: {
        align: $align.center,
    },
    views: [
        {
            type: "text",
            props: {
                text: "Open Github Website",
            },
            events: {
                widgetClick: {
                    action: WidgetClickAction.OPEN_URI,
                    data: {
                        uri: "https://github.com"
                    }
                }
            }
        }
    ]
})

REFRESH_WIDGET

支持点击时刷新小部件,示例代码如下所示:

const now = new Date();
const time  = now.toLocaleTimeString();
 
$widget.setView({
    type: "column",
    props: {
        align: $align.center,
    },
    views: [
        {
            type: "text",
            props: {
                text: "Refresh Widget",
            },
            events: {
                widgetClick: {
                    action: WidgetClickAction.REFRESH_WIDGET,
                }
            }
        },
        {
            type: "text",
            props: {
                text: time,
            }
        }
    ]
})