时空网前端
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.

24 lines
636 B

  1. /*
  2. 全局共享实用方法 shared.js
  3. */
  4. // 判断对错/是否显示,万能校验
  5. export function isRight(obj) {
  6. if (isValueType(obj) === 'string') {
  7. obj = obj.trim();
  8. if (obj === 'null' || obj === 'undefined') {
  9. return false;
  10. }
  11. } else if (isValueType(obj) === 'number' && (isValueType(obj) === "number" && !isNaN(obj)) && obj !== 0) {
  12. return true;
  13. }
  14. for (var key in obj) {
  15. return true;
  16. }
  17. return false;
  18. }
  19. // 判断一个值所属的类型,返回一个字符串
  20. export function isValueType(value) {
  21. let str = Object.prototype.toString.call(value);
  22. return str.match(/\[object (.*?)\]/)[1].toLowerCase();
  23. }