1.0.56 • Published 2 months ago

g6-fn v1.0.56

Weekly downloads
-
License
-
Repository
-
Last release
2 months ago

前端常用方法库

此仓库包含了一些前端在项目开发中的一些常用方法

方法

方法名使用
时间格式化dateFormat(date,format)
存储单位转换(MB、GB 等)sizeFilter(limit)
file 转 base64getBase64(file,cb)
全局唯一 iduuid()
将 hex 颜色转成 rgbhexToRgba(hex,opacity)
根据下载链接下载文件downloadFile(url: string, fileName: string)
计算字符的字节数countStrToBit(str: string)
对比两个对象值-lodashisEqual(value, other)
深拷贝-lodashdeepClone(obj)
防抖-lodashdebounce(func,wait,immediate)
节流-lodashthrottle(func,wait)

正则 regex

export const regex = {
  phone: /^1[3,4,5,6,7,8,9][0-9]{9}$/,
  name: /^[\u4e00-\u9fa5a-zA-Z]+$/, //中文|英文
  numName: /^[\u4e00-\u9fa5A-Za-z0-9]+$/, //中文|英文|数字
  email: /^[a-zA-Z0-9_-][.a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
  password:
    /^(?![\da-z]+$)(?![\dA-Z]+$)(?![\d~!!@#$%^&*_+='"|\\(){}[\]::;“'<>,.?/]+$)(?![a-zA-Z]+$)(?![a-z~!!@#$%^&*_+='"|\\(){}[\]::;“'<>,.?/]+$)(?![A-Z~!!@#$%^&*_+='"|\\(){}[\]::;“'<>,.?/]+$)[\da-zA-z~!!@#$%^&*_+='"|\\(){}[\]::;“'<>,.?/]{8,15}$/,
  generalName: /^[\u4E00-\u9FA5a-zA-Z0-9_-()()]+$/u, //中文|英文|数字|下划线|横线
  url: /^(ht|f)tp(s?):\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-.?,'/\\&%+$#_=]*)?$/,
  version: /^\d+(\.\d+)*$/,
  dirName: /^[^\\\\/:*?"<>|]*$/,
}

本地存储

storage

import { Storage } from 'g6-fn'
const storage = new Storage()

storage.set('key', 'value')
storage.get('key')
storage.remove('key')
storage.clear()
storage.getAll()

Axios 封装

createHttpServicefang(options,requestCallback,responseCallback)

  • options: Axios.create(options)
  • requestCallback: 请求拦截器回调
  • responseCallback: 响应拦截器回调
  • responseErrorCallback 响应拦截器错误捕获回调

使用

const http = createHttpService(
  {
    baseURL: '/api',
  },
  config => {
    // xxxxx
    return config
  },
  response => {
    // xxxxx
    return response.data
  },
)

const { get, put, post } = http

export const testApi = {
  list: get(`/list`),
  add: post('/list/add'),
}

// 页面上
import { testApi } from 'xxxx/service'

testApi.get({
  /* 参数 */
})
testApi.post({
  /* 参数 */
})
1.0.55

2 months ago

1.0.54

2 months ago

1.0.56

2 months ago

1.0.53

4 months ago

1.0.52

4 months ago

1.0.48

7 months ago

1.0.49

7 months ago

1.0.51

7 months ago

1.0.50

7 months ago

1.0.44

9 months ago

1.0.47

9 months ago

1.0.46

9 months ago

1.0.45

9 months ago

1.0.39

10 months ago

1.0.38

10 months ago

1.0.40

10 months ago

1.0.43

10 months ago

1.0.42

10 months ago

1.0.41

10 months ago

1.0.33

10 months ago

1.0.32

11 months ago

1.0.37

10 months ago

1.0.36

10 months ago

1.0.35

10 months ago

1.0.34

10 months ago

1.0.31

11 months ago

1.0.30

11 months ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago