project init & fix ui
This commit is contained in:
72
miniprogram_npm/tdesign-miniprogram/common/utils.wxs
Normal file
72
miniprogram_npm/tdesign-miniprogram/common/utils.wxs
Normal file
@@ -0,0 +1,72 @@
|
||||
/* utils */
|
||||
|
||||
/**
|
||||
* addUnit */
|
||||
// 为 css 添加单位
|
||||
function addUnit(value) {
|
||||
var REGEXP = getRegExp('^\d+(.\d+)?$');
|
||||
if (value == null) {
|
||||
return undefined;
|
||||
}
|
||||
return REGEXP.test('' + value) ? value + 'px' : value;
|
||||
}
|
||||
|
||||
function isString(string) {
|
||||
return string && string.constructor === 'String';
|
||||
}
|
||||
|
||||
function isArray(array) {
|
||||
return array && array.constructor === 'Array';
|
||||
}
|
||||
|
||||
function isObject(obj) {
|
||||
return obj && obj.constructor === 'Object';
|
||||
}
|
||||
|
||||
var isNoEmptyObj = function (obj) {
|
||||
return isObject(obj) && JSON.stringify(obj) !== '{}';
|
||||
};
|
||||
|
||||
function includes(arr, value) {
|
||||
if (!arr || !isArray(arr)) return false;
|
||||
|
||||
var i = 0;
|
||||
var len = arr.length;
|
||||
|
||||
for (; i < len; i++) {
|
||||
if (arr[i] === value) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function cls(base, arr) {
|
||||
var res = [base];
|
||||
var i = 0;
|
||||
for (size = arr.length; i < size; i++) {
|
||||
var item = arr[i];
|
||||
|
||||
if (item && item.constructor === 'Array') {
|
||||
var key = arr[i][0];
|
||||
var value = arr[i][1];
|
||||
|
||||
if (value) {
|
||||
res.push(base + '--' + key);
|
||||
}
|
||||
} else if (typeof item === 'string') {
|
||||
if (item) {
|
||||
res.push(base + '--' + item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res.join(' ');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
addUnit: addUnit,
|
||||
isString: isString,
|
||||
isArray: isArray,
|
||||
isObject: isObject,
|
||||
isNoEmptyObj: isNoEmptyObj,
|
||||
includes: includes,
|
||||
cls: cls,
|
||||
};
|
||||
Reference in New Issue
Block a user