npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@assetcloud/asset-sdk

v2.1.12

Published

资产云前端SDK

Downloads

18

Readme

资产云前端 SDK

Release npm

旧版文档

注意:

资产云前端SDK,利用postMessage进行跨iframe的安全数据请求。用于获取用户id等基础信息,或者请求平台前端进行某些操作。

SDK采用TypeScript开发,采用npm包引入可以自动获得完善的类型定义和代码自动补全。

快速开始

  1. 引入和初始化

    可以使用script标签或者npm包两种方式进行引入。

    • npm包安装(推荐)

    可以使用ES7 async/await 语法简化异步调用

    import SdkClient from "@assetcloud/asset-sdk";
    // 初始化时可设定超时时间(秒)
    const ac = new SdkClient(5);
    await ac.init();
    • script标签引入
    <!-- 将包内dist/sdk.umd.js复制到项目中合适的位置 -->
    <script src="path/to/sdk.umd.js"></script>
    <script>
    var ac = new ACSDK.SdkClient();
    ac.init().then(function() {
        console.log("SDK已初始化");
    });
    </script>

    注意:在构建工具(如Webpack)中直接使用script标签引入,需要以正确的顺序排列script标签,不然会找不到变量。如果需要在引用npm包的情况下使用script标签的全局变量,可以通过配置外部依赖的方式使用。

    // webpack.config.js(或vue.config.js)
    module.exports = {
        //...
        externals: {
            "@assetcloud/asset-sdk": "ACSDK"
        },
    };
    
    // OK
    import SdkClient from "@assetcloud/asset-sdk";
    const ac1 = new SdkClient();
    // OK, 全局变量依然可以使用
    const ac2 = new ACSDK.SdkClient();
  2. 监听和发送消息

    处理消息有两种方法,添加事件监听器和直接异步发送消息并等待返回结果。

    直接监听事件&直接发送消息

    支持接收来自平台主动推送的消息。 支持发送没有响应结果的消息。

    ac.addEventListener("GET_USER", e => {
      console.log(e.data.data.userId);
    });
    ac.send("GET_USER");
       

    发送消息并等待返回结果

    返回Promise,如果平台返回值的success字段为false,会自动触发reject。

    try {
      const res = await ac.sendAsync("GET_USER");
      const { userId } = res.data.data;
    } catch (error) {
      console.error(error.data.msg);
    }

    返回结果类型

    AssetCloudEvent<T extends AssetCloudMessage>

前端可用消息

| 功能 | 消息类型 AssetCloudMessage | 请求参数 | 返回结果中data的格式AssetCloudMessageMap[T] | | -- | -- | -- | :--: | | 获取用户 Id | GET_USER | 无 | { userId: string } | | 获取用户账号 | GET_USER_PHONE | 无 | { phone: string } | | 获取当前用户所属集团列表 | GET_GROUP | 无 | { groupIds: object[] } | | 在浏览器打开新的标签页 | OPEN_TAB | 需要打开的url,如:"http://www.baidu.com" | — | | 跳转到平台首页 | GO_HOME | 无 | — | | 跳转到平台待办 | GO_TODO | 无 | — | | 将当前页面全屏(整个屏幕全屏) | OPEN_FULLSCREEN | 无 | — | | 获取当前应用入口菜单 | GET_MENU | 无 | object |