You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.1 KiB
125 lines
3.1 KiB
import configdata from './config'
|
|
import cache from './cache'
|
|
import aes from "@/common/aes.js";
|
|
module.exports = {
|
|
config: function (name) {
|
|
var info = null;
|
|
if (name) {
|
|
var name2 = name.split("."); //字符分割
|
|
if (name2.length > 1) {
|
|
info = configdata[name2[0]][name2[1]] || null;
|
|
} else {
|
|
info = configdata[name] || null;
|
|
}
|
|
if (info == null) {
|
|
let web_config = cache.get("web_config");
|
|
if (web_config) {
|
|
if (name2.length > 1) {
|
|
info = web_config[name2[0]][name2[1]] || null;
|
|
} else {
|
|
info = web_config[name] || null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return info;
|
|
},
|
|
post: function (url, data, headerContentType, tentId, needAes, auth) {
|
|
console.log(url, data, headerContentType, tentId, needAes, 'post请求参数');
|
|
|
|
if (needAes !== false) {
|
|
for (var key in data) {
|
|
data[key] = aes.aesMinEncrypt(data[key]);
|
|
}
|
|
}
|
|
|
|
headerContentType = headerContentType == "json" ? "application/json" : "application/x-www-form-urlencoded";
|
|
|
|
let headers = {
|
|
"content-type": headerContentType
|
|
};
|
|
|
|
if (auth==true) {
|
|
const tok = store.state.userInfo.accessToken || uni.getStorageSync('userInfo').accessToken;
|
|
headers['Authorization'] = 'Bearer ' + tok;
|
|
}
|
|
|
|
if (tentId && tentId !== "" && tentId !== null && tentId !== undefined) {
|
|
headers['tenant-id'] = tentId;
|
|
}
|
|
|
|
return new Promise((succ, error) => {
|
|
uni.request({
|
|
url: url,
|
|
data: headerContentType == "application/json" ? JSON.stringify(data) : data,
|
|
method: "POST",
|
|
header: headers,
|
|
xhrFields: {
|
|
withCredentials: true // 这里设置了withCredentials
|
|
},
|
|
success: function (result) {
|
|
succ.call(self, result.data);
|
|
},
|
|
fail: function (e) {
|
|
error.call(self, e);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
|
|
get: function (url, data, headerContentType, tentId, needAes, auth) {
|
|
console.log(url, data, headerContentType, tentId, needAes, 'get请求参数');
|
|
headerContentType = headerContentType ? headerContentType : "application/x-www-form-urlencoded";
|
|
|
|
let headers = {
|
|
"content-type": headerContentType
|
|
};
|
|
|
|
if (auth == true) {
|
|
const tok = store.state.userInfo.accessToken || uni.getStorageSync('userInfo').accessToken;
|
|
headers['Authorization'] = 'Bearer ' + tok;
|
|
}
|
|
|
|
if (tentId && tentId !== "" && tentId !== null && tentId !== undefined) {
|
|
headers['tenant-id'] = tentId;
|
|
}
|
|
|
|
return new Promise((succ, error) => {
|
|
uni.request({
|
|
url: url,
|
|
data: data,
|
|
method: "GET",
|
|
header: headers,
|
|
success: function (result) {
|
|
succ.call(self, result.data);
|
|
},
|
|
fail: function (e) {
|
|
error.call(self, e);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
// 写法示例
|
|
// var data = {
|
|
// "pageno": "1",
|
|
// "pagesize": "10",
|
|
// "sort": "-2",
|
|
// "region": "1301",
|
|
// "type": "2907"
|
|
// }
|
|
// this.$Request.post(this.$config.messagelist, data).then(
|
|
// res => {
|
|
// console.log(">>>"+JSON.stringify(res));
|
|
// var d = res.data;
|
|
// for (var i = 0; i < d.length; i++) {
|
|
// d[i].logo = this.$config.ROOTPATH + d[i].logo;
|
|
// }
|
|
// this.mudidiList = res.data;
|
|
// },
|
|
// error => {//请求进入fail错误方法,返回接收
|
|
// console.log(">>>"+JSON.stringify(error));
|
|
// }
|
|
// )
|
|
|