# iot-axios2

> kaifangpingtai-vue2

Latest version **1.1.12** (published 2024-03-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install iot-axios2
pnpm add iot-axios2
yarn add iot-axios2
bun add iot-axios2
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.12 |
| Published | 2024-03-22 |
| First published | 2021-11-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 809.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | qisibo |
| Maintainers | qisibo916 |
| Keywords | axios, vue2 |

## Links

- npm: https://www.npmjs.com/package/iot-axios2
- npm.io page: https://npm.io/package/iot-axios2

## Recent versions

- 1.1.12 (latest) — 2024-03-22
- 1.1.11 — 2023-11-03
- 1.1.10 — 2023-11-03
- 1.1.9 — 2023-11-03
- 1.1.8 — 2023-05-10
- 1.1.7 — 2023-03-27
- 1.1.6 — 2023-01-06
- 1.1.5 — 2022-12-06
- 1.1.4 — 2022-12-06
- 1.1.3 — 2022-10-25
- 1.1.2 — 2022-10-25
- 1.1.1 — 2022-08-31
- 1.1.0 — 2022-08-18
- 1.0.29 — 2022-08-18
- 1.0.28 — 2022-08-16
- … 28 more at https://npm.io/package/iot-axios2/versions

## README

# iot-vue项目脚手架工具

## 介绍
基于axios封装，适用于iot-开放平台项目的http请求插件。

## 安装
Vue2版本：npm install iot-axios2    

Vue3版本：npm install iot-axios

## 说明
### 入参
#### 1>autoerror：string (兼容header_isPromptAbnormalInfo）
0:代表以前旧写法（默认值）

1:自动提示后台异常信息(Message提示)

2:不自动提示后台异常信息，用来请求中自定义catch方法

3:自动提示后台异常信息(MessageBox.alert提示)

注：如果需要1、3自动提示，自行引入elementUI/element-plus样式
#### 2>hnoloading：bool 
false:请求时自动显示loading（默认值）

true:请求时不显示loading
#### 3>encryptLevel：string
0:参数为json类型数据（默认值）

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

2:参数为multipart/form-data类型数据
#### 4>headSignLog：bool
false:不打印header参数antiReplaySign（默认值）

true:打印header参数antiReplaySign
#### 5>headDevice：number
0:不携带设备调用接口中的header默认配置项

1:携带设备调用接口中得header默认配置项
#### 6>noLogin：bool
false:接口403需要自动跳转登录（默认值）

true:接口403不需要自动跳转登录
#### 7>noHeadSign：bool
false:增加防重放、灰度等参数（默认值）

true:不增加防重放、灰度等参数
#### 8>qiCustormCode：string | number
'00000': 默认值

其他:自定义请求成功状态码
#### 9>qiCustormStatus： string
'retCode': 默认值

其他:自定义请求状态key值
#### 10>qiCustormMsg： string
'retInfo': 默认值

其他：自定义请求失败错误信息key值

### 登录过期回调函数：window.loginDateCallback

### 使用
#### 1>iotAxios：正常axios库
#### 2>iotExtpost：
请求地址为：/managecenter-api/ext/${serveName}/post 的请求，参数（params,serveName）:

params: 请求入参

serveName：地址中${serveName}的值，默认为hardware
#### 3>iotExtget：
请求地址为：/managecenter-api/ext/${serveName}/get 的请求，参数（params,serveName）:

params: 请求入参

serveName：地址中${serveName}的值，默认为hardware

## 示例
```
import { axiosapi } from '@/assets/js/api';
import { iotAxios, iotExtpost, iotExtget} from 'iot-axios2';
export default {
  name: 'App',
  created () {
    //iotAxios
    iotAxios({
      method: 'post',
      url: `${axiosapi}/intelligenceapp/user/app/list`,
      data: {
        pageNum: 1,
        pageSize: 10,
        queryParam: '',
        hnoloading: true
      }
    }).then((res) => {
      console.log(res)
    })
    //iotExtpost
    iotExtpost({
      autoerror: 1,
      url: '/modelType/appTypeInfoList'
    }).then((res) => {
      console.log(res)
    })
    //iotExtget
    iotExtget({
      headSignLog: 1,
      url: '/modelType/appTypeInfoList'
    }).then((res) => {
      console.log(res)
    })
  }
}
```
## 封装
```
window.loginDateCallback = function(){	//登录过期时会自动调用
  let curPath = window.location.href
  if(curPath) {
    const route = `./index.html#/login?backurl=${encodeURIComponent(curPath)}`
    if(top!=self) {
      window.parent.location.replace(route)
    } else {
      window.location.replace(route)
    }
  }
}

import { iotAxios } from 'iot-axios2'
const env = process.env.NODE_ENV  
export const baseapi = env === 'development' ? '/apiprod' : ''
/**
  * @description: 封装请求类
  * @param {method} method 请求方式
  * @param {path} path 请求路径
  * @param {params} params 参数
  * @param {headers} headers 请求头
  */
export const iotRequest = (method, path, params, headers) => {
  if (method.toLowerCase() === 'get') {
    return iotAxios.get(baseapi + path, { params: params }, headers)
  } else {
    return iotAxios.post(baseapi + path, params, headers)
  }
}

// 使用
import { iotRequest } from '@/apis/api'
export const fnLogout = (params) => {
  return iotRequest('post', '/developercenter-api/index/logout', params)
}
```

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