add member status judgement
parent
5614ce5818
commit
2d5ce655ef
|
|
@ -50,10 +50,16 @@ export default {
|
||||||
data: {},
|
data: {},
|
||||||
},
|
},
|
||||||
'POST /member/login': {
|
'POST /member/login': {
|
||||||
data: {},
|
success: true,
|
||||||
|
data: {
|
||||||
|
isMember: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'GET /member/tickets/uncompleted': {
|
'GET /member/tickets/uncompleted': {
|
||||||
success: true,
|
success: true,
|
||||||
data: uncompleted,
|
data: uncompleted,
|
||||||
},
|
},
|
||||||
|
'POST /member/logout': {
|
||||||
|
success: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,65 +6,85 @@ import wechatUser from '@/wechat';
|
||||||
import 'taro-ui/dist/style/index.scss';
|
import 'taro-ui/dist/style/index.scss';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
|
||||||
const navList: Array<Taro.TabBarItem> = [
|
const navList: () => Array<Taro.TabBarItem> = () => {
|
||||||
{
|
return wechatUser.getAccess()
|
||||||
pagePath: '/pages/index/index',
|
? [
|
||||||
text: pt.get().tabBar.indexText,
|
{
|
||||||
},
|
pagePath: '/pages/index/index',
|
||||||
{
|
text: pt.get().tabBar.indexText,
|
||||||
pagePath: '/pages/repair/repair',
|
},
|
||||||
text: pt.get().tabBar.repairText,
|
{
|
||||||
},
|
pagePath: '/pages/repair/repair',
|
||||||
{
|
text: pt.get().tabBar.repairText,
|
||||||
pagePath: '/pages/member/member',
|
},
|
||||||
text: pt.get().tabBar.memberText,
|
{
|
||||||
},
|
pagePath: '/pages/member/member',
|
||||||
{
|
text: pt.get().tabBar.memberText,
|
||||||
pagePath: '/pages/user/user',
|
},
|
||||||
text: pt.get().tabBar.userText,
|
{
|
||||||
},
|
pagePath: '/pages/user/user',
|
||||||
];
|
text: pt.get().tabBar.userText,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
{
|
||||||
|
pagePath: '/pages/index/index',
|
||||||
|
text: pt.get().tabBar.indexText,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pagePath: '/pages/repair/repair',
|
||||||
|
text: pt.get().tabBar.repairText,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pagePath: '/pages/user/user',
|
||||||
|
text: pt.get().tabBar.userText,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
const tabList = () => {
|
||||||
|
return wechatUser.getAccess()
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
title: pt.get().tabBar.indexText,
|
||||||
|
iconType: 'home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: pt.get().tabBar.repairText,
|
||||||
|
iconType: 'settings',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: pt.get().tabBar.memberText,
|
||||||
|
iconType: 'sketch',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: pt.get().tabBar.userText,
|
||||||
|
iconType: 'user',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
{
|
||||||
|
title: pt.get().tabBar.indexText,
|
||||||
|
iconType: 'home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: pt.get().tabBar.repairText,
|
||||||
|
iconType: 'settings',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: pt.get().tabBar.userText,
|
||||||
|
iconType: 'user',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
export default class Index extends Component {
|
export default class Index extends Component {
|
||||||
state = {
|
state = {
|
||||||
selected: 0,
|
selected: 0,
|
||||||
tabList: wechatUser.getAccess()
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
title: pt.get().tabBar.indexText,
|
|
||||||
iconType: 'home',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: pt.get().tabBar.repairText,
|
|
||||||
iconType: 'settings',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: pt.get().tabBar.memberText,
|
|
||||||
iconType: 'sketch',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: pt.get().tabBar.userText,
|
|
||||||
iconType: 'user',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
{
|
|
||||||
title: pt.get().tabBar.indexText,
|
|
||||||
iconType: 'home',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: pt.get().tabBar.repairText,
|
|
||||||
iconType: 'settings',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: pt.get().tabBar.userText,
|
|
||||||
iconType: 'user',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleClick(idx: number) {
|
handleClick(idx: number) {
|
||||||
this.switchTab(idx, navList[idx].pagePath);
|
this.switchTab(idx, navList()[idx].pagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
switchTab(idx: number, url: string) {
|
switchTab(idx: number, url: string) {
|
||||||
|
|
@ -82,7 +102,7 @@ export default class Index extends Component {
|
||||||
return (
|
return (
|
||||||
<AtTabBar
|
<AtTabBar
|
||||||
fixed
|
fixed
|
||||||
tabList={this.state.tabList}
|
tabList={tabList()}
|
||||||
onClick={this.handleClick.bind(this)}
|
onClick={this.handleClick.bind(this)}
|
||||||
current={this.state.selected}
|
current={this.state.selected}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
import { Component, ReactNode } from 'react';
|
import { Component, ReactNode } from 'react';
|
||||||
import { AtForm, AtInput, AtButton, AtMessage } from 'taro-ui';
|
import { AtForm, AtInput, AtButton, AtMessage } from 'taro-ui';
|
||||||
import { getUrl } from '@/service';
|
|
||||||
import Taro from '@tarojs/taro';
|
import Taro from '@tarojs/taro';
|
||||||
import pt from '@/plain-text';
|
import pt from '@/plain-text';
|
||||||
|
import { memberLogin, memberLogout } from '@/service/memberLogin';
|
||||||
|
import wechatUser from '@/wechat';
|
||||||
import './member.scss';
|
import './member.scss';
|
||||||
|
|
||||||
const loginInterval = 5000;
|
export default class UserMemberPage extends Component {
|
||||||
|
|
||||||
export default class MemberPage extends Component {
|
|
||||||
state = {
|
state = {
|
||||||
stuid: '',
|
stuid: '',
|
||||||
passwd: '',
|
passwd: '',
|
||||||
|
|
@ -32,46 +31,15 @@ export default class MemberPage extends Component {
|
||||||
return passwd;
|
return passwd;
|
||||||
}
|
}
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
this.setState({
|
memberLogin(this);
|
||||||
isLoading: true,
|
}
|
||||||
isDisable: true,
|
|
||||||
});
|
onLogout() {
|
||||||
console.log([this.state.stuid, this.state.passwd]);
|
memberLogout(this);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): ReactNode {
|
render(): ReactNode {
|
||||||
return (
|
return !wechatUser.getAccess() ? (
|
||||||
<AtForm onSubmit={this.onSubmit.bind(this)}>
|
<AtForm onSubmit={this.onSubmit.bind(this)}>
|
||||||
<AtMessage />
|
<AtMessage />
|
||||||
<AtInput
|
<AtInput
|
||||||
|
|
@ -103,6 +71,10 @@ export default class MemberPage extends Component {
|
||||||
{pt.get().button.buttonText.login}
|
{pt.get().button.buttonText.login}
|
||||||
</AtButton>
|
</AtButton>
|
||||||
</AtForm>
|
</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,
|
clicks: memberClickTimes,
|
||||||
isToastOpen: false,
|
isToastOpen: false,
|
||||||
toastText: '',
|
toastText: '',
|
||||||
haveAccess: wechatUser.getAccess(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 以下是TabBar相关
|
// 以下是TabBar相关
|
||||||
pageCtx = Taro.getCurrentInstance().page;
|
pageCtx = Taro.getCurrentInstance().page;
|
||||||
componentDidShow() {
|
componentDidShow() {
|
||||||
const tabbar = Taro.getTabBar<CustomTabBar>(this.pageCtx);
|
const tabbar = Taro.getTabBar<CustomTabBar>(this.pageCtx);
|
||||||
tabbar?.setSelected(this.state.haveAccess ? 3 : 2);
|
tabbar?.setSelected(wechatUser.getAccess() ? 3 : 2);
|
||||||
}
|
}
|
||||||
// 以上是TabBar相关
|
// 以上是TabBar相关
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ export interface ButtonText {
|
||||||
submit: string;
|
submit: string;
|
||||||
reset: string;
|
reset: string;
|
||||||
login: string;
|
login: string;
|
||||||
|
logout: string;
|
||||||
};
|
};
|
||||||
submitText: {
|
submitText: {
|
||||||
success: string;
|
success: string;
|
||||||
|
|
@ -12,6 +13,10 @@ export interface ButtonText {
|
||||||
success: string;
|
success: string;
|
||||||
error: string;
|
error: string;
|
||||||
};
|
};
|
||||||
|
logoutText: {
|
||||||
|
success: string;
|
||||||
|
error: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const buttonZhCn: ButtonText = {
|
export const buttonZhCn: ButtonText = {
|
||||||
|
|
@ -19,6 +24,7 @@ export const buttonZhCn: ButtonText = {
|
||||||
submit: '提交',
|
submit: '提交',
|
||||||
reset: '清空',
|
reset: '清空',
|
||||||
login: '登录',
|
login: '登录',
|
||||||
|
logout: '登出',
|
||||||
},
|
},
|
||||||
submitText: {
|
submitText: {
|
||||||
success: '提交成功',
|
success: '提交成功',
|
||||||
|
|
@ -28,6 +34,10 @@ export const buttonZhCn: ButtonText = {
|
||||||
success: '登录成功',
|
success: '登录成功',
|
||||||
error: '登录失败',
|
error: '登录失败',
|
||||||
},
|
},
|
||||||
|
logoutText: {
|
||||||
|
success: '登出成功',
|
||||||
|
error: '登出失败',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const buttonEnUs: ButtonText = {
|
export const buttonEnUs: ButtonText = {
|
||||||
|
|
@ -35,6 +45,7 @@ export const buttonEnUs: ButtonText = {
|
||||||
submit: 'Submit',
|
submit: 'Submit',
|
||||||
reset: 'Reset',
|
reset: 'Reset',
|
||||||
login: 'Login',
|
login: 'Login',
|
||||||
|
logout: 'Logout',
|
||||||
},
|
},
|
||||||
submitText: {
|
submitText: {
|
||||||
success: 'Success',
|
success: 'Success',
|
||||||
|
|
@ -44,4 +55,8 @@ export const buttonEnUs: ButtonText = {
|
||||||
success: 'Login Success',
|
success: 'Login Success',
|
||||||
error: 'Login Failed',
|
error: 'Login Failed',
|
||||||
},
|
},
|
||||||
|
logoutText: {
|
||||||
|
success: 'Logout Success',
|
||||||
|
error: 'Logout Failed',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
import UserMemberPage from '@/pages/user/member/member';
|
||||||
|
import Taro from '@tarojs/taro';
|
||||||
|
import pt from '@/plain-text';
|
||||||
|
import wechatUser from '@/wechat';
|
||||||
|
import { getUrl } from '.';
|
||||||
|
|
||||||
|
const logInterval = 5000;
|
||||||
|
|
||||||
|
export function memberLogin(that: UserMemberPage) {
|
||||||
|
that.setState({
|
||||||
|
isLoading: true,
|
||||||
|
});
|
||||||
|
Taro.request({
|
||||||
|
url: getUrl('/member/login'),
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
token: 'token_test',
|
||||||
|
name: that.state.stuid,
|
||||||
|
phone: that.state.passwd,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res.data);
|
||||||
|
that.setState({
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
|
Taro.atMessage({
|
||||||
|
message: pt.get().button.loginText.success,
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
|
wechatUser.setAccess(true);
|
||||||
|
Taro.reLaunch({
|
||||||
|
url: '/pages/member/member',
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
that.setState({
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
|
Taro.atMessage({
|
||||||
|
message: pt.get().button.loginText.error + err.toString(),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
this.setState({
|
||||||
|
isDisable: false,
|
||||||
|
});
|
||||||
|
}, logInterval);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function memberLogout(that: UserMemberPage) {
|
||||||
|
that.setState({
|
||||||
|
isLoading: true,
|
||||||
|
});
|
||||||
|
Taro.request({
|
||||||
|
url: getUrl('/member/logout'),
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
token: 'token_test',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res.data);
|
||||||
|
that.setState({
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
|
Taro.atMessage({
|
||||||
|
message: pt.get().button.logoutText.success,
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
|
wechatUser.setAccess(false);
|
||||||
|
Taro.reLaunch({
|
||||||
|
url: '/pages/index/index',
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
that.setState({
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
|
Taro.atMessage({
|
||||||
|
message: pt.get().button.logoutText.error + err.toString(),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
this.setState({
|
||||||
|
isDisable: false,
|
||||||
|
});
|
||||||
|
}, logInterval);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ class WechatUser {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.userInfo = '';
|
this.userInfo = '';
|
||||||
this.hasUserInfo = false;
|
this.hasUserInfo = false;
|
||||||
this.isMember = true;
|
this.isMember = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAccess() {
|
getAccess() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue