76 lines
1.4 KiB
JavaScript
76 lines
1.4 KiB
JavaScript
/**
|
||
* 工具类
|
||
*/
|
||
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);
|
||
},
|
||
|
||
}; |