From 6afdec0062dacbded57e166230eb22cc55ced0c1 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 08 五月 2021 14:30:21 +0800 Subject: [PATCH] 2021-05-08 --- src/tabviews/custom/index.jsx | 1093 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 891 insertions(+), 202 deletions(-) diff --git a/src/tabviews/custom/index.jsx b/src/tabviews/custom/index.jsx index ea43555..40f0818 100644 --- a/src/tabviews/custom/index.jsx +++ b/src/tabviews/custom/index.jsx @@ -1,27 +1,46 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import {connect} from 'react-redux' +import { connect } from 'react-redux' import { is, fromJS } from 'immutable' -import { notification, Spin, Row, Col, Button, message } from 'antd' +import { notification, Spin, Row, Col } from 'antd' import moment from 'moment' +import md5 from 'md5' 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 asyncSpinComponent from '@/utils/asyncSpinComponent' -import { refreshTabView } from '@/store/action' - +import UtilsDM from '@/utils/utils-datamanage.js' +import asyncComponent from '@/utils/asyncComponent' +import MKEmitter from '@/utils/events.js' import NotFount from '@/components/404' import './index.scss' // 閫氱敤缁勪欢 -const AntvBarAndLine = asyncSpinComponent(() => import('./components/chart/antv-bar-line')) +const AntvBarAndLine = asyncComponent(() => import('./components/chart/antv-bar-line')) +const AntvPie = asyncComponent(() => import('./components/chart/antv-pie')) +const AntvTabs = asyncComponent(() => import('./components/tabs/antv-tabs')) +const AntvDashboard = asyncComponent(() => import('./components/chart/antv-dashboard')) +const AntvScatter = asyncComponent(() => import('./components/chart/antv-scatter')) +const DataCard = asyncComponent(() => import('./components/card/data-card')) +const PropCard = asyncComponent(() => import('./components/card/prop-card')) +const NormalForm = asyncComponent(() => import('./components/form/normal-form')) +const CarouselDataCard = asyncComponent(() => import('./components/carousel/data-card')) +const CarouselPropCard = asyncComponent(() => import('./components/carousel/prop-card')) +const TableCard = asyncComponent(() => import('./components/card/table-card')) +const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch')) +const NormalTable = asyncComponent(() => import('./components/table/normal-table')) +const NormalGroup = asyncComponent(() => import('./components/group/normal-group')) +const BraftEditor = asyncComponent(() => import('./components/editor/braft-editor')) +const SandBox = asyncComponent(() => import('./components/code/sand-box')) +const SettingComponent = asyncComponent(() => import('@/tabviews/zshare/settingcomponent')) +const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage')) -class NormalTable extends Component { +class CustomPage extends Component { static propTpyes = { param: PropTypes.any, // 鍏朵粬椤甸潰浼犻�掔殑鍙傛暟 + Tab: PropTypes.string, // 寮圭獥鏍囩 MenuID: PropTypes.string, // 鑿滃崟Id MenuNo: PropTypes.string, // 鑿滃崟鍙傛暟 MenuName: PropTypes.string // 鑿滃崟鍚嶇О @@ -30,26 +49,25 @@ state = { dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, ContainerId: Utils.getuuid(), // 鑿滃崟澶栧眰html Id - BID: null, // 椤甸潰璺宠浆鏃舵惡甯D + BID: '', // 椤甸潰璺宠浆鏃舵惡甯D loadingview: true, // 椤甸潰鍔犺浇涓� viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 lostmsg: '', // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅 config: null, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷粍浠剁瓑 - mainSearch: null, + mainSearch: null, // 涓绘悳绱� userConfig: null, // 鐢ㄦ埛鑷畾涔夎缃� - arr_field: '', // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆� - setting: null, // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑 data: null, // 鍒楄〃鏁版嵁闆� loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� visible: false, // 鏍囩椤垫帶鍒� treevisible: false, // 鑿滃崟缁撴瀯鏍戝脊妗嗘樉绀洪殣钘忔帶鍒� + shortcuts: null // 蹇嵎閿� } /** * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅 */ async loadconfig () { - const { permAction, param } = this.props + const { permAction, permMenus, param } = this.props let _param = { func: 'sPC_Get_LongParam', @@ -59,7 +77,7 @@ if (result.status) { let config = '' - let userConfig = null + let shortcuts = [] try { // 閰嶇疆淇℃伅瑙f瀽 config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) @@ -67,136 +85,134 @@ console.warn('Parse Failure') config = '' } - + // HS涓嶄娇鐢ㄨ嚜瀹氫箟璁剧疆 if (result.LongParamUser && this.props.menuType !== 'HS') { try { // 閰嶇疆淇℃伅瑙f瀽 - userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser))) + let userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser))) + if (userConfig) { + shortcuts = userConfig.action + userConfig.printers.forEach(item => { + window.GLOB.UserCacheMap.set(item.parentId + item.uuid, item) + }) + } } catch (e) { console.warn('Parse Failure') - userConfig = null } } // 椤甸潰閰嶇疆瑙f瀽閿欒鏃舵彁绀� if (!config) { this.setState({ - loadingview: false, - viewlost: true + viewlost: true, + loadingview: false }) return } - + // 椤甸潰鏈惎鐢ㄦ椂锛屾樉绀烘湭鍚敤椤甸潰 if (!config.enabled) { this.setState({ - loadingview: false, viewlost: true, + loadingview: false, lostmsg: this.state.dict['main.view.unenabled'] }) return } + // 鏁版嵁缂撳瓨璁剧疆 + if (config.cacheUseful === 'true') { + if (!['day', 'hour'].includes(config.timeUnit)) { + config.timeUnit = 'day' + } + config.cacheTime = config.cacheTime || 1 + } + + // 鏉冮檺杩囨护 + let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID + config.components = this.filterComponent(config.components, roleId, permAction, permMenus) + // 鑾峰彇涓绘悳绱㈡潯浠� let mainSearch = [] config.components.forEach(component => { - if (component.type === 'search') { - component.search = component.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.toLowerCase() === 'bid') { - item.initval = param.BID - } else if (param.data && param.data[item.field]) { - item.initval = param.data[item.field] - } - } - - 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 - }) + if (component.type !== 'search') return - mainSearch = Utils.initMainSearch(component.search) - } + component.search = component.search.map(item => { + item.oriInitval = item.initval + if (['text', 'select', 'link'].includes(item.type) && param && param.$searchkey === item.field) { + item.initval = param.$searchval + } + + return item + }) + + mainSearch = Utils.initMainSearch(component.search) }) - // 鏉冮檺杩囨护 - if (this.props.menuType !== 'HS') { - config.components.forEach(component => { - if (component.action) { - component.action = component.action.filter(item => permAction[item.uuid]) - } + let params = [] + let BID = param && param.$BID ? param.$BID : '' + let inherit = {} + + if (config.cacheUseful === 'true') { // 缂撳瓨缁ф壙 + inherit.cacheUseful = config.cacheUseful + inherit.timeUnit = config.timeUnit + inherit.cacheTime = config.cacheTime + } + + let userName = sessionStorage.getItem('User_Name') || '' + let fullName = sessionStorage.getItem('Full_Name') || '' + let city = sessionStorage.getItem('city') || '' + + if (sessionStorage.getItem('isEditState') === 'true') { + userName = sessionStorage.getItem('CloudUserName') || '' + fullName = sessionStorage.getItem('CloudFullName') || '' + } + + let regs = [ + { reg: /@userName@/ig, value: userName }, + { reg: /@fullName@/ig, value: fullName }, + { reg: /@login_city@/ig, value: city } + ] + + if (window.GLOB.externalDatabase !== null) { + regs.push({ + reg: /@db@/ig, + value: window.GLOB.externalDatabase + }) + } + if (config.urlFields) { + config.urlFields.forEach(field => { + let val = `'${param ? (param[field] || '') : ''}'` + regs.push({ + reg: new RegExp('@' + field + '@', 'ig'), + value: val + }) }) } - let params = [] - config.components.forEach(component => { - let _customScript = '' - component.scripts && component.scripts.forEach(script => { - if (script.status !== 'false') { - _customScript += ` - ${script.sql} - ` - } - }) - delete component.scripts - - if (component.setting && component.setting.interType === 'system') { // 浣跨敤绯荤粺鍑芥暟 - component.setting.execute = component.setting.execute !== 'false' // 榛樿sql鏄惁鎵ц锛岃浆涓篵oolean 缁熶竴鏍煎紡 - component.setting.laypage = component.setting.laypage === 'true' // 鏄惁鍒嗛〉锛岃浆涓篵oolean 缁熶竴鏍煎紡 - - if (!component.setting.execute) { - component.setting.dataresource = '' - } - if (/\s/.test(component.setting.dataresource)) { - component.setting.dataresource = '(' + component.setting.dataresource + ') tb' - } - - if (this.props.dataManager) { // 鏁版嵁鏉冮檺 - component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*') - component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/') - _customScript = _customScript.replace(/\$@/ig, '/*') - _customScript = _customScript.replace(/@\$/ig, '*/') - } else { - component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '') - _customScript = _customScript.replace(/@\$|\$@/ig, '') - } - } - - if (component.setting) { - component.setting.customScript = _customScript // 鏁寸悊鍚庤嚜瀹氫箟鑴氭湰 - } - - // format 鏁版嵁鏍煎紡 array 鎴� object - // dataName 绯荤粺鐢熸垚鐨勬暟鎹簮鍚嶇О - // pageable 鏄惁鍒嗛〉锛岀粍浠跺睘鎬э紝涓嶅垎椤电殑缁勪欢鎵嶅彲浠ョ粺涓�鏌ヨ - if (component.format && component.dataName && !component.pageable && component.setting.interType === 'system' && component.setting.onload === 'true' && component.setting.sync === 'true') { - let param = this.getDefaultParam(component, mainSearch) - params.push(param) - } else { - component.setting.sync = 'false' - } - }) + config.components = this.formatSetting(config.components, params, mainSearch, inherit, regs) this.setState({ - BID: param && param.BID ? param.BID : '', - loadingview: false, - userConfig: userConfig, - setting: config.setting, + BID: BID, + shortcuts, config, mainSearch }, () => { - this.loadmaindata(params) + if (!params || params.length === 0) { + setTimeout(() => { // 寤舵椂鍔犺浇鐘舵�� + this.setState({ + loadingview: false + }) + }, 1000) + } else { + this.loadmaindata(params) + } + + if (!this.props.Tab) { + this.setShortcut() + } + + this.loadData() }) } else { this.setState({ @@ -211,6 +227,576 @@ } } + setShortcut = () => { + const { shortcuts } = this.state + + if (!shortcuts || shortcuts.length === 0) { + document.onkeydown = () => {} + 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 || !keyCode) return + + let _shortcut = `${preKey}+${keyCode}` + + shortcuts.some(item => { + if (item.$shortcut === _shortcut) { + MKEmitter.emit('triggerBtnId', item.uuid) + return true + } + return false + }) + } + } + + loadData = () => { + const { config } = this.state + + if (!config.interfaces || config.interfaces.length === 0) return + + let inters = [] + + config.interfaces.forEach(item => { + if (item.status !== 'true') return + + if (window.GLOB.systemType === 'production' && !item.proInterface) { + notification.warning({ + top: 92, + message: `銆�${item.name}銆嬫湭璁剧疆姝e紡绯荤粺鍦板潃!`, + duration: 3 + }) + return + } + + inters.push(item) + }) + + if (inters.length > 0) { + this.loadOutResource(inters) + } + } + + loadOutResource = (inters) => { + let setting = inters.shift() + let param = UtilsDM.getPrevQueryParams(setting, [], this.state.BID, this.props.menuType) + + Api.genericInterface(param).then(res => { + if (res.status) { + if (res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) { + if (inters.length > 0) { + this.loadOutResource(inters) + } + } else { + this.customOuterRequest(res, setting, inters) + } + } else { + notification.error({ + top: 92, + message: res.message, + duration: 10 + }) + } + }) + } + + customOuterRequest = (result, setting, inters) => { + let url = '' + + if (window.GLOB.systemType === 'production') { + url = setting.proInterface + } else { + url = setting.interface + } + + let mkey = result.mk_api_key || '' + + delete result.mk_ex_invoke + delete result.status + delete result.message + delete result.ErrCode + delete result.ErrMesg + delete result.mk_api_key + + let param = {} + + Object.keys(result).forEach(key => { + key = key.replace(/^mk_/ig, '') + param[key] = result[key] + }) + + Api.directRequest(url, setting.method, param, setting.cross).then(res => { + if (typeof(res) !== 'object' || Array.isArray(res)) { + let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒' + + if (typeof(res) === 'string') { + error = res.replace(/'/ig, '"') + } + + let _result = { + mk_api_key: mkey, + $ErrCode: 'E', + $ErrMesg: error + } + + this.customCallbackRequest(_result, setting, inters) + } else { + res.mk_api_key = mkey + this.customCallbackRequest(res, setting, inters) + } + }, (e) => { + let _result = { + mk_api_key: mkey, + $ErrCode: 'E', + $ErrMesg: e && e.statusText ? e.statusText : '' + } + + this.customCallbackRequest(_result, setting, inters) + }) + } + + customCallbackRequest = (result, setting, inters) => { + let errSql = '' + if (result.$ErrCode === 'E') { + errSql = ` + set @ErrorCode='E' + set @retmsg='${result.$ErrMesg}' + ` + delete result.$ErrCode + delete result.$ErrMesg + } + + let lines = UtilsDM.getCallBackSql(setting, result) + let param = {} + + if (setting.callbackType === 'script') { // 浣跨敤鑷畾涔夎剼鏈� + let sql = lines.map(item => (` + ${item.insert} + ${item.selects.join(` union all + `)} + `)) + sql = sql.join('') + + param = UtilsDM.getCallBackQueryParams(setting, sql, errSql) + + if (this.state.BID) { + param.BID = this.state.BID + } + + if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉 + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) + } + } else { + param.func = 's_ex_result_back' + param.s_ex_result = lines.map((item, index) => ({ + MenuID: this.props.MenuID || '', + MenuName: this.props.MenuName || '', + TableName: item.table, + LongText: window.btoa(window.encodeURIComponent(`${item.insert} ${item.selects.join(` union all `)}`)), + Sort: index + 1 + })) + + if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) { + let sql = lines.map(item => (` + ${item.insert} + ${item.selects.join(` union all + `)} + `)) + sql = sql.join('') + console.info(sql.replace(/\n\s{10}/ig, '\n')) + } + } + + Api.genericInterface(param).then(res => { + if (res.status) { + if (inters.length > 0) { + this.loadOutResource(inters) + } + } else { + notification.error({ + top: 92, + message: res.message, + duration: 10 + }) + } + }) + } + + filterComponent = (components, roleId, permAction, permMenus) => { + return components.filter(item => { + if (item.type === 'tabs') { + if ( + item.setting.blacklist && item.setting.blacklist.length > 0 && + item.setting.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0 + ) { + return false + } + + item.subtabs = item.subtabs.filter(tab => { + if ( + tab.blacklist && tab.blacklist.length > 0 && + tab.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0 + ) { + return false + } + return true + }) + + item.subtabs = item.subtabs.map(tab => { + tab.components = this.filterComponent(tab.components, roleId, permAction, permMenus) + return tab + }) + + let supIds = [] + item.subtabs.forEach(tab => { + tab.components.forEach(comp => { + if (comp.type === 'tabs' && comp.parentIds) { + supIds.push(...comp.parentIds) + } else if (comp.setting && comp.setting.supModule) { + supIds.push(comp.setting.supModule) + } + }) + }) + item.parentIds = supIds + } else if (item.type === 'group') { + if ( + item.setting.blacklist && item.setting.blacklist.length > 0 && + item.setting.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0 + ) { + return false + } + + item.components = this.filterComponent(item.components, roleId, permAction, permMenus) + } else if (['pie', 'bar', 'line', 'dashboard', 'scatter'].includes(item.type)) { + if ( + item.plot.blacklist && item.plot.blacklist.length > 0 && + item.plot.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0 + ) { + return false + } + } else if (item.wrap) { + if ( + item.wrap.blacklist && item.wrap.blacklist.length > 0 && + item.wrap.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0 + ) { + return false + } + } + // 鎼滅储榛戝悕鍗曡繃婊� + if (item.search && item.search.length > 0) { + item.search = item.search.map(cell => { + cell.oriInitval = cell.initval + + if (!cell.blacklist || cell.blacklist.length === 0) return cell + if (cell.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) { + cell.Hide = 'true' + } + + return item + }) + } + if (item.type === 'table' && item.subtype === 'normaltable') { + let statFields = [] + let getCols = (cols) => { + return cols.filter(col => { + if (col.blacklist && col.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) { + return false + } else if (col.Hide === 'true') { + return false + } + if (col.type === 'number' && col.sum === 'true' && !statFields.includes(col.field)) { + statFields.push(col) + } else if (col.type === 'colspan') { + col.subcols = getCols(col.subcols || []) + if (col.subcols.length === 0) { + return false + } + } else if (col.type === 'custom') { + col.elements = col.elements.map(cell => { + if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height) { + cell.innerHeight = 'auto' + } + return cell + }) + } + + if (col.linkmenu && col.linkmenu.length > 0) { + let menu_id = col.linkmenu.pop() + col.linkThdMenu = permMenus.filter(m => m.MenuID === menu_id)[0] || '' + } else { + col.linkThdMenu = '' + } + + return true + }) + } + + item.cols = getCols(item.cols) + item.statFields = statFields + } + + // 鏉冮檺杩囨护 + let isHS = this.props.menuType === 'HS' + let tabId = this.props.Tab ? this.props.Tab.uuid : '' // 寮圭獥鏍囩鎸夐挳Id + if (item.action && item.action.length > 0) { + item.action = item.action.filter(cell => { + cell.logLabel = item.name + '-' + cell.label + cell.ContainerId = this.state.ContainerId + cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : '' + cell.$menuId = item.uuid + cell.$tabId = tabId + cell.$view = 'CustomPage' + + if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃� + cell = this.getPrinter(cell, item.uuid) + } + + if (cell.btnstyle) { // 鍏煎 + cell.style = cell.style || {} + cell.style = {...cell.style, ...cell.btnstyle} + } + + return isHS || permAction[cell.uuid] + }) + } + + if (item.type === 'card') { + item.subcards.forEach(card => { + let _hasheight = card.style.height && card.style.height !== 'auto' + + if (card.style.shadow) { // 鍗$墖闃村奖 + card.style.boxShadow = '0 0 4px ' + card.style.shadow + delete card.style.shadow + } + + card.elements = card.elements.filter(cell => { + if (cell.eleType === 'button') { + cell.logLabel = item.name + '-' + cell.label + cell.Ot = 'requiredSgl' + cell.ContainerId = this.state.ContainerId + cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : '' + cell.$menuId = item.uuid + cell.$tabId = tabId + cell.$view = 'CustomPage' + + if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃� + cell = this.getPrinter(cell, item.uuid) + } + if (card.btnstyle) { // 鍏煎 + card.style = card.style || {} + card.style = {...card.style, ...card.btnstyle} + } + } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) { + cell.innerHeight = 'auto' + } + + return cell.eleType !== 'button' || isHS || permAction[cell.uuid] + }) + card.backElements = card.backElements.filter(cell => { + if (cell.eleType === 'button') { + cell.logLabel = item.name + '-' + cell.label + cell.Ot = 'requiredSgl' + cell.ContainerId = this.state.ContainerId + cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : '' + cell.$menuId = item.uuid + cell.$tabId = tabId + cell.$view = 'CustomPage' + + if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃� + cell = this.getPrinter(cell, item.uuid) + } + if (card.btnstyle) { // 鍏煎 + card.style = card.style || {} + card.style = {...card.style, ...card.btnstyle} + } + } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) { + cell.innerHeight = 'auto' + } + return cell.eleType !== 'button' || isHS || permAction[cell.uuid] + }) + }) + } else if ((item.type === 'table' && item.subtype === 'tablecard') || item.type === 'carousel') { + item.subcards.forEach(card => { + let _hasheight = card.style.height && card.style.height !== 'auto' + card.elements = card.elements.filter(cell => { + if (cell.eleType === 'button') { + cell.logLabel = item.name + '-' + cell.label + cell.Ot = 'requiredSgl' + cell.ContainerId = this.state.ContainerId + cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : '' + cell.$menuId = item.uuid + cell.$tabId = tabId + cell.$view = 'CustomPage' + + if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃� + cell = this.getPrinter(cell, item.uuid) + } + + if (card.btnstyle) { // 鍏煎 + card.style = card.style || {} + card.style = {...card.style, ...card.btnstyle} + } + } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) { + cell.innerHeight = 'auto' + } + return cell.eleType !== 'button' || isHS || permAction[cell.uuid] + }) + }) + } else if (item.type === 'table' && item.subtype === 'normaltable') { + item.cols = item.cols.filter(col => { + if (col.type !== 'action') return true + col.elements = col.elements.filter(cell => { + cell.logLabel = item.name + '-' + cell.label + cell.Ot = 'requiredSgl' + cell.ContainerId = this.state.ContainerId + cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : '' + cell.$menuId = item.uuid + cell.$tabId = tabId + cell.$view = 'CustomPage' + + if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃� + cell = this.getPrinter(cell, item.uuid) + } + + if (cell.btnstyle) { // 鍏煎 + cell.style = cell.style || {} + cell.style = {...cell.style, ...cell.btnstyle} + } + + return isHS || permAction[cell.uuid] + }) + return col.elements.length !== 0 + }) + } + + if (item.setting && item.setting.supModule) { + let pid = item.setting.supModule.pop() + if (pid && pid !== 'empty') { + item.setting.supModule = pid + } else { + item.setting.supModule = '' + } + } + if (item.wrap && item.wrap.doubleClick) { + let index = item.action.findIndex((btn) => btn.uuid === item.wrap.doubleClick) + if (index === -1) { + item.wrap.doubleClick = '' + } + } + + return true + }) + } + + getPrinter = (item, parentId) => { + let _item = window.GLOB.UserCacheMap.get(parentId + item.uuid) + + if (_item) { + item.printer = _item.printer || '' + item.verify.defaultPrinter = _item.printer || '' + if (item.verify.printerTypeList && _item.printerList) { + item.verify.printerTypeList = item.verify.printerTypeList.map(cell => { + cell.printer = _item.printerList[cell.Value] || '' + + return cell + }) + } + } + + return item + } + + // 鏍煎紡鍖栭粯璁よ缃� + formatSetting = (components, params, mainSearch, inherit, regs) => { + return components.map(component => { + if (component.type === 'tabs') { + component.subtabs = component.subtabs.map(tab => { + tab.components = this.formatSetting(tab.components, [], [], inherit, regs) + tab = {...tab, ...inherit} + return tab + }) + return component + } else if (component.type === 'group') { + component.components = this.formatSetting(component.components, [], [], inherit, regs) + component = {...component, ...inherit} + return component + } + + if (['propcard', 'brafteditor', 'sandbox', 'stepform'].includes(component.subtype) && component.wrap.datatype === 'static') { + component.format = '' + } + + if (!component.setting) return component // 涓嶄娇鐢ㄧ郴缁熷嚱鏁版椂 + if (!component.format) return component // 娌℃湁鍔ㄦ�佹暟鎹� 鏁版嵁鏍煎紡 array 鎴� object + if (component.setting.interType !== 'system') { // 涓嶄娇鐢ㄧ郴缁熷嚱鏁版椂 + component.setting.sync = 'false' + component.setting.laypage = component.setting.laypage === 'true' + return component + } + + let _customScript = '' + component.scripts && component.scripts.forEach(script => { + if (script.status !== 'false') { + _customScript += ` + ${script.sql} + ` + } + }) + delete component.scripts + component.setting.$name = component.name || '' + component.setting.execute = component.setting.execute !== 'false' // 榛樿sql鏄惁鎵ц锛岃浆涓篵oolean 缁熶竴鏍煎紡 + component.setting.laypage = component.setting.laypage === 'true' // 鏄惁鍒嗛〉锛岃浆涓篵oolean 缁熶竴鏍煎紡 + + if (!component.setting.execute) { + component.setting.dataresource = '' + } + if (/\s/.test(component.setting.dataresource)) { + component.setting.dataresource = '(' + component.setting.dataresource + ') tb' + } + + if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 + component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*') + component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/') + _customScript = _customScript.replace(/\$@/ig, '/*') + _customScript = _customScript.replace(/@\$/ig, '*/') + } else { + component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '') + _customScript = _customScript.replace(/@\$|\$@/ig, '') + } + + regs.forEach(cell => { + component.setting.dataresource = component.setting.dataresource.replace(cell.reg, cell.value) + _customScript = _customScript.replace(cell.reg, cell.value) + }) + + component.setting.customScript = _customScript // 鏁寸悊鍚庤嚜瀹氫箟鑴氭湰 + + // floor 缁勪欢鐨勫眰绾� + // dataName 绯荤粺鐢熸垚鐨勬暟鎹簮鍚嶇О + // pageable 鏄惁鍒嗛〉锛岀粍浠跺睘鎬э紝涓嶅垎椤电殑缁勪欢鎵嶅彲浠ョ粺涓�鏌ヨ + if (component.floor === 1 && component.dataName && (!component.pageable || (component.pageable && !component.setting.laypage)) && component.setting.onload === 'true' && component.setting.sync === 'true') { + let param = this.getDefaultParam(component, mainSearch) + params.push(param) + } else if (component.floor === 1) { + component.setting.sync = 'false' + } + + return component + }) + } + /** * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁� */ @@ -221,14 +807,21 @@ if (search && search.length > 0) { searchlist = Utils.initMainSearch(search) } + if (setting.useMSearch === 'true') { - searchlist = [...mainSearch, ...searchlist] + let keys = searchlist.map(item => item.key) + mainSearch.forEach(item => { + if (!keys.includes(item.key)) { + searchlist.push(item) + } + }) } let arr_field = columns.map(col => col.field) let _dataresource = setting.dataresource let _customScript = setting.customScript + if (setting.queryType === 'statistics' || _customScript) { let allSearch = Utils.getAllSearchOptions(searchlist) let regoptions = allSearch.map(item => { @@ -242,9 +835,7 @@ if (_dataresource && setting.queryType === 'statistics') { _dataresource = _dataresource.replace(item.reg, item.value) } - if (_customScript) { - _customScript = _customScript.replace(item.reg, item.value) - } + _customScript = _customScript.replace(item.reg, item.value) }) } @@ -262,8 +853,8 @@ // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞 if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) { - _customScript && console.log(`${_dataresource ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`) - _dataresource && console.log(_dataresource) + _customScript && console.info(`${setting.$name ? `/*缁勪欢-${setting.$name} 鑷畾涔夎剼鏈�*/\n` : ''}${_dataresource ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`) + _dataresource && console.info(`${setting.$name ? `/*缁勪欢-${setting.$name} 鏁版嵁婧�*/\n` : ''}` + _dataresource) } return { @@ -282,45 +873,65 @@ * @description 涓昏〃鏁版嵁鍔犺浇 */ loadmaindata = (params) => { + const { config } = this.state let LText_field = [] - let LText = params.map((item, index) => { - let _sql = item.sql + let diffUser = false + let userName = sessionStorage.getItem('User_Name') || '' + let fullName = sessionStorage.getItem('Full_Name') || '' + let city = sessionStorage.getItem('city') || '' + + if (sessionStorage.getItem('isEditState') === 'true') { + userName = sessionStorage.getItem('CloudUserName') || '' + fullName = sessionStorage.getItem('CloudFullName') || '' + } + + let _LText = params.map((item, index) => { let _script = item.script - // if (index === 0) { - // _script = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode='',@retmsg ='' - // ${_script} - // ` - // } - - // if (params.length === index + 1) { - // _sql = `${_sql} - // aaa: - // if @ErrorCode!='' - // begin - // insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ - // goto bbb - // end - // ` - // } + if (index === 0) { + _script = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@login_city nvarchar(50) + select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @login_city='${city}' + ${_script} + ` + } + if (!diffUser && (/@userid@/ig.test(item.sql) || /@userid@/ig.test(_script))) { + diffUser = true + } item.columns.forEach(cell => { LText_field.push(`Select '${item.name}' as tablename,'${cell.field}' as fieldname,'${cell.datatype}' as field_type`) }) - return `Select '${item.name}' as tablename,'${window.btoa(window.encodeURIComponent(_sql))}' as LText,'${window.btoa(window.encodeURIComponent(_script))}' as Lcustomize,'${item.type}' as table_type,'${item.primaryKey}' as primary_key,'${item.par_tablename}' as par_tablename,'${item.foreign_key}' as foreign_key,'${index}' as Sort` - // return `Select '${item.name}' as tablename,'${_sql}' as LText,'${_script}' as Lcustomize,'${item.type}' as table_type,'${item.primaryKey}' as primary_key,'${item.par_tablename}' as par_tablename,'${item.foreign_key}' as foreign_key,'${index}' as Sort` + return `Select '${item.name}' as tablename,'${window.btoa(window.encodeURIComponent(item.sql))}' as LText,'${window.btoa(window.encodeURIComponent(_script))}' as Lcustomize,'${item.type}' as table_type,'${item.primaryKey}' as primary_key,'${item.par_tablename}' as par_tablename,'${item.foreign_key}' as foreign_key,'${index}' as Sort` }) + // 鎶婂ぇ鎺ュ彛sPC_Get_structured_data鐨刲text鎷嗘垚涓変唤锛岀涓�娈碉細@LText1锛岀浜屾@LText锛岀涓夋@LText2 let param = { func: 'sPC_Get_structured_data', - LText: LText.join(' union all '), - LText_field: LText_field.join(' union all ') + LText: _LText.join(' union all '), + LText_field: LText_field.join(' union all '), + BID: this.state.BID || '' } - - param.LText = Utils.formatOptions(param.LText) + + let { LText, LText1, LText2 } = Utils.sPCInUpDeFormatOptions(param.LText) + + param.LText1 = LText1 + param.LText = LText + param.LText2 = LText2 param.LText_field = Utils.formatOptions(param.LText_field) + + if (config.cacheUseful === 'true') { + param.time_type = config.timeUnit + param.time_limit = config.cacheTime + if (diffUser) { + param.userid = sessionStorage.getItem('UserID') + } + param.data_md5 = md5(JSON.stringify(param)) + } + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) + + this.setState({loading: true, loadingview: false}) Api.getLocalConfig(param).then(result => { if (result.status) { @@ -347,46 +958,20 @@ }) } - /** - * @description 鎼滅储鏉′欢鏀瑰彉鏃讹紝閲嶇疆琛ㄦ牸鏁版嵁 - * 鍚湁鍒濆涓嶅姞杞界殑椤甸潰锛屼慨鏀硅缃� - */ - refreshbysearch = (searches) => { - this.setState({ - mainSearch: searches - }) + reloadMenuView = (menuId) => { + const { MenuID } = this.props + + if (MenuID !== menuId) return + + this.reloadview() } + resetActiveMenu = (menuId) => { + const { MenuID, Tab } = this.props - /** - * @description 椤甸潰鍒锋柊锛岄噸鏂拌幏鍙栭厤缃� - */ - reloadview = () => { - this.setState({ loadingview: true, viewlost: false, lostmsg: '', data: null, loading: false, search: '' - }, () => { - this.loadconfig() - }) - } + if (MenuID !== menuId || Tab) return - 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']) - } + this.setShortcut() } UNSAFE_componentWillMount () { @@ -394,17 +979,13 @@ this.loadconfig() } - UNSAFE_componentWillReceiveProps(nextProps) { - if (nextProps.refreshTab && nextProps.refreshTab.MenuID === this.props.MenuID) { - if (nextProps.refreshTab.position === 'view') { - this.reloadview() - } - this.props.refreshTabView('') - } - } - shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) + } + + componentDidMount () { + MKEmitter.addListener('reloadMenuView', this.reloadMenuView) + MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu) } /** @@ -414,19 +995,135 @@ this.setState = () => { return } + MKEmitter.removeListener('reloadMenuView', this.reloadMenuView) + MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu) + } + + reloadview = () => { + this.setState({ + BID: '', // 椤甸潰璺宠浆鏃舵惡甯D + loadingview: true, // 椤甸潰鍔犺浇涓� + viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 + config: null, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷粍浠剁瓑 + loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� + shortcuts: null + }, () => { + this.loadconfig() + }) + } + + resetSearch = (search) => { + this.setState({mainSearch: null}, () => { + this.setState({mainSearch: search}) + }) } getComponents = () => { - const { menuType, dataManager } = this.props + const { menuType } = this.props const { config, BID, data, mainSearch } = this.state if (!config || !config.components) return return config.components.map(item => { + let _bid = BID + if (item.setting && item.setting.supModule) { + _bid = '' + } + if (item.type === 'bar' || item.type === 'line') { return ( - <Col key={item.uuid}> - <AntvBarAndLine config={item} data={data} BID={BID} mainSearch={mainSearch} menuType={menuType} dataManager={dataManager} /> + <Col span={item.width} key={item.uuid}> + <AntvBarAndLine config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'pie') { + return ( + <Col span={item.width} key={item.uuid}> + <AntvPie config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'scatter') { + return ( + <Col span={item.width} key={item.uuid}> + <AntvScatter config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'dashboard') { + return ( + <Col span={item.width} key={item.uuid}> + <AntvDashboard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'form') { + return ( + <Col span={item.width} key={item.uuid}> + <NormalForm config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'search') { + return ( + <Col span={item.width} key={item.uuid}> + <MainSearch config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} refreshdata={this.resetSearch} /> + </Col> + ) + } else if (item.type === 'tabs') { + return ( + <Col span={item.width} key={item.uuid}> + <AntvTabs config={item} mainSearch={mainSearch} /> + </Col> + ) + } else if (item.type === 'card' && item.subtype === 'datacard') { + return ( + <Col span={item.width} key={item.uuid}> + <DataCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'card' && item.subtype === 'propcard') { + return ( + <Col span={item.width} key={item.uuid}> + <PropCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'carousel' && item.subtype === 'datacard') { + return ( + <Col span={item.width} key={item.uuid}> + <CarouselDataCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'carousel' && item.subtype === 'propcard') { + return ( + <Col span={item.width} key={item.uuid}> + <CarouselPropCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'table' && item.subtype === 'tablecard') { + return ( + <Col span={item.width} key={item.uuid}> + <TableCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'table' && item.subtype === 'normaltable') { + return ( + <Col span={item.width} key={item.uuid}> + <NormalTable config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'group' && item.subtype === 'normalgroup') { + return ( + <Col span={item.width} key={item.uuid}> + <NormalGroup config={item} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'editor') { + return ( + <Col span={item.width} key={item.uuid}> + <BraftEditor config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> + </Col> + ) + } else if (item.type === 'code') { + return ( + <Col span={item.width} key={item.uuid}> + <SandBox config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} /> </Col> ) } else { @@ -435,20 +1132,16 @@ }) } - render() { - const { loadingview, viewlost } = this.state + const { menuType } = this.props + const { loadingview, viewlost, config, loading, shortcuts } = this.state return ( - <div className="calendar-page" id={this.state.ContainerId}> - {loadingview && <Spin size="large" />} + <div className={'custom-page-wrap ' + (loadingview || loading ? 'loading' : '')} id={this.state.ContainerId} style={config ? config.style : null}> + {(loadingview || loading) ? <Spin className="view-spin" size="large" /> : null} <Row>{this.getComponents()}</Row> - {options.sysType !== 'cloud' ? <Button - icon="copy" - shape="circle" - className="common-table-copy" - onClick={this.handleviewconfig} - /> : null} + {menuType !== 'HS' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null} + {menuType !== 'HS' && shortcuts ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts} permAction={this.props.permAction}/> : null} {viewlost ? <NotFount msg={this.state.lostmsg} /> : null} </div> ) @@ -458,18 +1151,14 @@ const mapStateToProps = (state) => { return { menuType: state.editLevel, - tabviews: state.tabviews, refreshTab: state.refreshTab, permAction: state.permAction, - permRoles: state.permRoles, - dataManager: state.dataManager + permMenus: state.permMenus } } -const mapDispatchToProps = (dispatch) => { - return { - refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)) - } +const mapDispatchToProps = () => { + return {} } -export default connect(mapStateToProps, mapDispatchToProps)(NormalTable) \ No newline at end of file +export default connect(mapStateToProps, mapDispatchToProps)(CustomPage) \ No newline at end of file -- Gitblit v1.8.0