var config = require('./config.js');
|
|
import MD5G from './md5utf-8.js';
|
|
//排序的函数
|
|
function objKeySort(arys) {
|
|
var newkey = Object.keys(arys).sort();
|
|
var newObj = {};
|
|
for (var i = 0; i < newkey.length; i++) {
|
|
newObj[newkey[i]] = arys[newkey[i]];
|
|
}
|
|
return newObj; //返回排好序的新对象
|
|
}
|
|
//转换为json字符串
|
|
function Jsonstr(data){
|
|
var obj = {};
|
|
for (var key in data) {
|
|
obj[key] = data[key]
|
|
}
|
|
return JSON.stringify(obj);
|
|
}
|
|
|
|
//api签名
|
|
function getSign(params) {
|
|
var str = '';
|
|
var sortparams = objKeySort(params);
|
|
for (var p in sortparams) {
|
|
if (params[p] != '') {
|
|
str += p + '=' + params[p] + '&';
|
|
}
|
|
}
|
|
str = str + config.ACCESS;
|
|
str = MD5G.md5(str);
|
|
return str.toLowerCase();
|
|
}
|
|
function showLoading(){
|
|
uni.showLoading({
|
|
title: '加载中...',
|
|
duration: 10000
|
|
});
|
|
|
|
}
|
|
function hideLoading(){
|
|
uni.hideLoading();
|
|
}
|
|
|
|
function showToast(title){
|
|
uni.showToast({
|
|
title: title,
|
|
icon: "none",
|
|
duration: 2000,
|
|
mask:false
|
|
})
|
|
}
|
|
|
|
function showToastSuccess(title){
|
|
uni.showToast({
|
|
title: title,
|
|
icon: "success",
|
|
duration: 2000,
|
|
mask:false
|
|
})
|
|
}
|
|
function Urlencode(str) {
|
|
str = (str + '').toString();
|
|
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
|
|
replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
|
|
}
|
|
function GetUrlKey(name){
|
|
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
|
|
}
|
|
/**
|
|
* 是否存在字符
|
|
* @param {Object} value
|
|
*/
|
|
function isExist(value) {
|
|
if (value !== null && value !== undefined && value !== "undefined" && value !== "null" && value.length > 0) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
export default {
|
|
getSign:getSign,
|
|
showToast:showToast,
|
|
showLoading:showLoading,
|
|
hideLoading:hideLoading,
|
|
showToastSuccess:showToastSuccess,
|
|
Urlencode:Urlencode,
|
|
GetUrlKey:GetUrlKey,
|
|
isExist:isExist
|
|
}
|