| | |
| | | import { prefix } from './config'; |
| | | const systemInfo = wx.getSystemInfoSync(); |
| | | export const systemInfo = wx.getSystemInfoSync(); |
| | | export const debounce = function (func, wait = 500) { |
| | | let timerId; |
| | | return function (...rest) { |
| | |
| | | .join('; '); |
| | | }; |
| | | export const getAnimationFrame = function (context, cb) { |
| | | return wx |
| | | return context |
| | | .createSelectorQuery() |
| | | .in(context) |
| | | .selectViewport() |
| | | .boundingClientRect() |
| | | .exec(() => { |
| | |
| | | }; |
| | | export const getRect = function (context, selector, needAll = false) { |
| | | return new Promise((resolve, reject) => { |
| | | wx.createSelectorQuery() |
| | | .in(context)[needAll ? 'selectAll' : 'select'](selector) |
| | | context |
| | | .createSelectorQuery()[needAll ? 'selectAll' : 'select'](selector) |
| | | .boundingClientRect((rect) => { |
| | | if (rect) { |
| | | resolve(rect); |
| | |
| | | .exec(); |
| | | }); |
| | | }; |
| | | const isDef = function (value) { |
| | | return value !== undefined && value !== null; |
| | | }; |
| | | export const isNumber = function (value) { |
| | | return /^\d+(\.\d+)?$/.test(value); |
| | | }; |
| | | export const isNull = function (value) { |
| | | return value === null; |
| | | }; |
| | | export const isUndefined = (value) => typeof value === 'undefined'; |
| | | export const isDef = function (value) { |
| | | return !isUndefined(value) && !isNull(value); |
| | | }; |
| | | export const addUnit = function (value) { |
| | | if (!isDef(value)) { |
| | |
| | | value = String(value); |
| | | return isNumber(value) ? `${value}px` : value; |
| | | }; |
| | | export const getCharacterLength = (type, str, max) => { |
| | | if (!str || str.length === 0) { |
| | | export const getCharacterLength = (type, char, max) => { |
| | | const str = String(char !== null && char !== void 0 ? char : ''); |
| | | if (str.length === 0) { |
| | | return { |
| | | length: 0, |
| | | characters: '', |
| | |
| | | } |
| | | return parseInt(value, 10); |
| | | } |
| | | return value; |
| | | return value !== null && value !== void 0 ? value : 0; |
| | | }; |
| | | export const setIcon = (iconName, icon, defaultIcon) => { |
| | | if (icon) { |
| | |
| | | const computedSize = typeof sizeLimit === 'number' ? sizeLimit * base : (sizeLimit === null || sizeLimit === void 0 ? void 0 : sizeLimit.size) * unitMap[(_a = sizeLimit === null || sizeLimit === void 0 ? void 0 : sizeLimit.unit) !== null && _a !== void 0 ? _a : 'KB']; |
| | | return size > computedSize; |
| | | }; |
| | | export const rpx2px = (rpx) => Math.floor((systemInfo.windowWidth * rpx) / 750); |
| | | export const nextTick = () => { |
| | | return new Promise((resolve) => { |
| | | wx.nextTick(() => { |
| | | resolve(); |
| | | }); |
| | | }); |
| | | }; |