类型
ConnectOptions
初始化连接配置项
type ConnectOptions = {
appCode: string;
request?: RequestConfig;
socket?: SocketConfig;
};
appCode
: 应用id
【必传】request
:ajax
请求配置socket
:websocket
请求配置- 参考:SocketConfig
Core
tacos
初始化建立连接后异步生成的核心 SDK 实例对象
interface SDK {
context: Context;
sdkList: Array<TacosSDK>;
interceptor: <T extends keyof Interceptor>(type: T) => Interceptor[T];
createInstance: <M extends (...args: any) => any, P>(sdk: M, props?: P) => ReturnType<M>;
destroy: () => void;
}
RequestConfig
ajax 请求配置对象
interface RequestConfig extends AxiosRequestConfig {
interceptor?: {
request?: {
handle: InterceptorRequest;
error?: InterceptorError;
};
response?: {
handle: InterceptorResponse;
error?: InterceptorError;
};
};
}
type InterceptorError = (res: Error) => Error;
type InterceptorRequest = (config: AxiosRequestConfig) => AxiosRequestConfig;
type InterceptorResponse = (res: AxiosResponse) => AxiosResponse;
参考: AxiosRequestConfig 更多相关信息见Axios
SocketConfig
socket
通信配置对象
type SocketConfig = Partial<{
url: string;
protocols: string | string[];
pingTimeout: number;
pongTimeout: number;
reconnectTimeout: number;
pingMsg: any;
repeatLimit: null | number;
interceptor: {
request?: InterceptorRequest;
response?: InterceptorResponse;
};
}>;
SpaceMetaData
空间元数据
interface SpaceMetaData {
id: string;
name: string;
zhname: string;
driver: string;
parent?: string;
rules?: RuleMetaData[];
plans?: PlanMetaData[];
modes?: ModeMetaData[];
devices?: DeviceMetaData[];
metrics?: MetricsMetaData[];
layouts?: LayoutMetaData[];
}
id
: 空间id
name
: 空间名称zhname
: 空间中文名称driver
: 空间驱动名称parent
: 父级空间id
rules
: 规则元数据列表- 参考: RuleMetaData
plans
: 计划元数据列表- 参考: PlanMetaData
modes
: 模式元数据列表- 参考: ModeMetaData
devices
: 设备元数据列表- 参考: DeviceMetaData
metrics
: 点位元数据列表(暂不需求使用)layouts
: 布局元数据列表- 参考: LayoutMetaData
DeviceMetaData
设备元数据
interface DeviceMetaData {
id: string;
name: string;
zhname: string;
driver: string;
type: string;
attrs: Record<string, any>;
spaceId?: string;
category?: string;
}
id
: 设备id
name
: 设备名称zhname
: 设备中文名称driver
: 设备驱动名称type
: 设备类型attrs
: 设备属性spaceId
: 关联的空间id
category
: 类别
ModeMetaData
模式元数据
export interface ModeMetaData {
id: string;
type: string;
enable: number;
remark?: string;
zhname?: string;
commands?: string[];
}
id
: 模式id
type
: 模式类型enable
: 模式启用状态(启用-1;禁用-0)remark
: 备注zhname
: 模式中文名commands
: 模式指令列表
RuleMetaData
规则元数据
interface RuleMetaData {
id: string;
type: string;
enable: number;
remark?: string;
zhname?: string;
condition?: string;
commands?: string[];
}
id
: 规则id
type
: 规则类型enable
: 规则启用状态(启用-1;禁用-0)remark
: 备注zhname
: 规则中文名condition
: 规则条件commands
: 规则指令
PlanMetaData
计划元数据
interface PlanMetaData {
id: string;
type: string;
cron: string;
enable: number;
remark?: string;
zhname?: string;
condition?: string;
commands?: string[];
}
id
: 计划id
type
: 计划类型cron
: 计划cron
表达式enable
: 计划启用状态(启用-1;禁用-0)remark
: 备注zhname
: 计划中文名condition
: 计划逻辑条件commands
: 计划指令
LayoutMetaData
布局元数据
interface LayoutMetaData {
uri: string;
type: string;
}
uri
: 布局三维模型url
type
: 布局类型
ResourceOption
空间资源对象
interface ResourceOption<T extends RuleMetaData | ModeMetaData | PlanMetaData>{
enableList: Resource<T>;
disalbeList: Resource<T>;
}
Resource
资源对象
type Resource<T extends RuleMetaData | ModeMetaData | PlanMetaData> = T & {
actionGroups: CommandActionGroup[];
};
CommandActionGroup
动作分组
type CommandActionGroup = {
group: string; //动作分组key
actions: CommandAction[]; //动作列表
targetIds: string[]; //目标设备id列表
};
CommandAction
动作
type CommandAction = {
actionCode: string; // 动作编码(当动作是模式时,表示模式编码,当动作时指令时,表示指令编码)
actionName: string; // 指令操作中文名
actionSort: number; // 动作排序号
actionType: number; // 动作类型(模式-1;指令-2)
driver: string; // 设备驱动名(动作类型为指令时必填)
driverName: string; // 设备驱动中文名
param: any; // 指令入参
paramName: string; //指令入参中文名
};
Space
SpaceSDK 类型声明
type Space = TacosSDK & {
list: SpaceMetaData[];
readonly mode: Mode;
readonly rule: Rule;
readonly plan: Plan;
readonly device: Device;
readonly layout: Layout;
path: () => Promise<{ id: string; path: string }[]>;
fullPath: () => Promise<SpaceTree>;
parent: <S>() => Promise<TacosSDK & S>;
root: <S>() => Promise<TacosSDK & S>;
search: (tacosPath: string) => Promise<TacosSDK & S>;
addListener: (
callback: (device: SocketResponseBody) => void,
options?: Partial<SocketConfig>
) => void;
removeListener: () => void;
findById: (id: string) => Space | undefined;
getSpaceMode: (spaceId: string) => Promise<string>;
getSpacePathBy: (
id: string, list: SpaceNode[],
paths: string[]
) => string[];
getSpaceBy: <T>(
id:string,
list: SpaceNode[],
callbackFn: (node: SpaceNode) => T,
collects: T[]
) => T[];
xml: () => any[];
};
Device
DeviceSDK 类型声明
type Device = TacosSDK & {
list: DeviceMetaData[];
state: () => Promise<DeviceMetaData[]>;
findById: (id: string) => Device | undefined;
getDrivers: () => Promise<DeviceDriver[]>;
addListener: (
callback: (body: SocketResponseBody<keyof PayloadMap>) => void,
options?: Partial<SocketConfig>
) => () => void;
removeListener: () => void;
};
Mode
ModeSDK 类型声明
type Mode = {
toggle: (name: string) => Promise<boolean>;
create: (type: string) => ResourceMode;
update: (type: string, spaceId: string) => ResourceMode;
getResourceBy: (spaceId: string) => Promise<ResourceOption<ModeMetaData>>;
} & TacosSDK & {
enable: (name?: string | undefined) => Promise<boolean>;
disable: (name?: string | undefined) => Promise<boolean>;
remove: (name?: string | undefined) => Promise<boolean>;
};
Rule
RuleSDK 类型声明
type Rule = {
create: (type: string) => ResourceRule;
update: (type: string, spaceId: string) => ResourceRule;
getResourceBy: (spaceId: string) => Promise<ResourceOption<RuleMetaData>>;
} & TacosSDK & {
enable: (name?: string | undefined) => Promise<boolean>;
disable: (name?: string | undefined) => Promise<boolean>;
remove: (name?: string | undefined) => Promise<boolean>;
};
Plan
PlanSDK 类型声明
type Plan = {
create: (type: string) => ResourcePlan;
update: (type: string, spaceId: string) => ResourcePlan;
getResourceBy: (spaceId: string) => Promise<ResourceOption<PlanMetaData>>;
} & TacosSDK & {
enable: (name?: string | undefined) => Promise<boolean>;
disable: (name?: string | undefined) => Promise<boolean>;
remove: (name?: string | undefined) => Promise<boolean>;
};
ResourceBase
type ResourceBase = {
id: string;
type: string;
spaceId: string;
name: string;
remark: string;
sign: string;
isEnable: 0 | 1;
commandsWithGroup: SpecBase["commandsWithGroup"] = [];
operationMode: "new" | "override";
list: SpaceModuleProps["list"];
enable: (bool: boolean) => ResourceBase;
remarks: (remark: string) => ResourceBase;
zhname: (name: string) => ResourceBase;
actions: (commandsWithGroup) => ResourceBase;
};
id
: 资源id
type
: 资源类型/标识符spaceId
: 空间ID
remark
: 资源备注isEnable
: 是否启用(1 启用,0 关闭)commandsWithGroup
: 执行动作列表enable()
: 设置是否启用remarks()
: 设置备注zhname()
: 设置中文名称actions()
: 设置执行动作
ResourceRule
ResourceRule 实例类型
type ResourceRule = ResourceBase & {
condition: string;
conditions: (condition: string) => ResourceRule;
};
condition
: 执行条件conditions()
: 设置执行条件参考: ResourceBase
ResourcePlan
ResourcePlan 实例类型
type ResourcePlan = ResourceBase & {
cron: string;
time: (cron: string) => ResourcePlan;
};
cron
: 执行时间(cron
表达式)time()
: 设置执行时间参考: ResourceBase
ResourceMode
ResourceMode 实例类型
type ResourceMode = ResourceBase;
- 参考: ResourceBase
Layout
LayoutSDK 类型声明
type Layout = TacosSDK & {
get: (type?: string) => Array<LayoutMetaData & { spaceId: string }>
update: (type: string | undefined, url: string) => Promise<boolean>;
};
SpaceTree
空间目录树
interface SpaceTree {
id: string;
name: string;
zhname?: string;
driver?: string;
children: SpaceNode[];
}
id
: 命名空间 idname
: 命名空间名zhname
: 命名空间中文名driver
: 驱动children
: 空间节点列表- 参考: SpaceNode
SpaceNode
空间节点
interface SpaceNode {
id: string;
name: string;
zhname?: string;
driver: string;
uris: LayoutMetaData[] | [];
children?: SpaceNode[];
}
id
: 空间节点id
zhname
: 空间中文名称name
: 空间名称uris
: 布局元数据列表driver
: 空间驱动children
: 空间嵌套子节点列表
TacosSDK
SDK 基类,所有 SDK 子类都继承于此类
type TacosSDK = {
version: string;
interceptor: <T extends keyof Interceptor>(type: T) => Interceptor[T];
createInstance: <M extends (...args: any) => any, P>(
sdkCreator: M,
props?: P,
extension?: any
) => ReturnType<M>;
createRequest: <T extends (...args: any) => any>(
api: T,
config?: AxiosRequestConfig
) => ReturnType<T>;
createSocket: <T extends keyof CreateSocketReturn, K extends keyof PayloadMap>(
config: CreateSocketConfig[T],
callback: (res: SocketResponseBody<K, PayloadMap[k]>) => void,
type?: T
) => () => void;
$destroy: () => void;
};
New
DeviceDriver警告
此为新版 DeviceDriver
,点击查看旧版DeviceDriver
设备驱动的元数据
interface DeviceDriver {
/**
* 自定义物模型-功能
*/
customFunctions: any;
/**
* 设备描述
*/
description: string;
/**
* 设备驱动名称
*/
driver: string;
/**
* 唯一标识符
*/
identifier: string;
/**
* 设备驱动中文名称
*/
name: string;
/**
* 命名空间
*/
namespace: string;
/**
* 标准物模型-功能
*/
standardFunctions: Model[];
/**
* 设备产品模型版本
*/
version: string;
}
standardFunctions
: 标准物模型-功能- 参考:Model
Model
标准物模型-功能
interface Model {
commands: Command[];
events: Event[];
properties: Property[];
description: string;
identifier: string;
name: string;
namespace: string;
version: string;
}
commands
: 标准物模型-指令- 参考: Command
properties
: 标准物模型-属性- 参考:Property
events
: 标准物模型-事件- 参考:Event
name
: 设备模型中文名称version
: 设备模型版本号
Command
标准物模型-指令
interface Command {
description: string;
identifier: string;
inputs: Property[];
name: string;
outputs: Property[];
required: boolean;
}
Property
标准物模型-属性
interface Property {
identifier: string;
name: string;
accessMode?: AccessMode;
dataType: DataType;
required: boolean;
description: string;
multiple: boolean;
specification: Record<string, any>;
specifications: any;
}
identifier
: 模型属性唯一标识符dataType
: 标准物模型-属性-类型- 参考:DataType
accessMode
: 标准物模型-属性-可读写模式- 参考:AccessMode
required
: 是否必传multiple
: 是否枚举;(是:specifications有值;否:specification有值)specification
: 非枚举属性值具体描述specifications
: 可枚举属性多个枚举值的具体表述
Event
标准物模型-事件
interface Event {
identifier: string;
name: string;
description: string;
required: boolean;
outputs: Property[];
}
AccessMode
标准物模型-属性-可读写模式
const enum AccessMode {
/**
* 只读
*/
r = "r",
/**
* 读写
*/
rw = "rw"
}
DataType
标准物模型-属性-类型
const enum DataType {
/**
* 小数类型
*/
decimal = "decimal",
/**
* 整数类型
*/
int32 = "int32",
/**
* 长整型
*/
int64 = "int64",
/**
* 文本型
*/
text = "text",
/**
* 布尔类型
*/
bool = "bool",
/**
* 枚举类型
*/
enum = "enum",
/**
* 结构体类型
*/
struct = "struct",
/**
* 数组类型
*/
array = "array"
}
PayloadMap
消息推送数据集合
export type PayloadMap = {
[SocketResponseType.deviceProperty]: DevicePropertyPayload;
[SocketResponseType.spaceProperty]: SpacePropertyPayload;
[SocketResponseType.runtimeLog]: RuntimeLogPayload;
[SocketResponseType.spaceEvent]: SpaceEventPayload;
[SocketResponseType.sceneEvent]: SceneEventPayload;
};
SocketResponseType
消息推送响应消息类型
export const enum SocketResponseType {
spaceProperty = "space_property_notice", // 空间属性
deviceProperty = "device_property_notice", // 空间设备属性
runtimeLog = "runtime_log_notice", //空间日志
spaceEvent = "space_event_notice", //空间事件
sceneEvent = "scene_event_notice", //场景事件
heartbeat = "heartbeat" // 心跳检测"
}
DevicePropertyPayload
空间设备属性消息体
export type DevicePropertyPayload = {
deviceId: string;
property: Record<string, any>;
};
SpacePropertyPayload
空间属性消息体
export type SpacePropertyPayload = {
property: Record<string, any>;
};
RuntimeLogPayload
空间日志消息体
export type RuntimeLogPayload = {
/**
* 操作类型
*/
actionType: RuntimeLogActionType;
result: boolean; //操作结果
desc: string;
};
SpaceEventPayload
空间事件消息体
export type SpaceEventPayload = {
/**
* 事件编码
*/
identifier: string;
name: string;
/**
* 影响事件触发的因素
*/
outputs: Record<string, any>;
};
SceneEventPayload
场景事件消息体
export type SceneEventPayload = {
event: SceneEventDetail;
source: SceneEventSource;
};
SocketResponseBody
socket
响应消息实体对象
type SocketResponseBody<T extends keyof PayloadMap, D = PayloadMap[T]> = {
event:string; // 事件名
type?: string;
source?: SOCKET_SOURCE; // 消息来源 "space" or "scene"
messageType?: T; // 消息类型
data?: SocketResponsePayload<D>[]; // 数据内容
};
event
: 事件名("socket | message | ...")messageType
: 响应指令消息类型data
: 指令消息主体
SocketResponsePayload
export type SocketResponsePayload<D> = D & { spaceId: string };
SceneEventSource
场景事件source
export type SceneEventSource = {
/**
* 场景实例id
*/
instanceId: string;
/**
* 场景名称
*/
instanceName: string;
/**
* 场景的空间事件编码
*/
sourceEventCode: string;
/**
* 场景所绑定的空间id
*/
spaceId: string;
};
SceneEventDetail
场景事件 event
type SceneEventDetail = {
eventCode: SceneEventType; // 事件编码
eventName: string; // 事件名称
output?: { // 事件输出
currentNode?: { // 当前节点信息
nodeId: string; // 当前场景节点id
nodeName: string; // 当前场景节点名称
};
interaction?: Record<string, any>; // 前端交互内容
outParams?: Record<string, any>; // 输出内容(不固定,需要参考具体场景定义)
cmdResult?: { // 指令
device: {
devices: string[];
spaceId: string;
spacePath: string;
cmd: string;
productType: string; // 产品物模型编码
}[];
frontActions: {
[key: string]: any;
};
};
};
[key: string]: any;
};
弃用类型
已弃用
DeviceDriver设备驱动的元数据
interface DeviceDriver {
driverName: string;
driver: string;
commands: Array<Commands>;
properties: Array<Properties>;
}
已弃用
Commands驱动指令
interface Commands {
method: string;
desc: string;
inputs: Array<Properties>;
}
method
: 指令方法名desc
: 指令方法表述inputs
: 指令方法入参属性列表- 参考: Properties
已弃用
Properties驱动属性
interface Properties {
name: string;
desc: string;
dataType: string;
specifications: Array<{ name: string; value: string; desc: string }>;
// "[{\"name\":\"off\",\"value\":\"0\",\"desc\":\"关闭\"},{\"name\":\"on\",\"value\":\"3\",\"desc\":\"开启\"}]"
}
name
: 属性名称desc
: 属性描述dataType
: 属性数据类型specifications
: 属性数据类型补充表述