Browse Source

用户端登录

master
kuaileWu 10 months ago
parent
commit
406beb6ec8
  1. 43
      main.js
  2. 2
      manifest.json
  3. 60
      pages/index/index.vue

43
main.js

@ -22,7 +22,7 @@ const NODE_ENV = 'development';
// const NODE_ENV = 'production';
if(NODE_ENV == 'development'){
Vue.prototype.cssUrl = '/static/images/frontend/';
Vue.prototype.request_domain = "http://api.checkcopy.com/";
Vue.prototype.request_domain = "http://jasonyizherenxin.checkcopy.com/";
}else{
Vue.prototype.cssUrl = '/static/images/frontend/';
Vue.prototype.request_domain = "http://api.yizherenxin.cn/";
@ -183,8 +183,13 @@ Vue.prototype.edit_preview = 2;
Vue.prototype.add_preview = 3;
Vue.prototype.edit_album = 4;
function removeLogin() {
uni.removeStorageSync('token');
// function removeLogin() {
// uni.removeStorageSync('token');
// }
function removeLogin() {
uni.removeStorageSync("token");
uni.removeStorageSync("uinfo");
}
function req(url, data={}, method = 'POST', header={}) {
@ -193,7 +198,7 @@ function req(url, data={}, method = 'POST', header={}) {
data.appid = Vue.prototype.appid;
data.xcx_scource = Vue.prototype.USER_SOURCE_WX_XCX;
}else{
domain = '/api/user/';
domain = '/api/';
if(Vue.prototype.isMobile){
data.xcx_scource = Vue.prototype.USER_SOURCE_H5;
if(Vue.prototype.env_val.indexOf('weixin') > -1) data.xcx_scource = Vue.prototype.USER_SOURCE_WX_H5;
@ -201,18 +206,17 @@ function req(url, data={}, method = 'POST', header={}) {
data.xcx_scource = Vue.prototype.USER_SOURCE_PC;
}
}
var getWxH5LoginConfigUri = 'common/wxh5_login'
var noNeedLoginFunc = [
'client/common/mp/config',
getWxH5LoginConfigUri,
'client/user/login'
]
var isNeedLogin = !noNeedLoginFunc.includes(url);
var headerObj = {'content-type': 'application/x-www-form-urlencoded'};
var token = uni.getStorageSync('token');
if(token) headerObj.Authorization = token
var getWxH5LoginConfigUri = 'client/common/mp/config'
if(token) headerObj.AUTH = token
return new Promise((resolve, reject) => {
uni.request({
@ -225,20 +229,23 @@ function req(url, data={}, method = 'POST', header={}) {
try{
var rdata = res.data;
if(rdata.code != CODE_SUCCESS) {
if((rdata.code==CODE_LOGIN_EXIPRE || rdata.msg.indexOf('Signature verification failed')>-1 || rdata.msg.indexOf('身份认证信息未提供')>-1) && data.xcx_scource == Vue.prototype.USER_SOURCE_WX_H5 && url != getWxH5LoginConfigUri && data.repeat != 1){
if(rdata.code==CODE_LOGIN_EXIPRE && data.xcx_scource == Vue.prototype.USER_SOURCE_WX_H5 && url != getWxH5LoginConfigUri && data.repeat != 1){
removeLogin();
var logindatac = new Object();
logindatac.host = location.host;
logindatac.redirect_uri = location.origin;
logindatac.state = 'user';
const pagesc = getCurrentPages();
const currentPagec = pagesc[pagesc.length - 1];
var pageUrlc = '/'+currentPagec.route;
uni.setStorageSync('rebackPagePath', pageUrlc);
location.href = Vue.prototype.request_domain+'api/common/wxh5_login/?state=user'
// req(getWxH5LoginConfigUri, logindatac, 'GET').then(data=>{
// if(data == -1 || !data.user_authorize_url) return;
// location.href = data.user_authorize_url;
// });
var doctor_id = uni.getStorageSync('doctor_id');
req(getWxH5LoginConfigUri+'/?did='+doctor_id, logindatac, 'POST').then(data=>{
if(data == -1 || !data.authurl) return;
location.href = data.authurl;
});
return;
}
@ -247,7 +254,7 @@ function req(url, data={}, method = 'POST', header={}) {
showCancel: false,
content: rdata.msg ? rdata.msg+'|'+rdata.code : '网络错误,请重试|'+res.statusCode,
success: function (rs) {
if (rs.confirm && (rdata.code==CODE_LOGIN_EXIPRE || rdata.msg.indexOf('Signature verification failed')>-1 || rdata.msg.indexOf('身份认证信息未提供')>-1)) {
if (rs.confirm && rdata.code==CODE_LOGIN_EXIPRE) {
removeLogin();
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
@ -262,7 +269,7 @@ function req(url, data={}, method = 'POST', header={}) {
}
}
});
return resolve("-1");
}else{
return resolve(res.data.data);

2
manifest.json

@ -80,7 +80,7 @@
"disableHostCheck" : true,
"proxy" : {
"/api" : {
"target" : "http://api.checkcopy.com",
"target" : "http://jasonyizherenxin.checkcopy.com",
"changeOrigin" : true,
"secure" : false
}

60
pages/index/index.vue

@ -91,7 +91,8 @@
doctor_dept:false,
hospitals:false,
recentAppoint:[],
loginToken:false
loginToken:false,
state:'',
}
},
components:{
@ -99,13 +100,16 @@
preBookList,
},
onLoad(option) {
if(option.code) this.code = option.code
if(option.token) {
this.loginToken = option.token
uni.setStorageSync('token', this.loginToken)
// var rebackPagePath = uni.getStorageSync('rebackPagePath')
// if(!rebackPagePath)
if(option.code && option.state) {
this.code = option.code
this.state = option.state
}
// if(option.token) {
// this.loginToken = option.token
// uni.setStorageSync('token', this.loginToken)
// // var rebackPagePath = uni.getStorageSync('rebackPagePath')
// // if(!rebackPagePath)
// }
},
async onShow() {
this.doctor_id = getApp().globalData.doctorId
@ -117,12 +121,12 @@
title:title
})
// var token = uni.getStorageSync('token')
// if(this.code && !token) {
// var rebackPagePath = uni.getStorageSync('rebackPagePath')
// this.login()
// return
// }
var token = uni.getStorageSync('token')
if(this.code && this.state && !token) {
var rebackPagePath = uni.getStorageSync('rebackPagePath')
this.login()
return
}
await this.getDoctorInfo()
},
methods: {
@ -148,21 +152,27 @@
}
});
},
setLoginUserInfo(info) {
var uinfo = new Object();
uni.setStorageSync("uinfo", JSON.stringify(info));
},
login() {
// this.$http.req('login', {code:this.code}, 'POST').then(data=>{
// if(data == -1) return
// uni.setStorageSync('token', data.token)
// var rebackPagePath = uni.getStorageSync('rebackPagePath')
// if(rebackPagePath){
// uni.navigateTo({
// url:rebackPagePath
// })
// }
// });
this.$http.req('common/get_user_info', {code:this.code,state:this.state}, 'POST').then(data=>{
if(data == -1) return
uni.setStorageSync('token', data.jwttoken)
this.setLoginUserInfo(data)
this.getDoctorInfo()
// var rebackPagePath = uni.getStorageSync('rebackPagePath')
// if(rebackPagePath){
// uni.navigateTo({
// url:rebackPagePath
// })
// }
});
},
async getDoctorInfo() {
// if(this.loginToken) return;
await this.$http.req('index_info', {}, 'GET').then(data=>{
await this.$http.req('user/get_user_info', {}, 'GET').then(data=>{
if(data == -1) return
this.pageShow = true
this.doctorInfo = data

Loading…
Cancel
Save