1.1.8 • Published 3 years ago

turbo_miniapp_util v1.1.8

Weekly downloads
20
License
MIT
Repository
-
Last release
3 years ago

微信小程序常用工具

import Util from 'turbo_miniapp_util'

formatTime

let now = Uitl.formatTime()
// 2020/11/01 12:15:35

formatNumber

Uitl.formatNumber(1)
// 01

Uitl.formatNumber(10)
// 10

hasOwn

let obj = {
  a:1,
  c:2
}
Uitl.hasOwn(obj,'a')
// true
Uitl.hasOwn(obj,'b')
// false

isArray

let arr = [1,2]
Uitl.isArray(arr)
// true

isDefined

Uitl.isDefined(b)
// false

isUndefined

Uitl.isUndefined(b)
// true

isEmail

Uitl.isEmail('555@123.com')
// true

isEmpty

Uitl.isEmpty('')
// true

isFunction

Uitl.isFunction('')
// false

isNumber

Uitl.isNumber('')
// false
Uitl.isNumber('234')
// false
Uitl.isNumber(12.5)
// true
Uitl.isNumber(12)
// true
Uitl.isNumber(NaN)
// false

isObject

isPhone

isString

isUrl

isWechat

getArray

getObject

getNumber

getString

getFunction

json

parse

strToObject

rtrim

删除右边的空格

ltrim

删除左边的空格

trim

删除两边的空格

strim

删除所有的空格

strlen

字符串计算字符长度(英文一个字符,中文为2个字符)

leavetime

let time_end = '2020/12/12 12:12:59'
let str = Util.leavetime(time_end, 'D天H时M分S秒')
// 5天6时35分9秒

timeformat

let nowtime = Util.timeformat()
let timestr = Util.timeformat(1581223453, 'y-m-d h:i:s')
let timestamp = Util.timeformat("2020-01-02", 'timestamp')

calcDistance

let distance = Util.calcDistance(lat1, lng1, lat2, lng2)

isWxMiniapp

page

let page = Util.page()
// {
//   pages: [...],
//   current: {},
//   url: '/pages/...',
//   options: {}
// }

toast

Util.toast("thanks")

confirm

Util.confirm({
  title: "提示",
  content: "确定要关闭吗",
  confirm: () => {

  },
  cancel: () => {

  }
})

loading

Util.loading({
  title: '加载中...',
  mask: true
})
// or
Util.loading('加载中...')

closeToast

Util.closeToast()
// 等同于执行
// wx.hideLoading()
// wx.hideToast()

navigator

// 接受tab/普通页面路径
Util.navigator(url)

saveImage

Util.saveImage(imageUrl).then().catch(e)

getLocation

Util.getLocation({
  tip: "我们需要您授权位置信息"
}).then(res => {
  // code
}).catch(e)

upload

    // 支持多图上传 已经内置文件选择,页面直接调用函数即可(默认为上传图片)

    // 上传图片
    Util.upload({
      url: 'http://www.bookbag.com/api/common/upload',
      name: "file",
      count: 1,
      formData: {},
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      process: (res) => {
        console.log("上传进度",res)
      }
    }).then(res=>{
      console.log("上传结果", res)
    }).catch(e=>{
      console.log("err", e)
    })

    // 上传视频
    Util.upload({
      type: 'video',
      url: 'http://www.bookbag.com/api/common/upload',
      maxDuration: 60,
      formData: {},
      compressed: true,
      process: (res) => {
        console.log("上传进度", res)
      }
    }).then(res => {
      console.log("上传结果", res)
    }).catch(e => {
      console.log("err", e)
    })

getWxcode

// 获取微信小程序登录的code码
Util.getWxcode().then(code=>{
  // code
}).catch(e=>{

})

setToken

setUinfo

setUid

getToken

getUinfo

getUid

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago