add inform page request

yhy
Dawn_Ocean 2024-03-08 22:45:40 +08:00
parent b174304d74
commit dd770b8ece
7 changed files with 73 additions and 45 deletions

View File

@ -1,9 +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 './inform.scss'; import './inform.scss';
const submitInterval = 5000;
export default class InformPage extends Component { export default class InformPage extends Component {
state = { state = {
phone: '', phone: '',
@ -29,19 +32,39 @@ export default class InformPage extends Component {
isDisable: true, isDisable: true,
}); });
console.log(this.state.name, this.state.phone); console.log(this.state.name, this.state.phone);
Taro.request({
url: getUrl('/user/update'),
method: 'POST',
data: {
token: 'token_test',
name: this.state.name,
phone: this.state.phone,
},
})
.then(res => {
console.log(res.data);
Taro.atMessage({
message: pt.get().button.submitText.success,
type: 'success',
});
})
.catch(err => {
console.log(err);
Taro.atMessage({
message: pt.get().button.submitText.error + err.toString(),
type: 'error',
});
});
this.setState({ this.setState({
isLoading: false, isLoading: false,
}); });
Taro.atMessage({
message: pt.get().informPage.submitText.success,
type: 'success',
});
setTimeout(() => { setTimeout(() => {
this.setState({ this.setState({
isDisable: false, isDisable: false,
}); });
}, 5000); }, submitInterval);
} }
onReset() { onReset() {
this.setState({ this.setState({
phone: '', phone: '',
@ -79,10 +102,10 @@ export default class InformPage extends Component {
type='primary' type='primary'
disabled={this.state.isDisable} disabled={this.state.isDisable}
> >
{pt.get().informPage.buttonText.submit} {pt.get().button.buttonText.submit}
</AtButton> </AtButton>
<AtButton formType='reset' type='secondary'> <AtButton formType='reset' type='secondary'>
{pt.get().informPage.buttonText.reset} {pt.get().button.buttonText.reset}
</AtButton> </AtButton>
</AtForm> </AtForm>
); );

View File

@ -35,14 +35,14 @@ export default class SettingsPage extends Component {
.then(res => { .then(res => {
console.log(res.data); console.log(res.data);
Taro.atMessage({ Taro.atMessage({
message: '提交成功', message: pt.get().button.submitText.success,
type: 'success', type: 'success',
}); });
}) })
.catch(err => { .catch(err => {
console.log(err); console.log(err);
Taro.atMessage({ Taro.atMessage({
message: '提交失败,错误为:' + err.toString(), message: pt.get().button.submitText.error + err.toString(),
type: 'error', type: 'error',
}); });
}); });
@ -79,10 +79,10 @@ export default class SettingsPage extends Component {
type='primary' type='primary'
disabled={this.state.isDisable} disabled={this.state.isDisable}
> >
{pt.get().reportPage.buttonText.submit} {pt.get().button.buttonText.submit}
</AtButton> </AtButton>
<AtButton formType='reset' type='secondary'> <AtButton formType='reset' type='secondary'>
{pt.get().reportPage.buttonText.reset} {pt.get().button.buttonText.reset}
</AtButton> </AtButton>
</AtForm> </AtForm>
); );

View File

@ -10,6 +10,8 @@ import pt, { Lang } from '@/plain-text';
import logo from '@/assets/images/UserPage/logo.png'; import logo from '@/assets/images/UserPage/logo.png';
import './user.scss'; import './user.scss';
const listLangInterval = 20;
export default class UserPage extends Component { export default class UserPage extends Component {
state = { state = {
selector: ['简体中文', 'English'], selector: ['简体中文', 'English'],
@ -123,7 +125,7 @@ export default class UserPage extends Component {
thumb={aboutIcon} thumb={aboutIcon}
onClick={this.aboutPage} onClick={this.aboutPage}
/> />
<View style={{ height: 20 }}></View> <View style={{ height: listLangInterval }}></View>
<Picker <Picker
mode='selector' mode='selector'
range={this.state.selector} range={this.state.selector}

View File

@ -0,0 +1,32 @@
export interface ButtonText {
buttonText: {
submit: string;
reset: string;
};
submitText: {
success: string;
error: string;
};
}
export const buttonZhCn: ButtonText = {
buttonText: {
submit: '提交',
reset: '清空',
},
submitText: {
success: '提交成功',
error: '提交失败:',
},
};
export const buttonEnUs: ButtonText = {
buttonText: {
submit: 'Submit',
reset: 'Reset',
},
submitText: {
success: 'Success',
error: 'Error: ',
},
};

View File

@ -1,7 +1,4 @@
export interface InformPageText { export interface InformPageText {
submitText: {
success: string;
};
phoneText: { phoneText: {
title: string; title: string;
placeholder: string; placeholder: string;
@ -10,16 +7,9 @@ export interface InformPageText {
title: string; title: string;
placeholder: string; placeholder: string;
}; };
buttonText: {
submit: string;
reset: string;
};
} }
export const informPageZhCn: InformPageText = { export const informPageZhCn: InformPageText = {
submitText: {
success: '提交成功',
},
phoneText: { phoneText: {
title: '手机号码', title: '手机号码',
placeholder: '便于查询工单', placeholder: '便于查询工单',
@ -28,16 +18,9 @@ export const informPageZhCn: InformPageText = {
title: '真实姓名', title: '真实姓名',
placeholder: '必填,与工单绑定', placeholder: '必填,与工单绑定',
}, },
buttonText: {
submit: '提交',
reset: '清空',
},
}; };
export const informtPageEnUs: InformPageText = { export const informtPageEnUs: InformPageText = {
submitText: {
success: 'Success',
},
phoneText: { phoneText: {
title: 'Phone', title: 'Phone',
placeholder: '便于查询工单', placeholder: '便于查询工单',
@ -46,8 +29,4 @@ export const informtPageEnUs: InformPageText = {
title: 'Real Name', title: 'Real Name',
placeholder: '必填,与工单绑定', placeholder: '必填,与工单绑定',
}, },
buttonText: {
submit: 'Submit',
reset: 'Reset',
},
}; };

View File

@ -1,25 +1,13 @@
export interface ReportPageText { export interface ReportPageText {
placeHolderText: string; placeHolderText: string;
buttonText: {
submit: string;
reset: string;
};
} }
export const reportPageZhCn: ReportPageText = { export const reportPageZhCn: ReportPageText = {
placeHolderText: placeHolderText:
'无论是有关于小程序的建议还是关于E志者协会的建议都可以提出来哦', '无论是有关于小程序的建议还是关于E志者协会的建议都可以提出来哦',
buttonText: {
submit: '提交',
reset: '清空',
},
}; };
export const reportPageEnUs: ReportPageText = { export const reportPageEnUs: ReportPageText = {
placeHolderText: placeHolderText:
'无论是有关于小程序的建议还是关于E志者协会的建议都可以提出来哦', '无论是有关于小程序的建议还是关于E志者协会的建议都可以提出来哦',
buttonText: {
submit: 'Submit',
reset: 'Reset',
},
}; };

View File

@ -5,6 +5,7 @@ import { TabBarText, tabBarEnUs, tabBarZhCn } from './TabBar';
import { ReportPageText, reportPageEnUs, reportPageZhCn } from './ReportPage'; import { ReportPageText, reportPageEnUs, reportPageZhCn } from './ReportPage';
import { InformPageText, informPageZhCn, informtPageEnUs } from './InformPage'; import { InformPageText, informPageZhCn, informtPageEnUs } from './InformPage';
import { AboutPageText, aboutPageEnUs, aboutPageZhCn } from './AboutPage'; import { AboutPageText, aboutPageEnUs, aboutPageZhCn } from './AboutPage';
import { ButtonText, buttonEnUs, buttonZhCn } from './Button';
interface TextRecord { interface TextRecord {
pageFooter: PageFooterText; pageFooter: PageFooterText;
@ -14,6 +15,7 @@ interface TextRecord {
reportPage: ReportPageText; reportPage: ReportPageText;
informPage: InformPageText; informPage: InformPageText;
aboutPage: AboutPageText; aboutPage: AboutPageText;
button: ButtonText;
} }
const textZhCn: TextRecord = { const textZhCn: TextRecord = {
@ -24,6 +26,7 @@ const textZhCn: TextRecord = {
reportPage: reportPageZhCn, reportPage: reportPageZhCn,
informPage: informPageZhCn, informPage: informPageZhCn,
aboutPage: aboutPageZhCn, aboutPage: aboutPageZhCn,
button: buttonZhCn,
}; };
const textEnUs: TextRecord = { const textEnUs: TextRecord = {
@ -34,6 +37,7 @@ const textEnUs: TextRecord = {
reportPage: reportPageEnUs, reportPage: reportPageEnUs,
informPage: informtPageEnUs, informPage: informtPageEnUs,
aboutPage: aboutPageEnUs, aboutPage: aboutPageEnUs,
button: buttonEnUs,
}; };
// type Lang = 'zh_CN' | 'en_US' | ...; // type Lang = 'zh_CN' | 'en_US' | ...;