1.0.45 • Published 2 years ago

@baic/yolk-miniapp v1.0.45

Weekly downloads
188
License
MIT
Repository
github
Last release
2 years ago

@baic/yolk-miniapp

Taro之上的微信小程序封装,包含基础Config配置、表单、Request、Util

使用

yarn add @baic/yolk-miniapp

API

Config

内置Taro的Config配置,扩展了针对Css Modules的Typescript支持,并简化部分Taro配置。
// config/index.ts
import config from '@baic/yolk-miniapp/lib/config';

export default (merge) => {
  return merge({}, config(merge, {
    // 自定义Taro的Config
  }));
};

yolk

参数说明类型默认值
sassVarsResources加入全局引用sass变量文件源string[]-

Form

使用antd.Form扩展Taro的表单能力(注:由于antd体积过大,打包过大会被微信规则限制,这里内部进行了优化,使用者不应在项目中直接使用antd)。

useForm()

同antd.Form的useForm,并增加createFormItem方法,使得表单双向绑定适用于Taro。并扩展了一部分常用的rules。
import * as React from 'react';
import { View } from '@tarojs/components';
import { AtForm, AtButton } from 'taro-ui';
import { Form } from '@baic/yolk-miniapp';
import {
  Input,
} from '@baic/yolk-miniapp-ui';
export default () => {
  const [form, formProps] = Form.useForm();
  const { createFormItem, validateFields } = form;
  const onClick = async () => {
    const values = await validateFields();
    console.log(values);
  }
  return <View>
    <Form form={form} {...formProps}>
      <AtForm>
        {createFormItem({
          name: 'name',
          rules: 'required',
        })(<Input />)}
      </AtForm>
    </Form>
    <AtButton onClick={onClick}>获取输入</AtButton>
  </View>
}

validator

为表单rules扩展的常用验证
export type ValidatorKeys =
  | 'required' // 必填
  | 'mobile'  // 手机号
  | 'idcard'  // 身份证
  | 'cn'  // 英文
  | 'en'  // 中文
  | 'email' // 邮箱
  | 'int' // 整型
  | 'float' // 小数
  | 'number'  // 数字
  | 'url' // 链接
  | 'trim'  // 前后空格
  | 'noSpaces'  // 全文空格
  | 'len' // 指定长度
  | 'maxLen'  // 最大长度
  | 'minLen'  // 最小长度
  | 'max' // 小于
  | 'min' // 大于
  | 'maxEqual'  // 小于等于
  | 'minEqual'  // 大于等于
  | 'checked' // 选中
  | 'maxDecimalDigits'  // 小数位数小于
  | 'minDecimalDigits'  // 小数位数大于
  | 'maxEqualDecimalDigits' // 小数位数小于等于
  | 'minEqualDecimalDigits' // 小数位数大于等于
  | 'ip';

Request

基于Taro.request构建的请求对象,这里只列举扩展参数

参数说明类型默认值
baseUrl基础Urlstring-
logger实时日志boolean-
suffix默认后缀名,如果url内部包含不添加string-
randomStringName随机数参数名string_
shallowTrim参数浅层次去掉前后空格booleantrue
deepTrim参数深层次去掉前后空格booleanfalse
onStart请求前调用,返回请求参数function-
onEnd请求完成调用function-
onFail请求失败调用function-
onError请求发生错误调用,返回response对象function-
onInterceptorCatch判断返回结果符合的Promisefunction-
transformResult转换返回response.datafunction-
loading是否开启默认Loadingbooleantrue
header扩展为可异步函数返回headerobjectfunction-

Request.get(url, data, option)

static方式的默认get方法

Request.post(url, data, option)

static方式的默认post方法

useRequest

获取上下文初始化的request实例

request.get(url, data, option)

request.post(url, data, option)

request.data(defaultValue: any).get(url, data, option)

设定默认值,并获取transformResult转换后的data

request.data(defaultValue: any).post(url, data, option)

设定默认值,并获取transformResult转换后的data
import * as React from 'react';
import { useRequest } from '@baic/yolk-miniapp';
import { View } from '@tarojs/components';
export default () => {
  const [request] = useRequest();
  // request.get();
  // request.post();
  // request.data().get();
  // request.data().post();
  return <View/>
}

Util

getRandomString(maxLength):String

说明:生成随机字符串

参数说明类型默认值
maxLength字符串长度number6

isEmpty(object):Boolean

说明:判断类型

参数说明类型默认值
object判断对象object-

getByteLength(string):Number

说明:获取字符串真实长度

参数说明类型默认值
string字符串string-

random(min, max):Number

说明:获取区间随机数

参数说明类型默认值
min最小值number-
max最大值number-

