# haigeek-axios

> 海极网网关请求插件

Latest version **1.1.4** (published 2025-02-08) · 0 weekly downloads

## Install

```sh
npm install haigeek-axios
pnpm add haigeek-axios
yarn add haigeek-axios
bun add haigeek-axios
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2025-02-08 |
| First published | 2023-06-16 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 92 KB |
| Known vulnerabilities | 0 (+24 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | qisibo916 |

## Links

- npm: https://www.npmjs.com/package/haigeek-axios
- npm.io page: https://npm.io/package/haigeek-axios

## Dependencies (9)

- [vue](https://npm.io/package/vue.md) ^2.6.11
- [axios](https://npm.io/package/axios.md) ^0.21.1
- [js-md5](https://npm.io/package/js-md5.md) ^0.7.3
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [core-js](https://npm.io/package/core-js.md) ^3.6.5
- [haier-ui](https://npm.io/package/haier-ui.md) ^1.2.7
- [element-ui](https://npm.io/package/element-ui.md) ^2.15.1
- [vue-cookies](https://npm.io/package/vue-cookies.md) ^1.7.4
- [haigeek-axios](https://npm.io/package/haigeek-axios.md) ^1.0.0

## Recent versions

- 1.1.4 (latest) — 2025-02-08
- 1.1.3 — 2024-10-12
- 1.1.2 — 2024-10-08
- 1.1.1 — 2024-09-30
- 1.1.0 — 2024-08-21
- 1.0.9 — 2024-08-20
- 1.0.8 — 2024-03-22
- 1.0.7 — 2023-10-07
- 1.0.6 — 2023-09-26
- 1.0.5 — 2023-09-25
- 1.0.4 — 2023-09-25
- 1.0.3 — 2023-06-27
- 1.0.2 — 2023-06-16
- 1.0.1 — 2023-06-16
- 1.0.0 — 2023-06-16

## README

# haigeek-axios请求插件

## 介绍
基于axios封装，适用于调用海尔对外开放能力的http请求插件。

## 安装
npm install haigeek-axios  

## 示例
```
import { haigeekRequest } from 'haigeek-axios'
haigeekRequest('get', url, params).then(res => {})
import axios from 'haigeek-axios'
axios......
```
## 封装
```
import { haigeekRequest } from '@/assets/js/http'
const env = process.env.NODE_ENV
export const baseapi = env === 'development' ? '/apiprod' : 'https://ys-openservice.haigeek.com'
/**
  * @description: 封装请求类
  * @param {method} method 请求方式
  * @param {path} path 请求路径
  * @param {params} params 参数
  * @param {headers} headers 请求头
  */
export const iotRequest = (method, path, params, headers) => {
    return haigeekRequest(
        method,
        baseapi + path,
        params,
        {
            hgAppId: 'MB-IYD10511011511-0000',
            hgAppKey: '08764dc218830a9a05cbfa1814020cdf',
            hgUrlPrefix: baseapi,
            hgLoading: true, 
            hgAutoError: '1',
            hgSuccessCodeKey: 'retCode', // 默认retCode，可不传
            hgSuccessCode: '00000', // 默认00000，可不传
            hgErrorMsgKey: 'retInfo', // 默认retInfo，可不传
            hgEncryptLevel: '0', // 默认0，可不传
            hgLoginCode: '403',
            fnShowError: fnShowError,
            fnStartLoading: fnStartLoading,
            fnEndLoading: fnEndLoading,
            fnLogin: fnLogin
        },
        headers
    )
}
const fnStartLoading = () => {
    document.getElementById('loading').style.display = 'block';
}
const fnEndLoading = () => {
    document.getElementById('loading').style.display = 'none';
}
const fnShowError = (msg) => {
    document.getElementById('showMsg').innerHTML = msg;
    document.getElementById('showMsg').style.display = 'block';
    setTimeout(() => {
        document.getElementById('showMsg').style.display = 'none';
    }, 3000);
}
const fnLogin = () => {
    console.log('跳转至登录')
}

// 使用
import { iotRequest } from '@/api/api.js'
iotRequest(
  'post',
  '接口地址',
  {
    "参数1":"111",
  }
).then(res => {
  console.log(res)
}).catch(e => {
  console.log(e)
})
```
## haigeekRequest(method, ajaxurl, params, config, headers, other): 说明
### method
请求方式：get/post

### ajaxurl
请求地址

### params
入参：json类型（其他类型时通过config.hgEncryptLevel控制）
HOtherype: 非json类型入参时可通过该参数传入

### config主要配置项
#### 1>hgAppId：string
对应智能应用appId, 验证签名-必传
#### 2>hgAppKey：string
对应智能应用appKey, 验证签名-必传
#### 3>hgAutoError：string
0:不自动提示（默认值）

1:自动提示后台异常信息（注意需要传fnShowError）
#### 4>hgLoading：bool 
false:请求时不显示loading（默认值）

true:请求时自动显示loading（注意需要传fnStartLoading，fnEndLoading）
#### 5>hgEncryptLevel：string
0:入参为json类型数据（默认值）

1:入参为application/x-www-form-urlencoded类型数据

2:入参为multipart/form-data类型数据
#### 6>hgHeadSignLog：bool
false:不打印header参数sign（默认值）

true:打印header参数sign(用于调试)
#### 7>hgSuccessCodeKey：string | number
'retCode': 默认值

其他:自定义code的key
#### 8>hgSuccessCode：string | number
'00000': 默认值

其他:自定义请求成功code值
#### 9>hgErrorMsgKey： string
'retInfo': 默认值

其他：自定义请求失败错误信息key值
#### 10>hgUrlPrefix： string
请求前缀--签名时去除使用，生产环境一般传域名
#### 11>fnStartLoading： function
打开loading
#### 12>fnEndLoading： function
关闭loading
#### 13>fnShowError： function
自动错误提示方法，参数为提示的错误信息
#### 14>hgLoginCode： string
用户信息失效，需要登录使用；登录失效返回的code值（默认不自动登录）
#### 15>fnLogin: function
自动跳转登录方法
#### 16>hgErrorType: string
接口报错类型：不传：接口必须正常返回，通过code值判断是否请求失败（默认值），1：接口请求失败时直接返回错误信息
#### 17>hgSuccessResult: string
请求成功返回结果对应的属性数据，默认无(返回整个结果数据)

---
_Source: https://npm.io/package/haigeek-axios · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
