npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@winfe/win-request

v1.2.2

Published

@winfe/win-request 基于 `axios` 提供了一套统一的网络请求和错误处理方案。兼容`his-request`

Downloads

50

Readme

request

@winfe/win-request 基于 axios 提供了一套统一的网络请求和错误处理方案。兼容his-request

启用方式

默认启用

介绍

安装

npm install @winfe/win-request
# OR
yarn add @winfe/win-request

支持

  • 自定义请求配置
export interface AxiosRequestConfig {
  successTxt?: string;
  failTxt?: string;
  warning?: boolean;
  cover?: boolean;
  repeat?: boolean;
  isAddHospitalSoid?: boolean;
  isAddSoid?: boolean;
  baseUrl?: string;
  message?: MessageInstance;
  global?: boolean;
  checkFn?: (data: unknown) => boolean;
  transformData?: (data: unknown) => unknown;
  errorHandler?: (error: AxiosError) => void;
  showDetail?: boolean;
}
  • 响应成功及异常的全局拦截统一处理
export interface AxiosResponse {
  success: boolean;
  traceid: string;
  errorDetail: {
    id: string;
    path?: string;
    detailMsg?: string;
    fixMsg?: string;
    ipAddress?: string;
    message?: string;
    original?: string;
  };
  appid: string;
  hostip: string;
}

使用

import Request from '@winfe/win-request';
import { Message } from 'element-ui';

const isProduction = process.env.NODE_ENV === 'production';

export const request = new Request({
  baseUrl: isProduction ? '/' : 'http://172.16.6.201:41200',
  warning: false, // 默认为 ture (是否使用默认错误提示)
  isAddHospitalSoid: false, // 默认为true (这里只是展示)
  message: Message
});

export default request;

API

service

通过 { service } = new Request(options);

options 具体格式参考 axios。service 的大部分用法等同于 axios,不同的是 options 扩展了一个axios 配置

示例如下:

service('/api/user', {
  params: {
    name: 1
  },
  successTxt: '请求成功'
});

temp

核心 temp 方法返回一个 promise 对象

/** 本服务计费 */
const { temp } = request
export const addOriginService = temp(url, {
  failTxt: '本服务计费设置添加失败!',
  successTxt: '本服务计费设置添加成功!',
  warning: false, // 关闭默认弹窗
  transformData: function (data) {
  	... // 处理data 的钩子
    return data
  },
  checkFn: function (data) {
	 ... // 可以校验api 入参 是否合法,不合法则取消这次请求
	 return data
	}
})

getCookieData

该方法获取 cookie 信息, 它放回一个 object 包括 user 、header 信息

import Request from '@winfe/win-request';
/*
 * @return { Object } Cookies
 */
const { user: userInfo, header } = Request.getCookieData();

返回数据

export const COOKIE_DATA = {
  user: getUserInfo(),
  header: getRequestHeader()
};
{
  user: {
    employeeId: // 员工id
    userId: // 用户id
    employeeNo: // 员工号
    employeeName: // 员工姓名
    hospitalSOID: // 医院soid
    userHospitalSOID: // 员工所属于医院 soid
    orgName: // 员工组织名称
  },
  header: {
    Authorization: '', // BEARER_TOKEN
    'W-FLOW': '', //
    'X-DEBUG': '',
    ip: ''
  }
}