blank(object):String

说明:为空返回Util.blankPlaceholder

参数说明类型默认值
object判断对象object-

isIdCard(object):Boolean

说明:判断是否是合法的身份证号码

参数说明类型默认值
object判断对象object-

Math.add(...number):Number

说明:加法

参数说明类型默认值
number数字number-

Math.sub(...number):Number

说明:加法

参数说明类型默认值
number数字number-

Math.mul(...number):Number

说明:减法

参数说明类型默认值
number数字number-

Math.div(...number):Number

说明:乘法

参数说明类型默认值
number数字number-

Date.format(time, formater):String

说明:时间格式化

参数说明类型默认值
time格式化时间Date or moment-
formater格式化格式,包含Date.NY(NYR,SFM,NYRSFM,NYRSF,NYR000,NYREND)string-

Date.ny(time):String

说明:Date.format(time, Date.NY);

参数说明类型默认值
time格式化时间Date or moment-

Date.nyr(time):String

说明:Date.format(time, Date.NYR);

参数说明类型默认值
time格式化时间Date or moment-

Date.sfm(time):String

说明:Date.format(time, Date.SFM);

参数说明类型默认值
time格式化时间Date or moment-

Date.nyrsfm(time):String

说明:Date.format(time, Date.NYRSFM);

参数说明类型默认值
time格式化时间Date or moment-

Date.nyrsf(time):String

说明:Date.format(time, Date.NYRSF);

参数说明类型默认值
time格式化时间Date or moment-

Date.nyr000(time):String

说明:Date.format(time, Date.NYR000);

参数说明类型默认值
time格式化时间Date or moment-

Date.nyrend(time):String

说明:Date.format(time, Date.NYREND);

参数说明类型默认值
time格式化时间Date or moment-

Number.format(number, decimals,thousands):String

说明:数字格式化

参数说明类型默认值
number格式化数字number0
decimals保留小数位数number2
thousands千分位符号string,

Money.format(number, decimals,thousands):String

说明:Number.format

参数说明类型默认值
number格式化数字number0
decimals保留小数位数number2
thousands千分位符号string,

Money.thousands(number, decimals,thousands):String

说明:Number.format

参数说明类型默认值
number格式化数字number0
decimals保留小数位数number2
thousands千分位符号string,

Money.y2w(number, decimals):String

说明:元转万

参数说明类型默认值
number格式化数字number0
decimals保留小数位数number2

Money.f2y(number, decimals):String

说明:分转元

参数说明类型默认值
number格式化数字number0
decimals保留小数位数number2

Provider

yolk-miniapp的初始化上下文
import * as React from 'react';
import { Provider, Request } from '@baic/yolk-miniapp';

export default () => {
  return <Provider request={new Request()}/>
};

Hooks

一些hooks工具

Hooks.useDidShow(callback: () => void | Promise): void;

扩展Taro的useDidShow,确保第一次不执行

Hooks.useFastClickCallback(callback: FastClickCallback, autoRelease?: boolean): ClickCallback;

点击事件的useCallback,防止执行过程连续点击

Logger

小程序日志,会反应到实时日志中
1.0.44

2 years ago

1.0.45

2 years ago

1.0.39

3 years ago

1.0.38

3 years ago

1.0.40

3 years ago

1.0.43

3 years ago

1.0.42

3 years ago

1.0.41

3 years ago

1.0.37

3 years ago

1.0.26

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.25

3 years ago

1.0.19

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

2.0.0-beta.2

3 years ago

2.0.0-beta.1

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.3

3 years ago

1.0.0-alpha.129

3 years ago

1.0.0-alpha.124

3 years ago

1.0.0-alpha.123

3 years ago

1.0.0-alpha.128

3 years ago

1.0.0-alpha.127

3 years ago

1.0.0-alpha.126

3 years ago

1.0.0-alpha.125

3 years ago

1.0.0-alpha.119

4 years ago

1.0.0-alpha.118

4 years ago

1.0.0-alpha.120

4 years ago

1.0.0-alpha.122

3 years ago

1.0.0-alpha.121

3 years ago

1.0.0-alpha.117

4 years ago

1.0.0-alpha.116

4 years ago

1.0.0-alpha.115

4 years ago

1.0.0-alpha.113

4 years ago

1.0.0-alpha.112

4 years ago

1.0.0-alpha.114

4 years ago

1.0.0-alpha.111

4 years ago

1.0.0-alpha.109

4 years ago

1.0.0-alpha.108

4 years ago

1.0.0-alpha.107

4 years ago

1.0.0-alpha.106

4 years ago

1.0.0-alpha.110

4 years ago

1.0.0-alpha.105

4 years ago

1.0.0-alpha.104

