Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
swx_weapp
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
You need to sign in or sign up before continuing.
Authored by
hookehuyr
2022-10-18 17:21:46 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
65674986395aee146c6c503aa3a28b458455daa9
65674986
1 parent
a9065107
授权接口正式版联调
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
36 deletions
src/pages/auth/index.vue
src/pages/auth/index.vue
View file @
6567498
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-10-18 1
6:09:34
* @LastEditTime: 2022-10-18 1
7:17:17
* @FilePath: /swx/src/pages/auth/index.vue
* @Description: 文件描述
-->
<template>
<div>
<button wx:if="{{canIUse}}" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">授权登录</button>
<view @tap="auth">授权登陆</view>
<
!-- <
button wx:if="{{canIUse}}" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">授权登录</button>
<view @tap="auth">授权登陆</view>
-->
</div>
</template>
...
...
@@ -16,7 +16,6 @@
import Taro from '@tarojs/taro'
import { ref } from "vue";
import request from '@/utils/request';
import { userInfo } from 'os';
</script>
...
...
@@ -25,30 +24,38 @@ import "./index.less";
export default {
name: "authPage",
mounted () {
// TODO: 现在先传openid,小程序的密钥还有搞到
// 小程序预览,接口没有跑起来,真机调试可以运行
request.post('/srv/?a=openid', {
openid: 'wxa2e50e76487d1d7b'
})
.then(res => {
if (res.data.code) {
var cookie = res.cookies[0];
if (cookie != null) {
wx.setStorageSync("sessionid", res.cookies[0]);//服务器返回的 Set-Cookie,保存到本地
//TAG 小程序绑定cookie
// 修改请求头
request.defaults.headers.cookie = res.cookies[0];
Taro.navigateBack({
delta: 1 // 返回上一级页面。
// 授权登陆
Taro.login({
success: function (res) {
if (res.code) {
//发起网络请求
request.post('/srv/?a=openid', {
code: res.code
})
.then(res => {
if (res.data.code) {
var cookie = res.cookies[0];
if (cookie != null) {
wx.setStorageSync("sessionid", res.cookies[0]);//服务器返回的 Set-Cookie,保存到本地
//TAG 小程序绑定cookie
// 修改请求头
request.defaults.headers.cookie = res.cookies[0];
Taro.navigateBack({
delta: 1 // 返回上一级页面。
});
}
} else {
console.warn(res.data.msg);
}
})
.catch(err => {
console.error(err);
});
} else {
console.log('登录失败!' + res.errMsg)
}
} else {
console.warn(res.data.msg);
}
})
.catch(err => {
console.error(err);
});
},
data () {
return {
...
...
@@ -57,18 +64,18 @@ export default {
},
onLoad: function() {
// 查看是否授权
wx.getSetting({
success (res){
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({
success: function(res) {
console.warn(res.userInfo)
}
})
}
}
})
//
wx.getSetting({
//
success (res){
//
if (res.authSetting['scope.userInfo']) {
//
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
//
wx.getUserInfo({
//
success: function(res) {
//
console.warn(res.userInfo)
//
}
//
})
//
}
//
}
//
})
},
methods: {
bindGetUserInfo (e) {
...
...
Please
register
or
login
to post a comment