From f22bb55c4ff50a8a63c795487b057c0cebdae649 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 12 十二月 2019 09:19:58 +0800 Subject: [PATCH] 2019-12-12 --- src/components/header/index.scss | 7 public/index.html | 2 src/components/sidemenu/editthdmenu/preview/index.jsx | 60 ++++++ src/views/login/loginform.jsx | 38 +++ src/templates/comtableconfig/source.jsx | 4 src/components/sidemenu/editthdmenu/index.jsx | 17 + src/templates/comtableconfig/index.jsx | 205 +++++++++++++++++---- src/templates/comtableconfig/settingform/index.jsx | 44 +++- src/views/login/index.scss | 1 public/hxlogo.png | 0 src/tabviews/commontable/index.jsx | 13 + src/components/sidemenu/editthdmenu/preview/index.scss | 30 +++ src/components/sidemenu/menuelement/index.jsx | 3 src/utils/utils.js | 94 ++++++++++ src/views/login/index.jsx | 8 15 files changed, 445 insertions(+), 81 deletions(-) diff --git a/public/hxlogo.png b/public/hxlogo.png new file mode 100644 index 0000000..980b6f9 --- /dev/null +++ b/public/hxlogo.png Binary files differ diff --git a/public/index.html b/public/index.html index 8876915..d0440ac 100644 --- a/public/index.html +++ b/public/index.html @@ -2,10 +2,10 @@ <html lang="en"> <head> <meta charset="utf-8" /> - <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="theme-color" content="#000000" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> + <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" /> <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo.png" /> <script src="%PUBLIC_URL%/options.js"></script> <title></title> diff --git a/src/components/header/index.scss b/src/components/header/index.scss index 3c4a3f1..b98fff2 100644 --- a/src/components/header/index.scss +++ b/src/components/header/index.scss @@ -12,9 +12,11 @@ .header-logo { float: left; - width: 170px; + width: 180px; line-height: 48px; text-align: center; + padding-left: 5px; + box-sizing: border-box; opacity: 1; transition: width 0.2s, opacity 0.15s; img { @@ -25,13 +27,14 @@ .header-logo.collapse { opacity: 0; width: 0px; + padding-left: 0px; } .header-collapse { float: left; width: 80px; line-height: 48px; - padding-left: 30px; + padding-left: 20px; cursor: pointer; transition: padding-left 0.15s; i { diff --git a/src/components/sidemenu/editthdmenu/index.jsx b/src/components/sidemenu/editthdmenu/index.jsx index a93e485..e889af4 100644 --- a/src/components/sidemenu/editthdmenu/index.jsx +++ b/src/components/sidemenu/editthdmenu/index.jsx @@ -5,7 +5,7 @@ import HTML5Backend from 'react-dnd-html5-backend' import { notification, Modal, Button, Spin, Icon, Col, Card, Tabs, Row, Input } from 'antd' import moment from 'moment' -import Preview from '@/components/preview' +import Preview from './preview' import TransferForm from '@/components/transferform' import Utils from '@/utils/utils.js' import DragElement from '../menuelement' @@ -53,6 +53,8 @@ menuConfig: '', tempSearchKey: '', loading: false, + preview: null, + pretemplate: null, baseTemplates: [{ title: '鍩虹琛ㄦ牸', type: 'CommonTable', @@ -300,10 +302,11 @@ }) } - previewPicture = (url) => { + previewPicture = (template) => { // 鍥剧墖棰勮 this.setState({ - preview: url + preview: template.url, + pretemplate: template }) } @@ -444,9 +447,8 @@ <Col key={template.type} span={8}> <Card title={template.title}> - <img onClick={() => {this.previewPicture(template.url)}} src={template.url} alt=""/> + <img onClick={() => {this.previewPicture(template)}} src={template.url} alt=""/> <div className="card-operation"> - {/* <Button type="primary" onClick={() => {this.previewPicture(template.url)}}>棰勮</Button> */} <Button type="primary" onClick={() => {this.useTemplate(template)}}>浣跨敤妯℃澘</Button> </div> </Card> @@ -468,9 +470,8 @@ <Col key={template.type + index} span={8}> <Card title={template.title}> - <img onClick={() => {this.previewPicture(template.url)}} src={template.url} alt=""/> + <img onClick={() => {this.previewPicture(template)}} src={template.url} alt=""/> <div className="card-operation"> - {/* <Button type="primary" onClick={() => {this.previewPicture(template.url)}}>棰勮</Button> */} <Button type="primary" onClick={() => {this.useTemplate(template)}}>浣跨敤妯℃澘</Button> </div> </Card> @@ -502,7 +503,7 @@ /> } {/* 鍥剧墖棰勮 */} - <Preview cancel={this.cancelPrePicture} preview={this.state.preview}/> + <Preview cancel={this.cancelPrePicture} preview={this.state.preview} template={this.state.pretemplate} confirm={this.useTemplate}/> {/* 瑙e喕鑿滃崟妯℃�佹 */} <Modal title={this.state.dict['header.thawmenu']} diff --git a/src/components/sidemenu/editthdmenu/preview/index.jsx b/src/components/sidemenu/editthdmenu/preview/index.jsx new file mode 100644 index 0000000..bffdb6c --- /dev/null +++ b/src/components/sidemenu/editthdmenu/preview/index.jsx @@ -0,0 +1,60 @@ +import React, {Component} from 'react' +import PropTypes from 'prop-types' +import { Button} from 'antd' +import './index.scss' + +class Preview extends Component { + static propTpyes = { + preview: PropTypes.any, + cancel: PropTypes.func, + confirm: PropTypes.func, + template: PropTypes.object + } + + state = { + show: false, + url: '' + } + + UNSAFE_componentWillReceiveProps (nextProps) { + if (nextProps.preview) { + this.setState({ + url: nextProps.preview + }) + setTimeout(() => { + this.setState({ + show: true + }) + }, 10) + } else { + this.setState({ + show: false + }) + setTimeout(() => { + this.setState({ + url: '' + }) + }, 500) + } + } + + close = () => { + this.props.cancel() + } + + render () { + return ( + <div> + {this.state.url && + <div className={'preview-box ' + (this.state.show ? 'active' : '')} onClick={this.close}> + <Button shape="circle" icon="close"></Button> + <Button type="primary" onClick={() => {this.props.confirm(this.props.template)}}>浣跨敤妯℃澘</Button> + {this.state.url && <img src={this.state.url} alt=""/>} + </div> + } + </div> + ) + } +} + +export default Preview \ No newline at end of file diff --git a/src/components/sidemenu/editthdmenu/preview/index.scss b/src/components/sidemenu/editthdmenu/preview/index.scss new file mode 100644 index 0000000..1a52608 --- /dev/null +++ b/src/components/sidemenu/editthdmenu/preview/index.scss @@ -0,0 +1,30 @@ +.preview-box { + position: fixed; + z-index: 1100; + left: 0; + right: 0px; + top: 0px; + bottom: 0px; + background: rgba($color: #000000, $alpha: 0.6); + line-height: 100vh; + text-align: center; + opacity: 0; + transition: opacity 0.5s; + cursor: zoom-out; + img { + max-width: 80vw; + max-height: 90vh; + } + button { + position: absolute; + top: 4vh; + right: 4vw; + } + button + button { + top: calc(4vh + 55px); + right: calc(4vw - 30px); + } +} +.active { + opacity: 1; +} \ No newline at end of file diff --git a/src/components/sidemenu/menuelement/index.jsx b/src/components/sidemenu/menuelement/index.jsx index 6b47ed1..03d0f62 100644 --- a/src/components/sidemenu/menuelement/index.jsx +++ b/src/components/sidemenu/menuelement/index.jsx @@ -39,7 +39,6 @@ type: 'close' }) } - const [, drop] = useDrop({ accept: ItemTypes.CARD }) return ( <div ref={drop} className="sidemenu-dragboard"> @@ -47,7 +46,7 @@ <Card key={card.id} id={`${card.id}`} - icon={card.PageParam.Icon} + icon={card.PageParam && card.PageParam.Icon} text={card.text} moveCard={moveCard} editCard={editCard} diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx index 41ca634..31a4806 100644 --- a/src/tabviews/commontable/index.jsx +++ b/src/tabviews/commontable/index.jsx @@ -127,7 +127,7 @@ columns: _columns, arr_field: _arrField.join(','), search: _search ? 'where (' + _search + ')' : '', - orderColumn: config.setting.orderColumn, + // orderColumn: config.setting.orderColumn, loading: true }, () => { this.improveSearch() @@ -255,16 +255,19 @@ async loadmaindata () { const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state + console.log(setting) // 鑾峰彇鍒楄〃鏁版嵁 let param = { - func: 'sPC_Get_TableData', + func: setting.innerFunc || 'sPC_Get_TableData', obj_name: 'data', arr_field: arr_field } - let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderColumn} ${orderType}) as rows from ${setting.dataresource} ${search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows` - let DateCount = `select count(1) as total from ${setting.dataresource} ${search}` + let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order + let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${setting.dataresource} ${search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows` + let DateCount = `select count(1) as total from ${setting.dataresource} ${search}` + console.log(LText) param.LText = Utils.formatOptions(LText) param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' param.secretkey = Utils.encrypt(param.LText, param.timestamp) @@ -359,6 +362,8 @@ UNSAFE_componentWillMount () { // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁 this.loadconfig() + + console.log(Utils.getfunc()) } shouldComponentUpdate (nextProps, nextState) { diff --git a/src/templates/comtableconfig/index.jsx b/src/templates/comtableconfig/index.jsx index 2ca9f9a..2385c9b 100644 --- a/src/templates/comtableconfig/index.jsx +++ b/src/templates/comtableconfig/index.jsx @@ -929,26 +929,15 @@ } } - if (this.state.operaType === 'add') { - _config[res.type] = _config[res.type].map(item => { - if (item.uuid === res.values.uuid) { - isupdate = true - return res.values - } else { - return item - } - }) - _config[res.type] = _config[res.type].filter(item => !item.origin) - } else { - _config[res.type] = _config[res.type].map(item => { - if (item.uuid === res.values.uuid) { - isupdate = true - return res.values - } else { - return item - } - }) - } + _config[res.type] = _config[res.type].map(item => { + if (item.uuid === res.values.uuid) { + isupdate = true + return res.values + } else { + return item + } + }) + _config[res.type] = _config[res.type].filter(item => !item.origin) if (!isupdate) { // 鎿嶄綔涓嶆槸淇敼锛屾坊鍔犲厓绱犺嚦鍒楄〃 _config[res.type].push(res.values) @@ -1005,6 +994,126 @@ } } + creatFunc = () => { + // let _config = JSON.parse(JSON.stringify(this.state.config)) + + this.formRef.handleConfirm().then(res => { + let btn = res.values + let LText = '' + if (!btn.innerFunc) { + notification.warning({ + top: 92, + message: '璇峰~鍐欏唴閮ㄥ嚱鏁帮紒', + duration: 10 + }) + return + } + + new Promise(resolve => { + // 鍐呴儴璇锋眰 + if (btn.OpenType === 'pop') { + Api.getSystemConfig({ + func: 'sPC_Get_LongParam', + MenuID: btn.uuid + }).then(res => { + let _LongParam = '' + if (res.status && res.LongParam) { + _LongParam = window.decodeURIComponent(window.atob(res.LongParam)) + try { + _LongParam = JSON.parse(_LongParam) + } catch (e) { + _LongParam = '' + } + } + + if (_LongParam) { + resolve(_LongParam) + } else { + resolve(false) + notification.warning({ + top: 92, + message: '寮圭獥锛堣〃鍗曪級鎸夐挳锛岃鍏堥厤缃〃鍗曚俊鎭紒', + duration: 10 + }) + } + }) + } else { + resolve(true) + } + }).then(res => { + if (!res) return + LText = Utils.formatOptions(Utils.getfunc()) + console.log(LText) + return Api.getSystemConfig({ + func: 'sPC_Get_TVP', + TVPName: btn.innerFunc + }) + }).then(res => { + console.log(res) + if (res.status) { + return true + } else { + notification.warning({ + top: 92, + message: res.message, + duration: 10 + }) + return false + } + }).then(res => { + console.log(res) + }) + + // let isupdate = false + // _config.action = _config.action.map(item => { + // if (item.uuid === res.values.uuid) { + // isupdate = true + // return res.values + // } else { + // return item + // } + // }) + // _config.action = _config.action.filter(item => !item.origin) + + + // if (!isupdate) { // 鎿嶄綔涓嶆槸淇敼锛屾坊鍔犲厓绱犺嚦鍒楄〃 + // _config.action.push(res.values) + // } + + // let gridbtn = _config.action.filter(act => act.position === 'grid') + // let _display = false + + // if (gridbtn.length > 0) { + // _display = true + // } + + // if (_config.gridBtn) { + // _config.gridBtn.display = _display + // } else { + // _config.gridBtn = { + // display: _display, + // Align: 'center', + // IsSort: 'false', + // uuid: Utils.getuuid(), + // label: this.state.dict['header.form.column.action'], + // type: 'action', + // style: 'button', + // show: 'horizontal', + // Width: 120 + // } + // } + + // this.setState({ + // config: _config, + // actionloading: true + // }, () => { + // this.setState({ + // actionloading: false + // }) + // }) + }) + } + deleteElement = (element) => { let _this = this confirm({ @@ -1045,30 +1154,32 @@ const { config, originMenu } = this.state this.menuformRef.handleConfirm().then(res => { config.search = config.search.filter(item => !item.origin) - if (config.search[0] && config.search[0].origin) { - notification.warning({ - top: 92, - message: '璇疯缃悳绱㈡潯浠�', - duration: 10 - }) - return - } - if (config.action[0] && config.action[0].origin) { - notification.warning({ - top: 92, - message: '璇疯缃寜閽�', - duration: 10 - }) - return - } - if (config.columns[0] && config.columns[0].origin) { - notification.warning({ - top: 92, - message: '璇疯缃樉绀哄垪', - duration: 10 - }) - return - } + config.action = config.action.filter(item => !item.origin) + config.columns = config.columns.filter(item => !item.origin) + // if (config.search[0] && config.search[0].origin) { + // notification.warning({ + // top: 92, + // message: '璇疯缃悳绱㈡潯浠�', + // duration: 10 + // }) + // return + // } + // if (config.action[0] && config.action[0].origin) { + // notification.warning({ + // top: 92, + // message: '璇疯缃寜閽�', + // duration: 10 + // }) + // return + // } + // if (config.columns[0] && config.columns[0].origin) { + // notification.warning({ + // top: 92, + // message: '璇疯缃樉绀哄垪', + // duration: 10 + // }) + // return + // } let _LongParam = '' let _config = {...config, tables: this.state.selectedTables} @@ -1833,6 +1944,12 @@ width={700} onCancel={() => { this.setState({ visible: false }) }} onOk={this.handleSubmit} + footer={[ + this.state.formtemp === 'action' ? + <Button key="delete" className="mk-btn mk-purple" onClick={this.creatFunc} loading={this.state.confirmLoading}>{this.state.dict['header.delete']}</Button> : null, + <Button key="cancel" onClick={() => { this.setState({ visible: false }) }}>{this.state.dict['header.cancel']}</Button>, + <Button key="confirm" type="primary" onClick={this.handleSubmit}>{this.state.dict['header.confirm']}</Button> + ]} destroyOnClose > {this.state.formtemp === 'search' ? diff --git a/src/templates/comtableconfig/settingform/index.jsx b/src/templates/comtableconfig/settingform/index.jsx index 3e7c4b2..98a1943 100644 --- a/src/templates/comtableconfig/settingform/index.jsx +++ b/src/templates/comtableconfig/settingform/index.jsx @@ -1,6 +1,6 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { Form, Row, Col, Input, Radio, Select } from 'antd' +import { Form, Row, Col, Input, Radio, Select, Tooltip, Icon } from 'antd' import './index.scss' const { TextArea } = Input @@ -10,6 +10,10 @@ dict: PropTypes.object, // 瀛楀吀椤� data: PropTypes.object, columns: PropTypes.array + } + + state = { + interType: this.props.data.interType || 'inner' } handleConfirm = () => { @@ -23,6 +27,10 @@ } }) }) + } + + onChange = (e) => { + console.log(e.target.value) } render() { @@ -79,16 +87,34 @@ )} </Form.Item> </Col> + <Col span={12}> + <Form.Item label="鎺ュ彛绫诲瀷"> + {getFieldDecorator('interType', { + initialValue: data.interType || 'inner' + })( + <Radio.Group onChange={this.onChange}> + <Radio value="inner">鍐呴儴</Radio> + <Radio value="outer">澶栭儴</Radio> + </Radio.Group> + )} + </Form.Item> + </Col> + <Col span={12}> + <Form.Item label="鍐呴儴鍑芥暟"> + {getFieldDecorator('innerFunc', { + initialValue: data.innerFunc || '' + })(<Input placeholder="" autoComplete="off" />)} + </Form.Item> + </Col> <Col span={24}> - <Form.Item label="鏁版嵁婧�" className="textarea"> + <Form.Item label={ + <Tooltip placement="topLeft" title=""> + <Icon type="question-circle" /> + {'鏁版嵁婧�'} + </Tooltip> + } className="textarea"> {getFieldDecorator('dataresource', { - initialValue: data.dataresource, - rules: [ - { - required: true, - message: dict['form.required.input'] + '鏁版嵁婧�!' - } - ] + initialValue: data.dataresource })(<TextArea rows={4} />)} </Form.Item> </Col> diff --git a/src/templates/comtableconfig/source.jsx b/src/templates/comtableconfig/source.jsx index 5f8ab0b..1915ca5 100644 --- a/src/templates/comtableconfig/source.jsx +++ b/src/templates/comtableconfig/source.jsx @@ -15,7 +15,9 @@ tableType: 'checkbox', primaryKey: '', order: '', - dataresource: '' + dataresource: '', + interType: 'inner', + innerFunc: '' }, tables: [], search: [ diff --git a/src/utils/utils.js b/src/utils/utils.js index b0119dd..dd60cbb 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -296,4 +296,98 @@ let realurl = url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url return realurl } + + /** + * @description 鍒犻櫎瀛樺偍杩囩▼sql + * @return {String} name 瀛樺偍杩囩▼鍚嶇О + */ + static dropfunc (name) { + return `IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('${name}') AND type in (N'P', N'PC')) DROP PROCEDURE ${name}` + } + + /** + * @description 鍒涘缓瀛樺偍杩囩▼ + * @return {String} + */ + static getfunc (param) { + param = { + name: 'ls' + } + let Ltext = `create proc ${param.name} + ( + @BID nvarchar(50)='', + @ID nvarchar(50)='', + 琛ㄥ崟浼犲��,鏂囨湰鐢╪varchar(50)='',鏃ユ湡鐢╠atetime is null ,鏁板�肩敤decimal(18,灏忔暟鐐逛綅鏁�)=0, + @sEPTMenuNo='', --浼犺彍鍗曞弬鏁� + @lang nvarchar(50)='', + @debug nvarchar(50)='', + @LoginUID nvarchar(50)='', + @SessionUid nvarchar(50)='', + @UserID nvarchar(50), + @ErrorCode nvarchar(50) out, + @retmsg nvarchar(4000) out + ) + as + begin + declare @BegindateTest datetime,@EnddateTest datetime + select @BegindateTest=getdate() + set @ErrorCode='' + set @retmsg='' + BEGIN TRY + /*浜嬪姟鎿嶄綔*/ + BEGIN TRAN + /*鍏蜂綋涓氬姟鎿嶄綔*/ + + /* + select top 10 * from sProcExcep order by id desc + + declare @UserName nvarchar(50),@FullName nvarchar(50) + + select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID + + insert into 琛ㄥ悕 (琛ㄥ崟瀛楁) select 瀵瑰簲鍏ュ弬锛屽垱寤轰汉 + + update 琛ㄥ悕 set 琛ㄥ崟瀛楁=瀵瑰簲鍏ュ弬,modifydate=getdate(),modifyuserid=@UserID + + if 1=2 + begin + set @ErrorCode='E' + set @retmsg='鍦ㄦ鍐欐姤閿�' + goto GOTO_RETURN + end + + insert into sNote (remark,createuserid,CreateUser,CreateStaff) + select '鍦ㄦ鍐欐棩蹇�',@UserID,@UserName,@FullName + */ + + COMMIT TRAN + SET NOCOUNT ON + RETURN + END TRY + BEGIN CATCH + /*閿欒澶勭悊*/ + ROLLBACK TRAN + DECLARE @ErrorMessage NVARCHAR(4000); + DECLARE @ErrorSeverity INT; + DECLARE @ErrorState INT; + + /*鎶婅嚜瀹氫箟鐨勫弸濂界殑閿欒淇℃伅鎻愮ず鍔犱笂*/ + set @ErrorCode=cast(ERROR_NUMBER() as nvarchar(50)) + SET @retmsg=ERROR_MESSAGE(); + SELECT @ErrorMessage=ERROR_MESSAGE(), + @ErrorSeverity=ERROR_SEVERITY(), + @ErrorState=ERROR_STATE(); + + RAISERROR(@ErrorMessage, /*-- Message text.*/ + @ErrorSeverity, /*-- Severity.*/ + @ErrorState /*-- State.*/ + ); + END CATCH + + GOTO_RETURN: + ROLLBACK TRAN + + END` + return Ltext.replace(/\n\s{4}/ig, '\'char(13)\'') + } } \ No newline at end of file diff --git a/src/views/login/index.jsx b/src/views/login/index.jsx index de9d5da..90fe6b8 100644 --- a/src/views/login/index.jsx +++ b/src/views/login/index.jsx @@ -66,12 +66,12 @@ sessionStorage.setItem('LoginUID', res.LoginUID) localStorage.setItem('lang', param.lang) + let _url = window.location.href.split('#')[0] + if (param.remember) { // 璁颁綇瀵嗙爜鏃惰处鍙峰瘑鐮佸瓨鍏ocalStorage - localStorage.setItem('username', param.username) - localStorage.setItem('password', param.password) + localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify({username: param.username, password: param.password})))) } else { - localStorage.removeItem('username') - localStorage.removeItem('password') + localStorage.removeItem(_url) } if (this.props.location.state && this.props.location.state.from.pathname) { diff --git a/src/views/login/index.scss b/src/views/login/index.scss index 20f480a..3f195b6 100644 --- a/src/views/login/index.scss +++ b/src/views/login/index.scss @@ -7,6 +7,7 @@ .logo { height: 100px; padding-top: 30px; + line-height: 80px; border-bottom: 2px solid #06b4f7; img { max-height: 100%; diff --git a/src/views/login/loginform.jsx b/src/views/login/loginform.jsx index 968b863..617b1c2 100644 --- a/src/views/login/loginform.jsx +++ b/src/views/login/loginform.jsx @@ -16,7 +16,10 @@ platName: PropTypes.string } - state = {} + state = { + username: '', + password: '' + } handleConfirm = () => { // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭� @@ -52,9 +55,32 @@ } componentDidMount () { - const input = document.getElementById('username') - if (input) { - input.focus() + let _url = window.location.href.split('#')[0] + let _user = localStorage.getItem(_url) + + if (_user) { + try { + _user = JSON.parse(window.decodeURIComponent(window.atob(_user))) + } catch { + _user = '' + } + } + + if (_user) { + this.setState({ + username: _user.username, + password: _user.password + }, () => { + const input = document.getElementById('username') + if (input) { + input.focus() + } + }) + } else { + const input = document.getElementById('username') + if (input) { + input.focus() + } } } @@ -67,7 +93,7 @@ <Form.Item> {getFieldDecorator('username', { rules: [{ required: true, message: this.props.dict['login.username.empty'] }], - initialValue: localStorage.getItem('username') || '', + initialValue: this.state.username || '', })( <Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} @@ -77,7 +103,7 @@ </Form.Item> <Form.Item> {getFieldDecorator('password', { - initialValue: localStorage.getItem('password') || '', + initialValue: this.state.password || '', rules: [ { required: true, -- Gitblit v1.8.0