Webwidget V1.0——SDK使用文档

1. SDK使用文档

1.1 概述

本文档描述了如何使用 @newcore/client SDK 来初始化和获取应用上下文信息。

1.2 安装

npm install @newcore/client

1.3 导入

import { XHYClient } from '@newcore/client';

1.4 初始化

在使用SDK前,必须先进行异步初始化以获取client对象。

1.5 方法签名

XHYClient.init(): Promise<Client>

1.6 使用示例

async function initializeApp() {
  try {
    const client = await XHYClient.init();
    // 初始化成功后可以使用client对象
  } catch (error) {
    console.error('初始化失败:', error);
  }
}

1.7 获取上下文信息

1.7.1 获取位置信息

通过 client.context.location 可以访问应用的位置配置信息。

  • 使用示例

const location = client.context.location;

console.log(location) // TopBar SideBar NavBar

1.7.2 获取语言信息

通过 client.context.language 可以获取当前应用的语言设置。

  • 使用示例
    const currentLanguage = client.context.language;

console.log('当前语言:', currentLanguage); // zh-CN en-US

1.8 manifest.json 配置说明

{
  "name": "应用名称",
  "author": {
    "name": "作者名称"
  },
  "location": {
    "topBar": {
      "flexible": true,
      "size": {
        "width": "220px",
        "height": "100px"
      }
    }
  },
  "version": "应用版本",
  "frameworkVersion": "框架版本要求"
}
  • 字段说明
字段 类型 必填 说明
name string 应用名称
author object 应用作者信息
author.name string 作者名称
location object 应用显示位置配置
location.topBar object 顶部栏位置配置
location.navBar object 导航栏位置配置
location.sideBar object 侧边栏位置配置
flexible boolean 是否占据父容器
size object 容器尺寸配置
size.width string 容器宽度(如"220px")
size.height string 容器高度(如"100px")
version string 应用版本号
frameworkVersion string 所需框架最低版本

1.9 注意事项

  1. 使用SDK前必须调用 XHYClient.init() 方法进行初始化
  2. location配置中至少需要提供一个位置(topBar/navBar/sideBar)