From b883ae5d7d46fc7a3503236f16a250c2264ea7c7 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 29 九月 2022 17:45:25 +0800 Subject: [PATCH] 2022-09-29 --- src/menu/sysinterface/index.jsx | 132 ++++++++++++++++++++++++------------------- 1 files changed, 74 insertions(+), 58 deletions(-) diff --git a/src/menu/sysinterface/index.jsx b/src/menu/sysinterface/index.jsx index e221366..797dc2c 100644 --- a/src/menu/sysinterface/index.jsx +++ b/src/menu/sysinterface/index.jsx @@ -1,14 +1,14 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Modal, Button, Popconfirm, message } from 'antd' -import { StopTwoTone, ApiOutlined, CopyOutlined, EditOutlined, CheckCircleTwoTone, DeleteOutlined } from '@ant-design/icons' +import { Modal, Button, Popconfirm, message, notification } from 'antd' +import { StopTwoTone, DatabaseOutlined, CopyOutlined, CheckCircleTwoTone, DeleteOutlined, PlusOutlined, SwapOutlined } from '@ant-design/icons' import Utils from '@/utils/utils.js' import asyncComponent from '@/utils/asyncComponent' import './index.scss' -const SettingForm = asyncComponent(() => import('./settingform')) +const DataSource = asyncComponent(() => import('@/menu/datasource')) const EditTable = asyncComponent(() => import('@/templates/zshare/editTable')) class InterfaceController extends Component { @@ -19,12 +19,10 @@ state = { visible: false, - setvisible: false, interfaces: [], - card: null, columns: [ { - title: '鎺ュ彛鍚嶇О', + title: '鍚嶇О', dataIndex: 'name', width: '50%' }, @@ -53,8 +51,9 @@ dataIndex: 'operation', render: (text, record) => (<div style={{textAlign: 'center'}}> - <span onClick={() => this.handleEdit(record)} style={{color: '#1890ff', cursor: 'pointer', fontSize: '16px', marginRight: '15px'}}><EditOutlined /></span> - <span onClick={() => {this.copy(record)}} style={{color: '#26C281', cursor: 'pointer', fontSize: '16px', marginRight: '15px'}}><CopyOutlined /></span> + <DataSource config={record} updateConfig={this.update}/> + <span onClick={() => this.handleStatus(record)} style={{color: '#8E44AD', cursor: 'pointer', fontSize: '16px', marginRight: '15px'}}><SwapOutlined /></span> + <span onClick={() => this.copy(record)} style={{color: '#26C281', cursor: 'pointer', fontSize: '16px', marginRight: '15px'}}><CopyOutlined /></span> <Popconfirm overlayClassName="popover-confirm" title="纭畾鍒犻櫎锛�" @@ -107,8 +106,46 @@ }) } - handleEdit = (record) => { - this.setState({card: record, setvisible: true}) + handleStatus = (record) => { + const { config } = this.props + + if (record.status === 'false') { + if (record.setting.interType === 'system' && record.setting.execute !== 'false' && !record.setting.dataresource) { + notification.warning({ + top: 92, + message: '鏈缃暟鎹簮锛屼笉鍙惎鐢紒', + duration: 5 + }) + return + } else if (!record.setting.primaryKey) { + notification.warning({ + top: 92, + message: '鏈缃富閿紝涓嶅彲鍚敤锛�', + duration: 5 + }) + return + } else if (record.columns.length === 0) { + notification.warning({ + top: 92, + message: '鏈坊鍔犲瓧娈甸泦锛屼笉鍙惎鐢紒', + duration: 5 + }) + return + } + } + + record = fromJS(record).toJS() + record.status = record.status === 'false' ? 'true' : 'false' + + let interfaces = this.state.interfaces.map(item => { + if (item.uuid !== record.uuid) { + return item + } + return record + }) + + this.setState({ interfaces }) + this.props.updateConfig({...config, interfaces}) } deleteScript = (record) => { @@ -126,37 +163,25 @@ this.props.updateConfig({...config, interfaces}) } - settingSave = () => { + update = (record) => { const { config } = this.props - const { card } = this.state - let interfaces = fromJS(this.state.interfaces).toJS() - this.settingRef.handleConfirm().then(res => { - interfaces = interfaces.map(item => { - if (item.uuid === card.uuid) { - res.uuid = item.uuid + if (record.setting.primaryKey && record.columns.length > 0) { + record.status = 'true' + } else if (record.columns.length === 0) { + record.status = 'false' + } + record.name = record.setting.name - if (res.procMode !== 'inner' && res.preScripts && res.preScripts.filter(item => item.status !== 'false').length === 0) { - message.warning('鏈缃墠缃剼鏈紝涓嶅彲鍚敤锛�') - res.status = 'false' - } else if (res.callbackType === 'script' && res.cbScripts && res.cbScripts.filter(item => item.status !== 'false').length === 0) { - message.warning('鏈缃洖璋冭剼鏈紝涓嶅彲鍚敤锛�') - res.status = 'false' - } - - return res - } + let interfaces = this.state.interfaces.map(item => { + if (item.uuid !== record.uuid) { return item - }) - - this.setState({ - card: null, - setvisible: false, - interfaces - }) - - this.props.updateConfig({...config, interfaces}) + } + return record }) + + this.setState({ interfaces }) + this.props.updateConfig({...config, interfaces}) } addInterface = () => { @@ -165,11 +190,14 @@ interfaces.push({ uuid: Utils.getuuid(), - name: 'interface ' + (interfaces.length + 1), - procMode: 'script', - callbackType: 'script', - preScripts: [], - cbScripts: [] + name: '鏁版嵁婧�' + (interfaces.length + 1), + status: 'false', + format: 'array', + type: 'interface', + pageable: false, + setting: { interType: 'system', name: '鏁版嵁婧�' + (interfaces.length + 1), status: 'false' }, + columns: [], + scripts: [], }) this.setState({ @@ -179,13 +207,13 @@ } render() { - const { visible, setvisible, columns, interfaces, card } = this.state + const { visible, columns, interfaces } = this.state return ( <div className="mk-sys-interface" style={{display: 'inline-block'}}> - <Button className="mk-border-green" onClick={this.trigger}><ApiOutlined /> 鎺ュ彛绠$悊</Button> + <Button className="mk-border-green" onClick={this.trigger}><DatabaseOutlined /> 鍏叡鏁版嵁婧�</Button> <Modal - title="鎺ュ彛绠$悊" + title="鍏叡鏁版嵁婧�" wrapClassName="interface-controller-modal" visible={visible} width={800} @@ -198,21 +226,9 @@ ]} destroyOnClose > - <Button key="add-interface" className="mk-border-green" onClick={this.addInterface}> 娣诲姞 </Button> + <PlusOutlined key="add-interface" onClick={this.addInterface}/> {/* <div style={{fontSize: '12px', position: 'relative', top: '20px'}}>娉細鎺ュ彛鎵ц瀹屾垚鍚庯紝浼氳Е鍙戦粯璁や笉鍔犺浇鐨勭粍浠跺埛鏂版暟鎹��</div> */} - <EditTable key="manage-interface" actions={['move', 'copy']} type="interface" data={interfaces} columns={columns} onChange={this.changeScripts}/> - </Modal> - <Modal - title={card ? card.name : '鎺ュ彛'} - wrapClassName="interface-edit-modal" - visible={setvisible} - width={900} - maskClosable={false} - onOk={this.settingSave} - onCancel={() => { this.setState({ setvisible: false })}} - destroyOnClose - > - <SettingForm config={card} wrappedComponentRef={(inst) => this.settingRef = inst}/> + <EditTable key="manage-interface" actions={['copy']} type="interface" data={interfaces} columns={columns} onChange={this.changeScripts}/> </Modal> </div> ) -- Gitblit v1.8.0