| | |
| | | import PropTypes from 'prop-types' |
| | | import { fromJS } from 'immutable' |
| | | import { Form, Tabs, Popconfirm, notification, Modal, Typography, Spin, message, Button } from 'antd' |
| | | import { StopOutlined, CheckCircleOutlined, EditOutlined, SwapOutlined, DeleteOutlined, CopyOutlined, BorderOutlined } from '@ant-design/icons' |
| | | import { StopOutlined, CheckCircleOutlined, EditOutlined, SwapOutlined, DeleteOutlined, CopyOutlined, BorderOutlined, SnippetsOutlined } from '@ant-design/icons' |
| | | import moment from 'moment' |
| | | |
| | | import Api from '@/api' |
| | |
| | | import ColForm from './columnform' |
| | | import CustomScriptsForm from './customscript' |
| | | import SettingForm from './settingform' |
| | | import PasteForm from '@/templates/zshare/pasteform' |
| | | import SettingUtils from './utils' |
| | | import MinView from '@/assets/img/minview.png' |
| | | import './index.scss' |
| | |
| | | defaultSearch: '', |
| | | systemScripts: [], |
| | | visible: false, |
| | | pvisible: false, |
| | | reload: false, |
| | | script: null, |
| | | scriptValue: '', |
| | | colColumns: [ |
| | |
| | | }) |
| | | } |
| | | |
| | | copyDatasource = () => { |
| | | const { config } = this.props |
| | | const { columns, scripts } = this.state |
| | | |
| | | if (columns.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请添加字段集!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | this.settingForm.handleConfirm().then(res => { |
| | | delete res.supModule |
| | | res.name = config.name |
| | | |
| | | let source = { |
| | | key: 'interface', |
| | | type: 'line', |
| | | data: {setting: res, columns, scripts, pageable: false, format: 'array', name: res.name, status: 'false', type: 'interface', uuid: '' } |
| | | } |
| | | |
| | | try { |
| | | source = window.btoa(window.encodeURIComponent(JSON.stringify(source))) |
| | | } catch (e) { |
| | | console.warn('Stringify Failure') |
| | | source = '' |
| | | } |
| | | |
| | | if (source) { |
| | | let oInput = document.createElement('input') |
| | | oInput.value = source |
| | | document.body.appendChild(oInput) |
| | | oInput.select() |
| | | document.execCommand('Copy') |
| | | document.body.removeChild(oInput) |
| | | message.success('复制成功。') |
| | | } |
| | | }) |
| | | } |
| | | |
| | | pasteSubmit = () => { |
| | | const { setting } = this.state |
| | | |
| | | this.pasteFormRef.handleConfirm().then(res => { |
| | | if (res.key !== 'interface') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '配置类型错误!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (res.type !== 'line') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请粘贴单项数据源!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | if (setting.supModule) { |
| | | res.data.setting.supModule = setting.supModule |
| | | } |
| | | |
| | | this.setState({ |
| | | scripts: res.data.scripts.map(col => { |
| | | col.uuid = Utils.getuuid() |
| | | return col |
| | | }), |
| | | columns: res.data.columns.map(col => { |
| | | col.uuid = Utils.getuuid() |
| | | return col |
| | | }), |
| | | setting: res.data.setting, |
| | | reload: true, |
| | | pvisible: false |
| | | }, () => { |
| | | this.setState({reload: false}) |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | copyColumns = () => { |
| | | const { columns } = this.state |
| | | let m = [] |
| | |
| | | |
| | | render() { |
| | | const { config } = this.props |
| | | const { columns, setting, scripts, colColumns, scriptsColumns, activeKey, loading, searches, defaultsql, visible, script, scriptValue } = this.state |
| | | const { columns, setting, scripts, colColumns, scriptsColumns, activeKey, loading, searches, defaultsql, visible, pvisible, reload, script, scriptValue } = this.state |
| | | |
| | | return ( |
| | | <div className="model-data-source-wrap"> |
| | | {config.name ? <div className="mk-com-name">{config.name} - 数据源</div> : null} |
| | | {loading && <Spin size="large" />} |
| | | <Tabs activeKey={activeKey} className="data-source-card-box" onChange={this.changeTab}> |
| | | <TabPane tab="数据源" key="setting"> |
| | | <SettingForm |
| | | <TabPane tab={ |
| | | <span> |
| | | 数据源 |
| | | {config.type !== 'interface' ? <CopyOutlined title="复制数据源" className="mk-copy-datasource" onClick={this.copyDatasource}/> : null} |
| | | {config.type !== 'interface' ? <SnippetsOutlined title="导入数据源" className="mk-paste-datasource" onClick={() => this.setState({pvisible: true})}/> : null} |
| | | </span> |
| | | } key="setting"> |
| | | {!reload ? <SettingForm |
| | | dict={this.props.dict} |
| | | config={config} |
| | | columns={columns} |
| | | setting={setting} |
| | | scripts={scripts} |
| | | wrappedComponentRef={(inst) => this.settingForm = inst} |
| | | /> |
| | | /> : null} |
| | | </TabPane> |
| | | <TabPane tab={ |
| | | <span> |
| | | 字段集 |
| | | {columns.length ? <span className="count-tip">{columns.length}</span> : null} |
| | | <CopyOutlined title="以逗号拼接形式复制字段" className="mk-copy-fields" onClick={this.copyColumns}/> |
| | | </span> |
| | | } key="columns"> |
| | |
| | | </div> |
| | | <CodeMirror value={scriptValue} onChange={(val) => {this.setState({scriptValue: val})}}></CodeMirror> |
| | | </Modal> |
| | | <Modal |
| | | title="粘贴" |
| | | visible={pvisible} |
| | | width={600} |
| | | maskClosable={false} |
| | | onOk={this.pasteSubmit} |
| | | onCancel={() => {this.setState({pvisible: false})}} |
| | | destroyOnClose |
| | | > |
| | | <PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst} inputSubmit={this.pasteSubmit}/> |
| | | </Modal> |
| | | </div> |
| | | ) |
| | | } |
| | |
| | | right: -210px; |
| | | color: rgb(24, 144, 255); |
| | | display: none; |
| | | opacity: 0.4; |
| | | transition: opacity 0.2s; |
| | | } |
| | | .ant-tabs-tab-active .mk-copy-fields { |
| | | .mk-copy-datasource { |
| | | position: absolute; |
| | | cursor: pointer; |
| | | z-index: 1; |
| | | top: 19px; |
| | | right: -319px; |
| | | color: rgb(24, 144, 255); |
| | | display: none; |
| | | opacity: 0.4; |
| | | transition: opacity 0.2s; |
| | | } |
| | | .mk-paste-datasource { |
| | | position: absolute; |
| | | cursor: pointer; |
| | | z-index: 1; |
| | | top: 19px; |
| | | right: -355px; |
| | | color:purple; |
| | | display: none; |
| | | opacity: 0.4; |
| | | transition: opacity 0.2s; |
| | | } |
| | | .mk-copy-fields:hover, .mk-copy-datasource:hover, .mk-paste-datasource:hover { |
| | | opacity: 1; |
| | | } |
| | | .ant-tabs-tab-active { |
| | | .mk-copy-fields, .mk-copy-datasource, .mk-paste-datasource { |
| | | display: inline-block; |
| | | } |
| | | } |
| | | .count-tip { |
| | | position: absolute; |
| | | top: 0px; |
| | |
| | | return record |
| | | }) |
| | | |
| | | |
| | | this.setState({ interfaces }) |
| | | this.props.updateConfig({...config, interfaces}) |
| | | |
| | |
| | | destroyOnClose |
| | | > |
| | | <PlusOutlined key="add-interface" onClick={this.addInterface}/> |
| | | {/* <div style={{fontSize: '12px', position: 'relative', top: '20px'}}>注:接口执行完成后,会触发默认不加载的组件刷新数据。</div> */} |
| | | <EditTable key="manage-interface" actions={['copy']} type="interface" data={interfaces} columns={columns} onChange={this.changeScripts}/> |
| | | </Modal> |
| | | </div> |
| | |
| | | } |
| | | |
| | | if (_config.components) { |
| | | config.components = MenuUtils.resetConfig(_config.components, {}, res.clearMenu === 'true') |
| | | let uuids = {} // 重置公共数据源 |
| | | if (_config.interfaces && _config.interfaces.length > 0) { |
| | | config.interfaces = _config.interfaces.map(inter => { |
| | | uuids[inter.uuid] = this.getuuid() |
| | | inter.uuid = uuids[inter.uuid] |
| | | return inter |
| | | }) |
| | | } |
| | | config.components = MenuUtils.resetConfig(_config.components, uuids, res.clearMenu === 'true') |
| | | config.tables = _config.tables || [] |
| | | config.style = _config.style || {} |
| | | config.statusBarbgColor = _config.statusBarbgColor || '' |
| | |
| | | import PasteForm from '@/templates/zshare/pasteform' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import CusSwitch from './cusSwitch' |
| | | import zhCN from '@/locales/zh-CN/model.js' |
| | | import enUS from '@/locales/en-US/model.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import './index.scss' |
| | | |
| | | const MkEditIcon = asyncComponent(() => import('@/components/mkIcon')) |
| | | let eTDict = sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS |
| | | const EditableContext = React.createContext() |
| | | const { confirm } = Modal |
| | | let dragingIndex = -1 |
| | |
| | | rules: [ |
| | | { |
| | | required: required, |
| | | message: ['number', 'text', 'input'].includes(inputType) ? `${eTDict['form.required.input']} ${title}!` : `${eTDict['form.required.select']} ${title}!`, |
| | | message: ['number', 'text', 'input'].includes(inputType) ? `请输入${title}!` : `请选择${title}!`, |
| | | }, |
| | | ...rules |
| | | ], |
| | |
| | | |
| | | operation = { |
| | | title: (<div> |
| | | {eTDict['model.operation']} |
| | | 操作 |
| | | <span className="copy-control"> |
| | | {actions.includes('copy') ? <CopyOutlined title="复制" onClick={() => this.copy()} /> : null} |
| | | {actions.includes('copy') ? <SnippetsOutlined title="粘贴" onClick={this.paste} /> : null} |
| | |
| | | <EditableContext.Consumer> |
| | | {form => ( |
| | | <span onClick={() => this.save(form, record.uuid)} style={{ marginRight: 8 , color: '#1890ff', cursor: 'pointer'}}> |
| | | {eTDict['model.save']} |
| | | 保存 |
| | | </span> |
| | | )} |
| | | </EditableContext.Consumer> |
| | | <span style={{ color: '#1890ff', cursor: 'pointer'}} onClick={() => this.cancel(record.uuid)}>{eTDict['model.cancel']}</span> |
| | | <span style={{ color: '#1890ff', cursor: 'pointer'}} onClick={() => this.cancel(record.uuid)}>取消</span> |
| | | </div> |
| | | ) : ( |
| | | <div className={'edit-operation-btn' + (editingKey !== '' ? ' disabled' : '')} style={{minWidth: '110px', whiteSpace: 'nowrap'}}> |
| | |
| | | {actions.includes('status') ? <span className="status" onClick={() => {editingKey === '' && this.handleStatus(record)}}><SwapOutlined /></span> : null} |
| | | {actions.includes('del') && editingKey === '' ? <Popconfirm |
| | | overlayClassName="popover-confirm" |
| | | title={eTDict['model.query.delete']} |
| | | title="确定删除吗?" |
| | | onConfirm={() => this.handleDelete(record.uuid) |
| | | }> |
| | | <span className="danger"><DeleteOutlined /></span> |
| | |
| | | uuid: Utils.getuuid() |
| | | }) |
| | | } |
| | | |
| | | }) |
| | | } else if (res.key !== type) { |
| | | message.warning('配置信息格式错误!') |
| | |
| | | </DndProvider> |
| | | {/* 信息粘贴 */} |
| | | <Modal |
| | | title={eTDict['header.form.paste']} |
| | | title="粘贴" |
| | | visible={this.state.visible} |
| | | width={600} |
| | | maskClosable={false} |
| | |
| | | onCancel={() => {this.setState({visible: false})}} |
| | | destroyOnClose |
| | | > |
| | | <PasteForm dict={eTDict} wrappedComponentRef={(inst) => this.pasteFormRef = inst} inputSubmit={this.pasteSubmit}/> |
| | | <PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst} inputSubmit={this.pasteSubmit}/> |
| | | </Modal> |
| | | </div> |
| | | </EditableContext.Provider> |
| | |
| | | return cell |
| | | }) |
| | | } else if (['card', 'carousel', 'timeline'].includes(item.type) || (item.type === 'table' && item.subtype === 'tablecard')) { |
| | | if (item.wrap.datatype === 'public' && uuids[item.wrap.publicId]) { |
| | | item.wrap.publicId = uuids[item.wrap.publicId] |
| | | } |
| | | |
| | | item.subcards.forEach(card => { |
| | | card.uuid = this.getuuid() |
| | | |
| | |
| | | } |
| | | }) |
| | | } else if (item.type === 'balcony') { |
| | | if (item.wrap.datatype === 'public' && uuids[item.wrap.publicId]) { |
| | | item.wrap.publicId = uuids[item.wrap.publicId] |
| | | } |
| | | if (item.elements) { |
| | | item.elements = item.elements.map(cell => { |
| | | cell.uuid = this.getuuid() |
| | |
| | | config.MenuName = param.MenuName |
| | | config.MenuNo = param.MenuNo |
| | | config.easyCode = '' |
| | | config.components = MenuUtils.resetConfig(config.components) |
| | | |
| | | let uuids = {} // 重置公共数据源 |
| | | if (config.interfaces && config.interfaces.length > 0) { |
| | | config.interfaces = config.interfaces.map(inter => { |
| | | uuids[inter.uuid] = this.getuuid() |
| | | inter.uuid = uuids[inter.uuid] |
| | | return inter |
| | | }) |
| | | } |
| | | |
| | | config.components = MenuUtils.resetConfig(config.components, uuids) |
| | | config.enabled = false |
| | | |
| | | param.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(config))) |
| | |
| | | MKEmitter.addListener('resetSelectLine', this.resetParentParam) |
| | | |
| | | Object.defineProperty(window, 'debug', { |
| | | configurable: true, |
| | | enumerable: true, |
| | | set(value) { |
| | | if (value + '' === 'false') { |
| | | window.debugger = false |
| | |
| | | } |
| | | } |
| | | } else { |
| | | config.components = MenuUtils.resetConfig(config.components, {}, urlParam.clearMenu) |
| | | let uuids = {} // 重置公共数据源 |
| | | if (config.interfaces && config.interfaces.length > 0) { |
| | | config.interfaces = config.interfaces.map(inter => { |
| | | uuids[inter.uuid] = this.getuuid() |
| | | inter.uuid = uuids[inter.uuid] |
| | | return inter |
| | | }) |
| | | } |
| | | |
| | | config.components = MenuUtils.resetConfig(config.components, uuids, urlParam.clearMenu) |
| | | config.enabled = false |
| | | message.success('复制成功,保存后生效。') |
| | | } |
| | |
| | | } |
| | | } |
| | | } else { |
| | | config.components = MenuUtils.resetConfig(config.components, {}, urlParam.clearMenu) |
| | | let uuids = {} // 重置公共数据源 |
| | | if (config.interfaces && config.interfaces.length > 0) { |
| | | config.interfaces = config.interfaces.map(inter => { |
| | | uuids[inter.uuid] = this.getuuid() |
| | | inter.uuid = uuids[inter.uuid] |
| | | return inter |
| | | }) |
| | | } |
| | | config.components = MenuUtils.resetConfig(config.components, uuids, urlParam.clearMenu) |
| | | config.enabled = false |
| | | message.success('复制成功,保存后生效。') |
| | | } |