登录优化,自动返回上一个。支持微信环境自动登录

master
gongfuxiang 2022-04-20 21:26:16 +08:00
parent a06f999cc7
commit 6ba461e70e
3 changed files with 157 additions and 50 deletions

145
App.vue
View File

@ -24,7 +24,9 @@
// key
cache_userlocation_key: "cache_userlocation_key",
// key
cache_page_pay_key: "cache_page_pay_key",
cache_page_pay_key: "cache_page_pay_key",
// key
cache_prev_page_key: 'cache_prev_page_key',
//
default_user_head_src: "/static/images/common/user.png",
//
@ -43,9 +45,11 @@
"/pages/user/user"
],
//
request_url: 'http://shopxo.com/',
request_url: 'https://d1.shopxo.vip/',
// publicpublichttps://d1.shopxo.vip/public/
static_url: 'http://shopxo.com/',
static_url: 'http://shopxo.com/',
// default
system_type: 'yifan',
//
application_title: "ShopXO",
application_describe: "ShopXO开源商城、MIT协议、可商用、可二次开发、满足99%电商运营需求",
@ -187,7 +191,7 @@
var client_value = this.application_client_type();
//
var join = (url.indexOf('?') == -1) ? '?' : '&';
return url + join + "application=app&application_client_type="+ client_value + "&token=" + token + "&uuid=" + uuid;
return url + join + "system_type="+ this.data.system_type +"&application=app&application_client_type="+ client_value + "&token=" + token + "&uuid=" + uuid;
},
/**
@ -823,7 +827,7 @@
// #endif
// #ifdef H5
// H5
if(this.is_weixin()) {
if(this.is_weixin_env()) {
var page_url = this.get_page_url();
uni.request({
url: this.get_request_url("signpackage", "index", "share"),
@ -939,7 +943,6 @@
//
init_config() {
var self = this;
uni.request({
url: this.get_request_url('common', 'base'),
method: 'POST',
@ -953,7 +956,10 @@
fail: () => {
this.showToast('配置信息缓存失败');
}
});
});
//
this.user_auto_login_handle();
} else {
this.showToast(res.data.msg);
}
@ -969,7 +975,7 @@
* object 回调操作对象
* method 回调操作对象的函数
*/
is_config(object, method) {
is_config(object, method) {
var self = this;
var count = 0;
var timer = setInterval(function() {
@ -1083,23 +1089,34 @@
//
url_event(e) {
var value = e.currentTarget.dataset.value || null;
if (value != null) {
var temp = value.substr(0, 6);
if (temp == 'http:/' || temp == 'https:') {
this.open_web_view(value);
} else {
if (this.is_tabbar_pages(value)) {
uni.switchTab({
url: value
});
} else {
uni.navigateTo({
url: value
});
}
}
}
var value = e.currentTarget.dataset.value || null;
this.url_open(value);
},
// url
url_open(value, is_redirect = false) {
if (value != null) {
var temp = value.substr(0, 6);
if (temp == 'http:/' || temp == 'https:') {
this.open_web_view(value);
} else {
if (this.is_tabbar_pages(value)) {
uni.switchTab({
url: value
});
} else {
if(is_redirect) {
uni.redirectTo({
url: value
});
} else {
uni.navigateTo({
url: value
});
}
}
}
}
},
//
@ -1271,7 +1288,7 @@
},
//
is_weixin() {
is_weixin_env() {
var agent = navigator.userAgent.toLowerCase();
if(agent.match(/MicroMessenger/i) == 'micromessenger') {
return true;
@ -1282,7 +1299,7 @@
// webopenid
is_user_weixin_web_openid(order_ids) {
// web_openid
if(this.is_weixin()) {
if(this.is_weixin_env()) {
var web_openid = this.get_user_cache_info('weixin_web_openid') || null;
if(web_openid == null) {
//
@ -1368,19 +1385,35 @@
current_page() {
//
var pages = getCurrentPages();
var page = pages[pages.length-1];
var route = page.route;
var options = page.options || {};
var query = '';
if(JSON.stringify(options) != '{}') {
for(var i in options) {
query += '&'+i+'='+options[i];
}
}
if((query || null) != null) {
route += '?'+query.substr(1);
}
return route;
var page = pages[pages.length-1];
return this.page_url_handle(page);
},
//
prev_page() {
var value = null;
var pages = getCurrentPages();
var length = pages.length;
if(length > 1) {
value = this.page_url_handle(pages[length-2]);
}
return value;
},
//
page_url_handle(page) {
var route = page.route;
var options = page.options || {};
var query = '';
if(JSON.stringify(options) != '{}') {
for(var i in options) {
query += '&'+i+'='+options[i];
}
}
if((query || null) != null) {
route += '?'+query.substr(1);
}
return route;
},
//
@ -1398,6 +1431,38 @@
// webview
this.open_web_view(url);
}
},
//
user_auto_login_handle() {
// #ifdef H5
var user = this.get_user_cache_info() || null;
if(user == null) {
var config = this.get_config('plugins_base.thirdpartylogin.data');
var data = this.get_config('plugins_thirdpartylogin_data');
var url = null;
//
if(this.is_weixin_env()) {
var is_auto = config.weixin_is_env_auto_login || 0;
var weixin = data.weixin || null;
if(is_auto != 0 && weixin != null) {
url = weixin.login_url;
}
}
// url
if(url != null) {
//
var page = this.current_page();
if(page != null) {
uni.setStorageSync(this.data.cache_prev_page_key, page);
}
//
window.location.href = url;
}
}
// #endif
}
},

View File

@ -49,8 +49,8 @@
</view>
</block>
<view v-if="current_opt_form == 'success'" class="tc margin-top-xxxl">
<view class="cr-green">已成功登录请点击进入首</view>
<navigator open-type="switchTab" :url="home_page_url" class="dis-inline-block auto bg-main br-main cr-white round text-size-sm padding-left-xxxl padding-right-xxxl padding-top-xs padding-bottom-xs margin-top-xl">进入首页</navigator>
<view class="cr-green">已成功登录请点击返回上一</view>
<button type="default" size="mini" class="dis-inline-block auto bg-main br-main cr-white round text-size-sm padding-left-xxxl padding-right-xxxl padding-top-xs padding-bottom-xs margin-top-xl" @tap="success_event"></button>
</view>
</view>
</block>
@ -329,6 +329,7 @@
return {
params: null,
user: null,
prev_page: null,
form_input_mobile_value: '',
form_input_email_value: '',
form_input_accounts_value: '',
@ -373,8 +374,6 @@
plugins_thirdpartylogin_user: null,
//
error_msg: null,
//
home_page_url: app.globalData.data.tabbar_pages[0]
};
},
@ -389,6 +388,12 @@
params: params
});
//
var page = app.globalData.prev_page();
if(page != null) {
uni.setStorageSync(app.globalData.data.cache_prev_page_key, page);
}
//
if((params.msg || null) != null) {
var msg = base64.decode(decodeURIComponent(params.msg));
@ -474,6 +479,17 @@
current_opt_type: type,
current_opt_form: form
});
//
if(this.current_opt_form == 'success') {
var page = uni.getStorageSync(app.globalData.data.cache_prev_page_key) || null;
if(page != null) {
this.setData({prev_page: page});
setTimeout(function() {
app.globalData.url_open('/'+page, true);
}, 2000);
}
}
},
//
@ -1274,12 +1290,18 @@
var url = e.currentTarget.dataset.url || null;
window.location.href = url;
},
//
plugins_thirdpartylogin_cancel_event(e) {
uni.redirectTo({
url: '/pages/login/login'
});
},
//
success_event(e) {
var url = (this.prev_page == null) ? app.globalData.data.tabbar_pages[0] : this.prev_page;
app.globalData.url_open(url, true);
}
}
};

