|
- /*
- * @Date: 2022-01-19 16:39:51
- * @LastEditors: JinxChen
- * @LastEditTime: 2022-04-13 16:22:59
- * @FilePath: \AntpayFrontEnd\src\utils\index.js
- * @description: 工具类
- */
-
-
- /**
- * 判断是否为空
- */
- export function isNull(o) {
- if (o === null || o === undefined || o === '') {
- return true;
- // eslint-disable-next-line
- } else if (Array.prototype.isPrototypeOf(o) && o.length === 0) {
- return true;
- // eslint-disable-next-line
- } else if (Object.prototype.isPrototypeOf(o) && Object.keys(o).length === 0) {
- return true;
- }
- return false;
- }
- /**
- * 判断是否为非空
- */
- export function isNotNull(o) {
- return !isNull(o);
- }
-
- // 判断用户是否是支付宝浏览器
- export function isAlipayBrowser(userAgent) {
- if (/AlipayClient/.test(userAgent)) {
- console.log("当前浏览器是支付宝浏览器");
- return true;
- } else {
- console.log("当前浏览器是非支付宝浏览器");
- return false;
- }
- }
-
- // 判断用户的设备是否是android
- export function isAndroid(userAgent) {
- if (userAgent.indexOf('Android') > -1 || userAgent.indexOf('Linux') > -1) {
- console.log("当前用户设备是android");
- return true;
- } else if (userAgent.indexOf('iPhone') > -1) {
- console.log("当前用户设备是ios");
- return false;
- }
- }
-
-
- // 初始化分期数数组, 1. 如果 分数数组面 包含有 '1' 并且还有其它'12' '24'两个分期, 则把 '1'删掉
- // 2. 否则直接返回该数组
- export function intCount(array) {
- let index = array.some(item => item === '1');
- if( index) {
- // 大于-1表示存在
- let newArray = array.splice(1, 2);
- return newArray;
- // 存在就删除
- } else {
- return array;
- }
- }
-
-
- // 通过接口返回的数组判读是否显示花呗或者支付宝,, 1. 1 12 24 都存在则支付宝花呗全都显示
- // 2. 只有 1 则 只显示支付宝
- // 3. 没有 1 则显示花呗
- export function isShowAlipay(array) {
- let index = array.indexOf('1');
- if(index > -1 && array.length === 1 ) {
- return true;
- } else if (index > -1 && array.length > 2) {
- return true;
- } else {
- return false;
- }
- }
-
- export function isShowAntpay(array) {
- let index = array.indexOf('1');
- if(index < 0 && array.length >= 1) {
- return true;
- } else {
- return false;
- }
- }
|