Browse Source

增加授权登录

master
lihua 5 years ago
parent
commit
0842a4f305
  1. 2
      .gitignore
  2. 6
      pages.json
  3. 105
      pages/index/index.vue

2
.gitignore

@ -65,4 +65,4 @@ fabric.properties
# Android studio 3.1+ serialized cache file # Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser .idea/caches/build_file_checksums.ser
unpackage

6
pages.json

@ -1,6 +1,9 @@
{ {
"pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages "pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages
{
"path" : "pages/index/index",
"style" : {"navigationBarTitleText": "授权登录"}
},
{ {
"path": "pages/device/device", "path": "pages/device/device",
"style": {"navigationBarTitleText": "设备"} "style": {"navigationBarTitleText": "设备"}
@ -9,6 +12,7 @@
"path" : "pages/about/about", "path" : "pages/about/about",
"style" : {"navigationBarTitleText": "关于"} "style" : {"navigationBarTitleText": "关于"}
} }
], ],
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",

105
pages/index/index.vue

@ -0,0 +1,105 @@
<template>
<view>
<view class='header'>
<image src='../../static/logo.png'></image>
</view>
<view class='content'>
<view>申请获取以下权限</view>
<text>获得你的公开信息(昵称头像等)</text>
</view>
<button class='bottom' type='primary' open-type="getUserInfo" @getuserinfo="bindGetUserInfo">
授权登录
</button>
</view>
</template>
<script>
export default {
data() {
return {
}
},
onLoad(){
uni.getSetting({
success(res) {
if(res && res.authSetting['scope.userInfo']){
uni.getUserInfo({
provider: 'weixin',
success:function(infoRes) {
wx.login({
success: res => {
console.log("用户的code:" + res.code);
}
});
}
})
}else{
uni.switchTab({url: '/pages/device/device'})
}
}
})
},
methods: {
bindGetUserInfo(e) {
if (e.detail.userInfo) {
//
var that = this;
//
console.log("用户的信息如下:");
console.log(e.detail.userInfo);
uni.switchTab({url: '/pages/device/device'})
} else {
//
uni.showModal({
title: '警告',
content: '您点击了拒绝授权,将无法进入小程序,请授权之后再进入!!!',
showCancel: false,
confirmText: '返回授权',
success: function(res) {
// isHide
if (res.confirm) {
console.log('用户点击了“返回授权”');
}
}
});
}
}
}
}
</script>
<style scoped>
.header {
margin: 90rpx 0 90rpx 50rpx;
border-bottom: 1px solid #ccc;
text-align: center;
width: 650rpx;
height: 300rpx;
line-height: 450rpx;
}
.header image {
width: 200rpx;
height: 200rpx;
}
.content {
margin-left: 50rpx;
margin-bottom: 90rpx;
}
.content text {
display: block;
color: #9d9d9d;
margin-top: 40rpx;
}
.bottom {
border-radius: 80rpx;
margin: 70rpx 50rpx;
font-size: 35rpx;
}
</style>
Loading…
Cancel
Save