mina-tool

小程序实用工具库,包含组件、wxs、behaviors、wxss几个维度


Keywords
yrobot, mina, tools, components, behaviors, wxs, wxss
License
ISC
Install
npm install mina-tool@1.0.0

Documentation

mina-tool

小程序 开发实用工具集合
主要包含几个维度:

  1. 组件
  2. behaviors
  3. wxs
  4. 样式

安装

  1. npm install mina-tool
  2. 微信开发者工具编译 npm 包

组件

popup-window

快速实现全屏浮动弹窗

使用
{
  "usingComponents": {
    "popup-window": "mina-tool/components/popup-window"
  }
}
<popup-window
  selector="{{selector}}"
  id="popup-window"
  tap-bg-close="{{true}}"
  catch-scroll="{{true}}"
  scroll-bg-close="{{true}}"
  visible="{{true}}"
  background-color="rgba(0,0,0,0.4)"
>
  <!-- popup-window内部展示slot -->
</popup-window>

multi-picker

在小程序原生 picker - multiSelector 的基础上封装一层逻辑
feature:

  1. 封装一层中间选择状态,保证选择过程中不会 trigger 外部状态变化
  2. bindcancel 时自动将 picker 选择状态更新为外部状态,保证每次点开 picker 时的选中项和外部状态保持一致
  3. 通过 getRanges,函数式更新 range 值,代码更简洁
使用
{
  "usingComponents": {
    "multi-picker": "mina-tool/components/multi-picker"
  }
}
<multi-picker
  getRanges="{{getRanges}}"
  rangeKey="title"
  value="{{value}}"
  bindchange="{{onChange}}"
  bindcancel="{{onCancel}}"
>
  <!-- multi-picker内部展示slot -->
</multi-picker>

error-img

在 img 的 src 展示失败时,自动用 err 属性值更新 src 作为展示兜底

使用
{
  "usingComponents": {
    "error-img": "mina-tool/components/error-img"
  }
}
<error-img err="{{err_img_url}}" ...其他image属性 />

data-status

封装 数据请求展示过程中的一些状态展示:loading、empty、show_data

使用
{
  "usingComponents": {
    "data-status": "mina-tool/components/data-status"
  }
}
<data-status min-height="600rpx" loading="{{loading}}" empty="{{empty}}">
  <!-- data展示slot -->
</data-status>

wxs

format.wxs

展示格式化:formatNumber, formatTime

使用
<wxs src="mina-tool/wxs/format.wxs" module="format" />
...
<!-- 98.6万 -->
<view class="number">{{format.formatNumber(985800)}}</view>
<!-- 1.45亿 -->
<view class="number">{{format.formatNumber(145004545)}}</view>
<!-- 2021-01-04 -->
<view class="date">{{format.formatTime(1609756055278,'YYYY-MM-dd')}}</view>
...