From 0746b7bbe6aa3d9f02e03654a2cd4fde2081c335 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期一, 21 四月 2025 09:29:40 +0800 Subject: [PATCH] bug修复 --- miniprogram_npm/tdesign-miniprogram/common/utils.js | 34 +++++++++++++++++++++++----------- 1 files changed, 23 insertions(+), 11 deletions(-) diff --git a/miniprogram_npm/tdesign-miniprogram/common/utils.js b/miniprogram_npm/tdesign-miniprogram/common/utils.js index 2d6daef..95dcaf7 100644 --- a/miniprogram_npm/tdesign-miniprogram/common/utils.js +++ b/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(); + }); + }); +}; -- Gitblit v1.9.3