From 0c439ced2c97905cb2b02f5f689a37b19369fb8a Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 22 七月 2022 15:00:58 +0800 Subject: [PATCH] 2022-07-22 --- src/tabviews/formtab/index.jsx | 430 ++++++++++++++++++++++++++++++----------------------- 1 files changed, 246 insertions(+), 184 deletions(-) diff --git a/src/tabviews/formtab/index.jsx b/src/tabviews/formtab/index.jsx index e0a108c..9c15dfd 100644 --- a/src/tabviews/formtab/index.jsx +++ b/src/tabviews/formtab/index.jsx @@ -2,30 +2,30 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { notification, Spin, Tabs, Icon} from 'antd' +import { notification, Spin, Tabs} from 'antd' import moment from 'moment' import Api from '@/api' 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 asyncComponent from '@/utils/asyncLoadComponent' +import MKEmitter from '@/utils/events.js' +import MkIcon from '@/components/mk-icon' import FormGroup from './formgroup' import FormAction from './actionList' -import SubTable from '@/tabviews/subtable' import NotFount from '@/components/404' -import {refreshTabView, modifyTabview} from '@/store/action' import './index.scss' const { TabPane } = Tabs +const SubTable = asyncComponent(() => import('@/tabviews/subtable')) +const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage')) class NormalTable extends Component { static propTpyes = { - // MenuNo: PropTypes.string, // 鑿滃崟鍙傛暟 - // MenuName: PropTypes.string, // 鑿滃崟鍙傛暟 MenuID: PropTypes.string, // 鑿滃崟Id param: PropTypes.any, // 涓昏〃浼犻�掑弬鏁� - refresh: PropTypes.any // 鍒锋柊涓昏〃椤甸潰 } state = { @@ -40,34 +40,28 @@ arr_field: '', // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆� setting: null, // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑 data: null, // 鍒楄〃鏁版嵁闆� - configMap: {}, // 椤甸潰閰嶇疆淇℃伅锛氫笅鎷夈�佹寜閽瓑 BIDs: {}, // 涓婄骇琛╥d - setsingle: false, // 涓昏〃鍗曢�夊閫夊垏鎹� - pickup: false, // 涓昏〃鏁版嵁闅愯棌鏄剧ず鍒囨崲 - popData: false, // 寮规椤甸潰锛屾墍閫夌殑琛ㄦ牸鏁版嵁 - visible: false, // 寮规鏄剧ず闅愯棌鎺у埗 primaryId: null, - refreshtabs: null } /** * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅 */ async loadconfig () { - const { permAction } = this.props + const { permAction, MenuID } = this.props let param = { func: 'sPC_Get_LongParam', - MenuID: this.props.MenuID + MenuID: MenuID } - let result = await Api.getSystemCacheConfig(param) + let result = await Api.getCacheConfig(param) if (result.status) { let config = '' try { // 閰嶇疆淇℃伅瑙f瀽 - config = window.decodeURIComponent(window.atob(result.LongParam)) - config = JSON.parse(config) + config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) } catch (e) { + console.warn('Parse Failure') config = '' } @@ -90,27 +84,67 @@ return } - let _arrField = [] // 瀛楁闆� + // 鍏煎鏍囩 + if (!config.tabgroups) { + config.tabgroups = [{ uuid: 'tabs', sublist: [] }] + } else if (typeof(config.tabgroups[0]) === 'string') { + let _tabgroups = [] + config.tabgroups.forEach(groupId => { + let _group = { + uuid: groupId, + sublist: fromJS(config[groupId]).toJS() + } + + delete config[groupId] + + _tabgroups.push(_group) + }) + + config.tabgroups = _tabgroups + } - // if (this.props.param && this.props.param.arr_field) { // 浣跨敤鏄剧ず鍒楀瓧娈垫煡璇� - // _arrField = this.props.param.arr_field - // } else { + if (!window.GLOB.mkHS) { + config.action = config.action.filter(item => permAction[item.uuid]) + config.tabgroups.forEach(group => { + group.sublist = group.sublist.filter(tab => { + if (tab.supMenu === 'mainTable') { + tab.supMenu = MenuID + } + return permAction[tab.linkTab] + }) + }) + } else { + config.tabgroups.forEach(group => { + group.sublist = group.sublist.filter(tab => { + if (tab.supMenu === 'mainTable') { + tab.supMenu = MenuID + } + return true + }) + }) + } + + // 鎸夐挳绫诲瀷鍏煎 + config.action = config.action.map(item => { + if (item.intertype === 'inner' && !item.innerFunc) { + item.intertype = 'system' + } + return item + }) + + let _arrField = [config.setting.primaryKey] // 瀛楁闆� , 榛樿娣诲姞涓婚敭 + let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID + config.groups.forEach(group => { - group.sublist.forEach(item => { - if (!item.field) return - - _arrField.push(item.field) + group.sublist = group.sublist.filter(item => { + item.field && _arrField.push(item.field) + if (!item.blacklist || item.blacklist.length === 0) { + return true + } + return item.blacklist.filter(v => roleId.indexOf(v) > -1).length === 0 }) }) _arrField = _arrField.join(',') - // } - - // 鏉冮檺杩囨护 - config.action = config.action.filter(item => permAction[item.uuid]) - // config.tabgroups.forEach(group => { - // if (!config[group]) return - // config[group] = config[group].filter(tab => permAction[tab.uuid]) - // }) this.setState({ config: config, @@ -118,16 +152,22 @@ actions: config.action, arr_field: _arrField, primaryId: this.props.param.primaryId || '', - data: config.setting.datatype === 'query' ? null : this.props.param.data, + data: this.props.param.data || null, BIDs: { - mainTable: this.props.param.primaryId || '', - mainTabledata: config.setting.datatype === 'query' ? '' : this.props.param.data + [MenuID]: config.setting.onload !== 'false' ? (this.props.param.primaryId || '') : '', + [MenuID + 'data']: config.setting.onload !== 'false' ? (config.setting.datatype === 'query' ? '' : this.props.param.data) : '' } }, () => { this.improveSelectOption(config.groups) - if (config.setting.datatype === 'query' && this.props.param.primaryId) { + if (config.setting.datatype === 'query' && config.setting.onload !== 'false') { this.loadmaindata() + } else if (config.setting.datatype !== 'query' && (!this.props.param.primaryId || !this.props.param.data)) { + notification.warning({ + top: 92, + message: '鏈幏鍙栧埌涓昏〃鏁版嵁锛�', + duration: 5 + }) } }) } else { @@ -138,7 +178,7 @@ notification.warning({ top: 92, message: result.message, - duration: 10 + duration: 5 }) } } @@ -156,14 +196,13 @@ item.options.unshift({ key: Utils.getuuid(), Value: '', - Text: this.state.dict['main.all'] + Text: '鍏ㄩ儴' }) } if (item.resourceType === '1' && item.dataSource) { let _option = Utils.getSelectQueryOptions(item) let _sql = Utils.formatOptions(_option.sql) - let isSSO = item.database === 'sso' let param = { func: 'sPC_Get_SelectedList', @@ -172,11 +211,23 @@ arr_field: _option.field } - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) + + if (window.GLOB.mkHS) { // 浜戠鏁版嵁楠岃瘉 + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) + + if (item.database === 'sso' && options.cloudServiceApi) { // 瀛樺湪浜戠鍦板潃鏃讹紝浣跨敤浜戠绯荤粺鍙傛暟 + param.rduri = options.cloudServiceApi + param.userid = sessionStorage.getItem('CloudUserID') || '' + param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' + } + } else if (item.database === 'sso' && window.GLOB.mainSystemApi && window.GLOB.systemType === 'production') { + param.rduri = window.GLOB.mainSystemApi + } let defer = new Promise(resolve => { - Api.getSystemCacheConfig(param, isSSO).then(res => { + Api.getSystemCacheConfig(param).then(res => { res.search = item resolve(res) }) @@ -186,7 +237,7 @@ notification.warning({ top: 92, message: item.label + ': ' + this.state.dict['main.datasource.settingerror'], - duration: 10 + duration: 5 }) } @@ -214,7 +265,7 @@ } if (res.search.type === 'link') { - _item.parentId = cell[res.search.linkField] + _item.ParentID = cell[res.search.linkField] } else if (res.search.type === 'select' && res.search.linkSubField && res.search.linkSubField.length > 0) { res.search.linkSubField.forEach(_field => { _item[_field] = (cell[_field] || cell[_field] === 0) ? cell[_field] : '' @@ -229,7 +280,7 @@ notification.warning({ top: 92, message: res.search.label + ':' + res.message, - duration: 10 + duration: 5 }) } }) @@ -258,13 +309,13 @@ * @description 涓昏〃鏁版嵁鍔犺浇 */ async loadmaindata () { - const { setting, BIDs } = this.state + const { setting, BIDs, config } = this.state if (setting.datatype !== 'query') { notification.warning({ top: 92, message: '鏈缃暟鎹煡璇㈤厤缃紒', - duration: 10 + duration: 5 }) return } @@ -279,6 +330,11 @@ if (!param) return // 鏈幏鍙栧弬鏁版椂锛屼笉鍙戣姹� + // 鏁版嵁绠$悊鏉冮檺 + if (sessionStorage.getItem('dataM') === 'true') { + param.dataM = 'Y' + } + let result = await Api.genericInterface(param) if (result.status) { let _data = result.data[0] || '' @@ -286,22 +342,49 @@ if (_data) { _primaryId = _data[setting.primaryKey] || '' + } else { + notification.warning({ + top: 92, + message: '鏈煡璇㈠埌鏁版嵁淇℃伅锛�', + duration: 5 + }) } this.setState({ data: _data, primaryId: _primaryId, - BIDs: { - ...BIDs, - mainTable: _primaryId, - mainTabledata: _data - } + BIDs: { ...BIDs, [this.props.MenuID]: _primaryId, [this.props.MenuID + 'data']: _data } }) + + if (_data && (setting.interType !== 'inner' || (setting.interType === 'inner' && setting.innerFunc))) { + let keys = Object.keys(_data) + let emptys = [] + + if (!keys.includes(config.setting.primaryKey)) { + emptys.push(config.setting.primaryKey) + } + + config.groups.forEach(group => { + group.sublist.forEach(item => { + if (!keys.includes(item.field)) { + emptys.push(item.field + '(' + item.label + ')') + } + }) + }) + + if (emptys.length > 0) { + notification.warning({ + top: 92, + message: '鏈煡璇㈠埌' + emptys.join(', ') + '瀛楁淇℃伅锛�', + duration: 5 + }) + } + } } else { notification.error({ top: 92, message: result.message, - duration: 15 + duration: 10 }) } } @@ -316,24 +399,16 @@ notification.warning({ top: 92, message: '鏈缃〃鍗曞瓧娈碉紒', - duration: 10 - }) - return null - } else if (!primaryId) { - notification.warning({ - top: 92, - message: '鏈幏鍙栧埌涓婚敭鍊硷紒', - duration: 10 + duration: 5 }) return null } - let param = { func: 'sPC_Get_TableData', obj_name: 'data', arr_field: arr_field, - appkey: window.GLOB.appkey || '' + ID: primaryId } let _dataresource = setting.dataresource @@ -342,12 +417,30 @@ _dataresource = '(' + _dataresource + ') tb' } - let LText = `select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() from ${_dataresource}) tmptable where ${setting.primaryKey}=${primaryId}` + if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 + _dataresource = _dataresource.replace(/\$@/ig, '/*') + _dataresource = _dataresource.replace(/@\$/ig, '*/') + // param.custom_script = param.custom_script.replace(/\$@/ig, '/*') + // param.custom_script = param.custom_script.replace(/@\$/ig, '*/') + } else { + _dataresource = _dataresource.replace(/@\$|\$@/ig, '') + // param.custom_script = param.custom_script.replace(/@\$|\$@/ig, '') + } + + if (!/@ID@/ig.test(_dataresource)) { + _dataresource = `${_dataresource} where ${setting.primaryKey}='${primaryId}'` + } + + let LText = `select ${arr_field} from ${_dataresource}` param.LText = Utils.formatOptions(LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) param.DateCount = '' + + if (!window.GLOB.mkHS) { // 浜戠鏁版嵁楠岃瘉 + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) + } return param } @@ -363,13 +456,19 @@ if (setting.interType === 'inner') { param.func = setting.innerFunc } else { - if (setting.sysInterface === 'true') { - param.rduri = window.GLOB.mainSystemApi || window.GLOB.subSystemApi + if (window.GLOB.mkHS) { + if (setting.sysInterface === 'true' && options.cloudServiceApi) { + param.rduri = options.cloudServiceApi + } else if (setting.sysInterface !== 'true') { + param.rduri = setting.interface + } } else { - param.rduri = setting.interface + if (setting.sysInterface === 'true' && window.GLOB.mainSystemApi) { + param.rduri = window.GLOB.mainSystemApi + } else if (setting.sysInterface !== 'true') { + param.rduri = setting.interface + } } - - param.appkey = window.GLOB.appkey || '' // 璋冪敤澶栭儴鎺ュ彛澧炲姞appkey if (setting.outerFunc) { param.func = setting.outerFunc @@ -391,7 +490,7 @@ this.setState({ primaryId: primaryId }, () => { - if (btn.execSuccess === 'refresh') { + if (btn.execSuccess === 'refresh' || btn.execSuccess === 'grid') { this.loadmaindata() } else { let data = {} @@ -403,104 +502,25 @@ } this.setState({ - BIDs: { - ...BIDs, - mainTable: primaryId, - mainTabledata: data - } + BIDs: { ...BIDs, [this.props.MenuID]: primaryId, [this.props.MenuID + 'data']: data } }) } }) } else if (type === 'success' && btn.afterExecSuccess === 'close') { - if (this.props.refresh) { - this.props.refresh(btn.execSuccess) - } else { - if (btn.execSuccess !== 'never') { - let PMenu = { - MenuID: this.props.param.parentId || '', - position: btn.execSuccess - } - this.props.refreshTabView(PMenu) - } - - let tabs = this.props.tabviews.filter(tab => { - tab.selected = false - if (tab.MenuID === this.props.param.parentId) { - tab.selected = true - } - - return tab.MenuID !== this.props.MenuID - }) - - this.props.modifyTabview(tabs) + if (btn.execSuccess !== 'never') { + MKEmitter.emit('reloadData', this.props.param.parentId, 'formtab', btn) } + + MKEmitter.emit('closeTabView', this.props.MenuID) } else if (type === 'error' && btn.afterExecError === 'notclose') { - if (btn.execSuccess === 'refresh') { + if (btn.execError === 'refresh') { this.loadmaindata() } } else if (type === 'error' && btn.afterExecError === 'close') { - if (this.props.refresh) { - this.props.refresh(btn.execError) - } else { - if (btn.execError !== 'never') { - let PMenu = { - MenuID: this.props.param.parentId || '', - position: btn.execError - } - this.props.refreshTabView(PMenu) - } - - let tabs = this.props.tabviews.filter(tab => { - tab.selected = false - if (tab.MenuID === this.props.param.parentId) { - tab.selected = true - } - - return tab.MenuID !== this.props.MenuID - }) - - this.props.modifyTabview(tabs) + if (btn.execError !== 'never') { + MKEmitter.emit('reloadData', this.props.param.parentId, 'formtab', btn) } - } - } - - /** - * @description 琛ㄦ牸Id鍙樺寲 - */ - handleTableId = (type, id, data) => { - const { BIDs } = this.state - - this.setState({ - BIDs: { - ...BIDs, - [type]: id, - [type + 'data']: data - } - }) - } - - /** - * @description 瀛愯〃鎿嶄綔瀹屾垚鍚庡埛鏂颁富琛� - */ - handleMainTable = (type, tab) => { - if (type === 'maingrid' && tab.supMenu === 'mainTable') { - this.loadmaindata() - } else if (type === 'maingrid' && tab.supMenu) { - this.setState({ - refreshtabs: [tab.supMenu] - }, () => { - this.setState({ - refreshtabs: null - }) - }) - } else if (type === 'equaltab' && tab.equalTab && tab.equalTab.length > 0) { - this.setState({ - refreshtabs: tab.equalTab - }, () => { - this.setState({ - refreshtabs: null - }) - }) + MKEmitter.emit('closeTabView', this.props.MenuID) } } @@ -509,6 +529,47 @@ */ getFormData = () => { return this.formGroupRef.handleConfirm() + } + + reloadview = () => { + this.setState({ + loadingview: true, + viewlost: false, + lostmsg: '', + config: {}, + groups: null, + actions: null, + setting: null, + data: null, + BIDs: {}, + primaryId: null, + }, () => { + this.loadconfig() + }) + } + + reloadMenuView = (menuId) => { + const { MenuID } = this.props + + if (MenuID !== menuId) return + + this.reloadview() + } + + reloadData = (menuId) => { + const { MenuID } = this.props + + if (MenuID !== menuId) return + + this.loadmaindata() + } + + changeTableLine = (ContainerId, tableId, id, data) => { + if (this.state.ContainerId !== ContainerId) return + + this.setState({ + BIDs: {...this.state.BIDs, [tableId]: id, [tableId + 'data']: data} + }) } UNSAFE_componentWillMount () { @@ -520,6 +581,12 @@ return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) } + componentDidMount () { + MKEmitter.addListener('reloadData', this.reloadData) + MKEmitter.addListener('reloadMenuView', this.reloadMenuView) + MKEmitter.addListener('changeTableLine', this.changeTableLine) + } + /** * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 */ @@ -527,6 +594,10 @@ this.setState = () => { return } + + MKEmitter.removeListener('reloadData', this.reloadData) + MKEmitter.removeListener('reloadMenuView', this.reloadMenuView) + MKEmitter.removeListener('changeTableLine', this.changeTableLine) } render() { @@ -551,7 +622,6 @@ } {hasform ? <FormAction - logcolumns={[]} setting={setting} actions={actions} dict={this.state.dict} @@ -563,30 +633,26 @@ /> : null } {!loadingview && !viewlost && config.tabgroups.map(group => { - if (config[group].length === 0) return null + if (group.sublist.length === 0) return null return ( - <Tabs defaultActiveKey="0" key={group}> - {config[group].map((_tab, index) => { + <Tabs defaultActiveKey="0" key={group.uuid}> + {group.sublist.map((_tab, index) => { return ( <TabPane tab={ <span> - {_tab.icon ? <Icon type={_tab.icon} /> : null} + {_tab.icon ? <MkIcon type={_tab.icon} /> : null} {_tab.label} </span> } key={`${index}`}> - {_tab.type === 'SubTable' ? - <SubTable - Tab={_tab} - MenuID={_tab.linkTab} - SupMenuID={this.props.MenuID} - refreshtabs={this.state.refreshtabs} - ContainerId={this.state.ContainerId} - BID={this.state.BIDs[_tab.supMenu] || ''} - BData={this.state.BIDs[_tab.supMenu + 'data'] || ''} - handleTableId={this.handleTableId} - handleMainTable={(type) => this.handleMainTable(type, _tab)} - /> : null} + <SubTable + Tab={_tab} + MenuID={_tab.linkTab} + SupMenuID={this.props.MenuID} + ContainerId={this.state.ContainerId} + BID={this.state.BIDs[_tab.supMenu] || ''} + BData={this.state.BIDs[_tab.supMenu + 'data'] || ''} + /> </TabPane> ) })} @@ -594,6 +660,7 @@ ) }) } + {!window.GLOB.mkHS && window.GLOB.systemType !== 'production' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null} {viewlost ? <NotFount msg={this.state.lostmsg} /> : null} </div> ) @@ -602,17 +669,12 @@ const mapStateToProps = (state) => { return { - tabviews: state.tabviews, - refreshTab: state.refreshTab, permAction: state.permAction } } -const mapDispatchToProps = (dispatch) => { - return { - refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)), - modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)) - } +const mapDispatchToProps = () => { + return {} } export default connect(mapStateToProps, mapDispatchToProps)(NormalTable) \ No newline at end of file -- Gitblit v1.8.0