From abf582fbe18c20ab4f01458a9209878c77fea9c0 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 15 一月 2020 18:59:52 +0800 Subject: [PATCH] 2020-01-15 --- src/templates/comtableconfig/index.jsx | 299 ++++++++++++++++++++++++++++++++++------------------------- 1 files changed, 171 insertions(+), 128 deletions(-) diff --git a/src/templates/comtableconfig/index.jsx b/src/templates/comtableconfig/index.jsx index feacc6b..5fcbc29 100644 --- a/src/templates/comtableconfig/index.jsx +++ b/src/templates/comtableconfig/index.jsx @@ -47,8 +47,6 @@ state = { dict: CommonDict, // 瀛楀吀 config: null, // 椤甸潰閰嶇疆 - visible: false, // 鎼滅储鏉′欢銆佹寜閽�佹樉绀哄垪锛屾ā鎬佹鏄剧ず鎺у埗 - modalTitle: '', // 妯℃�佹鐨勬爣棰� tableVisible: false, // 鏁版嵁琛ㄥ瓧娈垫ā鎬佹 addType: '', // 娣诲姞绫诲瀷-鎼滅储鏉′欢鎴栨樉绀哄垪 tableColumns: [], // 琛ㄦ牸鏄剧ず鍒� @@ -67,7 +65,7 @@ originMenu: null, // 鍘熷鑿滃崟 originActions: null, // 鍘熷鎸夐挳淇℃伅锛屼娇鐢ㄥ凡鏈夌敤鎴锋ā鏉� delActions: [], // 鍒犻櫎鎸夐挳鍒楄〃 - copyActions: [], // 鍒犻櫎鎸夐挳鍒楄〃 + copyActions: [], // 澶嶅埗鎸夐挳缁� funcLoading: false, // 瀛樺偍杩囩▼鍒涘缓涓� showColumnName: false, // 鏄剧ず鍒楀瓧娈靛悕鎺у埗 tabviews: [], // 鎵�鏈夋爣绛鹃〉 @@ -349,10 +347,13 @@ this.setState({ modaltype: type === 'copy' ? 'actionCopy' : 'actionEdit', card: card, - formlist: getActionForm(card, functip, this.state.config, this.props.permFuncField) + formlist: getActionForm(card, functip, this.state.config, this.props.permFuncField, 'main') }) } + /** + * @description 鏄剧ず鍒椾笌鍚堝苟鍒楃紪杈戯紝鑾峰彇琛ㄥ崟淇℃伅 + */ handleColumn = (card) => { if (card.type !== 'colspan') { this.setState({ @@ -368,6 +369,9 @@ } } + /** + * @description 鏍囩缂栬緫锛岀瓫閫夊彲閫夌殑涓嬬骇鏍囩涓庡凡鍏宠仈鐨勪笅绾ф爣绛� + */ handleTab = (card) => { const { config } = this.state @@ -386,12 +390,12 @@ let _tabMap = new Map() let _usedTabMap = new Map() - config[nextTabId].forEach(tab => { // 涓嬬骇鎵�鏈夌殑鏍囩 + config[nextTabId].forEach(tab => { // 涓嬬骇鎵�鏈夌殑鏍囩 menus.push(tab) _tabMap.set(tab.uuid, true) }) - config[card.groupId].forEach(tab => { // 鍚岀骇鏍囩宸查�夌殑涓嬬骇鏍囩 + config[card.groupId].forEach(tab => { // 鍚岀骇鏍囩宸查�夌殑涓嬬骇鏍囩 if (tab.uuid === card.uuid) return tab.subtabs.forEach(subtab => { @@ -403,7 +407,7 @@ _usedTabMap.set(subtab, true) }) - subtabs = subtabs.filter(tab => _tabMap.has(tab.uuid) && !_usedTabMap.has(tab.uuid)) + subtabs = subtabs.filter(tabId => _tabMap.has(tabId) && !_usedTabMap.has(tabId)) menus = menus.filter(tab => !_usedTabMap.has(tab.uuid)) } else { subtabs = [] @@ -474,6 +478,9 @@ }) } + /** + * @description 鎿嶄綔鍒楃紪杈� + */ handleGridBtn = () => { this.setState({ modaltype: 'gridbtn' @@ -484,7 +491,7 @@ * @description 鎼滅储銆佹寜閽�佹樉绀哄垪淇敼鍚庢彁浜や繚瀛� * 1銆佹悳绱㈡潯浠朵繚瀛� * 2銆佹寜閽寘鎷甯哥紪杈戝拰澶嶅埗锛屽鍒舵椂,鏈熬娣诲姞,濡傛寜閽负琛ㄥ崟锛堜繚瀛樿嚦鏁版嵁搴擄級锛屽鍒舵寜閽甶d瀛樹簬澶嶅埗鍒楄〃锛堢偣鍑讳笉淇濆瓨鏃跺垹闄わ級 - * 3銆佹坊鍔犳垨缂栬緫鍒楋紝淇濆瓨鏃讹紝濡傛寜閽綅缃缃负琛ㄦ牸锛屽垯淇敼鎿嶄綔鍒楁樉绀虹姸鎬� + * 3銆佸鎸夐挳浣嶇疆璁剧疆涓鸿〃鏍硷紝鍒欎慨鏀规搷浣滃垪鏄剧ず鐘舵�� */ handleSubmit = () => { const { menu } = this.props @@ -557,7 +564,7 @@ // 鍒ゆ柇鏄惁瀛樺湪鎿嶄綔鍒� let _hasGridbtn = _action.filter(act => act.position === 'grid').length > 0 - let _gridBtn = {...config.gridBtn} + let _gridBtn = config.gridBtn if (_gridBtn) { _gridBtn.display = _hasGridbtn @@ -605,20 +612,14 @@ }) } else if (modaltype === 'tabs') { this.tabsFormRef.handleConfirm().then(res => { - let isupdate = false let _tabgroup = config[res.values.groupId].map(item => { if (item.uuid === res.values.uuid) { - isupdate = true return res.values } else { return item } }) _tabgroup = _tabgroup.filter(item => !item.origin) - - if (!isupdate) { // 鎿嶄綔涓嶆槸淇敼锛屾坊鍔犲厓绱犺嚦鍒楄〃 - _tabgroup.push(res.values) - } this.setState({ config: {...config, [res.values.groupId]: _tabgroup}, @@ -628,6 +629,9 @@ } } + /** + * @description 鍙栨秷淇濆瓨锛屽鏋滃厓绱犱负鏂版坊鍏冪礌锛屽垯浠庡簭鍒椾腑鍒犻櫎 + */ editModalCancel = () => { const { config, card, modaltype } = this.state @@ -642,6 +646,9 @@ } else if (modaltype === 'columns' || modaltype === 'colspan') { let _columns = config.columns.filter(item => item.uuid !== card.uuid) _config = {...config, columns: _columns} + } else if (modaltype === 'tabs') { + let _tabgroup = config[card.groupId].filter(item => item.uuid !== card.uuid) + _config = {...config, [card.groupId]: _tabgroup} } else { _config = config } @@ -664,7 +671,7 @@ */ creatFunc = () => { const { menu } = this.props - let _config = JSON.parse(JSON.stringify(this.state.config)) + const { config } = this.state this.actionFormRef.handleConfirm().then(res => { let btn = res // 鎸夐挳淇℃伅 @@ -719,11 +726,11 @@ let _param = { funcName: btn.innerFunc, - name: _config.setting.tableName || '', + name: config.setting.tableName || '', fields: fields, menuNo: menu.MenuNo } - newLText = Utils.formatOptions(Utils.getfunc(_param, btn, menu, _config)) + newLText = Utils.formatOptions(Utils.getfunc(_param, btn, menu, config)) DelText = Utils.formatOptions(Utils.dropfunc(_param.funcName)) resolve(true) } else { @@ -738,18 +745,17 @@ } else { let _param = { funcName: btn.innerFunc, - name: _config.setting.tableName || '', + name: config.setting.tableName || '', fields: '', menuNo: menu.MenuNo } - newLText = Utils.formatOptions(Utils.getfunc(_param, btn, menu, _config)) + newLText = Utils.formatOptions(Utils.getfunc(_param, btn, menu, config)) DelText = Utils.formatOptions(Utils.dropfunc(_param.funcName)) resolve(true) } }).then(res => { // 鑾峰彇浜戠鍙婃湰鍦帮紝鏄惁宸插瓨鍦ㄨ瀛樺偍杩囩▼鐨勪俊鎭� if (res === false) return res - if (res !== false) return false let sysDefer = new Promise(resolve => { Api.getSystemConfig({ @@ -918,34 +924,24 @@ return } - let isupdate = false - _config.action = _config.action.map(item => { + let _action = config.action.map(item => { if (item.uuid === btn.uuid) { - isupdate = true return btn } else { return item } }) - _config.action = _config.action.filter(item => !item.origin) + _action = _action.filter(item => !item.origin) + // 鍒ゆ柇鏄惁瀛樺湪鎿嶄綔鍒� + let _hasGridbtn = _action.filter(act => act.position === 'grid').length > 0 + let _gridBtn = config.gridBtn - if (!isupdate) { // 鎿嶄綔涓嶆槸淇敼锛屾坊鍔犲厓绱犺嚦鍒楄〃 - _config.action.push(btn) - } - - let gridbtn = _config.action.filter(act => act.position === 'grid') - let _display = false - - if (gridbtn.length > 0) { - _display = true - } - - if (_config.gridBtn) { - _config.gridBtn.display = _display + if (_gridBtn) { + _gridBtn.display = _hasGridbtn } else { - _config.gridBtn = { - display: _display, + _gridBtn = { + display: _hasGridbtn, Align: 'center', IsSort: 'false', uuid: Utils.getuuid(), @@ -958,7 +954,7 @@ } this.setState({ - config: _config, + config: {...config, action: _action, gridBtn: _gridBtn}, funcLoading: false }) }) @@ -1187,30 +1183,40 @@ } deleteElement = (element) => { + const { config } = this.state let _this = this + confirm({ content: `纭畾鍒犻櫎<<${element.card.label}>>鍚楋紵`, okText: this.state.dict['header.confirm'], cancelText: this.state.dict['header.cancel'], onOk() { - let _config = JSON.parse(JSON.stringify(_this.state.config)) + let _config = null if (element.type === 'tabs') { - _config[element.card.groupId] = _config[element.card.groupId].filter(item => { + let _tabgroup = config[element.card.groupId].filter(item => { if (item.uuid === element.card.uuid) { return false } else { return true } }) + _config = {...config, [element.card.groupId]: _tabgroup} } else { - _config[element.type] = _config[element.type].filter(item => { + let list = config[element.type].filter(item => { if (item.uuid === element.card.uuid) { return false } else { return true } }) + + _config = {...config, [element.type]: list} + + // 鍒犻櫎鎸夐挳鏃跺垽鏂槸鍚﹀瓨鍦ㄦ搷浣滃垪 + if (element.type === 'action' && _config.gridBtn) { + _config.gridBtn.display = _config.action.filter(act => act.position === 'grid').length > 0 + } } _this.setState({ @@ -1315,9 +1321,9 @@ return } - let btnParam = { // 娣诲姞鑿滃崟鎸夐挳 + let btnParam = { // 娣诲姞鑿滃崟鎸夐挳 func: 'sPC_Button_AddUpt', - Type: 40, // 娣诲姞鑿滃崟涓嬬殑鎸夐挳 + Type: 40, // 娣诲姞鑿滃崟涓嬬殑鎸夐挳type涓�40锛屾寜閽笅鐨勬寜閽畉ype涓�60 ParentID: menu.MenuID, MenuNo: res.menuNo, Template: menu.PageParam.Template || '', @@ -1406,7 +1412,7 @@ } /** - * @description 淇濆瓨鎴栦慨鏀硅彍鍗曟寜閽� + * @description 淇濆瓨鎴栦慨鏀硅彍鍗曟寜閽泦 */ submitAction = (btnParam, tabParam) => { const { config } = this.state @@ -1559,6 +1565,9 @@ }) } + /** + * @description 鐐瑰嚮杩斿洖鏃讹紝鍒ゆ柇閰嶇疆淇濆瓨鐘舵�� + */ cancelConfig = () => { const { menu } = this.props const { config, originMenu } = this.state @@ -1613,6 +1622,9 @@ } } + /** + * @description 绛涢�夊彲鐢ㄥ瓧娈甸泦 + */ queryField = (type) => { const {selectedTables, tableColumns, config} = this.state // 鍒ゆ柇鏄惁宸查�夋嫨琛ㄥ悕 @@ -1659,7 +1671,12 @@ }) } + /** + * @description 娣诲姞瀛楁闆� + */ addFieldSubmit = () => { + const {addType, config} = this.state + // 瀛楁闆嗕负绌猴紝鍏抽棴寮圭獥 if (!this.state.fields || this.state.fields.length === 0) { this.setState({ @@ -1668,7 +1685,6 @@ }) } - const {addType, config} = this.state const textmatch = { // 閫夋嫨text鏃跺尮閰嶈鍒� text: 'like', number: 'like', @@ -1690,23 +1706,31 @@ // 鑾峰彇宸查�夊瓧娈甸泦鍚� let cards = this.refs.searchcard.state.selectCards + + if (cards.length === 0) { + notification.warning({ + top: 92, + message: '璇烽�夋嫨娣诲姞瀛楁', + duration: 10 + }) + return + } + let columnsMap = new Map() cards.forEach(card => { columnsMap.set(card.field, card) }) - let items = [] if (addType === 'search') { - config.search.forEach(item => { + let _search = config.search.filter(item => !item.origin) + + // 閲嶇疆鍘熸湁鎼滅礌鏉′欢 + _search = _search.map(item => { if (columnsMap.has(item.field)) { let cell = columnsMap.get(item.field) - if (cell.selected && cell.type === item.type) { // 鏁版嵁鏈慨鏀� - items.push(item) - } else if (cell.selected) { // 鏁版嵁绫诲瀷淇敼 - if (cell.type === 'text') { - item.match = textmatch[cell.datatype] - } else if (cell.type === 'select') { + if (cell.type !== item.type) { // 鏁版嵁绫诲瀷淇敼 + if (cell.type === 'select') { item.match = selectmatch[cell.datatype] } else if (cell.type === 'daterange') { item.match = datematch[cell.datatype] @@ -1717,101 +1741,95 @@ item.type = cell.type item.initval = '' - items.push(item) } columnsMap.delete(item.field) - } else if (!item.origin) { - items.push(item) } + return item }) - + let _columns = [...columnsMap.values()] + // 椤哄簭娣诲姞鏂板鎼滅储 _columns.forEach(item => { - if (item.selected) { - let _match = '' - if (item.type === 'text') { - _match = textmatch[item.datatype] - } else if (item.type === 'select') { - _match = selectmatch[item.datatype] - } else if (item.type === 'daterange') { - _match = datematch[item.datatype] - } else { - item.type = 'text' - _match = textmatch[item.datatype] - } - - let newcard = { - uuid: Utils.getuuid(), - label: item.label, - field: item.field, - initval: '', - type: item.type, - resourceType: '0', - setAll: 'false', - options: [], - dataSource: '', - linkField: '', - valueField: '', - valueText: '', - orderBy: '', - orderType: 'asc', - match: _match, - display: 'dropdown' - } - - items.push(newcard) + let _match = '' + if (item.type === 'select') { + _match = selectmatch[item.datatype] + } else if (item.type === 'daterange') { + _match = datematch[item.datatype] + } else { + _match = textmatch[item.datatype] } + + let newcard = { + uuid: Utils.getuuid(), + label: item.label, + field: item.field, + initval: '', + type: item.type || 'text', + resourceType: '0', + setAll: 'false', + options: [], + orderType: 'asc', + match: _match, + display: 'dropdown' + } + + _search.push(newcard) + }) + + this.setState({ + config: {...config, search: _search} }) } else { - config.columns.forEach(item => { + let _columns = config.columns.filter(item => !item.origin) + + // 閲嶇疆鍘熸湁鏄剧ず鍒楃被鍨� + _columns = _columns.map(item => { if (columnsMap.has(item.field)) { let cell = columnsMap.get(item.field) - if (cell.selected) { - items.push(item) + if (cell.type) { + item.type = cell.type } + columnsMap.delete(item.field) - } else if (!item.origin) { - items.push(item) } + return item }) - let _columns = [...columnsMap.values()] + let _cols = [...columnsMap.values()] - _columns.forEach(item => { - if (item.selected) { - let newcard = { - uuid: Utils.getuuid(), - Align: 'left', - label: item.label, - field: item.field, - Hide: 'false', - IsSort: item.type === 'picture' ? 'false' : 'true', - type: item.type, - Width: 120 - } - - items.push(newcard) + // 娣诲姞鏄剧ず鍒� + _cols.forEach(item => { + let newcard = { + uuid: Utils.getuuid(), + Align: 'left', + label: item.label, + field: item.field, + Hide: 'false', + IsSort: item.type === 'picture' ? 'false' : 'true', + type: item.type, + Width: 120 } + + _columns.push(newcard) + }) + + this.setState({ + config: {...config, columns: _columns} }) } - this.setState({ - [addType + 'loading']: true, - config: {...config, [addType]: items} - }, () => { - notification.success({ - top: 92, - message: '鎿嶄綔鎴愬姛', - duration: 2 - }) - this.setState({ - [addType + 'loading']: false - }) + notification.success({ + top: 92, + message: '鎿嶄綔鎴愬姛', + duration: 2 }) } + /** + * @description 琛ㄥ悕鍒囨崲鏃讹紝娣诲姞琛ㄥ悕锛屾柊澧炴椂鏌ヨ琛ㄧ浉鍏冲瓧娈� + */ onTableChange = (value) => { const {tables, selectedTables, tableColumns} = this.state @@ -1867,6 +1885,9 @@ } } + /** + * @description 鍒犻櫎琛ㄥ悕浠ュ強琛ㄧ浉鍏冲瓧娈� + */ deleteTable = (table) => { const {selectedTables, tableColumns} = this.state @@ -1876,12 +1897,18 @@ }) } + /** + * @description 椤甸潰閰嶇疆淇℃伅妯℃�佹鏄剧ず + */ changeSetting = () => { this.setState({ settingVisible: true }) } + /** + * @description 淇濆瓨椤甸潰閰嶇疆淇℃伅 + */ settingSave = () => { const { menu } = this.props const {config} = this.state @@ -2024,7 +2051,10 @@ } } - onEnabledChange = (val, e) => { + /** + * @description 椤甸潰鍚敤鍋滄鍒囨崲 + */ + onEnabledChange = () => { const { config } = this.state let tabinvalid = true @@ -2055,6 +2085,9 @@ } } + /** + * @description 鏄剧ず闅愯棌鏄剧ず鍒楀瓧娈靛悕 + */ onColumnNameChange = () => { const { showColumnName } = this.state @@ -2063,6 +2096,9 @@ }) } + /** + * @description 澧炲姞鏍囩椤靛垎缁� + */ addTabGroup = () => { let _this = this let _config = JSON.parse(JSON.stringify(this.state.config)) @@ -2085,6 +2121,9 @@ }) } + /** + * @description 鍒犻櫎鏍囩椤靛垎缁� + */ delTabGroup = (groupId) => { let _this = this let _config = JSON.parse(JSON.stringify(this.state.config)) @@ -2106,6 +2145,9 @@ }) } + /** + * @description 閫夋嫨涓嶄繚瀛樻椂锛屽鏈夊鍒舵寜閽紝鍒欏垹闄� + */ notsave = () => { this.state.copyActions.forEach(item => { let _param = { @@ -2120,7 +2162,8 @@ render () { const { modaltype } = this.state const configAction = this.state.config.action.filter(_action => - !_action.origin && (_action.OpenType === 'pop' || _action.OpenType === 'popview' || _action.OpenType === 'blank' || _action.OpenType === 'tab') + !_action.origin && (_action.OpenType === 'pop' || _action.OpenType === 'popview') + // !_action.origin && (_action.OpenType === 'pop' || _action.OpenType === 'popview' || _action.OpenType === 'blank' || _action.OpenType === 'tab') ) let configTabs = [] @@ -2405,7 +2448,7 @@ wrappedComponentRef={(inst) => this.columnFormRef = inst} /> </Modal> - {/* 鍚堝苟鍒楃紪杈� */} + {/* 鎿嶄綔鍒楃紪杈� */} <Modal title={this.state.dict['header.modal.gridbtn.edit']} visible={modaltype === 'gridbtn'} -- Gitblit v1.8.0