lvmax 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
..
addUnit 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
animation 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
arrayBufferToFile 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
base64ToArrayBuffer 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
base64ToPath 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
camelCase 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
canIUseCanvas2d 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
capitalizedAmount 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
clamp 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
cloneDeep 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
closest 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
components 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
createAnimation 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
createCanvas 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
createImage 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
debounce 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
exif 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
fillZero 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
floatAdd 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
floatDiv 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
floatMul 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
floatSub 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
getClassStr 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
getCurrentPage 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
getLocalFilePath 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
getRect 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
getStyleStr 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
hasOwn 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
isBase64 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
isBrowser 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
isDef 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
isEmpty 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
isFunction 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
isNumber 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
isNumeric 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
isObject 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
isPromise 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
isString 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
kebabCase 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
pathToBase64 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
platform 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
raf 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
random 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
range 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
selectAllComponent 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
selectComponent 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
selectElement 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
sleep 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
throttle 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
toArray 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
toBoolean 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
toNumber 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
unitConvert 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
vue 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
changelog.md 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
index.ts 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
package.json 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前
readme.md 91f354b56f uniapp版本考试前端代码v1.0version 3 月之前

readme.md

lime-shared 工具库

  • 本人插件的几个公共函数
  • 按需引入

引入

按需引入只会引入相关的方法,不要看着 插件函数列表多 而占空间,只要不引用不会被打包

import {getRect} from '@/uni_modules/lime-shared/getRect'

目录

  • getRect: 获取节点尺寸信息
  • addUnit: 将未带单位的数值添加px,如果有单位则返回原值
  • unitConvert: 将带有rpx|px的字符转成number,若本身是number则直接返回
  • canIUseCanvas2d: 环境是否支持使用 canvas 2d
  • getCurrentPage: 获取当前页
  • base64ToPath: 把base64的图片转成临时路径
  • pathToBase64: 把图片的临时路径转成base64
  • sleep: async 内部程序等待一定时间后再执行
  • throttle: 节流
  • debounce: 防抖
  • random: 返回指定范围的随机数
  • range: 生成区间数组
  • clamp: 夹在min和max之间的数值
  • floatAdd: 返回两个浮点数相加的结果
  • fillZero: 补零,如果传入的是个位数则在前面补0
  • exif: 获取图片exif
  • selectComponent: 获取页面或当前实例的指定组件
  • createAnimation: uni.createAnimation
  • animation: 数值从一个值到另一个值的过渡
  • camelCase: 字符串转换为 camelCase 或 PascalCase 风格的命名约定
  • kebabCase: 将字符串转换为指定连接符的命名约定
  • closest: 在给定数组中找到最接近目标数字的元素
  • isBase64: 判断字符串是否为base64
  • isNumber: 检查一个值是否为数字类型
  • isNumeric: 检查一个值是否为数字类型或表示数字的字符串
  • isString: 检查一个值是否为字符串类型
  • composition-api: 为兼容vue2

Utils

getRect

  • 返回节点尺寸信息

    // 组件内需要传入上下文
    // 如果是nvue 则需要在节点上加与id或class同名的ref
    getRect('#id',{context: this}).then(res => {})
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

addUnit

  • 将未带单位的数值添加px,如果有单位则返回原值

    addUnit(10)
    // 10px
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

unitConvert

  • 将带有rpx|px的字符转成number,若本身是number则直接返回

    unitConvert('10rpx') 
    // 5 设备不同 返回的值也不同
    unitConvert('10px') 
    // 10
    unitConvert(10) 
    // 10
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

canIUseCanvas2d

  • 环境是否支持使用 canvas 2d

    canIUseCanvas2d()
    // 若支持返回 true 否则 false
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

getCurrentPage

  • 获取当前页

    const page = getCurrentPage()
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

base64ToPath

  • 把base64的图片转成临时路径

    base64ToPath(`xxxxx`).then(res => {})
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

