141 lines
4.3 KiB
JavaScript
141 lines
4.3 KiB
JavaScript
import Store from '../store/store'
|
||
import { encryptAES } from './handleAes.js'
|
||
const publicOptions = (() => { // 获取本机的信息
|
||
let systemInfo = uni.getSystemInfoSync()
|
||
return {
|
||
APPGuid: "9880519c-351d-4a05-b6ef-80db0286a7ab",
|
||
SourcePlatform: 'minProgram', // 客户端平台
|
||
brand: systemInfo.brand || '', // 设备名称
|
||
model: encodeURIComponent(systemInfo.model), // 机型
|
||
os_version: systemInfo.system, // 安卓版本号
|
||
|
||
}
|
||
})()
|
||
|
||
export default {
|
||
/**
|
||
* 自定义post,get函数,返回Promise
|
||
* @param {String} url 接口网址
|
||
* @param {arrayObject} data 要传的数组对象 例如: {name: '武当山道士', age: 32}
|
||
* +-------------------
|
||
* @return {Promise} promise 返回promise供后续操作
|
||
*/
|
||
request: function (method, url, data, isWebApi) {
|
||
var promise = new Promise((resolve, reject) => {
|
||
//init
|
||
Store.state.isLoading = true
|
||
var that = this;
|
||
// console.log(Store.state.userData)
|
||
data.provinceCode = '530000' // 如果用户没有省份编码信息,则默认浙江省
|
||
data.time = data.time || (new Date()).getTime()
|
||
data = Object.assign(data, publicOptions);
|
||
data.WeChat_AppId = 'wx6e28691bea93c6ec'
|
||
data.WeChat_MiniProToken = Store.state.userData.WeChat_MiniProToken || ''
|
||
data.WeChatAppId = 'wx6e28691bea93c6ec'
|
||
|
||
data.memberShipId = !data.memberShipId ? (Store.state.userData.Membership_Id || '') :
|
||
data.memberShipId // ||'3255' 1170386 1125717 //
|
||
let requstOptions = {
|
||
url: url,
|
||
data: data,
|
||
method: method,
|
||
}
|
||
let ModuleGuid = ''
|
||
let obj = Store.state.userData.AuthorityInfo
|
||
for (let key in obj) {
|
||
// 经管 财务
|
||
if (key === 'f0889950-f98a-40de-a369-613efeed2579' || key === 'c021bbca-3c0a-478d-81e7-87e81ef80e05') {
|
||
if (obj[key] === 1) {
|
||
if (ModuleGuid === '') {
|
||
ModuleGuid = key
|
||
} else {
|
||
ModuleGuid += `,${key}`
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (method == 'POST' && !isWebApi) {
|
||
requstOptions.header = {
|
||
'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
|
||
'ServerpartCodes': Store.state.userData.UserCityAuthority,
|
||
'ProvinceCode': '530000',
|
||
'ModuleGuid': ModuleGuid,
|
||
'WeChat_AppId': 'wx6e28691bea93c6ec',
|
||
'memberShipId': !data.memberShipId ? (Store.state.userData.Membership_Id || '') : data.memberShipId,
|
||
'SourcePlatform': 'minProgram'
|
||
}
|
||
} else {
|
||
requstOptions.header = {
|
||
'ServerpartCodes': Store.state.userData.UserCityAuthority,
|
||
'ProvinceCode': '530000',
|
||
'ModuleGuid': ModuleGuid,
|
||
'WeChat_AppId': 'wx6e28691bea93c6ec',
|
||
'memberShipId': !data.memberShipId ? (Store.state.userData.Membership_Id || '') : data.memberShipId,
|
||
'SourcePlatform': 'minProgram',
|
||
"UserId": Store.state.userData.UserId,
|
||
}
|
||
}
|
||
|
||
requstOptions.data = requstOptions.data.type === 'encryption' ?
|
||
{
|
||
name: "",
|
||
value: encryptAES(JSON.stringify(requstOptions.data))
|
||
} :
|
||
requstOptions.data.type === 'encryption1' ? {
|
||
postData: encryptAES(JSON.stringify(requstOptions.data))
|
||
} :
|
||
requstOptions.data,
|
||
|
||
|
||
|
||
|
||
requstOptions.success = (res) => {
|
||
|
||
//服务器返回数据
|
||
if (res && (res.statusCode === 200 || res.statusCode === 304 || res.statusCode === 400)) {
|
||
if (res.data && ((res.data.ResultCode != '999' && res.data.ResultCode != undefined) ||
|
||
(res.data.Result_Code != '999' && res.data.Result_Code != undefined))) {
|
||
resolve(res.data);
|
||
} else if (typeof res.data == 'object') { // 兼容招标投标模块
|
||
resolve(res.data);
|
||
} else {
|
||
resolve({
|
||
ResultCode: 999,
|
||
Result_Code: 999
|
||
});
|
||
uni.showToast({
|
||
title: res.data || '服务器错误,请稍后重试',
|
||
icon: 'none'
|
||
})
|
||
}
|
||
} else {
|
||
//返回错误提示信息
|
||
console.log(res)
|
||
reject(res.data);
|
||
// reject("服务器错误,请稍后重试");
|
||
}
|
||
}
|
||
requstOptions.fail = (e) => {
|
||
resolve({
|
||
data: {
|
||
error: '网络连接失败,请重试'
|
||
}
|
||
});
|
||
reject('网络连接失败,请重试');
|
||
}
|
||
requstOptions.complete = () => {
|
||
Store.state.isLoading = false
|
||
}
|
||
//网络请求
|
||
uni.request(requstOptions)
|
||
}).catch(function (reason, request) {
|
||
|
||
uni.showToast({
|
||
title: reason,
|
||
icon: 'none'
|
||
})
|
||
});
|
||
return promise;
|
||
}
|
||
|
||
} |