|
@@ -1,119 +1,140 @@
|
|
|
-import store from '@/store/index.js'
|
|
|
-import config from '@/common/config'
|
|
|
-var num = 1
|
|
|
-//接口api
|
|
|
+import store from "@/store/index.js";
|
|
|
+import config from "@/common/config";
|
|
|
+var num = 1;
|
|
|
+//接口api
|
|
|
// export const BASE_URL = 'https://api.xyyxt.net' //release
|
|
|
-export const BASE_URL = config.BASE_URL // 测试环境
|
|
|
+export const BASE_URL = config.BASE_URL; // 测试环境
|
|
|
// export const BASE_URL = 'http://42.192.164.187:19005' //test(后端本地)
|
|
|
-export const tenantId = config.tenantId // 祥粤云学堂:867735392558919680,祥粤学堂:667735392758919630, 中建云学堂-567735392758918520
|
|
|
+export const tenantId = config.tenantId; // 祥粤云学堂:867735392558919680,祥粤学堂:667735392758919630, 中建云学堂-567735392758918520
|
|
|
|
|
|
export const myRequest = (options) => {
|
|
|
- if (store.state.allowLoading && !options.noLoading) {
|
|
|
- uni.showLoading({
|
|
|
- title: '拼命加载中...',
|
|
|
- mask: true,
|
|
|
- })
|
|
|
- }
|
|
|
+ if (store.state.allowLoading && !options.noLoading) {
|
|
|
+ uni.showLoading({
|
|
|
+ title: "拼命加载中...",
|
|
|
+ mask: true,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // await getTenantId(options)
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let token = uni.getStorageSync("token");
|
|
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- let token = uni.getStorageSync('token')
|
|
|
+ uni.request({
|
|
|
+ url: BASE_URL + options.url,
|
|
|
+ method: options.method || "GET",
|
|
|
+ data: options.data,
|
|
|
+ header: options.noToken
|
|
|
+ ? {
|
|
|
+ TenantId: tenantId,
|
|
|
+ }
|
|
|
+ : {
|
|
|
+ AuthorizationToken:
|
|
|
+ "WX " + (token ? token : uni.getStorageSync("token_temp")),
|
|
|
+ TenantId: tenantId,
|
|
|
+ },
|
|
|
+ success: async (res) => {
|
|
|
+ if (!options.compleLoading) {
|
|
|
+ // 请求的接口有带compleLoading 就不隐藏加载中
|
|
|
+ uni.hideLoading();
|
|
|
+ }
|
|
|
+ if (res.data.code == 401) {
|
|
|
+ if (num <= 2) {
|
|
|
+ if (!uni.getStorageSync("user_account")) {
|
|
|
+ var pages = getCurrentPages(); // 获取栈实例
|
|
|
+ let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
|
|
|
+ if (currentRoute != "pages4/login/login") {
|
|
|
+ uni.navigateTo({
|
|
|
+ url: "/pages4/login/login",
|
|
|
+ });
|
|
|
+ uni.removeStorageSync("h5_code");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ num++;
|
|
|
+ res = await doRequest(options);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ uni.removeStorageSync("user_account");
|
|
|
+ var pages = getCurrentPages(); // 获取栈实例
|
|
|
+ let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
|
|
|
+ if (currentRoute != "pages4/login/login") {
|
|
|
+ uni.navigateTo({
|
|
|
+ url: "/pages4/login/login",
|
|
|
+ });
|
|
|
+ uni.removeStorageSync("h5_code");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resolve(res);
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ uni.hideLoading();
|
|
|
+ uni.showToast({
|
|
|
+ title: "请求接口失败",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ console.log("请求失败err---: ", options.url);
|
|
|
+ if (options.url == "/face/certification/CompareFace") {
|
|
|
+ console.log("人脸识别错误---1:", err);
|
|
|
+ }
|
|
|
+ reject(JSON.stringify(err));
|
|
|
+ },
|
|
|
+ complete: () => {
|
|
|
+ // uni.hideLoading()
|
|
|
+ // uni.hideToast()
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+ async function doRequest(response) {
|
|
|
+ let user_account = uni.getStorageSync("user_account");
|
|
|
+ var datas = {
|
|
|
+ url: "/refreshToken/" + user_account,
|
|
|
+ method: "get",
|
|
|
+ noToken: true,
|
|
|
+ };
|
|
|
+ const res = await myRequest(datas);
|
|
|
+ if (res.data.code === 200) {
|
|
|
+ uni.setStorageSync("token", res.data.data.token);
|
|
|
|
|
|
- uni.request({
|
|
|
- url: BASE_URL + options.url,
|
|
|
- method: options.method || 'GET',
|
|
|
- data: options.data,
|
|
|
- header: options.noToken ? {
|
|
|
- TenantId: tenantId,
|
|
|
- } : {
|
|
|
- AuthorizationToken: 'WX ' + (token ? token : uni.getStorageSync('token_temp')),
|
|
|
- TenantId: tenantId
|
|
|
- },
|
|
|
- success: async (res) => {
|
|
|
- if (!options.compleLoading) { // 请求的接口有带compleLoading 就不隐藏加载中
|
|
|
- uni.hideLoading()
|
|
|
- }
|
|
|
- if (res.data.code == 401) {
|
|
|
- if (num <= 2) {
|
|
|
- if (!uni.getStorageSync('user_account')) {
|
|
|
- var pages = getCurrentPages() // 获取栈实例
|
|
|
- let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
|
|
|
- if (currentRoute != 'pages4/login/login') {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages4/login/login'
|
|
|
- });
|
|
|
- uni.removeStorageSync('h5_code')
|
|
|
- }
|
|
|
- } else {
|
|
|
- num++
|
|
|
- res = await doRequest(options)
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- uni.removeStorageSync('user_account');
|
|
|
- var pages = getCurrentPages() // 获取栈实例
|
|
|
- let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
|
|
|
- if (currentRoute != 'pages4/login/login') {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages4/login/login'
|
|
|
- });
|
|
|
- uni.removeStorageSync('h5_code')
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- resolve(res)
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- uni.hideLoading()
|
|
|
- uni.showToast({
|
|
|
- title: "请求接口失败",
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- console.log('请求失败err---: ', options.url);
|
|
|
- if (options.url == '/face/certification/CompareFace') {
|
|
|
- console.log('人脸识别错误---1:', err)
|
|
|
- }
|
|
|
- reject(JSON.stringify(err))
|
|
|
- },
|
|
|
- complete: () => {
|
|
|
- // uni.hideLoading()
|
|
|
- // uni.hideToast()
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- async function doRequest(response) {
|
|
|
- let user_account = uni.getStorageSync('user_account')
|
|
|
- var datas = {
|
|
|
- url: '/refreshToken/' + user_account,
|
|
|
- method: 'get',
|
|
|
- noToken: true
|
|
|
- }
|
|
|
- const res = await myRequest(datas)
|
|
|
- if (res.data.code === 200) {
|
|
|
- uni.setStorageSync('token', res.data.data.token)
|
|
|
-
|
|
|
- var userInfo = {
|
|
|
- url: '/app/user/getInfo',
|
|
|
- method: 'get',
|
|
|
- data: { fromPlat: 1 }, // 来源平台 1小程序 2PC网站
|
|
|
- }
|
|
|
- const resUser = await myRequest(userInfo)
|
|
|
- if (resUser.data.code === 200) {
|
|
|
- store.state.userInfo = resUser.data.data
|
|
|
- uni.setStorageSync('user_account', user_account)
|
|
|
- num = 1;
|
|
|
- }
|
|
|
- let onset = await myRequest(response)
|
|
|
- return onset
|
|
|
- } else {
|
|
|
- var pages = getCurrentPages() // 获取栈实例
|
|
|
- let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
|
|
|
- console.log('request-->333:', currentRoute);
|
|
|
- if (currentRoute != 'pages4/login/login') {
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages4/login/login'
|
|
|
- });
|
|
|
- uni.removeStorageSync('h5_code')
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+ var userInfo = {
|
|
|
+ url: "/app/user/getInfo",
|
|
|
+ method: "get",
|
|
|
+ data: { fromPlat: 1 }, // 来源平台 1小程序 2PC网站
|
|
|
+ };
|
|
|
+ const resUser = await myRequest(userInfo);
|
|
|
+ if (resUser.data.code === 200) {
|
|
|
+ store.state.userInfo = resUser.data.data;
|
|
|
+ uni.setStorageSync("user_account", user_account);
|
|
|
+ num = 1;
|
|
|
+ }
|
|
|
+ let onset = await myRequest(response);
|
|
|
+ return onset;
|
|
|
+ } else {
|
|
|
+ var pages = getCurrentPages(); // 获取栈实例
|
|
|
+ let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
|
|
|
+ console.log("request-->333:", currentRoute);
|
|
|
+ if (currentRoute != "pages4/login/login") {
|
|
|
+ uni.navigateTo({
|
|
|
+ url: "/pages4/login/login",
|
|
|
+ });
|
|
|
+ uni.removeStorageSync("h5_code");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ function getTenantId(response) {
|
|
|
+ new Promise((resolve, reject) => {
|
|
|
+ uni.request({
|
|
|
+ url: config.BASE_URL + "/app/user/edit/shareActivityCode",
|
|
|
+ method: "POST",
|
|
|
+ success: (res) => {
|
|
|
+ if (res.data.code == 200) {
|
|
|
+ resolve(res.data.data);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ reject(JSON.stringify(err));
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+};
|