import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Button, notification } from 'antd'
|
import moment from 'moment'
|
|
import Utils from '@/utils/utils.js'
|
import FuncUtils from './utils.js'
|
import Api from '@/api'
|
// import './index.scss'
|
|
class CreateFunc extends Component {
|
static propTypes = {
|
getMsg: PropTypes.func
|
}
|
|
state = {
|
loading: false
|
}
|
|
trigger = () => {
|
this.props.getMsg().then(config => {
|
let newLText = ''
|
let func = ''
|
|
if (config.$type === 'table') {
|
func = config.func
|
newLText = FuncUtils.getTableFunc(config)
|
} else if (config.$type === 'excelIn') {
|
func = config.func
|
newLText = FuncUtils.getexcelInfunc(config)
|
} else if (config.$type === 'btn') {
|
func = config.func
|
newLText = FuncUtils.getfunc(config)
|
}
|
|
if (!newLText || !func) return
|
|
this.createExec(func, newLText)
|
})
|
}
|
|
createExec = (func, newLText) => {
|
let dropfunc = `IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('${func}') AND type in (N'P', N'PC')) mdrpk PROCEDURE ${func}`
|
// 删除存储过程
|
let droparam = {
|
func: 'sPC_TableData_InUpDe',
|
LText: Utils.formatOptions(dropfunc, window.GLOB.execType || 'y'),
|
exec_type: window.GLOB.execType || 'y',
|
TypeCharOne: 'proc' // 删除或创建存储过程标志
|
}
|
|
droparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
droparam.secretkey = Utils.encrypt('', droparam.timestamp)
|
droparam.open_key = Utils.encryptOpenKey(droparam.secretkey, droparam.timestamp)
|
|
// 新建存储过程
|
let _param = {
|
func: 'sPC_TableData_InUpDe',
|
LText: Utils.formatOptions(newLText, window.GLOB.execType || 'y'),
|
exec_type: window.GLOB.execType || 'y',
|
TypeCharOne: 'proc'
|
}
|
_param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
_param.secretkey = Utils.encrypt('', _param.timestamp)
|
_param.open_key = Utils.encryptOpenKey(_param.secretkey, _param.timestamp)
|
|
let saveParam = {
|
func: 's_proc_save',
|
sql_script: window.btoa(window.encodeURIComponent(newLText)),
|
proc_name: func,
|
save_type: 'auto'
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
Api.genericInterface(droparam).then(res => {
|
if (!res.status) {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
this.setState({
|
loading: false
|
})
|
return
|
}
|
Api.genericInterface(_param).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
|
})
|
}
|
})
|
})
|
})
|
}
|
|
render() {
|
return (
|
<Button
|
className="mk-btn mk-purple"
|
onClick={this.trigger}
|
loading={this.state.loading}
|
>
|
创建存储过程
|
</Button>
|
)
|
}
|
}
|
|
export default CreateFunc
|