riku
2025-04-27 f46786f11c5c08ead7501a82e5a71430ad69b782
miniprogram_npm/tdesign-miniprogram/common/utils.js
@@ -1,5 +1,5 @@
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) {
@@ -67,9 +67,8 @@
        .join('; ');
};
export const getAnimationFrame = function (context, cb) {
    return wx
    return context
        .createSelectorQuery()
        .in(context)
        .selectViewport()
        .boundingClientRect()
        .exec(() => {
@@ -78,8 +77,8 @@
};
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);
@@ -91,11 +90,15 @@
            .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)) {
@@ -104,8 +107,9 @@
    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: '',
@@ -168,7 +172,7 @@
        }
        return parseInt(value, 10);
    }
    return value;
    return value !== null && value !== void 0 ? value : 0;
};
export const setIcon = (iconName, icon, defaultIcon) => {
    if (icon) {
@@ -231,3 +235,11 @@
    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();
        });
    });
};