天波h5前端应用
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

91 行
2.4KB

  1. /*
  2. * @Date: 2022-01-19 16:39:51
  3. * @LastEditors: JinxChen
  4. * @LastEditTime: 2022-04-13 16:22:59
  5. * @FilePath: \AntpayFrontEnd\src\utils\index.js
  6. * @description: 工具类
  7. */
  8. /**
  9. * 判断是否为空
  10. */
  11. export function isNull(o) {
  12. if (o === null || o === undefined || o === '') {
  13. return true;
  14. // eslint-disable-next-line
  15. } else if (Array.prototype.isPrototypeOf(o) && o.length === 0) {
  16. return true;
  17. // eslint-disable-next-line
  18. } else if (Object.prototype.isPrototypeOf(o) && Object.keys(o).length === 0) {
  19. return true;
  20. }
  21. return false;
  22. }
  23. /**
  24. * 判断是否为非空
  25. */
  26. export function isNotNull(o) {
  27. return !isNull(o);
  28. }
  29. // 判断用户是否是支付宝浏览器
  30. export function isAlipayBrowser(userAgent) {
  31. if (/AlipayClient/.test(userAgent)) {
  32. console.log("当前浏览器是支付宝浏览器");
  33. return true;
  34. } else {
  35. console.log("当前浏览器是非支付宝浏览器");
  36. return false;
  37. }
  38. }
  39. // 判断用户的设备是否是android
  40. export function isAndroid(userAgent) {
  41. if (userAgent.indexOf('Android') > -1 || userAgent.indexOf('Linux') > -1) {
  42. console.log("当前用户设备是android");
  43. return true;
  44. } else if (userAgent.indexOf('iPhone') > -1) {
  45. console.log("当前用户设备是ios");
  46. return false;
  47. }
  48. }
  49. // 初始化分期数数组, 1. 如果 分数数组面 包含有 '1' 并且还有其它'12' '24'两个分期, 则把 '1'删掉
  50. // 2. 否则直接返回该数组
  51. export function intCount(array) {
  52. let index = array.some(item => item === '1');
  53. if( index) {
  54. // 大于-1表示存在
  55. let newArray = array.splice(1, 2);
  56. return newArray;
  57. // 存在就删除
  58. } else {
  59. return array;
  60. }
  61. }
  62. // 通过接口返回的数组判读是否显示花呗或者支付宝,, 1. 1 12 24 都存在则支付宝花呗全都显示
  63. // 2. 只有 1 则 只显示支付宝
  64. // 3. 没有 1 则显示花呗
  65. export function isShowAlipay(array) {
  66. let index = array.indexOf('1');
  67. if(index > -1 && array.length === 1 ) {
  68. return true;
  69. } else if (index > -1 && array.length > 2) {
  70. return true;
  71. } else {
  72. return false;
  73. }
  74. }
  75. export function isShowAntpay(array) {
  76. let index = array.indexOf('1');
  77. if(index < 0 && array.length >= 1) {
  78. return true;
  79. } else {
  80. return false;
  81. }
  82. }