| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import {connect} from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { DndProvider } from 'react-dnd' |
| | | import HTML5Backend from 'react-dnd-html5-backend' |
| | |
| | | selectedTables: [], // 已选表名 |
| | | originMenu: null, // 原始菜单 |
| | | originActions: null, |
| | | delActions: [] |
| | | delActions: [], |
| | | funcLoading: false |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | handleAction = (card) => { |
| | | let ableField = this.props.permFuncField.join(', ') |
| | | this.setState({ |
| | | visible: true, |
| | | formtemp: 'action', |
| | |
| | | label: this.state.dict['header.form.innerFunc'], |
| | | initVal: card.innerFunc, |
| | | tooltip: <div> |
| | | <p>内部接口: 可自定义数据处理函数,未设置时会调用系统函数,使用系统函数需完善数据源及操作类型;</p> |
| | | <p>内部接口: 可自定义数据处理函数,函数名称需以{ableField}等字符开始;未设置时会调用系统函数,使用系统函数需完善数据源及操作类型;</p> |
| | | <p>外部接口: 可自定义数据处理函数,提交数据经过内部函数处理后,传入外部接口,未设置时,数据会直接传入外部接口。</p> |
| | | </div>, |
| | | fields: this.props.permFuncField, |
| | | tooltipClass: 'middle', |
| | | required: false, |
| | | readonly: false |
| | |
| | | type: 'select', |
| | | key: 'sqlType', |
| | | label: this.state.dict['header.form.action.type'], |
| | | initVal: card.sqlType || 'insert', |
| | | initVal: card.sqlType || '', |
| | | tooltip: this.state.dict['header.form.actionhelp.sqlType'], |
| | | required: false, |
| | | options: [{ |
| | | MenuID: '', |
| | | text: this.state.dict['header.form.empty'] |
| | | }, { |
| | | MenuID: 'insert', |
| | | text: this.state.dict['header.form.action.insert'] |
| | | }, { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 创建按钮存储过程 |
| | | */ |
| | | creatFunc = () => { |
| | | 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 |
| | | let btn = res.values // 按钮信息 |
| | | let newLText = '' // 创建存储过程sql |
| | | let DelText = '' // 删除存储过程sql |
| | | let isExit = false // 存储过程是否存在 |
| | | let sysTVPText = '' // 已有的存储过程语句(云端) |
| | | let localTVPText = '' // 已有的存储过程语句(本地) |
| | | |
| | | // 创建存储过程,必须填写内部函数名 |
| | | if (!btn.innerFunc) { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | return |
| | | } |
| | | |
| | | // 创建中 |
| | | this.setState({ |
| | | funcLoading: true |
| | | }) |
| | | |
| | | new Promise(resolve => { |
| | | // 内部请求 |
| | | // 弹窗(表单)类按钮,先获取按钮配置信息,如果尚未配置按钮则会报错并终止。 |
| | | // 获取信息后生成删除和创建存储过程的语句 |
| | | if (btn.OpenType === 'pop') { |
| | | Api.getSystemConfig({ |
| | | func: 'sPC_Get_LongParam', |
| | |
| | | fields: fields, |
| | | menuNo: this.props.menu.MenuNo |
| | | } |
| | | LText = Utils.formatOptions(Utils.getfunc(_param)) |
| | | newLText = Utils.formatOptions(Utils.getfunc(_param)) |
| | | DelText = Utils.formatOptions(Utils.dropfunc(_param.funcName)) |
| | | resolve(true) |
| | | } else { |
| | |
| | | fields: '', |
| | | menuNo: this.props.menu.MenuNo |
| | | } |
| | | LText = Utils.formatOptions(Utils.getfunc(_param)) |
| | | newLText = Utils.formatOptions(Utils.getfunc(_param)) |
| | | DelText = Utils.formatOptions(Utils.dropfunc(_param.funcName)) |
| | | resolve(true) |
| | | } |
| | | }).then(res => { |
| | | // 获取云端及本地,是否已存在该存储过程的信息 |
| | | console.log(res) |
| | | if (res === false) return res |
| | | |
| | | return Api.getSystemConfig({ |
| | | func: 'sPC_Get_TVP', |
| | | let sysDefer = new Promise(resolve => { |
| | | Api.getSystemConfig({ |
| | | func: 'sPC_Get_TVP', // 云端获取存储结果 |
| | | TVPName: btn.innerFunc |
| | | }).then(result => { |
| | | resolve(result) |
| | | }) |
| | | }) |
| | | |
| | | let localDefer = new Promise(resolve => { |
| | | let _param = { // 获取本地存储过程信息 |
| | | func: 's_get_userproc', |
| | | LText: btn.innerFunc |
| | | } |
| | | _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' |
| | | _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp) |
| | | |
| | | Api.getLocalConfig(_param).then(result => { |
| | | resolve(result) |
| | | }) |
| | | }) |
| | | |
| | | return Promise.all([sysDefer, localDefer]) |
| | | }).then(res => { |
| | | // 云端结果与新语句不同时,更新云端信息 |
| | | console.log(res) |
| | | if (res === false) return res |
| | | if (!res.status) { |
| | | |
| | | let isError = false |
| | | |
| | | res.forEach((result, index) => { |
| | | if (!result.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: res.message, |
| | | message: result.message, |
| | | duration: 10 |
| | | }) |
| | | return false |
| | | } |
| | | |
| | | if (res.TVPText && LText === res.TVPText) { |
| | | return 'drop' |
| | | isError = true |
| | | } else if (index === 0) { |
| | | sysTVPText = result.TVPText |
| | | } else { |
| | | if (res.TVPText) { |
| | | console.log(result.Ltext) |
| | | if (result.Ltext) { // 本地存储过程是否存在 |
| | | isExit = true |
| | | } |
| | | localTVPText = Utils.formatOptions(result.Ltext) |
| | | } |
| | | }) |
| | | |
| | | if (isError) return false |
| | | |
| | | if ((newLText === localTVPText) && (newLText === sysTVPText)) { |
| | | return 'drop' |
| | | } else if (!localTVPText || (sysTVPText === localTVPText)) { |
| | | // 本地存储过程不存在,或云端和本地存储过程一致时,将新的存储过程更新至云端 |
| | | return Api.getSystemConfig({ |
| | | func: 'sPC_TVP_InUp', |
| | | TVPName: btn.innerFunc, |
| | | TVPText: LText, |
| | | TVPText: newLText, |
| | | TypeName: 'P' |
| | | }) |
| | | } else { |
| | | return new Promise(resolve => { |
| | | Api.getSystemConfig({ // 添加现有的本地存储过程至云端 |
| | | func: 'sPC_TVP_InUp', |
| | | TVPName: btn.innerFunc, |
| | | TVPText: localTVPText, |
| | | TypeName: 'P' |
| | | }).then(result => { |
| | | if (result.status) { |
| | | Api.getSystemConfig({ |
| | | func: 'sPC_TVP_InUp', // 添加最新的存储过程至云端 |
| | | TVPName: btn.innerFunc, |
| | | TVPText: newLText, |
| | | TypeName: 'P' |
| | | }).then(response => { |
| | | resolve(response) |
| | | }) |
| | | } else { |
| | | resolve(result) |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | }).then(res => { |
| | | // 云端信息更新后,判断是删除或是直接新建存储过程 |
| | | console.log(res) |
| | | if (res === false || res === 'drop') return res |
| | | |
| | |
| | | return 'create' |
| | | } |
| | | }).then(res => { |
| | | // 删除存储过程 |
| | | console.log(res) |
| | | if (res === false || res === 'create') return res |
| | | |
| | | let _param = { |
| | | func: 'sPC_TableData_InUpDe', |
| | | LText: DelText |
| | | LText: DelText, |
| | | TypeCharOne: 'proc' // 删除或创建存储过程 |
| | | } |
| | | |
| | | _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' |
| | | _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp) |
| | | return Api.getSystemConfig(_param) |
| | | |
| | | return Api.getLocalConfig(_param) |
| | | }).then(res => { |
| | | // 根据上述操作结果,判断是否新建存储过程 |
| | | console.log(res) |
| | | if (res === false || res === 'create') return res |
| | | |
| | |
| | | return 'create' |
| | | } |
| | | }).then(res => { |
| | | // 新建存储过程 |
| | | console.log(res) |
| | | if (res === false) return res |
| | | |
| | | let _param = { |
| | | func: 'sPC_TableData_InUpDe', |
| | | LText: LText |
| | | LText: newLText, |
| | | TypeCharOne: 'proc' // 删除或创建存储过程 |
| | | } |
| | | _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' |
| | | _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp) |
| | | |
| | | return Api.getSystemConfig(_param) |
| | | return Api.getLocalConfig(_param) |
| | | }).then(res => { |
| | | // 处理新建结果 |
| | | console.log(res) |
| | | if (res === false) return res |
| | | |
| | |
| | | return true |
| | | } |
| | | }).then(res => { |
| | | // 新建成功后,更新页面按钮信息 |
| | | console.log(res) |
| | | if (res === false) return res |
| | | if (res === false) { |
| | | this.setState({ |
| | | funcLoading: false |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let isupdate = false |
| | | _config.action = _config.action.map(item => { |
| | |
| | | |
| | | this.setState({ |
| | | config: _config, |
| | | actionloading: true |
| | | actionloading: true, |
| | | funcLoading: false |
| | | }, () => { |
| | | this.setState({ |
| | | actionloading: false |
| | |
| | | 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.menu.func.create']}</Button> : null, |
| | | <Button key="delete" className="mk-btn mk-purple" onClick={this.creatFunc} loading={this.state.funcLoading}>{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> |
| | | ]} |
| | |
| | | } |
| | | } |
| | | |
| | | export default ComTableConfig |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | permFuncField: state.permFuncField |
| | | } |
| | | } |
| | | |
| | | const mapDispatchToProps = () => { |
| | | return {} |
| | | } |
| | | |
| | | export default connect(mapStateToProps, mapDispatchToProps)(ComTableConfig) |