From 31ec63f0419895876cbaba99637a884a32d33d0d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 01 九月 2021 10:31:45 +0800 Subject: [PATCH] 2021-09-01 --- src/templates/formtabconfig/index.jsx | 238 ++++++++++++++++++++++++---------------------------------- 1 files changed, 99 insertions(+), 139 deletions(-) diff --git a/src/templates/formtabconfig/index.jsx b/src/templates/formtabconfig/index.jsx index 5571f51..e2aacac 100644 --- a/src/templates/formtabconfig/index.jsx +++ b/src/templates/formtabconfig/index.jsx @@ -10,42 +10,42 @@ import Api from '@/api' import zhCN from '@/locales/zh-CN/model.js' import enUS from '@/locales/en-US/model.js' -import Utils from '@/utils/utils.js' +import Utils, { FuncUtils } from '@/utils/utils.js' import { getModalForm, getActionForm } from '@/templates/zshare/formconfig' import { queryTableSql } from '@/utils/option.js' import TabsComponent from '@/templates/sharecomponent/tabscomponent' -import ModalForm from '@/templates/zshare/modalform' import PasteForm from '@/templates/zshare/pasteform' import ActionForm from './actionform' import SettingForm from './settingform' import DragElement from './dragelement' import GroupForm from './groupform' import EditCard from '@/templates/zshare/editcard' -import VerifyCard from '@/templates/zshare/verifycard' + import MenuForm from '@/templates/zshare/menuform' import SourceElement from '@/templates/zshare/dragsource' -import CreateFunc from '@/templates/zshare/createfunc' +import asyncComponent from '@/utils/asyncComponent' import Source from './source' import './index.scss' const { Panel } = Collapse const { Option } = Select const { confirm } = Modal -const CommonDict = (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS +const ModalForm = asyncComponent(() => import('@/templates/zshare/modalform')) +const CreateFunc = asyncComponent(() => import('@/templates/zshare/createfunc')) +const VerifyCard = asyncComponent(() => import('@/templates/zshare/verifycard')) class ComTableConfig extends Component { static propTpyes = { menu: PropTypes.any, - optionLibs: PropTypes.any, btnTab: PropTypes.object, config: PropTypes.any, handleView: PropTypes.func } state = { - dict: CommonDict, // 瀛楀吀 + dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, // 瀛楀吀 config: null, // 椤甸潰閰嶇疆 modaltype: '', // 妯℃�佹绫诲瀷锛屾帶鍒舵ā鎬佹鏄剧ず tableVisible: false, // 鏁版嵁琛ㄥ瓧娈垫ā鎬佹 @@ -67,10 +67,10 @@ profileVisible: false, // 楠岃瘉淇℃伅妯℃�佹 editgroup: null, // 褰撳墠缂栬緫缁� groupVisible: false, // 缂栬緫缁勬ā鎬佹 - optionLibs: null, // 鑷畾涔変笅鎷夐�夐」搴� activeKey: '0', // 榛樿灞曞紑鍩烘湰淇℃伅 pasteVisible: false, // 绮樿创妯℃�佹 - sqlVerifing: false // sql楠岃瘉 + sqlVerifing: false, // sql楠岃瘉 + openEdition: '' // 缂栬緫鐗堟湰鏍囪锛岄槻姝㈠浜烘搷浣� } /** @@ -79,7 +79,7 @@ * 2銆佽缃搷浣滅被鍨嬨�佸師濮嬭彍鍗曚俊鎭紙姣忔淇濆瓨鍚庨噸缃級銆佸凡浣跨敤琛ㄥ強鍩烘湰淇℃伅琛ㄥ崟 */ UNSAFE_componentWillMount () { - const { menu, btnTab, config, optionLibs } = this.props + const { menu, btnTab, config } = this.props let _config = '' let columns = [] @@ -103,24 +103,6 @@ if (menu && menu.LongParam && menu.LongParam.setting) { _config.setting.primaryKey = menu.LongParam.setting.primaryKey } - - _config.groups.forEach(group => { - group.sublist.forEach(item => { - if ( - (item.type === 'select' || item.type === 'multiselect' || item.type === 'link') && - item.resourceType === '0' && - item.options && item.options.length > 0 - ) { - optionLibs.set(btnTab.uuid + item.uuid, { - uuid: btnTab.uuid + item.uuid, - label: item.label, - parname: btnTab.label, - type: 'Modal', - options: item.options - }) - } - }) - }) } if (!_config.tabgroups) { @@ -145,10 +127,19 @@ columns = menu.LongParam.columns } + // 閰嶇疆榛樿鍊硷紝鍏煎 + _config.Template = 'FormTab' + _config.action = _config.action.map(item => { + if (item.intertype === 'inner' && !item.innerFunc) { + item.intertype = 'system' + } + return item + }) + this.setState({ config: _config, activeKey: btnTab.activeKey || '0', - optionLibs: optionLibs, + openEdition: btnTab.open_edition || '', columns: columns, originMenu: JSON.parse(JSON.stringify(_config)), selectedTables: _config.tables, @@ -156,7 +147,7 @@ { type: 'text', key: 'menuName', - label: this.state.dict['header.menu.menuName'], + label: this.state.dict['model.menu'] + this.state.dict['model.name'], initVal: menu.MenuName, readonly: true }, @@ -186,8 +177,10 @@ } param.LText = Utils.formatOptions(param.LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) + + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 浜戠鏁版嵁楠岃瘉 Api.getSystemConfig(param).then(res => { if (res.status) { @@ -348,7 +341,6 @@ let _tabview = menu ? menu.LongParam.Template : '' let param = { editMenu: menu, - optionLibs: this.state.optionLibs, editTab: null, tabConfig: null, editSubTab: null, @@ -435,6 +427,7 @@ const { menu } = this.props const { config } = this.state let _inputfields = [] + let _tabfields = [] let _linkableFields = [] let _linksupFields = [{ value: '', @@ -444,12 +437,12 @@ // 璁剧疆涓嬫媺鑿滃崟鍙叧鑱斿瓧娈� config.groups.forEach(group => { - let sublist = group.sublist.filter(item => item.type === 'text' || item.type === 'number') - _inputfields = [..._inputfields, ...sublist] - - let suplist = group.sublist.filter(item => item.type === 'select' || item.type === 'link') - _formfields = [..._formfields, ...suplist] + _formfields = [..._formfields, ...group.sublist] }) + + _inputfields = _formfields.filter(item => item.type === 'text' || item.type === 'number' || item.type === 'textarea' || item.type === 'color') + _tabfields = _formfields.filter(item => card.field !== item.field && item.hidden !== 'true' && ['text', 'number', 'select', 'link'].includes(item.type)) + _tabfields.unshift({field: '', text: '鍘熻〃鍗�'}) if (card.linkSubField && card.linkSubField.length > 0) { let fields = _inputfields.map(item => item.field) @@ -460,6 +453,7 @@ uniq.set(card.field, true) _formfields.forEach(item => { + if (item.type !== 'select' && item.type !== 'link') return if (item.field && !uniq.has(item.field)) { uniq.set(item.field, true) @@ -487,35 +481,39 @@ }) } - let roleList = [] - if (this.props.sysRoles && this.props.sysRoles.length > 0) { - roleList = this.props.sysRoles.map(role => { - return { - uuid: role.uuid, - field: role.value, - label: role.text - } - }) - } - this.setState({ modaltype: 'search', card: card, - formlist: getModalForm(card, _inputfields, _linkableFields, _linksupFields, false, roleList) + formlist: getModalForm(card, _inputfields, _tabfields, _linkableFields, _linksupFields, false).map(item => { + if (item.key === 'type') { + item.options = item.options.filter(option => !['switch', 'checkbox', 'radio', 'checkcard', 'hint'].includes(option.value)) + } + return item + }) }) } handleAction = (card) => { - let ableField = this.props.permFuncField.join(', ') + let usefulFields = sessionStorage.getItem('permFuncField') + if (usefulFields) { + try { + usefulFields = JSON.parse(usefulFields) + } catch (e) { + usefulFields = [] + } + } else { + usefulFields = [] + } + + let ableField = usefulFields.join(', ') let functip = <div> <p style={{marginBottom: '5px'}}>{this.state.dict['model.tooltip.func.innerface'].replace('@ableField', ableField)}</p> - <p>{this.state.dict['model.tooltip.func.outface']}</p> </div> this.setState({ modaltype: 'actionEdit', card: card, - formlist: getActionForm(card, functip, this.state.config, this.props.permFuncField) + formlist: getActionForm(card, functip, this.state.config, usefulFields) }) } @@ -527,8 +525,7 @@ * 3銆佹坊鍔犳垨缂栬緫鍒楋紝淇濆瓨鏃讹紝濡傛寜閽綅缃缃负琛ㄦ牸锛屽垯淇敼鎿嶄綔鍒楁樉绀虹姸鎬� */ handleSubmit = () => { - const { btnTab } = this.props - const { config, modaltype, optionLibs, card } = this.state + const { config, modaltype, card } = this.state if (modaltype === 'search') { this.modalFormRef.handleConfirm().then(res => { @@ -541,19 +538,6 @@ duration: 5 }) return - } - if ( // 鏇存柊涓嬫媺瀛楀吀 - (res.type === 'select' || res.type === 'multiselect' || res.type === 'link') && - res.resourceType === '0' && - res.options && res.options.length > 0 - ) { - optionLibs.set(btnTab.uuid + res.uuid, { - uuid: btnTab.uuid + res.uuid, - label: res.label, - parname: btnTab.label, - type: 'Modal', - options: res.options - }) } let _groups = null @@ -629,11 +613,15 @@ let param = { func: 's_debug_sql', + exec_type: 'y', LText: res.dataSource } + + param.LText = param.LText.replace(/@\$|\$@/ig, '') + param.LText = Utils.formatOptions(param.LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' - param.secretkey = Utils.encrypt(param.LText, param.timestamp) + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + param.secretkey = Utils.encrypt('', param.timestamp) if (window.GLOB.mainSystemApi && res.database === 'sso') { param.rduri = window.GLOB.mainSystemApi @@ -644,7 +632,6 @@ this.setState({ sqlVerifing: false, config: {..._config, groups: _groups}, - optionLibs: optionLibs, modaltype: '' }) } else { @@ -658,7 +645,6 @@ } else { this.setState({ config: {..._config, groups: _groups}, - optionLibs: optionLibs, modaltype: '' }) } @@ -746,30 +732,10 @@ menuNo: menu.MenuNo } - newLText = Utils.formatOptions(Utils.getfunc(_param, btn, menu, _config)) - DelText = Utils.formatOptions(Utils.dropfunc(_param.funcName)) + newLText = Utils.formatOptions(FuncUtils.getfunc(_param, btn, menu, _config)) + DelText = Utils.formatOptions(FuncUtils.dropfunc(_param.funcName)) - this.refs.btnCreatFunc.exec(btn.innerFunc, newLText, DelText).then(result => { - if (result !== 'success') return - - let isupdate = false - _config.action = _config.action.map(item => { - if (item.uuid === btn.uuid) { - isupdate = true - return btn - } else { - return item - } - }) - - if (!isupdate) { // 鎿嶄綔涓嶆槸淇敼锛屾坊鍔犲厓绱犺嚦鍒楄〃 - _config.action.push(btn) - } - - this.setState({ - config: _config - }) - }) + this.refs.btnCreatFunc.exec(btn.innerFunc, newLText, DelText) }) } @@ -799,15 +765,15 @@ } param.LText = Utils.formatOptions(param.LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) Api.getLocalConfig(param) } let _config = {...config, setting: setting} - let newLText = Utils.formatOptions(Utils.getTableFunc(setting, menu, _config)) // 鍒涘缓瀛樺偍杩囩▼sql - let DelText = Utils.formatOptions(Utils.dropfunc(setting.innerFunc)) // 鍒犻櫎瀛樺偍杩囩▼sql + let newLText = Utils.formatOptions(FuncUtils.getTableFunc(setting, menu, _config)) // 鍒涘缓瀛樺偍杩囩▼sql + let DelText = Utils.formatOptions(FuncUtils.dropfunc(setting.innerFunc)) // 鍒犻櫎瀛樺偍杩囩▼sql this.refs.tableCreatFunc.exec(setting.innerFunc, newLText, DelText).then(result => { if (result === 'success') { @@ -823,8 +789,6 @@ let _this = this confirm({ content: `纭畾鍒犻櫎<<${element.card.label}>>鍚楋紵`, - okText: this.state.dict['model.confirm'], - cancelText: this.state.dict['header.cancel'], onOk() { let _config = JSON.parse(JSON.stringify(_this.state.config)) let _delActions = _this.state.delActions @@ -893,7 +857,7 @@ */ submitConfig = () => { const { menu, btnTab } = this.props - const { delActions } = this.state + const { delActions, openEdition } = this.state let config = JSON.parse(JSON.stringify(this.state.config)) @@ -902,9 +866,7 @@ if (config.groups[0] && config.groups[0].sublist[0] && config.groups[0].sublist[0].origin) { config.groups[0].sublist = config.groups[0].sublist.filter(item => !item.origin) } - if (config.tabs[0] && config.tabs[0].origin) { - config.tabs = config.tabs.filter(item => !item.origin) - } + config.tabgroups[0].sublist = config.tabgroups[0].sublist.filter(item => !item.origin) } let btnNames = config.action.map(item => item.label) @@ -945,7 +907,7 @@ if (_ismutil && group.sublist.length === 0) { _config.enabled = false } - let arr = group.sublist.filter(item => item.field.toLowerCase() === _primary) + let arr = group.sublist.filter(item => item.field && item.field.toLowerCase() === _primary) if (arr.length > 0) { _config.enabled = false @@ -1086,7 +1048,7 @@ btnParam.LText = btnParam.LText.join(' union all ') btnParam.LText = Utils.formatOptions(btnParam.LText) - btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp) let tabParam = { // 娣诲姞鑿滃崟tab椤� @@ -1107,7 +1069,7 @@ tabParam.LText = Utils.formatOptions(_LText) - tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') tabParam.secretkey = Utils.encrypt(tabParam.LText, tabParam.timestamp) let param = { @@ -1119,6 +1081,10 @@ MenuName: btnTab.label, PageParam: JSON.stringify({Template: 'FormTab'}), LongParam: _LongParam + } + + if (openEdition) { + param.open_edition = openEdition } // 鏈夋寜閽垨鏍囩鍒犻櫎鏃讹紝鍏堣繘琛屽垹闄ゆ搷浣� @@ -1171,6 +1137,7 @@ Api.getSystemConfig(param).then(response => { if (response.status) { this.setState({ + openEdition: response.open_edition || '', config: _config, originMenu: _config }) @@ -1193,7 +1160,7 @@ }, () => { notification.warning({ top: 92, - message: this.state.dict['header.menu.basemsg'], + message: this.state.dict['model.menu.basemsg'], duration: 5 }) }) @@ -1279,8 +1246,6 @@ if (config.isAdd) { confirm({ content: '鎸夐挳閰嶇疆灏氭湭鎻愪氦锛岀‘瀹氭斁寮冧繚瀛樺悧锛�', - okText: this.state.dict['model.confirm'], - cancelText: this.state.dict['header.cancel'], onOk() { _this.handleViewBack() }, @@ -1492,7 +1457,7 @@ } param.LText = Utils.formatOptions(param.LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) Api.getLocalConfig(param) @@ -1505,12 +1470,15 @@ let param = { func: 's_debug_sql', + exec_type: 'y', LText: res.dataresource } + param.LText = param.LText.replace(/@\$|\$@/ig, '') + param.LText = Utils.formatOptions(param.LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' - param.secretkey = Utils.encrypt(param.LText, param.timestamp) + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + param.secretkey = Utils.encrypt('', param.timestamp) Api.getLocalConfig(param).then(result => { if (result.status) { @@ -1541,7 +1509,7 @@ */ setSubConfig = (btn) => { const {menu, btnTab} = this.props - const { config, originMenu, activeKey } = this.state + const { config, originMenu, activeKey, openEdition } = this.state if (config.isAdd) { notification.warning({ @@ -1564,12 +1532,11 @@ loading: true }) - // 淇濆瓨褰撳墠鎵撳紑椤电 - btnTab.activeKey = activeKey + btnTab.activeKey = activeKey // 淇濆瓨褰撳墠鎵撳紑椤电 + btnTab.open_edition = openEdition // 鏇存柊鐗堟湰鍙� let param = { editMenu: menu, - optionLibs: this.state.optionLibs, editTab: btn, tabConfig: null, editSubTab: null, @@ -1601,6 +1568,10 @@ if (_LongParam && param.tabview === 'SubTable' && _LongParam.Template === 'SubTable') { param.subConfig = _LongParam + } + + if (param.editTab) { + param.editTab.open_edition = res.open_edition || '' } this.props.handleView(param) @@ -1650,7 +1621,7 @@ let primaryrepeat = false config.groups.forEach(group => { - let arr = group.sublist.filter(item => item.field.toLowerCase() === _primary) + let arr = group.sublist.filter(item => item.field && item.field.toLowerCase() === _primary) if (arr.length > 0) { primaryrepeat = true @@ -1720,8 +1691,6 @@ confirm({ content: `纭畾鍒犻櫎鍒嗙粍<<${group.label}>>鍚楋紵`, - okText: this.state.dict['model.confirm'], - cancelText: this.state.dict['header.cancel'], onOk() { let groups = config.groups.filter(item => !(item.uuid === group.uuid)) groups = groups.map(item => { @@ -1929,12 +1898,11 @@ } bordered={false} extra={ <div> <Switch className="big" checkedChildren="鍚�" unCheckedChildren="鍋�" checked={this.state.config.enabled} onChange={this.onEnabledChange} /> - <Button type="primary" onClick={this.submitConfig} loading={this.state.menuloading}>{this.state.dict['header.save']}</Button> - <Button onClick={this.cancelConfig}>{this.state.dict['header.return']}</Button> + <Button type="primary" onClick={this.submitConfig} loading={this.state.menuloading}>{this.state.dict['model.save']}</Button> + <Button onClick={this.cancelConfig}>{this.state.dict['model.back']}</Button> </div> } style={{ width: '100%' }}> <Icon type="setting" onClick={this.changeSetting} /> - {/* <Icon type="snippets" title={this.state.dict['header.form.paste']} onClick={() => {this.setState({pasteVisible: true})}} /> */} <Tooltip placement="bottomLeft" overlayClassName="middle" title="鍦ㄥ乏渚у伐鍏锋爮銆婃悳绱€�嬩腑锛岄�夋嫨瀵瑰簲鎼滅储妗嗘嫋鑷虫澶勬坊鍔狅紱鎴栫偣鍑绘寜閽�婃坊鍔犳悳绱㈡潯浠躲�嬫壒閲忔坊鍔狅紝閫夋嫨鎵归噺娣诲姞鏃讹紝闇�鎻愬墠閫夋嫨浣跨敤琛ㄣ��"> <Icon type="question-circle" /> </Tooltip> @@ -1989,7 +1957,6 @@ </div> {/* 鏍囩缁� */} <TabsComponent - type="formtab" config={config} tabs={this.state.tabviews} setSubConfig={(item) => this.setSubConfig(item, 'tab')} @@ -2014,7 +1981,6 @@ card={this.state.card} formlist={this.state.formlist} inputSubmit={this.handleSubmit} - optionLibs={this.state.optionLibs} wrappedComponentRef={(inst) => this.modalFormRef = inst} /> </Modal> @@ -2028,7 +1994,7 @@ footer={[ this.state.card && this.state.card.btnType !== 'cancel' ? <CreateFunc key="create" dict={this.state.dict} ref="btnCreatFunc" trigger={this.creatFunc}/> : null, - <Button key="cancel" onClick={this.editModalCancel}>{this.state.dict['header.cancel']}</Button>, + <Button key="cancel" onClick={this.editModalCancel}>{this.state.dict['model.cancel']}</Button>, <Button key="confirm" type="primary" onClick={this.handleSubmit}>{this.state.dict['model.confirm']}</Button> ]} destroyOnClose @@ -2049,8 +2015,7 @@ visible={this.state.tableVisible} width={'65vw'} maskClosable={false} - style={{minWidth: '900px', maxWidth: '1200px'}} - cancelText={this.state.dict['header.close']} + cancelText={this.state.dict['model.close']} onOk={this.addFieldSubmit} onCancel={() => { // 鍙栨秷娣诲姞 this.setState({ @@ -2073,8 +2038,7 @@ visible={this.state.profileVisible} width={'75vw'} maskClosable={false} - style={{minWidth: '900px', maxWidth: '1200px'}} - okText={this.state.dict['header.submit']} + okText={this.state.dict['model.submit']} onOk={this.verifySubmit} onCancel={() => { this.setState({ profileVisible: false }) }} destroyOnClose @@ -2101,7 +2065,7 @@ }} footer={[ <CreateFunc key="create" dict={this.state.dict} ref="tableCreatFunc" trigger={this.tableCreatFunc}/>, - <Button key="cancel" onClick={() => { this.setState({ settingVisible: false }) }}>{this.state.dict['header.cancel']}</Button>, + <Button key="cancel" onClick={() => { this.setState({ settingVisible: false }) }}>{this.state.dict['model.cancel']}</Button>, <Button key="confirm" type="primary" loading={this.state.sqlVerifing} onClick={this.settingSave}>{this.state.dict['model.confirm']}</Button> ]} destroyOnClose @@ -2111,7 +2075,6 @@ menu={this.props.menu} config={this.state.config} inputSubmit={this.settingSave} - usefulFields={this.props.permFuncField} wrappedComponentRef={(inst) => this.settingRef = inst} /> </Modal> @@ -2122,9 +2085,9 @@ visible={this.state.closeVisible} onCancel={() => { this.setState({closeVisible: false}) }} footer={[ - <Button key="save" className="mk-btn mk-green" loading={this.state.menucloseloading} onClick={this.submitConfig}>{this.state.dict['header.save']}</Button>, - <Button key="confirm" className="mk-btn mk-yellow" onClick={this.handleViewBack}>{this.state.dict['header.notsave']}</Button>, - <Button key="cancel" onClick={() => { this.setState({closeVisible: false}) }}>{this.state.dict['header.cancel']}</Button> + <Button key="save" className="mk-btn mk-green" loading={this.state.menucloseloading} onClick={this.submitConfig}>{this.state.dict['model.save']}</Button>, + <Button key="confirm" className="mk-btn mk-yellow" onClick={this.handleViewBack}>{this.state.dict['model.notsave']}</Button>, + <Button key="cancel" onClick={() => { this.setState({closeVisible: false}) }}>{this.state.dict['model.cancel']}</Button> ]} destroyOnClose > @@ -2168,11 +2131,8 @@ } } -const mapStateToProps = (state) => { - return { - sysRoles: state.sysRoles, - permFuncField: state.permFuncField - } +const mapStateToProps = () => { + return {} } const mapDispatchToProps = () => { -- Gitblit v1.8.0