From 9b6ce1a5778c6e1a813237e87588c0052aae1bbb Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 29 四月 2020 17:26:15 +0800 Subject: [PATCH] 2020-04-29 --- src/tabviews/subtable/index.jsx | 536 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 387 insertions(+), 149 deletions(-) diff --git a/src/tabviews/subtable/index.jsx b/src/tabviews/subtable/index.jsx index 0868e5a..88105fc 100644 --- a/src/tabviews/subtable/index.jsx +++ b/src/tabviews/subtable/index.jsx @@ -2,29 +2,42 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { notification, Spin, Modal, Button} from 'antd' +import { notification, Spin, Modal, Button, Switch} from 'antd' import moment from 'moment' + import Api from '@/api' -import SubTable from './subTable' -import SubAction from '@/tabviews/tableshare/actionList' -import SubSearch from '@/tabviews/tableshare/topSearch' -import asyncComponent from '@/utils/asyncLoadComponent' -import NotFount from '@/components/404' 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 { modifyTabview } from '@/store/action' + +import SubTable from '@/tabviews/zshare/normalTable' +import SubSearch from '@/tabviews/zshare/topSearch' +import asyncComponent from '@/utils/asyncComponent' +import asyncLoadComponent from '@/utils/asyncLoadComponent' +import NotFount from '@/components/404' + import './index.scss' -const SubTabTable = asyncComponent(() => import('@/tabviews/subtabtable')) +const SubAction = asyncComponent(() => import('@/tabviews/zshare/actionList')) +const SubTabTable = asyncLoadComponent(() => import('@/tabviews/subtabtable')) class SubTabViewTable extends Component { static propTpyes = { + menuType: PropTypes.any, // 鑿滃崟绫诲瀷锛屾櫘閫氳彍鍗曟垨HS Tab: PropTypes.object, // 鏍囩淇℃伅 BID: PropTypes.string, // 涓婄骇鏁版嵁ID + BData: PropTypes.any, // 涓婄骇鏁版嵁 MenuID: PropTypes.string, // 鑿滃崟Id SupMenuID: PropTypes.string, // 涓婄骇鑿滃崟Id + mainSearch: PropTypes.any, // 涓昏〃鎼滅储鏉′欢 + ContainerId: PropTypes.any, // 涓夌骇鑿滃崟Container(html) ID handleTableId: PropTypes.func, // 鎺у埗琛ㄦ牸鏁版嵁鍒囨崲鏃讹紝鏇存柊鍦ㄤ富琛ㄤ腑鐨刬d - handleMainTable: PropTypes.func // 鎺у埗琛ㄦ牸鏁版嵁鍒囨崲鏃讹紝鏇存柊鍦ㄤ富琛ㄤ腑鐨刬d + handleMainTable: PropTypes.func, // 鍒锋柊涓昏〃 + refreshtabs: PropTypes.any, // 鏍囩鍒锋柊鎺у埗 + userConfig: PropTypes.any, // 鐢ㄦ埛鑷畾涔夎缃� + triggerBtn: PropTypes.any // 蹇嵎閿垨鐐瑰嚮琛屾寜閽Е鍙戜簨浠� } state = { @@ -32,10 +45,11 @@ loadingview: true, // 椤甸潰鍔犺浇涓� viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 lostmsg: '', // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅 - config: {}, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑 + config: null, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑 searchlist: null, // 鎼滅储鏉′欢 actions: null, // 鎸夐挳闆� columns: null, // 鏄剧ず鍒� + logcolumns: null, // 鏃ュ織涓樉绀虹殑鍒椾俊鎭� (澧炲姞鑷冲叏閮ㄥ垪锛岄櫎鍘诲悎骞跺垪) arr_field: '', // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆� setting: null, // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑 data: null, // 鍒楄〃鏁版嵁闆� @@ -43,21 +57,36 @@ loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� pageIndex: 1, // 椤电爜 pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 - orderColumn: '', // 鎺掑簭瀛楁 - orderType: 'asc', // 鎺掑簭鏂瑰紡 + orderBy: '', // 鎺掑簭 search: '', // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞� - configMap: {}, // 椤甸潰閰嶇疆淇℃伅锛氫笅鎷夈�佹寜閽瓑 popAction: false, // 寮规椤甸潰锛屾寜閽俊鎭� popData: false, // 寮规椤甸潰锛屾墍閫夌殑琛ㄦ牸鏁版嵁 - visible: false // 寮规鏄剧ず闅愯棌鎺у埗 + visible: false, // 寮规鏄剧ず闅愯棌鎺у埗 + pickup: false, // 瀛愯〃鏁版嵁闅愯棌鏄剧ず鍒囨崲 + triggerBtn: null // 鎸夐挳瑙﹀彂 } /** * @description 涓婄骇鑿滃崟id鍙樺寲鏃讹紝鍒锋柊鏁版嵁 */ UNSAFE_componentWillReceiveProps(nextProps) { - if (this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) { + if (this.state.config && this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) { + this.refs.subTable.resetTable() this.loadmaindata(nextProps.BID, 'refresh') + } else if (this.state.config && nextProps.refreshtabs && nextProps.refreshtabs.includes(this.props.Tab.uuid)) { + this.reloadtable() + } else if (nextProps.triggerBtn && !is(fromJS(this.props.triggerBtn), fromJS(nextProps.triggerBtn)) && nextProps.triggerBtn.parentId === this.props.Tab.uuid) { + let trigger = nextProps.triggerBtn + + trigger.parentId = this.props.MenuID + + this.setState({ + triggerBtn: trigger + }) + } else if (!this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { + this.setState({}, () => { + this.loadmaindata() + }) } } @@ -65,7 +94,7 @@ * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅 */ async loadconfig () { - const { permAction, Tab, BID } = this.props + const { permAction, permMenus, Tab, BID, userConfig } = this.props let param = { func: 'sPC_Get_LongParam', @@ -76,9 +105,9 @@ 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 = '' } @@ -103,16 +132,78 @@ let _arrField = [] // 瀛楁闆� let _columns = [] // 鏄剧ず鍒� + let _logcolumns = [] // 鏃ュ織鏄剧ず鍒� let _hideCol = [] // 闅愯棌鍙婂悎骞跺垪涓瓧娈电殑uuid闆� let colMap = new Map() // 鏉冮檺杩囨护 - config.action = config.action.filter(item => permAction[item.uuid]) + if (this.props.menuType !== 'HS') { + config.action = config.action.filter(item => permAction[item.uuid]) + + // 瀛楁鏉冮檺榛戝悕鍗� + config.search = config.search.filter(item => { + 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) { + return false + } else { + return true + } + }) + + config.columns = config.columns.filter(col => { + if (!col.field || !col.blacklist || col.blacklist.length === 0 || config.setting.primaryKey === col.field) return true + + let _black = col.blacklist.filter(v => { + return this.props.permRoles.indexOf(v) !== -1 + }) + + if (_black.length > 0) { + return false + } else { + return true + } + }) + } + + if (userConfig) { + config.setting.tableType = userConfig.setting.tableType + + 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.type === 'colspan' && col.sublist) { // 绛涢�夐殣钘忓垪 _hideCol = _hideCol.concat(col.sublist) @@ -123,8 +214,14 @@ }) // 鐢熸垚鏄剧ず鍒楋紝澶勭悊鍚堝苟鍒椾腑鐨勫瓧娈� - config.columns.forEach(col => { + config.columns.forEach((col, index) => { if (_hideCol.includes(col.uuid)) return + + if (col.linkThdMenu && !permMenus[col.linkThdMenu.MenuID]) { + col.linkThdMenu = '' + } + + col.sort = index if (col.type === 'colspan' && col.sublist) { let _col = JSON.parse(JSON.stringify(col)) @@ -141,13 +238,48 @@ } }) - let _actions = config.action.filter(item => item.position === 'toolbar') // 杩囨护宸ュ叿鏍忔寜閽� - let _operations = config.action.filter(item => item.position === 'grid') // 娣诲姞鎿嶄綔鍒楋紙瀛樺湪鏃讹級 + let _actions = [] // 宸ュ叿鏍忔寜閽� + let _operations = [] // 鎿嶄綔鍒楁寜閽紙瀛樺湪鏃讹級 + + config.action.forEach(item => { + if (item.execMode) { + item.OpenType = 'funcbutton' + } + + if (item.position === 'toolbar') { + _actions.push(item) + } else if (item.position === 'grid') { + _operations.push(item) + } + }) if (config.gridBtn && config.gridBtn.display && _operations.length > 0) { _columns.push({ ...config.gridBtn, operations: _operations + }) + } + + let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉 + config.search.forEach(field => { + if (field.required === 'true' && !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 }) } @@ -158,15 +290,13 @@ searchlist: config.search, actions: _actions, columns: _columns, + logcolumns: _logcolumns, arr_field: _arrField.join(','), search: Utils.initMainSearch(config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 }, () => { this.improveSearch() - if (config.setting.onload !== 'false' && (!Tab.supMenu || BID)) { // 鍒濆鍖栧彲鍔犺浇 - this.setState({ - loading: true - }) + if (config.setting.onload !== 'false' && (!Tab.supMenu || BID) && valid) { // 鍒濆鍖栧彲鍔犺浇 this.loadmaindata() } }) @@ -175,10 +305,12 @@ loadingview: false, viewlost: true }) + let prex = Tab && Tab.label ? Tab.label + ': ' : '' + notification.warning({ top: 92, - message: result.message, - duration: 10 + message: prex + result.message, + duration: 5 }) } } @@ -202,6 +334,7 @@ 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', @@ -210,21 +343,27 @@ arr_field: _option.field } + if (this.props.BID) { + param.BID = this.props.BID + } + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' param.secretkey = Utils.encrypt(param.LText, param.timestamp) let defer = new Promise(resolve => { - Api.getSystemCacheConfig(param).then(res => { + Api.getSystemCacheConfig(param, isSSO).then(res => { res.search = item resolve(res) }) }) deffers.push(defer) } else if (item.resourceType === '1' && !item.dataSource) { + let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : '' + notification.warning({ top: 92, - message: item.label + ': ' + this.state.dict['main.datasource.settingerror'], - duration: 10 + message: prex + item.label + ': ' + this.state.dict['main.datasource.settingerror'], + duration: 5 }) } }) @@ -256,10 +395,12 @@ return item }) } else { + let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : '' + notification.warning({ top: 92, - message: res.search.label + ':' + res.message, - duration: 10 + message: prex + res.search.label + ':' + res.message, + duration: 5 }) } }) @@ -271,12 +412,36 @@ * @description 瀛愯〃鏁版嵁鍔犺浇 */ async loadmaindata (bid, type) { - const { setting } = this.state + const { setting, search } = this.state let param = '' let _BID = this.props.BID + + let requireFields = search.filter(item => item.required && !item.value) + + if (requireFields.length > 0) { + notification.warning({ + top: 92, + message: this.state.dict['form.required.input'] + requireFields.map(item => item.label).join('銆�') + ' !', + duration: 3 + }) + return + } + + this.setState({ + loading: true + }) if (type === 'refresh') { _BID = bid + if (!bid) { // 涓昏〃ID涓嶅瓨鍦ㄦ椂锛屼笉鏌ヨ瀛愯〃 + this.setState({ + data: [], + total: 0, + loading: false + }) + + return + } } if (setting.interType !== 'inner' || (setting.interType === 'inner' && setting.innerFunc)) { @@ -285,7 +450,7 @@ param = this.getDefaultParam(_BID) } - this.handleTableId('') + this.handleTableId() let result = await Api.genericInterface(param) if (result.status) { @@ -295,16 +460,19 @@ return item }), total: result.total, + pickup: false, loading: false }) } else { this.setState({ loading: false }) + let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + ': ' : '' + notification.error({ top: 92, - message: result.message, - duration: 15 + message: prex + result.message, + duration: 10 }) } } @@ -313,15 +481,20 @@ * @description 鑾峰彇鐢ㄦ埛鑷畾涔夊瓨鍌ㄨ繃绋嬩紶鍙� */ getCustomParam = (BID) => { - const { pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state + const { mainSearch } = this.props + const { pageIndex, pageSize, orderBy, search, setting } = this.state - let _search = Utils.formatCustomMainSearch(search) + let searches = search + if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 + searches = [...mainSearch, ...search] + } + + let _search = Utils.formatCustomMainSearch(searches) let param = { PageIndex: pageIndex, PageSize: pageSize, - OrderCol: orderColumn, - OrderType: orderType, + OrderCol: orderBy || setting.order, BID: BID, ..._search } @@ -329,7 +502,20 @@ if (setting.interType === 'inner') { param.func = setting.innerFunc } else { - param.rduri = setting.interface + if (this.props.menuType === 'HS') { + if (setting.sysInterface === 'true' && options.cloudServiceApi) { + param.rduri = options.cloudServiceApi + } else if (setting.sysInterface !== 'true') { + param.rduri = setting.interface + } + } else { + if (setting.sysInterface === 'true' && window.GLOB.mainSystemApi) { + param.rduri = window.GLOB.mainSystemApi + } else if (setting.sysInterface !== 'true') { + param.rduri = setting.interface + } + } + if (setting.outerFunc) { param.func = setting.outerFunc } @@ -342,9 +528,15 @@ * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁� */ getDefaultParam = (BID) => { - const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state + const { mainSearch } = this.props + const { arr_field, pageIndex, pageSize, orderBy, search, setting } = this.state - let _search = Utils.joinMainSearchkey(search) + let searches = search + if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 + searches = [...mainSearch, ...search] + } + + let _search = Utils.joinMainSearchkey(searches) _search = _search ? 'where ' + _search : '' let param = { @@ -354,7 +546,7 @@ BID: BID } - let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order + let _orderBy = orderBy || setting.order let _dataresource = setting.dataresource if (/\s/.test(_dataresource)) { @@ -373,12 +565,12 @@ fieldmap.set(item.key, true) return { - reg: new RegExp('@' + _field, 'ig'), + reg: new RegExp('@' + _field + '@', 'ig'), value: item.value } }) - options.reverse() + // options.reverse() options.forEach(item => { _dataresource = _dataresource.replace(item.reg, `'${item.value}'`) @@ -387,7 +579,7 @@ _search = '' } - let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows` + let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows` let DateCount = `select count(1) as total from ${_dataresource} ${_search}` param.LText = Utils.formatOptions(LText) @@ -406,7 +598,6 @@ this.refs.subTable.resetTable() this.setState({ - loading: true, pageIndex: 1, search: searches }, () => { @@ -427,11 +618,9 @@ } this.setState({ - loading: true, pageIndex: pagination.current, pageSize: pagination.pageSize, - orderColumn: sorter.field || this.state.setting.orderColumn, - orderType: sorter.order || 'asc' + orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : '' }, () => { this.loadmaindata() }) @@ -443,7 +632,6 @@ reloadtable = () => { this.refs.subTable.resetTable() this.setState({ - loading: true, pageIndex: 1 }, () => { this.loadmaindata() @@ -458,7 +646,7 @@ loadingview: true, viewlost: false, lostmsg: '', - config: {}, + config: null, searchlist: null, actions: null, columns: null, @@ -469,10 +657,9 @@ loading: false, pageIndex: 1, pageSize: 10, - orderColumn: '', - orderType: 'asc', + orderBy: '', search: '', - configMap: {} + triggerBtn: null }, () => { this.loadconfig() }) @@ -485,72 +672,46 @@ if (btn.execSuccess === 'grid' && type === 'success') { this.reloadtable() } else if (btn.execError === 'grid' && type === 'error') { - this.reloadview() - } else if (btn.execSuccess === 'view' && type === 'success') { this.reloadtable() + } else if (btn.execSuccess === 'view' && type === 'success') { + this.reloadview() } else if (btn.execError === 'view' && type === 'error') { this.reloadview() - } else if (btn.popClose === 'maingrid' && type === 'pop') { - this.props.handleMainTable() - } else if (btn.popClose === 'subgrid' && type === 'pop') { + } else if (btn.popClose === 'grid' && type === 'pop') { this.reloadtable() - } else if (type === 'excelOut') { - this.handleDefaultExcelout(btn) + } else if (btn.popClose === 'view' && type === 'pop') { + this.reloadview() + } else if (btn.popClose === 'maingrid' && type === 'pop') { + this.props.handleMainTable('maingrid') + } else if (btn.popClose === 'equaltab' && type === 'pop') { + this.reloadtable() + this.props.handleMainTable('equaltab') + } else if (btn.execSuccess === 'maingrid' && type === 'success') { + this.props.handleMainTable('maingrid') + } else if (btn.execSuccess === 'equaltab' && type === 'success') { + this.reloadtable() + this.props.handleMainTable('equaltab') } } /** - * @description 浣跨敤榛樿瀛樺偍杩囩▼ sPC_Get_TableData 瀵煎嚭excel琛ㄦ牸 + * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ - handleDefaultExcelout = (btn) => { - const { MenuName } = this.props - const { arr_field, orderColumn, orderType, search, setting, config } = this.state + getexceloutparam = () => { + const { Tab, mainSearch } = this.props + const { arr_field, orderBy, search, setting} = this.state - let _arr_labels = [] // 鍒楀悕绉伴泦 - let _arr_label_field = [] // 鍒楀悕绉板瓧娈甸泦 - - config.columns.forEach(col => { - if (col.field) { - _arr_labels.push(col.label) - _arr_label_field.push(`${col.field} as ${col.label}`) - } - }) - - _arr_labels = _arr_labels.join(',') - _arr_label_field = _arr_label_field.join(',') - - let _search = Utils.joinMainSearchkey(search) - _search = _search ? 'where (' + _search + ')' : '' - // 鑾峰彇鍒楄〃鏁版嵁 - let param = { - func: 'sPC_Get_TableData', - obj_name: 'data', - arr_field: _arr_labels + let searches = search + if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 + searches = [...mainSearch, ...search] } - let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order - let _dataresource = setting.dataresource - - if (/\s/.test(_dataresource)) { - _dataresource = '(' + _dataresource + ') tb' + return { + arr_field: arr_field, + orderBy: orderBy || setting.order, + search: searches, + menuName: Tab.label } - - let LText = `select ${_arr_label_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows` - - param.LText = Utils.formatOptions(LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' - param.secretkey = Utils.encrypt(param.LText, param.timestamp) - param.DateCount = '' - - let name = `${MenuName}${moment().format('YYYYMMDDHHmmss')}.xlsx` - - Api.getExcelOut(param, name).then(res => { - if (res && res.status === false) { - this.refs.subButton.execError(res, btn) - } else { - this.refs.subButton.execSuccess(btn) - } - }) } /** @@ -568,14 +729,21 @@ * @description 琛ㄦ牸涓紝鎸夐挳瑙﹀彂浜嬩欢浼犻�� */ buttonTrigger = (btn, record) => { - this.refs.subButton.actionTrigger(btn, record) + this.setState({ + triggerBtn: { + uuid: new Date().getTime(), + parentId: this.props.MenuID, + button: btn, + data: record + } + }) } /** * @description 琛ㄦ牸Id鍙樺寲 */ - handleTableId = (id = '') => { - this.props.handleTableId(this.props.Tab.uuid, id) + handleTableId = (type = this.props.Tab.uuid, id = '', data = '') => { + this.props.handleTableId(type, id, data) } /** @@ -589,6 +757,45 @@ }) } + /** + * @description 鏁版嵁灞曞紑鍚堝苟鍒囨崲 + */ + pickupChange = () => { + const { pickup } = this.state + + this.setState({ + pickup: !pickup + }) + } + + linkTrigger = (menu) => { + const { tabviews, SupMenuID } = this.props + + menu.selected = true + + let index = 0 + let isexit = false + let tabs = tabviews.map((tab, i) => { + tab.selected = false + + if (tab.MenuID === SupMenuID) { + index = i + } else if (tab.MenuID === menu.MenuID) { + tab.param = menu.param + tab.selected = true + isexit = true + } + + return tab + }) + + if (!isexit) { + tabs.splice(index + 1, 0, menu) + } + + this.props.modifyTabview(tabs) + } + popclose = () => { this.setState({ visible: false @@ -596,13 +803,13 @@ this.refreshbyaction(this.state.popAction, 'pop') } - UNSAFE_componentWillMount () { + UNSAFE_componentWillMount() { // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁 this.loadconfig() } - shouldComponentUpdate (nextProps, nextState) { - return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) + shouldComponentUpdate (nextProps, nextState) { // handleMainTable 鍑芥暟鍒ゆ柇鏃朵笉鐩哥瓑 + return !is(fromJS({...this.props, handleMainTable: '', handleTableId: ''}), fromJS({...nextProps, handleMainTable: '', handleTableId: ''})) || !is(fromJS(this.state), fromJS(nextState)) } /** @@ -615,7 +822,7 @@ } render() { - const { setting, searchlist, actions, columns, loadingview, viewlost } = this.state + const { setting, searchlist, actions, columns, loadingview, viewlost, pickup, triggerBtn } = this.state return ( <div className="subtable" id={'subtable' + this.props.MenuID}> @@ -627,35 +834,52 @@ dict={this.state.dict} /> : null } - {actions && - <SubAction - ref="subButton" - type="sub" - setting={setting} - actions={actions} - Tab={this.props.Tab} - BID={this.props.BID} - dict={this.state.dict} - MenuID={this.props.SupMenuID} - refreshdata={this.refreshbyaction} - triggerPopview={this.triggerPopview} - gettableselected={this.gettableselected} - /> + {actions ? + <div className="sub-action"> + <SubAction + type="sub" + menuType={this.props.menuType} + triggerBtn={triggerBtn} + setting={setting} + actions={actions} + Tab={this.props.Tab} + BID={this.props.BID} + BData={this.props.BData} + dict={this.state.dict} + MenuID={this.props.MenuID} + permRoles={this.props.permRoles} + logcolumns={this.state.logcolumns} + refreshdata={this.refreshbyaction} + ContainerId={this.props.ContainerId} + triggerPopview={this.triggerPopview} + getexceloutparam={this.getexceloutparam} + gettableselected={this.gettableselected} + /> + </div> : null } - {columns && - <SubTable - ref="subTable" - dict={this.state.dict} - MenuID={this.props.MenuID} - setting={setting} - columns={columns} - data={this.state.data} - total={this.state.total} - loading={this.state.loading} - refreshdata={this.refreshbytable} - buttonTrigger={this.buttonTrigger} - handleTableId={this.handleTableId} - /> + {columns ? + <div className="subtable-box"> + {this.state.data && this.state.data.length > 0 ? + <Switch title="鏀惰捣" className="subtable-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null + } + <SubTable + ref="subTable" + menuType={this.props.menuType} + tableId={this.props.Tab.uuid} + pickup={pickup} + setting={setting} + columns={columns} + dict={this.state.dict} + data={this.state.data} + total={this.state.total} + MenuID={this.props.MenuID} + loading={this.state.loading} + refreshdata={this.refreshbytable} + buttonTrigger={this.buttonTrigger} + linkTrigger={this.linkTrigger} + handleTableId={this.handleTableId} + /> + </div> : null } <Modal className="popview-modal" @@ -665,11 +889,20 @@ visible={this.state.visible} onCancel={this.popclose} footer={[ - <Button key="cancel" onClick={this.popclose}>{this.state.dict['main.close']}</Button> + <Button key="close" onClick={this.popclose}>{this.state.dict['main.close']}</Button> ]} destroyOnClose > - {<SubTabTable SupMenuID={this.props.MenuID} MenuID={this.state.popAction.linkTab} BID={''} ID={this.state.popData ? this.state.popData[setting.primaryKey] : ''} />} + {<SubTabTable + BID={this.props.BID} + menuType={this.props.menuType} + BData={this.props.BData} + SupMenuID={this.props.MenuID} + ContainerId={this.props.ContainerId} + MenuID={this.state.popAction.linkTab} + ID={this.state.popData ? this.state.popData[setting.primaryKey] : ''} + refreshSupView={this.reloadtable} + />} </Modal> {viewlost ? <NotFount msg={this.state.lostmsg} /> : null} </div> @@ -679,12 +912,17 @@ const mapStateToProps = (state) => { return { - permAction: state.permAction + tabviews: state.tabviews, + permAction: state.permAction, + permRoles: state.permRoles, + permMenus: state.permMenus } } -const mapDispatchToProps = () => { - return {} +const mapDispatchToProps = (dispatch) => { + return { + modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)) + } } export default connect(mapStateToProps, mapDispatchToProps)(SubTabViewTable) \ No newline at end of file -- Gitblit v1.8.0