// 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),
|
}
|
})
|