You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
242 lines
5.4 KiB
242 lines
5.4 KiB
<template>
|
|
<view>
|
|
<lf-nav title="登录/注册" :showIcon="true" bgColor="#fff"></lf-nav>
|
|
<view class="illustration">
|
|
<image class="img" src="../../../static/images/empty.png" mode="aspectFill"></image>
|
|
</view>
|
|
<view class="fixed-btn">
|
|
<button class="btn1" hover-class="lf-opacity" @click="toPhoneLogin">手机号登录</button>
|
|
<button class="btn2" hover-class="lf-opacity" @click="wxLogin">微信授权登录</button>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { config, wechat, GetUrl } from '@/common/js/utils.js';
|
|
export default {
|
|
data(){
|
|
return {
|
|
code: '',
|
|
url: '',
|
|
logo: '',
|
|
author: config.PACKAGES.author,
|
|
config: '',
|
|
showAgreement: false,
|
|
agreement: '',
|
|
open_id: '',
|
|
h5_url: ''
|
|
}
|
|
},
|
|
onShow(){
|
|
var token = this.$cookieStorage.get('user_token');
|
|
// this.setData({
|
|
// token: token
|
|
// });
|
|
this.token = token;
|
|
|
|
var initInfo = this.$cookieStorage.get('init');
|
|
|
|
if (initInfo && initInfo.shop_show_logo) {
|
|
this.setData({
|
|
logo: initInfo.shop_show_logo
|
|
});
|
|
}
|
|
|
|
if (token) {
|
|
wx.switchTab({
|
|
url: '/pages/user/personal/personal'
|
|
});
|
|
} else {
|
|
// #ifdef MP-WEIXIN
|
|
this.wxLogin();
|
|
// #endif
|
|
}
|
|
},
|
|
onLoad(e){
|
|
// 第三方平台配置颜色
|
|
var bgConfig = this.$cookieStorage.get('globalConfig') || '';
|
|
this.setData({
|
|
config: bgConfig
|
|
});
|
|
if (e.url) {
|
|
this.url = decodeURIComponent(e.url);
|
|
console.log('this.url',this.url)
|
|
}
|
|
if (e.shop_id) {
|
|
this.$cookieStorage.set('shop_id', e.shop_id);
|
|
}
|
|
|
|
this.getGreementInfo();
|
|
|
|
},
|
|
methods: {
|
|
// 获取用户协议
|
|
getGreementInfo() {
|
|
console.log("获取协议")
|
|
// this.$http.get({
|
|
// api: 'api/user/agreement'
|
|
// }).then(res => {
|
|
// if (res.statusCode == 200) {
|
|
// res = res.data;
|
|
|
|
// if (res.status) {
|
|
// this.setData({
|
|
// agreement: res.data
|
|
// });
|
|
// }
|
|
// }
|
|
// });
|
|
},
|
|
wxLogin(){
|
|
uni.showLoading({
|
|
title: '正在自动登录',
|
|
mask: true
|
|
});
|
|
uni.login({
|
|
success: res => {
|
|
console.log(res);
|
|
if (res.code) {
|
|
this.autoLogin(res.code);
|
|
} else {
|
|
this.$msg('获取code失败');
|
|
}
|
|
},
|
|
});
|
|
|
|
// uni.getUserProfile({
|
|
// desc: '我们将获取到的信息用于展示',
|
|
// lang: 'zh_CN',
|
|
// complete: result => {
|
|
// console.log(result);
|
|
// if(result.errMsg == 'getUserProfile:ok'){
|
|
// console.log("获取成功!");
|
|
// }
|
|
// }
|
|
// })
|
|
},
|
|
autoLogin(code) {
|
|
this.$http.post({
|
|
api: 'api/oauth/miniprogram/login',
|
|
data: {
|
|
code: code,
|
|
open_type: 'miniprogram',
|
|
shop_id: this.$cookieStorage.get('shop_id') || '',
|
|
agent_code: this.$cookieStorage.get('coupon_agent_code') || this.$cookieStorage.get('agent_code') || '',
|
|
clerk_id: this.$cookieStorage.get('clerk_id') || '',
|
|
agent_code_time: this.$cookieStorage.get('agent_code_time') || '',
|
|
shop_id_time: this.$cookieStorage.get('shop_id_time') || ''
|
|
}
|
|
}).then(res => {
|
|
res = res.data;
|
|
if (res.data && res.data.open_id) {
|
|
this.setData({
|
|
open_id: res.data.open_id
|
|
});
|
|
} // 如果接口返回token就直接登录,如果没有则弹出授权
|
|
|
|
if (res.data.access_token) {
|
|
console.log('已经返回给我了token');
|
|
wx.hideLoading();
|
|
var access_token = res.data.token_type + ' ' + res.data.access_token;
|
|
var expires_in = res.data.expires_in || 315360000;
|
|
this.$cookieStorage.set("user_token", access_token, expires_in);
|
|
|
|
if (this.url) {
|
|
wx.redirectTo({
|
|
url: "/" + this.url,
|
|
fail: () => {
|
|
wx.switchTab({
|
|
url: "/" + this.url
|
|
});
|
|
}
|
|
})
|
|
|
|
} else {
|
|
wx.switchTab({
|
|
url: '/pages/user/personal/personal'
|
|
});
|
|
}
|
|
} else {
|
|
wx.hideLoading();
|
|
}
|
|
}).catch(rej => {
|
|
wx.hideLoading();
|
|
wx.showModal({
|
|
content: '请求失败,请重试',
|
|
showCancel: false,
|
|
success: res => {
|
|
if (res.confirm || !res.cancel && !res.confirm) {
|
|
this.wxLogin();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
},
|
|
toPhoneLogin(){
|
|
this.$url('/pages/user/loginType/loginType');
|
|
},
|
|
setData: function(obj) {
|
|
let that = this;
|
|
let keys = [];
|
|
let val, data;
|
|
Object.keys(obj).forEach(function(key) {
|
|
keys = key.split('.');
|
|
val = obj[key];
|
|
data = that.$data;
|
|
keys.forEach(function(key2, index) {
|
|
if (index + 1 == keys.length) {
|
|
that.$set(data, key2, val);
|
|
} else {
|
|
if (!data[key2]) {
|
|
that.$set(data, key2, {});
|
|
}
|
|
}
|
|
|
|
data = data[key2];
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.illustration{
|
|
width: 750rpx;
|
|
height: 750rpx;
|
|
position: fixed;
|
|
top: 44%;
|
|
left: 0;
|
|
margin-top: -375rpx;
|
|
.img{
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
}
|
|
.fixed-btn{
|
|
width: 630rpx;
|
|
height: max-content;
|
|
position: fixed;
|
|
left: calc(50% - 315rpx);
|
|
top: calc(46% + 375rpx);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
.btn1, .btn2{
|
|
width: 300rpx;
|
|
height: 100rpx;
|
|
border-radius: 60rpx;
|
|
border: 1rpx solid #15716E;
|
|
box-sizing: border-box;
|
|
line-height: 100rpx;
|
|
font-size: 32rpx;
|
|
}
|
|
.btn1{
|
|
background-color: #F3F8F8;
|
|
color: #15716E;
|
|
}
|
|
.btn2{
|
|
background-color: #15716E;
|
|
color: #FFFFFF;
|
|
}
|
|
}
|
|
</style>
|