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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. import store from "@/store";
  9. /**
  10. * 判断是否为空
  11. */
  12. export function isNull(o) {
  13. if (o === null || o === undefined || o === '') {
  14. return true;
  15. // eslint-disable-next-line
  16. } else if (Array.prototype.isPrototypeOf(o) && o.length === 0) {
  17. return true;
  18. // eslint-disable-next-line
  19. } else if (Object.prototype.isPrototypeOf(o) && Object.keys(o).length === 0) {
  20. return true;
  21. }
  22. return false;
  23. }
  24. /**
  25. * 判断是否为非空
  26. */
  27. export function isNotNull(o) {
  28. return !isNull(o);
  29. }
  30. // 判断用户是否是支付宝浏览器
  31. export function isAlipayBrowser(userAgent) {
  32. if (/AlipayClient/.test(userAgent)) {
  33. console.log("当前浏览器是支付宝浏览器");
  34. return true;
  35. } else {
  36. console.log("当前浏览器是非支付宝浏览器");
  37. return false;
  38. }
  39. }
  40. // 判断用户的设备是否是android
  41. export function isAndroid(userAgent) {
  42. if (userAgent.indexOf('Android') > -1 || userAgent.indexOf('Linux') > -1) {
  43. console.log("当前用户设备是android");
  44. return true;
  45. } else if (userAgent.indexOf('iPhone') > -1) {
  46. console.log("当前用户设备是ios");
  47. return false;
  48. }
  49. }
  50. // 初始化分期数数组, 1. 如果 分数数组面 包含有 '1' 并且还有其它'12' '24'两个分期, 则把 '1'删掉
  51. // 2. 否则直接返回该数组
  52. export function intCount(array) {
  53. let index = array.some(item => item === '1');
  54. if( index) {
  55. // 大于-1表示存在
  56. let newArray = array.splice(1, 2);
  57. return newArray;
  58. // 存在就删除
  59. } else {
  60. return array;
  61. }
  62. }
  63. // 通过接口返回的数组判读是否显示花呗或者支付宝,, 1. 1 12 24 都存在则支付宝花呗全都显示
  64. // 2. 只有 1 则 只显示支付宝
  65. // 3. 没有 1 则显示花呗
  66. export function isShowAlipay(array) {
  67. let index = array.indexOf('1');
  68. if(index > -1 && array.length === 1 ) {
  69. return true;
  70. } else if (index > -1 && array.length > 2) {
  71. return true;
  72. } else {
  73. return false;
  74. }
  75. }
  76. export function isShowAntpay(array) {
  77. let index = array.indexOf('1');
  78. if(index < 0 && array.length >= 1) {
  79. return true;
  80. } else {
  81. return false;
  82. }
  83. }
  84. // 将传入内容的某个文字全部替换成指定的文字
  85. /**
  86. *
  87. * @param {*} target 目标字符串
  88. * @param {*} searchValue 要搜索和替换的子串
  89. * @param {*} replacement 替换的新字符串
  90. * @returns
  91. */
  92. export function replaceAll(target, searchValue, replacement) {
  93. // 应用类型,目前1 是健康好蕴,其他则不替换
  94. const appTypeList = ['1'];
  95. const appType = store.getters.appType;
  96. if(appTypeList.indexOf(appType) > -1) {
  97. if(isNotNull(target) && isNotNull(searchValue)) {
  98. if(target.includes(searchValue)) {
  99. return target.replace(new RegExp(searchValue, 'g'), replacement);
  100. } else {
  101. return target
  102. }
  103. } else {
  104. return target
  105. }
  106. } else {
  107. return target
  108. }
  109. }