This commit is contained in:
zoujiandong
2025-06-16 19:01:04 +08:00
parent c1309bc9fc
commit bbc99ec0dd
26 changed files with 488 additions and 260 deletions
+33
View File
@@ -0,0 +1,33 @@
const cookie = {
//写cookies
setCookie: function(name, value) {
//let days = 0.5;
let exp = new Date();
exp.setTime(exp.getTime() + 15*60*1000)
// exp.setTime(exp.getTime() + days*24*60*60*1000)
document.cookie = name + '=' + escape (value) + ';expires=' + exp.toGMTString()
},
//读取cookies
readCookie: function (name) {
let arr = null
let reg = new RegExp('(^| )'+name+'=([^;]*)(;|$)')
if (document.cookie && (arr = document.cookie.match(reg))) {
return unescape(arr[2])
} else {
return null;
}
},
//删除cookies
delCookie: function (name) {
let cval = this.readCookie(name);
var domain = '.igandan.com';
if (cval!=null) {
document.cookie = name + '=;expires=' + (new Date(0)).toGMTString()+";path=/;domain="+domain
}
}
}
export default cookie
+9
View File
@@ -0,0 +1,9 @@
let host='';
let path=window.location.href;
if (path.indexOf("//prod-casedata.igandan.com") > 1 ) {
host = "https://prod-casedata.igandan.com";
} else {
host = "https://dev-casedata.igandan.com";
}
export default host;
+23 -14
View File
@@ -2,10 +2,19 @@ import pageUrl from './pageUrl'
function navTo(obj) {
let token = '';
if (process.env.NODE_ENV === 'development') {
token = uni.getStorageSync('DEV_AUTH_TOKEN_CASEDATA');
} else {
token = uni.getStorageSync('AUTH_TOKEN_CASEDATA');
if(process.env.UNI_PLATFORM =="h5"){
if(window.location.href.indexOf('//casedata.igandan.com')>-1){
token = uni.getStorageSync('AUTH_TOKEN_CASEDATA');
}else{
token = uni.getStorageSync('DEV_AUTH_TOKEN_CASEDATA');
}
}else{
const { envVersion } = uni.getAccountInfoSync().miniProgram;
if (envVersion == "release") {
token = uni.getStorageSync('AUTH_TOKEN_CASEDATA');
}else{
token = uni.getStorageSync('DEV_AUTH_TOKEN_CASEDATA');
}
}
if (!token) {
let page_url = pageUrl();
@@ -14,19 +23,19 @@ function navTo(obj) {
url: '/pages/login/login?redirectUrl=has'
});
} else {
// # ifdef MP-WEIXIN
const pages = getCurrentPages();
if(process.env.UNI_PLATFORM =="h5"){
uni.navigateTo(obj)
}else{
const pages = getCurrentPages();
let len = pages.length;
if (len < 10) {
uni.navigateTo(obj)
} else {
console.log(len)
if (len >=10) {
uni.redirectTo(obj)
} else {
uni.navigateTo(obj)
}
}
// # endif
// # ifdef H5
uni.navigateTo(obj)
//# endif
}
+97 -78
View File
@@ -11,100 +11,119 @@ import BASE_URL from "./config.js";
//import host from "@/utils/host";
//import {msg} from "./util.js"
import pageUrl from './pageUrl'
//alert(BASE_URL)
// # ifdef H5
import cookie from "./cookie.js";
//# endif
//const BASE_URL=host+"/api"
export const request = (url, data = {}, method = 'post',loading = false,contentType='application/x-www-form-urlencoded') => {
if(loading){
export const request = (url, data = {}, method = 'post', loading = false, contentType = 'application/x-www-form-urlencoded') => {
if (loading) {
uni.showLoading({
title: '加载中',
mask:true
title: '加载中',
mask: true
})
};
let token='';
if(process.env.NODE_ENV === 'development'){
token = uni.getStorageSync('DEV_AUTH_TOKEN_CASEDATA');
}else{
token = uni.getStorageSync('AUTH_TOKEN_CASEDATA');
}
// if(!token){
// let freeList=['/login','/code/phone','/login/wx','/index','/user/check'];
// if(freeList.indexOf(url) == -1){
// let page_url=pageUrl();
// if(page_url.indexOf('/login/login')==-1){
// uni.setStorageSync('redirectUrl',page_url);
// uni.navigateTo({
// url: '/pages/login/login?redirectUrl=has'
// });
// return false;
// }else{
// uni.setStorageSync('redirectUrl','');
// uni.navigateTo({
// url: '/pages/login/login'
// });
// return false;
// }
// }
// }
let header = {
'content-type':contentType ,
'Authorization': 'Bearer ' + token
}
return new Promise(function(e, n) {
let token = '';
if(process.env.UNI_PLATFORM =="h5"){
if(window.location.href.indexOf('//casedata.igandan.com')>-1){
token = uni.getStorageSync('AUTH_TOKEN_CASEDATA');
}else{
token = uni.getStorageSync('DEV_AUTH_TOKEN_CASEDATA');
}
}else{
const { envVersion } = uni.getAccountInfoSync().miniProgram;
if (envVersion == "release") {
token = uni.getStorageSync('AUTH_TOKEN_CASEDATA');
}else{
token = uni.getStorageSync('DEV_AUTH_TOKEN_CASEDATA');
}
}
// if(!token){
// let freeList=['/login','/code/phone','/login/wx','/index','/user/check'];
// if(freeList.indexOf(url) == -1){
// let page_url=pageUrl();
// if(page_url.indexOf('/login/login')==-1){
// uni.setStorageSync('redirectUrl',page_url);
// uni.navigateTo({
// url: '/pages/login/login?redirectUrl=has'
// });
// return false;
// }else{
// uni.setStorageSync('redirectUrl','');
// uni.navigateTo({
// url: '/pages/login/login'
// });
// return false;
// }
// }
// }
let header = {
'content-type': contentType,
'Authorization': 'Bearer ' + token
}
return new Promise(function (e, n) {
let timestamp = Date.now();
uni.request({
data,
url: url.indexOf('http')!=-1?url:encodeURI(BASE_URL+url+"?timestamp="+timestamp),
url: url.indexOf('http') != -1 ? url : encodeURI(BASE_URL + url + "?timestamp=" + timestamp),
method: method,
sslVerify:false,
header:url.indexOf('/manager/getSignature4bing')==-1?header:{},
timeout:10000,
success: function(res) {
var Authorization_token = res.header.Authorization;
if(Authorization_token){
if(process.env.NODE_ENV === 'development'){
uni.setStorageSync('DEV_AUTH_TOKEN_CASEDATA', Authorization_token);
}else{
uni.setStorageSync('AUTH_TOKEN_CASEDATA', Authorization_token);
}
}
if(loading){
sslVerify: false,
header: url.indexOf('/manager/getSignature4bing') == -1 ? header : {},
timeout: 10000,
success: function (res) {
var Authorization_token = res.header.Authorization;
if (Authorization_token) {
if (process.env.NODE_ENV === 'development') {
uni.setStorageSync('DEV_AUTH_TOKEN_CASEDATA', Authorization_token);
} else {
uni.setStorageSync('AUTH_TOKEN_CASEDATA', Authorization_token);
}
}
if (loading) {
uni.hideLoading();
};
if(res.data.code==200){
if (res.data.code == 200) {
e(res)
}else if(res.data.code==401 || res.data.code==403 || res.data.code==405 || res.data.code==406){
let freeList=['/login/wechat/mobile','/code/phone','/login/mobile_login','/index','/user/check'];
if(freeList.indexOf(url) == -1){
let page_url=pageUrl();
uni.setStorageSync('redirectUrl',page_url);
uni.navigateTo({
url: '/pages/login/login?redirectUrl=has'
});
return false
}
}else if(res.data.code==500){
} else if (res.data.code == 401 || res.data.code == 403 || res.data.code == 405 || res.data.code == 406) {
if(process.env.UNI_PLATFORM =="h5"){
// let H5url = 'https://dev-wx.igandan.com';
// if (window.location.href.indexOf('//dev-casedata.igandan.com') == -1) {
// H5url = 'https://dev-wx.igandan.com'
// }
// window.location.href = H5url + "/hcp/Signup2020online_tologin?back_url=" + encodeURIComponent(window.location.href);
}else{
let freeList = ['/login/wechat/mobile', '/code/phone', '/login/mobile_login', '/index', '/user/check'];
if (freeList.indexOf(url) == -1) {
let page_url = pageUrl();
uni.setStorageSync('redirectUrl', page_url);
uni.navigateTo({
url: '/pages/login/login?redirectUrl=has'
});
return false
}
}
} else if (res.data.code == 500) {
n(res)
}else{
} else {
uni.showToast({
title:res.data.message,
icon:'none',
title: res.data.message,
icon: 'none',
})
n(res)
}
n(res)
}
},
fail: function(err) {
fail: function (err) {
"request:fail " === err.errMsg && msg("请求数据失败!"), n(err.data);
}
});
});
}
}