| | |
| | | MenuID: PropTypes.string, |
| | | actions: PropTypes.array, // 搜索条件列表 |
| | | dict: PropTypes.object, // 字典项 |
| | | fixed: PropTypes.any |
| | | setting: PropTypes.any |
| | | } |
| | | |
| | | state = { |
| | |
| | | formdata: null, |
| | | tabledata: null, |
| | | confirmLoading: false, |
| | | execAction: null |
| | | execAction: null, |
| | | loadingUuid: '' |
| | | } |
| | | |
| | | refreshdata = () => { |
| | | this.props.refreshdata() |
| | | refreshdata = (item, type) => { |
| | | this.props.refreshdata(item, type) |
| | | } |
| | | actionTrigger = (item) => { |
| | | const { setting } = this.props |
| | | let _this = this |
| | | let data = this.props.gettableselected() || [] |
| | | console.log(item) |
| | | console.log(data) |
| | | |
| | | if (item.Ot !== 'notRequired' && data.length === 0) { |
| | | // 需要选择行时,校验数据 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.props.dict['main.action.confirm.selectline'] |
| | | message: this.props.dict['main.action.confirm.selectline'], |
| | | duration: 10 |
| | | }) |
| | | return |
| | | } else if (item.Ot === 'requiredSgl' && data.length !== 1) { |
| | | // 需要选择单行时,校验数据 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.props.dict['main.action.confirm.selectSingleLine'] |
| | | message: this.props.dict['main.action.confirm.selectSingleLine'], |
| | | duration: 10 |
| | | }) |
| | | return |
| | | } else if (item.Ot !== 'notRequired' && !setting.primaryKey) { |
| | | // 需要选择行时,校验是否设置主键 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未设置主键!', |
| | | duration: 10 |
| | | }) |
| | | return |
| | | } |
| | |
| | | confirm({ |
| | | title: this.props.dict['main.action.confirm.tip'], |
| | | onOk() { |
| | | return Api.setActionSubmit({ |
| | | func: 'SetActionSubmitSuccess' |
| | | // func: 'SetActionSubmitError' |
| | | }).then((res) => { |
| | | if (res.status) { |
| | | notification.success({ |
| | | top: 92, |
| | | message: _this.props.dict['main.action.confirm.success'] |
| | | // duration: 0 |
| | | // description: |
| | | }) |
| | | _this.refreshdata() |
| | | } else { |
| | | notification.error({ |
| | | top: 92, |
| | | message: res.message |
| | | }) |
| | | } |
| | | return new Promise(resolve => { |
| | | _this.execSubmit(item, data, resolve) |
| | | }) |
| | | }, |
| | | onCancel() {} |
| | | }) |
| | | } else if (item.OpenType === 'exec') { |
| | | Api.getModelFormData(item.MenuID).then(res => { |
| | | if (res.status) { |
| | | this.setState({ |
| | | formdata: res.data.map(input => { |
| | | let validate = input.Validate && JSON.parse(input.Validate) |
| | | input.DynOptions = JSON.parse(input.DynOptions) |
| | | input.required = (validate && validate.required) || false |
| | | return input |
| | | }), |
| | | visible: true, |
| | | execAction: item, |
| | | tabledata: data[0] |
| | | }) |
| | | } |
| | | this.setState({loadingUuid: item.uuid}) |
| | | this.execSubmit(item, data, () => { |
| | | this.setState({loadingUuid: ''}) |
| | | }) |
| | | } |
| | | } |
| | | |
| | | execSubmit = (btn, data, _resolve) => { |
| | | const { setting } = this.props |
| | | if (btn.intertype === 'inner') { |
| | | // 使用内部接口时,内部函数和数据源不可同时为空 |
| | | if (!btn.innerFunc && !btn.sql) { |
| | | this.actionSettingError() |
| | | _resolve() |
| | | return |
| | | } |
| | | |
| | | if (btn.Ot === 'notRequired' || btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce') { |
| | | // 获取id |
| | | let param = { |
| | | func: 'sPC_TableData_InUpDe' |
| | | } |
| | | let ID = '' |
| | | if (btn.Ot === 'notRequired') { |
| | | |
| | | } else if (btn.Ot === 'requiredSgl') { |
| | | ID = data[0][setting.primaryKey] |
| | | } else if (btn.Ot === 'requiredOnce') { |
| | | let ids = data.map(d => { return d[setting.primaryKey]}) |
| | | ID = ids.join(',') |
| | | } |
| | | |
| | | if (btn.innerFunc) { |
| | | param.func = btn.innerFunc |
| | | param.ID = ID |
| | | param.BID = '' |
| | | } else if (btn.sql) { |
| | | param.LText = btn.sql // 数据源 |
| | | } |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(btn) |
| | | } else { |
| | | this.execError(res, btn) |
| | | } |
| | | _resolve() |
| | | }) |
| | | } else if (btn.Ot === 'required') { |
| | | let deffers = data.map(cell => { |
| | | let param = { |
| | | func: 'sPC_TableData_InUpDe' |
| | | } |
| | | let ID = cell[setting.primaryKey] |
| | | |
| | | if (btn.innerFunc) { |
| | | param.func = btn.innerFunc |
| | | param.ID = ID |
| | | param.BID = '' |
| | | } else if (btn.sql) { |
| | | param.LText = btn.sql // 数据源 |
| | | } |
| | | |
| | | return new Promise(resolve => { |
| | | Api.genericInterface(param).then(res => { |
| | | resolve(res) |
| | | }) |
| | | }) |
| | | }) |
| | | Promise.all(deffers).then(result => { |
| | | let iserror = false |
| | | let errorMsg = '' |
| | | result.forEach(res => { |
| | | if (res.status) { |
| | | |
| | | } else { |
| | | iserror = true |
| | | errorMsg = res.message |
| | | } |
| | | }) |
| | | if (!iserror) { |
| | | this.execSuccess(btn) |
| | | } else { |
| | | notification.error({ |
| | | top: 92, |
| | | message: errorMsg, |
| | | duration: 15 |
| | | }) |
| | | this.refreshdata(btn, 'error') |
| | | } |
| | | _resolve() |
| | | }) |
| | | } else { |
| | | this.actionSettingError() |
| | | _resolve() |
| | | return |
| | | } |
| | | } else if (btn.intertype === 'outer') { |
| | | /** *********************调用外部接口************************* */ |
| | | let param = { |
| | | ID: '', |
| | | BID: '' |
| | | } |
| | | |
| | | if (!btn.interface) { // 接口地址不存在时报错 |
| | | this.actionSettingError() |
| | | _resolve() |
| | | return |
| | | } |
| | | |
| | | if (btn.Ot === 'notRequired' || btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce') { |
| | | // 获取id |
| | | if (btn.Ot === 'notRequired') { |
| | | |
| | | } else if (btn.Ot === 'requiredSgl') { |
| | | param.ID = data[0][setting.primaryKey] |
| | | } else if (btn.Ot === 'requiredOnce') { |
| | | let ids = data.map(d => { return d[setting.primaryKey]}) |
| | | param.ID = ids.join(',') |
| | | } |
| | | |
| | | new Promise(resolve => { |
| | | // 内部请求 |
| | | if (btn.innerFunc) { |
| | | param.func = btn.innerFunc |
| | | // 存在内部函数时,数据预处理 |
| | | Api.genericInterface(param).then(res => { |
| | | if (res.status) { |
| | | delete res.ErrCode |
| | | delete res.ErrMesg |
| | | delete res.message |
| | | delete res.status |
| | | |
| | | res.rduri = btn.interface |
| | | // res.method = btn.method |
| | | if (btn.outerFunc) { |
| | | res.func = btn.outerFunc |
| | | } |
| | | // 使用处理后的数据调用外部接口 |
| | | resolve(res) |
| | | } else { |
| | | this.execError(res, btn) |
| | | _resolve() |
| | | } |
| | | }) |
| | | } else { |
| | | // 不存在内部函数时,生成外部请求参数 |
| | | param.rduri = btn.interface |
| | | // param.method = btn.method |
| | | if (btn.outerFunc) { |
| | | param.func = btn.outerFunc |
| | | } |
| | | resolve(param) |
| | | } |
| | | }).then(res => { |
| | | if (!res) return |
| | | // 外部请求 |
| | | console.log(res) |
| | | return Api.genericInterface(res) |
| | | }).then(response => { |
| | | // 回调请求 |
| | | if (response.status) { |
| | | if (btn.callbackFunc) { |
| | | // 存在回调函数时,调用 |
| | | delete response.ErrCode |
| | | delete response.ErrMesg |
| | | delete response.message |
| | | delete response.status |
| | | |
| | | response.func = btn.callbackFunc |
| | | return Api.genericInterface(response) |
| | | } else { |
| | | this.execSuccess(btn) |
| | | _resolve() |
| | | } |
| | | } else { |
| | | this.execError(response, btn) |
| | | _resolve() |
| | | } |
| | | }).then(res => { |
| | | if (!res) return |
| | | |
| | | if (res.status) { |
| | | this.execSuccess(btn) |
| | | } else { |
| | | this.execError(res, btn) |
| | | } |
| | | _resolve() |
| | | }) |
| | | |
| | | } else if (btn.Ot === 'required') { |
| | | // 选择多行,循环调用 |
| | | |
| | | new Promise(resolve => { |
| | | // 内部请求 |
| | | if (btn.innerFunc) { |
| | | let deffers = data.map(cell => { |
| | | let _param = { |
| | | BID: '', |
| | | func: btn.innerFunc |
| | | } |
| | | _param.ID = cell[setting.primaryKey] |
| | | return new Promise(resolve => { |
| | | Api.genericInterface(_param).then(res => { |
| | | resolve(res) |
| | | }) |
| | | }) |
| | | }) |
| | | Promise.all(deffers).then(result => { |
| | | let iserror = false |
| | | let errorMsg = '' |
| | | result.forEach(res => { |
| | | if (!res.status) { |
| | | iserror = true |
| | | errorMsg = res.message |
| | | } |
| | | }) |
| | | if (!iserror) { |
| | | resolve(result) |
| | | } else { |
| | | notification.error({ |
| | | top: 92, |
| | | message: errorMsg, |
| | | duration: 15 |
| | | }) |
| | | this.refreshdata(btn, 'error') |
| | | _resolve() |
| | | } |
| | | }) |
| | | } else { |
| | | let params = data.map(cell => { |
| | | return { |
| | | BID: '', |
| | | ID: cell[setting.primaryKey] |
| | | } |
| | | }) |
| | | resolve(params) |
| | | } |
| | | }).then(result => { |
| | | // 外部请求 |
| | | if (!result) return |
| | | |
| | | let deffers = result.map(res => { |
| | | delete res.ErrCode |
| | | delete res.ErrMesg |
| | | delete res.message |
| | | delete res.status |
| | | |
| | | res.rduri = btn.interface |
| | | // res.method = btn.method |
| | | if (btn.outerFunc) { |
| | | res.func = btn.outerFunc |
| | | } |
| | | return new Promise(resolve => { |
| | | Api.genericInterface(res).then(response => { |
| | | resolve(response) |
| | | }) |
| | | }) |
| | | }) |
| | | return Promise.all(deffers) |
| | | |
| | | }).then(result => { |
| | | // 回调请求 |
| | | let iserror = false |
| | | let errorMsg = '' |
| | | result.forEach(res => { |
| | | if (!res.status) { |
| | | iserror = true |
| | | errorMsg = res.message |
| | | } |
| | | }) |
| | | if (iserror) { |
| | | notification.error({ |
| | | top: 92, |
| | | message: errorMsg, |
| | | duration: 15 |
| | | }) |
| | | this.refreshdata(btn, 'error') |
| | | _resolve() |
| | | return |
| | | } |
| | | |
| | | if (btn.callbackFunc) { |
| | | // 存在回调函数时,调用 |
| | | let deffers = result.map(res => { |
| | | delete res.ErrCode |
| | | delete res.ErrMesg |
| | | delete res.message |
| | | delete res.status |
| | | |
| | | res.func = btn.callbackFunc |
| | | return new Promise(resolve => { |
| | | Api.genericInterface(res).then(response => { |
| | | resolve(response) |
| | | }) |
| | | }) |
| | | }) |
| | | return Promise.all(deffers) |
| | | } else { |
| | | _resolve() |
| | | this.execSuccess(btn) |
| | | } |
| | | }).then(result => { |
| | | if (!result) return |
| | | |
| | | let iserror = false |
| | | let errorMsg = '' |
| | | result.forEach(res => { |
| | | if (!res.status) { |
| | | iserror = true |
| | | errorMsg = res.message |
| | | } |
| | | }) |
| | | if (iserror) { |
| | | notification.error({ |
| | | top: 92, |
| | | message: errorMsg, |
| | | duration: 15 |
| | | }) |
| | | this.refreshdata(btn, 'error') |
| | | return |
| | | } else { |
| | | this.execSuccess(btn) |
| | | } |
| | | _resolve() |
| | | }) |
| | | |
| | | } else { |
| | | this.actionSettingError() |
| | | _resolve() |
| | | return |
| | | } |
| | | |
| | | } else { |
| | | this.actionSettingError() |
| | | _resolve() |
| | | return |
| | | } |
| | | } |
| | | |
| | | execSuccess = (btn) => { |
| | | notification.success({ |
| | | top: 92, |
| | | message: this.props.dict['main.action.confirm.success'], |
| | | duration: 5 |
| | | }) |
| | | this.refreshdata(btn, 'success') |
| | | } |
| | | |
| | | execError = (res, btn) => { |
| | | notification.error({ |
| | | top: 92, |
| | | message: res.message, |
| | | duration: 15 |
| | | }) |
| | | this.refreshdata(btn, 'error') |
| | | } |
| | | |
| | | actionSettingError = () => { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.props.dict['main.action.settingerror'], |
| | | duration: 10 |
| | | }) |
| | | } |
| | | |
| | | getModels = () => { |
| | |
| | | } |
| | | |
| | | render() { |
| | | if (this.props.fixed) { // 按钮是否固定在头部 |
| | | const { loadingUuid } = this.state |
| | | |
| | | if (this.props.setting.actionfixed) { // 按钮是否固定在头部 |
| | | return ( |
| | | <Affix offsetTop={48}> |
| | | <div className="button-list" id={this.props.MenuID + 'mainaction'}> |
| | | {this.props.actions.map((item, index) => { |
| | | if (loadingUuid === item.uuid) { |
| | | return ( |
| | | <Button |
| | | className={'mk-btn mk-' + item.class} |
| | | icon={item.icon} |
| | | key={'action' + index} |
| | | onClick={() => {this.actionTrigger(item)}} |
| | | loading |
| | | >{item.label}</Button> |
| | | ) |
| | | } else { |
| | | return ( |
| | | <Button |
| | | className={'mk-btn mk-' + item.class} |
| | | icon={item.icon} |
| | | key={'action' + index} |
| | | onClick={() => {this.actionTrigger(item)}} |
| | | >{item.label}</Button> |
| | | ) |
| | | } |
| | | })} |
| | | {this.getModels()} |
| | | </div> |
| | | </Affix> |
| | | ) |
| | | } else { |
| | | return ( |
| | | <div className="button-list"> |
| | | {this.props.actions.map((item, index) => { |
| | | if (loadingUuid === item.uuid) { |
| | | return ( |
| | | <Button |
| | | className={'mk-btn mk-' + item.class} |
| | | icon={item.icon} |
| | | key={'action' + index} |
| | | onClick={() => {this.actionTrigger(item)}} |
| | | loading |
| | | >{item.label}</Button> |
| | | ) |
| | | } else { |
| | | return ( |
| | | <Button |
| | | className={'mk-btn mk-' + item.class} |
| | |
| | | onClick={() => {this.actionTrigger(item)}} |
| | | >{item.label}</Button> |
| | | ) |
| | | })} |
| | | {this.getModels()} |
| | | </div> |
| | | </Affix> |
| | | } |
| | | })} |
| | | </div> |
| | | ) |
| | | } |
| | | return ( |
| | | <div className="button-list"> |
| | | {this.props.actions.map((item, index) => { |
| | | return ( |
| | | <Button |
| | | className={'mk-btn mk-' + item.class} |
| | | icon={item.icon} |
| | | key={'action' + index} |
| | | onClick={() => {this.actionTrigger(item)}} |
| | | >{item.label}</Button> |
| | | ) |
| | | })} |
| | | </div> |
| | | ) |
| | | } |
| | | } |
| | | |