View File

@ -79,8 +79,14 @@
<!-- 清除缓存 -->
<view class="nav-item padding-main fl tc cp" @tap="clear_storage">
<image :src="common_static_url+'cache-icon.png'" class="item-icon" mode="widthFix"></image>
<view class="item-name single-text cr-base">清除缓存</view>
<!-- #ifndef MP -->
<image :src="common_static_url+'logout-icon.png'" class="item-icon" mode="widthFix"></image>
<view class="item-name single-text cr-base">退出登录</view>
<!-- #endif -->
<!-- #ifdef MP -->
<image :src="common_static_url+'cache-icon.png'" class="item-icon" mode="widthFix"></image>
<view class="item-name single-text cr-base">清除缓存</view>
<!-- #endif -->
</view>
<!-- 联系客服 -->
@ -328,14 +334,13 @@
});
},
//
// 退/
clear_storage(e) {
// uuiduuid
var uuid = uni.getStorageSync(app.globalData.data.cache_user_uuid_key) || null;
//
uni.clearStorage();
app.globalData.showToast("清除缓存成功", "success");
// uuid
if (uuid != null) {
@ -343,7 +348,22 @@
key: app.globalData.data.cache_user_uuid_key,
data: uuid
});
}
}
// #ifdef MP
//
app.globalData.showToast("清除成功", "success");
// #endif
// #ifndef MP
//
app.globalData.showToast("退出成功", "success");
setTimeout(function() {
uni.switchTab({
url: app.globalData.data.tabbar_pages[0]
});
}, 2000);
// #endif
},
//