New: Introducing PHP and Composer Support.Read the Announcement
Socket
Book a DemoInstallSign in
Socket

gisquest-component-request

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gisquest-component-request

只给前端使用的request封装包

latest
npmnpm
Version
1.0.3
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

统一前端的Request请求:

1、安装依赖

npm install

私服的依赖(暂时在公网上,方便安装 npm i gisquest-component-request)

npm install gisquest-component-request --registry=http://192.168.11.146:8073/repository/npm-all/

2、修改public/下配置

添加环境变量文件 public/env.*.js 添加参数,确保改js被引入到index.html中 (星号代表环境变量名:env.development.js 【本地调试】,env.production.js 【打包后的环境】)

<body>
  <noscript>
    <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
  </noscript>
  <script src="./env.<%=process.env.NODE_ENV%>.js?t=<%= new Date().getTime() %>"></script>
  <div id="app"></div>
  <!-- built files will be auto injected -->
</body>
    

在 env.*.js 添加参数,

/**
 * API路网关地址,作为整个程序的baseURL,如果没有网关,则为空
 */
window.apiGateway = '';
/**
 * 单点登陆的认证地址
 * @type {string}
 */
window.ssoUrl = '/tdcb';

4、调用

4.1 一般调用

如果不需要认证失败或成功后的处理,那么直接调用组件即可

import {request} from 'gisquest-component-request'

export function SubSystems() {
    return request({
        url: window.appAllotnum + '/allotnum/platform/subsystem', method: 'post'
    })
}

4.2、如果要做失败或成功后的回调处理

请自己编写一个request.js

import {request} from 'gisquest-component-request'

function myRequest(args) {
    return request(args, AuthSuccess, AuthFail);
}


/**
 * 认证成功后的处理
 * @param res
 * @returns {Promise<AxiosResponse<any>>}
 * @constructor
 */
function AuthSuccess(res) {
    if (res != null && res.data != null && res.data.status == 200) {
        
    }
}

/**
 * 认证失败后处理
 * @param res
 * @constructor
 */
function AuthFail(res) {

}

export default myRequest;

在api中进行调用

import request from "../utils/myRequest"

/**
 * 读取子系统
 * @param params
 * @returns {*}
 */
export function SubSystems() {
    return request({
        url: '/allotnum/platform/subsystem', method: 'post'
    })
}

FAQs

Package last updated on 02 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts