justin-cli-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.1.16 • Public • Published

justin-cli-plugin

TODO:

1,收集常用 公共方法、hooks、公共组件

Realized:

1,部分常用 公共方法、公共组件

Usage

1,请求

import { createAxios } from "justin-cli-plugin";

const { axiosInstance }: any = createAxios({
  baseURL:'',
  beforeRequestHook,
  beforeResponseHook,
});

export function get(
  url: string,
  data: any = {},
  options: Record<string, any> = {},
) {
  const temURl = Object.keys(data)
    .reduce((acc, item) => acc + `${item}=${data[item]}&`, "")
    .slice(0, -1);
  return axiosInstance.get(url + `${temURl ? "?" + temURl : ""}`, {
    requestOptions: {
      isDirectConnection: false, //是否直接连接
      isEncryption: false, //是否加密
      needLogin: true, // 需要登录
      ...options,
    },
    headers: options.headers || {},
  });
}

export function post(
  url: string,
  data: Record<string, any> = {},
  options: Record<string, any> = {},
) {
  return axiosInstance.post(url, data, {
    requestOptions: {
      isDirectConnection: false, //是否直接连接
      isEncryption: true, //是否加密
      needLogin: true, // 需要登录
      ...options,
    },
    headers: options.headers || {},
  });
}

2,取消请求

// 用于存储取消令牌集合
export const cancelTokenObj: any = ref({});
// 用于存储取消白名单集合
export const requestWhiteList: any = ref([]);

//移除单个失效请求
export function cancelToken({ url }: any) {
  if (!url) {
    return;
  }
  if (cancelTokenObj.value[url]) {
    cancelTokenObj.value[url]();
  }
  delete cancelTokenObj.value[url];
}

//取消全部请求==》排除白名单
export function cancelAllToken() {
  Object.keys(cancelTokenObj.value).forEach((key) => {
    if (!requestWhiteList.value.includes(key)) {
      cancelTokenObj.value[key]();
      delete cancelTokenObj.value[key];
    }
  });
}

2,logger控制

import { CustomConsole } from "justin-cli-plugin";

// 使用示例
export const logger = new CustomConsole();
// 设置日志级别为 'debug',这样所有级别的日志都会显示
logger.setLogLevel("debug");

3,unoconfig

safeBottom // 定义 safe-bottom 类,应用 iOS 的底部安全区域
px2Text //定义 px转rem 的类, px2-* 类名

4,utils

5,viteConfig

6,公共组件

Readme

Keywords

none

Package Sidebar

Install

npm i justin-cli-plugin

Weekly Downloads

101

Version

1.1.16

License

ISC

Unpacked Size

2.76 MB

Total Files

45

Last publish

Collaborators

  • yingzhixiaoyi