0.0.2 • Published 2 years ago

@syyfe/tools v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

@syyfe/tools

安装

npm install @syyfe/tools --save

yarn add @syyfe/tools --save

api 请求

import { api } from "@syyfe/tools"

请求方式

"get" | "post" | "delete" | "options" | "head" | "put" | "patch" | "text" | "open"

名称描述
get发送一个 get 方式的请求
post发送一个 post 方式的请求
delete发送一个 delete 方式的请求
options发送一个 options 方式的请求
head发送一个 head 方式的请求
put发送一个 put 方式的请求
patch发送一个 patch 方式的请求
text返回请求地址 (baseURL + 参数)
open浏览器新窗口打开请求的 url

使用方法

配置 api

@/api/apis.ts

/**
 *  @param url 接口地址
 *  @param baseURL 主域名地址
 */
const apis = {
  getConfig: api.get(url, baseURL),
  postConfig: api.post(url, baseURL),
  deleteConfig: api.delete(url, baseURL),
  optionsConfig: api.delete(url, baseURL),
  headConfig: api.head(url, baseURL),
  putConfig: api.put(url, baseURL),
  patchConfig: api.patch(url, baseURL),
  textConfig: api.text(url, baseURL),
  openConfig: api.open(url, baseURL),
};
export default apis;

使用 api

@/views/index.vue

const data = { name: "lee", age: 1 }
interface UserParams {
  name: string;
  age: number;
}
interface UserResponse {
  code: number;
  total: number;
  rows: Array<any>;
}

// 1. 请求参数强类型约束
this.$request<UserParams, any>('getConfig', data)
.then(res => {
  console.log(res);
}).catch(error=> {
  console.log(error)
})

// 2. 响应数据强类型约束
this.$request<any, UserResponse>('getConfig', data)
.then(res => {
  console.log(res.rows); // Yes
  console.log(res.xxx); // Error
}).catch(error=> {
  console.log(error)
})

// 3. 请求 / 响应数据强类型约束
this.$request<UserParams, UserResponse>('getConfig', data)
.then(res => {
  console.log(res.rows); // Yes
  console.log(res.xxx); // Error
}).catch(error=> {
  console.log(error)
})

// 4. 不强类型约束
this.$request('getConfig', data)
.then((res: any) => {
  console.log(res);
}).catch(error=> {
  console.log(error)
})

NewFormHelper

import { NewFormHelper } from "@syyfe/tools"

使用方法

NewFormHelper.show()
NewFormHelper.input("名称", "name")
...

方法

方法名称描述
show生成一个 文本 类型的表单
input生成一个 密码 类型的表单
password生成一个 密码 类型的表单
int生成一个 整数 类型的表单
mobile生成一个 手机号 类型的表单
cascader生成一个 级联选择 类型的表单
select生成一个 选择器 类型的表单
switch生成一个 开关 类型的表单
agerange生成一个 滑块 类型的表单
imageUpload生成一个 上传图片 类型的表单
checkbox生成一个 多选框 类型的表单
radio生成一个 单选框 类型的表单
textarea生成一个 文本区 类型的表单
date生成一个 日期选择 类型的表单
time生成一个 时间选择 类型的表单
dateRange生成一个 日期范围选择 类型的表单
dateTimeRange生成一个 日期时间范围选择 类型的表单
slot生成一个 自定义 类型的表单

show Attributes

参数类型描述
other.questionstring表单Tooltip提示

input Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.placeholderstring占位文本
other.maxLengthnumber最大长度
other.rulesArray校验规则
other.typestring表单类型
other.widthstring宽度
other.rowsstring行数
other.prependstring前置文案
other.appendstring后置文案
other.customPendstring自定义信息
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

password Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.rulesArray校验规则
other.placeholderstring占位文本
other.maxLengthnumber最大长度
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

int Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.placeholderstring占位文本
other.maxLengthnumber最大长度
other.rulesArray校验规则
other.showWordLimitstring限制遮挡文本
other.widthstring宽度
other.prependstring前置文案
other.appendstring后置文案
other.customPendstring自定义信息
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

mobile Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.placeholderstring占位文本
other.rulesArray校验规则
other.customPendstring自定义信息
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

cascader Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.placeholderstring占位文本
other.rulesArray校验规则
other.widthstring宽度
other.filterableboolean是否可筛选
other.optionsArray
other.checkStrictlyboolean严格的遵守父子节点不互相关联
other.questionstring表单Tooltip提示
other.element attrstring表单Tooltip提示

select Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.placeholderstring占位文本
other.rulesArray校验规则
other.filterableboolean是否可筛选
other.optionsArray
other.widthstring宽度
other.multipleboolean是否可以多选
other.multipleLimitnumber最多可以选择的项目数
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

switch Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.placeholderstring占位文本
other.rulesArray校验规则
other.activeValueany打开时的值
other.inactiveValueany关闭时的值
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

agerange Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.placeholderstring占位文本
other.rulesArray校验规则
other.widthstring宽度
other.minnumber最小值
other.maxnumber最大值
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

imageUpload Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.rulesArray校验规则
other.actionstring上传的地址
other.fileSizenumber文件大小
other.acceptstring上传的文件类型
other.hintContentstring提示文案
other.questionstring表单Tooltip提示

checkbox Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.rulesArray校验规则
other.optionsArray
other.questionstring表单Tooltip提示

radio Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.rulesArray校验规则
other.optionsArray
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

textarea Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.rulesArray校验规则
other.placeholderstring占位文本
other.maxLengthnumber最大长度
other.widthstring宽度
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

date Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.rulesArray校验规则
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

time Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.rulesArray校验规则
other.optionObjectselectableRange/format
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

dateRange Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.rulesArray校验规则
other.widthstring校验规则
other.formerOnlyboolean是否禁用今天之后
other.formerTodayOnlyboolean是否禁用今天和之后
other.afterTodayboolean是否禁用今天之前
other.clearableboolean是否可清空
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

dateTimeRange Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.disabledboolean是否禁用
other.rulesArray校验规则
other.formatstring日期格式
other.defaultTimestring默认时间
other.valueFormatstring绑定值的格式
other.afterTodayboolean是否禁用今天之前
other.afterDateboolean是否禁用当前时刻之前
other.tipstring表单文案提示
other.questionstring表单Tooltip提示

slot Attributes

参数类型描述
labelstring表单域
propstring绑定属性值
other.ifboolean是否显示
other.rulesArray校验规则
other.tipstring表单文案提示
other.questionstring表单Tooltip提示