add member status judgement
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import { Component, ReactNode } from 'react';
|
||||
import { AtForm, AtInput, AtButton, AtMessage } from 'taro-ui';
|
||||
import { getUrl } from '@/service';
|
||||
import Taro from '@tarojs/taro';
|
||||
import pt from '@/plain-text';
|
||||
import { memberLogin, memberLogout } from '@/service/memberLogin';
|
||||
import wechatUser from '@/wechat';
|
||||
import './member.scss';
|
||||
|
||||
const loginInterval = 5000;
|
||||
|
||||
export default class MemberPage extends Component {
|
||||
export default class UserMemberPage extends Component {
|
||||
state = {
|
||||
stuid: '',
|
||||
passwd: '',
|
||||
@@ -32,46 +31,15 @@ export default class MemberPage extends Component {
|
||||
return passwd;
|
||||
}
|
||||
onSubmit() {
|
||||
this.setState({
|
||||
isLoading: true,
|
||||
isDisable: true,
|
||||
});
|
||||
console.log([this.state.stuid, this.state.passwd]);
|
||||
Taro.request({
|
||||
url: getUrl('/member/login'),
|
||||
method: 'POST',
|
||||
data: {
|
||||
token: 'token_test',
|
||||
name: this.state.stuid,
|
||||
passwd: this.state.passwd,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(res.data);
|
||||
Taro.atMessage({
|
||||
message: pt.get().button.loginText.success,
|
||||
type: 'success',
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
Taro.atMessage({
|
||||
message: pt.get().button.loginText.error + err.toString(),
|
||||
type: 'error',
|
||||
});
|
||||
});
|
||||
this.setState({
|
||||
isLoading: false,
|
||||
});
|
||||
setTimeout(() => {
|
||||
this.setState({
|
||||
isDisable: false,
|
||||
});
|
||||
}, loginInterval);
|
||||
memberLogin(this);
|
||||
}
|
||||
|
||||
onLogout() {
|
||||
memberLogout(this);
|
||||
}
|
||||
|
||||
render(): ReactNode {
|
||||
return (
|
||||
return !wechatUser.getAccess() ? (
|
||||
<AtForm onSubmit={this.onSubmit.bind(this)}>
|
||||
<AtMessage />
|
||||
<AtInput
|
||||
@@ -103,6 +71,10 @@ export default class MemberPage extends Component {
|
||||
{pt.get().button.buttonText.login}
|
||||
</AtButton>
|
||||
</AtForm>
|
||||
) : (
|
||||
<AtButton type='primary' onClick={this.onLogout.bind(this)}>
|
||||
{pt.get().button.buttonText.logout}
|
||||
</AtButton>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,13 @@ export default class UserPage extends Component {
|
||||
clicks: memberClickTimes,
|
||||
isToastOpen: false,
|
||||
toastText: '',
|
||||
haveAccess: wechatUser.getAccess(),
|
||||
};
|
||||
|
||||
// 以下是TabBar相关
|
||||
pageCtx = Taro.getCurrentInstance().page;
|
||||
componentDidShow() {
|
||||
const tabbar = Taro.getTabBar<CustomTabBar>(this.pageCtx);
|
||||
tabbar?.setSelected(this.state.haveAccess ? 3 : 2);
|
||||
tabbar?.setSelected(wechatUser.getAccess() ? 3 : 2);
|
||||
}
|
||||
// 以上是TabBar相关
|
||||
|
||||
|
||||
Reference in New Issue
Block a user