| | |
| | | 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 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 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 = { |
| | | MenuID: PropTypes.string, // 菜单Id |
| | | param: PropTypes.any, // 主表传递参数 |
| | | refresh: PropTypes.any // 刷新主表页面 |
| | | } |
| | | |
| | | state = { |
| | |
| | | arr_field: '', // 使用 sPC_Get_TableData 时的查询字段集 |
| | | setting: null, // 页面全局设置:数据源、按钮及显示列固定、主键等 |
| | | data: null, // 列表数据集 |
| | | configMap: {}, // 页面配置信息:下拉、按钮等 |
| | | BIDs: {}, // 上级表id |
| | | 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.getCacheConfig(param) |
| | | if (result.status) { |
| | |
| | | config.tabgroups = _tabgroups |
| | | } |
| | | |
| | | // 权限过滤 |
| | | if (this.props.menuType !== 'HS') { |
| | | if (!window.GLOB.mkHS) { |
| | | config.action = config.action.filter(item => permAction[item.uuid]) |
| | | config.tabgroups.forEach(group => { |
| | | group.sublist = group.sublist.filter(tab => permAction[tab.linkTab]) |
| | | 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 = group.sublist.filter(item => { |
| | | item.field && _arrField.push(item.field) |
| | | if (!item.blacklist || item.blacklist.length === 0) { |
| | | _arrField.push(item.field) |
| | | return true |
| | | } |
| | | |
| | | let _black = item.blacklist.filter(v => { |
| | | return this.props.permRoles.indexOf(v) !== -1 |
| | | }) |
| | | |
| | | if (_black.length > 0) { |
| | | return false |
| | | } else { |
| | | _arrField.push(item.field) |
| | | return true |
| | | } |
| | | return item.blacklist.filter(v => roleId.indexOf(v) > -1).length === 0 |
| | | }) |
| | | }) |
| | | _arrField = _arrField.join(',') |
| | |
| | | primaryId: this.props.param.primaryId || '', |
| | | data: this.props.param.data || null, |
| | | BIDs: { |
| | | mainTable: config.setting.onload !== 'false' ? (this.props.param.primaryId || '') : '', |
| | | mainTabledata: config.setting.onload !== 'false' ? (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) |
| | |
| | | item.options.unshift({ |
| | | key: Utils.getuuid(), |
| | | Value: '', |
| | | Text: this.state.dict['main.all'] |
| | | Text: '全部' |
| | | }) |
| | | } |
| | | |
| | |
| | | obj_name: 'data', |
| | | arr_field: _option.field |
| | | } |
| | | |
| | | if (this.props.dataManager) { // 数据权限 |
| | | param.LText = param.LText.replace(/\$@/ig, '/*') |
| | | param.LText = param.LText.replace(/@\$/ig, '*/') |
| | | } else { |
| | | param.LText = param.LText.replace(/@\$|\$@/ig, '') |
| | | } |
| | | |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | |
| | | if (this.props.menuType === 'HS') { // 云端数据验证 |
| | | if (window.GLOB.mkHS) { // 云端数据验证 |
| | | param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) |
| | | |
| | | if (item.database === 'sso' && options.cloudServiceApi) { // 存在云端地址时,使用云端系统参数 |
| | |
| | | if (!param) return // 未获取参数时,不发请求 |
| | | |
| | | // 数据管理权限 |
| | | if (this.props.dataManager) { |
| | | if (sessionStorage.getItem('dataM') === 'true') { |
| | | param.dataM = 'Y' |
| | | } |
| | | |
| | |
| | | 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))) { |
| | |
| | | _dataresource = '(' + _dataresource + ') tb' |
| | | } |
| | | |
| | | if (this.props.dataManager) { // 数据权限 |
| | | if (sessionStorage.getItem('dataM') === 'true') { // 数据权限 |
| | | _dataresource = _dataresource.replace(/\$@/ig, '/*') |
| | | _dataresource = _dataresource.replace(/@\$/ig, '*/') |
| | | // param.custom_script = param.custom_script.replace(/\$@/ig, '/*') |
| | |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | param.DateCount = '' |
| | | |
| | | if (this.props.menuType !== 'HS') { // 云端数据验证 |
| | | if (!window.GLOB.mkHS) { // 云端数据验证 |
| | | param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) |
| | | } |
| | | |
| | |
| | | if (setting.interType === 'inner') { |
| | | param.func = setting.innerFunc |
| | | } else { |
| | | if (this.props.menuType === 'HS') { |
| | | if (window.GLOB.mkHS) { |
| | | if (setting.sysInterface === 'true' && options.cloudServiceApi) { |
| | | param.rduri = options.cloudServiceApi |
| | | } else if (setting.sysInterface !== 'true') { |
| | |
| | | this.setState({ |
| | | primaryId: primaryId |
| | | }, () => { |
| | | if (btn.execSuccess === 'refresh') { |
| | | if (btn.execSuccess === 'refresh' || btn.execSuccess === 'grid') { |
| | | this.loadmaindata() |
| | | } else { |
| | | let data = {} |
| | |
| | | } |
| | | |
| | | 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.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' || type === 'mainline') && tab.supMenu === 'mainTable') { |
| | | this.loadmaindata() |
| | | } else if ((type === 'maingrid' || type === 'mainline') && tab.supMenu) { |
| | | this.setState({ |
| | | refreshtabs: [type, 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) |
| | | } |
| | | } |
| | | |
| | |
| | | config: {}, |
| | | groups: null, |
| | | actions: null, |
| | | arr_field: '', |
| | | setting: null, |
| | | data: null, |
| | | configMap: {}, |
| | | BIDs: {}, |
| | | setsingle: false, |
| | | pickup: false, |
| | | popData: false, |
| | | visible: false, |
| | | primaryId: null, |
| | | refreshtabs: 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} |
| | | }) |
| | | } |
| | | |
| | |
| | | this.loadconfig() |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (nextProps.refreshTab && nextProps.refreshTab.MenuID === this.props.MenuID) { |
| | | this.reloadview() |
| | | this.props.refreshTabView('') |
| | | } |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | 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) |
| | | } |
| | | |
| | | /** |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | |
| | | MKEmitter.removeListener('reloadData', this.reloadData) |
| | | MKEmitter.removeListener('reloadMenuView', this.reloadMenuView) |
| | | MKEmitter.removeListener('changeTableLine', this.changeTableLine) |
| | | } |
| | | |
| | | render() { |
| | |
| | | } |
| | | {hasform ? |
| | | <FormAction |
| | | menuType={this.props.menuType} |
| | | logcolumns={[]} |
| | | setting={setting} |
| | | actions={actions} |
| | | dict={this.state.dict} |
| | |
| | | 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> |
| | | ) |
| | | })} |
| | |
| | | ) |
| | | }) |
| | | } |
| | | {!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> |
| | | ) |
| | |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | menuType: state.editLevel, |
| | | tabviews: state.tabviews, |
| | | refreshTab: state.refreshTab, |
| | | permAction: state.permAction, |
| | | dataManager: state.dataManager, |
| | | permRoles: state.permRoles |
| | | 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) |