From 5df578ff69f6b02e821d59a8883bc75d78695a62 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 10 十一月 2020 11:07:31 +0800 Subject: [PATCH] 2020-11-10 --- src/templates/sharecomponent/settingcalcomponent/verifycard/index.jsx | 339 +++++++++++++++----------------------------------------- 1 files changed, 90 insertions(+), 249 deletions(-) diff --git a/src/templates/sharecomponent/settingcalcomponent/verifycard/index.jsx b/src/templates/sharecomponent/settingcalcomponent/verifycard/index.jsx index 69fb0fd..2cc9b20 100644 --- a/src/templates/sharecomponent/settingcalcomponent/verifycard/index.jsx +++ b/src/templates/sharecomponent/settingcalcomponent/verifycard/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { fromJS } from 'immutable' -import { Form, Tabs, Table, Popconfirm, Icon, notification, Modal, Typography, Spin } from 'antd' +import { Form, Tabs, Table, Popconfirm, Icon, notification, Modal, Spin } from 'antd' import moment from 'moment' import Api from '@/api' @@ -9,13 +9,12 @@ import asyncComponent from '@/utils/asyncComponent' import ColForm from './columnform' -import CustomScriptsForm from './customscript' +import CustomScript from '@/templates/zshare/customscript' import SettingForm from './settingform' import SettingUtils from './utils' import './index.scss' const { TabPane } = Tabs -const { Paragraph } = Typography const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent')) @@ -33,13 +32,8 @@ columns: [], activeKey: 'setting', loading: false, - initsql: '', // sql楠岃瘉鏃跺彉閲忓0鏄庡強璧嬪�� usefulfields: '', defaultsql: '', // 榛樿Sql - systemScripts: [{ - name: '榛樿sql', - value: '' - }], colColumns: [ { title: '鍚嶇О', @@ -63,59 +57,11 @@ dataIndex: 'operation', render: (text, record) => (<div> - <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record, 'columns')} style={{color: '#1890ff'}}><Icon type="edit" /></span> + <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record)} style={{color: '#1890ff'}}><Icon type="edit" /></span> <Popconfirm overlayClassName="popover-confirm" title={this.props.dict['model.query.delete']} onConfirm={() => this.deleteColumn(record) - }> - <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span> - </Popconfirm> - </div>) - } - ], - scriptsColumns: [ - { - title: 'SQL', - dataIndex: 'sql', - width: '60%', - render: (text) => ( - <Paragraph copyable ellipsis={{ rows: 5, expandable: true }}>{text}</Paragraph> - ) - }, - { - title: '鐘舵��', - dataIndex: 'status', - width: '20%', - render: (text, record) => record.status === 'false' ? - ( - <div> - {this.props.dict['model.status.forbidden']} - <Icon style={{marginLeft: '5px'}} type="stop" theme="twoTone" twoToneColor="#ff4d4f" /> - </div> - ) : - ( - <div> - {this.props.dict['model.status.open']} - <Icon style={{marginLeft: '5px'}} type="check-circle" theme="twoTone" twoToneColor="#52c41a" /> - </div> - ) - }, - { - title: '鎿嶄綔', - align: 'center', - width: '20%', - dataIndex: 'operation', - render: (text, record) => - (<div> - <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record, 'scripts')} style={{color: '#1890ff'}}><Icon type="edit" /></span> - <span className="operation-btn" onClick={() => this.handleUpDown(record, 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span> - <span className="operation-btn" onClick={() => this.handleUpDown(record, 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span> - <span className="operation-btn" title={this.props.dict['model.status.change']} onClick={() => this.handleStatus(record)} style={{color: '#8E44AD'}}><Icon type="swap" /></span> - <Popconfirm - overlayClassName="popover-confirm" - title={this.props.dict['model.query.delete']} - onConfirm={() => this.deleteScript(record) }> <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span> </Popconfirm> @@ -127,59 +73,10 @@ UNSAFE_componentWillMount() { const { config } = this.props - let _setting = fromJS(config.setting).toJS() - if (_setting.interType === 'inner' && !_setting.innerFunc) { - _setting.interType = 'system' - } - this.setState({ - setting: _setting, + setting: fromJS(config.setting).toJS(), columns: fromJS(config.columns).toJS(), scripts: fromJS(config.scripts).toJS() - }) - - this.getsysScript() - } - - getsysScript = () => { - let _scriptSql = `Select distinct func+Remark as funcname,longparam, s.Sort from聽 s_custom_script s inner join (select OpenID from sapp where ID=@Appkey@) p on s.openid = case when s.appkey='' then s.openid else p.OpenID end order by s.Sort` - - _scriptSql = Utils.formatOptions(_scriptSql) - - let _sParam = { - func: 'sPC_Get_SelectedList', - LText: _scriptSql, - obj_name: 'data', - arr_field: 'funcname,longparam' - } - - _sParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' - _sParam.secretkey = Utils.encrypt(_sParam.LText, _sParam.timestamp) - _sParam.open_key = Utils.encryptOpenKey(_sParam.secretkey, _sParam.timestamp) // 浜戠鏁版嵁楠岃瘉 - - Api.getSystemConfig(_sParam).then(res => { - if (res.status) { - let _scripts = [] - - res.data.forEach(item => { - let _item = { - name: item.funcname, - value: Utils.UnformatOptions(item.longparam) - } - - _scripts.push(_item) - }) - - this.setState({ - systemScripts: [...this.state.systemScripts, ..._scripts] - }) - } else { - notification.warning({ - top: 92, - message: res.message, - duration: 5 - }) - } }) } @@ -206,18 +103,10 @@ this.setState({ columns: this.state.columns.filter(item => item.uuid !== record.uuid) }) } - deleteScript = (record) => { - this.setState({ scripts: this.state.scripts.filter(item => item.uuid !== record.uuid) }) - } + handleEdit = (record) => { + this.contrastForm.edit(record) - handleEdit = (record, type) => { - if (type === 'scripts') { - this.scriptsForm.edit(record) - } else if (type === 'columns') { - this.contrastForm.edit(record) - } - - let node = document.getElementById('model-verify-card-box-tab').parentNode + let node = document.getElementById('model-setting-form-body').parentNode if (node && node.scrollTop) { let inter = Math.ceil(node.scrollTop / 10) @@ -233,118 +122,57 @@ } } - handleStatus = (record) => { - let scripts = fromJS(this.state.scripts).toJS() - record.status = record.status === 'false' ? 'true' : 'false' - - scripts = scripts.map(item => { - if (item.uuid === record.uuid) { - return record - } else { - return item - } - }) - - this.setState({ scripts }) - } - - handleUpDown = (record, direction) => { - let scripts = fromJS(this.state.scripts).toJS() - let index = 0 - - scripts = scripts.filter((item, i) => { - if (item.uuid === record.uuid) { - index = i - } - - return item.uuid !== record.uuid - }) - if ((index === 0 && direction === 'up') || (index === scripts.length && direction === 'down')) { - return - } - - if (direction === 'up') { - scripts.splice(index - 1, 0, record) - } else { - scripts.splice(index + 1, 0, record) - } - - this.setState({ scripts }) - } - - scriptsChange = (values) => { - let scripts = fromJS(this.state.scripts).toJS() - - if (values.uuid) { - scripts = scripts.map(item => { - if (item.uuid === values.uuid) { - return values - } else { - return item - } - }) - } else { - scripts.push(values) - } - - return new Promise((resolve, reject) => { - this.sqlverify(resolve, reject, false, scripts) - }) - } - - scriptSubmit = (values) => { - let scripts = fromJS(this.state.scripts).toJS() - - if (values.uuid) { - scripts = scripts.map(item => { - if (item.uuid === values.uuid) { - return values - } else { - return item - } - }) - } else { - values.uuid = Utils.getuuid() - scripts.push(values) - } - - this.setState({ scripts }) - } - changeTab = (val) => { - const { activeKey } = this.state + const { activeKey, setting } = this.state - this.setState({loading: true}) if (activeKey === 'setting') { this.settingForm.handleConfirm().then(res => { + if (res.interType !== 'system' && val === 'scripts') { + notification.warning({ + top: 92, + message: '浣跨敤绯荤粺鎺ュ彛鏃讹紝鎵嶅彲浠ヨ缃嚜瀹氫箟鑴氭湰锛�', + duration: 5 + }) + return + } + this.setState({ setting: res }, () => { - this.sqlverify(() => { // 楠岃瘉鎴愬姛 + if (res.interType === 'system') { // 绯荤粺鎺ュ彛锛宻ql楠岃瘉 + this.setState({loading: true}) + + this.sqlverify(() => { // 楠岃瘉鎴愬姛 + this.setState({ + activeKey: val, + loading: false + }) + }, () => { // 楠岃瘉澶辫触 + this.setState({ + activeKey: val, + loading: false + }) + }, activeKey) + } else { this.setState({ - activeKey: val, - loading: false + activeKey: val }) - }, () => { // 楠岃瘉澶辫触 - this.setState({ - loading: false - }) - }, true) + } }) - }, () => { - this.setState({loading: false}) }) } else if (activeKey === 'columns') { - this.sqlverify(() => { // 楠岃瘉鎴愬姛 - this.setState({ - activeKey: val, - loading: false + if (setting.interType !== 'system' && val === 'scripts') { + notification.warning({ + top: 92, + message: '浣跨敤绯荤粺鎺ュ彛鏃讹紝鎵嶅彲浠ヨ缃嚜瀹氫箟鑴氭湰锛�', + duration: 5 }) - }, () => { // 楠岃瘉澶辫触 - this.setState({ - loading: false - }) - }, true) + return + } + + this.setState({ + activeKey: val + }) } else if (activeKey === 'scripts') { let _loading = false if (this.scriptsForm && this.scriptsForm.state.editItem) { @@ -359,12 +187,10 @@ message: '瀛樺湪鏈繚瀛樿剼鏈紝璇风偣鍑荤‘瀹氫繚瀛橈紝鎴栫偣鍑诲彇娑堟斁寮冧慨鏀癸紒', duration: 5 }) - this.setState({ - loading: false - }) return } + this.setState({loading: true}) this.sqlverify(() => { // 楠岃瘉鎴愬姛 this.setState({ activeKey: val, @@ -372,9 +198,10 @@ }) }, () => { // 楠岃瘉澶辫触 this.setState({ + activeKey: val, loading: false }) - }, true) + }, activeKey) } } @@ -387,13 +214,13 @@ this.setState({ setting: res }, () => { - this.sqlverify(() => { resolve({setting: res, columns, scripts }) }, reject, false) + this.sqlverify(() => { resolve({setting: res, columns, scripts }) }, reject, 'submit') }) }, () => { reject() }) } else if (activeKey === 'columns') { - this.sqlverify(() => { resolve({setting, columns, scripts }) }, reject, false) + this.sqlverify(() => { resolve({setting, columns, scripts }) }, reject, 'submit') } else if (activeKey === 'scripts') { let _loading = false if (this.scriptsForm && this.scriptsForm.state.editItem) { @@ -412,14 +239,20 @@ return } - this.sqlverify(() => { resolve({setting, columns, scripts }) }, reject, false) + this.sqlverify(() => { resolve({setting, columns, scripts }) }, reject, 'submit') } }) } - sqlverify = (resolve, reject, change = false, testScripts) => { + sqlverify = (resolve, reject, type, testScripts) => { const { searches } = this.props - const { columns, setting, scripts, activeKey } = this.state + const { columns, setting, scripts } = this.state + + if (setting.interType !== 'system') { // 涓嶄娇鐢ㄧ郴缁熸帴鍙f椂锛屼笉闇�瑕乻ql楠岃瘉 + resolve() + return + } + let _scripts = [] if (testScripts) { @@ -428,7 +261,7 @@ _scripts = scripts.filter(item => item.status !== 'false') } - if (!change && setting.interType === 'system' && !setting.innerFunc && setting.execute === 'false' && _scripts.length === 0) { + if (type === 'submit' && setting.execute === 'false' && _scripts.length === 0) { notification.warning({ top: 92, message: '涓嶆墽琛岄粯璁ql鏃讹紝璇锋坊鍔犺嚜瀹氫箟鑴氭湰锛�', @@ -439,17 +272,17 @@ } // 涓嶄娇鐢ㄩ粯璁ql鍒囨崲 - if (change && activeKey === 'setting' && setting.interType === 'system' && setting.execute === 'false') { + if (type === 'setting' && setting.execute === 'false') { resolve() - } else if (change && activeKey === 'scripts' && _scripts.length === 0) { + } else if (type === 'scripts' && _scripts.length === 0) { resolve() - } else if ((setting.interType === 'system' && setting.execute !== 'false') || _scripts.length > 0) { + } else if (setting.execute !== 'false' || _scripts.length > 0) { let param = { func: 's_debug_sql', LText: SettingUtils.getDebugSql(setting, _scripts, columns, searches) } param.LText = Utils.formatOptions(param.LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) Api.getLocalConfig(param).then(result => { @@ -473,6 +306,18 @@ }) } + // 鑷畾涔夎剼鏈慨鏀� + scriptsChange = (scripts) => { + return new Promise((resolve, reject) => { + this.sqlverify(resolve, reject, 'verify', scripts) + }) + } + + // 鑷畾涔夎剼鏈洿鏂� + scriptsUpdate = (scripts) => { + this.setState({scripts}) + } + /** * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 */ @@ -483,10 +328,10 @@ } render() { - const { columns, setting, scripts, colColumns, scriptsColumns, activeKey, loading } = this.state + const { columns, setting, scripts, colColumns, activeKey, loading } = this.state return ( - <div id="model-verify-card-box-tab"> + <div className="model-verify-card-box-tab" id="model-setting-form-body"> {loading && <Spin size="large" />} <Tabs activeKey={activeKey} className="verify-card-box" onChange={this.changeTab}> <TabPane tab="鏁版嵁婧�" key="setting"> @@ -521,25 +366,21 @@ pagination={false} /> </TabPane> - <TabPane tab="鑷畾涔夎剼鏈�" key="scripts"> - <CustomScriptsForm - setting={setting} - searches={this.props.searches} - initsql={this.state.initsql} + <TabPane tab={ + <span> + 鑷畾涔夎剼鏈� + {scripts.length ? <span className="count-tip">{scripts.length}</span> : null} + </span> + } key="scripts"> + <CustomScript dict={this.props.dict} - customScripts={scripts} - systemScripts={this.state.systemScripts} + setting={setting} + scripts={scripts} + defaultSql={this.state.defaultsql} + searches={this.props.searches} scriptsChange={this.scriptsChange} - scriptSubmit={this.scriptSubmit} + scriptsUpdate={this.scriptsUpdate} wrappedComponentRef={(inst) => this.scriptsForm = inst} - /> - <Table - bordered - rowKey="uuid" - className="custom-table" - dataSource={scripts} - columns={scriptsColumns} - pagination={false} /> </TabPane> </Tabs> -- Gitblit v1.8.0