import React, { Component } from 'react'
|
import { Input, Button, message } from 'antd'
|
|
import Api from '@/api'
|
import sqlFormatter from '@/utils/sqlFormatter.js'
|
import Utils from '@/utils/utils.js'
|
|
import './index.scss'
|
|
const { TextArea } = Input
|
|
class MkTrans extends Component {
|
state = {
|
type: '',
|
value: null,
|
textInput: ''
|
}
|
|
changeVal = (e) => {
|
this.setState({textInput: e.target.value})
|
}
|
|
changeType = (type) => {
|
if (type === 'mk_func' && this.state.textInput) {
|
let val = this.state.textInput.replace(/(\s|\t|\v)*/ig, '')
|
if (/^[a-zA-Z_]+$/.test(val)) {
|
let params = {
|
url: window.location.origin + '/star',
|
method: 'post',
|
data: JSON.stringify({
|
FUNC: 's_get_userproc',
|
LText: val,
|
UserID: '',
|
USERNAME: ''
|
})
|
}
|
|
Api.directRequest(params).then(result => {
|
this.setState({textInput: JSON.stringify(result)})
|
})
|
}
|
}
|
if (!this.state.type) {
|
this.setState({type: type, value: null})
|
} else if (['mk_fields', 'mk_cols'].includes(type) && ['mk_fields', 'mk_cols'].includes(this.state.type)) {
|
this.setState({type: type, value: null})
|
} else {
|
this.setState({type: type, textInput: '', value: null})
|
}
|
|
let node = document.getElementById('trans-input')
|
node && node.focus()
|
}
|
|
trans = () => {
|
const { type, textInput } = this.state
|
|
if (!type) {
|
message.error('请选择转化类型!')
|
return
|
}
|
|
let result = ''
|
if (type === 'mk_searches') {
|
let list = JSON.parse(textInput)
|
|
if (list.rows) {
|
list = list.rows
|
list = list.map(item => {
|
item.Sort = +item.Sort
|
return item
|
})
|
list.sort((a, b) => a.Sort - b.Sort)
|
}
|
|
result = []
|
|
list.forEach(item => {
|
if (item.Op === 'lessorequal') {
|
item.Op = '<='
|
} else if (item.Op === 'greaterorequal') {
|
item.Op = '>='
|
} else if (item.Op === 'equal') {
|
item.Op = '='
|
}
|
let cell = {
|
uuid: Utils.getuuid(),
|
label: item.Label,
|
match: ['like', 'not like', '=', '>', '<', '>=', '<='].includes(item.Op) ? item.Op : '',
|
field: item.FieldName.toLowerCase(),
|
initval: '',
|
ratio: 6,
|
type: 'text'
|
}
|
|
if (item.Type === 'string') {
|
cell.type = 'text'
|
} else if (item.Type === 'select') {
|
cell.type = 'select'
|
cell.resourceType = '1'
|
cell.valueField = item.IdField
|
cell.valueText = item.TextField
|
cell.dataSource = item.FromField
|
cell.orderBy = item.OrderField || ''
|
cell.orderType = 'asc'
|
cell.options = []
|
cell.initval = item.InitVal || ''
|
|
if (cell.dataSource) {
|
cell.dataSource = `select * from @db@${cell.dataSource}`
|
|
if (item.WhereField) {
|
if (/\(/.test(item.WhereField) && item.WhereField.match(/\(/g).length === 1) {
|
cell.dataSource += ' where ' + item.WhereField.replace(/^\s*\(|\)\s*$/g, '')
|
} else {
|
cell.dataSource += ' where ' + item.WhereField
|
}
|
}
|
}
|
|
cell.dataSource = this.sqltrans(cell.dataSource)
|
|
if (item.multiple === 'true') {
|
cell.type = 'multiselect'
|
}
|
} else if (item.Type === 'date') {
|
cell.type = 'date'
|
cell.precision = 'day'
|
if (item.InitVal === '30dd' || item.BeginDate === 'getLastMonth()') {
|
cell.initval = '30'
|
}
|
}
|
|
result.push(cell)
|
})
|
|
result = JSON.stringify(result)
|
} else if (type === 'mk_actions') {
|
let list = JSON.parse(textInput)
|
|
if (list.rows) {
|
list = list.rows.filter(item => item.IsButton === '1')
|
list = list.map(item => {
|
item.Sort = +item.Sort
|
return item
|
})
|
list.sort((a, b) => a.Sort - b.Sort)
|
}
|
|
result = []
|
|
list.forEach(item => {
|
let cell = {
|
uuid: Utils.getuuid(),
|
label: item.MenuName,
|
show: 'button',
|
execError: 'never',
|
execSuccess: 'grid',
|
Ot: 'required',
|
class: 'primary',
|
verify: null
|
}
|
|
// if (item.ReloadForm === 'grid') {
|
// cell.execSuccess = 'grid'
|
// }
|
if (item.Action === 'PopDlg') {
|
cell.OpenType = 'pop'
|
} else if (item.Action === 'Add' || item.Action === 'Update' || item.Action === 'AddUpdate') {
|
cell.OpenType = 'pop'
|
} else if (item.Action === 'PopGrid') {
|
cell.OpenType = 'popview'
|
} else if (item.Action === 'Print') {
|
cell.OpenType = 'innerpage'
|
cell.pageTemplate = 'billprint'
|
} else if (item.Action === 'View') {
|
cell.OpenType = 'popview'
|
} else if (['PromptOnce', 'Prompt', 'Delete'].includes(item.Action)) {
|
cell.OpenType = 'prompt'
|
} else if (item.Action === 'ExportExcel') {
|
cell.OpenType = 'excelOut'
|
} else if (item.Action === 'ExcelIn') {
|
cell.OpenType = 'excelIn'
|
}
|
|
if (/添加/.test(cell.label)) {
|
cell.Ot = 'notRequired'
|
cell.class = 'green'
|
} else if (/修改/.test(cell.label)) {
|
cell.Ot = 'requiredSgl'
|
cell.class = 'purple'
|
} else if (/删除/.test(cell.label)) {
|
cell.class = 'danger'
|
} else if (/导入/.test(cell.label)) {
|
cell.Ot = 'notRequired'
|
cell.class = 'border-dgreen'
|
} else if (/扫码|扫描/.test(cell.label)) {
|
cell.Ot = 'notRequired'
|
cell.class = 'border-green'
|
} else if (cell.OpenType === 'excelOut') {
|
cell.Ot = 'requiredOnce'
|
cell.class = 'dgreen'
|
}
|
|
if (item.TableName) {
|
cell.sql = item.TableName
|
}
|
if (['pop', 'prompt', 'exec'].includes(cell.OpenType)) {
|
cell.intertype = 'system'
|
cell.verify = {invalid: 'false'}
|
if (/添加/.test(cell.label)) {
|
cell.sqlType = 'insert'
|
} else if (/修改/.test(cell.label)) {
|
cell.sqlType = 'update'
|
} else if (/删除/.test(cell.label)) {
|
cell.sqlType = 'LogicDelete'
|
}
|
if (!cell.sqlType) {
|
if (cell.OpenType === 'pop') {
|
cell.sqlType = 'audit'
|
} else {
|
cell.sqlType = 'custom'
|
}
|
}
|
} else if (cell.OpenType === 'excelOut') {
|
cell.intertype = 'system'
|
}
|
|
if (cell.Ot === 'required') {
|
cell.execError = 'grid'
|
}
|
|
if (cell.class) {
|
let color = { primary: '#1890ff', yellow: '#c49f47', orange: 'orange', danger: '#ff4d4f', green: '#26C281', dgreen: '#32c5d2', purple: '#8E44AD', cyan: '#13c2c2', gray: '#E7E7EF', default: 'rgba(0, 0, 0, 0.65)' }
|
let _c = cell.class.replace('border-', '')
|
if (cell.class === 'default') {
|
cell.style = {color: 'rgba(0, 0, 0, 0.65)', backgroundColor: '#fff', borderColor: '#d9d9d9', marginRight: '15px'}
|
} else if (cell.class.indexOf('border') > -1) {
|
cell.style = {color: color[_c], backgroundColor: '#fff', borderColor: color[_c], marginRight: '15px'}
|
} else if (cell.class === 'gray') {
|
cell.style = {color: 'rgba(0, 0, 0, 0.65)', backgroundColor: color[_c], borderColor: color[_c], marginRight: '15px'}
|
} else {
|
cell.style = {color: '#fff', backgroundColor: color[_c], borderColor: color[_c], marginRight: '15px'}
|
}
|
}
|
|
result.push(cell)
|
})
|
|
result = JSON.stringify(result)
|
} else if (type === 'mk_setting') {
|
let list = JSON.parse(textInput)
|
let data = list.rows[0]
|
|
let tb = data.QueryFrom
|
let id = data.TableID ? data.TableID.toLowerCase() : 'id'
|
let order = ''
|
|
if (data.SortName) {
|
order = data.SortName.toLowerCase() + ' ' + (data.SortOrder || 'desc')
|
}
|
|
if (/^[a-zA-Z0-9_]+$/.test(data.QueryFrom)) {
|
tb = 'select * from @db@' + data.QueryFrom
|
}
|
if (tb && data.AppendWhere) {
|
if (/\(/.test(data.AppendWhere) && data.AppendWhere.match(/\(/g).length === 1) {
|
tb += ` where ${data.AppendWhere.replace(/^\s*\(|\)\s*$/g, '')}`
|
} else {
|
tb += ` where ${data.AppendWhere}`
|
}
|
}
|
|
tb = this.sqltrans(tb)
|
|
result = {
|
tableName: '@db@' + data.TableName,
|
interType: 'system',
|
queryType: 'query',
|
execute: 'true',
|
laypage: 'true',
|
pageSize: 10,
|
supModule: ['empty'],
|
primaryKey: id,
|
order: order,
|
sync: 'false',
|
useMSearch: 'false',
|
onload: 'true',
|
dataresource: tb
|
}
|
|
result = JSON.stringify(result)
|
} else if (type === 'mk_fields') {
|
let list = JSON.parse(textInput)
|
|
if (list.rows) {
|
list = list.rows
|
list = list.map(item => {
|
item.Sort = +item.Sort
|
return item
|
})
|
list.sort((a, b) => a.Sort - b.Sort)
|
}
|
|
result = []
|
|
list.forEach(item => {
|
let cell = {
|
uuid: Utils.getuuid(),
|
label: item.Label,
|
field: item.FieldName.toLowerCase(),
|
datatype: 'Nvarchar(50)',
|
}
|
|
if (item.Type === 'text') {
|
if (cell.field === 'description') {
|
cell.datatype = 'Nvarchar(100)'
|
} else if (['remark', 'address'].includes(cell.field)) {
|
cell.datatype = 'Nvarchar(256)'
|
}
|
} else if (item.Type === 'image') {
|
cell.datatype = 'Nvarchar(256)'
|
} else if (item.Type === 'number') {
|
cell.datatype = 'Int'
|
}
|
|
if (/int/ig.test(cell.datatype)) {
|
cell.type = 'number'
|
cell.decimal = 0
|
} else {
|
cell.type = 'text'
|
cell.fieldlength = +cell.datatype.replace(/^Nvarchar\(/ig, '').replace(/\)/ig, '')
|
}
|
|
result.push(cell)
|
})
|
|
result = JSON.stringify(result)
|
} else if (type === 'mk_cols') {
|
let list = JSON.parse(textInput)
|
|
if (list.rows) {
|
list = list.rows
|
list = list.map(item => {
|
item.Sort = +item.Sort
|
return item
|
})
|
list.sort((a, b) => a.Sort - b.Sort)
|
}
|
|
result = []
|
let cosCol = null
|
|
list.forEach(item => {
|
if (item.Hide === 'true') return
|
if (item.ColSpanID && item.ColSpanTitle) {
|
let _cell = {
|
uuid: Utils.getuuid(),
|
datatype: 'dynamic',
|
width: 24,
|
marks: null,
|
height: '',
|
noValue: 'hide',
|
style: { paddingLeft: '4px' },
|
prefix: '',
|
postfix: '',
|
eleType: 'text',
|
field: item.FieldName.toLowerCase(),
|
innerHeight: 'auto'
|
}
|
if (cosCol) {
|
if (cosCol.ColSpanID === item.ColSpanID) {
|
cosCol.elements.push(_cell)
|
} else {
|
result.push(JSON.parse(JSON.stringify(cosCol)))
|
cosCol = {
|
ColSpanID: item.ColSpanID,
|
uuid: Utils.getuuid(),
|
label: item.ColSpanTitle,
|
Hide: 'false',
|
Align: item.Align || 'left',
|
IsSort: 'false',
|
type: 'custom',
|
Width: 120,
|
elements: [_cell]
|
}
|
}
|
} else {
|
cosCol = {
|
ColSpanID: item.ColSpanID,
|
uuid: Utils.getuuid(),
|
label: item.ColSpanTitle,
|
Hide: 'false',
|
Align: item.Align || 'left',
|
IsSort: 'false',
|
type: 'custom',
|
Width: 120,
|
elements: [_cell]
|
}
|
}
|
return
|
} else if (cosCol) {
|
result.push(JSON.parse(JSON.stringify(cosCol)))
|
cosCol = null
|
}
|
|
let cell = {
|
uuid: Utils.getuuid(),
|
label: item.Label,
|
field: item.FieldName.toLowerCase(),
|
Hide: 'false',
|
Align: item.Align || 'left',
|
IsSort: 'false',
|
type: 'text',
|
Width: 120
|
}
|
|
if (item.Type === 'text') {
|
cell.textFormat = 'none'
|
} else if (item.Type === 'image') {
|
cell.type = 'picture'
|
cell.span = 24
|
cell.lenWidRadio = '1:1'
|
cell.backgroundSize = 'cover'
|
cell.scale = 'true'
|
cell.lostTip = 'true'
|
} else if (item.Type === 'number') {
|
cell.type = 'number'
|
cell.Width = 80
|
cell.decimal = 0
|
cell.format = 'none'
|
}
|
|
result.push(cell)
|
})
|
|
if (cosCol) {
|
result.push(JSON.parse(JSON.stringify(cosCol)))
|
}
|
|
result = JSON.stringify(result)
|
} else if (type === 'mk_forms') {
|
let list = JSON.parse(textInput)
|
|
if (list.rows) {
|
let types = []
|
list = list.rows.map(item => {
|
item.Sort = +item.Sort
|
types.push(item.SubMenu)
|
return item
|
})
|
types = Array.from(new Set(types))
|
|
if (types.length > 1) {
|
list = list.filter(item => !item.SubMenu)
|
}
|
|
list.sort((a, b) => a.Sort - b.Sort)
|
}
|
|
result = []
|
let groups = []
|
|
list.forEach(item => {
|
if (item.InputType === 'hidden' && item.FieldName === 'ID') return
|
|
if (item.GROUPLabel && !groups.includes(item.GROUPLabel)) {
|
groups.push(item.GROUPLabel)
|
|
result.push({
|
uuid: Utils.getuuid(),
|
label: item.GROUPLabel,
|
type: 'split',
|
hidden: 'false',
|
})
|
}
|
|
let cell = {
|
uuid: Utils.getuuid(),
|
label: item.Label,
|
field: item.FieldName.toLowerCase(),
|
initval: item.InitVal || '',
|
type: 'text',
|
span: 12,
|
labelwidth: 33.3,
|
decimal: 0,
|
fieldlength: 50,
|
readonly: 'false',
|
required: 'true',
|
hidden: 'false',
|
readin: 'top'
|
}
|
|
if (cell.field === 'description') {
|
cell.fieldlength = 100
|
} else if (['remark', 'address'].includes(cell.field)) {
|
cell.fieldlength = 256
|
}
|
|
if (item.Hide === 'true') {
|
cell.hidden = 'true'
|
}
|
if (item.ReadOnly === 'true') {
|
cell.readonly = 'true'
|
}
|
|
if (item.Validate && /required:\s?true/.test(item.Validate)) {
|
cell.required = 'true'
|
} else {
|
cell.required = 'false'
|
}
|
|
if (item.InputType === 'text') {
|
|
} else if (item.InputType === 'textarea') {
|
cell.type = 'textarea'
|
cell.fieldlength = 8000
|
cell.maxRows = 6
|
cell.span = 24
|
cell.labelwidth = 16.2
|
} else if (item.InputType === 'date') {
|
cell.type = 'date'
|
cell.initval = ''
|
cell.precision = 'day'
|
cell.declareType = 'datetime'
|
} else if (item.InputType === 'hidden') {
|
cell.type = 'text'
|
cell.hidden = 'true'
|
} else if (item.InputType === 'image') {
|
cell.type = 'fileupload'
|
cell.fieldlength = 512
|
cell.fileType = 'text'
|
cell.compress = 'oss'
|
} else if (item.InputType === 'spinner') {
|
cell.type = 'number'
|
cell.required = 'true'
|
cell.initval = cell.initval ? +cell.initval : ''
|
cell.decimal = 0
|
cell.min = item.MinValue ? +item.MinValue : ''
|
cell.max = item.MAXValue ? +item.MAXValue : ''
|
} else if (item.InputType === 'select') {
|
cell.type = 'select'
|
cell.resourceType = '1'
|
cell.valueField = item.IdField
|
cell.valueText = item.TextField
|
cell.dataSource = item.FromField
|
cell.orderBy = item.OrderField || ''
|
cell.orderType = 'asc'
|
cell.options = []
|
|
if (cell.dataSource) {
|
cell.dataSource = `select * from @db@${cell.dataSource}`
|
|
if (item.WhereField) {
|
if (/\(/.test(item.WhereField) && item.WhereField.match(/\(/g).length === 1) {
|
cell.dataSource += ' where ' + item.WhereField.replace(/^\s*\(|\)\s*$/g, '')
|
} else {
|
cell.dataSource += ' where ' + item.WhereField
|
}
|
}
|
}
|
|
cell.dataSource = this.sqltrans(cell.dataSource)
|
|
if (item.Multi === 'true') {
|
cell.type = 'multiselect'
|
}
|
}
|
|
result.push(cell)
|
})
|
|
if (result.length === 1 && result[0].span === 12) {
|
result[0].span = 22
|
}
|
|
result = JSON.stringify(result)
|
} else if (type === 'mk_func') {
|
let res = JSON.parse(textInput)
|
result = ''
|
|
if (res.getproc) {
|
result = res.getproc[0].Ltext
|
}
|
|
result = result.replace(/mchr13k/g, '\n')
|
result = result.replace(/\t|\v/g, ' ')
|
result = result.replace(/--[^\n]+\n/g, (w) => {
|
w = w.replace(/-{2,10}/, '/* ')
|
w = w.replace(/-{2,10}/g, '-')
|
w = w.replace(/\n/, ' */\n')
|
return w
|
})
|
|
result = result.replace(/@ID[^0-9a-z_@]/ig, (w) => w.replace(/@ID/i, '@ID@'))
|
result = result.replace(/@BID[^0-9a-z_@]/ig, (w) => w.replace(/@BID/i, '@BID@'))
|
result = result.replace(/@userid[^0-9a-z_@]/ig, (w) => w.replace(/@UserID/i, '@UserID@'))
|
|
result = result.replace(/@ID@\s+nvarchar\(/ig, '@ID nvarchar(')
|
result = result.replace(/@BID@\s+nvarchar\(/ig, '@BID nvarchar(')
|
result = result.replace(/@userid@\s+nvarchar\(/ig, '@UserID nvarchar(')
|
|
result = result.replace(/@ErrorCode='10'/ig, `@ErrorCode='E'`)
|
result = result.replace(/@ParValue[^0-9a-z_]/ig, (w) => {
|
return w.replace(/@ParValue/ig, `@bid@`)
|
})
|
result = result.replace(/\n(\s*\n)+/ig, `\n\n`)
|
|
// result = this.handleFormat(result)
|
}
|
|
this.setState({value: result})
|
}
|
|
sqltrans = (sql) => {
|
sql = sql.replace(/@ID[^0-9a-z_@]/ig, (w) => w.replace(/@ID/i, '@ID@'))
|
sql = sql.replace(/@BID[^0-9a-z_@]/ig, (w) => w.replace(/@BID/i, '@BID@'))
|
sql = sql.replace(/@userid[^0-9a-z_@]/ig, (w) => w.replace(/@UserID/i, '@UserID@'))
|
|
sql = sql.replace(/@ID@\s+nvarchar\(/ig, '@ID nvarchar(')
|
sql = sql.replace(/@BID@\s+nvarchar\(/ig, '@BID nvarchar(')
|
sql = sql.replace(/@userid@\s+nvarchar\(/ig, '@UserID nvarchar(')
|
|
// 系统表
|
let tables = ['sPermission', 'V_DealerType', "areas","BDCRMChannel","BDCRMChannelProduct","BDCRMCustomer","BDCRMCustomerAccount","BDCRMCustomerAccountFI","BDCRMCustomerChannel","BDCRMCustomerCoupon","BDCRMCustomerPerson","BDCRMCustomerpricediffCoupon","BDCRMCustomersMateriel","BDCRMCustomersMateriel_Log","BDCRMCustomersOrg","BDCRMCustomersOrgCredit","BDCRMCustomersSales","BDCRMCustomersSO","BDDMSAllocation","BDDMSAreas","BDDMSDealerMateriel","BDDMSDealerMaterielBatch","BDDMSDealers","BDDMSIntegral","BDDMSLogistics","BDEShopIndexGroup","BDFactory","BDFactoryPerson","BDFCCPayCondition","BDFCCVoucher","BDMESTechDeviceAffairUser","BDQCCheckPlanProduct","BDSRMSupplier","BDWMSClassify","BDWMSMateriel","BDWMSMaterielClassify","BDWMSMaterielFactory","BDWMSMaterielFactoryKeepFit","BDWMSMaterielImages","BDWMSMaterielPacking","BDWMSMaterielStockType","BDWMSMaterielUnit","BDWMSWareHouse","CRMCouponBlacklist","CRMCouponWhitelist","CRMMarketingActiChannel","CRMMarketingActiChannel_Log","CRMMarketingActiCustomer","CRMMarketingActiCustomer_Log","CRMMarketingActivities","CRMMarketingActivities_Log","CRMMarketingActivitiesUnitPrice","CRMMarketingActivitiesUnitPrice_Log","CRMSaleOrder","CRMSaleOrderDetail","CRMSaleOrderDetailForSale","CRMSaleOrderDiscount","CRMSaleOrderForSale","CRMSalesForecast","CRMZdmsBillList","CRMZdmsBillList_log","DMSFlGoodsOrderBarCode","DMSIntegralOrdeDetail","DMSIntegralOrder","DMSScrapOrderBarCode","DMSStatistics","DOCFramework","DOCFramParagraph","DOCLanguagePacks","DOCMenus","DOCTitle","EShopOrderSendExpress","EShopShopping","EShopShopping_Log","EShopShopping_Order","EShopShopping_Order_Log","FCCAccountStatement","FCCAccountStatementDetail","FCCInvoiceDN","FCCInvoiceDNDetail","FCCInvoiceNoteOrder_ZMKP","FCCInvoiceNoteOrder_ZMKP_Log","FCCInvoiceNoteOrderDetail_ZMKP","FCCInvoiceNoteOrderDetailForPDF_ZMKP","FCCInvoiceOrder","FCCInvoiceOrderSP","FCCMonthlyBills","FCCMonthlyBillsBalance","FCCMonthlyBillsPayment","FCCMonthlyBillsRecev","FCCRecePayVoucher","INV_IHEAD","INV_NOTY_SMS","INV_ZBAPI_DMS_SAP_JIANDN","INV_ZdmsBillList","KUNOsMain","KUNOsMain_PARAMS","KUNOsMain_TABLES","MESOrder","MESOrderDetail","MSNList","MSNListRecv","OMSDeliverNotice","OMSDeliverNoticeBarCode","OMSDeliverNoticeDetail","OMSDeliverNoticeExpress","QCBarcode","QCBarCode","QCExpirationDateSet","QCFlow","QCRecallConfirmBarcode","QCRecallConfirmDetail","QCRecallConfirmOrder","QCRecallList","QCRecallListDetail","QCRecallSendBarcode","QCRecallSendDetail","QCRecallSendOrder","sBDA_Color","sBDA_Color_Affair","sBDA_Statistics","sBDA_Where","sDataDictionary","sdebug","sDurgs","sExProcTime","sExRate","sGridMyReport","sIOT","sMap","sOrganization","sOrganizationAccount","spage_gather","spage_gather_detail","sRightsForFields","SRMPurchaseOrder","SRMPurchaseOrderDetail","SRoles","sSystemParameters","Susers","sVersion","sWorkflow","sWorkflowDetail","sWorkflowDetailButton","sWorkflowDetailFour","sWorkflowDetailRoles","sWorkflowDetailTree","sWorkflowKeyWords","sWorkflowKeyWordsULog","sWorkflowlog","sWorkflowMSNlog","sWorkflowRpermission","sWorkflowStatus","Tmp_DMSIntegralOrder","TMP_IT_LIPS","TMP_IT_LIPS_WareSpaceCode","TMP_TAB_DN_log","Tmp_WMSSalesOut","Tmp_WMSSalesOutBarCodeForScan","Tmp_WMSSalesOutBarCodeForScanFct","Tmp_WMSSalesOutBarCodeForScanOne","Tmp_WMSSalesOutBarCodeForScanThird","Tmp_WMSSalesOutBarCodeForScanTwo","Tmp_WMSSalesOutDetail","WMSAllocated","WMSAllocatedBarCode","WMSAllocatedDetail","WMSAllocatedNewBNLog","WMSAllocatedTotalLog","WMSInventoryOrder","WMSInventoryOrderBarCode","WMSInventoryOrderDetail","WMSRGIN","WMSRGINBarCode","WMSRGINDetail","WMSRGINNewBNLog","WMSRGINTotalLog","WMSSalesOut","WMSSalesOutBarCode","WMSSalesOutBarCodeForScanFct","WMSSalesOutBarCodeOne","WMSSalesOutBarCodeSalesEnd","WMSSalesOutBarCodeSalesEndRecv","WMSSalesOutBarCodeTwo","WMSSalesOutBarCodeTwoRecv","WMSSalesOutDetail","WMSSalesOutDetailOne","WMSSalesOutDetailSalesEnd","WMSSalesOutDetailTwo","WMSSalesOutInvoice","WMSSalesOutNewBNLog","WMSSalesOutNewBNLogOne","WMSSalesOutNewBNLogTwo","WMSSalesOutNewBNLogTwoRecv","WMSSalesOutOne","WMSSalesOutSalesEnd","WMSSalesOutST","WMSSalesOutSTBarCode","WMSSalesOutSTBarCodeRecv","WMSSalesOutSTDetail","WMSSalesOutSTNewBNLog","WMSSalesOutSTNewBNLogRecv","WMSSalesOutSTTotalLog","WMSSalesOutSTTotalLogRecv","WMSSalesOutTotalLog","WMSSalesOutTotalLogOne","WMSSalesOutTotalLogTwo","WMSSalesOutTotalLogTwoRecv","WMSSalesOutTwo","WMSStock","WMSStockBarCode","WMSStockBarCodeFrozenLog","WMSStockBarCodeOne","WMSStockBarCodeSalesEnd","WMSStockBarCodeST","WMSStockBarCodeTwo","WMSStockBatch","WMSStockBatchOne","WMSStockBatchST","WMSStockBatchTwo","WMSStockTotal","WMSStockTotalForSap","WMSStockTotalOne","WMSStockTotalST","WMSStockTotalTwo","WMSStockUnOrFreezLog","WMSTransWareSpace","ZBAPI_DMS_SAP_JIANBILLING_DATE"]
|
|
tables.forEach(tb => {
|
sql = sql.replace(new RegExp(`[^0-9a-z_]from\\s+${tb}[^0-9a-z_]`, 'ig'), (w) => w.replace(/from\s+/i, 'from @db@'))
|
})
|
|
// sql = this.handleFormat(sql)
|
|
return sql
|
}
|
|
handleFormat = (_sql) => {
|
let arr = []
|
_sql = _sql.replace(/@[0-9a-zA-Z_]+@/g, (word) => {
|
let uuid = Utils.getuuid()
|
arr.push({id: uuid, value: word})
|
return uuid
|
})
|
|
_sql = sqlFormatter.format(_sql.replace(/\s{2,}/g, ' '))
|
|
_sql = _sql.replace(/\$\s\*\s\//g, '$*/').replace(/\*\s\//g, '*/')
|
|
arr.forEach(item => {
|
_sql = _sql.replace(item.id, item.value)
|
})
|
|
_sql = _sql.replace(/,\n\s*/g, ',')
|
_sql = _sql.replace(/@db@\s+[a-zA-Z]/g, (w) => {
|
return w.replace(/\s+/g, '')
|
})
|
|
return _sql
|
}
|
|
copy = () => {
|
const { type, value } = this.state
|
|
if (!type || !value) return
|
|
if (type === 'mk_func') {
|
try {
|
navigator.clipboard.writeText(value)
|
message.success('复制成功。')
|
} catch (err) {
|
console.error('Failed to copy: ', err)
|
message.error('复制失败!')
|
}
|
return
|
}
|
|
let val = {copyType: type}
|
|
let vals = JSON.parse(value)
|
if (type === 'mk_setting') {
|
val.setting = vals
|
} else if (type === 'mk_searches') {
|
val.search = vals
|
} else if (type === 'mk_actions') {
|
val.action = vals
|
} else if (type === 'mk_forms') {
|
val.fields = vals
|
} else if (type === 'mk_fields') {
|
val.columns = vals
|
} else if (type === 'mk_cols') {
|
val.cols = vals
|
}
|
|
try {
|
navigator.clipboard.writeText(window.btoa(window.encodeURIComponent(JSON.stringify(val))))
|
message.success('复制成功。')
|
} catch (err) {
|
console.error('Failed to copy: ', err)
|
message.error('复制失败!')
|
}
|
}
|
|
render () {
|
const { textInput, value, type } = this.state
|
|
return (
|
<div className="mk-trans-wrap">
|
<div className="mk-trans-type">
|
<Button className={type === 'mk_setting' ? 'active' : ''} onClick={() => this.changeType('mk_setting')}>数据源</Button>
|
<Button className={type === 'mk_fields' ? 'active' : ''} onClick={() => this.changeType('mk_fields')}>字段集</Button>
|
<Button className={type === 'mk_cols' ? 'active' : ''} onClick={() => this.changeType('mk_cols')}>显示列</Button>
|
<Button className={type === 'mk_searches' ? 'active' : ''} onClick={() => this.changeType('mk_searches')}>搜索条件</Button>
|
<Button className={type === 'mk_actions' ? 'active' : ''} onClick={() => this.changeType('mk_actions')}>按钮</Button>
|
<Button className={type === 'mk_forms' ? 'active' : ''} onClick={() => this.changeType('mk_forms')}>表单</Button>
|
<Button className={type === 'mk_func' ? 'active' : ''} onClick={() => this.changeType('mk_func')}>存储过程</Button>
|
</div>
|
<div className="input-wrap">
|
<Button onClick={this.trans}>转换</Button>
|
<TextArea value={textInput} id="trans-input" autoSize={{minRows: 10, maxRows: 10}} onChange={this.changeVal}/>
|
</div>
|
<div className="result-wrap">
|
<Button onClick={this.copy}>复制</Button>
|
<div className="result">{value}</div>
|
</div>
|
</div>
|
)
|
}
|
}
|
|
export default MkTrans
|