WebCAD-Lib-TS API 文档 - v1.0.0
    Preparing search index...

    Interface MainViewConfig

    主视图配置接口

    interface MainViewConfig {
        appname?: string;
        version?: string;
        wasmServiceUrl?: string;
        serviceUrl?: string;
        workspace?: string;
        accessToken?: string;
        accessKey?: string;
        fonts?: {
            path: string;
            name?: string;
            kind?: "ttf" | "woff" | "otf" | "shx";
        }[];
        closeDocOnOpen?: boolean;
        plugins?: PluginConfig[];
        pluginMarketUrl?: string;
        docUrl?: string;
        sidebarStyle?: "left"
        | "right"
        | "none"
        | "both";
        viewMode?: "full" | "viewer";
        showMenuBar?: boolean;
        showToolBar?: boolean;
        showDocBar?: boolean;
        showCoordsBar?: boolean;
        showCommandLine?: boolean;
        showBottomBar?: boolean;
        enableContextMenu?: boolean;
        showGrips?: boolean;
        showUcsIcon?: boolean;
        showAxis?: boolean;
        backgroundAlpha?: number;
        showCrosshair?: boolean;
        disablePointerEvents?: boolean;
        themeMode?: number;
        autoActivatePropertyPanel?: boolean;
        excludedPanelsFromAutoActivate?: string[];
        leftPanels?: string[];
        rightPanels?: string[];
        userInfo?: { userId: string; userName?: string; sessionId?: string };
        onAuthError?: (
            error: { errorCode: string; message: string; operation: string },
        ) => void;
    }
    Index

    Properties

    appname?: string
    version?: string
    wasmServiceUrl?: string
    serviceUrl?: string
    workspace?: string
    accessToken?: string
    accessKey?: string
    fonts?: { path: string; name?: string; kind?: "ttf" | "woff" | "otf" | "shx" }[]
    closeDocOnOpen?: boolean

    打开图纸时关闭当前文档(单文档打开模式)

    • true(默认): 打开新图纸时先关闭当前文档,节省内存
      • 新建文档不受影响,可以正常增加文档数量
    • false: 打开新图纸时保留当前文档(传统方式)
    plugins?: PluginConfig[]

    插件配置列表 - 启动时自动加载的插件

    plugins: [
    { url: '/plugins/find-replace/plugin.js' },
    { url: 'https://example.com/my-plugin.js', cssUrl: 'https://example.com/my-plugin.css' }
    ]
    pluginMarketUrl?: string

    服务端插件市场地址

    访问此地址可获取服务端插件市场的插件列表(JSON格式)。 自动加载的插件会在程序启动时自动下载并加载。

    pluginMarketUrl: "http://127.0.0.1:8082/plugins.json"
    
    docUrl?: string

    官方文档地址

    点击顶栏右侧的文档按钮时打开此地址。 默认为 https://www.vjmap.com

    docUrl: "https://www.vjmap.com/docs"
    
    sidebarStyle?: "left" | "right" | "none" | "both"

    侧边栏样式

    控制侧边栏的初始显示位置:

    • "both": 左右两侧都显示
    • "left": 只显示左侧
    • "right": 只显示右侧(默认)
    • "none": 不显示侧边栏
    sidebarStyle: "none" // 初始不显示侧边栏
    
    viewMode?: "full" | "viewer"

    视图模式

    控制 UI 组件的显示:

    • "full": 完整模式,显示所有 UI 组件(默认)
    • "viewer": 查看模式,只显示绘图区域,隐藏菜单、工具栏、命令行等

    viewer 模式适用于只需要查看和选择实体的场景,可通过 SDK 获取选中实体信息。

    viewMode: "viewer" // 只显示绘图区域
    
    showMenuBar?: boolean

    是否显示菜单栏(细粒度控制) 默认 true。设为 false 时隐藏菜单栏。

    showToolBar?: boolean

    是否显示工具栏/Ribbon(细粒度控制) 默认 true。设为 false 时隐藏工具栏。

    showDocBar?: boolean

    是否显示文档栏(细粒度控制) 默认 true。设为 false 时隐藏文档标签栏。

    showCoordsBar?: boolean

    是否显示坐标栏(细粒度控制) 默认 true。设为 false 时隐藏坐标栏。

    showCommandLine?: boolean

    是否显示命令行(细粒度控制) 默认 true。设为 false 时隐藏命令行。

    showBottomBar?: boolean

    是否显示底部状态栏(细粒度控制) 默认 true。设为 false 时隐藏底部状态栏。

    enableContextMenu?: boolean

    是否启用右键菜单(细粒度控制) 默认 true。设为 false 时禁用右键菜单。 viewer 模式下默认禁用。

    showGrips?: boolean

    是否显示选择夹点(细粒度控制) 默认 true。设为 false 时选择实体后不显示夹点。 viewer 模式下默认禁用(防止通过夹点拖动修改实体)。

    showUcsIcon?: boolean

    是否显示左下角的坐标轴图标(UCS 图标) 默认 true。设为 false 时隐藏左下角的坐标轴指示器。

    showAxis?: boolean

    是否显示图中绘制的坐标轴 默认 true。设为 false 时隐藏图中绘制的坐标轴。

    backgroundAlpha?: number

    背景透明度 (0-1) 默认 1(不透明)。设为 0 可实现透明背景,用于图层叠加场景。

    showCrosshair?: boolean

    是否显示十字光标 默认 true。设为 false 时隐藏十字光标和拾取框。

    disablePointerEvents?: boolean

    是否禁用鼠标事件(允许事件穿透) 默认 false。设为 true 时 canvas 不接收鼠标事件,用于图层叠加场景。

    themeMode?: number

    主题模式 0=深色(默认),1=浅色。影响实体默认颜色等。

    autoActivatePropertyPanel?: boolean

    选择实体时是否自动激活特性面板

    默认 true。设为 false 时,选择实体后不会自动切换到特性面板, 保持当前激活的面板不变。

    // 禁用自动激活特性面板
    const cadView = new MainView({
    autoActivatePropertyPanel: false
    });
    excludedPanelsFromAutoActivate?: string[]

    排除自动激活特性面板的面板名称列表

    当 autoActivatePropertyPanel 为 true 时,如果当前激活的面板在此列表中, 则选择实体时不会自动切换到特性面板。

    这允许在启用自动激活的同时,为特定面板(如 AI 面板)排除此行为。

    // AI 面板激活时不切换,其他面板激活时自动切换到特性面板
    const cadView = new MainView({
    autoActivatePropertyPanel: true, // 默认启用自动切换
    excludedPanelsFromAutoActivate: ["ai-assistant"] // AI 面板除外
    });
    leftPanels?: string[]

    左侧侧边栏面板列表

    指定哪些内置面板显示在左侧侧边栏。 可用的面板名称:

    • "props" - 特性面板
    • "blocks" - 块面板
    • "images" - 图像面板
    • "dsettings" - 捕捉设置面板
    • "commands" - 命令列表面板
    • "alias" - 命令别名面板

    默认:["props", "blocks", "images"]

    const cadView = new MainView({
    leftPanels: ["props", "dsettings"],
    rightPanels: ["blocks", "images", "commands", "alias"]
    });
    rightPanels?: string[]

    右侧侧边栏面板列表

    指定哪些内置面板显示在右侧侧边栏。 可用的面板名称同 leftPanels。

    默认:["dsettings", "commands", "alias"]

    userInfo?: { userId: string; userName?: string; sessionId?: string }

    业务系统用户信息(用于协同编辑中区分用户和后台权限回调)

    二次开发者通过此配置传入业务系统中的用户信息。 如果设置了 userId,则协同编辑中将使用此用户身份替代默认的机器指纹ID。 后端会将 userId 和 sessionId 传递给配置的权限回调接口进行鉴权。

    Type Declaration

    • userId: string

      用户唯一标识(必填,用于协同编辑的用户区分和权限回调)

    • OptionaluserName?: string

      用户显示名称(选填,为空时显示 userId,用于协同编辑中的作者显示)

    • OptionalsessionId?: string

      会话ID(选填,用于业务系统会话验证,传递给权限回调接口)

    const cadView = new MainView({
    serviceUrl: "http://127.0.0.1:27660/api/v1",
    userInfo: {
    userId: "user_12345",
    userName: "张三",
    sessionId: "sess_abc123"
    }
    });
    onAuthError?: (
        error: { errorCode: string; message: string; operation: string },
    ) => void

    权限错误回调(当后台配置的业务系统权限校验失败时触发)

    二次开发者可以在此回调中处理不同的错误场景:

    • errorCode 为 "session_expired" 时,可跳转到登录页
    • errorCode 为 "no_permission" 时,可提示用户无权限
    • 其他业务自定义错误码
    const cadView = new MainView({
    onAuthError: (error) => {
    if (error.errorCode === 'session_expired') {
    window.location.href = '/login';
    } else {
    alert(error.message);
    }
    }
    });