From 8ed1e158001e1a3f6f988c2037f7ef6f82df343d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 07 六月 2023 21:02:25 +0800
Subject: [PATCH] 2023-06-07

---
 src/views/login/loginform.jsx |  223 +++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 174 insertions(+), 49 deletions(-)

diff --git a/src/views/login/loginform.jsx b/src/views/login/loginform.jsx
index cb74ecf..eda2530 100644
--- a/src/views/login/loginform.jsx
+++ b/src/views/login/loginform.jsx
@@ -1,25 +1,29 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { is, fromJS } from 'immutable'
-import { Form, Icon, Input, Button, Modal, message } from 'antd'
-import { UserOutlined } from '@ant-design/icons'
+import { Form, Input, Button, Checkbox, Select, Modal, message } from 'antd'
+import { UserOutlined, LockOutlined, QrcodeOutlined, RedoOutlined } from '@ant-design/icons'
 import md5 from 'md5'
 import moment from 'moment'
 
 import Api from '@/api'
+import Utils from '@/utils/utils.js'
 import options from '@/store/options.js'
+import asyncLoadComponent from '@/utils/asyncLoadComponent'
 import './index.scss'
 
 const { warning } = Modal
 let LoginVerCodeTimer = null
+const QrCode = asyncLoadComponent(() => import('@/components/qrcode'))
 
 class LoginTabForm extends Component {
   static propTpyes = {
     isDisabled: PropTypes.bool,
     changelang: PropTypes.func,
     handleSubmit: PropTypes.func,
+    authLogin: PropTypes.func,
     dict: PropTypes.object,
     auth: PropTypes.bool,
+    authError: PropTypes.string,
     touristLogin: PropTypes.bool,
     lang: PropTypes.string,
     langList: PropTypes.array,
@@ -29,14 +33,20 @@
 
   state = {
     activeKey: 'uname_pwd',
+    scanId: '',
     username: '',
     password: '',
     remember: true,
     delay: null,
     loginWays: [],
     smsId: '',
-    verdisabled: false
+    verdisabled: false,
+    hasScan: false,
+    timeout: false
   }
+
+  timer = null
+  splitTime = 0
 
   UNSAFE_componentWillMount () {
     const { loginWays } = this.props
@@ -51,43 +61,76 @@
     }
 
     let smsId = ''
+    let hasScan = false
     let _loginWays = []
     loginWays.forEach(item => {
       if (item.type === 'sms_vcode') {
+        item.label = '鐭俊鐧诲綍'
         smsId = item.smsId
         _loginWays.push(item)
       } else if (item.type === 'uname_pwd') {
+        item.label = '璐﹀彿鐧诲綍'
         _loginWays.push(item)
+      } else if (item.type === 'app_scan') {
+        _loginWays.push(item)
+        hasScan = true
       }
     })
+
+    let activeKey = _loginWays[0].type
 
     this.setState({
       smsId: smsId,
       loginWays: _loginWays,
-      activeKey: _loginWays[0].type,
-      remember
+      activeKey,
+      scanId: activeKey === 'app_scan' ? Utils.getuuid() : '',
+      timeout: false,
+      remember,
+      hasScan
     })
+
+    if (activeKey === 'app_scan') {
+      this.splitTime = 0
+      this.timer = setTimeout(() => {
+        this.checkResult()
+      }, 10000)
+    }
   }
 
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    if (!is(fromJS(this.props.loginWays), fromJS(nextProps.loginWays))) {
-      let smsId = ''
-      let _loginWays = []
-      nextProps.loginWays.forEach(item => {
-        if (item.type === 'sms_vcode') {
-          smsId = item.smsId
-          _loginWays.push(item)
-        } else if (item.type === 'uname_pwd') {
-          _loginWays.push(item)
-        }
-      })
+  checkResult = () => {
+    const { scanId } = this.state
 
-      this.setState({
-        smsId: smsId,
-        loginWays: _loginWays,
-        activeKey: _loginWays[0].type
-      })
+    this.splitTime += 10000
+
+    let _param = {
+      func: 'webapi_get_binding_key',
+      scan_type: 'pc',
+      id: scanId,
+      UserName: ''
     }
+
+    _param.userid = sessionStorage.getItem('visitorUserID')
+    _param.LoginUID = sessionStorage.getItem('visitorLoginUID')
+
+    if (this.splitTime >= 180000) {
+      this.setState({
+        timeout: true
+      })
+      return
+    }
+
+    Api.getSystemConfig(_param).then(res => {
+      if (!res.status) {
+        message.warning(res.message)
+        return
+      } else if (res.thd_party_appid && res.thd_party_member_id && res.thd_party_openid) {
+        this.props.authLogin(res.thd_party_appid, res.thd_party_openid, res.thd_party_member_id, scanId)
+      } else {
+        this.timer = setTimeout(() => {
+          this.checkResult()
+        }, 10000)
+      }
+    })
   }
 
   handleConfirm = () => {
@@ -121,9 +164,9 @@
     e.preventDefault()
     if (!this.props.auth) {
       warning({
-        title: this.props.dict['login.auth.tip'],
-        okText: this.props.dict['login.auth.ok'],
-        cancelText: this.props.dict['login.auth.cancel'],
+        title: this.props.authError || this.props.dict['login.auth.tip'],
+        okText: this.props.dict['login.ok'],
+        cancelText: this.props.dict['login.cancel'],
         onOk() {},
         onCancel() {}
       })
@@ -168,7 +211,7 @@
     if (_user) {
       try {
         _user = JSON.parse(window.decodeURIComponent(window.atob(_user)))
-      } catch {
+      } catch (e) {
         console.warn('Parse Failure')
         _user = ''
       }
@@ -193,7 +236,29 @@
   }
 
   onChangeTab = (activeKey) => {
-    this.setState({activeKey})
+    this.setState({activeKey, scanId: activeKey === 'app_scan' ? Utils.getuuid() : ''})
+
+    if (this.state.activeKey === 'app_scan') {
+      this.timer && clearTimeout(this.timer)
+    }
+
+    if (activeKey === 'app_scan') {
+      this.splitTime = 0
+      this.setState({timeout: false})
+      this.timer = setTimeout(() => {
+        this.checkResult()
+      }, 10000)
+    }
+  }
+
+  reCode = () => {
+    this.splitTime = 0
+
+    this.setState({timeout: false, scanId: Utils.getuuid()})
+
+    this.timer = setTimeout(() => {
+      this.checkResult()
+    }, 10000)
   }
 
   getvercode = () => {
@@ -303,17 +368,20 @@
     this.setState = () => {
       return
     }
+    this.timer && clearTimeout(this.timer)
   }
 
   render() {
     const { getFieldDecorator } = this.props.form
-    const { activeKey, verdisabled, delay, loginWays } = this.state
+    const { activeKey, verdisabled, delay, loginWays, remember, scanId, timeout, hasScan } = this.state
+    const wayLabels = {app_scan: '鎵爜鐧诲綍', uname_pwd: '璐﹀彿鐧诲綍', sms_vcode: '鐭俊鐧诲綍'}
 
     return (
-      <Form className={`login-form login-form-${loginWays.length}`} id="login-form" onSubmit={this.handleSubmit}>
-        <p className="title">{this.props.platName}</p>
-        <div className="form-item-wrap">
-          {activeKey === 'uname_pwd' ? <Form.Item>
+      <Form className="login-form" id="login-form" onSubmit={this.handleSubmit}>
+        <div className="login-way-title">{wayLabels[activeKey]}</div>
+        {hasScan && activeKey !== 'app_scan' ? <div className="scan-icon" onClick={() => this.onChangeTab('app_scan')}><QrcodeOutlined /></div> : null}
+        {activeKey === 'uname_pwd' ? <div className="form-item-wrap">
+          <Form.Item>
             {getFieldDecorator('username', {
               rules: [{ required: true, message: this.props.dict['login.username.empty'] }],
               initialValue: this.state.username || '',
@@ -324,8 +392,8 @@
                 autoComplete="off"
               />,
             )}
-          </Form.Item> : null}
-          {activeKey === 'uname_pwd' ? <Form.Item>
+          </Form.Item>
+          <Form.Item>
             {getFieldDecorator('password', {
               initialValue: this.state.password || '',
               rules: [
@@ -334,9 +402,40 @@
                   message: this.props.dict['login.password.empty'],
                 }
               ]
-            })(<Input.Password placeholder={this.props.dict['login.password']} prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} />)}
+            })(<Input.Password placeholder={this.props.dict['login.password']} prefix={<LockOutlined style={{ color: 'rgba(0,0,0,.25)' }} />} />)}
+          </Form.Item>
+          {window.GLOB.keepKey ? <Form.Item className="minline">
+            {getFieldDecorator('remember', {
+              valuePropName: 'checked',
+              initialValue: remember,
+            })(<Checkbox onChange={this.rememberChange}>{this.props.dict['login.remember']}</Checkbox>)}
+          </Form.Item> : <div style={{height: '30px', float: 'left'}}></div>}
+          {this.props.langList && this.props.langList.length > 0 ? <Form.Item className="minline right">
+            {getFieldDecorator('lang', {
+              initialValue: this.props.lang,
+            })(
+              <Select
+                onChange={(value) => {this.changelang(value)}}
+                getPopupContainer={() => document.getElementById('login-form')}
+              >
+                {this.props.langList.map((item, index) => {
+                  return <Select.Option key={index} value={item.Lang}>{item.LangName}</Select.Option>
+                })}
+              </Select>
+            )}
           </Form.Item> : null}
-          {activeKey === 'sms_vcode' ? <Form.Item>
+          <Form.Item className="btn-login">
+            <Button type="primary" htmlType="submit" className="login-form-button" disabled={this.props.isDisabled} loading={this.props.isDisabled}>
+              {this.props.dict['login.submit']}
+            </Button>
+          </Form.Item>
+          {options.sysType === 'cloud' && options.cdomain.indexOf('mk9h') > -1 ? <Form.Item className="register-line">
+            <a href="http://www.minkesoft.com/signup" target="_blank" rel="noopener noreferrer" className="register">娉ㄥ唽</a>
+            <a href="http://www.minkesoft.com/forgotPwd" target="_blank" rel="noopener noreferrer" className="forgot">蹇樿瀵嗙爜锛�</a>
+          </Form.Item> : null}
+        </div> : null}
+        {activeKey === 'sms_vcode' ? <div className="form-item-wrap">
+          <Form.Item>
             {getFieldDecorator('phone', {
               rules: [{ required: true, message: this.props.dict['login.phone.empty'] }],
               initialValue: '',
@@ -346,8 +445,8 @@
                 autoComplete="off"
               />
             )}
-          </Form.Item> : null}
-          {activeKey === 'sms_vcode' ? <Form.Item className="vercode">
+          </Form.Item>
+          <Form.Item className="vercode">
             {getFieldDecorator('vercode', {
               initialValue: '',
               rules: [
@@ -367,22 +466,48 @@
                 autoComplete="off"
               />
             )}
+          </Form.Item>
+          {this.props.langList && this.props.langList.length > 0 ? <Form.Item className="minline right">
+            {getFieldDecorator('lang', {
+              initialValue: this.props.lang,
+            })(
+              <Select
+                onChange={(value) => {this.changelang(value)}}
+                getPopupContainer={() => document.getElementById('login-form')}
+              >
+                {this.props.langList.map((item, index) => {
+                  return <Select.Option key={index} value={item.Lang}>{item.LangName}</Select.Option>
+                })}
+              </Select>
+            )}
           </Form.Item> : null}
-          {/* {activeKey === 'uname_pwd' ? <Form.Item className="minline">
-            {getFieldDecorator('remember', {
-              valuePropName: 'checked',
-              initialValue: remember,
-            })(<Checkbox onChange={this.rememberChange}>{this.props.dict['login.remember']}</Checkbox>)}
-          </Form.Item> : null} */}
-          {['uname_pwd', 'sms_vcode'].includes(activeKey) ? <Form.Item className="btn-login">
+          <Form.Item className="btn-login">
             <Button type="primary" htmlType="submit" className="login-form-button" disabled={this.props.isDisabled} loading={this.props.isDisabled}>
               {this.props.dict['login.submit']}
             </Button>
-          </Form.Item> : null}
+          </Form.Item>
           {options.sysType === 'cloud' && options.cdomain.indexOf('mk9h') > -1 ? <Form.Item className="register-line">
-            <a href="http://minkesoft.com/#/signup" target="_blank" rel="noopener noreferrer" className="register">娉ㄥ唽</a>
-            <a href="http://minkesoft.com/#/forgotPwd" target="_blank" rel="noopener noreferrer" className="forgot">蹇樿瀵嗙爜锛�</a>
+            <a href="http://www.minkesoft.com/signup" target="_blank" rel="noopener noreferrer" className="register">娉ㄥ唽</a>
+            <a href="http://www.minkesoft.com/forgotPwd" target="_blank" rel="noopener noreferrer" className="forgot">蹇樿瀵嗙爜锛�</a>
           </Form.Item> : null}
+        </div> : null}
+        {activeKey === 'app_scan' ? <div className="form-item-wrap">
+          <div className="form-scan-wrap">
+            <div className="qr-wrap">
+              {scanId ? <QrCode card={{qrWidth: 500, color: '#000000'}} value={`mkpcscan,${window.GLOB.appkey},${scanId}`}/> : null}
+              {timeout ? <div className="qrcode-out">
+                <RedoOutlined onClick={this.reCode} />
+                浜岀淮鐮佸凡澶辨晥銆�
+              </div> : null}
+            </div>
+            璇蜂娇鐢ㄥ鎴风鎵竴鎵櫥褰�
+          </div>
+        </div> : null}
+        <div className={'login-ways ' + (activeKey === 'app_scan' ? 'center' : '')}>
+          {loginWays.map(item => {
+            if (item.type === 'app_scan' || activeKey === item.type) return null
+            return (<span key={item.type} onClick={() => this.onChangeTab(item.type)}>{item.label}</span>)
+          })}
         </div>
       </Form>
     )

--
Gitblit v1.8.0