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

yk-chat-public

v1.0.12

Published

chat公共服务

Downloads

743

Readme

API 客户端函数

此模块提供用于处理登录请求和通过 token 获取用户角色的函数,使用 axios 进行 HTTP 请求。

安装

首先安装 axios 包:

npm install axios

使用

在项目中引入此模块:

import apiClient from './index.js';

函数说明

1. IpLogin(baseUrl)

通过 IP 地址进行登录。

参数:

  • baseUrl (字符串): API 的基础 URL。

返回:

  • 一个 Promise,成功时返回登录数据,失败时返回错误。

示例:

apiClient.IpLogin('https://api.example.com/') .then(data => console.log(data)) .catch(error => console.error(error));

2. OrgLogin(baseUrl, data)

使用机构账号进行登录。

参数:

  • baseUrl (字符串): API 的基础 URL。
  • data (对象): 包含以下属性的对象:
    • username (字符串): 机构账号的用户名。
    • password (字符串): 机构账号的密码。

返回:

  • 一个 Promise,成功时返回登录数据,失败时返回错误。

示例:

const loginData = { username: 'orgUser', password: 'orgPassword' }; apiClient.OrgLogin('https://api.example.com/', loginData) .then(data => console.log(data)) .catch(error => console.error(error));

3. PersonLogin(baseUrl, data)

使用个人账号进行登录。

参数:

  • baseUrl (字符串): API 的基础 URL。
  • data (对象): 包含以下属性:
    • username (字符串): 个人账号的用户名。
    • password (字符串): 个人账号的密码。

返回:

  • 一个 Promise,成功时返回登录数据,失败时返回错误。

示例:

const loginData = { username: 'personUser', password: 'personPassword' }; apiClient.PersonLogin('https://api.example.com/', loginData) .then(data => console.log(data)) .catch(error => console.error(error));

4. GetRole(baseUrl, token)

通过 token 获取用户角色。

参数:

  • baseUrl (字符串): API 的基础 URL。
  • token (字符串): 用于身份验证的 token。

返回:

  • 一个 Promise,成功时返回角色权限

示例:

const token = 'yourAuthToken'; apiClient.GetRole('https://api.example.com/', token) .then(roleData => console.log(roleData)) .catch(error => console.error(error));

5. ForgetPassword(baseUrl, data)

忘记密码功能,通过提供邮箱、验证码和新密码来重置密码。

参数:

  • baseUrl (字符串): API 的基础 URL。
  • data (对象): 包含以下属性:
    • email (字符串): 用户的邮箱地址。
    • code (字符串): 通过邮箱接收的验证码。
    • password (字符串): 用户的新密码。

返回:

  • 一个 Promise,成功时返回重置密码的响应,失败时返回错误。

示例:

const resetData = { email: '[email protected]', code: '123456', password: 'newPassword' }; apiClient.ForgetPassword('https://api.example.com/', resetData) .then(data => console.log(data)) .catch(error => console.error(error));

6. SendEmailCode(baseUrl, data)

找回密码时发送邮箱验证码。

参数:

  • baseUrl (字符串): API 的基础 URL。
  • data (对象): 包含以下属性:
    • email (字符串): 用户的邮箱地址。

返回:

  • 一个 Promise,成功时返回验证码发送的响应,失败时返回错误。

示例:

const emailData = { email: '[email protected]' }; apiClient.SendEmailCode('https://api.example.com/', emailData) .then(data => console.log(data)) .catch(error => console.error(error));

7. getNavListApi(baseUrl, data)

获取导航列表。

参数:

  • baseUrl (字符串): API 的基础 URL。
  • data (对象): 导航列表的查询参数。

返回:

  • 一个 Promise,成功时返回导航列表数据,失败时返回错误。

示例:

const queryData = { type: 'product' }; apiClient.getNavListApi('https://api.example.com/', queryData) .then(data => console.log(data)) .catch(error => console.error(error));

错误处理

所有函数都返回 Promise,你可以通过 .then() 和 .catch() 处理响应和错误。