import md5_js from './md5.js'
export default {
user() {
return uni.getStorageSync('userinfo')
},
token() {
return uni.getStorageSync('Accesstoken')
},
sendRequest(url, data, toast,method="GET",header="application/x-www-form-urlencoded") {
var promise = new Promise(function(resolve, reject) {
const value = uni.getStorageSync('userinfo');
var toolData = {}
// #ifdef APP-PLUS
if (uni.getSystemInfoSync().platform == 'ios') {
toolData.source = 2
} else {
toolData.source = 1
}
// #endif
// #ifdef MP-WEIXIN
toolData.source = 3
// #endif
if (value) {
toolData.uid = value.id
toolData.token = value.token
toolData.cityid = value.cityid
}
const system_info = uni.getStorageSync('system_info')
const Accesstoken = uni.getStorageSync('Accesstoken')
var lag = system_info.language ? system_info.language : 'th-TH'
// #ifdef APP-PLUS
lag = system_info.appLanguage ? system_info.appLanguage : 'th-TH'
// #endif
const cur_lang = lag.indexOf('zh') != -1 ? toolData.lang ='zh' : toolData.lang ='th'
const baseUrl = getApp().globalData.mainurl
console.log("---->",url,data)
uni.request({
url: baseUrl + url,
data: data,
method,
header: {
"content-type": header,
appYSToken:Accesstoken
}, // 请求头
success: function(res) {
console.log("<----",url,res,res.data.code)
setTimeout(() => {
uni.hideLoading();
}, 400)
if (toast) {
uni.showToast({
title: res.data.message,
icon: 'none'
})
}
resolve(res.data)
// if (res.data.code === 401) {
// uni.reLaunch({
// url: '/pages/login/login'
// })
// }
// if (res.data.code == 200) {
// if (res.data.data.code == 0) {
// resolve(res.data)
// } else {
// reject(res.data.data)
// }
// } else {
// console.log(res.data)
// reject(res.data.data)
// uni.showToast({
// title: res.data.msg,
// icon: 'none'
// })
// }
},
fail: function(err) {
console.log(err)
uni.hideLoading();
}
})
})
return promise;
},
checktoken() {
var promise = new Promise(function(resolve, reject) {
const value = uni.getStorageSync('userinfo');
uni.request({
url: getApp().globalData.mainurl + 'Rider.User.Iftoken',
method: 'POST',
data: {
'uid': value.id,
'token': value.token
},
success: res => {
uni.hideLoading()
if (res.data.data.code == 0) {
resolve(res.data.data)
} else {
reject(res.data.data)
}
},
fail: () => {
uni.hideLoading()
},
complete: () => {
uni.hideLoading()
}
});
})
return promise;
},
decypt(code) {
var newcode = '';
var str = '1ecxXyLRB.COdrAi:q09Z62ash-QGn8VFNIlb=fM/D74WjS_EUzYuw?HmTPvkJ3otK5gp&*'
for (var i = 0; i < code.length; i++) {
var codeIteam = code[i];
for (var j = 0; j < str.length; j++) {
var stringIteam = str[j];
if (codeIteam == stringIteam) {
if (j == 0) {
newcode += str[str.length - 1];
} else {
newcode += str[j - 1];
}
}
}
}
return newcode;
},
sort2url(arr1) {
var newkey = Object.keys(arr1).sort();
var newObj = {};
for (var i = 0; i < newkey.length; i++) {
newObj[newkey[i]] = arr1[newkey[i]];
}
var text = "";
for (var index in newObj) {
text = text + index + "=" + newObj[index] + "&";
}
text = text.substr(0, text.length - 1);
text += '&' + '400d069a791d51ada8af3e6c2979bcd7';
return md5_js(text);
},
getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
},
formatRichText(html) {
if (html == undefined) {
return ''
}
let newContent = html.replace(/
]*>/gi, function(match, capture) {
match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
return match;
});
newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
'max-width:100%;');
return match;
});
newContent = newContent.replace(/
]*\/>/gi, '');
newContent = newContent.replace(/\
{
const value = uni.getStorageSync('userinfo');
uni.request({
url: getApp().globalData.mainurl + 'Login.GetWechatInfo',
method: 'GET',
data: {
'uid': value.id,
'token': value.token,
'code': code
},
success: res => {
if (res.data.data.code == 0) {
var openid = res.data.data.info[0].openid
getApp().globalData.openid = openid
uni.setStorage({
key: 'openid',
data: openid
})
resolve(openid)
} else {
uni.showToast({
title: res.data.data.msg,
icon: 'none'
});
}
},
});
});
},
}