From 95f2f60ba9eb343c2605e1ae68c221443d75f704 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 30 十一月 2019 00:55:07 +0800 Subject: [PATCH] commontable-update --- src/tabviews/commontable/mainAction/index.jsx | 488 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 429 insertions(+), 59 deletions(-) diff --git a/src/tabviews/commontable/mainAction/index.jsx b/src/tabviews/commontable/mainAction/index.jsx index 277e536..4124488 100644 --- a/src/tabviews/commontable/mainAction/index.jsx +++ b/src/tabviews/commontable/mainAction/index.jsx @@ -13,7 +13,7 @@ MenuID: PropTypes.string, actions: PropTypes.array, // 鎼滅储鏉′欢鍒楄〃 dict: PropTypes.object, // 瀛楀吀椤� - fixed: PropTypes.any + setting: PropTypes.any } state = { @@ -21,29 +21,40 @@ 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 } @@ -52,45 +63,377 @@ 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 = () => { @@ -151,11 +494,53 @@ } 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} @@ -164,26 +549,11 @@ 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> - ) } } -- Gitblit v1.8.0