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 Api from '@/api'
|
import './index.scss'
|
|
class CreateFunc extends Component {
|
static propTypes = {
|
dict: PropTypes.object, // 字典项
|
trigger: PropTypes.func
|
}
|
|
state = {
|
loading: false,
|
}
|
|
exec = (menu, config) => {
|
let _grid = []
|
let _fields = []
|
let _index = 1
|
|
config.columns.forEach(item => {
|
if (!item.field || item.type === 'colspan') return
|
|
let _type = `nvarchar(${item.fieldlength || 50})`
|
|
if (item.type === 'number') {
|
_type = `decimal(18,${item.decimal ? item.decimal : 0})`
|
} else if (item.type === 'picture' || item.type === 'textarea') {
|
_type = `nvarchar(${item.fieldlength || 512})`
|
}
|
|
_grid.push(item.field)
|
_fields.push(`select '${item.field}' as gridfield,'${_type}' as fieldtype,'${item.label}' as label,'${_index}' as Sort`)
|
_index++
|
})
|
|
let _search = []
|
_index = 1
|
|
if (menu.type !== 'main') {
|
if (config.setting.dataresource && /@BID@/ig.test(config.setting.dataresource)) {
|
_search.push(`select 'BID' as searchfield,'BID' as label,'0' as Sort,'' as defaultvalue,'required' as DefaultType`)
|
_index++
|
} else {
|
_search.push(`select 'BID' as searchfield,'BID' as label,'0' as Sort,'' as defaultvalue,'' as DefaultType`)
|
_index++
|
}
|
}
|
|
let _fieldMap = new Map()
|
|
config.search.forEach(item => {
|
let fields = [item.field]
|
let _val = item.initval
|
|
if (item.type === 'text') {
|
fields = item.field.split(',')
|
}
|
if (/^date/ig.test(item.type)) {
|
_val = ''
|
}
|
|
if (item.type === 'datemonth' || item.type === 'dateweek' || item.type === 'daterange') {
|
fields = [item.field, item.field]
|
}
|
|
fields.forEach(cell => {
|
let _field = cell
|
if (_fieldMap.has(cell)) {
|
_field = _field + '1'
|
}
|
|
_fieldMap.set(cell, true)
|
|
_search.push(`select '${_field}' as searchfield,'${item.label}' as label,'${_index}' as Sort,'${_val}' as defaultvalue,'${item.required === 'true' ? 'required' : ''}' as DefaultType`)
|
_index++
|
})
|
})
|
|
let searchText = []
|
_fieldMap = new Map()
|
|
config.search.forEach((item, i) => {
|
if (item.type === 'text') {
|
let str = item.match === '=' ? '' : '\'%\''
|
let _fields_ = item.field.split(',').map(field => { // 综合搜索,所字段拼接
|
|
return field + ' ' + item.match + ` ${str ? str + '+' : ''}@` + field + `@${str ? '+' + str : ''}`
|
})
|
|
if (_fields_.length === 1) {
|
searchText.push(_fields_[0])
|
} else {
|
searchText.push('(' + _fields_.join(' OR ') + ')')
|
}
|
} else if (item.type === 'select') {
|
|
searchText.push(item.field + ' ' + item.match + ' @' + item.field + '@')
|
} else if (item.type === 'multiselect') {
|
|
searchText.push(`@${item.field}@ ` + item.match + ' \'%\'+' + item.field + '+\'%\'')
|
} else if (item.type === 'date') {
|
let _field = item.field
|
if (_fieldMap.has(item.field)) {
|
_field = _field + '1'
|
}
|
|
_fieldMap.set(item.field, true)
|
|
searchText.push(item.field + ' ' + item.match + ' @' + _field + '@')
|
} else if (item.type === 'datemonth' || item.type === 'dateweek' || item.type === 'daterange') {
|
|
searchText.push('(' + item.field + ' >= @' + item.field + '@ AND ' + item.field + ' < @' + item.field + '1@)')
|
} else {
|
searchText.push(item.field + ' ' + item.match + ' @' + item.field + '@')
|
}
|
})
|
|
let param = {
|
func: 's_get_para_for_out',
|
Menuid: menu.MenuID,
|
Menuname: menu.menuName,
|
Menuno: menu.menuNo,
|
Ltextgridparam: _fields.join(' union all '),
|
Ltextsearchparam: _search.join(' union all '),
|
AppendWhere: config.setting.queryType === 'query' ? searchText.join(' AND ') : '',
|
Ltextgrid: _grid.join(','),
|
WhereType: config.setting.queryType === 'statistics' ? 'Statistics' : 'query',
|
OrderCol: config.setting.order
|
}
|
|
param.Ltextsearchparam = Utils.formatOptions(param.Ltextsearchparam)
|
param.AppendWhere = Utils.formatOptions(param.AppendWhere)
|
|
param.Ltextgridparam = Utils.formatOptions(param.Ltextgridparam)
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
|
param.secretkey = Utils.encrypt(param.Ltextgridparam, param.timestamp)
|
|
this.setState({
|
loading: true
|
})
|
|
return new Promise(resolve => {
|
this.createExec(resolve, param)
|
})
|
}
|
|
createExec = (_resolve, param) => {
|
let _mainParam = JSON.parse(JSON.stringify(param))
|
|
new Promise(resolve => {
|
// 获取云端存储过程信息
|
Api.getLocalConfig(param).then(result => {
|
if (!result.status) {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 10
|
})
|
resolve(false)
|
} else {
|
resolve(true)
|
}
|
})
|
}).then(res => {
|
if (res === false) return res
|
|
if (window.GLOB.mainSystemApi) {
|
_mainParam.rduri = window.GLOB.mainSystemApi
|
|
return Api.getLocalConfig(_mainParam)
|
}
|
return 'success'
|
}).then(result => {
|
if (result === false || result === 'success') return result
|
|
if (!result.status) {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 10
|
})
|
return false
|
} else {
|
return 'success'
|
}
|
}).then(res => {
|
// 结果处理
|
if (res === false) {
|
_resolve('error')
|
} else {
|
notification.success({
|
top: 92,
|
message: '创建成功',
|
duration: 2
|
})
|
_resolve('success')
|
}
|
|
this.setState({
|
loading: false
|
})
|
})
|
}
|
|
render() {
|
|
return (
|
<Button
|
className="mk-btn mk-green"
|
onClick={this.props.trigger}
|
loading={this.state.loading}
|
>
|
{this.props.dict['header.menu.interface.create']}
|
</Button>
|
)
|
}
|
}
|
|
export default CreateFunc
|