Commit a4c4f49a authored by 付清曌's avatar 付清曌

Merge branch 'feature/userinfo' into 'master'

Feature/userinfo

See merge request !1
parents fcd7cf84 cbffa4f7
...@@ -4,47 +4,29 @@ import eventHub from './common/eventHub'; ...@@ -4,47 +4,29 @@ import eventHub from './common/eventHub';
import vuex from '@wepy/x'; import vuex from '@wepy/x';
wepy.use(vuex); wepy.use(vuex);
// import store from './store';
wepy.app({ wepy.app({
hooks: { hooks: {
// App 级别 hook,对整个 App 生效 // App 级别 hook,对整个 App 生效
// 同时存在 Page hook 和 App hook 时,优先执行 Page hook,返回值再交由 App hook 处 // 同时存在 Page hook 和 App hook 时,优先执行 Page hook,返回值再交由 App hook 处
}, },
data: {
userInfo: null
},
onLaunch() { onLaunch() {
let that = this; wx.checkSession({
wx.getSetting({ success () {
success: res => { console.log('已登录')
if (res.authSetting['scope.userInfo']) { //session_key 未过期,并且在本生命周期一直有效
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 },
wx.getUserInfo({ fail () {
success: res => { // session_key 已经失效,需要重新执行登录流程
// 可以将 res 发送给后台解码出 unionId wx.login({
// store.dispatch('setUserInfo',res.userInfo); success (res) {
if (res.code) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 //发起网络请求,告诉后端
// 所以此处加入 callback 以防止这种情况 wx.setStorageSync('wxCode',res.code);
if (that.userInfoReadyCallback) { } else {
that.userInfoReadyCallback(res => { console.log('登录失败!' + res.errMsg)
// store.dispatch('setUserInfo',res.userInfo);
});
}
},
fail: () => {
wx.reLaunch({
url: '/pages/auth'
});
} }
}); }
} else { })
// 未授权,跳转到授权页面
wx.reLaunch({
url: '/pages/auth'
});
}
} }
}); });
wx.setStorageSync('onNetworkStatusChange', true); wx.setStorageSync('onNetworkStatusChange', true);
...@@ -59,7 +41,6 @@ wepy.app({ ...@@ -59,7 +41,6 @@ wepy.app({
{ {
pages: [ pages: [
'pages/index', 'pages/index',
'pages/auth'
], ],
window: { window: {
navigationStyle: "custom", navigationStyle: "custom",
......
<style lang="less">
.contain {
padding:200rpx 0;
}
</style>
<template>
<div class="contain">
<p>需要进行微信授权</p>
<button open-type="getUserInfo" bindgetuserinfo="getUserInfo">授权登录</button>
</div>
</template>
<script>
import { mapActions } from '@wepy/x';
import wepy from '@wepy/core';
import store from '../store';
wepy.page({
store,
hooks: {
'before-setData': function (dirty) {
}
},
data: {
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
methods: {
...mapActions([ 'setUserInfo' ]),
getUserInfo (e) {
this.setUserInfo(e.$wx.detail.userInfo);
wx.reLaunch({
url: '/pages/index'
});
}
},
created () {
}
});
</script>
<config>
{
navigationBarTitleText: '微信授权',
usingComponents: {
'van-button': '../components/vant/button/index',
}
}
</config>
...@@ -89,12 +89,13 @@ ...@@ -89,12 +89,13 @@
margin-top: 2rpx; margin-top: 2rpx;
} }
.list-item image { .list-item image {
width: 100%; width: 95%;
max-height: 102px; display: block;
height: 85px;
margin:0 auto;
} }
.list-item .text { .list-item .text {
font-size: 10px; font-size: 10px;
margin-top: -5px;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
...@@ -134,8 +135,31 @@ ...@@ -134,8 +135,31 @@
position: absolute; position: absolute;
z-index: 7; z-index: 7;
} }
.authmodal{
width:100%;
height:100%;
background-color: rgba(0,0,0,0.7);
position: fixed;
z-index:20;
.wrap {
width: 90%;
margin:0 auto;
position: relative;
top:200px;
padding: 50rpx 0;
background-color: #fff;
border-radius: 20rpx;
.text {
color:#333;
text-align: center;
}
button {
width:80%;
}
}
}
</style> </style>
<wxs module="tools" lang="babel"> <wxs module="tools">
function computClass (current,index,length) { function computClass (current,index,length) {
var allclass = ""; var allclass = "";
if(current==index) if(current==index)
...@@ -160,9 +184,8 @@ ...@@ -160,9 +184,8 @@
<view class="userInfo"> <view class="userInfo">
<image src="{{userInfo.avatarUrl}}" mode="cover" class="userimage"></image> <image src="{{userInfo.avatarUrl}}" mode="cover" class="userimage"></image>
</view> </view>
<video-gold type="gold"></video-gold>
<video-sign type="sign" :sign="sign" @sign-in="signIn"></video-sign>
<view class="content"> <view class="content">
<!-- <video-sign title="签"></video-sign> -->
<view class="leftcont"> <view class="leftcont">
<view>零售价:¥190003.00元</view> <view>零售价:¥190003.00元</view>
<view>开奖时间:15:20</view> <view>开奖时间:15:20</view>
...@@ -197,7 +220,7 @@ ...@@ -197,7 +220,7 @@
bindtouchend="touchEnd" bindtouchend="touchEnd"
class="list-item {{item.select?'delete':''}} {{tools.computClass(currentIndex,index,list.length)}}" class="list-item {{item.select?'delete':''}} {{tools.computClass(currentIndex,index,list.length)}}"
> >
<image src="/static/images/test2.png" mode="widthFix"></image> <image src="/static/images/test2.png"></image>
<view class="text">{{item.text}}</view> <view class="text">{{item.text}}</view>
<view class="goods"> <view class="goods">
<text class="price">¥99.9</text><text class="buy">2200人购买</text> <text class="price">¥99.9</text><text class="buy">2200人购买</text>
...@@ -218,7 +241,6 @@ ...@@ -218,7 +241,6 @@
import store from '../store'; import store from '../store';
import { mapState, mapActions } from '@wepy/x'; import { mapState, mapActions } from '@wepy/x';
import wepy from '@wepy/core'; import wepy from '@wepy/core';
wepy.page({ wepy.page({
store, store,
hooks: { hooks: {
...@@ -229,7 +251,7 @@ ...@@ -229,7 +251,7 @@
list:[], list:[],
adlist:[], adlist:[],
current:5, current:5,
userInfo: {}, // userInfo: {},
swiperItem:3, swiperItem:3,
videoList:[], videoList:[],
length: 4, length: 4,
...@@ -237,16 +259,17 @@ ...@@ -237,16 +259,17 @@
topPage:0, topPage:0,
lastPage:0, lastPage:0,
currentIndex:5, currentIndex:5,
authmodal:false,
sign: false, sign: false,
showAnimation: false, showAnimation: false,
}, },
computed: { computed: {
...mapState([ 'isConnected' ]) ...mapState([ 'isConnected', 'userInfo' ])
}, },
methods: { methods: {
...mapActions([ 'setIsConnected' ]), ...mapActions([ 'setIsConnected', 'setUserInfo' ]),
moveSwiper(e){ moveSwiper(e){
if(e.$wx.detail.source == 'touch') { if(e.$wx.detail.source == 'touch') {
let current = e.$wx.detail.current; let current = e.$wx.detail.current;
...@@ -283,7 +306,6 @@ ...@@ -283,7 +306,6 @@
if (callNow) func(); if (callNow) func();
} }
} }
console.log(current,this.list.length,222);
if(current <= 2) { if(current <= 2) {
debounce(setTimeout(function(){ debounce(setTimeout(function(){
that.topPage +=1; that.topPage +=1;
...@@ -364,7 +386,7 @@ ...@@ -364,7 +386,7 @@
} }
}, },
forbidMove() { forbidMove() {
}, },
changeVideo(e) { changeVideo(e) {
this.setIsConnected(); this.setIsConnected();
...@@ -377,7 +399,7 @@ ...@@ -377,7 +399,7 @@
} }
// }, 3000) // }, 3000)
}, },
deleteAnimation: function(current) { deleteAnimation (current) {
if (current && current.itemid != undefined) { if (current && current.itemid != undefined) {
let list = this.list; let list = this.list;
list = list.map((item, index) => { list = list.map((item, index) => {
...@@ -398,15 +420,6 @@ ...@@ -398,15 +420,6 @@
that.list = newlist; that.list = newlist;
}, 500); }, 500);
} }
},
signIn: function(v) {
this.sign = v;
this.showAnimation = this.sign;
// if (timeout) timeout = null;
// timeout = setTimeout(() => {
// this.showAnimation = false;
// }, 1000);
// console.log(this.sign);
} }
}, },
...@@ -419,11 +432,6 @@ ...@@ -419,11 +432,6 @@
success (res) { success (res) {
self.userInfo = res.userInfo; self.userInfo = res.userInfo;
store.dispatch('setUserInfo', res.userInfo); store.dispatch('setUserInfo', res.userInfo);
},
fail () {
wx.reLaunch({
url: '/pages/auth'
});
} }
}); });
} }
...@@ -458,7 +466,35 @@ ...@@ -458,7 +466,35 @@
this.videoList = urls.map((url, index) => ({ id: index + 1, url })); this.videoList = urls.map((url, index) => ({ id: index + 1, url }));
}, },
onLoad () { onLoad () {
let that = this;
//如果已经存在store里就不用再获取用户信息了
if(this.userInfo) return;
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
if(res.userInfo) {
that.setUserInfo(res.userInfo);
// that.userInfo = res.userInfo;
}
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (that.userInfoReadyCallback) {
that.userInfoReadyCallback(res => {
that.setUserInfo(res.userInfo||{});
// that.userInfo = res.userInfo||{};
})
}
}
})
}else{
that.authmodal = true;
}
}
});
}, },
}); });
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment