import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { DndProvider } from 'react-dnd'
|
import HTML5Backend from 'react-dnd-html5-backend'
|
import { Button, Modal, notification, Form, Select } from 'antd'
|
|
import Utils from '@/utils/utils.js'
|
import Api from '@/api'
|
import asyncComponent from '@/utils/asyncComponent'
|
import './index.scss'
|
|
const EditTable = asyncComponent(() => import('@/templates/zshare/modalform/modaleditable'))
|
|
class TransferWrap extends Component {
|
static propTpyes = {
|
MenuID: PropTypes.string
|
}
|
|
state = {
|
visible: false,
|
loading: false,
|
VersionName: '',
|
translist: [],
|
options: []
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
verifySubmit = () => {
|
const { content, procName } = this.props
|
const { VersionName, options } = this.state
|
let value = content.replace(/^(\s*)|(\s*)$/ig, '')
|
|
if (!VersionName) {
|
notification.warning({
|
top: 92,
|
message: '请选择传输号',
|
duration: 5
|
})
|
return
|
} else if (!value) {
|
notification.warning({
|
top: 92,
|
message: '存储过程不可为空',
|
duration: 5
|
})
|
return
|
}
|
|
let regs = []
|
options.forEach(item => {
|
if (item.origin && !/^\s+$/.test(item.origin) && item.origin !== item.value) {
|
regs.push({reg: new RegExp(item.origin, 'g'), value: item.value})
|
}
|
})
|
|
regs.forEach(item => {
|
value = value.replace(item.reg, item.value)
|
})
|
|
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},
|
{key: ',,', reg: /,,/ig}
|
]
|
|
let error = ''
|
|
if (!/create(\s+)proc/ig.test(value)) {
|
error = '脚本中必须使用create proc'
|
}
|
|
chars.forEach(char => {
|
if (!error && char.reg.test(value)) {
|
error = '不可使用' + char.key
|
}
|
})
|
|
if (error) {
|
notification.warning({
|
top: 92,
|
message: error,
|
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 dropParam = {
|
func: 's_sVersionDetail_Add',
|
BID: VersionName,
|
VType: 'VSQL',
|
VSQL: window.btoa(window.encodeURIComponent(dropfunc))
|
}
|
|
let addParam = {
|
func: 's_sVersionDetail_Add',
|
BID: VersionName,
|
VType: 'VSQL',
|
VSQL: window.btoa(window.encodeURIComponent(value))
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
Api.genericInterface(dropParam).then(result => {
|
if (!result.status) {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
this.setState({
|
loading: false
|
})
|
return
|
}
|
|
delete result.status
|
delete result.message
|
delete result.ErrCode
|
delete result.ErrMesg
|
result.func = 's_sVersionDetail_CloudAdd'
|
|
Api.genericInterface(addParam).then(res => {
|
if (!res.status) {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
this.setState({
|
loading: false
|
})
|
return
|
}
|
|
delete res.status
|
delete res.message
|
delete res.ErrCode
|
delete res.ErrMesg
|
res.func = 's_sVersionDetail_CloudAdd'
|
|
Api.getCloudConfig(result).then(re => {
|
if (!re.status) {
|
notification.warning({
|
top: 92,
|
message: re.message,
|
duration: 5
|
})
|
this.setState({
|
loading: false
|
})
|
return
|
}
|
|
Api.getCloudConfig(res).then(r => {
|
if (!r.status) {
|
notification.warning({
|
top: 92,
|
message: r.message,
|
duration: 5
|
})
|
this.setState({
|
loading: false
|
})
|
return
|
} else {
|
notification.success({
|
top: 92,
|
message: '添加成功!',
|
duration: 3
|
})
|
this.setState({
|
loading: false,
|
visible: false
|
})
|
}
|
})
|
})
|
})
|
})
|
}
|
|
getTransList = () => {
|
const { content } = this.props
|
let value = content.replace(/^(\s*)|(\s*)$/ig, '')
|
|
if (!value) {
|
notification.warning({
|
top: 92,
|
message: '存储过程不可为空',
|
duration: 5
|
})
|
return
|
}
|
|
let param = {
|
func: 's_get_sVersion',
|
dataM: 'Y',
|
PageSize: 9999,
|
PageIndex: 1,
|
OrderCol: 'ID desc'
|
}
|
|
let options = []
|
|
let list = value.match(/\s+[a-z0-9_]+\.(dbo)?\./ig)
|
list && list.forEach(str => {
|
str = str.replace(/^\s/, '')
|
options.push({
|
key: Utils.getuuid(),
|
origin: str,
|
value: str
|
})
|
})
|
|
this.setState({
|
options: options,
|
VersionName: '',
|
visible: true,
|
loading: false
|
})
|
|
Api.getCloudConfig(param).then(result => {
|
if (result.status) {
|
this.setState({
|
translist: result.data
|
})
|
} else {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
changeOptions = (value) => {
|
this.setState({options: value})
|
}
|
|
render () {
|
const { visible, loading, translist, options } = this.state
|
const columns = [{ title: '原信息', key: 'origin', width: '50%', fixed: true }, { title: '替换为', width: '50%', key: 'value' }]
|
|
return (
|
<>
|
<Button icon="pull-request" className="mk-border-green" onClick={this.getTransList}>传输号</Button>
|
<Modal
|
title="加入传输号"
|
wrapClassName="proc-transfer"
|
visible={visible}
|
width={900}
|
maskClosable={false}
|
okText="确定"
|
onOk={this.verifySubmit}
|
onCancel={() => { this.setState({ visible: false }) }}
|
confirmLoading={loading}
|
destroyOnClose
|
>
|
<Form.Item label="传输号">
|
<Select onChange={(val) => this.setState({VersionName: val})}>
|
{translist.map(option =>
|
<Select.Option key={option.VersionName} value={option.VersionName}>{`${option.ProgramName}(${option.VersionName})`}</Select.Option>
|
)}
|
</Select>
|
</Form.Item>
|
{options.length > 0 ? <DndProvider backend={HTML5Backend}>
|
<Form.Item label="替换项">
|
<EditTable type="proc" columns={columns} value={options} onChange={this.changeOptions}/>
|
</Form.Item>
|
</DndProvider> : null}
|
</Modal>
|
</>
|
)
|
}
|
}
|
|
export default TransferWrap
|