From 047dbd742341e268ca772eda8d2ff0b6ba09cb44 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 05 六月 2025 16:57:36 +0800 Subject: [PATCH] 2025-06-05 --- src/tabviews/subtabtable/index.jsx | 395 ++++++++++++++++++-------------------------------------- 1 files changed, 126 insertions(+), 269 deletions(-) diff --git a/src/tabviews/subtabtable/index.jsx b/src/tabviews/subtabtable/index.jsx index 63ebd78..888ef15 100644 --- a/src/tabviews/subtabtable/index.jsx +++ b/src/tabviews/subtabtable/index.jsx @@ -1,14 +1,10 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { notification, Spin} from 'antd' +import { notification, Spin, Modal } from 'antd' import Api from '@/api' -import zhCN from '@/locales/zh-CN/main.js' -import enUS from '@/locales/en-US/main.js' import Utils from '@/utils/utils.js' -import options from '@/store/options.js' import UtilsDM from '@/utils/utils-datamanage.js' import { updateSubTabTable } from '@/utils/utils-update.js' import asyncComponent from '@/utils/asyncComponent' @@ -32,15 +28,12 @@ } state = { - dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, loadingview: true, // 椤甸潰鍔犺浇涓� viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 lostmsg: '', // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅 config: null, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑 - searchlist: null, // 鎼滅储鏉′欢 actions: null, // 鎸夐挳闆� columns: null, // 鏄剧ず鍒� - arr_field: '', // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆� setting: null, // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑 data: [], // 鍒楄〃鏁版嵁闆� selectedData: [], // 宸查�夎〃鏍兼暟鎹� @@ -53,15 +46,13 @@ statFields: [], // 鍚堣瀛楁 statFValue: [], // 鍚堣鍊� absFields: [], // 缁濆鍊煎瓧娈� - loadCustomApi: true, // 鍔犺浇澶栭儴璧勬簮 - hasReqFields: false } /** * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅 */ async loadconfig () { - const { permAction, Tab } = this.props + const { Tab } = this.props let param = { func: 'sPC_Get_LongParam', @@ -94,7 +85,7 @@ this.setState({ loadingview: false, viewlost: true, - lostmsg: this.state.dict['main.view.unenabled'] + lostmsg: '鎶辨瓑锛屾偍璁块棶鐨勯〉闈㈡湭鍚敤锛岃鑱旂郴绠$悊鍛樸��' }) return } @@ -128,18 +119,9 @@ } // 鏉冮檺杩囨护 - if (this.props.menuType !== 'HS') { - config.action = config.action.filter(item => permAction[item.uuid]) - } + config.action = config.action.filter(item => item.hidden !== 'true') - config.search = Utils.initSearchVal(config.search) - - let hasReqFields = false - config.search.forEach(field => { - if (field.required) { - hasReqFields = true - } - }) + Utils.initSearchVal(config) // 瀛楁鏉冮檺榛戝悕鍗� let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID @@ -157,6 +139,15 @@ config.columns.forEach(col => { if (col.field) { _arrField.push(col.field) + + if (col.type === 'number') { + col.decimal = col.decimal || 0 + col.round = Math.pow(10, col.decimal) + + if (col.format === 'percent') { + col.decimal = col.decimal > 2 ? col.decimal - 2 : 0 + } + } col.nameField && _arrField.push(col.nameField) // 閾炬帴鍚嶅瓧娈� if (col.Hide !== 'true' && col.type === 'number' && col.sum === 'true') { @@ -201,14 +192,56 @@ let _actions = [] // 宸ュ叿鏍忔寜閽� let _operations = [] // 鎿嶄綔鍒楁寜閽紙瀛樺湪鏃讹級 + let colors = { primary: '#1890ff', yellow: '#c49f47', orange: 'orange', danger: '#ff4d4f', green: '#26C281', dgreen: '#32c5d2', purple: '#8E44AD', cyan: '#13c2c2', gray: '#E7E7EF', default: 'rgba(0, 0, 0, 0.65)' } config.action.forEach(item => { item.logLabel = Tab.label + '-' + item.label // 鐢ㄤ簬sPC_TableData_InUpDe璁板綍鎿嶄綔鎸夐挳 item.$menuId = this.props.MenuID + item.$old = true + + if (item.OpenType === 'popview') return + + if (item.OpenType === 'excelOut') { // 瀵煎嚭 + item.$menuName = Tab.label + } + + if (item.verify && item.verify.invalid === 'true') { + if (item.sqlType === 'insert') { + item.verify.invalid = 'false' + } else if (item.Ot === 'notRequired') { + item.verify.invalid = 'false' + } else if (item.intertype !== 'system' && item.procMode !== 'system') { + item.verify.invalid = 'false' + } + } + + if (item.controlField) { + if (/,/ig.test(item.controlVal)) { + item.controlVals = item.controlVal.split(',') + } else { + item.controlVals = [(item.controlVal || '')] + } + } + + item.show = 'button' + + let _c = item.class ? item.class.replace('border-', '') : '' + let color = colors[_c] || '#1890ff' if (item.position === 'toolbar') { + item.$toolbtn = true + + if (item.class === 'default') { + item.style = {color: 'rgba(0, 0, 0, 0.65)', backgroundColor: '#fff', borderColor: '#d9d9d9', marginRight: '15px'} + } else if (item.class.indexOf('border') > -1) { + item.style = {color: color, backgroundColor: '#fff', borderColor: color, marginRight: '15px'} + } else { + item.style = {color: item.class === 'gray' ? 'rgba(0, 0, 0, 0.65)' : '#fff', backgroundColor: color, borderColor: color, marginRight: '15px'} + } + _actions.push(item) } else if (item.position === 'grid') { + item.style = {color: color, backgroundColor: 'transparent', borderColor: 'transparent'} _operations.push(item) } }) @@ -224,7 +257,7 @@ config.setting.execute = config.setting.default !== 'false' // 榛樿sql鏄惁鎵ц锛岃浆涓篵oolean 缁熶竴鏍煎紡 config.setting.customScript = '' // 鑷畾涔夎剼鏈� - if (config.setting.interType === 'system' || (config.setting.interType === 'custom' && config.setting.requestMode === 'system')) { + if (config.setting.interType === 'system') { if (config.setting.scripts && config.setting.scripts.length > 0) { let _customScript = '' config.setting.scripts.forEach(item => { @@ -246,10 +279,8 @@ } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*') - config.setting.dataresource = config.setting.dataresource.replace(/@\$/ig, '*/') - config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*') - config.setting.customScript = config.setting.customScript.replace(/@\$/ig, '*/') + config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/') + config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/') } else { config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '') config.setting.customScript = config.setting.customScript.replace(/@\$|\$@/ig, '') @@ -257,29 +288,26 @@ 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}'` } + { reg: /@fullName@/ig, value: `'${fullName}'` } ] regs.forEach(cell => { config.setting.dataresource = config.setting.dataresource.replace(cell.reg, cell.value) config.setting.customScript = config.setting.customScript.replace(cell.reg, cell.value) }) + } else { + config.setting.dataresource = '' } if (config.setting.selected !== 'init' && config.setting.selected !== 'always') { config.setting.selected = 'false' } else if (config.setting.selected === 'init' && config.setting.onload === 'false') { config.setting.selected = 'false' + } else { + config.setting.orisel = true } if (config.setting.controlField) { @@ -290,6 +318,21 @@ } } + config.type = 'table' + config.wrap = { + show: config.setting.show || '', + float: config.setting.float || '', + advanceType: config.setting.advanceType || '', + advanceWidth: config.setting.advanceWidth || '', + drawerPlacement: config.setting.drawerPlacement || '', + searchRatio: config.setting.searchRatio || '', + searchLwidth: config.setting.searchLwidth, + borderRadius: config.setting.borderRadius, + resetContrl: config.setting.resetContrl, + } + + config.setting.arr_field = _arrField.join(',') + this.setState({ pageSize: config.setting.pageSize || 10, loadingview: false, @@ -297,12 +340,9 @@ absFields, statFields, setting: config.setting, - searchlist: config.search, actions: _actions, columns: _columns, - arr_field: _arrField.join(','), search: Utils.initMainSearch(config.search), // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 - hasReqFields }, () => { if (config.setting.onload !== 'false') { // 鍒濆鍖栧彲鍔犺浇 this.loadData() @@ -321,12 +361,12 @@ } } - loadData = () => { - const { setting, search, hasReqFields, loadCustomApi } = this.state + loadData = (id) => { + const { setting, search, config } = this.state let searches = fromJS(search).toJS() - if (hasReqFields) { + if (config.$s_req) { let requireFields = searches.filter(item => item.required && item.value === '') if (requireFields.length > 0) { this.setState({ @@ -336,10 +376,10 @@ } } - if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) { + if (setting.interType === 'custom') { notification.warning({ top: 92, - message: '鏈缃寮忕郴缁熷湴鍧�!', + message: '绯荤粺涓嶅湪鏀寔鑷畾涔夋帴鍙�!', duration: 3 }) return @@ -349,194 +389,15 @@ selectedData: [] }) - if (setting.interType === 'custom' && loadCustomApi) { - if (setting.execTime === 'once') { - this.setState({loadCustomApi: false}) - } - - this.loadOutResource(searches) - if (setting.execType === 'async') { - this.loadmaindata() - } - } else { - this.loadmaindata() - } - } - - loadOutResource = (searches) => { - const { setting } = this.state - - let param = UtilsDM.getPrevQueryParams(setting, searches, this.props.BID, this.props.menuType) - - if (setting.execType === 'sync') { - this.setState({ - loading: true - }) - } - - Api.genericInterface(param).then(res => { - if (res.status) { - if (res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) { - this.loadmaindata() - } else { - this.customOuterRequest(res) - } - } else { - this.setState({ - loading: false - }) - notification.error({ - top: 92, - message: res.message, - duration: 10 - }) - } - }, () => { - this.setState({ - loading: false - }) - }) - } - - customOuterRequest = (result) => { - const { setting } = this.state - 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') { - let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒' - - if (typeof(res) === 'string') { - error = res.replace(/'/ig, '"') - } - - let _result = { - mk_api_key: mkey, - $ErrCode: 'E', - $ErrMesg: error - } - - this.customCallbackRequest(_result) - } else { - if (Array.isArray(res)) { - res = { data: res } - } - res.mk_api_key = mkey - this.customCallbackRequest(res) - } - }, (e) => { - let _result = { - mk_api_key: mkey, - $ErrCode: 'E', - $ErrMesg: e && e.statusText ? e.statusText : '' - } - - this.customCallbackRequest(_result) - }) - } - - customCallbackRequest = (result) => { - const { setting } = this.state - 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.props.BID) { - param.BID = this.props.BID - } - - if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉 - param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) - } - } else { - let name = this.props.Tab ? (this.props.Tab.label || '') : '' - param.func = 's_ex_result_back' - param.s_ex_result = lines.map((item, index) => ({ - MenuID: this.props.MenuID, - MenuName: name, - 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) { - this.loadmaindata() - } else { - this.setState({ - loading: false - }) - notification.error({ - top: 92, - message: res.message, - duration: 10 - }) - } - }, () => { - this.setState({ - loading: false - }) - }) + this.loadmaindata(id) } /** * @description 瀛愯〃鏁版嵁鍔犺浇 */ - async loadmaindata () { + async loadmaindata (id) { const { BID } = this.props - const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state + const { setting, search, orderBy, pageIndex, pageSize, absFields } = this.state let searches = fromJS(search).toJS() @@ -545,7 +406,9 @@ }) let _orderBy = orderBy || setting.order - let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType) + let param = UtilsDM.getQueryDataParams(setting, searches, _orderBy, pageIndex, pageSize, BID) + + delete param.s_version_up let result = await Api.genericInterface(param) @@ -557,9 +420,9 @@ start = pageSize * (pageIndex - 1) + 1 } - if (setting.selected !== 'false') { + if (setting.selected !== 'false' || (setting.orisel && id)) { setTimeout(() => { - MKEmitter.emit('mkTableCheckTopLine', this.props.MenuID) + MKEmitter.emit('mkTableCheckTopLine', this.props.MenuID, id) }, 200) if (setting.selected === 'init') { this.setState({setting: {...setting, selected: 'false'}}) @@ -578,11 +441,12 @@ } item.key = index item.$$uuid = item[setting.primaryKey] || '' + item.$$key = '' + item.key + item.$$uuid item.$$BID = BID || '' item.$Index = start + index + '' if (setting.controlField) { - if (setting.controlVal.includes(item[setting.controlField])) { + if (setting.controlVal.includes(item[setting.controlField] + '')) { item.$disabled = true } } @@ -596,11 +460,17 @@ this.setState({ loading: false }) - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) + if (result.ErrCode === 'N') { + Modal.error({ + title: result.message, + }) + } else { + notification.error({ + top: 92, + message: result.message, + duration: 10 + }) + } } } @@ -611,10 +481,10 @@ const { BID } = this.props const { setting, orderBy, statFields } = this.state - if (statFields.length === 0 || !(setting.interType === 'system' || (setting.interType === 'custom' && setting.requestMode === 'system')) || !setting.dataresource) return + if (statFields.length === 0 || setting.interType !== 'system' || !setting.dataresource) return let _orderBy = orderBy || setting.order - let param = UtilsDM.getStatQueryDataParams(setting, statFields, searches, _orderBy, BID, this.props.menuType) + let param = UtilsDM.getStatQueryDataParams(setting, statFields, searches, _orderBy, BID) Api.genericInterface(param).then(res => { if (res.status) { @@ -654,7 +524,7 @@ */ async loadmainLinedata (id) { const { BID } = this.props - const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state + const { setting, search, orderBy, pageIndex, pageSize, absFields } = this.state let searches = fromJS(search).toJS() @@ -663,7 +533,9 @@ }) let _orderBy = orderBy || setting.order - let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id) + let param = UtilsDM.getQueryDataParams(setting, searches, _orderBy, pageIndex, pageSize, BID, id) + + delete param.s_version_up let result = await Api.genericInterface(param) if (result.status) { @@ -688,6 +560,7 @@ data = data.map(item => { if (item.$$uuid === _data.$$uuid) { _data.key = item.key + _data.$$key = '' + item.key + item.$$uuid _data.$Index = item.$Index return _data } else { @@ -760,17 +633,17 @@ /** * @description 琛ㄦ牸鍒锋柊 */ - reloadtable = (btn) => { + reloadtable = (btn, id) => { if (!btn || btn.resetPageIndex !== 'false') { MKEmitter.emit('resetTable', this.props.Tab.uuid) // 鍒楄〃閲嶇疆 this.setState({ pageIndex: 1 }, () => { - this.loadData() + this.loadData(id) }) } else { MKEmitter.emit('resetTable', this.props.Tab.uuid, 'false') // 鍒楄〃閲嶇疆 - this.loadData() + this.loadData(id) } } @@ -785,17 +658,15 @@ /** * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ - queryModuleParam = (menuId, btnId) => { - const { Tab, MenuID } = this.props - const { arr_field, orderBy, search, setting} = this.state + queryModuleParam = (menuId, callback) => { + const { MenuID } = this.props + const { orderBy, search, setting} = this.state if (MenuID !== menuId) return - MKEmitter.emit('returnModuleParam', MenuID, btnId, { - arr_field: arr_field, + callback({ orderBy: orderBy || setting.order, - search: search, - menuName: Tab.label + search: search }) } @@ -805,7 +676,7 @@ * @param {*} position // 鍒锋柊浣嶇疆 * @param {*} btn // 鎵ц鐨勬寜閽� */ - refreshByButtonResult = (menuId, position, btn, id, lines) => { + refreshByButtonResult = (menuId, position, btn, id = '', lines) => { const { MenuID } = this.props if (MenuID !== menuId) return @@ -813,7 +684,7 @@ if (position === 'line' && lines && lines.length === 1) { this.loadmainLinedata(lines[0].$$uuid) } else { - this.reloadtable(btn) + this.reloadtable(btn, id) } MKEmitter.emit('refreshPopButton', this.props.Tab.uuid) } @@ -844,13 +715,13 @@ } render() { - const { config, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, selectedData } = this.state + const { config, setting, pageSize, actions, columns, loadingview, viewlost, selectedData } = this.state return ( <div className="subtabtable" id={'subtabtable' + this.props.MenuID}> {loadingview && <Spin />} - {searchlist && searchlist.length ? - <SubSearch BID={this.props.BID} setting={setting} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null + {config && config.search && config.search.length ? + <SubSearch BID={this.props.BID} config={config} refreshdata={this.refreshbysearch}/> : null } {config ? <div style={{minHeight: '25px'}}> <SubAction @@ -858,7 +729,6 @@ actions={actions} columns={columns} BID={this.props.BID} - dict={this.state.dict} BData={this.props.BData} selectedData={selectedData} MenuID={this.props.SupMenuID} @@ -870,7 +740,6 @@ columns={columns} pageSize={pageSize} data={this.state.data} - dict={this.state.dict} BData={this.props.BData} total={this.state.total} MenuID={this.props.MenuID} @@ -885,16 +754,4 @@ } } -const mapStateToProps = (state) => { - return { - menuType: state.editLevel, - permAction: state.permAction, - memberLevel: state.memberLevel - } -} - -const mapDispatchToProps = () => { - return {} -} - -export default connect(mapStateToProps, mapDispatchToProps)(SubTabModalTable) \ No newline at end of file +export default SubTabModalTable \ No newline at end of file -- Gitblit v1.8.0