From 9a82bce9cf0ed4a51c1b0b0669eaa38cedbace07 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 16 七月 2020 16:35:58 +0800 Subject: [PATCH] 2020-07-16 --- src/tabviews/commontable/index.jsx | 1125 +++++++++++++++++++++++++++++++--------------------------- 1 files changed, 603 insertions(+), 522 deletions(-) diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx index ca5f5ff..623948b 100644 --- a/src/tabviews/commontable/index.jsx +++ b/src/tabviews/commontable/index.jsx @@ -2,26 +2,32 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { notification, Spin, Tabs, Icon, Switch, Modal, Button, message, Tree, Typography } from 'antd' +import { notification, Spin, Tabs, Icon, Switch, Modal, Button, message, Tree, Typography, Col } from 'antd' import moment from 'moment' import Api from '@/api' +import options from '@/store/options.js' 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 asyncComponent from '@/utils/asyncComponent' +import asyncSpinComponent from '@/utils/asyncSpinComponent' +import { refreshTabView } from '@/store/action' -import MainTable from '@/tabviews/zshare/normalTable' -import MainAction from '@/tabviews/zshare/actionList' -import VerifyCard from '@/tabviews/zshare/verifycard' import MainSearch from '@/tabviews/zshare/topSearch' import NotFount from '@/components/404' import './index.scss' -const SubTable = asyncLoadComponent(() => import('@/tabviews/subtable')) -const SubTabTable = asyncLoadComponent(() => import('@/tabviews/subtabtable')) -const FormTab = asyncLoadComponent(() => import('@/tabviews/formtab')) +// 閫氱敤缁勪欢 +const MainAction = asyncSpinComponent(() => import('@/tabviews/zshare/actionList')) +const MainTable = asyncSpinComponent(() => import('@/tabviews/zshare/normalTable')) +const SettingComponent = asyncComponent(() => import('@/tabviews/zshare/settingcomponent')) +const SubTable = asyncSpinComponent(() => import('@/tabviews/subtable')) +const CardComponent = asyncSpinComponent(() => import('@/tabviews/zshare/cardcomponent')) +const ChartComponent = asyncSpinComponent(() => import('@/tabviews/zshare/chartcomponent')) + +// 鑷畾涔夋爣绛� +const SecretKeyTable = asyncSpinComponent(() => import('./secretKeyTable')) const { TabPane } = Tabs const { TreeNode } = Tree @@ -29,19 +35,21 @@ 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', // 褰撳墠椤甸潰榛樿涓轰富琛� + BID: null, // 椤甸潰璺宠浆鏃舵惡甯D loadingview: true, // 椤甸潰鍔犺浇涓� viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 lostmsg: '', // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅 config: {}, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑 + userConfig: null, // 鐢ㄦ埛鑷畾涔夎缃� searchlist: null, // 鎼滅储鏉′欢 actions: null, // 鎸夐挳闆� columns: null, // 鏄剧ず鍒� @@ -49,6 +57,8 @@ arr_field: '', // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆� setting: null, // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑 data: null, // 鍒楄〃鏁版嵁闆� + selectedData: [], // 宸查�夎〃鏍兼暟鎹� + resetTable: false, // 琛ㄦ牸閲嶇疆锛屽�煎湪true涓巉alse涔嬮棿鍒囨崲锛屽垏鎹㈡椂琛ㄦ牸閲嶇疆 total: 0, // 鎬绘暟 loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� pageIndex: 1, // 椤电爜 @@ -57,32 +67,29 @@ search: '', // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞� BIDs: {}, // 涓婄骇琛╥d pickup: false, // 涓昏〃鏁版嵁闅愯棌鏄剧ず鍒囨崲 - popAction: false, // 寮规椤甸潰锛屾寜閽俊鎭� - popData: false, // 寮规椤甸潰锛屾墍閫夌殑琛ㄦ牸鏁版嵁 - visible: false, // 寮规鏄剧ず闅愯棌鎺у埗 treevisible: false, // 鑿滃崟缁撴瀯鏍戝脊妗嗘樉绀洪殣钘忔帶鍒� - tabBtn: null, // 琛ㄥ崟鏍囩鎸夐挳 - tabParam: null, // 琛ㄥ崟鏍囩鍙傛暟 refreshtabs: null, // 闇�瑕佸埛鏂扮殑鏍囩闆� - confirmLoading: false,// 鑷畾涔夎缃ā鎬佹鍔犺浇涓� - settingVisible: false // 鑷畾涔夎缃ā鎬佹 + triggerBtn: null, // 鐐瑰嚮琛ㄦ牸涓垨蹇嵎閿Е鍙戠殑鎸夐挳 + tabActive: null, // 鏍囩椤靛睍寮�鎺у埗 + chartId: '' // 灞曞紑鍥捐〃ID } /** * @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 = '' + let userConfig = null + let _curUserConfig = '' try { // 閰嶇疆淇℃伅瑙f瀽 config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) @@ -91,12 +98,14 @@ config = '' } - if (result.LongParamUser) { + // HS涓嶄娇鐢ㄨ嚜瀹氫箟璁剧疆 + if (result.LongParamUser && this.props.menuType !== 'HS') { try { // 閰嶇疆淇℃伅瑙f瀽 userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser))) + _curUserConfig = userConfig[this.props.MenuID] } catch (e) { console.warn('Parse Failure') - userConfig = '' + userConfig = null } } @@ -119,58 +128,172 @@ return } + if (!config.version || config.version < '1.0') { + // 鍏煎鏍囩 + 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 (!config.charts) { + config.expand = true + config.charts = [{ uuid: Utils.getuuid(), label: '', title: '', chartType: 'table', icon: 'table', Hide: 'false', blacklist: [] }] + } else { + config.charts.forEach(card => { + if (card.chartType === 'card') { + card.details = card.details.map(_cell => { + _cell.fontSize = _cell.fontSize || 14 + if (!_cell.width) { + _cell.width = 100 + } else if (_cell.width === 'helf') { + _cell.width = 50 + } else if (_cell.width === 'third') { + _cell.width = 33 + } + if (!_cell.fontWeight && _cell.bold === 'true') { + _cell.fontWeight = 'normal' + } + _cell.height = _cell.height || 1 + + return _cell + }) + } + }) + } + } + // 鏉冮檺杩囨护 - config.action = config.action.filter(item => permAction[item.uuid]) - config.tabgroups.forEach(group => { - if (!config[group]) return + if (this.props.menuType !== 'HS') { + config.action = config.action.filter(item => permAction[item.uuid]) + config.tabgroups.forEach(group => { + group.sublist = group.sublist.filter(tab => permAction[tab.linkTab]) + }) + } + // 鍘婚櫎绌鸿鏍囩 + config.tabgroups = config.tabgroups.filter(group => group.sublist.length > 0) - config[group] = config[group].filter(tab => permAction[tab.linkTab]) - }) + // HS涓嬭嚜瀹氫箟澶勭悊鐨勬爣绛� + if (this.props.menuType === 'HS') { + config.tabgroups.forEach(group => { + group.sublist = group.sublist.map(tab => { + if (tab.linkTab === '1586577325055l2ng7t75g7i4ek2ng8o') { + tab.type = 'SecretKeyTable' + } + return tab + }) + }) + } - // 瀛楁鏉冮檺榛戝悕鍗� - config.search = config.search.filter(item => { + // 瑙嗗浘鏉冮檺 + config.charts = config.charts.filter(item => { + if (item.Hide === 'true') return false if (!item.blacklist || item.blacklist.length === 0) return true let _black = item.blacklist.filter(v => { return this.props.permRoles.indexOf(v) !== -1 }) - if (_black.length > 0) { + if (_black.length > 0 || item.Hide === 'true') { 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 + if (config.charts.length <= 1) { + config.expand = true + } + let chartId = config.charts[0] ? config.charts[0].uuid : '' + + // 瀛楁鏉冮檺榛戝悕鍗� + config.search = config.search.map(item => { + item.oriInitval = item.initval + if (['text', 'select', 'link'].includes(item.type) && param) { + if (param.searchkey === item.field) { + item.initval = param.searchval + } else if (param.BID && item.field === 'BID') { + item.initval = param.BID + } + } + + if (!item.blacklist || item.blacklist.length === 0) return item + + let _black = item.blacklist.filter(v => { + return this.props.permRoles.indexOf(v) !== -1 + }) + + if (_black.length > 0) { + item.Hide = 'true' + } + + return item + }) + + config.columns = config.columns.map(col => { + if (!col.field || !col.blacklist || col.blacklist.length === 0 || config.setting.primaryKey === col.field) return col let _black = col.blacklist.filter(v => { return this.props.permRoles.indexOf(v) !== -1 }) if (_black.length > 0) { - return false - } else { - return true + col.Hide = 'true' } + + return col }) - if (userConfig) { - config.setting = {...config.setting, ...userConfig.setting} - let _actions = {} - userConfig.action.forEach(item => { - _actions[item.uuid] = item - }) + // 鏍囪涓婚〉闈紝鐢ㄤ簬鎸夐挳鍥哄畾鍙婅〃鍗曟寕杞借缃� + config.setting.tabType = 'main' + + if (_curUserConfig) { + config.setting = {...config.setting, ..._curUserConfig.setting} + config.easyCode = _curUserConfig.easyCode || config.easyCode || '' config.action = config.action.map(item => { - if (_actions[item.uuid]) { - item = {...item, ..._actions[item.uuid]} + 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(group => { + _tabActive[group.uuid] = group.sublist[0].uuid + }) let _arrField = [] // 瀛楁闆� let _columns = [] // 鏄剧ず鍒� @@ -193,20 +316,13 @@ } }) - if (config.gridBtn && config.gridBtn.display && _operations.length > 0) { - _columns.push({ - ...config.gridBtn, - operations: _operations - }) - } - - // 1銆佺瓫閫夊瓧娈甸泦锛�2銆佽繃婊ら殣钘忓垪鍙婂悎骞跺垪涓殑瀛楁uuid config.columns.forEach(col => { if (col.field) { _arrField.push(col.field) - _logcolumns.push(col) + + col.nameField && _arrField.push(col.nameField) // 閾炬帴鍚嶅瓧娈� } if (col.type === 'colspan' && col.sublist) { // 绛涢�夐殣钘忓垪 _hideCol = _hideCol.concat(col.sublist) @@ -217,11 +333,17 @@ }) // 鐢熸垚鏄剧ず鍒楋紝澶勭悊鍚堝苟鍒椾腑鐨勫瓧娈� - 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)) + let _col = fromJS(col).toJS() let subColumn = [] _col.sublist.forEach(sub => { if (colMap.has(sub)) { @@ -234,26 +356,52 @@ _columns.push(col) } }) + + if (config.gridBtn && config.gridBtn.display && _operations.length > 0) { + config.gridBtn.operations = _operations + _columns.push(config.gridBtn) + } - let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉 - config.search.forEach(field => { - if (field.required === 'true' && !field.initval) { + let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉, 鍒濆鎼滅储鏉′欢, 濡傞�氳繃涓婄骇閫忚锛屽啓鍏ユ悳绱㈡潯浠� + let initSearch = config.search.map(item => { + let _item = fromJS(item).toJS() + + 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({ + BID: param && param.BID ? param.BID : '', loadingview: false, + chartId: chartId, config: config, + tabActive: _tabActive, + userConfig: userConfig, setting: config.setting, searchlist: config.search, actions: _actions, columns: _columns, logcolumns: _logcolumns, arr_field: _arrField.join(','), - search: Utils.initMainSearch(config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 + search: Utils.initMainSearch(initSearch) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 }, () => { - this.improveSearch() if (config.setting.onload !== 'false' && valid) { // 鍒濆鍖栧彲鍔犺浇 this.loadmaindata() } @@ -267,14 +415,14 @@ notification.warning({ top: 92, message: result.message, - duration: 10 + duration: 5 }) } } setShortcut = () => { - const { actions } = this.state - if (!actions) return + const { actions, userConfig, config } = this.state + if (!userConfig) return document.onkeydown = (event) => { let e = event || window.event @@ -288,8 +436,11 @@ } 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 @@ -297,111 +448,89 @@ e.preventDefault() istrigger = true - this.refs.mainButton.actionTrigger(item) + this.setState({ + triggerBtn: { + uuid: new Date().getTime(), + parentId: this.props.MenuID, + button: item, + data: null + } + }) } }) - } - } - /** - * @description 鎼滅储鏉′欢涓嬫媺閫夐」棰勫姞杞� - */ - improveSearch = () => { - let searchlist = JSON.parse(JSON.stringify(this.state.searchlist)) - let deffers = [] - searchlist.forEach(item => { - if (item.type !== 'multiselect' && item.type !== 'select' && item.type !== 'link') return - if (item.setAll === 'true') { - item.options.unshift({ - key: Utils.getuuid(), - Value: '', - Text: this.state.dict['main.all'] - }) - } + if (istrigger) return - if (item.resourceType === '1' && item.dataSource) { - let _option = Utils.getSelectQueryOptions(item) - let _sql = Utils.formatOptions(_option.sql) - let isSSO = item.database === 'sso' + Object.keys(userConfig).forEach(key => { + if (key === this.props.MenuID || !userConfig[key].action || istrigger) return - let param = { - func: 'sPC_Get_SelectedList', - LText: _sql, - obj_name: 'data', - arr_field: _option.field - } + let _actions = userConfig[key].action - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' - param.secretkey = Utils.encrypt(param.LText, param.timestamp) + Object.keys(_actions).forEach(btnkey => { + let item = _actions[btnkey] - let defer = new Promise(resolve => { - Api.getSystemCacheConfig(param, isSSO).then(res => { - res.search = item - resolve(res) - }) - }) - deffers.push(defer) - } else if (item.resourceType === '1' && !item.dataSource) { - notification.warning({ - top: 92, - message: item.label + ': ' + this.state.dict['main.datasource.settingerror'], - duration: 10 - }) - } - }) + if (!item.shortcut || typeof(item.shortcut) !== 'object' || item.shortcut.length === 0 || istrigger) return - if (deffers.length === 0) { - this.setState({searchlist: JSON.parse(JSON.stringify(searchlist))}) - return - } + if (preKey === item.shortcut[0] && keyCode === item.shortcut[1]) { + e.preventDefault() + istrigger = true - Promise.all(deffers).then(result => { - result.forEach(res => { - if (res.status) { - searchlist = searchlist.map(item => { - if (item.uuid === res.search.uuid) { - res.data.forEach(cell => { - let _item = { - key: Utils.getuuid(), - Value: cell[res.search.valueField], - Text: cell[res.search.valueText] + let _groupId = '' + let _ActiveTabId = '' + config.tabgroups.forEach(group => { + if (group.sublist.length === 0) return + + let _tab = group.sublist.filter(tab => tab.uuid === key)[0] + if (_tab) { + _groupId = group.uuid + _ActiveTabId = _tab.uuid + } + }) + + if (this.state.tabActive[_groupId] === _ActiveTabId) { + this.setState({ + triggerBtn: { + uuid: new Date().getTime(), + parentId: key, + button: {...item, uuid: btnkey}, + data: null } - - if (res.search.type === 'link') { - _item.parentId = cell[res.search.linkField] - } - - item.options.push(_item) + }) + } else { + this.setState({ + tabActive: {...this.state.tabActive, [_groupId]: _ActiveTabId} + }, () => { + this.setState({ + triggerBtn: { + uuid: new Date().getTime(), + parentId: key, + button: {...item, uuid: btnkey}, + data: null + } + }) }) } - return item - }) - } else { - notification.warning({ - top: 92, - message: res.search.label + ':' + res.message, - duration: 10 - }) - } + } + }) }) - - this.setState({searchlist}) - }) + } } /** * @description 涓昏〃鏁版嵁鍔犺浇 */ async loadmaindata () { - const { setting, BIDs, search } = this.state + const { setting, BIDs, search, BID } = this.state let param = '' - - let requireFields = search.filter(item => item.required && !item.value) + let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0)) if (requireFields.length > 0) { + let labels = requireFields.map(item => item.label) + labels = Array.from(new Set(labels)) + notification.warning({ top: 92, - message: this.state.dict['form.required.input'] + requireFields.map(item => item.label).join('銆�') + ' !', + message: this.state.dict['form.required.input'] + labels.join('銆�') + ' !', duration: 3 }) return @@ -417,10 +546,12 @@ param = this.getDefaultParam() } - this.handleTableId('mainTable', '', '') - - if (!param) { // 鏈幏鍙栧弬鏁版椂锛屼笉鍙戣姹� - return + if (BID) { + param.BID = BID + } + // 鏁版嵁绠$悊鏉冮檺 + if (this.props.dataManager) { + param.dataM = 'Y' } let result = await Api.genericInterface(param) @@ -435,7 +566,8 @@ pickup: false, BIDs: { ...BIDs, - mainTable: '' + mainTable: '', + mainTabledata: '' } }) } else { @@ -445,7 +577,7 @@ notification.error({ top: 92, message: result.message, - duration: 15 + duration: 10 }) } } @@ -459,22 +591,31 @@ let _search = Utils.formatCustomMainSearch(search) let param = { - PageIndex: pageIndex, - PageSize: pageSize, OrderCol: orderBy || setting.order, ..._search + } + + if (setting.laypage !== 'false') { + param.PageIndex = pageIndex + param.PageSize = pageSize } if (setting.interType === 'inner') { param.func = setting.innerFunc } else { - if (setting.sysInterface === 'true') { - param.rduri = window.GLOB.mainSystemApi || window.GLOB.subSystemApi + 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 { - 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 @@ -494,7 +635,7 @@ notification.warning({ top: 92, message: '鏈缃樉绀哄垪锛�', - duration: 10 + duration: 5 }) return null } @@ -507,7 +648,8 @@ func: 'sPC_Get_TableData', obj_name: 'data', arr_field: arr_field, - appkey: window.GLOB.appkey || '' + custom_script: setting.customScript || '', + default_sql: setting.default || 'true' } let _orderBy = orderBy || setting.order @@ -517,39 +659,90 @@ _dataresource = '(' + _dataresource + ') tb' } - if (setting.queryType === 'statistics') { // 缁熻鏁版嵁婧愶紝鍐呭鏇挎崲 - let fieldmap = new Map() - let options = search.map(item => { - let _field = item.key + if (this.props.dataManager) { // 鏁版嵁鏉冮檺 + _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 (fieldmap.has(_field)) { - _field = _field + '1' - } + let regoptions = null + if (setting.queryType === 'statistics' || param.custom_script) { + let allSearch = Utils.getAllSearchOptions(search) - fieldmap.set(item.key, true) - + regoptions = allSearch.map(item => { return { - reg: new RegExp('@' + _field, 'ig'), - value: item.value + reg: new RegExp('@' + item.key + '@', 'ig'), + value: `'${item.value}'` } }) + } - options.reverse() - - options.forEach(item => { - _dataresource = _dataresource.replace(item.reg, `'${item.value}'`) + if (setting.queryType === 'statistics' && setting.default !== 'false') { // 缁熻鏁版嵁婧愶紝鍐呭鏇挎崲 + regoptions.forEach(item => { + _dataresource = _dataresource.replace(item.reg, item.value) }) - _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 DateCount = `select count(1) as total from ${_dataresource} ${_search}` + let LText = '' + let DateCount = '' + + if (setting.default !== 'false' && setting.laypage !== 'false') { + 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 ` + DateCount = `select count(1) as total from ${_dataresource} ${_search}` + } else if (setting.default !== 'false') { + LText = ` select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows ` + DateCount = '' + } + + if (param.custom_script) { + regoptions.push({ + reg: new RegExp('@orderBy@', 'ig'), + value: _orderBy + }) + if (setting.laypage !== 'false') { + regoptions.push({ + reg: new RegExp('@pageSize@', 'ig'), + value: pageSize + }, { + reg: new RegExp('@pageIndex@', 'ig'), + value: pageIndex + }) + } + + regoptions.forEach(item => { + param.custom_script = param.custom_script.replace(item.reg, item.value) + }) + + if (LText) { + LText += ` + aaa: + if @ErrorCode!='' + insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ + ` + } else { + param.custom_script += ` + aaa: + if @ErrorCode!='' + insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ + ` + } + + param.custom_script = Utils.formatOptions(param.custom_script) + } 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 = Utils.formatOptions(DateCount) + + if (this.props.menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉 + param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true) + } return param } @@ -570,9 +763,9 @@ this.loadmaindata() }) } else { - this.refs.mainTable.resetTable() - this.setState({ + resetTable: !this.state.resetTable, + selectedData: [], pageIndex: 1, search: searches }, () => { @@ -594,6 +787,7 @@ } this.setState({ + selectedData: [], pageIndex: pagination.current, pageSize: pagination.pageSize, orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : '' @@ -606,8 +800,9 @@ * @description 琛ㄦ牸鍒锋柊 */ reloadtable = () => { - this.refs.mainTable.resetTable() this.setState({ + resetTable: !this.state.resetTable, + selectedData: [], pageIndex: 1 }, () => { this.loadmaindata() @@ -618,26 +813,9 @@ * @description 椤甸潰鍒锋柊锛岄噸鏂拌幏鍙栭厤缃� */ reloadview = () => { - this.setState({ - view: 'commontable', - loadingview: true, - viewlost: false, - lostmsg: '', - config: {}, - searchlist: null, - actions: null, - columns: null, - arr_field: '', - setting: null, - data: null, - total: 0, - loading: false, - pageIndex: 1, - pageSize: 10, - orderBy: '', - search: '', - BIDs: {}, - pickup: false + this.setState({ loadingview: true, viewlost: false, lostmsg: '', + data: null, total: 0, loading: false, pageIndex: 1, + pageSize: 10, orderBy: '', search: '', BIDs: {}, pickup: false }, () => { this.loadconfig() }) @@ -646,37 +824,12 @@ /** * @description 鎸夐挳鎿嶄綔瀹屾垚鍚庯紙鎴愬姛鎴栧け璐ワ級锛岄〉闈㈠埛鏂帮紝閲嶇疆椤电爜鍙婇�夋嫨椤� */ - refreshbyaction = (btn, type) => { - if (btn.execSuccess === 'grid' && type === 'success') { + refreshbyaction = (position) => { + if (position === 'grid') { this.reloadtable() - } else if (btn.execError === 'grid' && type === 'error') { - this.reloadtable() - } else if (btn.execSuccess === 'view' && type === 'success') { + } else if (position === 'view') { 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() } - } - - /** - * @description 琛ㄥ崟鎿嶄綔瀹屾垚鍚庡埛鏂颁富椤甸潰 - */ - refreshbyformtab = (type) => { - this.setState({ - view: 'commontable', - tabBtn: null, - tabParam: null - }, () => { - if (type === 'grid') { - this.reloadtable() - } else if (type === 'view') { - this.reloadview() - } - }) } /** @@ -685,9 +838,11 @@ handleMainTable = (type, tab) => { if (type === 'maingrid' && tab.supMenu === 'mainTable') { this.reloadtable() - } else if (type === 'maingrid' && tab.supMenu) { + } else if (type === 'mainline' && tab.supMenu === 'mainTable') { + this.reloadtable() + } else if ((type === 'maingrid' || type === 'mainline') && tab.supMenu) { this.setState({ - refreshtabs: [tab.supMenu] + refreshtabs: [type, tab.supMenu] }, () => { this.setState({ refreshtabs: null @@ -720,21 +875,24 @@ } /** - * @description 鑾峰彇琛ㄦ牸閫夋嫨椤� + * @description 琛ㄦ牸閫夋嫨椤瑰垏鎹� */ - gettableselected = () => { - let data = [] - this.refs.mainTable.state.selectedRowKeys.forEach(item => { - data.push(this.refs.mainTable.props.data[item]) - }) - return data + changeSelectedData = (selectedData) => { + this.setState({selectedData}) } /** * @description 琛ㄦ牸涓紝鎸夐挳瑙﹀彂浜嬩欢浼犻�� */ buttonTrigger = (btn, record) => { - this.refs.mainButton.actionTrigger(btn, record) + this.setState({ + triggerBtn: { + uuid: new Date().getTime(), + parentId: this.props.MenuID, + button: btn, + data: record + } + }) } /** @@ -760,84 +918,6 @@ this.setState({ pickup: !pickup }) - } - - /** - * @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] || 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: { - 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 isexit = false - let tabs = tabviews.map((tab, i) => { - tab.selected = false - - if (tab.MenuID === MenuID) { - index = i - } else if (tab.MenuID === btn.uuid) { - tab.selected = true - isexit = true - } - - 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 - } - }) - } - } - - popclose = () => { - this.setState({ - visible: false - }) - this.refreshbyaction(this.state.popAction, 'pop') } handleviewconfig = (e) => { @@ -899,48 +979,11 @@ }) } - controlCustomSetting = () => { - this.setState({ - settingVisible: true, - confirmLoading: false - }) - } - - settingSubmit = () => { - this.verifyRef.handleConfirm().then(res => { - let _LongParam = '' - - try { - _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(res))) - } catch (e) { - notification.warning({ - top: 92, - message: '缂栬瘧閿欒', - duration: 10 - }) - return - } - - let param = { - func: 'sPC_TrdMenu_UserParam', - MenuID: this.props.MenuID, - LongParam: _LongParam - } - - this.setState({ - confirmLoading: true - }) - - Api.getSystemConfig(param).then(result => { - this.setState({ - settingVisible: false, - confirmLoading: false - }, () => { - window.GLOB.CacheMap = new Map() - this.reloadview() - }) - }) - }) + /** + * @description 鍥捐〃瑙嗗浘鍒囨崲 + */ + changeChart = (uuid) => { + this.setState({chartId: uuid}) } UNSAFE_componentWillMount () { @@ -956,6 +999,19 @@ 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) } } @@ -964,178 +1020,201 @@ } /** - * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 + * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆 */ componentWillUnmount () { this.setState = () => { return } + document.onkeydown = () => {} } render() { - const { view, setting, searchlist, actions, columns, loadingview, viewlost, pickup, config } = this.state + const { BID, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, config, triggerBtn, userConfig, tabActive, chartId, search, selectedData } = this.state return ( - <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} - searchlist={searchlist} - refreshdata={this.refreshbysearch} - /> : null - } - {actions && setting.onload !== 'false' ? - <div style={{minHeight: '25px'}}> - <MainAction - ref="mainButton" - BID="" - type="main" - menuType="main" - setting={setting} - actions={actions} - 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} - handleTableId={this.handleTableId} - /> - </div> : null - } - {setting && setting.onload !== 'false' && - config.tabgroups.map(group => { - if (config[group].length === 0) return null + <div className="commontable pick-control" id={this.state.ContainerId}> + {loadingview && <Spin size="large" />} + {searchlist && searchlist.length > 0 ? + <MainSearch + BID={BID} + dict={this.state.dict} + searchlist={searchlist} + menuType={this.props.menuType} + dataManager={this.props.dataManager} + refreshdata={this.refreshbysearch} + /> : null + } + {setting && setting.onload !== 'false' ? <div className="chart-view"> + {/* 瑙嗗浘缁� */} + {!config.expand ? <Tabs activeKey={chartId} onChange={this.changeChart}> + {config.charts.map(item => ( + <TabPane tab={<Icon type={item.icon} />} key={item.uuid}></TabPane> + ))} + </Tabs> : null} + {config.charts.map(item => { + if (!config.expand && chartId !== item.uuid) return null + if (item.chartType === 'table') { return ( - <Tabs defaultActiveKey="0" key={group}> - {config[group].map((_tab, index) => { - return ( - <TabPane tab={ - <span> - {_tab.icon ? <Icon type={_tab.icon} /> : null} - {_tab.label} - </span> - } key={`${index}`}> - {_tab.type === 'SubTable' ? - <SubTable - Tab={_tab} - menuType="main" - 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} - </TabPane> - ) - })} - </Tabs> + <Col span={item.width || 24} key={item.uuid}> + {config.charts.length > 1 && item.title ? <p className="chart-table chart-title">{item.title}</p> : null} + <div style={{minHeight: '25px'}}> + <MainAction + BID={BID} + setting={setting} + actions={actions} + dict={this.state.dict} + triggerBtn={triggerBtn} + MenuID={this.props.MenuID} + selectedData={selectedData} + logcolumns={this.state.logcolumns} + ContainerId={this.state.ContainerId} + operations={config.gridBtn.operations || []} + refreshdata={this.refreshbyaction} + getexceloutparam={this.getexceloutparam} + /> + </div> + <div className="main-table-box"> + {this.props.menuType !== 'HS' ? <SettingComponent + config={config} + columns={columns} + dict={this.state.dict} + MenuID={this.props.MenuID} + MenuName={this.props.MenuName} + permAction={this.props.permAction} + permRoles={this.props.permRoles} + userConfig={this.state.userConfig} + reloadview={this.reloadview} + /> : null} + {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && this.state.data && this.state.data.length > 0 ? + <Switch title="鏀惰捣" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null + } + <MainTable + tableId="mainTable" + pickup={pickup} + config={config} + setting={setting} + columns={columns} + pageSize={pageSize} + 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} + resetTable={this.state.resetTable} + chgSelectData={this.changeSelectedData} + /> + </div> + </Col> ) - }) - } - <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> - {this.state.treevisible ? <Tree defaultExpandAll showLine={true}> - {this.getTreeNode(config.funcs)} - </Tree> : null} - </Modal> - {/* 鎸夐挳浣跨敤绯荤粺瀛樺偍杩囩▼鏃讹紝楠岃瘉淇℃伅妯℃�佹 */} - <Modal - wrapClassName="common-table-custom-modal" - title={'鑷畾涔夎缃�'} - maskClosable={false} - width={850} - visible={this.state.settingVisible} - onOk={this.settingSubmit} - onCancel={() => { this.setState({ settingVisible: false }) }} - confirmLoading={this.state.confirmLoading} - destroyOnClose - > - {this.state.config ? - <VerifyCard - config={this.state.config} - wrappedComponentRef={(inst) => this.verifyRef = inst} - /> : null + } else if (item.chartType === 'card') { + return ( + <Col span={item.width} key={item.uuid}> + <CardComponent + BID={BID} + plot={item} + config={config} + tableId="mainTable" + data={this.state.data} + MenuID={this.props.MenuID} + loading={this.state.loading} + logcolumns={this.state.logcolumns} + ContainerId={this.state.ContainerId} + refreshdata={this.refreshbyaction} + handleTableId={this.handleTableId} + /> + </Col> + ) + } else { + return ( + <Col span={item.width} key={item.uuid}> + <ChartComponent + BID={BID} + plot={item} + config={config} + data={this.state.data} + getexceloutparam={this.getexceloutparam} + loading={this.state.loading} + /> + </Col> + ) } - </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> : null } + {setting && setting.onload !== 'false' && + config.tabgroups.map(group => ( + <Tabs activeKey={tabActive[group.uuid]} key={group.uuid} onChange={(key) => this.setState({tabActive: {...tabActive, [group.uuid]: key}})}> + {group.sublist.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} + 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} + {_tab.type === 'SecretKeyTable' ? + <SecretKeyTable + 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'] || ''} + handleMainTable={(type) => this.handleMainTable(type, _tab)} + /> : null} + </TabPane> + ) + })} + </Tabs>) + ) + } + {options.sysType !== 'cloud' ? <Button + icon="copy" + shape="circle" + className="common-table-copy" + onClick={this.handleviewconfig} + /> : null} + <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> + {this.state.treevisible ? <Tree defaultExpandAll showLine={true}> + {this.getTreeNode(config.funcs)} + </Tree> : null} + </Modal> + {viewlost ? <NotFount msg={this.state.lostmsg} /> : null} </div> ) } @@ -1143,17 +1222,19 @@ const mapStateToProps = (state) => { return { + menuType: state.editLevel, tabviews: state.tabviews, refreshTab: state.refreshTab, permAction: state.permAction, - permRoles: state.permRoles + permMenus: state.permMenus, + permRoles: state.permRoles, + dataManager: state.dataManager } } const mapDispatchToProps = (dispatch) => { return { - refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)), - modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)) + refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)) } } -- Gitblit v1.8.0