c49a1142 by 杨炀

Merge commit '023f830b'

2 parents c579d87a 023f830b
<script>
import * as loginServer from '@/common/login.js';
import * as api from '@/common/api.js';
import config from '@/config.js';
import {
h5Login
} from '@/common/login.js';
import * as api from '@/common/api.js';
import config from '@/config.js';
let loginUrl=['pages/index/login', 'pages/index/register']
let firstload = false
export default {
onLaunch: function(options) {
console.log('App Launch', options);
firstload = true
let firstload = false
export default {
onLaunch: function() {
console.log('App Launch');
firstload = true
this.globalData.baseUrl = config.baseUrl;
this.globalData.baseUrl_api = config.baseUrl_api;
this.globalData.fileUrl = config.fileUrl;
new Promise((resolve, reject) => {
uni.checkSession({
success: res => {
loginServer
.getCurrUser(true)
.catch(() => {
return loginServer.pcLogin();
})
.then(user => {
resolve(user);
});
},
fail: res => {
loginServer
.wxLogin()
.then(loginRes => {
return loginServer.pcLogin(loginRes.code);
})
.then(user => {
resolve(user);
});
}
});
})
.then(()=>{
return loginServer.getNowOpenId()
})
.then(() => {
return loginServer.initData()
// console.log(22222222)
// const currUser = uni.getStorageSync('currUser');
// // console.log(currUser)
// return Promise.all([api.getVenue(), api.getOwnMemberInfo()]).then(res => {
// let ven = res[0].data;
// let men = res[1]?.data;
// if (ven.venuePic) {
// ven.venuePicArr = ven.venuePic.split(',');
// }
// if (ven.businessPeriod) {
// ven.startBus = ven.businessPeriod.split(',')[0];
// ven.endBus = ven.businessPeriod.split(',')[1];
// }
// ven.latitude = ven.lal.split(',')[0];
// ven.longitude = ven.lal.split(',')[1];
// this.globalData.venue = ven;
// this.globalData.isVip = men?.isVip;
// // this.globalData.relateProjectId = men.info.relateProjectId;
// this.globalData.relateProjectIdList = men?.info?.relateProjectIdList;
// this.globalData.relateVenueProjectIdList = men?.info?.relateVenueProjectIdList;
// this.globalData.venueConfig = {
// normalOverDay: ven.resSiteConfig?.normalOrderNum,
// normalPeriodStart: ven.resSiteConfig?.normalOrderPeriod.split(',')[0],
// normalPeriodEnd: ven.resSiteConfig?.normalOrderPeriod.split(',')[1]
// };
// if (men?.isVip) {
// this.globalData.venueConfig.memberOverDay = ven.resSiteConfig?.memberOrderNum;
// this.globalData.venueConfig.memberPeriodStart = ven.resSiteConfig?.memberOrderPeriod.split(',')[0];
// this.globalData.venueConfig.memberPeriodEnd = ven.resSiteConfig?.memberOrderPeriod.split(',')[1];
// }
// });
})
.then(() => {
this.globalData.isLogin = true;
let firstLoadCallback = getApp().firstLoadCallback;
if (firstLoadCallback) {
firstLoadCallback();
}
});
},
onShow: function() {
console.log('App Show');
// loginServer.getNowOpenId()
if (!firstload) {
loginServer.getCurrUser(true)
.catch(() => {
return loginServer.pcLogin().then(() => {
uni.redirectTo({
url: getCurrentPages()[getCurrentPages().length - 1].$page.fullPath
})
});
})
}
},
onHide: function() {
console.log('App Hide');
}
};
this.globalData.baseUrl_api = config.baseUrl_api;
if(loginUrl.indexOf( options.path)==-1){
let userName = uni.getStorageSync('userName')
if (userName) {
h5Login(userName)
.then(() => {
this.globalData.isLogin = true;
let firstLoadCallback = getApp().firstLoadCallback;
if (firstLoadCallback) {
firstLoadCallback();
}
})
.catch(() => {
uni.redirectTo({
url: '/pages/index/login'
})
})
} else {
this.globalData.isLogin = false;
uni.redirectTo({
url: '/pages/index/login'
})
}
}
},
onShow: function() {
console.log('App Show');
},
onHide: function() {
console.log('App Hide');
}
};
</script>
<style lang="scss">
......
import config from '@/config.js'
import {
pcLogin,
getNowOpenId,
initData
h5LoginAuto
} from './login'
const excludeUrls = ['/system/wx/getUserInfo']
const excludeUrls = ['pages/index/login', 'pages/index/register']
// 获取Token
function getToken() {
try {
const token = uni.getStorageSync('token');
if (token) {
return token
} else {
return ''
}
} catch (e) {
console.log(e)
}
try {
const token = uni.getStorageSync('token')
if (token) {
return token
} else {
return ''
}
} catch (e) {
console.log(e)
}
}
// 获取请求头
function getHeaders() {
let token = getToken()
let header = {
"Authorization": token,
"Content-Type": "application/json", //根据自己的数据类型
// "Content-Type":"application/x-www-form-urlencoded",
}
return header
const token = getToken()
const header = {
'Authorization': token,
'Content-Type': 'application/json' // 根据自己的数据类型
// "Content-Type":"application/x-www-form-urlencoded",
}
return header
}
let request = function(req) {
req.method = req.method.toUpperCase()
if (!['GET', 'POST','PUT', 'DELETE'].includes(req.method)) {
uni.showToast({
title: `暂不支持的请求方式: ${req.method}`,
icon: 'none'
});
return
}
const request = function(req) {
req.method = req.method.toUpperCase()
if (!['GET', 'POST', 'PUT', 'DELETE'].includes(req.method)) {
uni.showToast({
title: `暂不支持的请求方式: ${req.method}`,
icon: 'none'
})
return
}
// if (req.method == 'POST' && !req.hideLoding) {
// uni.showLoading({
// title: '提交中...'
// })
// }
// if (req.method == 'POST' && !req.hideLoding) {
// uni.showLoading({
// title: '提交中...'
// })
// }
return new Promise((resolve, reject) => {
uni.request({
url: config.baseUrl_api + req.url,
method: req.method,
data: req.params,
header: getHeaders(),
}).then(res => {
switch (res.statusCode) {
case 200:
const data = res.data || {};
if (data.code == 200) {
resolve(data)
} else {
//登录超时
if (data.code == 60002 || data.code == 60001) {
if (req.url != '/system/wx/getUserInfo') {
reLogin();
}
}
else if (data.code == 401 && req.url != '/system/wx/getUserInfo') {
pcLogin()
.then(()=>{
return getNowOpenId()
})
.then(()=>{
return initData()
})
.then(()=>{
uni.hideLoading();
uni.redirectTo({
url:getCurrentPages()[getCurrentPages().length-1].$page.fullPath
})
})
}
else {
if (!excludeUrls.includes(req.url)) {
uni.showToast({
title: data.msg,
icon: 'none',
duration: 3000
})
}
}
reject(res)
}
break
default:
reject(res)
}
}).catch(res => {
reject(res)
}).finally(() => {
// if (req.method == 'POST' && !req.hideLoding) {
// uni.hideLoading()
// }
})
})
}
function reLogin() {
const currUser = uni.getStorageSync('currUser') || {}
if (currUser.openId) {
const accountInfo = uni.getAccountInfoSync()
pcLoginByOpenId(accountInfo.miniProgram.appId, currUser.openId)
.then((res) => {
let user = res.data;
uni.setStorageSync('token', 'Bearer ' + user.token);
uni.setStorageSync('currUser', user);
return new Promise((resolve, reject) => {
uni.request({
url: config.baseUrl_api + req.url,
method: req.method,
data: req.params,
header: getHeaders()
}).then(res => {
switch (res.statusCode) {
case 200:
const data = res.data || {}
if (data.code === 200) {
resolve(data)
} else {
if (!excludeUrls.includes(req.url)) {
uni.showToast({
title: data.msg,
icon: 'none',
duration: 3000
})
}
uni.showToast({
title: '一走神把您的操作遗漏了,请重试',
icon: 'none'
})
}).catch(() => {
uni.showToast({
title: '服务异常,请稍后重试',
icon: 'none'
})
})
}
// 登录超时
if (data.code === 60002 || data.code === 60001) {
uni.redirectTo({
url: '/pages/index/login'
})
} else if (data.code === 401) {
h5LoginAuto()
.then(() => {
uni.hideLoading()
uni.redirectTo({
url: getCurrentPages()[getCurrentPages()
.length - 1].$page.fullPath
})
})
.catch(() => {
uni.showToast({
title: '服务异常,请稍后重试',
icon: 'none'
})
})
}
reject(res)
}
break
default:
reject(res)
}
}).catch(res => {
reject(res)
}).finally(() => {
// if (req.method == 'POST' && !req.hideLoding) {
// uni.hideLoading()
// }
})
})
}
function pcLoginByOpenId(appId, openId) {
return request({
url: "/system/wx/loginByOpenId",
method: "POST",
params: {
appId: appId,
openId: openId
}
})
}
export default request;
export default request
......
// prod
// const baseUrl = 'https://research.wtwuxicenter.com/';
// const baseUrl_api=`${baseUrl}/prod-api`;
// const baseUrl_api = 'https://research.wtwuxicenter.com/';
// uat
// const baseUrl = 'https://jxt.itechtop.cn';
const baseUrl = 'https://jxt.wtwuxicenter.com';
const baseUrl_api = `${baseUrl}/prod-api`;
// staging
// const baseUrl = 'https://5q5re1d432g2.ngrok2.xiaomiqiu123.top';
// const baseUrl = "http://192.168.1.118:8081";
// const baseUrl_api = `${baseUrl}`;
const fileUrl = "http://r.itechtop.cn";
const baseUrl_api = "http://192.168.1.96:8787";
export default {
baseUrl: baseUrl,
fileUrl: fileUrl,
baseUrl_api: baseUrl_api,
baseUrl_api
};
\ No newline at end of file
......
......@@ -85,7 +85,7 @@
const app = getApp();
const projectList = ref([]);
const priceTable = ref([]);
const priceTable = ref([]);
const czList = ref([]);
const isActive = ref(0);
const popup = ref(null);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!