From fdce913ce7b9d55c34a2abd7a94ee377a4869b9a Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 21 三月 2025 19:57:24 +0800 Subject: [PATCH] 2025-03-21 --- src/menu/components/share/pastecomponent/index.jsx | 35 +++ src/templates/sharecomponent/actioncomponent/index.jsx | 16 + src/views/transystem/index.scss | 38 ++++ src/menu/components/share/pasteforms/index.jsx | 6 src/views/transystem/index.jsx | 430 +++++++++++++++++++++++++++++++++++++++++++++++ src/router/index.js | 2 src/templates/sharecomponent/searchcomponent/index.jsx | 13 7 files changed, 528 insertions(+), 12 deletions(-) diff --git a/src/menu/components/share/pastecomponent/index.jsx b/src/menu/components/share/pastecomponent/index.jsx index 90944e9..4bb09c2 100644 --- a/src/menu/components/share/pastecomponent/index.jsx +++ b/src/menu/components/share/pastecomponent/index.jsx @@ -121,9 +121,44 @@ return item } + extra = (res) => { + let config = fromJS(this.props.config).toJS() + + if (res.copyType === 'mk_actions') { + config.action = res.action + this.props.updateConfig(config) + + setTimeout(() => { + MKEmitter.emit('revertBtn', config.uuid) + }, 30) + } else if (res.copyType === 'mk_searches') { + config.search = res.search + this.props.updateConfig(config) + + setTimeout(() => { + MKEmitter.emit('revert', config.uuid, 'search') + }, 30) + } else if (res.copyType === 'mk_fields') { + config.columns = res.columns + this.props.updateConfig(config) + } else if (res.copyType === 'mk_cols') { + config.cols = res.cols + this.props.updateConfig(config) + } else if (res.copyType === 'mk_setting') { + config.setting = res.setting + this.props.updateConfig(config) + } + console.log(config) + this.setState({visible: false}) + } + pasteSubmit = () => { const { options } = this.props this.pasteFormRef.handleConfirm().then(res => { + if (/^mk_/.test(res.copyType)) { // dms-trans + this.extra(res) + return + } if (!options.includes(res.copyType)) { notification.warning({ top: 92, message: '閰嶇疆淇℃伅鏍煎紡閿欒锛�', duration: 5 }) return diff --git a/src/menu/components/share/pasteforms/index.jsx b/src/menu/components/share/pasteforms/index.jsx index 180304b..dc18c89 100644 --- a/src/menu/components/share/pasteforms/index.jsx +++ b/src/menu/components/share/pasteforms/index.jsx @@ -26,6 +26,12 @@ const { config } = this.props this.pasteFormRef.handleConfirm().then(res => { + if (res.copyType === 'mk_forms') { // dms-trans + this.props.update(res.fields, res) + + this.setState({visible: false}) + return + } if (res.copyType === 'search' && ['text', 'select', 'multiselect', 'link', 'checkcard', 'date', 'datemonth'].includes(res.type)) { res.copyType = 'form' } diff --git a/src/router/index.js b/src/router/index.js index a1bc174..9d7cd9f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -27,6 +27,7 @@ // const SystemCheck = asyncLoadComponent(() => import('@/views/syscheck')) const MkIframe = asyncLoadComponent(() => import('@/views/mkiframe')) // const MkAi = asyncLoadComponent(() => import('@/views/mkai')) +const TranSystem = asyncLoadComponent(() => import('@/views/transystem')) const routers = [ {path: '/login', name: 'login', component: Login}, @@ -56,6 +57,7 @@ {path: '/view/:menuId', name: 'iframe', component: MkIframe}, {path: '/view/:menuId/:bid', name: 'iframe', component: MkIframe}, {path: '/interface', name: 'interface', component: Interface}, + {path: '/trans', name: 'trans', component: TranSystem}, // {path: '/ai', name: 'ai', component: MkAi}, // {path: '/syscheck', name: 'syscheck', component: SystemCheck} ] diff --git a/src/templates/sharecomponent/actioncomponent/index.jsx b/src/templates/sharecomponent/actioncomponent/index.jsx index 62be8b1..ded5aa6 100644 --- a/src/templates/sharecomponent/actioncomponent/index.jsx +++ b/src/templates/sharecomponent/actioncomponent/index.jsx @@ -53,15 +53,17 @@ componentDidMount () { this.getBillPrintTemp() - // MKEmitter.addListener('revert', this.revert) + MKEmitter.addListener('revert', this.revert) MKEmitter.addListener('pasteButton', this.pasteButton) } + // dms-trans + revert = (id, type) => { + if (id !== this.props.config.uuid || type !== 'action') return - // revert = () => { - // this.setState({ - // actionlist: fromJS(this.props.config.action).toJS() - // }) - // } + this.setState({ + actionlist: fromJS(this.props.config.action).toJS() + }) + } pasteButton = (MenuId, btn) => { const { config } = this.props @@ -384,7 +386,7 @@ this.setState = () => { return } - // MKEmitter.removeListener('revert', this.revert) + MKEmitter.removeListener('revert', this.revert) MKEmitter.removeListener('pasteButton', this.pasteButton) } diff --git a/src/templates/sharecomponent/searchcomponent/index.jsx b/src/templates/sharecomponent/searchcomponent/index.jsx index 16dcefa..fb583c6 100644 --- a/src/templates/sharecomponent/searchcomponent/index.jsx +++ b/src/templates/sharecomponent/searchcomponent/index.jsx @@ -42,12 +42,15 @@ componentDidMount () { MKEmitter.addListener('plusSearch', this.plusSearch) - // MKEmitter.addListener('revert', this.revert) + MKEmitter.addListener('revert', this.revert) } - // revert = () => { - // this.setState({searchlist: fromJS(this.props.config.search).toJS()}) - // } + // dms-trans + revert = (id, type) => { + if (id !== this.props.config.uuid || type !== 'search') return + + this.setState({searchlist: fromJS(this.props.config.search).toJS()}) + } plusSearch = (MenuId, item, type) => { const { config } = this.props @@ -319,7 +322,7 @@ this.setState = () => { return } - // MKEmitter.removeListener('revert', this.revert) + MKEmitter.removeListener('revert', this.revert) MKEmitter.removeListener('plusSearch', this.plusSearch) } diff --git a/src/views/transystem/index.jsx b/src/views/transystem/index.jsx new file mode 100644 index 0000000..66593ba --- /dev/null +++ b/src/views/transystem/index.jsx @@ -0,0 +1,430 @@ +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 \ No newline at end of file diff --git a/src/views/transystem/index.scss b/src/views/transystem/index.scss new file mode 100644 index 0000000..246c0c3 --- /dev/null +++ b/src/views/transystem/index.scss @@ -0,0 +1,38 @@ +.mk-trans-wrap { + padding: 30px 10vw 0px; + + .mk-trans-type { + margin-bottom: 20px; + .ant-btn { + margin-right: 20px; + } + .ant-btn.active { + margin-right: 20px; + color: #ffffff; + border: 1px solid #1890ff; + background-color: #1890ff; + } + } + .input-wrap { + text-align: right; + margin-bottom: 20px; + .ant-btn { + margin-bottom: 10px; + } + .ant-input { + text-align: left; + } + } + .result-wrap { + text-align: right; + .ant-btn { + margin-bottom: 10px; + } + .result { + text-align: left; + border: 1px solid #1890ff; + min-height: 200px; + padding: 5px; + } + } +} -- Gitblit v1.8.0