pathToBase64

  • 把图片的临时路径转成base64

    pathToBase64(`xxxxx/xxx.png`).then(res => {})
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

sleep

  • 睡眠,让 async 内部程序等待一定时间后再执行

    async next () => {
    	await sleep(300)
    	console.log('limeui');
    }
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

throttle

  • 节流

    throttle((nama) => {console.log(nama)}, 200)('limeui');
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

debounce

  • 防抖

    debounce((nama) => {console.log(nama)}, 200)('limeui');
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

random

  • 返回指定范围的随机数

    random(1, 5);
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

range

  • 生成区间数组

    range(0, 5)
    // [0,1,2,3,4,5]
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

clamp

  • 夹在min和max之间的数值,如小于min,返回min, 如大于max,返回max,否侧原值返回

    clamp(0, 10, -1)
    // 0
    clamp(0, 10, 11)
    // 10
    clamp(0, 10, 9)
    // 9
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

floatAdd

  • 返回两个浮点数相加的结果

    floatAdd(0.1, 0.2) // 0.3
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

fillZero

  • 补零,如果传入的是个位数则在前面补0

    fillZero(9);
    // 09
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

exif

  • 获取图片exif
  • 支持临时路径、base64

    uni.chooseImage({
    	count: 1, //最多可以选择的图片张数
    	sizeType: "original",
    	success: (res) => {
    		exif.getData(res.tempFiles[0], function() {
    			let tagj = exif.getTag(this, "GPSLongitude");
    			let	Orientation = exif.getTag(this, 'Orientation');  
    			console.log(tagj, Orientation)
    		})
    	}
    })
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | x |

selectComponent

  • 获取页面或当前实例的指定组件,会在页面或实例向所有的节点查找(包括子组件或子子组件)
  • 仅vue3,vue2没有测试过

    // 当前页面
    const page = getCurrentPage()
    selectComponent('.custom', {context: page}).then(res => {
    })
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | x |

createAnimation

  • 创建动画,与uni.createAnimation使用方法一致,只为了抹平nvue

    <view ref="ball" :animation="animationData"></view>
    
    const ball = ref(null)
    const animation = createAnimation({
    transformOrigin: "50% 50%",
    duration: 1000,
    timingFunction: "ease",
    delay: 0
    })
    
    animation.scale(2,2).rotate(45).step()
    // nvue 无导出数据,这样写只为了平台一致,
    // nvue 需要把 ref 传入,其它平台不需要
    const animationData = animation.export(ball.value)
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

camelCase

  • 将字符串转换为 camelCase 或 PascalCase 风格的命名约定

    camelCase("hello world") // helloWorld
    camelCase("hello world", true) // HelloWorld
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

kebabCase

  • 将字符串转换为指定连接符的命名约定

    kebabCase("helloWorld") // hello-world
    kebabCase("hello world_example") // hello-world-example
    kebabCase("helloWorld", "_") // hello_world
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

closest

  • 在给定数组中找到最接近目标数字的元素

    closest([1, 3, 5, 7, 9], 6) // 5
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

isBase64

  • 判断字符串是否为base64

    isBase64('xxxxx')
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

isNumber

  • 检查一个值是否为数字类型

    isNumber('0') // false
    isNumber(0) // true
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

isNumeric

  • 检查一个值是否为数字类型或表示数字的字符串

    isNumeric('0') // true
    isNumeric(0) // true
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

isString

  • 检查一个值是否为数字类型或表示数字的字符串

    isString('0') // true
    isString(0) // false
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | √ |

composition-api

  • 因本人插件需要兼容vue2/vue3,故增加一个vue文件,代替条件编译
  • vue2需要在main.js加上这一段

    // vue2
    import Vue from 'vue'
    import VueCompositionAPI from '@vue/composition-api'
    Vue.use(VueCompositionAPI)
    
    //使用
    import {computed, onMounted, watch, reactive} from '@/uni_modules/lime-shared/vue'
    
兼容性

| uni-app | uni-app x | |------------|----------------------------------| | √ | x |