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';
import vuex from '@wepy/x';
wepy.use(vuex);
// import store from './store';
wepy.app({
hooks: {
// App 级别 hook,对整个 App 生效
// 同时存在 Page hook 和 App hook 时,优先执行 Page hook,返回值再交由 App hook 处
},
data: {
userInfo: null
},
onLaunch() {
let that = this;
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
// store.dispatch('setUserInfo',res.userInfo);
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (that.userInfoReadyCallback) {
that.userInfoReadyCallback(res => {
// store.dispatch('setUserInfo',res.userInfo);
});
}
wx.checkSession({
success () {
console.log('已登录')
//session_key 未过期,并且在本生命周期一直有效
},
fail: () => {
wx.reLaunch({
url: '/pages/auth'
});
}
});
fail () {
// session_key 已经失效,需要重新执行登录流程
wx.login({
success (res) {
if (res.code) {
//发起网络请求,告诉后端
wx.setStorageSync('wxCode',res.code);
} else {
// 未授权,跳转到授权页面
wx.reLaunch({
url: '/pages/auth'
});
console.log('登录失败!' + res.errMsg)
}
}
})
}
});
wx.setStorageSync('onNetworkStatusChange', true);
......@@ -59,7 +41,6 @@ wepy.app({
{
pages: [
'pages/index',
'pages/auth'
],
window: {
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 @@
margin-top: 2rpx;
}
.list-item image {
width: 100%;
max-height: 102px;
width: 95%;
display: block;
height: 85px;
margin:0 auto;
}
.list-item .text {
font-size: 10px;
margin-top: -5px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
......@@ -134,8 +135,31 @@
position: absolute;
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>
<wxs module="tools" lang="babel">
<wxs module="tools">
function computClass (current,index,length) {
var allclass = "";
if(current==index)
......@@ -160,9 +184,8 @@
<view class="userInfo">
<image src="{{userInfo.avatarUrl}}" mode="cover" class="userimage"></image>
</view>
<video-gold type="gold"></video-gold>
<video-sign type="sign" :sign="sign" @sign-in="signIn"></video-sign>
<view class="content">
<!-- <video-sign title="签"></video-sign> -->
<view class="leftcont">
<view>零售价:¥190003.00元</view>
<view>开奖时间:15:20</view>
......@@ -197,7 +220,7 @@
bindtouchend="touchEnd"
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="goods">
<text class="price">¥99.9</text><text class="buy">2200人购买</text>
......@@ -218,7 +241,6 @@
import store from '../store';
import { mapState, mapActions } from '@wepy/x';
import wepy from '@wepy/core';
wepy.page({
store,
hooks: {
......@@ -229,7 +251,7 @@
list:[],
adlist:[],
current:5,
userInfo: {},
// userInfo: {},
swiperItem:3,
videoList:[],
length: 4,
......@@ -237,16 +259,17 @@
topPage:0,
lastPage:0,
currentIndex:5,
authmodal:false,
sign: false,
showAnimation: false,
},
computed: {
...mapState([ 'isConnected' ])
...mapState([ 'isConnected', 'userInfo' ])
},
methods: {
...mapActions([ 'setIsConnected' ]),
...mapActions([ 'setIsConnected', 'setUserInfo' ]),
moveSwiper(e){
if(e.$wx.detail.source == 'touch') {
let current = e.$wx.detail.current;
......@@ -283,7 +306,6 @@
if (callNow) func();
}
}
console.log(current,this.list.length,222);
if(current <= 2) {
debounce(setTimeout(function(){
that.topPage +=1;
......@@ -377,7 +399,7 @@
}
// }, 3000)
},
deleteAnimation: function(current) {
deleteAnimation (current) {
if (current && current.itemid != undefined) {
let list = this.list;
list = list.map((item, index) => {
......@@ -398,15 +420,6 @@
that.list = newlist;
}, 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 @@
success (res) {
self.userInfo = res.userInfo;
store.dispatch('setUserInfo', res.userInfo);
},
fail () {
wx.reLaunch({
url: '/pages/auth'
});
}
});
}
......@@ -458,7 +466,35 @@
this.videoList = urls.map((url, index) => ({ id: index + 1, url }));
},
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>
......
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