| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import { Component } from 'react'
- import Taro from '@tarojs/taro'
- import { connect } from 'react-redux'
- import {View, Button, Input} from '@tarojs/components'
- import {login} from '../../utils/servers/servers';
- import {setOpenId} from '../../utils/servers/servers';
- import { add, minus, asyncAdd } from '../../actions/counter'
- import './index.less'
- @connect(({ counter }) => ({
- counter
- }), (dispatch) => ({
- add () {
- dispatch(add())
- },
- dec () {
- dispatch(minus())
- },
- asyncAdd () {
- dispatch(asyncAdd())
- }
- }))
- class Login extends Component {
- constructor(props) {
- super(props);
- this.state={
- username:'',
- password:''
- }
- this.login = this.login.bind(this);
- }
- componentDidShow () {
- }
- componentDidMount() {
- }
- login(){
- // Taro.getSetting({
- // withSubscriptions: true,
- // success:(res)=>{
- // console.log(res.subscriptionsSetting,'res.subscriptionsSetting')
- // if(res.subscriptionsSetting.mainSwitch){
- // // res.subscriptionsSetting = {
- // // mainSwitch: true, // 订阅消息总开关
- // // itemSettings: { // 每一项开关
- // // SYS_MSG_TYPE_RANK: 'accept',
- // // 'pWia-KJPFwDM8ReDu_BOa2_42G7W2hXB16sUDbSxpcM': 'accept',
- // // 'j7WH3EwQnxGxwuV2HwmJhryxySPE8vOiV5cVOpp-42I': 'accept',
- // // 'vo28uzT2sLS-9ioroNyZbMSvu0mMvf6le2pDZVN891U': 'accept',
- // // }
- // // }
- // Taro.requestSubscribeMessage({ //获取下发权限
- // tmplIds: [
- // 'pWia-KJPFwDM8ReDu_BOa2_42G7W2hXB16sUDbSxpcM',
- // 'j7WH3EwQnxGxwuV2HwmJhryxySPE8vOiV5cVOpp-42I',
- // 'vo28uzT2sLS-9ioroNyZbMSvu0mMvf6le2pDZVN891U'
- // ], //此处写在后台获取的模板ID,可以写多个模板ID,看自己的需求
- // success: function (s) {
- // console.log(s)
- // },
- // fail: function (err) {
- // console.log(err)
- // }
- // })
- // }else if(res.subscriptionsSetting.mainSwitch.itemSettings){
- // console.log(res)
- // }else{
- // Taro.requestSubscribeMessage({
- // tmplIds: ['SLb0P5wDArFZU05iMrrnNEsXZ7H2wArqdY8__4M1NUUM'],
- // success : (res) => {
- //
- // }
- // })
- // }
- // }
- // })
- if(!this.state.username){
- Taro.showToast({
- title: '请输入用户名',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- if(!this.state.password){
- Taro.showToast({
- title: '请输入密码',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- this.setState({
- loading:true,
- })
- login({
- username:this.state.username,
- password:this.state.password
- }).then((msg)=>{
- this.setState({
- loading:false
- });
- if(!msg.data.openId){
- Taro.login({
- success: (res)=>{
- setOpenId({
- code:res.code,
- }).then(v=>{
- if(v.error.length === 0){
- Taro.switchTab({
- url: '/pages/applyDepart/index',
- })
- }else{
- Taro.showToast({title:v.error[0].message})
- }
- })
- },
- fail:()=>{
- Taro.showToast({title:'系统错误,请稍后重试'})
- }
- });
- }else{
- Taro.switchTab({
- url: '/pages/applyDepart/index',
- })
- }
- }).catch((err)=>{
- console.log(err)
- this.setState({
- loading:false
- })
- })
- }
- render () {
- return (
- <View>
- <View>
- <View>用户名</View>
- <Input
- type='text'
- placeholder='请输入用户名'
- value={this.state.username}
- onInput={(v)=>{
- this.setState({
- username: v.detail.value
- })
- }}
- />
- </View>
- <View>
- <View>密码</View>
- <Input
- type='password'
- password
- placeholder='请输入密码'
- value={this.state.password}
- onInput={(v)=>{
- this.setState({
- password: v.detail.value
- })
- }}
- />
- </View>
- <Button type='primary' loading={this.state.loading} onClick={this.login}>登录</Button>
- </View>
- )
- }
- }
- export default Login
|