Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mini-program-wepy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ui
mini-program-wepy
Commits
a4c4f49a
Commit
a4c4f49a
authored
May 19, 2020
by
付清曌
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/userinfo' into 'master'
Feature/userinfo See merge request
!1
parents
fcd7cf84
cbffa4f7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
114 deletions
+81
-114
app.wpy
src/app.wpy
+16
-35
auth.wpy
src/pages/auth.wpy
+0
-50
index.wpy
src/pages/index.wpy
+65
-29
No files found.
src/app.wpy
View file @
a4c4f49a
...
...
@@ -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);
});
}
},
fail: () => {
wx.reLaunch({
url: '/pages/auth'
});
wx.checkSession({
success () {
console.log('已登录')
//session_key 未过期,并且在本生命周期一直有效
},
fail () {
// session_key 已经失效,需要重新执行登录流程
wx.login({
success (res) {
if (res.code) {
//发起网络请求,告诉后端
wx.setStorageSync('wxCode',res.code);
} else {
console.log('登录失败!' + res.errMsg)
}
});
} else {
// 未授权,跳转到授权页面
wx.reLaunch({
url: '/pages/auth'
});
}
}
})
}
});
wx.setStorageSync('onNetworkStatusChange', true);
...
...
@@ -59,7 +41,6 @@ wepy.app({
{
pages: [
'pages/index',
'pages/auth'
],
window: {
navigationStyle: "custom",
...
...
src/pages/auth.wpy
deleted
100644 → 0
View file @
fcd7cf84
<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>
src/pages/index.wpy
View file @
a4c4f49a
...
...
@@ -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;
...
...
@@ -364,7 +386,7 @@
}
},
forbidMove() {
},
changeVideo(e) {
this.setIsConnected();
...
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment