wujingjing
2024-08-08 a689b45a6f80460f9891cc5a346036a7e4c4c0b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// pages/login/login.js
 
// 导入封装通用模块方法
import { toast } from '@/utils/extendApi'
// 导入本地存储 api
import { setStorage } from '@/utils/storage'
// 导入接口 API 函数
import { PostLogin } from '@/api/account';
// 导入 ComponentWithStore 方法
import { ComponentWithStore } from 'mobx-miniprogram-bindings'
// 导入 store 对象
import { accountStore } from '@/stores/accountStore'
 
import {STATIC_FILE_BASE_URL} from '@/config/constants'
 
// 使用 ComponentWithStore 方法替换 Component 方法构造页面
ComponentWithStore({
  // 让页面和 Store 对象建立关联
  storeBindings: {
    store: accountStore,
    fields: ['session', 'username'],
    actions: ['setSession', 'setUsername']
  },
  data: {
    activeTab: 'account',
    user: 'tc',
    password: 'a',
    STATIC_FILE_BASE_URL
  },
  lifetimes: {
    attached() {
      wx.hideHomeButton();
    }
  },
 
  methods: {
    tabChange: function (event) {
      this.setData({
        activeTab: event.detail.name
      })
 
    },
    // 授权登录
    login: wx.$_.debounce(async function () {
 
      let res: any = null;
      switch (this.data.activeTab) {
        case 'account':
          if (!this.data.user) {
            toast({
              title: '请输入账号!'
            });
            return;
          }
          if (!this.data.password) {
            toast({
              title: '请输入密码!'
            });
            return;
          }
 
          res = await PostLogin({
            user: this.data.user,
            pass: this.data.password,
          }, {
            noAuth: true
          });
          if (!res.json_ok || !res.hswatersession) {
            toast({
              title: res.json_msg
            })
            return;
          }
          break;
        case 'cellPhoneNumber':
          break;
        default:
          break;
      }
      setStorage('session', res.hswatersession);
      this.setSession(res.hswatersession)
      setStorage('username', this.data.user);
      this.setUsername(this.data.user);
      wx.switchTab({
        url: '/pages/question/question'
      });
    }, 500),
  }
})