From 6afdec0062dacbded57e166230eb22cc55ced0c1 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 08 五月 2021 14:30:21 +0800 Subject: [PATCH] 2021-05-08 --- src/tabviews/subtable/index.jsx | 646 ++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 403 insertions(+), 243 deletions(-) diff --git a/src/tabviews/subtable/index.jsx b/src/tabviews/subtable/index.jsx index 08fb464..ade1f1d 100644 --- a/src/tabviews/subtable/index.jsx +++ b/src/tabviews/subtable/index.jsx @@ -8,11 +8,9 @@ import zhCN from '@/locales/zh-CN/main.js' import enUS from '@/locales/en-US/main.js' import Utils from '@/utils/utils.js' +import options from '@/store/options.js' import UtilsDM from '@/utils/utils-datamanage.js' -import UtilsUpdate from '@/utils/utils-update.js' -import { modifyTabview } from '@/store/action' - -import SubSearch from '@/tabviews/zshare/topSearch' +import { updateSubTable } from '@/utils/utils-update.js' import asyncComponent from '@/utils/asyncComponent' import asyncSpinComponent from '@/utils/asyncSpinComponent' import NotFount from '@/components/404' @@ -21,6 +19,7 @@ import './index.scss' const { TabPane } = Tabs +const SubSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch')) const SubAction = asyncComponent(() => import('@/tabviews/zshare/actionList')) const SubTable = asyncSpinComponent(() => import('@/tabviews/zshare/normalTable')) const CardComponent = asyncSpinComponent(() => import('@/tabviews/zshare/cardcomponent')) @@ -36,7 +35,6 @@ mainSearch: PropTypes.any, // 涓昏〃鎼滅储鏉′欢 ContainerId: PropTypes.any, // 涓夌骇鑿滃崟Container(html) ID handleTableId: PropTypes.func, // 鎺у埗琛ㄦ牸鏁版嵁鍒囨崲鏃讹紝鏇存柊鍦ㄤ富琛ㄤ腑鐨刬d - userConfig: PropTypes.any, // 鐢ㄦ埛鑷畾涔夎缃� } state = { @@ -48,10 +46,9 @@ searchlist: null, // 鎼滅储鏉′欢 actions: null, // 鎸夐挳闆� columns: null, // 鏄剧ず鍒� - logcolumns: null, // 鏃ュ織涓樉绀虹殑鍒椾俊鎭� (澧炲姞鑷冲叏閮ㄥ垪锛岄櫎鍘诲悎骞跺垪) arr_field: '', // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆� setting: null, // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑 - data: null, // 鍒楄〃鏁版嵁闆� + data: [], // 鍒楄〃鏁版嵁闆� selectedData: [], // 宸查�夎〃鏍兼暟鎹� total: 0, // 鎬绘暟 loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� @@ -62,30 +59,29 @@ pickup: false, // 瀛愯〃鏁版嵁闅愯棌鏄剧ず鍒囨崲 chartId: '', // 灞曞紑鍥捐〃ID statFields: [], // 鍚堣瀛楁 - statFValue: [] // 鍚堣鍊� + statFValue: [], // 鍚堣鍊� + absFields: [], // 缁濆鍊煎瓧娈� + loadCustomApi: true, // 鍔犺浇澶栭儴璧勬簮 + hasReqFields: false } /** * @description 涓婄骇鑿滃崟id鍙樺寲鏃讹紝鍒锋柊鏁版嵁 */ UNSAFE_componentWillReceiveProps(nextProps) { - if (this.state.config && this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) { + const { config, setting } = this.state + + if (config && setting && this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) { MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 鍒楄〃閲嶇疆 this.setState({ pageIndex: 1 }, () => { - if (this.state.setting) { - this.loadmaindata(nextProps.BID, 'refresh') - this.getStatFieldsValue(nextProps.BID, 'refresh') - } + this.loadData() }) - } else if (!this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - if (this.state.setting) { - this.setState({}, () => { - this.loadmaindata() - this.getStatFieldsValue() - }) - } + } else if (setting && !this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { + this.setState({}, () => { + this.loadData() + }) } } @@ -93,7 +89,7 @@ * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅 */ async loadconfig () { - const { permAction, permMenus, Tab, BID, userConfig } = this.props + const { permAction, permMenus, Tab, BID } = this.props let param = { func: 'sPC_Get_LongParam', @@ -105,6 +101,7 @@ try { // 閰嶇疆淇℃伅瑙f瀽 config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) + config.setting.MenuName = Tab.label } catch (e) { console.warn('Parse Failure') config = '' @@ -131,43 +128,33 @@ let _arrField = [] // 瀛楁闆� let _columns = [] // 鏄剧ず鍒� - let _logcolumns = [] // 鏃ュ織鏄剧ず鍒� let _hideCol = [] // 闅愯棌鍙婂悎骞跺垪涓瓧娈电殑uuid闆� let colMap = new Map() let statFields = [] // 鍚堣瀛楁淇℃伅 + let absFields = [] // 缁濆鍊煎瓧娈� // 鐗堟湰鍏煎 - config = UtilsUpdate.updateSubTable(config) + config = updateSubTable(config) // 鏉冮檺杩囨护 if (this.props.menuType !== 'HS') { config.action = config.action.filter(item => permAction[item.uuid]) } + let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID // 瀛楁鏉冮檺榛戝悕鍗� config.search = config.search.map(item => { item.oriInitval = item.initval if (!item.blacklist || item.blacklist.length === 0) return item - - let _black = item.blacklist.filter(v => { - return this.props.permRoles.indexOf(v) !== -1 - }) - - if (_black.length > 0) { + if (item.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) { item.Hide = 'true' } - return item }) config.columns = config.columns.map(col => { - if (!col.field || !col.blacklist || col.blacklist.length === 0 || config.setting.primaryKey === col.field) return col - - let _black = col.blacklist.filter(v => { - return this.props.permRoles.indexOf(v) !== -1 - }) - - if (_black.length > 0) { + if (!col.blacklist || col.blacklist.length === 0) return col + if (col.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) { col.Hide = 'true' } @@ -178,16 +165,7 @@ config.charts = config.charts.filter(item => { if (item.Hide === 'true') return false if (!item.blacklist || item.blacklist.length === 0) return true - - let _black = item.blacklist.filter(v => { - return this.props.permRoles.indexOf(v) !== -1 - }) - - if (_black.length > 0 || item.Hide === 'true') { - return false - } else { - return true - } + return item.blacklist.filter(v => roleId.indexOf(v) > -1).length === 0 }) if (config.charts.length <= 1) { @@ -196,47 +174,28 @@ let chartId = config.charts[0] ? config.charts[0].uuid : '' - if (userConfig) { - config.action = config.action.map(item => { - if (userConfig.action[item.uuid]) { - delete userConfig.action[item.uuid].label - item = {...item, ...userConfig.action[item.uuid]} - } - - if (item.execMode) { - item.OpenType = 'funcbutton' - } - - if (item.OpenType === 'funcbutton' && item.funcType === 'print' && item.verify && item.printer) { - item.verify.defaultPrinter = item.printer.defaultPrinter || '' - if (item.verify.printerTypeList && item.printer.printerList) { - item.verify.printerTypeList = item.verify.printerTypeList.map(cell => { - cell.printer = item.printer.printerList[cell.Value] || '' - - return cell - }) - } - } - - return item - }) - } - // 1銆佺瓫閫夊瓧娈甸泦锛�2銆佽繃婊ら殣钘忓垪鍙婂悎骞跺垪涓殑瀛楁uuid config.columns.forEach(col => { if (col.field) { _arrField.push(col.field) - _logcolumns.push(col) + + if (col.linkmenu && col.linkmenu.length > 0) { + let menu_id = col.linkmenu.slice(-1)[0] + col.linkThdMenu = permMenus.filter(m => m.MenuID === menu_id)[0] || '' + } else { + col.linkThdMenu = '' + } col.nameField && _arrField.push(col.nameField) // 閾炬帴鍚嶅瓧娈� if (col.Hide !== 'true' && col.type === 'number' && col.sum === 'true') { statFields.push(col) } + if (col.format === 'abs') { + absFields.push(col.field) + } } if (col.type === 'colspan' && col.sublist) { // 绛涢�夐殣钘忓垪 _hideCol = _hideCol.concat(col.sublist) - } else if (col.Hide === 'true') { - _hideCol.push(col.uuid) } colMap.set(col.uuid, col) }) @@ -245,25 +204,24 @@ config.columns.forEach((col, index) => { if (_hideCol.includes(col.uuid)) return - if (col.linkmenu && col.linkmenu.length > 0) { - let menu_id = col.linkmenu.slice(-1)[0] - col.linkThdMenu = permMenus.filter(m => m.MenuID === menu_id)[0] || '' - } else { - col.linkThdMenu = '' - } - col.sort = index - if (col.type === 'colspan' && col.sublist) { - let _col = JSON.parse(JSON.stringify(col)) + if (col.type === 'colspan') { + if (col.unfold !== 'true') { // 涓嶅睍寮�涓烘棫鐗堝悎骞跺垪 + col.type = 'old_colspan' + } + + let _col = fromJS(col).toJS() let subcols = [] - _col.sublist.forEach(sub => { + _col.sublist && _col.sublist.forEach(sub => { if (colMap.has(sub)) { subcols.push(colMap.get(sub)) } }) - _col.subcols = subcols - _columns.push(_col) + if (subcols.length > 0) { + _col.subcols = subcols + _columns.push(_col) + } } else { _columns.push(col) } @@ -273,10 +231,23 @@ let _operations = [] // 鎿嶄綔鍒楁寜閽紙瀛樺湪鏃讹級 config.action.forEach(item => { - if (item.execMode) { - item.OpenType = 'funcbutton' - } + item.logLabel = Tab.label + '-' + item.label // 鐢ㄤ簬sPC_TableData_InUpDe璁板綍鎿嶄綔鎸夐挳 + item.$menuId = this.props.MenuID + if (item.OpenType === 'funcbutton' && item.funcType === 'print' && item.verify) { // 鎵撳嵃鏈鸿缃� + let _item = window.GLOB.UserCacheMap.get(Tab.uuid + item.uuid) + + if (_item) { + item.verify.defaultPrinter = _item.printer || '' + if (item.verify.printerTypeList && _item.printerList) { + item.verify.printerTypeList = item.verify.printerTypeList.map(cell => { + cell.printer = _item.printerList[cell.Value] || '' + + return cell + }) + } + } + } if (item.position === 'toolbar') { _actions.push(item) } else if (item.position === 'grid') { @@ -290,27 +261,14 @@ } let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉 + let hasReqFields = false config.search.forEach(field => { - if (field.required === 'true' && !field.initval) { + if (field.required !== 'true') return + hasReqFields = true + if (!field.initval) { valid = false } }) - - // 娣诲姞鐢ㄦ埛鏄剧ず鍒楄缃� - if (userConfig) { - _columns = _columns.map(item => { - if (userConfig.columns[item.uuid]) { - delete userConfig.columns[item.uuid].label - item = {...item, ...userConfig.columns[item.uuid]} - } - - return item - }) - - _columns.sort((pre, next) => { - return pre.sort - next.sort - }) - } config.setting.tabType = 'sub' // 鏁版嵁婧愪俊鎭澶勭悊 @@ -318,7 +276,7 @@ config.setting.execute = config.setting.default !== 'false' // 榛樿sql鏄惁鎵ц锛岃浆涓篵oolean 缁熶竴鏍煎紡 config.setting.customScript = '' // 鑷畾涔夎剼鏈� - if (config.setting.interType === 'system') { + if (config.setting.interType === 'system' || (config.setting.interType === 'custom' && config.setting.requestMode === 'system')) { if (config.setting.scripts && config.setting.scripts.length > 0) { let _customScript = '' config.setting.scripts.forEach(item => { @@ -339,7 +297,7 @@ config.setting.dataresource = '(' + config.setting.dataresource + ') tb' } - if (this.props.dataManager) { // 鏁版嵁鏉冮檺 + if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*') config.setting.dataresource = config.setting.dataresource.replace(/@\$/ig, '*/') config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*') @@ -352,20 +310,20 @@ this.setState({ loadingview: false, - chartId: chartId, - config: config, - statFields: statFields, + chartId, + config, + absFields, + statFields, setting: config.setting, searchlist: config.search, actions: _actions, columns: _columns, - logcolumns: _logcolumns, arr_field: _arrField.join(','), - search: Utils.initMainSearch(config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 + search: Utils.initMainSearch(config.search), // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 + hasReqFields }, () => { if (config.setting.onload !== 'false' && (!Tab.supMenu || BID || Tab.isTreeNode) && valid) { // 鍒濆鍖栧彲鍔犺浇 - this.loadmaindata() - this.getStatFieldsValue() + this.loadData() } }) } else { @@ -382,24 +340,23 @@ }) } } + + loadData = () => { + const { mainSearch, BID } = this.props + const { setting, search, loadCustomApi, hasReqFields } = this.state - /** - * @description 瀛愯〃鏁版嵁鍔犺浇 - */ - async loadmaindata (bid, type) { - const { mainSearch } = this.props - const { setting, arr_field, search, orderBy, pageIndex, pageSize } = this.state - - let _BID = this.props.BID let searches = fromJS(search).toJS() if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 searches = [...mainSearch, ...searches] } - let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0)) - let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : '' - + let requireFields = [] + if (hasReqFields) { + requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0)) + } + if (requireFields.length > 0) { + let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : '' let labels = requireFields.map(item => item.label) labels = Array.from(new Set(labels)) @@ -409,38 +366,256 @@ duration: 3 }) return + } else if (this.props.Tab.supMenu && !BID) { // 涓昏〃ID涓嶅瓨鍦ㄦ椂锛屼笉鏌ヨ瀛愯〃 + this.setState({ + data: [], + selectedData: [], + statFValue: [], + total: 0 + }) + this.handleTableId() + return + } else if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) { + notification.warning({ + top: 92, + message: '鏈缃寮忕郴缁熷湴鍧�!', + duration: 3 + }) + return } - if (type === 'refresh') { - if (!bid) { // 涓昏〃ID涓嶅瓨鍦ㄦ椂锛屼笉鏌ヨ瀛愯〃 - this.setState({ - data: [], - total: 0 - }) - return + this.setState({ + selectedData: [] + }) + this.handleTableId() + + if (setting.interType === 'custom' && loadCustomApi) { + if (setting.execTime === 'once') { + this.setState({loadCustomApi: false}) + } + + this.loadOutResource(searches) + if (setting.execType === 'async') { + this.loadmaindata() + } + } else { + this.loadmaindata() + } + } + + loadOutResource = (searches) => { + const { BID } = this.props + const { setting } = this.state + + let param = UtilsDM.getPrevQueryParams(setting, searches, BID, this.props.menuType) + + if (setting.execType === 'sync') { + this.setState({ + loading: true + }) + } + + Api.genericInterface(param).then(res => { + if (res.status) { + if (res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) { + this.loadmaindata() + } else { + this.customOuterRequest(res) + } } else { - _BID = bid + this.setState({ + loading: false + }) + notification.error({ + top: 92, + message: res.message, + duration: 10 + }) + } + }, () => { + this.setState({ + loading: false + }) + }) + } + + customOuterRequest = (result) => { + const { setting } = this.state + let url = '' + + if (window.GLOB.systemType === 'production') { + url = setting.proInterface + } else { + url = setting.interface + } + + let mkey = result.mk_api_key || '' + + delete result.mk_ex_invoke + delete result.status + delete result.message + delete result.ErrCode + delete result.ErrMesg + delete result.mk_api_key + + let param = {} + + Object.keys(result).forEach(key => { + key = key.replace(/^mk_/ig, '') + param[key] = result[key] + }) + + Api.directRequest(url, setting.method, param, setting.cross).then(res => { + if (typeof(res) !== 'object' || Array.isArray(res)) { + let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒' + + if (typeof(res) === 'string') { + error = res.replace(/'/ig, '"') + } + + let _result = { + mk_api_key: mkey, + $ErrCode: 'E', + $ErrMesg: error + } + + this.customCallbackRequest(_result) + } else { + res.mk_api_key = mkey + this.customCallbackRequest(res) + } + }, (e) => { + let _result = { + mk_api_key: mkey, + $ErrCode: 'E', + $ErrMesg: e && e.statusText ? e.statusText : '' + } + + this.customCallbackRequest(_result) + }) + } + + customCallbackRequest = (result) => { + const { setting } = this.state + let errSql = '' + if (result.$ErrCode === 'E') { + errSql = ` + set @ErrorCode='E' + set @retmsg='${result.$ErrMesg}' + ` + delete result.$ErrCode + delete result.$ErrMesg + } + + let lines = UtilsDM.getCallBackSql(setting, result) + let param = {} + + if (setting.callbackType === 'script') { // 浣跨敤鑷畾涔夎剼鏈� + let sql = lines.map(item => (` + ${item.insert} + ${item.selects.join(` union all + `)} + `)) + sql = sql.join('') + + param = UtilsDM.getCallBackQueryParams(setting, sql, errSql) + + if (this.props.BID) { + param.BID = this.props.BID + } + + if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉 + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) + } + } else { + param.func = 's_ex_result_back' + param.s_ex_result = lines.map((item, index) => ({ + MenuID: this.props.MenuID, + MenuName: this.props.Tab.label, + TableName: item.table, + LongText: window.btoa(window.encodeURIComponent(`${item.insert} ${item.selects.join(` union all `)}`)), + Sort: index + 1 + })) + + if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) { + let sql = lines.map(item => (` + ${item.insert} + ${item.selects.join(` union all + `)} + `)) + sql = sql.join('') + console.info(sql.replace(/\n\s{10}/ig, '\n')) } } + + Api.genericInterface(param).then(res => { + if (res.status) { + this.loadmaindata() + } else { + this.setState({ + loading: false + }) + notification.error({ + top: 92, + message: res.message, + duration: 10 + }) + } + }, () => { + this.setState({ + loading: false + }) + }) + } + + /** + * @description 瀛愯〃鏁版嵁鍔犺浇 + */ + async loadmaindata () { + const { mainSearch, BID } = this.props + const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state + + let searches = fromJS(search).toJS() + if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 + searches = [...mainSearch, ...searches] + } + this.setState({ - selectedData: [], loading: true }) let _orderBy = orderBy || setting.order - let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, _BID, this.props.menuType, this.props.dataManager) - - this.handleTableId() + let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType) if (param.func === 'sPC_Get_TableData') { param.menuname = this.props.Tab.label || '' } let result = await Api.genericInterface(param) + + this.getStatFieldsValue(searches) + if (result.status) { + let start = 1 + if (setting.laypage) { + start = pageSize * (pageIndex - 1) + 1 + } + this.setState({ data: result.data.map((item, index) => { + if (absFields.length) { + absFields.forEach(field => { + if (!item[field]) return + if (isNaN(Math.abs(item[field]))) return + + item[field] = Math.abs(item[field]) + }) + } item.key = index + item.$$uuid = item[setting.primaryKey] || '' + item.$$BID = BID || '' + item.$Index = start + index + return item }), total: result.total, @@ -448,6 +623,7 @@ loading: false }) } else { + let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : '' this.setState({ loading: false }) @@ -465,7 +641,7 @@ */ async loadmainLinedata (id) { const { mainSearch, BID } = this.props - const { setting, arr_field, search, orderBy, pageIndex, pageSize } = this.state + const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state let searches = fromJS(search).toJS() if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 @@ -477,7 +653,7 @@ }) let _orderBy = orderBy || setting.order - let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, this.props.dataManager, id) + let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id) if (param.func === 'sPC_Get_TableData') { param.menuname = this.props.Tab.label || '' @@ -486,17 +662,37 @@ let result = await Api.genericInterface(param) if (result.status) { let data = fromJS(this.state.data).toJS() + let selectedData = fromJS(this.state.selectedData).toJS() if (result.data && result.data[0]) { - let _data = result.data[0] + let _data = result.data[0] || {} + + if (absFields.length) { + absFields.forEach(field => { + if (!_data[field]) return + if (isNaN(Math.abs(_data[field]))) return + + _data[field] = Math.abs(_data[field]) + }) + } + + _data.$$uuid = _data[setting.primaryKey] || '' + _data.$$BID = BID || '' try { data = data.map(item => { - if (item[setting.primaryKey] === _data[setting.primaryKey]) { + if (item.$$uuid === _data.$$uuid) { _data.key = item.key + _data.$Index = item.$Index return _data } else { return item } + }) + selectedData = selectedData.map(item => { + if (_data.$$uuid === item.$$uuid) { + return _data + } + return item }) } catch { console.warn('鏁版嵁鏌ヨ閿欒') @@ -504,7 +700,8 @@ } this.setState({ - data: data, + data, + selectedData, loading: false }) } else { @@ -522,36 +719,14 @@ /** * @description 鑾峰彇鍚堣瀛楁鍊� */ - getStatFieldsValue = (bid, type) => { - const { mainSearch } = this.props - const { setting, search, orderBy, statFields } = this.state + getStatFieldsValue = (searches) => { + const { BID } = this.props + const { setting, orderBy, statFields } = this.state - let _BID = this.props.BID - let searches = fromJS(search).toJS() - if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - searches = [...mainSearch, ...searches] - } - - if (statFields.length === 0 || setting.interType !== 'system' || !setting.dataresource) return - - let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0)) - if (requireFields.length > 0) { - return - } - - if (type === 'refresh') { - if (!bid) { // 涓昏〃ID涓嶅瓨鍦ㄦ椂锛屼笉鏌ヨ瀛愯〃鍚堣鍊� - this.setState({ - statFValue: [] - }) - return - } else { - _BID = bid - } - } + if (statFields.length === 0 || !(setting.interType === 'system' || (setting.interType === 'custom' && setting.requestMode === 'system')) || !setting.dataresource) return let _orderBy = orderBy || setting.order - let param = UtilsDM.getStatQueryDataParams(setting, statFields, searches, _orderBy, _BID, this.props.menuType, this.props.dataManager) + let param = UtilsDM.getStatQueryDataParams(setting, statFields, searches, _orderBy, BID, this.props.menuType) if (param.func === 'sPC_Get_TableData') { param.menuname = this.props.Tab.label || '' @@ -600,8 +775,7 @@ pageIndex: 1, search: searches, }, () => { - this.loadmaindata() - this.getStatFieldsValue() + this.loadData() }) } @@ -622,7 +796,7 @@ pageSize: pagination.pageSize, orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : '' }, () => { - this.loadmaindata() + this.loadData() }) } @@ -635,59 +809,34 @@ this.setState({ pageIndex: 1 }, () => { - this.loadmaindata() - this.getStatFieldsValue() + this.loadData() }) } else { MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid, 'false') // 鍒楄〃閲嶇疆 - this.loadmaindata() - this.getStatFieldsValue() - } - } - - /** - * @description 鎸夐挳鎿嶄綔瀹屾垚鍚庯紙鎴愬姛鎴栧け璐ワ級锛岄〉闈㈠埛鏂帮紝閲嶇疆椤电爜鍙婇�夋嫨椤� - */ - refreshbyaction = (position, btn) => { - const { Tab, SupMenuID, BID } = this.props - - if (position === 'grid' || position === 'view') { - this.reloadtable(btn) - } else if (position === 'maingrid' || position === 'mainline') { - this.reloadtable(btn) - if (Tab.supMenu === 'mainTable') { - MKEmitter.emit('reloadData', SupMenuID, (BID || 'empty')) // 涓昏〃閲嶇疆 - } else if (Tab.supMenu) { - MKEmitter.emit('reloadData', Tab.supMenu, (BID || 'empty')) // 涓昏〃閲嶇疆 - } else if (!Tab.supMenu && Tab.level === 0) { - MKEmitter.emit('reloadData', SupMenuID, (BID || 'empty')) // 鏍戝舰缁撴瀯锛�0绾ф爣绛� - } - } else if (position === 'equaltab') { - this.reloadtable(btn) - if (Tab.equalTab && Tab.equalTab.length > 0) { - MKEmitter.emit('reloadData', Tab.equalTab.join(',')) // 鍚岀骇鏍囩閲嶇疆 - } + this.loadData() } } /** * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ - getexceloutparam = () => { - const { Tab, mainSearch } = this.props + getexceloutparam = (menuId, btnId) => { + const { Tab, mainSearch, MenuID } = this.props const { arr_field, orderBy, search, setting} = this.state + + if (MenuID !== menuId) return let searches = search if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 searches = [...mainSearch, ...search] } - return { + MKEmitter.emit('execExcelout', MenuID, btnId, { arr_field: arr_field, orderBy: orderBy || setting.order, search: searches, menuName: Tab.label - } + }) } /** @@ -722,7 +871,7 @@ this.setState({chartId: uuid}) } - reloadData = (menuId, id) => { + reloadData = (menuId, id) => { // Id瀛樺湪鏃讹紝鍒锋柊琛� const { MenuID } = this.props if (menuId.indexOf(MenuID) === -1) return @@ -732,6 +881,38 @@ this.reloadtable() } else { this.loadmainLinedata(id) + } + } + + /** + * @description 鎸夐挳鎵ц瀹屾垚鍚庨〉闈㈠埛鏂� + * @param {*} menuId // 鑿滃崟Id + * @param {*} position // 鍒锋柊浣嶇疆 + * @param {*} btn // 鎵ц鐨勬寜閽� + */ + refreshByButtonResult = (menuId, position, btn) => { + const { MenuID } = this.props + + if (MenuID !== menuId) return + + const { Tab, SupMenuID, BID } = this.props + + if (position === 'grid' || position === 'view') { + this.reloadtable(btn) + } else if (position === 'maingrid' || position === 'mainline') { + this.reloadtable(btn) + if (Tab.supMenu === 'mainTable') { + MKEmitter.emit('reloadData', SupMenuID, (BID || 'empty')) // 涓昏〃閲嶇疆 + } else if (Tab.supMenu) { + MKEmitter.emit('reloadData', Tab.supMenu, (BID || 'empty')) // 涓昏〃閲嶇疆 + } else if (!Tab.supMenu && Tab.level === 0) { + MKEmitter.emit('reloadData', SupMenuID, (BID || 'empty')) // 鏍戝舰缁撴瀯锛�0绾ф爣绛� + } + } else if (position === 'equaltab') { + this.reloadtable(btn) + if (Tab.equalTab && Tab.equalTab.length > 0) { + MKEmitter.emit('reloadData', Tab.equalTab.join(',')) // 鍚岀骇鏍囩閲嶇疆 + } } } @@ -746,6 +927,8 @@ componentDidMount () { MKEmitter.addListener('reloadData', this.reloadData) + MKEmitter.addListener('getexceloutparam', this.getexceloutparam) + MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) } /** @@ -756,6 +939,8 @@ return } MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('getexceloutparam', this.getexceloutparam) + MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) } render() { @@ -764,15 +949,8 @@ return ( <div className="subtable" id={'subtable' + this.props.MenuID}> {loadingview && <Spin />} - {searchlist && searchlist.length > 0 ? - <SubSearch - BID={this.props.BID} - dict={this.state.dict} - searchlist={searchlist} - menuType={this.props.menuType} - dataManager={this.props.dataManager} - refreshdata={this.refreshbysearch} - /> : null + {searchlist && searchlist.length ? + <SubSearch BID={this.props.BID} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null } {config ? <Row className="chart-view" gutter={16}> {/* 瑙嗗浘缁� */} @@ -791,43 +969,35 @@ <SubAction setting={setting} actions={actions} + columns={columns} Tab={this.props.Tab} BID={this.props.BID} BData={this.props.BData} MenuID={this.props.MenuID} selectedData={selectedData} - MenuName={this.props.Tab.label} - logcolumns={this.state.logcolumns} - refreshdata={this.refreshbyaction} ContainerId={this.props.ContainerId} - getexceloutparam={this.getexceloutparam} /> </div> <div className="subtable-box"> {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && this.state.data && this.state.data.length > 0 ? - <Switch title="鏀惰捣" className="subtable-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null + <Switch title="鏀惰捣" className="subtable-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" checked={pickup} onChange={this.pickupChange} /> : null } <SubTable tableId={this.props.Tab.uuid} pickup={pickup} - config={config} setting={setting} columns={columns} pageSize={pageSize} - BID={this.props.BID} dict={this.state.dict} data={this.state.data} BData={this.props.BData} total={this.state.total} MenuID={this.props.MenuID} loading={this.state.loading} - MenuName={this.props.Tab.label} - refreshdata={this.refreshbytable} - logcolumns={this.state.logcolumns} statFValue={this.state.statFValue} - handleTableId={this.handleTableId} ContainerId={this.props.ContainerId} - refreshbyaction={this.refreshbyaction} + refreshdata={this.refreshbytable} + handleTableId={this.handleTableId} chgSelectData={this.changeSelectedData} /> </div> @@ -839,6 +1009,7 @@ <CardComponent plot={item} config={config} + columns={columns} Tab={this.props.Tab} BID={this.props.BID} BData={this.props.BData} @@ -846,11 +1017,7 @@ MenuID={this.props.MenuID} loading={this.state.loading} tableId={this.props.Tab.uuid} - MenuName={this.props.Tab.label} - logcolumns={this.state.logcolumns} - refreshdata={this.refreshbyaction} handleTableId={this.handleTableId} - getexceloutparam={this.getexceloutparam} /> </Col> ) @@ -863,8 +1030,6 @@ BID={this.props.BID} Tab={this.props.Tab} data={this.state.data} - MenuName={this.props.Tab.label} - getexceloutparam={this.getexceloutparam} loading={this.state.loading} /> </Col> @@ -880,19 +1045,14 @@ const mapStateToProps = (state) => { return { - tabviews: state.tabviews, menuType: state.editLevel, permAction: state.permAction, - permRoles: state.permRoles, permMenus: state.permMenus, - dataManager: state.dataManager, } } -const mapDispatchToProps = (dispatch) => { - return { - modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)) - } +const mapDispatchToProps = () => { + return {} } export default connect(mapStateToProps, mapDispatchToProps)(SubTabViewTable) \ No newline at end of file -- Gitblit v1.8.0