From 790dfe8172be5027940a04594224531d15143389 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 12 十二月 2019 19:30:30 +0800 Subject: [PATCH] 2019-12-12 --- src/templates/comtableconfig/index.jsx | 650 ++++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 448 insertions(+), 202 deletions(-) diff --git a/src/templates/comtableconfig/index.jsx b/src/templates/comtableconfig/index.jsx index 2385c9b..fc39bd3 100644 --- a/src/templates/comtableconfig/index.jsx +++ b/src/templates/comtableconfig/index.jsx @@ -37,7 +37,6 @@ } state = { - operaType: '', // 鎿嶄綔绫诲瀷锛屾柊寤烘垨缂栬緫 dict: CommonDict, // 瀛楀吀 config: null, // 椤甸潰閰嶇疆 visible: false, // 鎼滅储鏉′欢銆佹寜閽�佹樉绀哄垪锛屾ā鎬佹鏄剧ず鎺у埗 @@ -60,7 +59,8 @@ tables: [], // 鍙敤琛ㄥ悕 selectedTables: [], // 宸查�夎〃鍚� originMenu: null, // 鍘熷鑿滃崟 - originActions: null + originActions: null, + delActions: [] } /** @@ -69,14 +69,12 @@ * 2銆佽缃搷浣滅被鍨嬨�佸師濮嬭彍鍗曚俊鎭紙姣忔淇濆瓨鍚庨噸缃級銆佸凡浣跨敤琛ㄥ強鍩烘湰淇℃伅琛ㄥ崟 */ UNSAFE_componentWillMount () { - const { menu, type } = this.props + const { menu } = this.props let _LongParam = menu.LongParam let _config = '' - let _type = type - if (_type === 'add' || !_LongParam) { - _type = 'add' + if (!_LongParam) { _config = JSON.parse(JSON.stringify((Source.baseConfig))) } else { let _setting = Source.baseConfig.setting @@ -86,16 +84,29 @@ _LongParam.setting = _setting _config = _LongParam } + + let _oriActions = [] + if (_config.type === 'user') { + _config.action = _config.action.map(item => { + let uuid = Utils.getuuid() - let _oriActions = _config.action - if (_config.type === 'user' || _config.type === 'system') { - _oriActions = [] + if (item.OpenType === 'pop') { // 鍚湁瀛愰厤缃」鐨勬寜閽�傘�傘�� + _oriActions.push({ + prebtn: JSON.parse(JSON.stringify(item)), + curuuid: uuid, + Template: 'Modal' + }) + } + + item.uuid = uuid + + return item + }) } this.setState({ originActions: _oriActions, config: _config, - operaType: _type, originMenu: JSON.parse(JSON.stringify(menu)), selectedTables: _config.tables || [], menuformlist: [ @@ -913,6 +924,8 @@ * 3銆佹坊鍔犳垨缂栬緫鍒楋紝淇濆瓨鏃讹紝濡傛寜閽綅缃缃负琛ㄦ牸锛屽垯淇敼鎿嶄綔鍒楁樉绀虹姸鎬� */ handleSubmit = () => { + const { menu } = this.props + const { card } = this.state let _config = JSON.parse(JSON.stringify(this.state.config)) if (this.state.formtemp !== 'gridbtn') { @@ -927,6 +940,35 @@ } res.values.dataSourceSql = Utils.formatOptions(sql) } + } + + if (res.type === 'action' && card.originCard && res.values.OpenType === 'pop') { + Api.getSystemConfig({ + func: 'sPC_Get_LongParam', + MenuID: card.originCard.uuid + }).then(result => { + if (result.status && result.LongParam) { + let param = { + func: 'sPC_ButtonParam_AddUpt', + ParentID: menu.MenuID, + MenuID: res.values.uuid, + MenuNo: menu.MenuNo, + Template: 'Modal', + MenuName: res.values.label, + PageParam: JSON.stringify({Template: 'Modal'}), + LongParam: result.LongParam + } + Api.getSystemConfig(param).then(response => { + if (!response.status) { + notification.warning({ + top: 92, + message: response.message, + duration: 10 + }) + } + }) + } + }) } _config[res.type] = _config[res.type].map(item => { @@ -995,11 +1037,14 @@ } creatFunc = () => { - // let _config = JSON.parse(JSON.stringify(this.state.config)) + let _config = JSON.parse(JSON.stringify(this.state.config)) this.formRef.handleConfirm().then(res => { let btn = res.values let LText = '' + let DelText = '' + let isExit = false + if (!btn.innerFunc) { notification.warning({ top: 92, @@ -1027,7 +1072,22 @@ } if (_LongParam) { - resolve(_LongParam) + let fields = [] + if (_LongParam.groups.length > 0) { + _LongParam.groups.forEach(group => { + fields = [...fields, ...group.sublist] + }) + } else { + fields = _LongParam.fields + } + + let _param = { + name: _config.setting.tableName || '', + fields: fields + } + LText = Utils.formatOptions(Utils.getfunc(_param)) + DelText = Utils.formatOptions(Utils.dropfunc(_param.name)) + resolve(true) } else { resolve(false) notification.warning({ @@ -1038,21 +1098,26 @@ } }) } else { + let _param = { + name: _config.setting.tableName || '', + fields: '' + } + LText = Utils.formatOptions(Utils.getfunc(_param)) + DelText = Utils.formatOptions(Utils.dropfunc(_param.name)) resolve(true) } }).then(res => { - if (!res) return - LText = Utils.formatOptions(Utils.getfunc()) - console.log(LText) + console.log(res) + if (res === false) return res + return Api.getSystemConfig({ func: 'sPC_Get_TVP', TVPName: btn.innerFunc }) }).then(res => { console.log(res) - if (res.status) { - return true - } else { + if (res === false) return res + if (!res.status) { notification.warning({ top: 92, message: res.message, @@ -1060,57 +1125,161 @@ }) return false } + + if (res.TVPText && LText === res.TVPText) { + return 'drop' + } else { + if (res.TVPText) { + isExit = true + } + return Api.getSystemConfig({ + func: 'sPC_TVP_InUp', + TVPName: btn.innerFunc, + TVPText: LText, + TypeName: 'P' + }) + } }).then(res => { console.log(res) + if (res === false || res === 'drop') return res + + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 10 + }) + return false + } else if (isExit) { + return 'drop' + } else { + return 'create' + } + }).then(res => { + console.log(res) + if (res === false || res === 'create') return res + + let _param = { + func: 'sPC_TableData_InUpDe', + LText: DelText + } + _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp) + return Api.getSystemConfig(_param) + }).then(res => { + console.log(res) + if (res === false || res === 'create') return res + + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 10 + }) + return false + } else { + return 'create' + } + }).then(res => { + console.log(res) + if (res === false) return res + + let _param = { + func: 'sPC_TableData_InUpDe', + LText: LText + } + _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp) + return Api.getSystemConfig(_param) + }).then(res => { + console.log(res) + if (res === false) return res + + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 10 + }) + return false + } else { + notification.success({ + top: 92, + message: '鍒涘缓鎴愬姛', + duration: 5 + }) + } + }).then(res => { + console.log(res) + if (res === false) return res + + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 10 + }) + return false + } else { + notification.success({ + top: 92, + message: '鍒涘缓鎴愬姛', + duration: 5 + }) + return true + } + }).then(res => { + console.log(res) + if (res === false) return res + + let isupdate = false + _config.action = _config.action.map(item => { + if (item.uuid === res.values.uuid) { + isupdate = true + return res.values + } else { + return item + } + }) + _config.action = _config.action.filter(item => !item.origin) + + + if (!isupdate) { // 鎿嶄綔涓嶆槸淇敼锛屾坊鍔犲厓绱犺嚦鍒楄〃 + _config.action.push(res.values) + } + + 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 + } else { + _config.gridBtn = { + display: _display, + Align: 'center', + IsSort: 'false', + uuid: Utils.getuuid(), + label: this.state.dict['header.form.column.action'], + type: 'action', + style: 'button', + show: 'horizontal', + Width: 120 + } + } + + this.setState({ + config: _config, + actionloading: true + }, () => { + this.setState({ + actionloading: false + }) + }) }) - - // let isupdate = false - // _config.action = _config.action.map(item => { - // if (item.uuid === res.values.uuid) { - // isupdate = true - // return res.values - // } else { - // return item - // } - // }) - // _config.action = _config.action.filter(item => !item.origin) - - - // if (!isupdate) { // 鎿嶄綔涓嶆槸淇敼锛屾坊鍔犲厓绱犺嚦鍒楄〃 - // _config.action.push(res.values) - // } - - // 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 - // } else { - // _config.gridBtn = { - // display: _display, - // Align: 'center', - // IsSort: 'false', - // uuid: Utils.getuuid(), - // label: this.state.dict['header.form.column.action'], - // type: 'action', - // style: 'button', - // show: 'horizontal', - // Width: 120 - // } - // } - - // this.setState({ - // config: _config, - // actionloading: true - // }, () => { - // this.setState({ - // actionloading: false - // }) - // }) }) } @@ -1131,6 +1300,7 @@ }) _this.setState({ config: _config, + delActions: [..._this.state.delActions, element.card.uuid], [element.type + 'loading']: true }, () => { _this.setState({ @@ -1151,35 +1321,21 @@ */ submitConfig = () => { const { menu } = this.props - const { config, originMenu } = this.state + const { originMenu } = this.state + + let config = JSON.parse(JSON.stringify(this.state.config)) + this.menuformRef.handleConfirm().then(res => { - config.search = config.search.filter(item => !item.origin) - config.action = config.action.filter(item => !item.origin) - config.columns = config.columns.filter(item => !item.origin) - // if (config.search[0] && config.search[0].origin) { - // notification.warning({ - // top: 92, - // message: '璇疯缃悳绱㈡潯浠�', - // duration: 10 - // }) - // return - // } - // if (config.action[0] && config.action[0].origin) { - // notification.warning({ - // top: 92, - // message: '璇疯缃寜閽�', - // duration: 10 - // }) - // return - // } - // if (config.columns[0] && config.columns[0].origin) { - // notification.warning({ - // top: 92, - // message: '璇疯缃樉绀哄垪', - // duration: 10 - // }) - // return - // } + + if (config.search[0] && config.search[0].origin) { + config.search = config.search.filter(item => !item.origin) + } + if (config.action[0] && config.action[0].origin) { + config.action = config.action.filter(item => !item.origin) + } + if (config.columns[0] && config.columns[0].origin) { + config.columns = config.columns.filter(item => !item.origin) + } let _LongParam = '' let _config = {...config, tables: this.state.selectedTables} @@ -1216,102 +1372,64 @@ btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp) - if (this.state.operaType === 'add') { // 鏂板缓鑿滃崟 - let param = { - func: 'sPC_TrdMenu_Add', - ParentID: res.parentId, - MenuID: menu.MenuID, - MenuNo: res.menuNo, - Template: menu.PageParam.Template || '', - MenuName: res.menuName, - PageParam: JSON.stringify(_pageParam), - LongParam: _LongParam - } - - if (this.state.closeVisible) { // 鏄剧ず鍏抽棴瀵硅瘽妗嗘椂锛屾ā鎬佹涓繚瀛樻寜閽紝鏄剧ず淇濆瓨涓姸鎬� - this.setState({ - menucloseloading: true - }) - } else { - this.setState({ - menuloading: true - }) - } - - Api.getSystemConfig(param).then(response => { - if (response.status) { - this.setState({ - operaType: 'edit', - originMenu: { - ...originMenu, - LongParam: _config, - PageParam: _pageParam, - MenuName: res.menuName, - MenuNo: res.menuNo, - ParentID: res.parentId - } - }) - this.submitAction(btnParam) - } else { - this.setState({ - menuloading: false, - menucloseloading: false - }) - notification.warning({ - top: 92, - message: response.message, - duration: 10 - }) - } + let param = { + func: 'sPC_TrdMenu_AddUpt', + ParentID: res.parentId, + MenuID: menu.MenuID, + MenuNo: res.menuNo, + Template: menu.PageParam.Template || '', + MenuName: res.menuName, + Sort: (this.props.supMenuList.length + 1) * 10, + PageParam: JSON.stringify(_pageParam), + LongParam: _LongParam + } + + if (this.state.closeVisible) { // 鏄剧ず鍏抽棴瀵硅瘽妗嗘椂锛屾ā鎬佹涓繚瀛樻寜閽紝鏄剧ず淇濆瓨涓姸鎬� + this.setState({ + menucloseloading: true }) - } else { // 淇敼鑿滃崟 - let param = { - func: 'sPC_TrdMenu_Upt', - ParentID: res.parentId, - MenuID: menu.MenuID, - MenuNo: res.menuNo, - Template: menu.PageParam.Template || '', - MenuName: res.menuName, - PageParam: JSON.stringify(_pageParam), - LongParam: _LongParam - } - - if (this.state.closeVisible) { // 鏄剧ず鍏抽棴瀵硅瘽妗嗘椂锛屾ā鎬佹涓繚瀛樻寜閽紝鏄剧ず淇濆瓨涓姸鎬� - this.setState({ - menucloseloading: true - }) - } else { - this.setState({ - menuloading: true - }) - } - - Api.getSystemConfig(param).then(response => { - if (response.status) { - this.setState({ - originMenu: { - ...originMenu, - LongParam: _config, - PageParam: _pageParam, - MenuName: res.menuName, - MenuNo: res.menuNo, - ParentID: res.parentId - } - }) - this.submitAction(btnParam) - } else { - this.setState({ - menuloading: false, - menucloseloading: false - }) - notification.warning({ - top: 92, - message: response.message, - duration: 10 - }) - } + } else { + this.setState({ + menuloading: true }) } + + Api.getSystemConfig(param).then(response => { + if (response.status) { + this.setState({ + config: _config, + originMenu: { + ...originMenu, + LongParam: _config, + PageParam: _pageParam, + MenuName: res.menuName, + MenuNo: res.menuNo, + ParentID: res.parentId + }, + searchloading: true, + actionloading: true, + columnsloading: true + }, () => { + this.setState({ + searchloading: false, + actionloading: false, + columnsloading: false + }) + }) + + this.submitAction(btnParam) + } else { + this.setState({ + menuloading: false, + menucloseloading: false + }) + notification.warning({ + top: 92, + message: response.message, + duration: 10 + }) + } + }) }, () => { notification.warning({ top: 92, @@ -1325,8 +1443,117 @@ * @description 淇濆瓨鎴栦慨鏀硅彍鍗曟寜閽� */ submitAction = (param) => { - Api.getSystemConfig(param).then(response => { - if (response.status) { + const { config } = this.state + new Promise(resolve => { + // 鍐呴儴璇锋眰 + Api.getSystemConfig(param).then(response => { + if (response.status) { + resolve('true') + } else { + resolve(response) + } + }) + }).then(res => { + console.log(res) + if (res === 'true' && this.state.delActions.length > 0) { + let deffers = this.state.delActions.map(item => { + let param = { + func: 'sPC_MainMenu_Del', + MenuID: item + } + return new Promise(resolve => { + Api.getSystemConfig(param).then(res => { + resolve(res) + }) + }) + }) + return Promise.all(deffers) + } else if (res === 'true' && this.state.delActions.length === 0) { + return 'copy' + } else if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 10 + }) + return false + } + }).then(response => { + console.log(response) + if (response === false || response === 'copy') return response + + let res = 'copy' + if (Array.isArray(response)) { + response.forEach(result => { + if (!result.status) { + res = result + } + }) + } + + if (res === 'copy') return 'copy' + + notification.warning({ + top: 92, + message: res.message, + duration: 10 + }) + return false + }).then(response => { + console.log(response) + if (response === false) return response + + let oriActions = [] + this.state.originActions.forEach(item => { + let curBtn = config.action.filter(cell => item.curuuid === cell.uuid)[0] // 鏌ョ湅鍒濆鍖栨寜閽槸鍚﹀瓨鍦� + if (!curBtn) return + if (curBtn.OpenType !== item.prebtn.OpenType) return + + oriActions.push({ + prebtn: item.prebtn, + curBtn: item.curBtn + }) + }) + + if (oriActions.length === 0) return 'true' + + oriActions.forEach(action => { + Api.getSystemConfig({ + func: 'sPC_Get_LongParam', + MenuID: action.prebtn ? action.prebtn.uuid : '' + }).then(result => { + if (result.status && result.LongParam) { + let _LongParam = '' + + if (result.LongParam) { + _LongParam = window.decodeURIComponent(window.atob(result.LongParam)) + try { + _LongParam = JSON.parse(_LongParam) + } catch (e) { + _LongParam = '' + } + } + + if (_LongParam) { + let param = { + func: 'sPC_ButtonParam_AddUpt', + ParentID: this.props.menu.MenuID, + MenuID: action.curBtn.uuid, + MenuNo: this.props.menu.MenuNo, + Template: _LongParam.type, + MenuName: action.curBtn.label, + PageParam: JSON.stringify({Template: _LongParam.type}), + LongParam: result.LongParam + } + Api.getSystemConfig(param).then(() => {}) + } + } + }) + }) + return 'true' + }).then(response => { + console.log(response) + if (response === 'true') { notification.success({ top: 92, message: '淇濆瓨鎴愬姛', @@ -1345,11 +1572,6 @@ menuloading: false, menucloseloading: false }) - notification.warning({ - top: 92, - message: response.message, - duration: 10 - }) } }) } @@ -1357,9 +1579,19 @@ cancelConfig = () => { const { menu } = this.props const { config, originMenu } = this.state - let _this = this - if (this.state.operaType === 'add') { + let _this = this + let isAdd = false + + if ( + (config.search[0] && config.search[0].origin) || + (config.action[0] && config.action[0].origin) || + (config.columns[0] && config.columns[0].origin) + ) { + isAdd = true + } + + if (isAdd) { confirm({ content: '鑿滃崟灏氭湭鎻愪氦锛岀‘瀹氭斁寮冧繚瀛樺悧锛�', okText: this.state.dict['header.confirm'], @@ -1590,11 +1822,14 @@ } this.setState({ - tableVisible: false, [addType + 'loading']: true, - addType: '', config: {...config, [addType]: items} }, () => { + notification.success({ + top: 92, + message: '鎿嶄綔鎴愬姛', + duration: 5 + }) this.setState({ [addType + 'loading']: false }) @@ -1693,7 +1928,17 @@ const { menu } = this.props const { config, originMenu } = this.state - if (this.state.operaType === 'add') { + let isAdd = false + + if ( + (config.search[0] && config.search[0].origin) || + (config.action[0] && config.action[0].origin) || + (config.columns[0] && config.columns[0].origin) + ) { + isAdd = true + } + + if (isAdd) { notification.warning({ top: 92, message: '鑿滃崟灏氭湭淇濆瓨锛岃淇濆瓨鑿滃崟閰嶇疆锛�', @@ -1739,7 +1984,7 @@ _LongParam = '' } } - + console.log(_LongParam) this.props.handleSubConfig(btn, originMenu, _LongParam) } else { this.setState({ @@ -1946,7 +2191,7 @@ onOk={this.handleSubmit} footer={[ this.state.formtemp === 'action' ? - <Button key="delete" className="mk-btn mk-purple" onClick={this.creatFunc} loading={this.state.confirmLoading}>{this.state.dict['header.delete']}</Button> : null, + <Button key="delete" className="mk-btn mk-purple" onClick={this.creatFunc} loading={this.state.confirmLoading}>{this.state.dict['header.menu.func.create']}</Button> : null, <Button key="cancel" onClick={() => { this.setState({ visible: false }) }}>{this.state.dict['header.cancel']}</Button>, <Button key="confirm" type="primary" onClick={this.handleSubmit}>{this.state.dict['header.confirm']}</Button> ]} @@ -1999,6 +2244,7 @@ visible={this.state.tableVisible} width={'65vw'} style={{minWidth: '900px', maxWidth: '1200px'}} + cancelText={this.state.dict['header.close']} onOk={this.addFieldSubmit} onCancel={() => { // 鍙栨秷娣诲姞 this.setState({ @@ -2009,7 +2255,7 @@ destroyOnClose > {this.state.addType && this.state.fields.length > 0 ? - <EditCard data={this.state.fields} ref="searchcard" type={this.state.addType} /> : null + <EditCard data={this.state.fields} ref="searchcard" type={this.state.addType} dict={this.state.dict} /> : null } {(!this.state.fields || this.state.fields.length === 0) && <Empty /> -- Gitblit v1.8.0