From 6def3330d1d1cf4036916ed04c8bbc4128e1e5d0 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 03 五月 2020 19:42:17 +0800 Subject: [PATCH] 2020-05-03 --- src/tabviews/commontable/index.jsx | 1126 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 821 insertions(+), 305 deletions(-) diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx index 699a2b3..b80a1da 100644 --- a/src/tabviews/commontable/index.jsx +++ b/src/tabviews/commontable/index.jsx @@ -2,40 +2,53 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { BackTop, notification, Spin, Tabs, Icon, Switch, Modal, Button} from 'antd' +import { notification, Spin, Tabs, Icon, Switch, Modal, Button, message, Tree, Typography } from 'antd' import moment from 'moment' + import Api from '@/api' -import MainTable from './mainTable' -import MainAction from '@/tabviews/tableshare/actionList' -import MainSearch from '@/tabviews/tableshare/topSearch' -import SubTable from '@/tabviews/subtable' -import NotFount from '@/components/404' -import asyncComponent from '@/utils/asyncLoadComponent' -import {refreshTabView, modifyTabview} from '@/store/action' import zhCN from '@/locales/zh-CN/main.js' import enUS from '@/locales/en-US/main.js' import Utils from '@/utils/utils.js' +import asyncLoadComponent from '@/utils/asyncLoadComponent' +import {refreshTabView, modifyTabview} from '@/store/action' + +import MainTable from '@/tabviews/zshare/normalTable' +import MainSearch from '@/tabviews/zshare/topSearch' +import NotFount from '@/components/404' import './index.scss' -const SubTabTable = asyncComponent(() => import('@/tabviews/subtabtable')) +const VerifyCard = asyncLoadComponent(() => import('@/tabviews/zshare/verifycard')) +const MainAction = asyncLoadComponent(() => import('@/tabviews/zshare/actionList')) +const SubTable = asyncLoadComponent(() => import('@/tabviews/subtable')) +const SubTabTable = asyncLoadComponent(() => import('@/tabviews/subtabtable')) +const FormTab = asyncLoadComponent(() => import('@/tabviews/formtab')) + const { TabPane } = Tabs +const { TreeNode } = Tree +const { Paragraph } = Typography class NormalTable extends Component { static propTpyes = { + param: PropTypes.any, // 鍏朵粬椤甸潰浼犻�掔殑鎼滅储鏉′欢绛夊弬鏁� + MenuID: PropTypes.string, // 鑿滃崟Id MenuNo: PropTypes.string, // 鑿滃崟鍙傛暟 - MenuName: PropTypes.string, // 鑿滃崟鍙傛暟 - MenuID: PropTypes.string // 鑿滃崟Id + MenuName: PropTypes.string // 鑿滃崟鍚嶇О } state = { dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, + ContainerId: Utils.getuuid(), // 鑿滃崟澶栧眰html Id + view: 'commontable', // 褰撳墠椤甸潰榛樿涓轰富琛� loadingview: true, // 椤甸潰鍔犺浇涓� viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 lostmsg: '', // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅 config: {}, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑 + userConfig: null, // 鐢ㄦ埛鑷畾涔夎缃� + userParam: null, // 淇濆瓨鐢ㄦ埛缂栬緫涓殑閰嶇疆 searchlist: null, // 鎼滅储鏉′欢 actions: null, // 鎸夐挳闆� columns: null, // 鏄剧ず鍒� + logcolumns: null, // 鏃ュ織涓樉绀虹殑鍒椾俊鎭� (澧炲姞鑷冲叏閮ㄥ垪锛岄櫎鍘诲悎骞跺垪) arr_field: '', // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆� setting: null, // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑 data: null, // 鍒楄〃鏁版嵁闆� @@ -43,38 +56,56 @@ loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� pageIndex: 1, // 椤电爜 pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 - orderColumn: '', // 鎺掑簭瀛楁 - orderType: 'asc', // 鎺掑簭鏂瑰紡 + orderBy: '', // 鎺掑簭 search: '', // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞� - configMap: {}, // 椤甸潰閰嶇疆淇℃伅锛氫笅鎷夈�佹寜閽瓑 BIDs: {}, // 涓婄骇琛╥d - setsingle: false, // 涓昏〃鍗曢�夊閫夊垏鎹� pickup: false, // 涓昏〃鏁版嵁闅愯棌鏄剧ず鍒囨崲 - isLinkMain: false, // 鏄惁瀛樺湪涓庝富琛ㄥ叧鑱旂殑瀛愯〃 popAction: false, // 寮规椤甸潰锛屾寜閽俊鎭� popData: false, // 寮规椤甸潰锛屾墍閫夌殑琛ㄦ牸鏁版嵁 - visible: false // 寮规鏄剧ず闅愯棌鎺у埗 + visible: false, // 寮规鏄剧ず闅愯棌鎺у埗 + treevisible: false, // 鑿滃崟缁撴瀯鏍戝脊妗嗘樉绀洪殣钘忔帶鍒� + tabBtn: null, // 琛ㄥ崟鏍囩鎸夐挳 + tabParam: null, // 琛ㄥ崟鏍囩鍙傛暟 + refreshtabs: null, // 闇�瑕佸埛鏂扮殑鏍囩闆� + confirmLoading: false,// 鑷畾涔夎缃ā鎬佹鍔犺浇涓� + revertLoading: false, // 鎭㈠榛樿璁剧疆 + settingVisible: false,// 鑷畾涔夎缃ā鎬佹 + triggerBtn: null, // 鐐瑰嚮琛ㄦ牸涓垨蹇嵎閿Е鍙戠殑鎸夐挳 + tabActive: null // 鏍囩椤靛睍寮�鎺у埗 } /** * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅 */ async loadconfig () { - const { permAction } = this.props + const { permAction, permMenus, param } = this.props - let param = { + let _param = { func: 'sPC_Get_LongParam', MenuID: this.props.MenuID } - let result = await Api.getSystemCacheConfig(param) + let result = await Api.getSystemCacheConfig(_param) + if (result.status) { let config = '' + let userConfig = null + let _curUserConfig = '' 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 = '' + } + + if (result.LongParamUser) { + try { // 閰嶇疆淇℃伅瑙f瀽 + userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser))) + _curUserConfig = userConfig[this.props.MenuID] + } catch (e) { + console.warn('Parse Failure') + userConfig = null + } } // 椤甸潰閰嶇疆瑙f瀽閿欒鏃舵彁绀� @@ -96,22 +127,106 @@ return } - let _arrField = [] // 瀛楁闆� - let _columns = [] // 鏄剧ず鍒� - let _hideCol = [] // 闅愯棌鍙婂悎骞跺垪涓瓧娈电殑uuid闆� - let colMap = new Map() - // 鏉冮檺杩囨护 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]) - // }) + config.tabgroups.forEach(group => { + if (!config[group]) return + + config[group] = config[group].filter(tab => permAction[tab.linkTab]) + }) + + // 瀛楁鏉冮檺榛戝悕鍗� + 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 (_curUserConfig) { + config.setting = {...config.setting, ..._curUserConfig.setting} + config.easyCode = _curUserConfig.easyCode || config.easyCode || '' + + config.action = config.action.map(item => { + if (item.execMode) { + item.OpenType = 'funcbutton' + } + + if (_curUserConfig.action[item.uuid]) { + delete _curUserConfig.action[item.uuid].label + item = {...item, ..._curUserConfig.action[item.uuid]} + } + + 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 + }) + } + + let _tabActive = {} // 绛涢�夊睍寮�鐨則ab椤� + + config.tabgroups.forEach(groupId => { + if (!config[groupId] || config[groupId].length === 0) return + _tabActive[groupId] = config[groupId][0].uuid + }) + + let _arrField = [] // 瀛楁闆� + let _columns = [] // 鏄剧ず鍒� + let _logcolumns = [] // 鏃ュ織鏄剧ず鍒� + let _hideCol = [] // 闅愯棌鍙婂悎骞跺垪涓瓧娈电殑uuid闆� + let colMap = new Map() // 鐢ㄤ簬瀛楁杩囨护 + + 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) + } + }) // 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) @@ -122,8 +237,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)) @@ -140,9 +261,6 @@ } }) - let _actions = config.action.filter(item => item.position === 'toolbar') // 杩囨护宸ュ叿鏍忔寜閽� - let _operations = config.action.filter(item => item.position === 'grid') // 娣诲姞鎿嶄綔鍒楋紙瀛樺湪鏃讹級 - if (config.gridBtn && config.gridBtn.display && _operations.length > 0) { _columns.push({ ...config.gridBtn, @@ -150,48 +268,52 @@ }) } - - let _isLinkMain = false // 妫�鏌ユ槸鍚︽湁涓庝富琛ㄥ叧鑱旂殑瀛愯〃 - let supmenus = {} - config.tabgroups.forEach(group => { - if (config[group] && config[group].length > 0) { - config[group] = config[group].map(tab => { - if (tab.subtabs && tab.subtabs.length > 0) { - tab.subtabs.forEach(id => { - supmenus[id] = tab.uuid - }) - } - if (config.setting.subtabs.includes(tab.uuid)) { - tab.supMenu = 'mainTable' - _isLinkMain = true - } else if (supmenus[tab.uuid]) { - tab.supMenu = supmenus[tab.uuid] - } - - return tab - }) + let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉, 鍒濆鎼滅储鏉′欢 + let initSearch = config.search.map(item => { + let _item = JSON.parse(JSON.stringify(item)) + if (_item.type === 'text' && param && param.searchkey === _item.field) { + _item.initval = param.searchval } + + if (_item.required === 'true' && !_item.initval) { + valid = false + } + return _item }) + + if (_curUserConfig) { + _columns = _columns.map(item => { + if (_curUserConfig.columns[item.uuid]) { + delete _curUserConfig.columns[item.uuid].label + item = {...item, ..._curUserConfig.columns[item.uuid]} + } + + return item + }) + + _columns.sort((pre, next) => { + return pre.sort - next.sort + }) + } this.setState({ loadingview: false, config: config, + tabActive: _tabActive, + userConfig: userConfig, setting: config.setting, searchlist: config.search, actions: _actions, columns: _columns, - isLinkMain: _isLinkMain, + logcolumns: _logcolumns, arr_field: _arrField.join(','), - search: Utils.initMainSearch(config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 + search: Utils.initMainSearch(initSearch) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 }, () => { this.improveSearch() - - if (config.setting.onload !== 'false') { // 鍒濆鍖栧彲鍔犺浇 - this.setState({ - loading: true - }) + if (config.setting.onload !== 'false' && valid) { // 鍒濆鍖栧彲鍔犺浇 this.loadmaindata() } + this.setShortcut() }) } else { this.setState({ @@ -201,7 +323,103 @@ notification.warning({ top: 92, message: result.message, - duration: 10 + duration: 5 + }) + } + } + + setShortcut = () => { + const { actions, userConfig, config } = this.state + if (!userConfig) return + + document.onkeydown = (event) => { + let e = event || window.event + let keyCode = e.keyCode || e.which || e.charCode + let preKey = '' + + if (e.ctrlKey) { + preKey = 'ctrl' + } else if (e.shiftKey) { + preKey = 'shift' + } else if (e.altKey) { + preKey = 'alt' + } + + if (!preKey) return + + let istrigger = false + + actions.forEach(item => { + if (!item.shortcut || typeof(item.shortcut) !== 'object' || item.shortcut.length === 0 || istrigger) return + + if (preKey === item.shortcut[0] && keyCode === item.shortcut[1]) { + e.preventDefault() + istrigger = true + + this.setState({ + triggerBtn: { + uuid: new Date().getTime(), + parentId: this.props.MenuID, + button: item, + data: null + } + }) + } + }) + + if (istrigger) return + + Object.keys(userConfig).forEach(key => { + if (key === this.props.MenuID || !userConfig[key].action || istrigger) return + + let _actions = userConfig[key].action + + Object.keys(_actions).forEach(btnkey => { + let item = _actions[btnkey] + + if (!item.shortcut || typeof(item.shortcut) !== 'object' || item.shortcut.length === 0 || istrigger) return + + if (preKey === item.shortcut[0] && keyCode === item.shortcut[1]) { + e.preventDefault() + istrigger = true + + let _groupId = '' + let _ActiveTabId = '' + config.tabgroups.forEach(groupId => { + if (!config[groupId] || config[groupId].length === 0) return + + let _tab = config[groupId].filter(tab => tab.uuid === key)[0] + if (_tab) { + _groupId = groupId + _ActiveTabId = _tab.uuid + } + }) + + if (this.state.tabActive[_groupId] === _ActiveTabId) { + this.setState({ + triggerBtn: { + uuid: new Date().getTime(), + parentId: key, + button: {...item, uuid: btnkey}, + data: null + } + }) + } else { + this.setState({ + tabActive: {...this.state.tabActive, [_groupId]: _ActiveTabId} + }, () => { + this.setState({ + triggerBtn: { + uuid: new Date().getTime(), + parentId: key, + button: {...item, uuid: btnkey}, + data: null + } + }) + }) + } + } + }) }) } } @@ -225,6 +443,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', @@ -237,7 +456,7 @@ 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) }) @@ -247,7 +466,7 @@ notification.warning({ top: 92, message: item.label + ': ' + this.state.dict['main.datasource.settingerror'], - duration: 10 + duration: 5 }) } }) @@ -282,7 +501,7 @@ notification.warning({ top: 92, message: res.search.label + ':' + res.message, - duration: 10 + duration: 5 }) } }) @@ -295,8 +514,23 @@ * @description 涓昏〃鏁版嵁鍔犺浇 */ async loadmaindata () { - const { setting, BIDs } = this.state + const { setting, BIDs, search } = this.state let param = '' + + 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 (setting.interType !== 'inner' || (setting.interType === 'inner' && setting.innerFunc)) { param = this.getCustomParam() @@ -304,11 +538,7 @@ param = this.getDefaultParam() } - this.setState({ - pickup: false - }) - - this.handleTableId('mainTable', '') + this.handleTableId('mainTable', '', '') if (!param) { // 鏈幏鍙栧弬鏁版椂锛屼笉鍙戣姹� return @@ -323,6 +553,7 @@ }), total: result.total, loading: false, + pickup: false, BIDs: { ...BIDs, mainTable: '' @@ -335,7 +566,7 @@ notification.error({ top: 92, message: result.message, - duration: 15 + duration: 10 }) } } @@ -344,22 +575,26 @@ * @description 鑾峰彇鐢ㄦ埛鑷畾涔夊瓨鍌ㄨ繃绋嬩紶鍙� */ getCustomParam = () => { - const { pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state + const { pageIndex, pageSize, orderBy, search, setting } = this.state let _search = Utils.formatCustomMainSearch(search) let param = { PageIndex: pageIndex, PageSize: pageSize, - OrderCol: orderColumn, - OrderType: orderType, + OrderCol: orderBy || setting.order, ..._search } if (setting.interType === 'inner') { param.func = setting.innerFunc } 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 + } + if (setting.outerFunc) { param.func = setting.outerFunc } @@ -372,13 +607,13 @@ * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁� */ getDefaultParam = () => { - const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state + const { arr_field, pageIndex, pageSize, orderBy, search, setting } = this.state if (!arr_field) { notification.warning({ top: 92, message: '鏈缃樉绀哄垪锛�', - duration: 10 + duration: 5 }) return null } @@ -393,7 +628,7 @@ arr_field: arr_field } - let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order + let _orderBy = orderBy || setting.order let _dataresource = setting.dataresource if (/\s/.test(_dataresource)) { @@ -401,23 +636,14 @@ } if (setting.queryType === 'statistics') { // 缁熻鏁版嵁婧愶紝鍐呭鏇挎崲 - let fieldmap = new Map() - let options = search.map(item => { - let _field = item.key + let allSearch = Utils.getAllSearchOptions(search) - if (fieldmap.has(_field)) { - _field = _field + '1' - } - - fieldmap.set(item.key, true) - + let options = allSearch.map(item => { return { - reg: new RegExp('@' + _field, 'ig'), + reg: new RegExp('@' + item.key + '@', 'ig'), value: item.value } }) - - options.reverse() options.forEach(item => { _dataresource = _dataresource.replace(item.reg, `'${item.value}'`) @@ -426,7 +652,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) @@ -446,7 +672,6 @@ if (setting.onload === 'false') { this.setState({ - loading: true, pageIndex: 1, search: searches, setting: {...setting, onload: 'true'} @@ -457,7 +682,6 @@ this.refs.mainTable.resetTable() this.setState({ - loading: true, pageIndex: 1, search: searches }, () => { @@ -479,11 +703,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() }) @@ -495,7 +717,6 @@ reloadtable = () => { this.refs.mainTable.resetTable() this.setState({ - loading: true, pageIndex: 1 }, () => { this.loadmaindata() @@ -507,10 +728,13 @@ */ reloadview = () => { this.setState({ + view: 'commontable', loadingview: true, viewlost: false, lostmsg: '', config: {}, + userConfig: null, + userParam: null, searchlist: null, actions: null, columns: null, @@ -521,14 +745,10 @@ loading: false, pageIndex: 1, pageSize: 10, - orderColumn: '', - orderType: 'asc', + orderBy: '', search: '', - configMap: {}, BIDs: {}, - setsingle: false, - pickup: false, - isLinkMain: false + pickup: false }, () => { this.loadconfig() }) @@ -541,80 +761,73 @@ 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 === 'view' && type === 'pop') { this.reloadview() } else if (btn.popClose === 'grid' && type === 'pop') { this.reloadtable() - } else if (type === 'excelOut') { - this.handleDefaultExcelout(btn) } + } + + /** + * @description 琛ㄥ崟鎿嶄綔瀹屾垚鍚庡埛鏂颁富椤甸潰 + */ + refreshbyformtab = (type) => { + this.setState({ + view: 'commontable', + tabBtn: null, + tabParam: null + }, () => { + if (type === 'grid') { + this.reloadtable() + } else if (type === 'view') { + this.reloadview() + } + }) } /** * @description 瀛愯〃鎿嶄綔瀹屾垚鍚庡埛鏂颁富琛� */ - handleMainTable = () => { - this.reloadtable() + handleMainTable = (type, tab) => { + if (type === 'maingrid' && tab.supMenu === 'mainTable') { + this.reloadtable() + } 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 + }) + }) + } } /** - * @description 浣跨敤榛樿瀛樺偍杩囩▼ sPC_Get_TableData 瀵煎嚭excel琛ㄦ牸 + * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ - handleDefaultExcelout = (btn) => { + getexceloutparam = () => { const { MenuName } = this.props - const { arr_field, orderColumn, orderType, search, setting, config } = this.state + 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 : '' - - // 鑾峰彇excel鏁版嵁锛屼笌鑾峰彇鍒楄〃鏁版嵁涓嶅悓涓烘湭璁剧疆椤电爜绛夊弬鏁� - let param = { - func: 'sPC_Get_TableData', - obj_name: 'data', - arr_field: _arr_labels + return { + arr_field: arr_field, + orderBy: orderBy || setting.order, + search: search, + menuName: MenuName } - - let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order - let _dataresource = setting.dataresource - - if (/\s/.test(_dataresource)) { - _dataresource = '(' + _dataresource + ') tb' - } - - 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.mainButton.execError(res, btn) - } else { - this.refs.mainButton.execSuccess(btn) - } - }) } /** @@ -632,36 +845,28 @@ * @description 琛ㄦ牸涓紝鎸夐挳瑙﹀彂浜嬩欢浼犻�� */ buttonTrigger = (btn, record) => { - this.refs.mainButton.actionTrigger(btn, record) - } - - /** - * @description 琛ㄦ牸Id鍙樺寲 - */ - handleTableId = (type, id) => { - const { BIDs } = this.state - this.setState({ - BIDs: { - ...BIDs, - [type]: id + triggerBtn: { + uuid: new Date().getTime(), + parentId: this.props.MenuID, + button: btn, + data: record } }) } /** - * @description 琛ㄦ牸鍗曢�夊閫夊垏鎹� + * @description 琛ㄦ牸Id鍙樺寲 */ - checkChange = () => { - const { setsingle, BIDs } = this.state - - let _BIDs = JSON.parse(JSON.stringify(BIDs)) - _BIDs.mainTable = '' + handleTableId = (type, id, data) => { + const { BIDs } = this.state this.setState({ - setsingle: !setsingle, - pickup: false, - BIDs: _BIDs + BIDs: { + ...BIDs, + [type]: id, + [type + 'data']: data + } }) } @@ -679,39 +884,70 @@ * @description 瑙﹀彂鎸夐挳寮圭獥锛堟爣绛鹃〉锛� */ triggerPopview = (btn, data) => { + const { setting } = this.state + + let _primaryId = '' + + if (data && data[0] && setting.primaryKey) { + _primaryId = data[0][setting.primaryKey] || '' + } + if (btn.OpenType === 'popview') { this.setState({ popAction: btn, - popData: data[0] ? data[0] : null, + popData: data[0] || null, visible: true }) } else if (btn.OpenType === 'tab') { - // const { tabviews, MenuNo, MenuID } = this.props - // let newtab = { - // MenuNo: MenuNo, - // MenuID: btn.uuid, - // MenuName: btn.label, - // type: btn.tabTemplate, - // selected: true, - // param: { - // btn: btn, - // data: data - // } - // } + const { tabviews, MenuNo, MenuID } = this.props + let newtab = { + MenuNo: MenuNo, + MenuID: btn.uuid, + MenuName: btn.label, + type: btn.tabTemplate, + selected: true, + param: { + menuType: 'main', + parentId: this.props.MenuID, + btn: btn, + data: data[0] || null, + primaryId: btn.Ot !== 'notRequired' ? _primaryId : '', + arr_field: this.state.arr_field + } + } - // let index = 0 - // let tabs = tabviews.map((tab, i) => { - // if (tab.MenuID === MenuID) { - // index = i - // } - // tab.selected = false + let index = 0 + let isexit = false + let tabs = tabviews.map((tab, i) => { + tab.selected = false - // return tab - // }) + if (tab.MenuID === MenuID) { + index = i + } else if (tab.MenuID === btn.uuid) { + tab.selected = true + isexit = true + } - // tabs.splice(index + 1, 0, newtab) - - // this.props.modifyTabview(tabs) + return tab + }) + + if (!isexit) { + tabs.splice(index + 1, 0, newtab) + } + + this.props.modifyTabview(tabs) + } else if (btn.OpenType === 'blank') { + this.setState({ + view: 'formtab', + tabBtn: btn, + tabParam: { + menuType: 'main', + btn: btn, + data: data[0] || null, + primaryId: btn.Ot !== 'notRequired' ? _primaryId : '', + arr_field: this.state.arr_field + } + }) } } @@ -722,9 +958,214 @@ this.refreshbyaction(this.state.popAction, 'pop') } + handleviewconfig = (e) => { + e.stopPropagation() + + const { MenuNo } = this.props + const { config } = this.state + + if (config && config.funcs && config.funcs.length > 0) { + this.setState({ + treevisible: true + }) + } else { + let oInput = document.createElement('input') + oInput.value = MenuNo || '' + document.body.appendChild(oInput) + oInput.select() + document.execCommand('Copy') + document.body.removeChild(oInput) + message.success(this.state.dict['main.copy.success']) + } + } + + getTreeNode = (data) => { + let _type = { + view: '椤甸潰', + btn: '鎸夐挳', + tab: '鏍囩' + } + + return data.map(item => { + let _title = _type[item.subtype] + let _others = [] + + _others.push( + (item.menuNo ? item.menuNo + '(鑿滃崟鍙傛暟)' : ''), + (item.tableName ? item.tableName + '(琛ㄥ悕) ' : ''), + (item.innerFunc ? item.innerFunc + '(鍐呴儴鍑芥暟) ' : ''), + (item.outerFunc ? item.outerFunc + '(澶栭儴鍑芥暟)' : '') + ) + _others = _others.filter(Boolean) + _others = _others.join('銆�') + + if (item.label) { + _title = _title + '(' + item.label + ')' + } + if (_others) { + _title = _title + ': ' + _others + } + + if (item.subfuncs && item.subfuncs.length > 0) { + return ( + <TreeNode title={_title} key={item.uuid} dataRef={item} selectable={false}> + {this.getTreeNode(item.subfuncs)} + </TreeNode> + ) + } + return <TreeNode key={item.uuid} title={_title} isLeaf selectable={false} /> + }) + } + + controlCustomSetting = () => { + this.setState({ + settingVisible: true, + confirmLoading: false, + revertLoading: false + }) + } + + changeMenuParam = (param) => { + this.setState({userParam: param}) + } + + linkTrigger = (menu) => { + const { tabviews, MenuID } = this.props + + menu.selected = true + + let index = 0 + let isexit = false + let tabs = tabviews.map((tab, i) => { + tab.selected = false + + if (tab.MenuID === MenuID) { + 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) + } + + settingRevert = () => { + let param = { + func: 's_TrdMenu_UserParam_del', + MenuID: this.props.MenuID + } + this.setState({ + revertLoading: true + }) + + Api.getSystemConfig(param).then(result => { + if (!result.status) { + this.setState({ + revertLoading: false + }) + notification.warning({ + top: 92, + message: result.message, + duration: 5 + }) + return + } + this.setState({ + settingVisible: false, + revertLoading: false + }, () => { + window.GLOB.CacheMap = new Map() + this.reloadview() + }) + }) + } + + settingSubmit = () => { + const { userParam } = this.state + let _LongParam = '' + + try { + _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(userParam))) + } catch (e) { + notification.warning({ + top: 92, + message: '缂栬瘧閿欒', + duration: 5 + }) + return + } + + let easyCode = userParam[this.props.MenuID] ? userParam[this.props.MenuID].easyCode : '' + + let param = { + func: 'sPC_TrdMenu_UserParam', + MenuID: this.props.MenuID, + EasyCode: easyCode || '', + LongParam: _LongParam + } + + this.setState({ + confirmLoading: true + }) + + Api.getSystemConfig(param).then(result => { + if (!result.status) { + this.setState({ + confirmLoading: false + }) + notification.warning({ + top: 92, + message: result.message, + duration: 5 + }) + return + } + this.setState({ + settingVisible: false, + confirmLoading: false + }, () => { + window.GLOB.CacheMap = new Map() + this.reloadview() + }) + }) + } + UNSAFE_componentWillMount () { // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁 this.loadconfig() + } + + UNSAFE_componentWillReceiveProps(nextProps) { + if (nextProps.refreshTab && nextProps.refreshTab.MenuID === this.props.MenuID) { + if (nextProps.refreshTab.position === 'grid') { + this.reloadtable() + } else if (nextProps.refreshTab.position === 'view') { + this.reloadview() + } + this.props.refreshTabView('') + } else if (!is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) { + let selectTab = nextProps.tabviews.filter(tab => tab.selected)[0] + if (selectTab && selectTab.MenuID === this.props.MenuID) { + this.setShortcut() + } + } else if (nextProps.param && !is(fromJS(this.props.param), fromJS(nextProps.param))) { + let search = this.state.search.map(item => { + if (item.type === 'text' && item.key === nextProps.param.searchkey) { + item.value = nextProps.param.searchval + } + + return item + }) + this.refreshbysearch(search) + } } shouldComponentUpdate (nextProps, nextState) { @@ -732,119 +1173,192 @@ } /** - * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 + * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆 */ componentWillUnmount () { this.setState = () => { return } + document.onkeydown = () => {} } render() { - const { setting, searchlist, actions, columns, loadingview, viewlost, setsingle, pickup, isLinkMain, config } = this.state + const { view, setting, searchlist, actions, columns, loadingview, viewlost, pickup, config, triggerBtn, userConfig, tabActive, search } = this.state return ( - <div className={'commontable ' + (isLinkMain ? 'pick-control' : '')} id={'commontable' + this.props.MenuID}> - {loadingview && <Spin size="large" />} - {searchlist && searchlist.length > 0 ? - <MainSearch - dict={this.state.dict} - searchlist={searchlist} - refreshdata={this.refreshbysearch} - /> : null - } - {actions && setting.onload !== 'false' ? - <MainAction - ref="mainButton" - BID="" - type="main" - setting={setting} - actions={actions} - dict={this.state.dict} - MenuID={this.props.MenuID} - refreshdata={this.refreshbyaction} - triggerPopview={this.triggerPopview} - gettableselected={this.gettableselected} - /> : null - } - {columns && setting.onload !== 'false' ? - <div className="main-table-box"> - {isLinkMain ? - <div className="pickchange"> - {setting.tableType === 'checkbox' ? <Switch title="鍗曢�夊垏鎹�" checkedChildren="鍗�" unCheckedChildren="澶�" defaultChecked={setsingle} onChange={this.checkChange} /> : null} - {this.state.BIDs.mainTable && (setting.tableType === 'radio' || setsingle) ? <Switch title="鏀惰捣" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null} - </div> : null - } - <MainTable - ref="mainTable" - pickup={pickup} - setting={setting} - columns={columns} - setsingle={setsingle} + <div> + {view === 'commontable' ? <div className="commontable pick-control" id={this.state.ContainerId}> + {loadingview && <Spin size="large" />} + {searchlist && searchlist.length > 0 ? + <MainSearch + ref="mainSearch" 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} - handleTableId={this.handleTableId} - /> - </div> : null - } - {setting && setting.onload !== 'false' && - config.tabgroups.map(group => { - if (config[group].length === 0) return null + searchlist={searchlist} + refreshdata={this.refreshbysearch} + /> : null + } + {actions && setting.onload !== 'false' ? + <div style={{minHeight: '25px'}}> + <MainAction + BID="" + type="main" + menuType="main" + setting={setting} + actions={actions} + triggerBtn={triggerBtn} + dict={this.state.dict} + MenuID={this.props.MenuID} + permRoles={this.props.permRoles} + logcolumns={this.state.logcolumns} + ContainerId={this.state.ContainerId} + refreshdata={this.refreshbyaction} + triggerPopview={this.triggerPopview} + getexceloutparam={this.getexceloutparam} + gettableselected={this.gettableselected} + /> + </div> : null + } + {columns && setting.onload !== 'false' ? + <div className="main-table-box"> + <Icon className="custom-control" type="setting" onClick={this.controlCustomSetting} /> + {this.state.data && this.state.data.length > 0 ? + <Switch title="鏀惰捣" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null + } + <MainTable + ref="mainTable" + tableId="mainTable" + 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 + } + {setting && setting.onload !== 'false' && + config.tabgroups.map(group => { + if (config[group].length === 0) return null - return ( - <Tabs defaultActiveKey="0" key={group}> - {config[group].map((_tab, index) => { - // return !_tab.supMenu || (_tab.supMenu && this.state.BIDs[_tab.supMenu]) ? - return ( - <TabPane tab={ - <span> - {_tab.icon ? <Icon type={_tab.icon} /> : null} - {_tab.label} - </span> - } key={`${index}`}> - {_tab.type === 'SubTable' ? - <SubTable - Tab={_tab} - MenuID={_tab.linkTab} - SupMenuID={this.props.MenuID} - BID={this.state.BIDs[_tab.supMenu] || ''} - handleTableId={this.handleTableId} - handleMainTable={this.handleMainTable} - /> : null} - </TabPane> - ) - })} - </Tabs> - ) - }) - } - <Modal - className="popview-modal" - title={this.state.popAction.label} - width={'80vw'} - maskClosable={false} - visible={this.state.visible} - onCancel={this.popclose} - footer={[ - <Button key="cancel" 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] : ''} />} - </Modal> - <BackTop> - <div className="ant-back-top"> - <div className="ant-back-top-content"> - <div className="ant-back-top-icon"></div> + return ( + <Tabs activeKey={tabActive[group]} key={group} onChange={(key) => this.setState({tabActive: {...tabActive, [group]: key}})}> + {config[group].map(_tab => { + return ( + <TabPane tab={ + <span> + {_tab.icon ? <Icon type={_tab.icon} /> : null} + {_tab.label} + </span> + } key={_tab.uuid}> + {_tab.type === 'SubTable' ? + <SubTable + Tab={_tab} + menuType="main" + MenuID={_tab.linkTab} + mainSearch={_tab.searchPass === 'true' ? search : null} + userConfig={userConfig ? userConfig[_tab.uuid] : null} + triggerBtn={triggerBtn} + 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} + </TabPane> + ) + })} + </Tabs> + ) + }) + } + <Button + icon="copy" + shape="circle" + className="common-table-copy" + onClick={this.handleviewconfig} + /> + <Modal + className="popview-modal" + title={this.state.popAction.label} + width={'80vw'} + maskClosable={false} + visible={this.state.visible} + onCancel={this.popclose} + footer={[ + <Button key="close" onClick={this.popclose}>{this.state.dict['main.close']}</Button> + ]} + destroyOnClose + > + {<SubTabTable + BID={''} + menuType="main" + SupMenuID={this.props.MenuID} + MenuID={this.state.popAction.linkTab} + BData={this.state.BIDs['mainTabledata'] || ''} + ContainerId={this.state.ContainerId} + ID={this.state.popData ? this.state.popData[setting.primaryKey] : ''} + refreshSupView={this.reloadtable} + />} + </Modal> + <Modal + className="menu-tree-modal" + title={'鑿滃崟缁撴瀯鏍�'} + width={'650px'} + maskClosable={false} + visible={this.state.treevisible} + onCancel={() => this.setState({treevisible: false})} + footer={[ + <Button key="close" onClick={() => this.setState({treevisible: false})}>{this.state.dict['main.close']}</Button> + ]} + destroyOnClose + > + <div className="menu-header"> + <span>鑿滃崟鍚嶇О锛歿this.props.MenuName}</span> + <span>鑿滃崟鍙傛暟锛歿<Paragraph copyable>{this.props.MenuNo}</Paragraph>}</span> </div> - </div> - </BackTop> - {viewlost ? <NotFount msg={this.state.lostmsg} /> : null} + {this.state.treevisible ? <Tree defaultExpandAll showLine={true}> + {this.getTreeNode(config.funcs)} + </Tree> : null} + </Modal> + {/* 鎸夐挳浣跨敤绯荤粺瀛樺偍杩囩▼鏃讹紝楠岃瘉淇℃伅妯℃�佹 */} + <Modal + wrapClassName="common-table-custom-modal" + title={'鑷畾涔夎缃�'} + maskClosable={false} + width={950} + visible={this.state.settingVisible} + onCancel={() => { this.setState({ settingVisible: false }) }} + footer={[ + <Button key="revert" type="danger" loading={this.state.revertLoading} onClick={this.settingRevert}>{this.state.dict['main.revert.default']}</Button>, + <Button key="cancel" onClick={() => { this.setState({ settingVisible: false }) }}>{this.state.dict['main.cancel']}</Button>, + <Button key="confirm" type="primary" loading={this.state.confirmLoading} onClick={this.settingSubmit}>{this.state.dict['main.submit']}</Button> + ]} + destroyOnClose + > + {this.state.settingVisible ? + <VerifyCard + MenuID={this.props.MenuID} + MenuName={this.props.MenuName} + permAction={this.props.permAction} + permRoles={this.props.permRoles} + config={this.state.config} + userConfig={this.state.userConfig} + columns={this.state.columns} + handleParam={this.changeMenuParam} + /> : null + } + </Modal> + {viewlost ? <NotFount msg={this.state.lostmsg} /> : null} + </div> : null} + {view === 'formtab' ? <FormTab MenuID={this.state.tabBtn.uuid} param={this.state.tabParam} refresh={this.refreshbyformtab}/> : null} </div> ) } @@ -854,7 +1368,9 @@ return { tabviews: state.tabviews, refreshTab: state.refreshTab, - permAction: state.permAction + permAction: state.permAction, + permMenus: state.permMenus, + permRoles: state.permRoles } } -- Gitblit v1.8.0