| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import shuoAPI, { shuoAPIClient } from '../api/api.js'
- import shuoUser from '../user/user.js';
- Component({
- properties: {
- // 属性值可以在组件使用时指定
-
- },
- data: {
- // 这里是一些组件内部数据
- selfAuthVisible: false
- },
-
- ready: function () {
- // 在组件实例进入页面节点树时执行
- let that = this
- //获取授权
- wx.checkSession({
- success: function () {
- console.log(" onLoad sessionId:", shuoUser.getMyTokenSync());
- if (!shuoUser.checkMyToken()) {
- that.loginAndInitData();
- }
- },
- fail: function () {
- console.log('fail session ')
- that.loginAndInitData();
- }
- });
- },
- detached: function () {
- // 在组件实例被从页面节点树移除时执行
- },
- methods: {
- // 这里是一个自定义方法
- loginAndInitData() {
- shuoAPI.wechatUserLogin().then(res => {
- console.log('wechatUserLogin res:', res);
- if (!res) {
- this.setData({
- selfAuthVisible: true
- })
- return;
- } else {
- this.initData()
- }
- });
- },
- // 授权遮罩
- authMask() {
- this.setData({
- selfAuthVisible: false
- })
- },
- // 点击获取用户信息
- onGotUserInfo(e) {
- console.log('点击获取用户信息: ', e.detail)
- wx.setStorageSync('userInfo', e.detail.userInfo)
- this.loginAndInitData()
- this.setData({
- selfAuthVisible: false
- })
- console.log('getCurrentPages()', getCurrentPages())
- },
- //初始化数据
- initData() {
- this.triggerEvent('loginCallBack', true) //myevent自定义名称事件,父组件中使用
- },
- }
- })
|