This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
yoshop-wechat/utils/util.js

76 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-04-25 22:59:04 +08:00
/**
* 工具类
*/
module.exports = {
/**
* scene解码
*/
scene_decode(e) {
if (e === undefined)
return {};
let scene = decodeURIComponent(e),
params = scene.split(','),
data = {};
for (let i in params) {
var val = params[i].split(':');
val.length > 0 && val[0] && (data[val[0]] = val[1] || null)
}
return data;
},
/**
* 格式化日期格式 (用于兼容ios Date对象)
*/
format_date(time) {
// 将xxxx-xx-xx的时间格式转换为 xxxx/xx/xx的格式
return time.replace(/\-/g, "/");
},
/**
* 对象转URL
*/
urlEncode(data) {
var _result = [];
for (var key in data) {
var value = data[key];
if (value.constructor == Array) {
value.forEach(_value => {
_result.push(key + "=" + _value);
});
} else {
_result.push(key + '=' + value);
}
}
return _result.join('&');
},
/**
* 遍历对象
*/
objForEach(obj, callback) {
Object.keys(obj).forEach((key) => {
callback(obj[key], key);
});
},
/**
* 是否在数组内
*/
inArray(search, array) {
for (var i in array) {
if (array[i] == search) {
return true;
}
}
return false;
},
/**
* 判断是否为正整数
*/
isPositiveInteger(value) {
return /(^[0-9]\d*$)/.test(value);
},
};