index.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { Component } from 'react'
  2. import Taro from '@tarojs/taro'
  3. import { connect } from 'react-redux'
  4. import {View, Map, Button, Input} from '@tarojs/components'
  5. import {login} from '../../utils/servers/servers';
  6. import { add, minus, asyncAdd } from '../../actions/counter'
  7. import './index.less'
  8. @connect(({ counter }) => ({
  9. counter
  10. }), (dispatch) => ({
  11. add () {
  12. dispatch(add())
  13. },
  14. dec () {
  15. dispatch(minus())
  16. },
  17. asyncAdd () {
  18. dispatch(asyncAdd())
  19. }
  20. }))
  21. class Login extends Component {
  22. constructor(props) {
  23. super(props);
  24. this.state={
  25. username:'',
  26. password:''
  27. }
  28. this.login = this.login.bind(this);
  29. }
  30. componentDidShow () {
  31. }
  32. componentDidMount() {
  33. }
  34. login(){
  35. if(!this.state.username){
  36. Taro.showToast({
  37. title: '请输入用户名',
  38. icon: 'none',
  39. duration: 2000
  40. })
  41. return;
  42. }
  43. if(!this.state.password){
  44. Taro.showToast({
  45. title: '请输入密码',
  46. icon: 'none',
  47. duration: 2000
  48. })
  49. return;
  50. }
  51. this.setState({
  52. loading:true,
  53. })
  54. login({
  55. username:this.state.username,
  56. password:this.state.password
  57. }).then(()=>{
  58. this.setState({
  59. loading:false
  60. });
  61. Taro.switchTab({
  62. url: '/pages/applyDepart/index',
  63. })
  64. }).catch(()=>{
  65. this.setState({
  66. loading:false
  67. })
  68. })
  69. }
  70. render () {
  71. return (
  72. <View>
  73. <View>
  74. <View>用户名</View>
  75. <Input
  76. type='text'
  77. placeholder='请输入用户名'
  78. value={this.state.username}
  79. onInput={(v)=>{
  80. this.setState({
  81. username: v.detail.value
  82. })
  83. }}
  84. />
  85. </View>
  86. <View>
  87. <View>密码</View>
  88. <Input
  89. type='password'
  90. password
  91. placeholder='请输入密码'
  92. value={this.state.password}
  93. onInput={(v)=>{
  94. this.setState({
  95. password: v.detail.value
  96. })
  97. }}
  98. />
  99. </View>
  100. <Button type='primary' loading={this.state.loading} onClick={this.login}>登录</Button>
  101. </View>
  102. )
  103. }
  104. }
  105. export default Login