You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
/* 全局共享实用方法 shared.js */
// 设置角标, 必须传入下标值,设置值可传可不传,传参时显示,不传时移除角标
function setBadge(index = 0, value){ if(isRight(value)){ uni.setTabBarBadge({ index: Number(index), text: value > 99 ? '99+' : String(value) }) }else{ uni.removeTabBarBadge({index: Number(index)}); }}
// 判断对错/是否显示,万能校验
function isRight(obj) { if (isValueType(obj) === 'string') { obj = obj.trim(); if (obj === 'null' || obj === 'undefined') { return false; } } else if (isValueType(obj) === 'number' && (isValueType(obj) === "number" && !isNaN(obj)) && obj !== 0) { return true; } for (var key in obj) { return true; } return false;}
// 判断一个值所属的类型,返回一个字符串
function isValueType(value) { let str = Object.prototype.toString.call(value); return str.match(/\[object (.*?)\]/)[1].toLowerCase();}
module.exports = { setBadge, isRight, isValueType}
|