Raycast 中文文档
  • 介绍
  • 链接
    • 官网
    • 官网 API 文档
    • 社区
    • GitHub
    • Store
    • Icon 生成器
    • 扩展图标模板
  • 基础
    • 起步
    • 创建您的第一个扩展
    • 贡献一个扩展
    • 过审一个扩展
    • 发布一个扩展
    • 调试一个扩展
    • 安装一个扩展
  • 团队
    • 开始
    • 发布私人扩展
    • 协作开发私有扩展
  • 例子
    • Doppler 共享 Secrets
    • Hacker News
    • Todo 列表
    • Spotify Controls
  • 资料
    • 最佳实践
    • 工具
      • CLI
      • ESLint
      • VS Code(社区工具)
    • 文件结构
    • 生命周期
      • 参数
      • 后台刷新
      • Deeplinks
    • Manifest
    • 安全性
    • 术语
    • 版本控制
  • API 参考
    • AI
    • Cache
    • Command
    • Clipboard
    • Environment
    • Feedback
      • Alert
      • HUD
      • Toast
    • Keyboard
    • Menu Bar Commands
    • OAuth
    • Preferences
    • Storage
    • System Utilities
    • 用户界面
      • Action Panel
      • Actions
      • Detail
      • Form
      • List
      • Grid
      • Colors
      • Icons & Images
      • Navigation
    • 窗口 & 搜索栏
  • 公共包
    • 起步
    • 功能
      • 执行 AppleScript
    • 图标
      • getAvatarIcon
      • getFavicon
      • getProgressIcon
    • React hooks
      • useCachedState
      • usePromise
      • useCachedPromise
      • useFetch
      • useForm
      • useExec
      • useSQL
      • useAI
  • 迁移
  • FAQ
由 GitBook 提供支持
在本页
  • API 参考
  • confirmAlert
  • 类型
  • Alert.Options
  • Alert.ActionOptions
  • Alert.ActionStyle
  1. API 参考
  2. Feedback

Alert

上一页Feedback下一页HUD

最后更新于1年前

当用户执行重要操作时(例如,不可逆地删除某些内容时),您可以使用 confirmAlert 请求确认。

API 参考

confirmAlert

签名

async function confirmAlert(options: Alert.Options): Promise<boolean>;

例子

import { confirmAlert } from "@raycast/api";

export default async function Command() {
  if (await confirmAlert({ title: "Are you sure?" })) {
    console.log("confirmed");
    // do something
  } else {
    console.log("canceled");
  }
}

参数

名称
描述
类型

options*

用于创建告警的选项。

返回

当用户触发其中一个操作时解析为布尔值的 Promise。对于 primary 操作,它为 true;对于 dismiss 操作,它为 false。

类型

Alert.Options

创建告警的选项。

例子

import { Alert, confirmAlert } from "@raycast/api";

export default async function Command() {
  const options: Alert.Options = {
    title: "Finished cooking",
    message: "Delicious pasta for lunch",
    primaryAction: {
      title: "Do something",
      onAction: () => {
        // while you can register a handler for an action, it's more elegant
        // to use the `if (await confirmAlert(...)) { ... }` pattern
        console.log("The alert action has been triggered");
      },
    },
  };
  await confirmAlert(options);
}

属性

名称
描述
类型

title*

告警的标题。显示在图标下方。

string

dismissAction

消除告警的操作。当用户执行此操作时通常不应该有任何副作用。

icon

用于说明操作的告警图标。显示在顶部。

message

告警的附加消息。有助于显示更多信息,例如破坏性操作的确认消息。

string

primaryAction

用户可以采取的 primary操作。

Alert.ActionOptions

用于创建告警操作的选项。

属性

名称
描述
类型

title*

操作的标题

string

style

操作的样式

onAction

触发操作的回调

() => void

Alert.ActionStyle

定义告警操作的视觉样式。

枚举成员

名称
值

Default

Destructive

Cancel

创建并显示带有给定 的确认告警。

使用 确认 positive 操作。使用 确认 destructive 操作(例如删除文件)。

选项
Alert.ActionStyle.Default
Alert.ActionStyle.Destructive
Alert.Options
Alert.ActionOptions
Alert.ActionOptions
Alert.ActionStyle
Image.ImageLike