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.
101 lines
3.5 KiB
101 lines
3.5 KiB
"use strict"; |
|
const common_vendor = require("../common/vendor.js"); |
|
const store_index = require("../store/index.js"); |
|
const utils_functions = require("./functions.js"); |
|
const config_host = require("../config/host.js"); |
|
const utils_base64 = require("./base64.js"); |
|
const utils_md5 = require("./md5.js"); |
|
const service = (params) => { |
|
return new Promise((relove, reject) => { |
|
let refresh_token = common_vendor.index.getStorageSync("refresh_token"); |
|
let token = common_vendor.index.getStorageSync("access_token"); |
|
let user = common_vendor.index.getStorageSync("userinfo"); |
|
let header = {}; |
|
if (user && token && refresh_token) { |
|
store_index.store.commit("updateislog", true); |
|
store_index.store.commit("updaterftk", refresh_token); |
|
store_index.store.commit("updatetk", token); |
|
store_index.store.commit("updatauser", user); |
|
header["Blade-Auth"] = `bearer ${store_index.store.state.access_token}`; |
|
} else { |
|
if (!token && params.url.indexOf("oauth/token") == -1) { |
|
common_vendor.index.reLaunch({ |
|
url: "/pages/login/login" |
|
}); |
|
utils_functions.api.error("请登录"); |
|
} |
|
} |
|
header.Authorization = `Basic ${utils_base64.base64.encode(config_host.APPKEY)}`; |
|
if (params.url.indexOf("blade-auth/oauth/token") != -1) { |
|
header["Content-Type"] = "application/x-www-form-urlencoded"; |
|
header["Tenant-Id"] = params.data.tenantId; |
|
params.data.password = utils_md5.hexMD5(params.data.password); |
|
} |
|
let urlhd = ""; |
|
if (common_vendor.index.getStorageSync("setip")) { |
|
urlhd = common_vendor.index.getStorageSync("setip"); |
|
} else { |
|
urlhd = config_host.host; |
|
} |
|
function req() { |
|
common_vendor.index.request({ |
|
url: urlhd + params.url, |
|
data: params.data, |
|
method: params.method, |
|
// dataType: "json", |
|
header |
|
}).then((res) => { |
|
common_vendor.index.hideLoading(); |
|
if (res.statusCode == 200) { |
|
let data = res.data; |
|
if (data.code != 200 && (data == null ? void 0 : data.msg)) { |
|
common_vendor.index.showToast({ |
|
title: (data == null ? void 0 : data.msg) || "", |
|
icon: "none" |
|
}); |
|
} else if (data.audio) { |
|
common_vendor.index.showToast({ |
|
title: data.msg, |
|
icon: "none" |
|
}); |
|
} |
|
switch (data.code) { |
|
case 200: |
|
relove(data); |
|
break; |
|
case 203: |
|
relove(data); |
|
break; |
|
default: |
|
relove(data); |
|
break; |
|
} |
|
} else { |
|
if (res.statusCode == 400) { |
|
relove({}); |
|
return; |
|
} else if (res.statusCode == 500) { |
|
utils_functions.api.error("接口出错,请联系后端开发人员"); |
|
return; |
|
} else if (res.statusCode == 401) { |
|
common_vendor.index.reLaunch({ |
|
url: "/pages/login/login" |
|
}); |
|
common_vendor.index.removeStorage({ |
|
key: "access_token" |
|
}); |
|
utils_functions.api.error("请登录"); |
|
return; |
|
} |
|
utils_functions.api.error("连接服务器失败"); |
|
} |
|
}).catch((err) => { |
|
console.log(err); |
|
utils_functions.api.error("请检查是否连接到无线网络"); |
|
common_vendor.index.hideLoading(); |
|
}); |
|
} |
|
req(); |
|
}); |
|
}; |
|
exports.service = service;
|
|
|