Browse Source

对接登录页

master
邓平艺 4 years ago
parent
commit
6602a61d3b
  1. 69
      pages.json
  2. 187
      pages/user/register/register.vue

69
pages.json

@ -51,13 +51,15 @@
{
"path": "pages/store/list/list",
"style": {
"navigationBarTitleText": "商品列表"
"navigationBarTitleText": "商品列表",
"navigationStyle":"custom"
}
},
{
"path": "pages/store/comment/comment",
"style": {
"navigationBarTitleText": "商品评论"
"navigationBarTitleText": "商品评论" ,
"navigationStyle":"custom"
}
},
{
@ -70,7 +72,8 @@
{
"path": "pages/article/details",
"style": {
"navigationBarTitleText": ""
"navigationBarTitleText": "",
"navigationStyle":"custom"
}
},
{
@ -189,7 +192,8 @@
{
"path": "pages/address/add/add",
"style": {
"navigationBarTitleText": "收货地址"
"navigationBarTitleText": "收货地址",
"navigationStyle":"custom"
}
},
{
@ -475,58 +479,7 @@
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
// "tabBar": {
// "backgroundColor": "#fff",
// "color": "#9B9B9B",
// "selectedColor": "#ff2741",
// "borderStyle": "white",
// "list": [
// {
// "pagePath": "pages/index/index/index",
// "text": "首页",
// "iconPath": "static/shop.png",
// "selectedIconPath": "static/shop-r.png"
// },
// {
// "pagePath": "pages/index/classification/classification",
// "text": "分类",
// "iconPath": "static/class.png",
// "selectedIconPath": "static/class-r.png"
// },
// {
// "pagePath": "pages/store/cart/cart",
// "text": "购物车",
// "iconPath": "static/card.png",
// "selectedIconPath": "static/card-r.png"
// },
// {
// "pagePath": "pages/user/personal/personal",
// "text": "我的",
// "iconPath": "static/user.png",
// "selectedIconPath": "static/user-r.png"
// }
// ]
// },
"condition" : { //
"current": 0, //(list )
"list": [
{
"name": "首页", //
"path": "pages/index/index/index", //
"query": "" //onLoad
},
{
"name": "测试",
"path": "pages/user/personal/personal",
"query": ""
}
]
}
"backgroundColor": "#F8F8F8",
"navigationStyle":"custom"
}
}

187
pages/user/register/register.vue

@ -6,28 +6,195 @@
</view>
<view class="fixed-btn">
<button class="btn1" hover-class="lf-opacity" @click="toPhoneLogin">手机号登录</button>
<button class="btn2" hover-class="lf-opacity" @click="getUserInfo">微信授权登录</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: {
getUserInfo(){
uni.getUserProfile({
desc: '我们将获取到的信息用于展示',
lang: 'zh_CN',
complete: result => {
console.log(result);
if(result.errMsg == 'getUserProfile:ok'){
console.log("获取成功!");
//
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];
});
});
}
}
}

Loading…
Cancel
Save