4 years ago

1.0.0-alpha.103

4 years ago

1.0.0-alpha.102

4 years ago

1.0.0-alpha.101

4 years ago

1.0.0-alpha.100

4 years ago

1.0.0-alpha.99

4 years ago

1.0.0-alpha.98

4 years ago

1.0.0-alpha.96

4 years ago

1.0.0-alpha.97

4 years ago

1.0.0-alpha.95

4 years ago

1.0.0-alpha.94

4 years ago

1.0.0-alpha.93

4 years ago

1.0.0-alpha.92

4 years ago

1.0.0-alpha.91

4 years ago

1.0.0-alpha.90

4 years ago

1.0.0-alpha.89

4 years ago

1.0.0-alpha.88

4 years ago

1.0.0-alpha.87

4 years ago

1.0.0-alpha.85

4 years ago

1.0.0-alpha.86

4 years ago

1.0.0-alpha.84

4 years ago

1.0.0-alpha.83

4 years ago

1.0.0-alpha.81

4 years ago

1.0.0-alpha.82

4 years ago

1.0.0-alpha.80

4 years ago

1.0.0-alpha.79

4 years ago

1.0.0-alpha.78

4 years ago

1.0.0-alpha.77

4 years ago

1.0.0-alpha.76

4 years ago

1.0.0-alpha.75

4 years ago

1.0.0-alpha.74

4 years ago

1.0.0-alpha.73

4 years ago

1.0.0-alpha.72

4 years ago

1.0.0-alpha.71

4 years ago

1.0.0-alpha.70

4 years ago

1.0.0-alpha.69

4 years ago

1.0.0-alpha.68

4 years ago

1.0.0-alpha.67

4 years ago

1.0.0-alpha.66

4 years ago

1.0.0-alpha.65

4 years ago

1.0.0-alpha.64

4 years ago

1.0.0-alpha.63

4 years ago

1.0.0-alpha.62

4 years ago

1.0.0-alpha.61

4 years ago

1.0.0-alpha.60

4 years ago

1.0.0-alpha.59

4 years ago

1.0.0-alpha.58

4 years ago

1.0.0-alpha.57

4 years ago

1.0.0-alpha.56

4 years ago

1.0.0-alpha.54

4 years ago

1.0.0-alpha.55

4 years ago

1.0.0-alpha.53

4 years ago

1.0.0-alpha.52

4 years ago

1.0.0-alpha.51

4 years ago

1.0.0-alpha.50

4 years ago

1.0.0-alpha.49

4 years ago

1.0.0-alpha.48

4 years ago

1.0.0-alpha.47

4 years ago

1.0.0-alpha.46

4 years ago

1.0.0-alpha.45

4 years ago

1.0.0-alpha.44

4 years ago

1.0.0-alpha.43

4 years ago

1.0.0-alpha.42

4 years ago

1.0.0-alpha.41

4 years ago

1.0.0-alpha.40

4 years ago

1.0.0-alpha.39

4 years ago

1.0.0-alpha.38

4 years ago

1.0.0-alpha.37

4 years ago

1.0.0-alpha.36

4 years ago

1.0.0-alpha.35

4 years ago

1.0.0-alpha.34

4 years ago

1.0.0-alpha.33

4 years ago

1.0.0-alpha.32

4 years ago

1.0.0-alpha.31

4 years ago

1.0.0-alpha.30

4 years ago

1.0.0-alpha.29

4 years ago

1.0.0-alpha.28

4 years ago

1.0.0-alpha.27

4 years ago

1.0.0-alpha.26

4 years ago

1.0.0-alpha.25

4 years ago

1.0.0-alpha.24

4 years ago

1.0.0-alpha.23

4 years ago

1.0.0-alpha.21

4 years ago

1.0.0-alpha.22

4 years ago

1.0.0-alpha.20

4 years ago

1.0.0-alpha.19

4 years ago

1.0.0-alpha.18

4 years ago

1.0.0-alpha.16

4 years ago

1.0.0-alpha.17

4 years ago

1.0.0-alpha.15

4 years ago

1.0.0-alpha.14

4 years ago

1.0.0-alpha.13

4 years ago

1.0.0-alpha.12

4 years ago

1.0.0-alpha.10

4 years ago

1.0.0-alpha.11

4 years ago

1.0.0-alpha.9

4 years ago

1.0.0-alpha.8

4 years ago

1.0.0-alpha.7

4 years ago

1.0.0-alpha.6

4 years ago

1.0.0-alpha.5

4 years ago

1.0.0-alpha.4

4 years ago

1.0.0-alpha.3

4 years ago

1.0.0-alpha.2

4 years ago

1.0.0-alpha.1

4 years ago