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

admin-axios-plus

v1.0.1

Published

axios扩展

Downloads

1

Readme

admin-axios-plus

介绍

axios 扩展,登录拦截(后置)、请求封装、过期刷新 token、字典合并请求。

安装

  npm i axios admin-axios-plus --save

说明

  • initAxios: 初始化,(options: AxiosConfig): void

  • getJSON: GET 请求,(url: string, data?: any, config?: AxiosRequestConfig) : Promise

  • postJSON:POST 请求,(url: string, data?: any, config?: AxiosRequestConfig) : Promise

  • putJSON:PUT 请求,(url: string, data?: any, config?: AxiosRequestConfig) : Promise

  • deleteJSON:DELETE 请求,(url: string, data?: any, config?: AxiosRequestConfig) : Promise

  • postFile:文件上传,(url: string, evt: any, params: object = {}, onProgress?: (e: any) => void): Promise

  • exportFlie:文件下载,(url: string, data: object, method = "get"): Promise

  • getDictionary: 获取字典列表,(codes: string, cb: Function): void

  • getDictionaryCodeName: 获取字典{code:name}列表,(codes: string, cb: Function): void

  • getDictionaryCodeValue: 获取字典{code:value}列表,(codes: string, cb: Function): void

  • getDictionaryValueName: 获取字典{value:name}列表,(codes: string, cb: Function): void

  • dicValueName:获取字典 name,(groupCode: string, value: string, ref: any): void

export declare interface AxiosConfig {
  baseURL: string; // 基础URL
  headers?: Record<string, unknown>; // 请求头参数
  jumpLoginFn: () => void; // 鉴权失败跳转登录方法
  ElMessageFn: (msg: string) => void; // 错误信息提示方法
  enableRefresh?: boolean; // 是否开启token刷新
  refreshRequest?: ((opt: AxiosRequestConfig) => Promise<[token: string, expires: number]>);  // token刷新请求
  enableDictionary?: boolean; // 是否开启字典请求
  dictionaryRequest?: (codes: string) => Promise<object>; // 字典请求
}

使用

manin.ts

import { createApp } from "vue";
import App from "./App.vue";

import { axiosPlus } from "admin-axios-plus";
import { router } from "admin-router-plus";
import { ElMessage } from "element-plus";
import apis from "./utils/apis";

const app = createApp(App);

app.use(axiosPlus, {
  baseURL: "/api", // [必填]基础URL
  headers: { clientToken: "Basic YW5kcm9pZDphbmRyb2lk" }, // [可选]请求头追加参数
  jumpLoginFn: () => {
    router.replace({ name: "login" });
  },
  ElMessageFn: (msg) => {
    ElMessage.error(msg);
  },
  enableRefresh: true, // [可选]开启动态刷新token
  refreshRequest: async (cfg) => {
    const res = await postJSON(apis.TokenRefresh, {}, cfg);
    return [res.data.accessToken, res.data.expiresIn];
  }, // 刷新token请求
  dictionaryRequest: async (codes) => {
    const res = await getJSON(apis.DictionaryCode, { groupCodes: codes }); // 字典请求
    return res.data;
  },
});

app.mount("#app");