ksxz api 是一组 JavaScript API,您可以在协作插件中调用。您可以在 ksxz.d.ts 文件中找到对应的 api。
ksxz.web(web插件api)
declare
export type IEventListener<T> = (data: T) => void
export type Event<T> = (listener: (data: T) => void) => { dispose(): void }
export type ValueOf<T extends object> = T[keyof T]
export type PickKeyByValue<T extends object, U> = ValueOf<{
[P in keyof T]: T[P] & U extends never ? never : P
}>
export type MapOptional<T extends object, K extends keyof T = PickKeyByValue<T, undefined>> = Pick<Partial<T>, K> & Omit<T, K>
export interface IExtensionContext {
extension: {
name: string
path: string
fsPath: string
}
}
export interface IDisposable {
dispose(): void
}
export namespace ui {
export interface IPoint {
x: number
y: number
}
export interface IRectangle {
x: number
y: number
width: number
height: number
}
export interface ISelectUserOptions {
/** 选择指定会话id内的成员 */
chatid?: number
/** 是否返回第三方用户id */
isThirdUserId?: boolean
/** 最大选中人数 */
maxCount?: number
/** 默认选中用户id */
selectedUserIds?: number[]
/** 是否多选 */
isMultiple?: boolean
/** 通讯录选择器标题 */
title?: string
/** 确定按钮文案 */
confirmText?: string
/** 取消按钮文案 */
cancelText?: string
}
/** 获取当前会话 */
export function getActiveChat(): Promise<im.IChat | undefined>
/** 调起通讯录选择器选择用户 */
export function selectUsers(options?: ISelectUserOptions): Promise<im.IUser[]>
export interface ISidebarTab {
id: string
viewId: string
name: string
icon: string
activeIcon: string
order: number
postCommand?: string
}
export interface ISidebarTabProvider {
expandedTabCount?: number
getTabs?(tabs: ISidebarTab[]): ISidebarTab[]
}
export interface ITabbarAction {
// 唯一标识
id: string
// 图标
icon: string
// 按钮名称(tooltip提示文本)
label?: string
// 点击触发的命令
command: string
}
export interface ITabbarMenuItemOptions {
// 唯一标识
id: string
// 图标
icon: string
// 按钮名称
label: string
// 渲染条件
when?: string
// 点击触发的命令
command: string
}
export interface IThemeConf {
// 主题背景色
'theme.bg': string
// 主题背景图
'theme.bg.image'?: string
// 侧边栏&顶栏卡片描边颜色
'theme.border.color'?: string
// 设置面板选色预览颜色值
'theme.thumbnail.color'?: string
// 设置面板选色预览勾选图标颜色值
'theme.thumbnail.icon.color': string
// 侧边栏图标颜色
'sidebar.icon.color': string
// 侧边栏图标选中状态颜色
'sidebar.icon.color.active': string
// 侧边栏导航文字颜色
'sidebar.title.color': string
// 侧边栏企业账号文字颜色
'sidebar.account.color': string
// 侧边栏企业账号hover状态文字颜色
'sidebar.account.color.hover': string
// 侧边栏企业账号选中状态文字颜色
'sidebar.account.color.active': string
// 侧边栏企业账号背景色
'sidebar.account.bg': string
// 侧边栏企业账号hover状态背景色
'sidebar.account.bg.hover': string
// 侧边栏企业账号选中状态背景色
'sidebar.account.bg.active': string
// 侧边栏导航菜单hover状态背景色
'sidebar.menu.bg.hover': string
// 侧边栏导航菜单选中状态背景色
'sidebar.menu.bg.active': string
// 侧边栏导航菜单图标&文字透明度
'sidebar.menu.opacity': string
// 侧边栏导航菜单选中状态图标&文字透明度
'sidebar.menu.opacity.active': string
// 顶部导航栏tab背景色
'tabbar.tab.bg': string
// 顶部导航栏tab hover状态背景色
'tabbar.tab.bg.hover': string
// 顶部导航栏tab选中状态背景色
'tabbar.tab.bg.active': string
// 顶部导航栏分割线颜色
'tabbar.divider.color': string
// 顶部导航栏tab选中状态投影颜色
'tabbar.tab.shadow.color.active'?: string
// 顶部导航栏tab闪烁动画投影颜色(预留)
'tabbar.tab.shadow.color.animate'?: string
// 顶部导航栏tab标题文字颜色
'tabbar.tab.title.color': string
// 顶部导航栏tab选中状态标题文字颜色
'tabbar.tab.title.color.active': string
// 顶部导航栏tab默认图标颜色
'tabbar.tab.icon.color': string
// 顶部导航栏tab关闭按钮颜色
'tabbar.tab.button.color': string
// 顶部导航栏tab选中状态关闭按钮颜色
'tabbar.tab.button.color.active': string
// 顶部导航栏tab关闭按钮hover背景色
'tabbar.tab.button.bg.hover': string
// 顶部导航栏tab选中状态关闭按钮hover背景色
'tabbar.tab.button.bg.hover.active': string
}
export interface IThemeOptions {
// 主题色唯一标识
id: string
// 主题色名称
label: string
// 主题色配置
conf: IThemeConf
}
export interface IMainViewDisplayer extends IViewDisplayer {
id: string
renderOptions?: {
keepAlive?: boolean
keepIframeState?: boolean
}
}
export interface IMenuItem {
id: string // 菜单项id
icon?: string // 菜单图标
label: string // 菜单项名
command?: string // commandId
viewletId: string // 视图单元 id
when?: string // 控制菜单项的显隐, 不传时默认显示该菜单项
order?: number // 排序
children?: Pick<
IMenuItem,
'id' | 'icon' | 'label' | 'command' | 'when' | 'order' | 'children'
>[]
}
// 消息右键菜单command参数
export interface IMsgContextmenuCommandParams {
msgid: number
chatid: number
}
// 自定义消息构造函数
export interface IMessageDisplayer {
mount(root: HTMLElement, context: IMessageContext): void
update?(updateContextKey: string, newVal: unknown, oldVal: unknown): void
dispose(): void
}
// 自定义消息标准化参数
export interface IMessageContext {
message: im.IMessage
}
export interface ICssResource {
id: string
cssContent: string
}
export interface IMessageDisplayerConfiguration {
// 自定义消息的类型,全局唯一
customizeType: string
// 自定义消息
MessageDisplayer: new () => IMessageDisplayer
// 自定义消息关联的样式,通过registerCssResource注册的css的id
dependencyCssResourceIds: string[]
options?: {
// 是否可以多选
isSelectable?: boolean
// 是否可以回复
isReplyable?: boolean
// 是否可以转发
isForwardable?: boolean
// 是否可以收藏
isCollectable?: boolean
// 是否可以表情快捷回复
isEmojiReplyEnabled?: boolean
// 是否可以快捷回复
isQuickReplyEnabled?: boolean
}
}
export interface IDialogConfiguration {
render(root: HTMLElement): void
onDidClose?(): void
dependencyCssResourceIds?: string[] // 自定义弹框关联的样式,通过registerCssResource注册的css的id
isHeaderVisible?: boolean // 是否隐藏 Dialog 的头部
isFooterVisible?: boolean // 是否隐藏 Dialog 的脚部
isCloseIconVisible?: boolean // 是否显示关闭按钮
isMaskVisible?: boolean // 是否展示遮罩
isMaskClosable?: boolean // 点击蒙层是否允许关闭
title?: string // Dialog 的标题
width?: string // Dialog 的宽度
okText?: string // 脚部确认按钮的文案
cancelText?: string // 脚部取消按钮的文案
}
// 拉起通讯录选择器创建群聊
export function createGroupChat(): Promise<void>
// 注册侧边栏 tab
export function registerSidebarTab(tab: ISidebarTab): void
// 注册侧边栏 tab provider
export function registerSidebarTabProvider(
provider: ISidebarTabProvider
): void
export interface IViewDisplayer<T extends object = object> {
render?(
node: HTMLElement,
props: T,
onDidChangeProps: Event<T>
): IDisposable
getWebviewUrl?(): string
}
// 注册主视图-自定义视图
export function registerMainViewDisplayer(
displayer: IMainViewDisplayer
): void
// 注册顶栏自定义图标
export function registerTabbarAction(options: ITabbarAction): void
// 注册顶栏下拉菜单子项
export function registerTabbarMenuItem(
options: ITabbarMenuItemOptions
): void
// 注册主题色
export function registerTheme(options: IThemeOptions): void
export function registerMenuItem(menuItem: IMenuItem): void
export function registerMessageDisplayer(
configuration: IMessageDisplayerConfiguration
): void
export function registerCssResource(cssResource: ICssResource): void
/** toast 提示 */
export function showToast(options: {
message: string
level?: 'info' | 'success' | 'warning' | 'error'
duration?: number
}): void
/** 更新侧边栏tab角标数 */
export function updateSidebarTabBadgeCount(
tabId: string,
count: number
): void
/** confirm 弹窗 */
export function showConfirmDialog(options: {
message: string
title: string
closeOnClickModal?: boolean
showCancelButton?: boolean
showClose?: boolean
}): Promise<void>
type closeDialog = () => void
export function showDialog(options?: IDialogConfiguration): closeDialog
}
export namespace im {
interface IMessage<T = any> {
cid: string
msgid: number
msgType: number
chatid: number
sender: number
content: T
}
// 文本消息的content
export interface ITextContent {
type: string
text: string
}
export interface IUser {
/** 用户头像 */
avatar: string
/** 用户名称 */
name: string
/** 用户woa id */
id: number
/** 用户第三方id */
thirdId?: number | string
}
export interface IChat {
/** 会话id */
id: number
/** 会话名称 */
name: string
/** 会话类型: 1-单聊,2-群聊,3-机器人会话 */
type: 1 | 2 | 3
}
/** 消息强提醒 */
export interface INotice {
/**
* 强提醒类型
* kim-mention: @人、@所有人
*/
noticeType: string
/** 全员设置 */
isAll: boolean
/** 接收强提醒用户标记 */
uids: string[]
}
// 消息离线推送配置
export interface IPushConfig {
/**
* 离线推送显示标题
* 如果是内置消息类型,则无需填,默认填充
* 如果是自定义消息类型,必填,不然无法离线推送
*/
title?: string
/**
* 离线推送显示内容
* 如果是内置消息类型,则无需填,默认填充
* 如果是自定义消息类型,必填,不然无法离线推送
*/
content?: string
/**
* 离线推送操作类型
* 0: 默认值,群聊所有人离线推送
* 1: 所有人不离线推送
*/
pushType?: number
/**
* 离线推送权限级别
* 0: 默认值
* 1: 忽视会话免打扰
*/
pushLevel?: number
}
export interface IAppCustomMsgContent {
content: string
customizeType: string
msgDesc: string
}
export interface ISendMessageParams {
chatid: number
sendProps: {
content: IAppCustomMsgContent
}
sendOptions?: {
// 离线推送配置
pushConfig?: IPushConfig
// 消息强提醒
notices?: INotice[]
// 不记录未读数
unmarkUnread?: boolean
}
}
// 创建单聊会话
export function createSingleChat(params: {
user: {
id: number | string
name: string
}
isThirdUserId?: boolean
}): Promise<number | void>
// 创建群聊会话
export function createGroupChat(params: {
users: {
id: number | string
name: string
}[]
isThirdUserId?: boolean
}): Promise<number | void>
// 获取消息数据
export function getMessage(params: { chatid: number; msgid: number }): Promise<IMessage>
// 发送消息
export function sendMessage(params: ISendMessageParams): Promise<void>
/**
* 根据用户id获取用户信息
* @param userid 用户id
* @param isThirdId 用户id是否为第三方id
*/
export function getUserById(userid: number | string, isThirdId?: boolean): Promise<IUser | undefined>
}
export namespace search {
export type ISearchData<Ext = void> = MapOptional<{
// 搜索结果图标
avatar?: string
// 搜索结果主标题,用<em></em>包裹高亮内容
title: string
// 搜索结果副标题,不支持高亮
subtitle?: string
// 搜索结果时间,以毫秒为单位,暂未用到
time?: number
// 业务存储其他自定义数据,自定义渲染组件时可使用
ext: Ext
}>
export interface ISearchResult<
Ext = void,
Context extends object | undefined = object | undefined
> {
// 当前分页搜索数据
data: ISearchData<Ext>[]
// 搜索结果总数(非当前分页结果总数),暂未用到
total: number
// 是否还有更多数据
hasNext: boolean
// 搜索状态上下文,将上一次搜索返回的上下文传递给下一次搜索
context?: Context
}
export interface ISearchTag {
id: string | number
label: string
mode?:
| 'inline' /** (默认)可展开显示完整结果 */
| 'inline-preview' /** 在综合分类显示预览结果,点击查看更多后跳转到独立分类搜索(id需为已注册的分类) */
| 'flatten' /** 平铺展开,适用于数据量在10条以下的场景 */
}
export type ISearchMode =
| 'integrated' /** 综合搜索 */
| 'ex-integrated' /** 独立窗口综合搜索 */
| 'separated' /** 独立分类搜索 */
| 'chat' /** 会话内搜索 */
export interface ISearchItemProps {
item: ISearchData
index: number
}
export interface ISearchViewProps {
keyword: string
}
export interface ISearchResultComponent {
integrated?: ui.IViewDisplayer<ISearchItemProps>
separated?:
| ui.IViewDisplayer<ISearchItemProps>
| ui.IViewDisplayer<ISearchViewProps>
}
export interface IUserFilterOptions {
chatid?: number
}
export interface IUserFilterResult {
users: im.IUser[]
}
export interface ITimeRangeFilterOptions {
start?: number | 'now'
end?: number | 'now'
}
export interface ITimeRangeFIlterResult {
start?: number
end?: number
}
export interface ISelectItem {
id: string | number
label: string
}
export interface ISelectFilterOptions {
selects: ISelectItem[]
multiple?: boolean
}
export interface ISelectFilterResult {
selected: Array<string | number>
}
export interface IFilterTypes {
'user-filter': (_?: IUserFilterOptions) => IUserFilterResult
'select-filter': (_: ISelectFilterOptions) => ISelectFilterResult
'time-range-filter': (
_?: ITimeRangeFilterOptions
) => ITimeRangeFIlterResult
}
export type ISearchFilter<
K extends keyof IFilterTypes = keyof IFilterTypes
> = MapOptional<{
id: string
label: string
type: K
options: Parameters<IFilterTypes[K]>[0]
defaultValue?: ReturnType<IFilterTypes[K]>
shareAs?: string
}>
export interface ISearchCategoryOptions<
Ext = void,
Context extends object | undefined = object | undefined
> {
// 自定义分类唯一id
category: string
// 分类图标
icon?: string
// 埋点上报名称,仅对内部插件开放
reportId?: string
// 自定义分类名称
label: string | Partial<Record<ISearchMode, string>>
// 搜索子分类
tags?: ISearchTag[]
// 搜索分类顺序
order?: number | Partial<Record<ISearchMode, number>>
// 搜索结果列表项自定义视图组件
component?: ui.IViewDisplayer<ISearchItemProps> | ISearchResultComponent
// 综合分类搜索模式
integrateMode?:
| 'inline' /** 在综合分类显示完整结果(仅主窗口综合搜索模式支持,独立窗口模式该值降级为inline-preview) */
| 'inline-preview' /** (默认)在综合分类显示预览结果,点击查看更多后跳转到独立分类搜索 */
| 'flatten' /** 平铺展开,适用于数据量在10条以下的场景 */
| 'collapsed' /** 收起到列表末尾「更多」分类,显示为「在 xx分类 中搜索“关键字”」 */
| 'off' /** 不在综合搜索展示 */
// 独立分类搜索模式
separateMode?:
| 'default' /** (默认)标准列表滚动视图,component 选项渲染为列表项 */
| 'custom' /** 整个页面自定义,component 选项渲染为页面根结点 */
// 搜索结果筛选器
filters?: Array<ISearchFilter<keyof IFilterTypes> | string>
// 每页最小数据量,拉取到数据小于该值时会自动重复拉取
minPageSize?: number
// 每页最大数据量,作为传递count值的上限(默认值:100)
maxPageSize?: number
// 自定义视图最小尺寸,用于计算首屏拉取数量
minViewSize?: Partial<Record<'width' | 'height', number>>
// 是否启用搜索分类
when?: (mode: ISearchMode) => boolean
// 静态数据提供器,追加到列表末尾
searchStatic?: (
// 搜索关键字
keyword: string,
// tags 中定义的 id,未定义时为 undefined
tag: string | number | undefined
) => ISearchData<Ext>[]
// 自定义分类搜索接口
search: (
// 搜索关键字
keyword: string,
// tags 中定义的 id,未定义或综合搜索模式为 undefined
tag: string | number | undefined,
// 搜索数量
count: number,
// 搜索偏移,即当前分页起始数据索引
offset: number,
// 取消回调,在搜索取消时调用,可用于取消 HTTP 请求
onCancel: (callback: () => void) => void,
// 搜索状态上下文,将上一次搜索返回的上下文传递给下一次搜索
context?: Context,
// 搜索结果筛选器
filters?: Record<string, ReturnType<ValueOf<IFilterTypes>>>
) => Promise<ISearchResult<Ext, Context>>
// 自定义分类搜索结果项点击事件
onDidClickItem: (data: ISearchData<Ext>, index: number) => void
}
export function registerCategory<
Ext = void,
Context extends object | undefined = object | undefined
>(options: ISearchCategoryOptions<Ext, Context>): void
}
export namespace client {
export interface IOpenUrlOptions {
/** 标签页图标,默认为网页图标 */
icon?: string
/** 标签页标题,默认为网页标题 */
title?: string
/** 页面加载中文案(仅侧边栏面板可用) */
loadingText?: string
}
export interface IDisplay {
/** 显示器id */
id: number
/** 显示器顺时针方向旋转角度,可能是0/90/180/270 */
rotation: number
/** 显示器缩放比 */
scaleFactor: number
/** 显示器边界信息 */
bounds: ui.IRectangle
/** 显示器工作区域边界信息(如:在windows系统下除去任务栏的区域) */
workArea: ui.IRectangle
}
export interface BeforeShutdownEvent {
// 通过veto返回true时,会阻止程序退出
veto(value: boolean | Promise<boolean>, id: string): void
}
export interface WillShutdownEvent {
// join添加的promise执行完,程序才会退出,可用于在程序退出前释放资源
join(promise: Promise<void>, id: string): void
}
// 调起浏览器或端内tab打开链接
export function openUrl(url: string, target?: 'browser' | 'maintab' | 'internal-browser' | 'aside-panel', options?: IOpenUrlOptions): Promise<void>
// 打开会话
export function openChat(chatId: number): Promise<void>
// 打开侧边tab
export function openSidebarTab(viewId: string, props?: Record<string, string>): void
// 注册第三方cmd msg推送回调
export function onDidThirdCmdMsgPush(callback: (data: string) => void): IDisposable
/** 注册应用退出前的回调
* @deprecated
*/
export function onBeforeAppQuit(callback: () => void): IDisposable
// 在应用程序关闭之前触发,允许监听器否决关闭,以阻止关闭发生。
export const onBeforeShutdown: Event<BeforeShutdownEvent>
// 当没有客户端阻止应用程序关闭时触发,程序必将退出,允许通过join()将此事件与异步操作进行关联,例如在程序退出前释放资源。
export const onWillShutdown: Event<WillShutdownEvent>
/**
* 获取显示器信息
* @param target 目标显示器
* primary - 主显示器
* mainwindow - 主窗口所在显示器
* cursor - 鼠标所在显示器
*/
export function getDisplayInfo(target: 'primary' | 'mainwindow' | 'cursor'): Promise<IDisplay>
// 注册deeplink
export function registerDeeplink(
url: string,
handler: (query: any) => void
): void
// 注册退出登录前事件
export function onBeforeAccountLogout(
callback: (evt: { join(promise: Promise<any>): void }) => void
): IDisposable
// 注册账号登录成功事件(向下兼容历史版本)
export function onAccountLoginSuccess(
callback: () => void
): IDisposable
// 注册账号登录成功事件(4.13版本生效)
export function onDidLoginSuccess(callback: () => void): IDisposable
// 注册 ws 已连接事件(向下兼容历史版本)
export function onWsConnected(callback: () => void): IDisposable
// 注册 ws 已连接事件(4.13版本生效)
export function onDidWsConnected(callback: () => void): IDisposable
}
export namespace commands {
export function registerCommand(id: string, callback: (...args: any[]) => any, thisArg?: any): IDisposable
export function executeCommand<T>(id: string, ...args: any[]): Promise<T>
}
export namespace viewer {
export interface IViewerOptions {
/** 窗口页面链接 */
url: string
/** 窗口标题 */
title?: string
/** 窗口宽度(默认值:主窗口默认宽度) */
width?: number
/** 窗口高度(默认值:主窗口默认高度) */
height?: number
/** 最小窗口宽度(默认值:主窗口最小宽度) */
minWidth?: number
/** 最小窗口高度(默认值:主窗口最小高度) */
minHeight?: number
/** 最大窗口宽度 */
maxWidth?: number
/** 最大窗口高度 */
maxHeight?: number
/** 窗口水平位置 */
x?: number
/** 窗口垂直位置 */
y?: number
/** 是否居中显示(默认值:true) */
center?: boolean
/** 是否置顶窗口层级(默认值:false) */
alwaysOnTop?: boolean
/** 是否隐藏任务栏窗口(默认值:false) */
skipTaskbar?: boolean
/** 窗口是否可获得焦点(默认值:true) */
focusable?: boolean
/** 是否允许拖拽窗口大小(默认值:true) */
resizable?: boolean
/** 是否允许窗口最小化(默认值:true) */
minimizable?: boolean
/** 是否允许窗口最大化(默认值:true) */
maximizable?: boolean
/** 是否允许窗口全屏(默认值:true) */
fullscreenable?: boolean
/**
* 窗口标题栏风格
* default - 默认标准风格
* hidden - 隐藏窗口标题栏
*/
titleBarStyle?: 'default' | 'hidden'
/** Mac系统交通灯位置 */
trafficLightPosition?: ui.IPoint
}
/**
* 创建自定义窗口
* @param id 窗口唯一标识,若id已存在将不会重复创建窗口
* @param options 窗口配置
*/
export function create(id: string, options: IViewerOptions): Promise<void>
/** 显示自定义窗口
* @param id 窗口唯一标识
* @param inactive 是否只显示窗口而不聚焦窗口
*/
export function show(id: string, inactive?: boolean): Promise<void>
/** 关闭自定义窗口
* @param id 窗口唯一标识
* @param force 是否强制关闭窗口(忽略beforeunload事件)
*/
export function close(id: string, force?: boolean): Promise<void>
/** 最小化窗口 */
export function minimize(id: string): Promise<void>
/** 获取窗口最小化状态 */
export function isMinimized(id: string): Promise<boolean>
/** 窗口最小化事件 */
export function onDidMinimize(id: string, listener: IEventListener<void>): IDisposable
/** 最大化窗口 */
export function maximize(id: string): Promise<void>
/** 窗口最大化事件 */
export function onDidMaximize(id: string, listener: IEventListener<void>): IDisposable
/** 取消最大化窗口 */
export function unmaximize(id: string): Promise<void>
/** 窗口取消最大化事件 */
export function onDidUnmaximize(id: string, listener: IEventListener<void>): IDisposable
/** 获取窗口最大化状态 */
export function isMaximized(id: string): Promise<boolean>
/** 设置窗口全屏状态 */
export function setFullScreen(id: string, flag: boolean): Promise<void>
/** 获取窗口全屏状态 */
export function isFullScreen(id: string): Promise<boolean>
/** 窗口进入全屏事件 */
export function onDidEnterFullScreen(id: string, listener: IEventListener<void>): IDisposable
/** 窗口退出全屏事件 */
export function onDidLeaveFullScreen(id: string, listener: IEventListener<void>): IDisposable
/** 设置窗口置顶状态 */
export function setAlwaysOnTop(id: string, isAlwaysOnTop: boolean): Promise<void>
/** 获取窗口置顶状态 */
export function isAlwaysOnTop(id: string): Promise<boolean>
/** 窗口置顶状态变化事件 */
export function onDidAlwaysOnTopChange(id: string, listener: IEventListener<boolean>): IDisposable
/** 向自定义窗口页面发送消息 */
export function postMessage(id: string, message: unknown): Promise<void>
/** 接收来自自定义窗口页面的消息事件 */
export function onDidReceiveMessage<T = unknown>(id: string, listener: IEventListener<T>): IDisposable
/** 设置窗口标题 */
export function setTitle(id: string, title: string): Promise<void>
/** 获取窗口标题 */
export function getTitle(id: string): Promise<string>
}
export namespace extensions {
/** 等待某个web插件加载完成 */
export function awaitForExtensionLoaded(name: string): Promise<void>
}
}
declare module 'ksxz' {
export * from 'ksxz.web'
}ksxz.node.ts(node插件api)
declare module 'ksxz.node' {
export type IEventListener<T> = (data: T) => void
export type Event<T> = (listener: (data: T) => void) => { dispose(): void }
export type ValueOf<T extends object> = T[keyof T]
export type PickKeyByValue<T extends object, U> = ValueOf<{
[P in keyof T]: T[P] & U extends never ? never : P
}>
export type MapOptional<T extends object, K extends keyof T = PickKeyByValue<T, undefined>> = Pick<Partial<T>, K> & Omit<T, K>
export interface IExtensionContext {
extension: {
name: string
path: string
fsPath: string
}
}
export interface IDisposable {
dispose(): void
}
export namespace ui {
export interface IPoint {
x: number
y: number
}
export interface IRectangle {
x: number
y: number
width: number
height: number
}
export interface ISelectUserOptions {
/** 选择指定会话id内的成员 */
chatid?: number
/** 是否返回第三方用户id */
isThirdUserId?: boolean
/** 最大选中人数 */
maxCount?: number
/** 默认选中用户id */
selectedUserIds?: number[]
/** 是否多选 */
isMultiple?: boolean
/** 通讯录选择器标题 */
title?: string
/** 确定按钮文案 */
confirmText?: string
/** 取消按钮文案 */
cancelText?: string
}
/** 获取当前会话 */
export function getActiveChat(): Promise<im.IChat | undefined>
/** 调起通讯录选择器选择用户 */
export function selectUsers(options?: ISelectUserOptions): Promise<im.IUser[]>
}
export namespace im {
interface IMessage<T = any> {
cid: string
msgid: number
msgType: number
chatid: number
sender: number
content: T
}
// 文本消息的content
export interface ITextContent {
type: string
text: string
}
export interface IUser {
/** 用户头像 */
avatar: string
/** 用户名称 */
name: string
/** 用户woa id */
id: number
/** 用户第三方id */
thirdId?: number | string
}
export interface IChat {
/** 会话id */
id: number
/** 会话名称 */
name: string
/** 会话类型: 1-单聊,2-群聊,3-机器人会话 */
type: 1 | 2 | 3
}
/** 消息强提醒 */
export interface INotice {
/**
* 强提醒类型
* kim-mention: @人、@所有人
*/
noticeType: string
/** 全员设置 */
isAll: boolean
/** 接收强提醒用户标记 */
uids: string[]
}
// 消息离线推送配置
export interface IPushConfig {
/**
* 离线推送显示标题
* 如果是内置消息类型,则无需填,默认填充
* 如果是自定义消息类型,必填,不然无法离线推送
*/
title?: string
/**
* 离线推送显示内容
* 如果是内置消息类型,则无需填,默认填充
* 如果是自定义消息类型,必填,不然无法离线推送
*/
content?: string
/**
* 离线推送操作类型
* 0: 默认值,群聊所有人离线推送
* 1: 所有人不离线推送
*/
pushType?: number
/**
* 离线推送权限级别
* 0: 默认值
* 1: 忽视会话免打扰
*/
pushLevel?: number
}
export interface IAppCustomMsgContent {
content: string
customizeType: string
msgDesc: string
}
export interface ISendMessageParams {
chatid: number
sendProps: {
content: IAppCustomMsgContent
}
sendOptions?: {
// 离线推送配置
pushConfig?: IPushConfig
// 消息强提醒
notices?: INotice[]
// 不记录未读数
unmarkUnread?: boolean
}
}
// 创建单聊会话
export function createSingleChat(params: {
user: {
id: number | string
name: string
}
isThirdUserId?: boolean
}): Promise<number | void>
// 创建群聊会话
export function createGroupChat(params: {
users: {
id: number | string
name: string
}[]
isThirdUserId?: boolean
}): Promise<number | void>
// 获取消息数据
export function getMessage(params: { chatid: number; msgid: number }): Promise<IMessage>
// 发送消息
export function sendMessage(params: ISendMessageParams): Promise<void>
/**
* 根据用户id获取用户信息
* @param userid 用户id
* @param isThirdId 用户id是否为第三方id
*/
export function getUserById(userid: number | string, isThirdId?: boolean): Promise<IUser | undefined>
}
export namespace client {
export interface IOpenUrlOptions {
/** 标签页图标,默认为网页图标 */
icon?: string
/** 标签页标题,默认为网页标题 */
title?: string
/** 页面加载中文案(仅侧边栏面板可用) */
loadingText?: string
}
export interface IDisplay {
/** 显示器id */
id: number
/** 显示器顺时针方向旋转角度,可能是0/90/180/270 */
rotation: number
/** 显示器缩放比 */
scaleFactor: number
/** 显示器边界信息 */
bounds: ui.IRectangle
/** 显示器工作区域边界信息(如:在windows系统下除去任务栏的区域) */
workArea: ui.IRectangle
}
export interface BeforeShutdownEvent {
// 通过veto返回true时,会阻止程序退出
veto(value: boolean | Promise<boolean>, id: string): void
}
export interface WillShutdownEvent {
// join添加的promise执行完,程序才会退出,可用于在程序退出前释放资源
join(promise: Promise<void>, id: string): void
}
// 调起浏览器或端内tab打开链接
export function openUrl(url: string, target?: 'browser' | 'maintab' | 'internal-browser' | 'aside-panel', options?: IOpenUrlOptions): Promise<void>
// 打开会话
export function openChat(chatId: number): Promise<void>
// 打开侧边tab
export function openSidebarTab(viewId: string, props?: Record<string, string>): void
// 注册第三方cmd msg推送回调
export function onDidThirdCmdMsgPush(callback: (data: string) => void): IDisposable
/** 注册应用退出前的回调
* @deprecated
*/
export function onBeforeAppQuit(callback: () => void): IDisposable
// 在应用程序关闭之前触发,允许监听器否决关闭,以阻止关闭发生。
export const onBeforeShutdown: Event<BeforeShutdownEvent>
// 当没有客户端阻止应用程序关闭时触发,程序必将退出,允许通过join()将此事件与异步操作进行关联,例如在程序退出前释放资源。
export const onWillShutdown: Event<WillShutdownEvent>
/**
* 获取显示器信息
* @param target 目标显示器
* primary - 主显示器
* mainwindow - 主窗口所在显示器
* cursor - 鼠标所在显示器
*/
export function getDisplayInfo(target: 'primary' | 'mainwindow' | 'cursor'): Promise<IDisplay>
// 注册打开 url 前事件和拦截器
export function onBeforeOpenUrl(
callback: (
join: (
joiner: (data: { url: string }) => Promise<{
nextHandler: boolean
}>
) => void
) => void
): IDisposable
}
export namespace commands {
export function registerCommand(id: string, callback: (...args: any[]) => any, thisArg?: any): IDisposable
export function executeCommand<T>(id: string, ...args: any[]): Promise<T>
}
export namespace viewer {
export interface IViewerOptions {
/** 窗口页面链接 */
url: string
/** 窗口标题 */
title?: string
/** 窗口宽度(默认值:主窗口默认宽度) */
width?: number
/** 窗口高度(默认值:主窗口默认高度) */
height?: number
/** 最小窗口宽度(默认值:主窗口最小宽度) */
minWidth?: number
/** 最小窗口高度(默认值:主窗口最小高度) */
minHeight?: number
/** 最大窗口宽度 */
maxWidth?: number
/** 最大窗口高度 */
maxHeight?: number
/** 窗口水平位置 */
x?: number
/** 窗口垂直位置 */
y?: number
/** 是否居中显示(默认值:true) */
center?: boolean
/** 是否置顶窗口层级(默认值:false) */
alwaysOnTop?: boolean
/** 是否隐藏任务栏窗口(默认值:false) */
skipTaskbar?: boolean
/** 窗口是否可获得焦点(默认值:true) */
focusable?: boolean
/** 是否允许拖拽窗口大小(默认值:true) */
resizable?: boolean
/** 是否允许窗口最小化(默认值:true) */
minimizable?: boolean
/** 是否允许窗口最大化(默认值:true) */
maximizable?: boolean
/** 是否允许窗口全屏(默认值:true) */
fullscreenable?: boolean
/**
* 窗口标题栏风格
* default - 默认标准风格
* hidden - 隐藏窗口标题栏
*/
titleBarStyle?: 'default' | 'hidden'
/** Mac系统交通灯位置 */
trafficLightPosition?: ui.IPoint
}
/**
* 创建自定义窗口
* @param id 窗口唯一标识,若id已存在将不会重复创建窗口
* @param options 窗口配置
*/
export function create(id: string, options: IViewerOptions): Promise<void>
/** 显示自定义窗口
* @param id 窗口唯一标识
* @param inactive 是否只显示窗口而不聚焦窗口
*/
export function show(id: string, inactive?: boolean): Promise<void>
/** 关闭自定义窗口
* @param id 窗口唯一标识
* @param force 是否强制关闭窗口(忽略beforeunload事件)
*/
export function close(id: string, force?: boolean): Promise<void>
/** 最小化窗口 */
export function minimize(id: string): Promise<void>
/** 获取窗口最小化状态 */
export function isMinimized(id: string): Promise<boolean>
/** 窗口最小化事件 */
export function onDidMinimize(id: string, listener: IEventListener<void>): IDisposable
/** 最大化窗口 */
export function maximize(id: string): Promise<void>
/** 窗口最大化事件 */
export function onDidMaximize(id: string, listener: IEventListener<void>): IDisposable
/** 取消最大化窗口 */
export function unmaximize(id: string): Promise<void>
/** 窗口取消最大化事件 */
export function onDidUnmaximize(id: string, listener: IEventListener<void>): IDisposable
/** 获取窗口最大化状态 */
export function isMaximized(id: string): Promise<boolean>
/** 设置窗口全屏状态 */
export function setFullScreen(id: string, flag: boolean): Promise<void>
/** 获取窗口全屏状态 */
export function isFullScreen(id: string): Promise<boolean>
/** 窗口进入全屏事件 */
export function onDidEnterFullScreen(id: string, listener: IEventListener<void>): IDisposable
/** 窗口退出全屏事件 */
export function onDidLeaveFullScreen(id: string, listener: IEventListener<void>): IDisposable
/** 设置窗口置顶状态 */
export function setAlwaysOnTop(id: string, isAlwaysOnTop: boolean): Promise<void>
/** 获取窗口置顶状态 */
export function isAlwaysOnTop(id: string): Promise<boolean>
/** 窗口置顶状态变化事件 */
export function onDidAlwaysOnTopChange(id: string, listener: IEventListener<boolean>): IDisposable
/** 向自定义窗口页面发送消息 */
export function postMessage(id: string, message: unknown): Promise<void>
/** 接收来自自定义窗口页面的消息事件 */
export function onDidReceiveMessage<T = unknown>(id: string, listener: IEventListener<T>): IDisposable
/** 设置窗口标题 */
export function setTitle(id: string, title: string): Promise<void>
/** 获取窗口标题 */
export function getTitle(id: string): Promise<string>
}
}
declare module 'ksxz' {
export * from 'ksxz.node'
}ksxz.webview.d.ts(暴露到webview的插件api)
import ksxzWeb from 'ksxz.web'
declare global {
interface IKsxzWebviewApi {
ui: {
selectUsers: typeof ksxzWeb.ui.selectUsers
getActiveChat: typeof ksxzWeb.ui.getActiveChat
}
im: {
createSingleChat: typeof ksxzWeb.im.createSingleChat
createGroupChat: typeof ksxzWeb.im.createGroupChat
getUserById: typeof ksxzWeb.im.getUserById
getMessage: typeof ksxzWeb.im.getMessage
sendMessage: typeof ksxzWeb.im.sendMessage
}
client: {
openChat: typeof ksxzWeb.client.openChat
openUrl: typeof ksxzWeb.client.openUrl
openSidebarTab: typeof ksxzWeb.client.openSidebarTab
onDidThirdCmdMsgPush: typeof ksxzWeb.client.onDidThirdCmdMsgPush
getDisplayInfo: typeof ksxzWeb.client.getDisplayInfo
}
commands: {
executeCommand: typeof ksxzWeb.commands.executeCommand
}
viewer: typeof ksxz.viewer,
webpage: {
onDidReceiveMessage: ksxzWeb.Event<unknown>,
postMessage: (message: unknown) => Promise<void>
}
}
export function acquireKsxzApi(): IKsxzWebviewApi
}