Skip to content
This repository has been archived by the owner on Mar 12, 2022. It is now read-only.

Commit

Permalink
fix: #9 小程序登录
Browse files Browse the repository at this point in the history
  • Loading branch information
klren0312 committed Mar 3, 2019
1 parent b916d29 commit 02ab1a0
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
55 changes: 55 additions & 0 deletions App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@
console.log('App Launch')
},
onShow: function () {
// #ifdef MP-WEIXIN
// 获取是否授权状态, 没授权跳登录页
try {
const token = uni.getStorageSync('token');
if (token ==='' || token === undefined || token === null) {
uni.getSetting({
success: (res) => {
let status = res.authSetting['scope.userInfo']
this.$store.commit('SET_INFO', status)
console.log(status)
if (!status) {
uni.redirectTo({
url: '/pages/auth/auth'
})
}
}
})
} else {}
} catch (err) {}
// #endif
console.log('App Show')
},
onHide: function () {
Expand All @@ -14,11 +34,46 @@

<style>
@import 'common/uni.css';
@font-face {
font-family: iconfont;
src: url('~@/static/iconfont.ttf');
}
/*每个页面公共css */
page {
min-height: 100%;
display: flex;
flex-direction: column;
/* justify-content: center; */
}
.iconfont {
font-family: iconfont;
}
.header {
height: 210upx;
background: #376956;
position: fixed;
width: 100%;
top: 0;
z-index: 1024;
box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0.1);
text-align:center;
line-height:190rpx;
color:#fff;
font-size:54rpx;
}
.go-back {
position:absolute;
left:14rpx;
/* top:68rpx; */
color:#fff;
}
.wave-gif {
position: absolute;
width: 100%;
bottom: 0;
left: 0;
z-index: 99;
mix-blend-mode: screen;
height: 100upx;
}
</style>
69 changes: 69 additions & 0 deletions pages/auth/auth.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<template>
<view>
<view class="login-banner">
</view>
<button class="login-btn" open-type="getUserInfo" @getuserinfo="getInfo">微信登录</button>
</view>
</template>

<script>
export default {
data() {
return {
code: ''
};
},
methods: {
getInfo(info) {
const {encryptedData, iv, signature} = info.target
uni.login({
provider: 'weixin',
success: (loginRes) => {
// 获取用户信息
uni.getUserInfo({
provider: 'weixin',
lang: 'zh_CN',
success: (infoRes) => {
const {encryptedData, iv, signature} = infoRes
wx.request({
url: `${this.$store.state.rootUrl}/weapp/login`,
method: 'POST',
data: {
crypted: encryptedData,
iv: iv,
signature: signature,
code: loginRes.code
},
success: (res) => {
uni.setStorageSync('token', res.data.token)
this.$store.commit('SET_INFO', true)
console.log("is", true)
// 跳tabbar必须用这个...
uni.switchTab({
url: '/pages/home/home'
});
}
})
}
});
}
})
}
}
}
</script>

<style>
.login-banner {
height: 600upx;
background: url(https://zzes-1251916954.cos.ap-shanghai.myqcloud.com/login-banner.png) center no-repeat;
background-size:100%;
background-position-y:0;
}
.login-btn {
width:60%;
margin-top:20%;
color: #2fc67b;
border:1px solid #2fc67b;
}
</style>
5 changes: 5 additions & 0 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ Vue.use(Vuex)
const store = new Vuex.Store({
state: {
rootUrl: "https://tlgcapi.zzes1314.cn/api/v1",
// rootUrl: "http://localhost:7001/api/v1",
userinfo: false
},
mutations: {
SET_INFO (state, status) {
state.userinfo = status
}
},
actions: {
}
Expand Down

0 comments on commit 02ab1a0

Please sign in to comment.