UNPKG

@lark-project/js-sdk

Version:

飞书项目 JSSDK 是飞书项目开放平台面向前端插件开发者提供的基于飞书项目内的开发工具包。 通过使用飞书项目 JSSDK,开发者可以方便的读取平台业务数据,如空间、工作项、字段等,当然也包括插件所运行环境的基础信息,如语言、地区、设备类型等。为开发者提供更高效的插件开发体验。

2,232 lines (2,191 loc) 54.1 kB
/** * @public * 用户信息 */ interface User { /** * 唯一标识 */ id: string; /** * 用户名 */ name: string; /** * 用户头像 */ avatar: string; /** * 所属租户 * @mobile_version >= 7.37 */ tenantId?: string; } /** * @public * 工作项属性枚举 */ declare enum AttributeType { /** * 工作项名称 */ name = "name", /** * 工作项模版 */ template = "template" } /** * @public * 字段类型枚举 * 仅包含字段管理模块支持新建的字段类型 */ declare enum FieldType { /** * 未知字段类型 */ unknown = "unknown", /** * 平台控件 * e.g. 角色与人员 */ control = "control", /** * 文本(单行、多行) * * @privateRemarks * 字段新建提供了单行文本、多行文本,但实际对应的都是 text */ text = "text", /** * 富文本 */ richText = "multi_text", /** * 单项选择 */ select = "select", /** * 多项选择 */ multiSelect = "multi_select", /** * 级联单选 */ treeSelect = "tree_select", /** * 级联多选 */ treeMultiSelect = "tree_multi_select", /** * 单选按钮 */ radio = "radio", /** * 单选人员 */ user = "user", /** * 多选人员 */ multiUser = "multi_user", /** * 日期(日期 + 时间) * * @privateRemarks * 字段新建提供了日期、日期 + 时间,但实际对应的都是 date */ date = "date", /** * 日期区间 */ dateRange = "schedule", /** * 表态投票 */ simpleVoting = "vote_boolean", /** * 单选投票 */ singleVoting = "vote_option", /** * 多选投票 */ multiVoting = "vote_option_multi", /** * 超链接 */ link = "link", /** * 数字 */ number = "number", /** * 附件 */ attachment = "multi_file", /** * 开关 */ bool = "bool", /** * 系统外信号 */ singleSignal = "signal", /** * 多值系统外信号 */ multiSignal = "multi_signal", /** * 复合字段 */ compoundField = "compound_field", /** * 单选关联工作项 */ workItemRelatedSelect = "work_item_related_select", /** * 多选关联工作项 */ workItemRelatedMultiSelect = "work_item_related_multi_select" } /** * @public * 空间(仅含关键属性) */ interface BriefSpace { /** * 唯一标识 */ id: string; /** * 名称 */ name: string; } /** * @public * 字段(仅含关键属性) */ interface BriefField { /** * 唯一标识 */ id: string; /** * 名称 */ name: string; /** * 字段类型 */ type: FieldType; } /** * @public * 工作项实例(仅含关键属性) */ type BriefWorkItem = { id: number; name: string; spaceId: string; workObjectId: string; }; /** * @public * 工作项模板(仅含关键属性) */ interface BriefTemplate { /** * 工作项模板唯一标识 */ id: number; /** * 工作项模板名称 */ name: string; /** * 流程模式 */ flowMode: FlowMode; /** * 模板已禁用 */ disabled: boolean; } /** * @public * 角色 */ interface Role { id: string; name: string; } /** * @public * 角色与人员 */ interface RoleOwners { roleId: string; owners: User[]; } /** * @public * 工作流模式 */ declare enum FlowMode { /** * 节点流,TODO: 需要给一些介绍 */ workFlow = "workflow", /** * 状态流,TODO: 同上 */ stateFlow = "stateflow" } /** * @public * 工作项基础信息 */ interface BriefWorkObject { /** * 工作项唯一标识 */ id: string; /** * 工作项系统标识 */ apiName: string; /** * 工作项名称 */ name: string; } /** * @public * 业务线 */ interface BizLine { id: string; name: string; isLeaf: boolean; disabled: boolean; children?: BizLine[]; } /** * @public * 流程节点(仅含关键属性) */ interface BriefNode { id: string; name: string; } /** * @public * 节点状态 */ declare enum NodeStatus { /** * 未开始 */ unreach = 1, /** * 进行中 */ reached = 2, /** * 已完成 */ passed = 3 } /** * @public * 视图(仅含关键属性) */ type BriefView = any; /** * @public * 语言 */ type Language = 'zh_CN' | 'en_US' | 'ja_JP'; /** * @public * 颜色方案 */ type ColorScheme = 'light' | 'dark'; /** * 集成构成 * 用于配置第三方平台&本平台的数据集成规则 */ interface IntegrationFeatureContext { /** * 空间标识 */ spaceId: string; } /** * 按钮位置 */ declare enum ButtonScene { /** * 工作项-更多 */ workItem = 3, /** * 工作项节点-更多 */ workItemNode = 4 } /** * 工作项实例按钮上下文 * 适用场景:工作项-更多 / 节点-更多 / 节点流转 */ interface WorkItemButtonFeatureContext { /** * 空间标识 */ spaceId: string; /** * 工作项类型标识 */ workObjectId: string; /** * 工作项实例唯一标识 */ workItemId: number; /** * 按钮所属节点标识 * 适用场景:节点-更多 / 节点流转 */ nodeId?: string; } /** * 新建按钮上下文 */ interface CreateButtonFeatureContext { /** * 空间标识 */ spaceId: string; /** * 工作项类型标识 * 适用场景:新建按钮出现在视图页时,该字段才有数据 */ workObjectId?: string; /** * 视图标识 * 适用场景:新建按钮出现在视图页时,该字段才有数据 */ viewId?: string; } interface ScheduleUnitButtonFeatureContext { /** * 空间标识 */ spaceId: string; /** * 工作项类型标识 */ workObjectId: string; /** * 工作项实例唯一标识 */ workItemId: number; /** * 计划表单元上下文信息 */ scheduleUnitCtx: { /** * 计划表编辑草稿标识 */ draftId: string; /** * 计划表单元父节点标识 */ parentUUID: string; /** * 计划表单元标识 */ uuid: string; /** * 计划表单元类型 */ type: string; /** * 计划表单元值 */ value: Record<string, any>; }; } /** * 视图批量按钮上下文 * 适用场景:普通视图、工作项主页视图、工作台视图组件 */ interface BatchButtonFeatureContext { /** * 视图所属空间标识 */ spaceId: string; /** * 视图所属工作项类型标识 */ workObjectId: string; /** * 视图标识 */ viewId?: string; /** * 勾选的工作项实例 */ selectedWorkItems: Array<{ spaceId: string; workObjectId: string; workItemIds: number[]; }>; } /** * 按钮构成 */ type ButtonFeatureContext = WorkItemButtonFeatureContext | CreateButtonFeatureContext | BatchButtonFeatureContext | ScheduleUnitButtonFeatureContext; /** * 内嵌页面构成 * 一个单独的导航入口+内嵌页面 */ interface PageFeatureContext { /** * 空间标识 */ spaceId: string; } /** * 配置页面构成 */ interface ConfigurationFeatureContext { /** * 空间标识 */ spaceId: string; } /** * 详情页 Tab 构成 * 工作项详情页中的 Tab 页面 */ interface TabFeatureContext { /** * 空间标识 */ spaceId: string; /** * 工作项类型标识 */ workObjectId: string; /** * 工作项实例唯一标识 * 适用场景:仅在工作项实例场景下,该字段才有数据,在工作项配置侧该字段为空 */ workItemId: number; } /** * 视图构成 * 工作项视图或者图表视图页面 */ interface ViewFeatureContext { /** * 空间标识 */ spaceId: string; /** * 工作项类型标识 */ workObjectId: string; /** * 视图标识 */ viewId: string; } /** * 控件构成 */ interface ControlFeatureContext { /** * 控件当前所属空间标识 */ spaceId: string; /** * 控件当前所属工作项类型标识 */ workObjectId: string; /** * 控件当前所属工作项实例标识 * 新建页表单内该值为空 */ workItemId?: number; /** * 控件唯一标识 * 新建场景结合 webhook 用于关联自有数据 * 详情页可能为空,不推荐强依赖 UUID 读取自有数据 */ UUID?: string; /** * 当前节点标识 * 适用场景:详情页为节点流时,且当前控件位于节点表单内,该字段才有数据 */ nodeId?: string; } /** * 拦截事件类型 */ declare enum InterceptEvent { /** 创建工作项 */ CreateWorkItem = 1001, /** 删除工作项 */ DeleteWorkItem = 1002, /** 批量删除工作项 */ BatchDeleteWorkItem = 1003, /** 恢复工作项 */ RecoveryWorkItem = 1004, /** 终止工作项 */ AbortWorkItem = 1005, /** 模板升级 */ UpgradeTemplate = 1006, /** 批量模板升级 */ BatchUpgradeTemplate = 1007, /** 导出工作项 */ ExportWorkItem = 1008, /** 完成节点 */ FinishNode = 2001, /** 删除节点 */ DeleteNode = 2002, /** 恢复节点 */ RecoveryNode = 2003, /** 回滚节点 */ RollBackNode = 2004, /** 填写排期与估分 */ EditSchedule = 2005, /** 变更状态 */ UpdateState = 3001 } /** * 拦截构成 * 用于拦截用户行为,包括拦截位置、触发规则和提示等相关配置 */ interface InterceptFeatureContext<T> { message: string; eventType: InterceptEvent; workItems: Array<BriefWorkItem & { /** * 当前触发事件,不同事件类型对应不同的 changedValue */ changedValue?: { fieldInfo?: Array<{ fieldKey: string; fieldType?: string; alias?: string; beforeFieldValue?: unknown; afterFieldValue?: unknown; }>; nodeInfo?: any; subTaskInfo?: any; transitionInfo?: any; }; }>; customData: T; } /** ----------------------- 拓展组件-排期组件特化属性 ----------------------- */ /** * 排期组件位置 */ declare enum ComponentScheduleScene { /** * 全部 */ ALL = 0, /** * 工作项节点/子任务 */ workItemNode = 1, /** * 计划表 */ scheduleTable = 2 } declare enum WorkItemNodeType { Node = "node", SubTask = "sub_task", SubWorkItem = "sub_workitem", SubInstance = "sub_instance" } interface WorkItemInfo { spaceId: string; workObjectId: string; workItemId: number; } type ComponentScheduleIdentity = WorkItemInfo & { type: WorkItemNodeType; nodeId: string; taskId: string; }; interface WbsStatus { wbsStatus: string; } interface UserInfo { userKey: string; } type ScheduleCompValueType = string[]; /** * schedule 组件类型校验返回值 */ interface ScheduleCompValidateMsg { code: 200 | number; msg: string; } /** ----------------------- 拓展点位通用类型 ----------------------- */ /** * 自定义组件构成 * 支持的定义组件类型 */ declare enum CustomComponentType { Schedule = "schedule" } /** * 自定义组件构成 * 允许用户定制指定业务组件类型的UI */ interface CustomComponentFeatureContext<I extends { /** * 组件节点标识 * 适用场景:详情页为节点流时,且当前控件位于节点表单/计划表内,该字段才有数据 */ nodeId?: string; /** * 组件子任务标识 * 适用场景:详情页为节点流时,且当前控件位于节点表单/计划表内,该字段才有数据 */ taskId?: string; }, S extends ComponentScheduleScene> { /** * 组件所处场景 */ scene: S; /** * 组件当前所属空间标识 */ spaceId: string; /** * 组件当前所属工作项类型标识 */ workObjectId: string; /** * 组件当前所属工作项实例标识 * 新建页表单内该值为空 */ workItemId?: number; /** * 组件唯一标识 * 组件所属节点的所属空间/工作项/工作项实例以及节点任务标识 */ identity?: I; } /** * 自定义组件构成 * 各业务组件类型拥有的 props */ interface CustomComponentProps { [CustomComponentType.Schedule]: { value: ScheduleCompValueType; disabled?: boolean; }; } /** ----------------------- 拓展字段构成类型 ----------------------- */ interface CustomFieldFeatureContext { /** * 拓展字段当前所属空间标识 */ spaceId: string; /** * 拓展字段当前所属工作项类型标识 */ workObjectId: string; /** * 拓展字段当前所属工作项实例标识 * 新建页表单内该值为空 */ workItemId?: number; /** * 当前节点标识 * 适用场景:详情页为节点流时,且当前拓展字段位于节点表单内,该字段才有数据 */ nodeId?: string; } type FieldNumberValue = number; type FieldMultiTextValue = string; type FieldTreeSelectOptionValue = string[]; type FieldDatePreciseValue = string | number; type FieldMultiUserValue = string[]; type FieldValue = FieldNumberValue | FieldMultiTextValue | FieldTreeSelectOptionValue | FieldDatePreciseValue | FieldMultiUserValue; interface ExCompoundFieldValueType { field_key: string; field_value: { field_key: string; value?: FieldValue; }[][]; } type CustomFieldValueType = ExCompoundFieldValueType; interface CustomFieldProps { value: CustomFieldValueType; disabled?: boolean; } interface CustomFieldConfig { key: string; type: FieldType.compoundField | SubFieldType; name: string; children?: CustomFieldConfig[]; } interface CustomFieldValidateMsg { /** * code 为 200 时 msg 按照正常成功数据返回外 * 401 | 402 | 403 | 404 | 405 | 406 按照 InvalidParams 类型异常返回,可以通过该异常的 errCode、errMsg 属性查看具体出错原因 * 其余执行过程异常按照 InternalError 异常抛出 * 具体的 code 和对应的 msg 信息及解释可参考开发者手册的详细介绍 */ code: 200 | 401 | 402 | 403 | 404 | 405 | 406; msg: string; } type SubFieldType = /** * 数字类型 */ FieldType.number /** * 多行文本 * 字段类型为 text * 在字段模型中和单行文本字段的区别为 multi = true */ | FieldType.text /** * 级联多选 * 如果写入不存在的选项可能导致接口报错/提示 */ | FieldType.treeMultiSelect /** * 时间+日期 * 字段类型为 date * 在字段模型中和普通日期字段的区别是本时间精确度为 "YYYY-MM-DD HH:mm:ss"(普通为 YYYY-MM-DD) */ | FieldType.date /** * 多选人员 * 如果写入不存在的人员可能导致接口报错/提示 */ | FieldType.multiUser; /** * 构成弹窗配置 */ interface ContainerModalConfigureOptions { /** * 关闭前确认 */ confirmBeforeClose?: { /** * 弹窗标题,仅支持字符串 */ title: string; /** * 弹窗内容,仅支持字符串 */ content: string; }; } /** * @internal */ type unwatch = () => void; type Off = unwatch; type IIgnore = string | RegExp | ((value: string) => boolean); interface IPluginCustomBuildConfig { /** 默认 /node_modules/ */ ignores?: IIgnore | IIgnore[]; /** 排除目录下图片资源的编译 */ assetsIgnores?: IIgnore | IIgnore[]; /** 排除目录下样式资源的编译 */ stylesIgnores?: IIgnore | IIgnore[]; externals?: Record<string, string>; } /** * @internal */ declare const MEEGO_BIZ_HUB = "__MEEGO_BIZ_HUB__"; /** * @internal * 每个声明的抽象类都必须实现这个属性,用于唯一标识 */ declare const IMPL_KEY = "__MEEGO_SDK_IMPL_KEY__"; /** * @internal */ declare abstract class BaseModel { protected static [IMPL_KEY]: string; } /** * @public * 应用上下文/状态 */ declare abstract class Context extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载上下文 */ static load(): Promise<Context>; /** * 当前语言 */ abstract language: Language; /** * 用户偏好的色彩方案 */ abstract colorScheme: ColorScheme; /** * 当前登录用户信息 */ abstract loginUser: User; /** * @deprecated 请使用各功能构成的上下文读取当前的工作项信息,如 JSSDK.Button.getContext() * 当前打开的工作项(仅工作项详情页可用) */ abstract activeWorkItem?: BriefWorkItem; /** * 当前选中的工作流节点(仅工作项详情页可用) */ abstract selectedWorkflowNode?: BriefNode & { status: NodeStatus; }; /** * 监听 Context 变化,目前仅在 Web 端 mainSpace、activeWorkItem、selectedWorkflowNode 变化时触发回调 * @param callback */ abstract watch(callback: (nextValue: Context) => void): unwatch; /** * only web 2.0 * 用于获取插件内设置的上下文数据 * 例如:在 sdk.modal.open 时传入的 context,可以通过该方法来获取 */ abstract getCustomContext<Context>(): Promise<Context>; } /** * @public * 项目空间 */ declare abstract class Space extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载空间模型 * @param id 空间唯一标识 * @returns 空间实例(Promise) */ static load(id: string): Promise<Space>; /** * 空间唯一标识 */ abstract id: string; /** * 空间域名 */ abstract simpleName: string; /** * 空间名称 */ abstract name: string; /** * 所有工作项列表 */ abstract allWorkObjectList: BriefWorkObject[]; /** * 启用的工作项列表 */ abstract enabledWorkObjectList: BriefWorkObject[]; /** * 禁用的工作项列表 */ abstract disabledWorkObjectList: BriefWorkObject[]; /** * 获取空间业务线列表 * @returns 空间业务线列表 */ abstract getBizLineList(): Promise<Array<BizLine> | undefined>; } /** * @public * 工作项对象 */ declare abstract class WorkObject extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载工作项对象模型 * @param params * spaceId 空间唯一标识 * workObjectId 工作项对象唯一标识 */ static load(params: { spaceId: string; workObjectId: string; }): Promise<WorkObject>; /** * 唯一标识 */ abstract id: string; /** * 系统标识 */ abstract apiName: string; /** * 工作流模式 */ abstract flowMode: FlowMode; /** * 所属空间标识 */ abstract spaceId: string; /** * 名称 */ abstract name: string; /** * 描述 */ abstract description: string; /** * 字段列表 */ abstract fieldList: BriefField[]; /** * 读流程模板列表 */ abstract getTemplateList(): Promise<BriefTemplate[]>; /** * 读取角色列表 */ abstract getRoleList(): Promise<Role[]>; } /** * @public * 工作项实例 */ declare abstract class WorkItem extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载工作项实例模型 * @param params * spaceId 空间唯一标识 * workObjectId 工作项对象唯一标识 * workItemId 工作项实例唯一标识 */ static load(params: { spaceId: string; workObjectId: string; workItemId: number; }): Promise<WorkItem>; /** * 唯一标识 */ abstract id: number; /** * 空间标识 */ abstract spaceId: string; /** * 所属工作项标识 */ abstract workObjectId: string; /** * 使用的工作项模板标识 */ abstract templateId: number; /** * 工作项实例名称 */ abstract name: string; /** * 角色与人员列表 */ abstract roleOwnersList: RoleOwners[]; /** * 工作项实例已终止 */ abstract isAborted: boolean; /** * 工作项实例已删除 */ abstract isDeleted: boolean; /** * 获取工作项实例自定义字段相关数据 * TODO: 类型暂未定义 */ abstract getFieldValue(fieldId: string): any; } /** * @public * 字段 */ declare abstract class Field extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载字段模型 * @param id 字段唯一标识 * spaceId 空间唯一标识 * workObjectId 工作项对象唯一标识 * fieldId 字段唯一标识 */ static load(params: { spaceId: string; workObjectId: string; fieldId: string; }): Promise<Field>; /** * 字段唯一标识 */ abstract id: string; /** * 字段类型 */ abstract type: FieldType; /** * 字段名称 */ abstract name: string; /** * 属于系统字段(用户可编辑值) */ abstract isSystemField: boolean; /** * 属于系统计算字段(用户不可编辑值,由系统自动计算) */ abstract isSystemCalculateField: boolean; /** * 属于公式字段 */ abstract isFormulaField: boolean; } /** * @public * 新建工作项表单预填 */ interface WorkItemCreateFormPreset { /** * 工作项属性,目前仅支持工作项名称(name) */ attribute?: { [key in AttributeType]?: { attributeValue: any; }; }; /** * 工作项字段 */ field?: { [fieldId: string]: { fieldType: Exclude<FieldType, FieldType.unknown | FieldType.simpleVoting | FieldType.singleVoting | FieldType.multiVoting | FieldType.attachment | FieldType.singleSignal | FieldType.multiSignal | FieldType.compoundField>; fieldValue: any; }; }; } /** * @public * 应用的导航 */ declare abstract class Navigation extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * @internal */ private static load; /** * @public * mobile version ≥ 7.41.0 * 读取当前页面地址的 hostname */ abstract getHostname(): Promise<string>; /** * @public * only web 2.0 * 读取当前完整的页面地址 */ abstract getHref(): Promise<string>; /** * 打开新标签页加载指定的资源 * @param url 需要载入的 URL,可以是 HTML 页面或者图片文件等浏览器支持的文件格式 * @param target 新标签页的名称,字符串中不能包含空格。使用相同的标签页名称可以复用同一个标签页(推荐) */ abstract open(url: string, target?: string): void; /** * 打开指定空间工作项新建页 * @param options * @param options.spaceId 空间唯一标识 * @param options.spaceSimpleName [废弃]空间标识,非空间唯一标识 * @param options.workObjectId 工作项类型唯一标识,如 story、issue * @param options.supportedWorkObjectIds 新建页支持切换的工作项类型列表,默认所有都展示 * @param options.formPreset 新建工作项表单预填值 * @param callback 新建完成回调,当 err 为 undefined 时为新建成功,可以通过 result.workItemId 取新建工作项实例 id */ abstract openWorkItemCreatePage(options: { spaceId: string; /** * @deprecated */ spaceSimpleName?: string; workObjectId: string; supportedWorkObjectIds?: string[]; formPreset?: WorkItemCreateFormPreset; }, callback?: (err: Error | undefined, result: { workItemId: number; }) => void, onCancel?: () => void): void; /** * 打开指定空间工作项实例 * @param options * @param options.spaceId 空间唯一标识 * @param options.spaceSimpleName [废弃]空间标识,非空间唯一标识 * @param options.workObjectId 工作项类型唯一标识,如 story、issue * @param options.workItemId 工作项实例唯一标识 */ abstract openWorkItemDetailPage(options: { spaceId: string; /** * @deprecated */ spaceSimpleName?: string; workObjectId: string; workItemId: number; }): void; } /** * @public * Share 用于配置一些共享模块 */ declare abstract class Shared extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * only web 2.0 * * 设置共享模块,以便注入资源消费,注入不同的共享模块,将决定使用不同的注入资源 * * 插件可决定是否使用注入资源能力: * 1. 使用,必须设置共享模块 * 2. 不使用,可不设置共享模块,完全自定义UI * * 消费共享模块的注入资源列表: * 1. 业务组件资源,依赖注入:React、ReactDOM * * @param params 插件可提供的共享模块,共享模块会被其他注入资源消费 * @returns 插件在promise返回后才可开始引用+执行插件UI,否则可能导致报错 */ abstract setSharedModules(params: { React: any; ReactDOM: any; }): Promise<void>; } /** * @public * 本地临时存储 * 存储是当前登录用户 + 插件维度隔离,跨插件无法实现互相访问,每个插件的临时存储空间不超过 5MB */ declare abstract class Storage extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * @internal */ private static load; /** * 写入存储 * @param key 存储标识 * @param value 存储值 */ abstract setItem(key: string, value: string | undefined): Promise<void>; /** * 读取存储 * @param key 存储标识 * @returns 存储值(Promise) */ abstract getItem(key: string): Promise<string | undefined>; /** * 移除存储 * @param key 待移除的存储标识 */ abstract removeItem(key: string): Promise<void>; /** * 清除所有存储 */ abstract clear(): Promise<void>; } /** * @public * 剪贴板 */ declare abstract class Clipboard extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * @internal */ private static load; /** * 写入字符串到剪贴板 * @param text 待写入的字符串,不多于 1000 个字符 */ abstract writeText(text: string): Promise<boolean>; } /** * Toast 提示展示配置 */ interface ToastOptions { /** * 提示文案,默认 '' * 长度不超过 40 个字符,超出将被截断以...代替 */ content: string; /** * 自动关闭的延时,单位 s,默认 5s 后自动关闭,允许延时最长不超过 10s */ duration?: number; } /** * @public * Toast 是对用户的操作做出及时反馈,由用户的操作触发,反馈信息可以是操作的结果状态,如成功、失败、出错、警告等 * 每个插件同时只能激活一个提示,如同时激活多个,则仅展示最后一个 */ declare abstract class Toast extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * @internal */ private static load; /** * 信息类型提示 * @param options */ abstract info(options: string | ToastOptions): Promise<string>; /** * 错误类型提示 * @param options */ abstract error(options: string | ToastOptions): Promise<string>; /** * 警告类型提示 * @param options */ abstract warning(options: string | ToastOptions): Promise<string>; /** * 成功类型提示 * @param options */ abstract success(options: string | ToastOptions): Promise<string>; /** * 关闭提示 * @param id */ abstract close(id: string): void; } /** * ActionSheet 配置选项 */ interface ActionSheetOptions { /** * 菜单列表 * 数量限制 1 至 6 个 */ itemList: string[]; } /** * @mobile * @public * ActionSheet 动作菜单用于让用户选择操作 */ declare abstract class ActionSheet extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * @internal */ private static load; /** * 打开操作菜单 * @param options * @param callback * tapIndex 用户点击的菜单位置 */ abstract show(options: ActionSheetOptions, callback: (result: { tapIndex: number; }) => void): Promise<void>; } /** * Modal confirm 展示配置 */ interface ModalConfirmOptions { /** * 标题 * title 和 content 不可同时为空 */ title?: string; /** * 内容 * title 和 content 不可同时为空 */ content?: string; /** * 确认按钮文字 * 默认 ok */ confirmText?: string; /** * 是否展示取消按钮 * 默认 true */ showCancel?: boolean; /** * 取消按钮文字 * 默认 cancel */ cancelText?: string; } /** * Modal 展示配置 */ interface ModalOpenOptions<Context> { /** * 指定 modal 内容的代码入口,即在入口文件中导出的模块名 */ entry: string; /** * 宽度 * 默认: 448 */ width?: number; /** * 高度 */ height?: number; /** * 是否全屏 * 全屏时 width / height 无效 */ fullScreen?: boolean; /** * 是否允许通过点击遮罩来关闭对话框 */ maskClosable?: boolean; /** * 传入 Modal 内的上下文数据 * 注:传入的数据在 Modal 内是通过 sdk.containerModal.getContext() 来获取的 */ context?: Context; /** * 响应弹窗内调用的 sdk.containerModal.submit 方法 * @param params 弹窗内调用的 sdk.containerModal.submit 的方法时传入的自定义参数 */ onSubmit?: (params: unknown) => void; } /** * @public * Modal 用于等待用户响应、告知用户重要信息或在不丢失上下文的情况下展示更多信息 */ declare abstract class Modal extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * @internal */ private static load; /** * 使用模态框 confirm * @param options * @param callback * confirmed 点击了确认 * canceled 点击了取消 */ abstract confirm(options: string | ModalConfirmOptions, callback: (result: { confirmed: boolean; canceled: boolean; }) => void): Promise<void>; /** * only web 2.0 * 打开自定义内容的模态框 * @param options * @returns 当前打开 Modal 的关闭方法 */ abstract open<Context>(options: ModalOpenOptions<Context>): Promise<{ close: () => void; }>; } interface IRichTextEditorImageUploadComplete { /** * 错误码,非 0 表示异常 */ code: number; /** * 错误信息 */ errMsg: string; /** * 图片上传接口返回的 response 数据 */ responseData: any; } /** * RichTextEditor 配置 */ interface RichTextEditorOptions { /** * 编辑器标题,仅用于展示 */ title?: string; /** * 富文本默认内容,对应 RichTextEditorContent.doc */ defaultValue?: string; /** * 额外的上下文 */ context: { /** * 空间 id * @人 下拉人员列表会按空间推荐 * 附件上传会关联该空间权限控制 */ spaceId: string; }; /** * 你自定义图床的配置 * @mobile_version >= 7.31 */ imageUpload?: { /** * 你的图片上传服务地址 */ url: string; /** * 你的图片上传服务的鉴权 token * token 会通过 request header 的 x-plugin-custom-token 提供 */ token?: string; /** * 上传完成回调 * @mobile_version >=7.37.0 * @param info * @returns */ onUploadComplete?: (info: IRichTextEditorImageUploadComplete) => void; }; } /** * 富文本完整内容 */ interface RichTextEditorContent { /** * 富文本结构化数据 */ doc?: string; /** * 富文本 HTML 版本 */ doc_html?: string; /** * 富文本的纯文本概要 */ doc_text?: string; /** * 是否为空 */ is_empty: boolean; } /** * @public * RichTextEditor 用于富文本的编辑 */ declare abstract class RichTextEditor extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * @internal */ private static load; /** * 打开富文本编辑器 * @param options * @param callback * confirmed 点击了确认 * canceled 点击了取消 * nextValue 当点击确认时,返回编辑器内最新的内容,否则为 undefined */ abstract show(options: RichTextEditorOptions, callback: (result: { confirmed: boolean; canceled: boolean; nextValue?: RichTextEditorContent; }) => void): Promise<void>; } /** * WorkItemFinder 配置 */ interface WorkItemFinderOptions { /** * 空间标识 */ spaceId: string; /** * 工作项类型标识 */ workObjectId: string; /** * 筛选器标题,仅用于展示 */ title?: string; /** * 搜索条件标识 * 如为空则生成新 key,不为空则会覆写 * searchId 与 workObjectId | spaceId 不匹配则会异常 */ searchId?: string; /** * 默认 true,控制 searchId 的筛选条件是否回填到筛选器 */ backfill?: boolean; } /** * @public * WorkItemFinder 用于生成工作项实例筛选条件的面板 */ declare abstract class WorkItemFinder extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * @internal */ private static load; /** * only web 2.0 * 打开工作项实例筛选条件面板 * @param options * @param callback * confirmed 点击了确认 * canceled 点击了取消 * searchId 当点击确认时,返回筛选条件标识 searchId */ abstract open(options: WorkItemFinderOptions, callback: (result: { confirmed: boolean; canceled: boolean; searchId?: string; }) => void): Promise<void>; } /** * @mobile * @public * Utils */ declare abstract class Utils extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * @internal */ private static load; /** * 信息类型提示 * @param apiList string[] 方法名列表 * @returns * availableList string[] 可用方法名列表 */ abstract canIUse(apiList: string[]): Promise<{ availableList: string[]; }>; /** * 获取用户身份授权码,用于 OpenAPI 换取 user_access_token * @returns * code 授权码 */ abstract getAuthCode(): Promise<{ code: string; }>; /** * 重置 @douyinfe/semi-ui 组件库的主题, 使组件更贴近飞书项目整体设计风格。 */ abstract overwriteThemeForSemiUI(): Promise<void>; } /** * @public * 插件容器模态框 */ declare abstract class ContainerModal extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载数据 */ static load(): Promise<ContainerModal>; /** * only web 2.0 * 只存在于 modal.open 打开的容器内 * submit 调用的是 sdk.modal.open 传入的 onSubmit 方法 */ abstract submit?: <Params>(params: Params) => Promise<void>; /** * mobile version ≥ 7.22.0 * 关闭插件当前激活的容器模态框 */ abstract close(): Promise<void>; /** * only web 2.0 * 配置当前弹窗,如点击关闭时是否需要确认 */ abstract configure(options: ContainerModalConfigureOptions): Promise<void>; } /** * @public * 拦截事件模态框 */ declare abstract class Intercept extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载数据 */ static load(): Promise<Intercept>; /** * mobile version ≥ 7.22.0 * 获取当前触发的拦截事件上下文 */ abstract getContext<T = any>(): Promise<InterceptFeatureContext<T>>; } /** * @public * 控件 */ declare abstract class Control extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载数据 */ static load(): Promise<Control>; /** * mobile version ≥ 7.25.0 * 获取当前控件所在的上下文 */ abstract getContext(): Promise<ControlFeatureContext>; /** * 获取新建工作项表单项的值 * mobile version ≥ 7.29.0 * @param keys 需要获取的工作项属性 / 字段 ID 列表,一次限制读取 10 个 keys * @param keys.key 工作项属性 / 字段 ID * @param keys.type 类型 * 工作项属性 name 为 FieldType.text,工作项属性 template 为 FieldType.number * 控件 role_owners 为 FieldType.control */ abstract getCreateWorkItemFormItemValues(keys: Array<{ key: string | AttributeType; type: Exclude<FieldType, FieldType.richText | FieldType.singleSignal | FieldType.multiSignal | FieldType.singleVoting | FieldType.multiVoting | FieldType.simpleVoting>; }>): Promise<Record<string | AttributeType, any>>; /** * only web 2.0 * 监听新建工作项表单项值变化 * @param options.watchKeys 需要监听的工作项属性 / 字段 ID 列表,一次限制读取 10 个 keys * @param options.watchKeys.key 工作项属性 / 字段 ID * @param options.watchKeys.type 类型 * 工作项属性 name 为 FieldType.text,工作项属性 template 为 FieldType.number * 控件 role_owners 为 FieldType.control * @param callback 当监听值发生变化时触发,changedKeys 为变化的 keys */ abstract onCreateWorkItemFormValueChanged(options: { watchKeys: Array<{ key: string | AttributeType; type: Exclude<FieldType, FieldType.richText | FieldType.singleSignal | FieldType.multiSignal | FieldType.singleVoting | FieldType.multiVoting | FieldType.simpleVoting>; }>; }, callback: (changedKeys: Array<string | AttributeType>) => void): Off; /** * 监听工作项表单项值变化 * @param options.watchKeys 需要监听的工作项 字段 ID 列表 * @param callback 当监听值发生变化时触发,changedValue 为变化的 kv */ abstract onWorkItemFormValueChanged(options: { watchKeys: Array<{ key: string | AttributeType; type: Exclude<FieldType, FieldType.richText | FieldType.singleSignal | FieldType.multiSignal | FieldType.singleVoting | FieldType.multiVoting | FieldType.simpleVoting>; }>; }, callback: (changedValue: Record<string, unknown>) => void): Promise<Off>; /** * only mobile 7.35.0+ * 获取插件的展示态信息 */ abstract getDisplayInfo(): Promise<{ display_height: number; }>; /** * only mobile 7.35.0+ * 打开全屏插件 */ abstract openFullScreenPlugin(): void; } /** * @public * 按钮 */ declare abstract class Button extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载数据 */ static load(): Promise<Button>; /** * mobile version ≥ 7.24.0 * 获取当前按钮的上下文 */ abstract getContext(): Promise<ButtonFeatureContext>; /** * only web 2.0 * 监听工作项表单项值变化 * @param options.watchKeys 需要监听的工作项 字段 ID 列表 * @param callback 当监听值发生变化时触发,changedValue 为变化的 kv */ abstract onWorkItemFormValueChanged(options: { watchKeys: Array<{ key: string | AttributeType; type: Exclude<FieldType, FieldType.richText | FieldType.singleSignal | FieldType.multiSignal | FieldType.singleVoting | FieldType.multiVoting | FieldType.simpleVoting>; }>; }, callback: (changedValue: Record<string, unknown>) => void): Promise<Off>; } /** * @public * 插件配置 */ declare abstract class Configuration extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载数据 */ static load(): Promise<Configuration>; /** * 获取当前配置点位的上下文 */ abstract getContext(): Promise<ConfigurationFeatureContext>; } /** * @public * 内嵌页面 */ declare abstract class Page extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载数据 */ static load(): Promise<Page>; /** * 获取当前内嵌页面的上下文 */ abstract getContext(): Promise<PageFeatureContext>; } /** * @public * 详情页 */ declare abstract class Tab extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载数据 */ static load(): Promise<Tab>; /** * 获取当前详情页 Tab 的上下文 */ abstract getContext(): Promise<TabFeatureContext>; /** * only web 2.0 * 监听工作项表单项值变化 * @param options.watchKeys 需要监听的工作项 字段 ID 列表 * @param callback 当监听值发生变化时触发,changedValue 为变化的 kv */ abstract onWorkItemFormValueChanged(options: { watchKeys: Array<{ key: string | AttributeType; type: Exclude<FieldType, FieldType.richText | FieldType.singleSignal | FieldType.multiSignal | FieldType.singleVoting | FieldType.multiVoting | FieldType.simpleVoting>; }>; }, callback: (changedValue: Record<string, unknown>) => void): Promise<Off>; } /** * @public * 视图 */ declare abstract class View extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; /** * 加载数据 */ static load(): Promise<View>; /** * 获取当前视图的上下文 */ abstract getContext(): Promise<ViewFeatureContext>; } /** * @public * 自定义组件构成 */ declare abstract class CustomComponent extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; abstract [CustomComponentType.Schedule]: { getProps: () => Promise<CustomComponentProps[CustomComponentType.Schedule]>; /** * 用于监听 props 变更 * @param callback 返回 schedule 组件新的 props * @param watchKeys 监听的 key,只能监听属性的 key(不能监听 api key),不传默认监听所有 key。监听的 key 对应的值变更会触发回调 * @returns */ watch: (callback: (next: CustomComponentProps[CustomComponentType.Schedule]) => void, watchKeys?: (keyof CustomComponentProps[CustomComponentType.Schedule])[]) => Off; getContext: () => Promise<CustomComponentFeatureContext<ComponentScheduleIdentity, ComponentScheduleScene>>; resizeContainer: (width?: number, height?: number) => Promise<undefined>; getWbsStatus?: () => Promise<WbsStatus>; getOwnersInfo?: () => Promise<UserInfo[]>; handleSubmit: (value: ScheduleCompValueType) => Promise<ScheduleCompValidateMsg>; handleCancel: () => Promise<void>; }; } /** * @public * 自定义组件构成 */ declare abstract class CustomField extends BaseModel { /** * @internal */ protected static [IMPL_KEY]: string; abstract getContext: () => Promise<CustomFieldFeatureContext>; abstract getProps: () => Promise<CustomFieldProps>; /** * only for form * 用于监听 props 变更 * @param callback 返回插件字段新的 props * @param watchKeys 监听的 key,只能监听属性的 key(不能监听 api key),不传默认监听所有 key。监听的 key 对应的值变更会触发回调 * @returns */ abstract watch: (callback: (next: CustomFieldProps | Record<string, never>) => void, watchKeys?: (keyof CustomFieldProps)[]) => Promise<Off>; abstract saveFieldValue: (value: CustomFieldValueType) => Promise<CustomFieldValidateMsg>; abstract getFieldConfig: () => Promise<CustomFieldConfig>; /** * 获取新建工作项表单项的值 * mobile version ≥ 7.29.0 * @param keys 需要获取的工作项属性 / 字段 ID 列表,一次限制读取 10 个 keys * @param keys.key 工作项属性 / 字段 ID * @param keys.type 类型 * 工作项属性 name 为 FieldType.text,工作项属性 template 为 FieldType.number * 控件 role_owners 为 FieldType.control */ abstract getCreateWorkItemFormItemValues(keys: Array<{ key: string | AttributeType; type: Exclude<FieldType, FieldType.richText | FieldType.singleSignal | FieldType.multiSignal | FieldType.singleVoting | FieldType.multiVoting | FieldType.simpleVoting>; }>): Promise<Record<string | AttributeType, any>>; /** * 监听工作项表单项值变化 * @param options.watchKeys 需要监听的工作项 字段 ID 列表 * @param callback 当监听值发生变化时触发,changedValue 为变化的 kv */ abstract onWorkItemFormValueChanged(options: { watchKeys: Array<{ key: string | AttributeType; type: Exclude<FieldType, FieldType.richText | FieldType.singleSignal | FieldType.multiSignal | FieldType.singleVoting | FieldType.multiVoting | FieldType.simpleVoting>; }>; }, callback: (changedValue: Record<string, unknown>) => void): Promise<Off>; /** * only web for table * 打开全屏插件 */ abstract getTableCellInitProps(): Promise<CustomFieldProps>; /** * only mobile 7.35.0+ * 获取插件的展示态信息 */ abstract getDisplayInfo(): Promise<{ display_height: number; }>; /** * only mobile 7.35.0+ * 打开全屏插件 */ abstract openFullScreenPlugin(): void; } /** * @public * SDKClient 的配置项 */ interface SDKClientOptions { isDebug?: boolean; pluginId: string; } /** * @public * SDKClient 是使用 SDK 的入口,需要通过 SDKClient 实例化并配置相关数据后才能调用 API */ declare class SDKClient { /** * SDK 版本号 */ static version: string; /** * 插件容器模态框 * only 2.0 */ get containerModal(): ContainerModal; /** * 拦截事件点位容器特有能力 * only 2.0 */ get intercept(): Intercept; /** * 控件点位容器特有能力 * only 2.0 */ get control(): Control; /** * 按钮点位容器特有能力 * only 2.0 */ get button(): Button; /** * 配置点位容器特有能力 * only 2.0 */ get configuration(): Configuration; /** * 导航点位容器特有能力 * only 2.0 */ get page(): Page; /** * tab 点位容器特有能力 * only 2.0 */ get tab(): Tab; /** * 视图点位容器特有能力 * only 2.0 */ get view(): View; /** * 组件点位容器特有能力 * 现有组件:节点排期 schedule * only 2.0 */ get customComponent(): CustomComponent; /** * 实例字段点位容器特有能力 * only 2.0 */ get customField(): CustomField; /** * 应用导航 */ get navigation(): Navigation; /** * 本地存储 */ get storage(): Storage; /** * 剪贴板 */ get clipboard(): Clipboard; /** * 提示 */ get toast(): Toast; /** * 富文本编辑器 * only 2.0 */ get richTextEditor(): RichTextEditor; /** * 工作项实例筛选器 * only web 2.0 */ get workItemFinder(): WorkItemFinder; /** * 模态框 */ get modal(): Modal; /** * 共享模块 * only 2.0 */ get shared(): Shared; /** * 操作菜单 * only mobile 2.0 */ get actionSheet(): ActionSheet; /** * 工具方法 */ get utils(): Utils; /** * 应用上下文 */ get Context(): typeof Context; /** * 空间 */ get Space(): typeof Space; /** * 工作项配置 */ get WorkObject(): typeof WorkObject; /** * 工作项 */ get WorkItem(): typeof WorkItem; /** * 字段 */ get Field(): typeof Field; /** * @internal */ private _meegoBizHub; /** * JSSDK 初始化配置 * @param options 配置项 * @returns sdk */ config(options: SDKClientOptions): Promise<this>; } /** * @internal */ declare class CustomError extends Error { originMessage: string; constructor(options: { message: string; originMessage: string; }); } /** * @public * 内部逻辑异常 */ declare class InternalError extends CustomError { constructor(options: { originMessage: string; }); } /** * @public * 无权限访问对应数据的异常 */ declare class NoAuthError extends CustomError { constructor(options: { originMessage: string; }); } /** * @public * 未找到对应数据的异常 */ declare class NotFoundError extends CustomError { constructor(options: { originMessage: string; }); } /** * @public * 超出限制异常,如 Storage 存储超额 */ declare class OutOfLimitError extends CustomError { constructor(options: { originMessage: string; }); } /** * @public * 请求参数异常 */ declare class InvalidParamsError extends CustomError { errCode: number; errMsg: string; constructor(options: { originMessage: string; }); _parseErrorCode(): void; } /** * @public * API 在当前环境不支持 */ declare class NotSupportedError extends CustomError { constructor(options: { originMessage: string; }); } /** * 用于飞书项目插件读取系统数据的 JSSDK * * @remarks * 使用 SDK 之前请先初始化 {@link SDKClient},并通过 config 配置 * * @packageDocumentation */ export { ActionSheet, ActionSheetOptions, AttributeType, BatchButtonFeatureContext, BizLine, BriefField, BriefNode, BriefSpace, BriefTemplate, BriefView, BriefWorkItem, BriefWorkObject, Button, ButtonFeatureContext, ButtonScene, Clipboard, ColorScheme, ComponentScheduleIdentity, ComponentScheduleScene, Configuration, ConfigurationFeatureContext, ContainerModal, ContainerModalConfigureOptions, Context, Control, ControlFeatureContext, CreateButtonFeatureContext, CustomComponent, CustomComponentFeatureContext, CustomComponentProps, CustomComponentType, CustomField, CustomFieldConfig, CustomFieldFeatureContext, CustomFieldProps, CustomFieldValidateMsg, CustomFieldValueType, ExCompoundFieldValueType, Field, FieldType, FieldValue, FlowMode, IMPL_KEY, IPluginCustomBuildConfig, IRichTextEditorImageUploadComplete, IntegrationFeatureContext, Intercept, InterceptEvent, InterceptFeatureContext, InternalError, InvalidParamsError, Language, MEEGO_BIZ_HUB, Modal, ModalConfirmOptions, ModalOpenOptions, Navigation, NoAuthError, NodeStatus, NotFoundError, NotSupportedError, Off, OutOfLimitError, Page, PageFeatureContext, RichTextEditor, RichTextEditorContent, RichTextEditorOptions, Role, RoleOwners, SDKClient, SDKClientOptions, ScheduleCompValidateMsg, ScheduleCompValueType, ScheduleUnitButtonFeatureContext, Shared, Space, Storage, SubFieldType, Tab, TabFeatureContext, Toast, ToastOptions, User, UserInfo, Utils, View, ViewFeatureContext, WbsStatus, WorkItem, WorkItemButtonFeatureContext, WorkItemCreateFormPreset, WorkItemFinder, WorkItemFinderOptions, WorkObject, SDKClient as default, unwatch };