1.1.12 • Published 9 months ago

iot-axios2 v1.1.12

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

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)
}
1.1.12

9 months ago

1.1.9

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.0.19

3 years ago

1.1.0

2 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.11

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago