first commit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
function auth(){ //鉴权
|
||||
return new Promise((resolve,reject)=>{
|
||||
uni.login({
|
||||
provider: 'weixin', //使用微信登录
|
||||
onlyAuthorize: true, //不弹出授权页面,直接进入微信登录流程
|
||||
success(res){
|
||||
if(res.errMsg=="login:ok"){
|
||||
resolve(res.code)
|
||||
}else{
|
||||
uni.showToast({
|
||||
title:res.errMsg,
|
||||
icon:'error'
|
||||
})
|
||||
}
|
||||
},
|
||||
fail(err){
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
export default auth
|
||||
@@ -0,0 +1,16 @@
|
||||
let BASE_URL=''
|
||||
if(process.env.UNI_PLATFORM =="h5"){
|
||||
if (window.location.href.indexOf('//casedata.igandan.com')>-1){
|
||||
BASE_URL='https://prod-casedata.igandan.com/api'
|
||||
}else{
|
||||
BASE_URL='https://dev-casedata.igandan.com/api'
|
||||
}
|
||||
}else{
|
||||
const { envVersion } = uni.getAccountInfoSync().miniProgram;
|
||||
if (envVersion == "release") {
|
||||
BASE_URL='https://prod-casedata.igandan.com/api'
|
||||
}else{
|
||||
BASE_URL='https://dev-casedata.igandan.com/api'
|
||||
}
|
||||
}
|
||||
export default BASE_URL
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import pageUrl from './pageUrl'
|
||||
|
||||
function navTo(obj) {
|
||||
let token = '';
|
||||
if(process.env.UNI_PLATFORM =="h5"){
|
||||
if(window.location.href.indexOf('//casedata.igandan.com')>-1){
|
||||
token = uni.getStorageSync('AUTH_TOKEN_App');
|
||||
}else{
|
||||
token = uni.getStorageSync('DEV_AUTH_TOKEN_App');
|
||||
}
|
||||
}else{
|
||||
const { envVersion } = uni.getAccountInfoSync().miniProgram;
|
||||
if (envVersion == "release") {
|
||||
token = uni.getStorageSync('AUTH_TOKEN_App');
|
||||
}else{
|
||||
token = uni.getStorageSync('DEV_AUTH_TOKEN_App');
|
||||
}
|
||||
}
|
||||
if (!token) {
|
||||
// let page_url = pageUrl();
|
||||
// uni.setStorageSync('redirectUrl', page_url);
|
||||
uni.navigateTo({
|
||||
url: '/pages_app/login/login'
|
||||
});
|
||||
} else {
|
||||
if(process.env.UNI_PLATFORM =="h5"){
|
||||
uni.navigateTo(obj)
|
||||
}else if(process.env.UNI_PLATFORM =="mp-weixin"){
|
||||
const pages = getCurrentPages();
|
||||
let len = pages.length;
|
||||
console.log(len)
|
||||
if (len >=10) {
|
||||
uni.redirectTo(obj)
|
||||
} else {
|
||||
uni.navigateTo(obj)
|
||||
|
||||
}
|
||||
}else{
|
||||
uni.navigateTo(obj)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default navTo
|
||||
@@ -0,0 +1,19 @@
|
||||
function pageUrl(){
|
||||
// 获取当前页面的实例
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
|
||||
// 获取页面的完整URL
|
||||
const url = currentPage.route; // 页面路径
|
||||
const options = currentPage.options; // 如果有查询参数,将会在这里
|
||||
|
||||
// 拼接URL
|
||||
let fullUrl = url + '?';
|
||||
for (let key in options) {
|
||||
fullUrl += `${key}=${options[key]}&`;
|
||||
}
|
||||
fullUrl = fullUrl.substring(0, fullUrl.length - 1); // 移除最后一个"&"
|
||||
|
||||
return fullUrl
|
||||
}
|
||||
export default pageUrl
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* @Method Description
|
||||
* @Author: zjd@
|
||||
* @Description: 数据请求整合 处理
|
||||
* @BASE_URL server
|
||||
* @param {a===Object||file} 传给后台参数Method 请求方法 url 所请求的接口路径
|
||||
* @return Promise对象 所有数据信息
|
||||
* @createTime: 2024-7-22 15:05:06
|
||||
*/
|
||||
import BASE_URL from "./config.js";
|
||||
//import host from "@/utils/host";
|
||||
//import {msg} from "./util.js"
|
||||
//const BASE_URL=host+"/api"
|
||||
export const request = (url, data = {}, method = 'post', loading = false, contentType =
|
||||
'application/x-www-form-urlencoded') => {
|
||||
if (loading) {
|
||||
uni.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
})
|
||||
|
||||
};
|
||||
let token = '';
|
||||
if (process.env.UNI_PLATFORM == "h5") {
|
||||
if (window.location.href.indexOf('//App.igandan.com') > -1) {
|
||||
token = uni.getStorageSync('AUTH_TOKEN_App');
|
||||
} else {
|
||||
token = uni.getStorageSync('DEV_AUTH_TOKEN_App');
|
||||
}
|
||||
} else if(process.env.UNI_PLATFORM == "mp-weixin") {
|
||||
const {
|
||||
envVersion
|
||||
} = uni.getAccountInfoSync().miniProgram;
|
||||
if (envVersion == "release") {
|
||||
token = uni.getStorageSync('AUTH_TOKEN_App');
|
||||
} else {
|
||||
token = uni.getStorageSync('DEV_AUTH_TOKEN_App');
|
||||
}
|
||||
}
|
||||
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),
|
||||
method: method,
|
||||
sslVerify: false,
|
||||
header: url.indexOf('/manager/getSignature4bing') == -1 ? header : {},
|
||||
timeout: 10000,
|
||||
success: async (res) => {
|
||||
var Authorization_token = res.header.Authorization;
|
||||
if (Authorization_token) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
uni.setStorageSync('DEV_AUTH_TOKEN_App', Authorization_token);
|
||||
} else {
|
||||
uni.setStorageSync('AUTH_TOKEN_App', Authorization_token);
|
||||
}
|
||||
|
||||
}
|
||||
if (loading) {
|
||||
uni.hideLoading();
|
||||
};
|
||||
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) {
|
||||
|
||||
uni.redirectTo({
|
||||
url: '/pages_app/login/login'
|
||||
});
|
||||
|
||||
|
||||
} else if (res.data.code == 500) {
|
||||
|
||||
uni.showToast({
|
||||
title: res.data.message,
|
||||
icon: 'none',
|
||||
|
||||
})
|
||||
n(res)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.data.message,
|
||||
icon: 'none',
|
||||
});
|
||||
n(res)
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
fail: function(err) {
|
||||
"request:fail " === err.errMsg && msg("请求数据失败!"), n(err.data);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
const throttle=function(fn,wait=1500){
|
||||
var flag = true;
|
||||
var timer = null;
|
||||
return function(){
|
||||
if(flag) {
|
||||
fn.apply(this,arguments);
|
||||
flag = false;
|
||||
timer = setTimeout(() => {
|
||||
flag = true
|
||||
},wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
export default throttle
|
||||
Reference in New Issue
Block a user