From 9e716f3bd30820a08757845b592db73363faa48c Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 25 四月 2022 14:53:37 +0800 Subject: [PATCH] 2022-04-25 --- src/tabviews/subtabtable/index.jsx | 357 ++++++++++++++++++++++++++++++---------------------------- 1 files changed, 184 insertions(+), 173 deletions(-) diff --git a/src/tabviews/subtabtable/index.jsx b/src/tabviews/subtabtable/index.jsx index af27534..9343c02 100644 --- a/src/tabviews/subtabtable/index.jsx +++ b/src/tabviews/subtabtable/index.jsx @@ -2,7 +2,7 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { notification, Spin, Col, Row, Icon, Tabs} from 'antd' +import { notification, Spin} from 'antd' import Api from '@/api' import zhCN from '@/locales/zh-CN/main.js' @@ -10,7 +10,7 @@ import Utils from '@/utils/utils.js' import options from '@/store/options.js' import UtilsDM from '@/utils/utils-datamanage.js' -import { updateSubTable } from '@/utils/utils-update.js' +import { updateSubTabTable } from '@/utils/utils-update.js' import asyncComponent from '@/utils/asyncComponent' import asyncSpinComponent from '@/utils/asyncSpinComponent' import NotFount from '@/components/404' @@ -18,12 +18,9 @@ import './index.scss' -const { TabPane } = Tabs const SubSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch')) const SubAction = asyncComponent(() => import('@/tabviews/zshare/actionList')) const SubTable = asyncSpinComponent(() => import('@/tabviews/zshare/normalTable')) -const CardComponent = asyncSpinComponent(() => import('@/tabviews/zshare/cardcomponent')) -const ChartComponent = asyncSpinComponent(() => import('@/tabviews/zshare/chartcomponent')) class SubTabModalTable extends Component { static propTpyes = { @@ -31,7 +28,6 @@ BID: PropTypes.string, // 涓婄骇鏁版嵁ID BData: PropTypes.any, // 涓婄骇鏁版嵁 MenuID: PropTypes.string, // 鑿滃崟Id - mainSearch: PropTypes.any, // 涓昏〃鎼滅储鏉′欢 SupMenuID: PropTypes.string, // 涓婄骇鑿滃崟Id } @@ -54,7 +50,6 @@ pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 orderBy: '', // 鎺掑簭 search: '', // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞� - chartId: '', // 灞曞紑鍥捐〃ID statFields: [], // 鍚堣瀛楁 statFValue: [], // 鍚堣鍊� absFields: [], // 缁濆鍊煎瓧娈� @@ -79,6 +74,7 @@ try { // 閰嶇疆淇℃伅瑙f瀽 config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) config.setting.MenuName = Tab.label + config.setting.$name = Tab.label } catch (e) { console.warn('Parse Failure') config = '' @@ -111,7 +107,7 @@ let absFields = [] // 缁濆鍊煎瓧娈� // 鐗堟湰鍏煎 - config = updateSubTable(config) + config = updateSubTabTable(config) // 涓嶆敮鎸乫uncbutton銆乸opview 绫诲瀷鎸夐挳 let labels = [] @@ -136,17 +132,17 @@ config.action = config.action.filter(item => permAction[item.uuid]) } - let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID - // 瀛楁鏉冮檺榛戝悕鍗� - config.search = config.search.filter(item => { - item.oriInitval = item.initval - if (!item.blacklist || item.blacklist.length === 0) return item - if (item.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) { - item.Hide = 'true' - } + config.search = Utils.initSearchVal(config.search) - return item + let hasReqFields = false + config.search.forEach(field => { + if (field.required) { + hasReqFields = true + } }) + + // 瀛楁鏉冮檺榛戝悕鍗� + let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID config.columns = config.columns.map(col => { if (!col.blacklist || col.blacklist.length === 0) return col @@ -156,19 +152,6 @@ return col }) - - // 瑙嗗浘鏉冮檺 - config.charts = config.charts.filter(item => { - if (item.Hide === 'true') return false - if (!item.blacklist || item.blacklist.length === 0) return true - return item.blacklist.filter(v => roleId.indexOf(v) > -1).length === 0 - }) - - if (config.charts.length <= 1) { - config.expand = true - } - - let chartId = config.charts[0] ? config.charts[0].uuid : '' // 1銆佺瓫閫夊瓧娈甸泦锛�2銆佽繃婊ら殣钘忓垪鍙婂悎骞跺垪涓殑瀛楁uuid config.columns.forEach(col => { @@ -235,16 +218,6 @@ _columns.push(config.gridBtn) } - let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉 - let hasReqFields = false - config.search.forEach(field => { - if (field.required !== 'true') return - hasReqFields = true - if (!field.initval) { - valid = false - } - }) - config.setting.tabType = 'subtab' // 鏁版嵁婧愪俊鎭澶勭悊 config.setting.laypage = config.setting.laypage !== 'false' // 鏄惁鍒嗛〉锛岃浆涓篵oolean 缁熶竴鏍煎紡 @@ -303,9 +276,25 @@ }) } + 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) { + if (config.setting.controlVal) { + config.setting.controlVal = config.setting.controlVal.split(',') + } else { + config.setting.controlVal = [''] + } + } + this.setState({ + pageSize: config.setting.pageSize || 10, loadingview: false, - chartId, config, absFields, statFields, @@ -317,7 +306,7 @@ search: Utils.initMainSearch(config.search), // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 hasReqFields }, () => { - if (config.setting.onload !== 'false' && valid) { // 鍒濆鍖栧彲鍔犺浇 + if (config.setting.onload !== 'false') { // 鍒濆鍖栧彲鍔犺浇 this.loadData() } }) @@ -334,27 +323,22 @@ } } - loadData = () => { - const { mainSearch } = this.props + loadData = (id) => { const { setting, search, hasReqFields, loadCustomApi } = this.state let searches = fromJS(search).toJS() - if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - searches = [...mainSearch, ...searches] - } - - let requireFields = [] if (hasReqFields) { - requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0)) + let requireFields = searches.filter(item => item.required && item.value === '') + if (requireFields.length > 0) { + this.setState({ + loading: false + }) + return + } } - if (requireFields.length > 0) { - this.setState({ - loading: false - }) - return - } else if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) { + if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) { notification.warning({ top: 92, message: '鏈缃寮忕郴缁熷湴鍧�!', @@ -374,10 +358,10 @@ this.loadOutResource(searches) if (setting.execType === 'async') { - this.loadmaindata() + this.loadmaindata(id) } } else { - this.loadmaindata() + this.loadmaindata(id) } } @@ -443,7 +427,7 @@ }) Api.directRequest(url, setting.method, param, setting.cross).then(res => { - if (typeof(res) !== 'object' || Array.isArray(res)) { + if (typeof(res) !== 'object') { let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒' if (typeof(res) === 'string') { @@ -458,6 +442,9 @@ this.customCallbackRequest(_result) } else { + if (Array.isArray(res)) { + res = { data: res } + } res.mk_api_key = mkey this.customCallbackRequest(res) } @@ -497,8 +484,8 @@ param = UtilsDM.getCallBackQueryParams(setting, sql, errSql) - if (this.state.BID) { - param.BID = this.state.BID + if (this.props.BID) { + param.BID = this.props.BID } if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉 @@ -515,7 +502,7 @@ Sort: index + 1 })) - if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) { + if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) { let sql = lines.map(item => (` ${item.insert} ${item.selects.join(` union all @@ -549,14 +536,11 @@ /** * @description 瀛愯〃鏁版嵁鍔犺浇 */ - async loadmaindata () { - const { mainSearch, BID } = this.props + async loadmaindata (id) { + const { BID } = this.props const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state let searches = fromJS(search).toJS() - if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - searches = [...mainSearch, ...searches] - } this.setState({ loading: true @@ -564,10 +548,6 @@ let _orderBy = orderBy || setting.order let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType) - - if (param.func === 'sPC_Get_TableData') { - param.menuname = this.props.Tab.label || '' - } let result = await Api.genericInterface(param) @@ -577,6 +557,15 @@ let start = 1 if (setting.laypage) { start = pageSize * (pageIndex - 1) + 1 + } + + if (setting.selected !== 'false' || (setting.orisel && id)) { + setTimeout(() => { + MKEmitter.emit('mkTableCheckTopLine', this.props.MenuID, id) + }, 200) + if (setting.selected === 'init') { + this.setState({setting: {...setting, selected: 'false'}}) + } } this.setState({ @@ -591,8 +580,15 @@ } item.key = index item.$$uuid = item[setting.primaryKey] || '' + item.$$key = '' + item.key + item.$$uuid item.$$BID = BID || '' - item.$Index = start + index + item.$Index = start + index + '' + + if (setting.controlField) { + if (setting.controlVal.includes(item[setting.controlField])) { + item.$disabled = true + } + } return item }), @@ -623,10 +619,6 @@ let _orderBy = orderBy || setting.order let param = UtilsDM.getStatQueryDataParams(setting, statFields, searches, _orderBy, BID, this.props.menuType) - if (param.func === 'sPC_Get_TableData') { - param.menuname = this.props.Tab.label || '' - } - Api.genericInterface(param).then(res => { if (res.status) { let _data = res.data[0] @@ -661,11 +653,85 @@ } /** + * @description 鑾峰彇鍗曡鏁版嵁 + */ + async loadmainLinedata (id) { + const { BID } = this.props + const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state + + let searches = fromJS(search).toJS() + + this.setState({ + loading: true + }) + + let _orderBy = orderBy || setting.order + let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id) + + let result = await Api.genericInterface(param) + if (result.status) { + let data = fromJS(this.state.data).toJS() + let selectedData = fromJS(this.state.selectedData).toJS() + if (result.data && result.data[0]) { + let _data = result.data[0] || {} + + if (absFields.length) { + absFields.forEach(field => { + if (!_data[field]) return + if (isNaN(Math.abs(_data[field]))) return + + _data[field] = Math.abs(_data[field]) + }) + } + + _data.$$uuid = _data[setting.primaryKey] || '' + _data.$$BID = BID || '' + + try { + 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 { + return item + } + }) + selectedData = selectedData.map(item => { + if (_data.$$uuid === item.$$uuid) { + return _data + } + return item + }) + } catch (e) { + console.warn('鏁版嵁鏌ヨ閿欒') + } + } + + this.setState({ + data, + selectedData, + loading: false + }) + } else { + this.setState({ + loading: false + }) + notification.error({ + top: 92, + message: result.message, + duration: 10 + }) + } + } + + /** * @description 鎼滅储鏉′欢鏀瑰彉鏃讹紝閲嶇疆琛ㄦ牸鏁版嵁 * 鍚湁鍒濆涓嶅姞杞界殑椤甸潰锛屼慨鏀硅缃� */ refreshbysearch = (searches) => { - MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 鍒楄〃閲嶇疆 + MKEmitter.emit('resetTable', this.props.Tab.uuid) // 鍒楄〃閲嶇疆 this.setState({ pageIndex: 1, search: searches @@ -698,17 +764,17 @@ /** * @description 琛ㄦ牸鍒锋柊 */ - reloadtable = (btn) => { + reloadtable = (btn, id) => { if (!btn || btn.resetPageIndex !== 'false') { - MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 鍒楄〃閲嶇疆 + MKEmitter.emit('resetTable', this.props.Tab.uuid) // 鍒楄〃閲嶇疆 this.setState({ pageIndex: 1 }, () => { - this.loadData() + this.loadData(id) }) } else { - MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid, 'false') // 鍒楄〃閲嶇疆 - this.loadData() + MKEmitter.emit('resetTable', this.props.Tab.uuid, 'false') // 鍒楄〃閲嶇疆 + this.loadData(id) } } @@ -724,20 +790,15 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, btnId) => { - const { Tab, mainSearch, MenuID } = this.props + const { Tab, MenuID } = this.props const { arr_field, orderBy, search, setting} = this.state if (MenuID !== menuId) return - let searches = search - if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - searches = [...mainSearch, ...search] - } - MKEmitter.emit('returnModuleParam', MenuID, btnId, { arr_field: arr_field, orderBy: orderBy || setting.order, - search: searches, + search: search, menuName: Tab.label }) } @@ -748,20 +809,17 @@ * @param {*} position // 鍒锋柊浣嶇疆 * @param {*} btn // 鎵ц鐨勬寜閽� */ - refreshByButtonResult = (menuId, position, btn) => { + refreshByButtonResult = (menuId, position, btn, id = '', lines) => { const { MenuID } = this.props if (MenuID !== menuId) return - this.reloadtable(btn) + if (position === 'line' && lines && lines.length === 1) { + this.loadmainLinedata(lines[0].$$uuid) + } else { + this.reloadtable(btn, id) + } MKEmitter.emit('refreshPopButton', this.props.Tab.uuid) - } - - /** - * @description 鍥捐〃瑙嗗浘鍒囨崲 - */ - changeChart = (uuid) => { - this.setState({chartId: uuid}) } UNSAFE_componentWillMount () { @@ -790,7 +848,7 @@ } render() { - const { config, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, chartId, selectedData } = this.state + const { config, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, selectedData } = this.state return ( <div className="subtabtable" id={'subtabtable' + this.props.MenuID}> @@ -798,80 +856,33 @@ {searchlist && searchlist.length ? <SubSearch BID={this.props.BID} setting={setting} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null } - {config ? <Row className="chart-view" gutter={16}> - {/* 瑙嗗浘缁� */} - {!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 ( - <Col span={item.width || 24} key={item.uuid}> - {config.charts.length > 1 ? <p className="chart-table chart-title">{item.title}</p> : null} - <div style={{minHeight: '25px'}}> - <SubAction - setting={setting} - actions={actions} - columns={columns} - BID={this.props.BID} - dict={this.state.dict} - BData={this.props.BData} - selectedData={selectedData} - MenuID={this.props.SupMenuID} - /> - </div> - <SubTable - tableId={this.props.Tab.uuid} - setting={setting} - columns={columns} - pageSize={pageSize} - data={this.state.data} - dict={this.state.dict} - BData={this.props.BData} - total={this.state.total} - MenuID={this.props.MenuID} - loading={this.state.loading} - refreshdata={this.refreshbytable} - statFValue={this.state.statFValue} - chgSelectData={this.changeSelectedData} - handleTableId={() => {}} - /> - </Col> - ) - } else if (item.chartType === 'card') { - return ( - <Col className="card-view" span={item.width} key={item.uuid}> - <CardComponent - tableId="" - plot={item} - config={config} - columns={columns} - BID={this.props.BID} - data={this.state.data} - BData={this.props.BData} - loading={this.state.loading} - handleTableId={() => {}} - /> - </Col> - ) - } else { - return ( - <Col span={item.width} key={item.uuid}> - <ChartComponent - plot={item} - config={config} - data={this.state.data} - loading={this.state.loading} - /> - </Col> - ) - } - })} - </Row> : null } + {config ? <div style={{minHeight: '25px'}}> + <SubAction + setting={setting} + actions={actions} + columns={columns} + BID={this.props.BID} + dict={this.state.dict} + BData={this.props.BData} + selectedData={selectedData} + MenuID={this.props.SupMenuID} + /> + </div> : null} + {config ? <SubTable + tableId={this.props.Tab.uuid} + setting={setting} + columns={columns} + pageSize={pageSize} + data={this.state.data} + dict={this.state.dict} + BData={this.props.BData} + total={this.state.total} + MenuID={this.props.MenuID} + loading={this.state.loading} + refreshdata={this.refreshbytable} + statFValue={this.state.statFValue} + chgSelectData={this.changeSelectedData} + /> : null} {viewlost ? <NotFount msg={this.state.lostmsg} /> : null} </div> ) -- Gitblit v1.8.0