index.js 9.11 KB
Newer Older
程恺文's avatar
程恺文 committed
1 2 3 4 5 6
/* eslint-disable */
/*
 * @Author: chengkaiwen;
 * @Date: 2022-7-8
 * @Description: 广州登录页;
 */
程恺文's avatar
程恺文 committed
7
import { appService } from '@/api';
程恺文's avatar
程恺文 committed
8 9 10 11 12 13 14 15 16 17 18
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { withRouter } from '@wisdom-utils/runtime';
import { Modal } from 'antd';
import { HelmetProvider, Helmet } from 'react-helmet-async';
import FormLogin from './FormLogin';
import { actionCreators } from '@/containers/App/store';
import LoginAction from '../../login';
import styles from './index.less';
import { defaultApp } from '@/micro';
import { log } from 'kit_utils';
喻天's avatar
喻天 committed
19 20 21
let big = '广州大.png'
let bigNew = ''
let hasOnline = true
22
let slogan = ''
程恺文's avatar
程恺文 committed
23 24 25
class HuaNongLogin extends Component {
  constructor(props) {
    super(props);
26
    console.log(props);
程恺文's avatar
程恺文 committed
27 28 29 30
    this.state = {
      time: '16:00',
      week: '星期一',
      date: '2020-04-14',
程恺文's avatar
程恺文 committed
31
      title: '节水主题2',
程恺文's avatar
程恺文 committed
32 33 34 35 36 37 38 39 40
      type: 'Account',
      status: 'normal',
      submitting: false,
      autoLogin: false,
      visible: false,
      action: new LoginAction(Object.assign({}, props, { history: props.history }), this.setVisible, true),
    };
    this.fromRef = React.createRef();
    this.sliVerify = React.createRef();
喻天's avatar
喻天 committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    props.loginParams.map(v => {
      let item = v.split('=')
      if (item.length > 0) {
        if (item[0] == 'big') {
          big = item[1]
        }
        if (item[0] == 'bigNew') {
          bigNew = item[1]
        }
        if (item[0] == 'slogan') {
          slogan = item[1]
        }
        if (item[0] == 'hasOnline') {
          hasOnline = item[1] == "true"
        }
56
      }
喻天's avatar
喻天 committed
57
    })
程恺文's avatar
程恺文 committed
58 59 60 61 62 63 64
  }
  handleSubmit = values => {
    const { action, type, autoLogin } = this.state;
    action &&
      (type === 'Account'
        ? action.loginHandler(values.userName, values.password, null, autoLogin, this.sliVerify)
        : type === 'Mobile'
喻天's avatar
喻天 committed
65 66
          ? action.phoneLoginFormHandler(values.mobile, values.captcha)
          : null);
程恺文's avatar
程恺文 committed
67 68 69

    this.setSubmitting(true);
    this.props.updateCurrentIndex(-1);
程恺文's avatar
程恺文 committed
70
    //没取到0id 要给定时器
喻天's avatar
喻天 committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    if (window.gzTime) {
      clearInterval(window.gzTime)
    }
    if (hasOnline) {

      setTimeout(() => {
        appService
          .getInOnLine({
            UserID: globalConfig.userInfo.oid || globalConfig.userInfo.OID,
            SatrtDate: this.getNowDate(),
            Port: location.port,
            Oid: this._createGuid(),
          })
      }, 10000)
      window.gzTime = setInterval(() => {
        appService
          .getInOnLine({
            UserID: globalConfig.userInfo.oid || globalConfig.userInfo.OID,
            SatrtDate: this.getNowDate(),
            Port: location.port,
            Oid: this._createGuid(),
          })
      }, 180000)
94
    }
喻天's avatar
喻天 committed
95

程恺文's avatar
程恺文 committed
96

程恺文's avatar
程恺文 committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
  };
  onActinoChange = action => {
    action &&
      action.events.on('loginSuccess', event => {
        this.setSubmitting(false);
        this.props.updateCurrentIndex && this.props.updateCurrentIndex(0);
        this.props.history.push(`/?client=${this.props.global.client}`);
        defaultApp();
      });
    action &&
      action.events.on('loginError', event => {
        this.setVisible(false);
        this.setSubmitting(false);
      });
    action &&
      action.events.on('loginVisible', status => {
        this.setVisible(status);
      });
  };
  setSubmitting = submitting => {
    this.setState({ submitting });
  };
  setVisible = visible => {
    this.setState({
      visible,
    });
  };
  setType = type => {
    this.setState({
      type,
    });
  };
  setAutoLogin = autoLogin => {
    this.setState({
      autoLogin,
    });
  };
  renderPlatform() {
    const params = {
      fromRef: this.formRef,
      type: this.state.type,
      setType: this.setType,
      status: this.state.status,
      submitting: this.state.submitting,
      autoLogin: this.state.autoLogin,
      setAutoLogin: this.setAutoLogin,
      action: this.state.action,
      onSubmit: this.handleSubmit,
      loginMode: this.props.loginMode,
      updateLoginMode: this.props.updateLoginMode,
    };
    return <FormLogin {...params} />;
  }
  getCurrentTime(callback) {
    const date = new Date();
    const week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    let minutes = date.getMinutes();
    if (minutes < 10) {
      minutes = '0' + minutes;
    }
    let second = date.getSeconds();
    const time = `${date.getHours()}:${minutes}`;
    const weekDay = week[date.getDay()];
    const dateStr = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
    const dateObj = {
      time,
      week: weekDay,
      date: dateStr,
      second,
    };
    callback && callback(dateObj);
  }
  showTime = (date) => {
    this.clearTime();
    this.setState({
      ...date,
    });
    const interval = 60 - date.second;
    this.timeTimer = setInterval(() => {
      this.getCurrentTime(this.showTime);
    }, interval * 1000);
  }
  // 清除时间定时器
  clearTime() {
    this.timeTimer && clearInterval(this.timeTimer);
  }
喻天's avatar
喻天 committed
183
  getNowDate() {
程恺文's avatar
程恺文 committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    var date = new Date();
    var sign2 = ":";
    var year = date.getFullYear() // 年
    var month = date.getMonth() + 1; // 月
    var day = date.getDate(); // 日
    var hour = date.getHours(); // 时
    var minutes = date.getMinutes(); // 分
    var seconds = date.getSeconds() //秒
    var weekArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天'];
    var week = weekArr[date.getDay()];
    // 给一位数的数据前面加 “0”
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (day >= 0 && day <= 9) {
      day = "0" + day;
    }
    if (hour >= 0 && hour <= 9) {
      hour = "0" + hour;
    }
    if (minutes >= 0 && minutes <= 9) {
      minutes = "0" + minutes;
    }
    if (seconds >= 0 && seconds <= 9) {
      seconds = "0" + seconds;
    }
    return year + "-" + month + "-" + day + " " + hour + sign2 + minutes + sign2 + seconds;
  }
喻天's avatar
喻天 committed
212
  _createGuid() {
程恺文's avatar
程恺文 committed
213 214 215 216 217 218 219 220
    return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
      .replace(/[xy]/g, function (c) {
        let r = (Math.random() * 16) | 0,
          v = c == "x" ? r : (r & 0x3) | 0x8;
        return v.toString(16);
      })
      .toUpperCase();
  }
程恺文's avatar
程恺文 committed
221
  componentDidMount() {
喻天's avatar
喻天 committed
222 223
    console.log(this.props, this.props.global.logo, this.props.global.transformDevAssetsBaseURL('assets/images/广州/背景.png'));
    console.log(this);
程恺文's avatar
程恺文 committed
224 225
    this.onActinoChange(this.state.action);
    this.getCurrentTime(this.showTime);
喻天's avatar
喻天 committed
226 227 228 229 230 231 232 233 234 235
    /* request(urlUtils.getUrl(
       "/PandaEnergy/GZshuiwuju"
     ) + '/GuangZhou/InOnLine', {
       query: {
           UserID: _config.userInfo.OID,
           SatrtDate: SatrtDate,
           Port: location.port,
           Oid,
       }
   })  */
程恺文's avatar
程恺文 committed
236 237 238



程恺文's avatar
程恺文 committed
239 240 241 242 243
  }
  componentWillUnmount() {
    this.clearTime();
  }
  render() {
244

程恺文's avatar
程恺文 committed
245 246
    return (
      <HelmetProvider>
喻天's avatar
喻天 committed
247
        <div className={styles.quota} style={{ 'background': `url(${bigNew ? this.props.global.transformDevAssetsBaseURL(bigNew) : require("@/assets/images/login/节水/" + big)}) no-repeat` }}>
程恺文's avatar
程恺文 committed
248
          <div className={styles.head}>
喻天's avatar
喻天 committed
249 250 251 252 253
            <div className={styles.title}>
              <img className={styles.imgs} src={this.props.global && this.props.global.transformDevAssetsBaseURL && this.props.global.transformDevAssetsBaseURL(this.props.global.logo)} alt="" />
              {/* <img src={require('@/assets/images/login/能源-定额/华农logo.png')} alt="" /> */}
              <span>{this.props.global.title || this.state.title}</span>
            </div>
程恺文's avatar
程恺文 committed
254 255 256 257 258 259 260 261 262 263 264
            <div className={styles.time_and_date}>
              <div className={styles.time}>{this.state.time}</div>
              <div className={styles.date}>
                <span>{this.state.week}</span>
                <span>{this.state.date}</span>
              </div>
            </div>
          </div>
          <div className={styles.wrap_content}>
            <div className={styles.from}>
              <div className={styles.slogan}>
265
                <div className={styles.slogan_back} style={{ background: `url( ${!slogan ? require("@/assets/images/login/节水/建桥宣传语.png") : this.props.global.transformDevAssetsBaseURL(slogan)}) center no-repeat` }} />
程恺文's avatar
程恺文 committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
              </div>
              <div className={styles.login}>{this.renderPlatform()}</div>
            </div>
          </div>
          <Modal
            centered
            visible={this.state.visible}
            width={340}
            footer={null}
            closable={false}
            bodyStyle={{ padding: '15px' }}
          >
            <div ref={this.sliVerify} />
          </Modal>
        </div>
      </HelmetProvider>
    );
  }
}

const mapStateToProps = state => ({
  global: state.getIn(['global', 'globalConfig']),
  loginMode: state.getIn(['global', 'loginMode']),
});

const mapDispatchToProps = dispatch => ({
  updateConfig(config) {
    dispatch(actionCreators.getConfig(config));
  },
  createContext(data) {
    dispatch(actionCreators.createContext(data));
  },
  updateLoginMode(mode) {
    dispatch(actionCreators.changeLoginMode(mode));
  },
  updateCurrentIndex(index) {
    dispatch(actionCreators.updateCurrentIndex(index));
  },
});
export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(withRouter(HuaNongLogin));