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() 处理响应和错误。