From c0cc3267837040320b4c8a572d8055b80c4d1594 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 11 十二月 2022 10:45:38 +0800 Subject: [PATCH] 2022-12-11 --- src/views/systemproc/proc/index.jsx | 290 +++++++++++++++++++++++++++++++++++++++++++++++- src/views/systemproc/proc/index.scss | 27 ++++ src/menu/components/table/base-table/columns/index.jsx | 24 +++ src/utils/utils.js | 12 +- 4 files changed, 339 insertions(+), 14 deletions(-) diff --git a/src/menu/components/table/base-table/columns/index.jsx b/src/menu/components/table/base-table/columns/index.jsx index a5f8102..c74157f 100644 --- a/src/menu/components/table/base-table/columns/index.jsx +++ b/src/menu/components/table/base-table/columns/index.jsx @@ -3,7 +3,7 @@ import { is, fromJS } from 'immutable' import { DndProvider, DragSource, DropTarget } from 'react-dnd' import { Table, Popover, Modal, message, notification } from 'antd' -import { PlusOutlined, EditOutlined, CopyOutlined, DeleteOutlined, FontColorsOutlined, CloseCircleOutlined, AntDesignOutlined } from '@ant-design/icons' +import { PlusOutlined, EditOutlined, CopyOutlined, DeleteOutlined, FontColorsOutlined, CloseCircleOutlined, AntDesignOutlined, InfoOutlined } from '@ant-design/icons' import asyncComponent from '@/utils/asyncComponent' import asyncIconComponent from '@/utils/asyncIconComponent' @@ -560,6 +560,27 @@ }) } + copyFields = () => { + const { config } = this.props + let m = [] + let n = [] + + config.columns.forEach(col => { + m.push(`${col.field}(${col.label})`) + n.push(col.field) + }) + + let oInput = document.createElement('input') + oInput.value = `/*${m.join(',')}*/ + ${n.join(',')}` + document.body.appendChild(oInput) + oInput.select() + document.execCommand('Copy') + document.body.removeChild(oInput) + + message.success('澶嶅埗鎴愬姛銆�') + } + componentDidMount () { MKEmitter.addListener('plusColumns', this.plusColumns) } @@ -604,6 +625,7 @@ <FieldsComponent config={config} type="columns" /> <CopyOutlined title="澶嶅埗鏄剧ず鍒�" onClick={this.copycolumn} /> <MarkColumn columns={fields} type="line" marks={lineMarks} onSubmit={this.updateLineMarks} /> + <InfoOutlined title="澶嶅埗瀛楁" style={{color: 'orange'}} onClick={this.copyFields}/> </div> <DndProvider> {groups ? groups.map((group, i) => { diff --git a/src/utils/utils.js b/src/utils/utils.js index e92cda2..6aac04b 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -2566,9 +2566,9 @@ @ErrorSeverity=ERROR_SEVERITY(), @ErrorState=ERROR_STATE(); - RAISERROR(@ErrorMessage, /*-- Message text.*/ - @ErrorSeverity, /*-- Severity.*/ - @ErrorState /*-- State.*/ + RAISERROR(@ErrorMessage, /* Message text.*/ + @ErrorSeverity, /* Severity.*/ + @ErrorState /* State.*/ ); END CATCH @@ -2707,9 +2707,9 @@ @ErrorSeverity=ERROR_SEVERITY(), @ErrorState=ERROR_STATE(); - RAISERROR(@ErrorMessage, /*-- Message text.*/ - @ErrorSeverity, /*-- Severity.*/ - @ErrorState /*-- State.*/ + RAISERROR(@ErrorMessage, /* Message text.*/ + @ErrorSeverity, /* Severity.*/ + @ErrorState /* State.*/ ); END CATCH diff --git a/src/views/systemproc/proc/index.jsx b/src/views/systemproc/proc/index.jsx index 56bc51f..51811aa 100644 --- a/src/views/systemproc/proc/index.jsx +++ b/src/views/systemproc/proc/index.jsx @@ -1,5 +1,5 @@ import React, {Component} from 'react' -import { Input, notification } from 'antd' +import { Input, notification, Button, Form, Modal } from 'antd' import moment from 'moment' import Utils from '@/utils/utils.js' @@ -7,17 +7,49 @@ import CodeMirror from '@/templates/zshare/codemirror' import './index.scss' +const { confirm } = Modal const { Search } = Input class ProcControl extends Component { state = { procName: '', - content: null, - loading: false + content: '', + loading: false, + visible: false, + permFuncs: [] } componentDidMount () { + if (sessionStorage.getItem('permFuncField')) { + this.setState({permFuncs: JSON.parse(sessionStorage.getItem('permFuncField'))}) + } else { + Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => { + if (res.status) { + let _permFuncs = [] + + if (res.sModular && res.sModular.length > 0) { + res.sModular.forEach(field => { + if (field.ModularNo) { + _permFuncs.push(field.ModularNo) + } + }) + _permFuncs = _permFuncs.sort() + } + + if (_permFuncs.length) { + this.setState({permFuncs: _permFuncs}) + sessionStorage.setItem('permFuncField', JSON.stringify(_permFuncs)) + } + } else { + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + } + }) + } } search = (value) => { @@ -47,14 +79,231 @@ }) this.setState({content: '', procName: '', loading: false}) return + } else if (!res.Ltext) { + this.setState({content: '', procName: '', loading: false}) + } else { + this.setState({content: res.Ltext.replace(/mchr13k/ig, '\n'), procName: proc, loading: false}) + } + }) + } + + save = (type) => { + const { content, procName, permFuncs } = this.state + let value = content.replace(/^(\s*)|(\s*)$/ig, '') + + if (!value) { + notification.warning({ + top: 92, + message: '瀛樺偍杩囩▼涓嶅彲涓虹┖', + duration: 5 + }) + return + } else { + let chars = [ + {key: 'drop', reg: /(^|\s)drop\s/ig}, + {key: 'alter', reg: /(^|\s)alter\s/ig}, + {key: 'object', reg: /(^|\s)object(\s|\()/ig}, + {key: 'kill', reg: /(^|\s)kill\s/ig}, + {key: '--', reg: /--/ig} + ] + + let error = '' + + chars.forEach(char => { + if (!error && char.reg.test(value)) { + error = char.key + } + }) + + if (error) { + notification.warning({ + top: 92, + message: '涓嶅彲浣跨敤' + error, + duration: 5 + }) + return + } + } + + if (!procName) { + if (permFuncs.length > 0) { + this.setState({visible: true}) + } else { + notification.warning({ + top: 92, + message: '鏈幏鍙栧埌鎺堟潈缂栫爜涓嶅彲鏂板缓锛�', + duration: 5 + }) + } + return + } + + let dropfunc = `IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('${procName}') AND type in (N'P', N'PC')) mdrpk PROCEDURE ${procName}` + let createfunc = value.replace(/\n/ig, 'mchr13k') + + let dropParam = { + func: 'sPC_TableData_InUpDe', + LText: Utils.formatOptions(dropfunc), + TypeCharOne: 'proc' // 鍒犻櫎瀛樺偍杩囩▼ + } + + dropParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + dropParam.secretkey = Utils.encrypt(dropParam.LText, dropParam.timestamp) + dropParam.open_key = Utils.encryptOpenKey(dropParam.secretkey, dropParam.timestamp) + + + let createParam = { + func: 'sPC_TableData_InUpDe', + LText: Utils.formatOptions(createfunc), + TypeCharOne: 'proc' // 鍒涘缓瀛樺偍杩囩▼ + } + + createParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + createParam.secretkey = Utils.encrypt(createParam.LText, createParam.timestamp) + createParam.open_key = Utils.encryptOpenKey(createParam.secretkey, createParam.timestamp) + + let saveParam = { + func: 's_proc_save', + sql_script: window.btoa(window.encodeURIComponent(createfunc)), + proc_name: procName, + save_type: type !== 'prev' ? 'auto' : '' // 'auto' 鏃� 浼氭竻y鐨勬暟鎹� + } + + this.setState({loading: true}) + + Api.genericInterface(dropParam).then(res => { + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + this.setState({loading: false}) + return } - this.setState({content: res.Ltext.replace(/mchr13k/ig, '\n'), procName: proc, loading: false}) + Api.genericInterface(createParam).then(result => { + if (!result.status) { + notification.warning({ + top: 92, + message: result.message, + duration: 5 + }) + this.setState({loading: false}) + return + } + + Api.genericInterface(saveParam).then(response => { + this.setState({loading: false}) + if (!response.status) { + notification.warning({ + top: 92, + message: response.message, + duration: 5 + }) + } else { + notification.success({ + top: 92, + message: '淇濆瓨鎴愬姛銆�', + duration: 5 + }) + } + }) + }) + }) + } + + prev = () => { + const { procName } = this.state + const that = this + + let saveParam = { + func: 's_proc_ctrl_z', + proc_name: procName + } + + confirm({ + title: '纭畾鍒囨崲涓婁竴鐗堟湰鍚楋紵', + content: '', + onOk() { + that.setState({loading: true}) + + Api.genericInterface(saveParam).then(res => { + that.setState({loading: false}) + if (!res.status || !res.Ltext) { + notification.warning({ + top: 92, + message: !res.status ? res.message : '娌℃湁鍙互鍚庨��鐨勭増鏈�', + duration: 5 + }) + return + } + + let value = window.decodeURIComponent(window.atob(res.Ltext)) + value = value.replace(/mchr13k/ig, '\n') + + that.setState({content: value}, () => { + that.save('prev') + }) + }) + }, + onCancel() {} + }) + } + + next = () => { + const { procName } = this.state + const that = this + + let saveParam = { + func: 's_proc_ctrl_y', + proc_name: procName + } + + confirm({ + title: '纭畾鍒囨崲涓嬩竴鐗堟湰鍚楋紵', + content: '', + onOk() { + that.setState({loading: true}) + + Api.genericInterface(saveParam).then(res => { + that.setState({loading: false}) + if (!res.status || !res.Ltext) { + notification.warning({ + top: 92, + message: !res.status ? res.message : '娌℃湁鍙互鎾ら攢鍚庨��鐨勭増鏈�', + duration: 5 + }) + return + } + + let value = window.decodeURIComponent(window.atob(res.Ltext)) + value = value.replace(/mchr13k/ig, '\n') + + that.setState({content: value}, () => { + that.save() + }) + }) + }, + onCancel() {} + }) + } + + handleConfirm = () => { + this.props.form.validateFieldsAndScroll((err, values) => { + if (err) return + + this.setState({procName: values.name}, () => { + this.save() + }) }) } render () { - const { loading, content } = this.state + const { getFieldDecorator } = this.props.form + const { loading, content, procName, visible, permFuncs } = this.state + + let _patten = permFuncs.length ? new RegExp('^(' + permFuncs.join('|') + ')[0-9a-zA-Z_]*$', 'g') : '' return ( <div className="mk-proc-wrap"> @@ -63,15 +312,42 @@ <Search placeholder="璇疯緭鍏ュ瓨鍌ㄨ繃绋嬪悕绉�" disabled={loading} enterButton="纭畾" onSearch={this.search}/> </div> <div className="action-wrap"> - + <Button key="save" className="mk-btn mk-green" disabled={loading} onClick={() => this.save()}>淇濆瓨</Button> + <Button key="prev" className="mk-btn mk-primary" disabled={!procName || loading} onClick={this.prev}>涓婁竴鐗堟湰</Button> + <Button key="next" className="mk-btn mk-primary" disabled={!procName || loading} onClick={this.next}>涓嬩竴鐗堟湰</Button> </div> </div> <div className="edit-wrap"> <CodeMirror value={content} onChange={(val) => this.setState({content: val})}/> </div> + <Modal + title="鏂板缓" + wrapClassName="mk-create-func" + visible={visible} + onOk={this.handleConfirm} + width={540} + onCancel={() => {this.setState({ visible: false })}} + destroyOnClose + > + <Form.Item label="瀛樺偍杩囩▼鍚嶇О"> + {getFieldDecorator('name', { + initialValue: '', + rules: [ + { + required: true, + message: '璇疯緭鍏ュ瓨鍌ㄨ繃绋嬪悕绉�!' + }, + { + pattern: _patten, + message: `鍙厑璁稿寘鍚暟瀛椼�佸瓧姣嶅拰涓嬪垝绾匡紝涓斾互${permFuncs.join(', ')}绛夊瓧绗﹀紑濮嬨�俙 + } + ] + })(<Input placeholder="" autoComplete="off" />)} + </Form.Item> + </Modal> </div> ) } } -export default ProcControl \ No newline at end of file +export default Form.create()(ProcControl) \ No newline at end of file diff --git a/src/views/systemproc/proc/index.scss b/src/views/systemproc/proc/index.scss index d8d5749..fc2fdff 100644 --- a/src/views/systemproc/proc/index.scss +++ b/src/views/systemproc/proc/index.scss @@ -15,6 +15,21 @@ opacity: 0.5; } } + .action-wrap { + text-align: right; + flex: 1; + + .ant-btn { + margin-left: 20px; + } + + .ant-btn[disabled] { + background-color: #1890ff!important; + border-color: #1890ff!important; + color: #ffffff!important; + opacity: 0.5; + } + } } .edit-wrap { @@ -33,3 +48,15 @@ } } } + +.mk-create-func { + .ant-modal-body { + min-height: 180px; + } + .ant-form-item { + display: flex; + .ant-form-item-control-wrapper { + flex: 1; + } + } +} -- Gitblit v1.8.0