Showing
1 changed file
with
43 additions
and
36 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-19 14:11:06 | 2 | * @Date: 2022-09-19 14:11:06 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2022-10-18 16:09:34 | 4 | + * @LastEditTime: 2022-10-18 17:17:17 |
| 5 | * @FilePath: /swx/src/pages/auth/index.vue | 5 | * @FilePath: /swx/src/pages/auth/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| 8 | <template> | 8 | <template> |
| 9 | <div> | 9 | <div> |
| 10 | - <button wx:if="{{canIUse}}" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">授权登录</button> | 10 | + <!-- <button wx:if="{{canIUse}}" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">授权登录</button> |
| 11 | - <view @tap="auth">授权登陆</view> | 11 | + <view @tap="auth">授权登陆</view> --> |
| 12 | </div> | 12 | </div> |
| 13 | </template> | 13 | </template> |
| 14 | 14 | ||
| ... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
| 16 | import Taro from '@tarojs/taro' | 16 | import Taro from '@tarojs/taro' |
| 17 | import { ref } from "vue"; | 17 | import { ref } from "vue"; |
| 18 | import request from '@/utils/request'; | 18 | import request from '@/utils/request'; |
| 19 | -import { userInfo } from 'os'; | ||
| 20 | 19 | ||
| 21 | </script> | 20 | </script> |
| 22 | 21 | ||
| ... | @@ -25,30 +24,38 @@ import "./index.less"; | ... | @@ -25,30 +24,38 @@ import "./index.less"; |
| 25 | export default { | 24 | export default { |
| 26 | name: "authPage", | 25 | name: "authPage", |
| 27 | mounted () { | 26 | mounted () { |
| 28 | - // TODO: 现在先传openid,小程序的密钥还有搞到 | 27 | + // 授权登陆 |
| 29 | - // 小程序预览,接口没有跑起来,真机调试可以运行 | 28 | + Taro.login({ |
| 30 | - request.post('/srv/?a=openid', { | 29 | + success: function (res) { |
| 31 | - openid: 'wxa2e50e76487d1d7b' | 30 | + if (res.code) { |
| 32 | - }) | 31 | + //发起网络请求 |
| 33 | - .then(res => { | 32 | + request.post('/srv/?a=openid', { |
| 34 | - if (res.data.code) { | 33 | + code: res.code |
| 35 | - var cookie = res.cookies[0]; | 34 | + }) |
| 36 | - if (cookie != null) { | 35 | + .then(res => { |
| 37 | - wx.setStorageSync("sessionid", res.cookies[0]);//服务器返回的 Set-Cookie,保存到本地 | 36 | + if (res.data.code) { |
| 38 | - //TAG 小程序绑定cookie | 37 | + var cookie = res.cookies[0]; |
| 39 | - // 修改请求头 | 38 | + if (cookie != null) { |
| 40 | - request.defaults.headers.cookie = res.cookies[0]; | 39 | + wx.setStorageSync("sessionid", res.cookies[0]);//服务器返回的 Set-Cookie,保存到本地 |
| 41 | - Taro.navigateBack({ | 40 | + //TAG 小程序绑定cookie |
| 42 | - delta: 1 // 返回上一级页面。 | 41 | + // 修改请求头 |
| 42 | + request.defaults.headers.cookie = res.cookies[0]; | ||
| 43 | + Taro.navigateBack({ | ||
| 44 | + delta: 1 // 返回上一级页面。 | ||
| 45 | + }); | ||
| 46 | + } | ||
| 47 | + } else { | ||
| 48 | + console.warn(res.data.msg); | ||
| 49 | + } | ||
| 50 | + }) | ||
| 51 | + .catch(err => { | ||
| 52 | + console.error(err); | ||
| 43 | }); | 53 | }); |
| 54 | + } else { | ||
| 55 | + console.log('登录失败!' + res.errMsg) | ||
| 44 | } | 56 | } |
| 45 | - } else { | ||
| 46 | - console.warn(res.data.msg); | ||
| 47 | } | 57 | } |
| 48 | }) | 58 | }) |
| 49 | - .catch(err => { | ||
| 50 | - console.error(err); | ||
| 51 | - }); | ||
| 52 | }, | 59 | }, |
| 53 | data () { | 60 | data () { |
| 54 | return { | 61 | return { |
| ... | @@ -57,18 +64,18 @@ export default { | ... | @@ -57,18 +64,18 @@ export default { |
| 57 | }, | 64 | }, |
| 58 | onLoad: function() { | 65 | onLoad: function() { |
| 59 | // 查看是否授权 | 66 | // 查看是否授权 |
| 60 | - wx.getSetting({ | 67 | + // wx.getSetting({ |
| 61 | - success (res){ | 68 | + // success (res){ |
| 62 | - if (res.authSetting['scope.userInfo']) { | 69 | + // if (res.authSetting['scope.userInfo']) { |
| 63 | - // 已经授权,可以直接调用 getUserInfo 获取头像昵称 | 70 | + // // 已经授权,可以直接调用 getUserInfo 获取头像昵称 |
| 64 | - wx.getUserInfo({ | 71 | + // wx.getUserInfo({ |
| 65 | - success: function(res) { | 72 | + // success: function(res) { |
| 66 | - console.warn(res.userInfo) | 73 | + // console.warn(res.userInfo) |
| 67 | - } | 74 | + // } |
| 68 | - }) | 75 | + // }) |
| 69 | - } | 76 | + // } |
| 70 | - } | 77 | + // } |
| 71 | - }) | 78 | + // }) |
| 72 | }, | 79 | }, |
| 73 | methods: { | 80 | methods: { |
| 74 | bindGetUserInfo (e) { | 81 | bindGetUserInfo (e) { | ... | ... |
-
Please register or login to post a comment