From c59e0c5a408aebe8080dfce3b2ebc4711f20e7a9 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 04 二月 2020 08:56:11 +0800 Subject: [PATCH] 2020-02-04 --- src/tabviews/formtab/index.jsx | 183 +++++++-------------------------------------- 1 files changed, 30 insertions(+), 153 deletions(-) diff --git a/src/tabviews/formtab/index.jsx b/src/tabviews/formtab/index.jsx index c63349d..8a9bbc4 100644 --- a/src/tabviews/formtab/index.jsx +++ b/src/tabviews/formtab/index.jsx @@ -2,19 +2,20 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { BackTop, notification, Spin, Tabs, Icon, Switch, Modal, Button} from 'antd' +import { BackTop, notification, Spin, Tabs, Icon, Modal, Button} from 'antd' import moment from 'moment' + import Api from '@/api' -import MainTable from './mainTable' +import zhCN from '@/locales/zh-CN/main.js' +import enUS from '@/locales/en-US/main.js' +import Utils from '@/utils/utils.js' + +import FormGroup from './formgroup' import MainAction from '@/tabviews/tableshare/actionList' -import MainSearch from '@/tabviews/tableshare/topSearch' import SubTable from '@/tabviews/subtable' import NotFount from '@/components/404' import asyncComponent from '@/utils/asyncLoadComponent' import {refreshTabView} from '@/store/action' -import zhCN from '@/locales/zh-CN/main.js' -import enUS from '@/locales/en-US/main.js' -import Utils from '@/utils/utils.js' import './index.scss' const SubTabTable = asyncComponent(() => import('@/tabviews/subtabtable')) @@ -24,7 +25,8 @@ static propTpyes = { MenuNo: PropTypes.string, // 鑿滃崟鍙傛暟 MenuName: PropTypes.string, // 鑿滃崟鍙傛暟 - MenuID: PropTypes.string // 鑿滃崟Id + MenuID: PropTypes.string, // 鑿滃崟Id + param: PropTypes.any // 涓昏〃浼犻�掑弬鏁� } state = { @@ -32,14 +34,11 @@ loadingview: true, // 椤甸潰鍔犺浇涓� viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 lostmsg: '', // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅 - config: {}, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑 - searchlist: null, // 鎼滅储鏉′欢 + config: {}, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佽〃鍗曘�佹爣绛剧瓑 actions: null, // 鎸夐挳闆� - columns: null, // 鏄剧ず鍒� arr_field: '', // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆� setting: null, // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑 data: null, // 鍒楄〃鏁版嵁闆� - total: 0, // 鎬绘暟 loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� pageIndex: 1, // 椤电爜 pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 @@ -97,59 +96,26 @@ } let _arrField = [] // 瀛楁闆� - let _columns = [] // 鏄剧ず鍒� - let _hideCol = [] // 闅愯棌鍙婂悎骞跺垪涓瓧娈电殑uuid闆� - let colMap = new Map() + if (this.props.param && this.props.param.arr_field) { + _arrField = this.props.param.arr_field + } else { + config.groups.forEach(group => { + group.sublist.forEach(item => { + if (!item.field) return + + _arrField.push(item.field) + }) + }) + _arrField = _arrField.join(',') + } + console.log(config) // 鏉冮檺杩囨护 config.action = config.action.filter(item => permAction[item.uuid]) // config.tabgroups.forEach(group => { // if (!config[group]) return // config[group] = config[group].filter(tab => permAction[tab.uuid]) // }) - - // 1銆佺瓫閫夊瓧娈甸泦锛�2銆佽繃婊ら殣钘忓垪鍙婂悎骞跺垪涓殑瀛楁uuid - config.columns.forEach(col => { - if (col.field) { - _arrField.push(col.field) - } - if (col.type === 'colspan' && col.sublist) { // 绛涢�夐殣钘忓垪 - _hideCol = _hideCol.concat(col.sublist) - } else if (col.Hide === 'true') { - _hideCol.push(col.uuid) - } - colMap.set(col.uuid, col) - }) - - // 鐢熸垚鏄剧ず鍒楋紝澶勭悊鍚堝苟鍒椾腑鐨勫瓧娈� - config.columns.forEach(col => { - if (_hideCol.includes(col.uuid)) return - - if (col.type === 'colspan' && col.sublist) { - let _col = JSON.parse(JSON.stringify(col)) - let subColumn = [] - _col.sublist.forEach(sub => { - if (colMap.has(sub)) { - subColumn.push(colMap.get(sub)) - } - }) - _col.subColumn = subColumn - _columns.push(_col) - } else { - _columns.push(col) - } - }) - - let _actions = config.action.filter(item => item.position === 'toolbar') // 杩囨护宸ュ叿鏍忔寜閽� - let _operations = config.action.filter(item => item.position === 'grid') // 娣诲姞鎿嶄綔鍒楋紙瀛樺湪鏃讹級 - - if (config.gridBtn && config.gridBtn.display && _operations.length > 0) { - _columns.push({ - ...config.gridBtn, - operations: _operations - }) - } - let _isLinkMain = false // 妫�鏌ユ槸鍚︽湁涓庝富琛ㄥ叧鑱旂殑瀛愯〃 let supmenus = {} @@ -177,11 +143,9 @@ loadingview: false, config: config, setting: config.setting, - searchlist: config.search, - actions: _actions, - columns: _columns, + actions: config.action, isLinkMain: _isLinkMain, - arr_field: _arrField.join(','), + arr_field: _arrField, search: Utils.initMainSearch(config.search), // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 loading: true }, () => { @@ -315,7 +279,6 @@ item.key = index return item }), - total: result.total, loading: false, BIDs: { ...BIDs, @@ -386,12 +349,10 @@ } let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows` - let DateCount = `select count(1) as total from ${_dataresource} ${_search}` param.LText = Utils.formatOptions(LText) param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' param.secretkey = Utils.encrypt(param.LText, param.timestamp) - param.DateCount = Utils.formatOptions(DateCount) return param } @@ -472,11 +433,9 @@ config: {}, searchlist: null, actions: null, - columns: null, arr_field: '', setting: null, data: null, - total: 0, loading: false, pageIndex: 1, pageSize: 10, @@ -509,8 +468,6 @@ this.reloadview() } else if (btn.popClose === 'grid' && type === 'pop') { this.reloadtable() - } else if (type === 'excelOut') { - this.handleDefaultExcelout(btn) } } @@ -519,61 +476,6 @@ */ handleMainTable = () => { this.reloadtable() - } - - /** - * @description 浣跨敤榛樿瀛樺偍杩囩▼ sPC_Get_TableData 瀵煎嚭excel琛ㄦ牸 - */ - handleDefaultExcelout = (btn) => { - const { MenuName } = this.props - const { arr_field, orderColumn, orderType, search, setting, config } = this.state - - let _arr_labels = [] // 鍒楀悕绉伴泦 - let _arr_label_field = [] // 鍒楀悕绉板瓧娈甸泦 - - config.columns.forEach(col => { - if (col.field) { - _arr_labels.push(col.label) - _arr_label_field.push(`${col.field} as ${col.label}`) - } - }) - - _arr_labels = _arr_labels.join(',') - _arr_label_field = _arr_label_field.join(',') - - let _search = Utils.joinMainSearchkey(search) - _search = _search ? 'where ' + _search : '' - - // 鑾峰彇excel鏁版嵁锛屼笌鑾峰彇鍒楄〃鏁版嵁涓嶅悓涓烘湭璁剧疆椤电爜绛夊弬鏁� - let param = { - func: 'sPC_Get_TableData', - obj_name: 'data', - arr_field: _arr_labels - } - - let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order - let _dataresource = setting.dataresource - - if (/\s/.test(_dataresource)) { - _dataresource = '(' + _dataresource + ') tb' - } - - let LText = `select ${_arr_label_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows` - - param.LText = Utils.formatOptions(LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' - param.secretkey = Utils.encrypt(param.LText, param.timestamp) - param.DateCount = '' - - let name = `${MenuName}${moment().format('YYYYMMDDHHmmss')}.xlsx` - - Api.getExcelOut(param, name).then(res => { - if (res && res.status === false) { - this.refs.mainButton.execError(res, btn) - } else { - this.refs.mainButton.execSuccess(btn) - } - }) } /** @@ -671,16 +573,16 @@ } render() { - const { setting, searchlist, actions, columns, loadingview, viewlost, setsingle, pickup, isLinkMain, config } = this.state + const { setting, actions, loadingview, viewlost, isLinkMain, config } = this.state return ( <div className={'commontable ' + (isLinkMain ? 'pick-control' : '')} id={'commontable' + this.props.MenuID}> {loadingview && <Spin size="large" />} - {searchlist && searchlist.length > 0 ? - <MainSearch + {config ? + <FormGroup dict={this.state.dict} - searchlist={searchlist} - refreshdata={this.refreshbysearch} + groups={config.groups} + wrappedComponentRef={(inst) => this.formGroupRef = inst} /> : null } {actions && setting.onload !== 'false' ? @@ -696,31 +598,6 @@ triggerPopview={this.triggerPopview} gettableselected={this.gettableselected} /> : null - } - {columns && setting.onload !== 'false' ? - <div className="main-table-box"> - {isLinkMain ? - <div className="pickchange"> - {setting.tableType === 'checkbox' ? <Switch title="鍗曢�夊垏鎹�" checkedChildren="鍗�" unCheckedChildren="澶�" defaultChecked={setsingle} onChange={this.checkChange} /> : null} - {this.state.BIDs.mainTable && (setting.tableType === 'radio' || setsingle) ? <Switch title="鏀惰捣" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null} - </div> : null - } - <MainTable - ref="mainTable" - pickup={pickup} - setting={setting} - columns={columns} - setsingle={setsingle} - 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 => { -- Gitblit v1.8.0