New file |
| | |
| | | import React, { Component } from 'react' |
| | | import { Input, Button, message } from 'antd' |
| | | |
| | | 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 (!this.state.type) { |
| | | this.setState({type: type, value: null}) |
| | | } else { |
| | | this.setState({type: type, textInput: '', value: null}) |
| | | } |
| | | } |
| | | |
| | | 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 |
| | | } |
| | | |
| | | result = [] |
| | | |
| | | list.forEach(item => { |
| | | 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' |
| | | } |
| | | // options |
| | | // resourceType |
| | | // orderType |
| | | |
| | | result.push(cell) |
| | | }) |
| | | |
| | | result = JSON.stringify(result) |
| | | } else if (type === 'mk_actions') { |
| | | let list = JSON.parse(textInput) |
| | | |
| | | if (list.rows) { |
| | | list = list.rows |
| | | } |
| | | |
| | | result = [] |
| | | |
| | | list.forEach(item => { |
| | | if (item.IsButton !== '1') return |
| | | |
| | | 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 (/添加/.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 = 'requiredOnce' |
| | | cell.class = 'dgreen' |
| | | } |
| | | |
| | | if (item.Action === 'PopDlg') { |
| | | cell.OpenType = 'pop' |
| | | } |
| | | if (item.TableName) { |
| | | cell.sql = item.TableName |
| | | } |
| | | if (['pop', 'prompt', 'exec'].includes(cell.OpenType)) { |
| | | 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' |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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) { |
| | | tb += ` where ${data.AppendWhere.replace(/^\s*\(|\)\s*$/g, '')}` |
| | | } |
| | | |
| | | 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.reverse() |
| | | } |
| | | |
| | | 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 === '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.reverse() |
| | | } |
| | | |
| | | result = [] |
| | | |
| | | list.forEach(item => { |
| | | if (item.Hide === 'true') return |
| | | |
| | | let cell = { |
| | | uuid: Utils.getuuid(), |
| | | label: item.Label, |
| | | field: item.FieldName.toLowerCase(), |
| | | Hide: 'false', |
| | | Align: item.Align || 'left', |
| | | IsSort: item.IsSort || 'false', |
| | | type: 'text', |
| | | Width: 120 |
| | | } |
| | | |
| | | if (item.Type === 'text') { |
| | | cell.textFormat = 'none' |
| | | } else if (item.Type === 'number') { |
| | | cell.type = 'number' |
| | | cell.Width = 80 |
| | | cell.decimal = 0 |
| | | cell.format = 'none' |
| | | } |
| | | |
| | | result.push(cell) |
| | | }) |
| | | |
| | | result = JSON.stringify(result) |
| | | } else if (type === 'mk_forms') { |
| | | let list = JSON.parse(textInput) |
| | | |
| | | if (list.rows) { |
| | | list = list.rows |
| | | // list.reverse() |
| | | } |
| | | |
| | | result = [] |
| | | |
| | | list.forEach(item => { |
| | | let cell = { |
| | | uuid: Utils.getuuid(), |
| | | label: item.Label, |
| | | field: item.FieldName.toLowerCase(), |
| | | initval: item.DefaultVal || '', |
| | | 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.InputType === 'text') { |
| | | if (item.Validate && /required:\s?true/.test(item.Validate)) { |
| | | cell.required = 'true' |
| | | } else { |
| | | cell.required = 'false' |
| | | } |
| | | } else if (item.InputType === 'select') { |
| | | if (item.Validate && /required:\s?true/.test(item.Validate)) { |
| | | cell.required = 'true' |
| | | } else { |
| | | cell.required = 'false' |
| | | } |
| | | 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) { |
| | | cell.dataSource += ' where ' + item.WhereField.replace(/^\s*\(|\)\s*$/g, '') |
| | | } |
| | | } |
| | | |
| | | if (item.Multi === 'true') { |
| | | cell.type = 'multiselect' |
| | | } |
| | | } |
| | | |
| | | result.push(cell) |
| | | }) |
| | | |
| | | 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(/\n/, ' */\n') |
| | | return w |
| | | }) |
| | | // result = result.replace(/\n+/g, '\n') |
| | | } |
| | | |
| | | this.setState({value: result}) |
| | | } |
| | | |
| | | 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_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_fields' ? 'active' : ''} onClick={() => this.changeType('mk_fields')}>字段集</Button> |
| | | <Button className={type === 'mk_cols' ? 'active' : ''} onClick={() => this.changeType('mk_cols')}>显示列</Button> |
| | | <Button className={type === 'mk_setting' ? 'active' : ''} onClick={() => this.changeType('mk_setting')}>数据源</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} 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 |