| | |
| | | import Utils from '@/utils/utils.js' |
| | | import options from '@/store/options.js' |
| | | import { scriptMainTable, buttonConfig } from './config' |
| | | import MKEmitter from '@/utils/events.js' |
| | | |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import asyncSpinComponent from '@/utils/asyncSpinComponent' |
| | | import TopSearch from './topSearch' |
| | | import MainAction from './actionList' |
| | | import './index.scss' |
| | | |
| | | const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch')) |
| | | const MainTable = asyncSpinComponent(() => import('@/tabviews/zshare/normalTable')) |
| | | |
| | | class ScriptTable extends Component { |
| | |
| | | actions: [], // 按钮集 |
| | | columns: [], // 显示列 |
| | | arr_field: '', // 使用 sPC_Get_TableData 时的查询字段集 |
| | | logcolumns: null, // 日志中显示的列信息 (增加至全部列,除去合并列) |
| | | setting: {}, // 页面全局设置:数据源、按钮及显示列固定、主键等 |
| | | data: [], // 列表数据集 |
| | | selectedData: [], // 已选表格数据 |
| | | resetTable: false, // 表格重置,值在true与false之间切换,切换时表格重置 |
| | | total: 0, // 总数 |
| | | loading: false, // 列表数据加载中 |
| | | pageIndex: 1, // 页码 |
| | |
| | | |
| | | let _arrField = [] // 字段集 |
| | | let _columns = [] // 显示列 |
| | | let _logcolumns = [] // 日志显示列 |
| | | let _hideCol = [] // 隐藏及合并列中字段的uuid集 |
| | | let colMap = new Map() // 用于字段过滤 |
| | | |
| | |
| | | config.columns.forEach(col => { |
| | | if (col.field) { |
| | | _arrField.push(col.field) |
| | | |
| | | _logcolumns.push(col) |
| | | } |
| | | 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 (col.type === 'colspan') { |
| | | if (col.unfold !== 'true') { // 不展开为旧版合并列 |
| | | col.type = 'old_colspan' |
| | | } |
| | | |
| | | let _col = fromJS(col).toJS() |
| | | let subcols = [] |
| | | _col.sublist && _col.sublist.forEach(sub => { |
| | | if (colMap.has(sub)) { |
| | | subColumn.push(colMap.get(sub)) |
| | | subcols.push(colMap.get(sub)) |
| | | } |
| | | }) |
| | | _col.subColumn = subColumn |
| | | _columns.push(_col) |
| | | if (subcols.length > 0) { |
| | | _col.subcols = subcols |
| | | _columns.push(_col) |
| | | } |
| | | } else { |
| | | _columns.push(col) |
| | | } |
| | |
| | | return item |
| | | }), |
| | | columns: _columns, |
| | | logcolumns: _logcolumns, |
| | | arr_field: _arrField.join(','), |
| | | search: Utils.initMainSearch(config.search) |
| | | }, () => { |
| | |
| | | * @description 主表数据加载 |
| | | */ |
| | | async loadmaindata () { |
| | | const { setting } = this.state |
| | | let param = this.getDefaultParam() |
| | | |
| | | this.setState({ |
| | |
| | | if (result.status) { |
| | | this.setState({ |
| | | data: result.data.map((item, index) => { |
| | | item.LongParam = Utils.UnformatOptions(item.LongParam) |
| | | item.key = index |
| | | item.$$uuid = item[setting.primaryKey] || '' |
| | | return item |
| | | }), |
| | | total: result.total, |
| | |
| | | let param = { |
| | | func: 'sPC_Get_TableData', |
| | | obj_name: 'data', |
| | | arr_field: arr_field |
| | | arr_field: arr_field, |
| | | menuname: this.props.MenuName || '' |
| | | } |
| | | |
| | | let _orderBy = orderBy || setting.order |
| | |
| | | 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.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | param.DateCount = Utils.formatOptions(DateCount) |
| | | |
| | |
| | | * 含有初始不加载的页面,修改设置 |
| | | */ |
| | | refreshbysearch = (searches) => { |
| | | MKEmitter.emit('resetTable', this.props.MenuID) // 列表重置 |
| | | this.setState({ |
| | | loading: true, |
| | | pageIndex: 1, |
| | | selectedData: [], |
| | | search: searches, |
| | | resetTable: !this.state.resetTable |
| | | search: searches |
| | | }, () => { |
| | | this.loadmaindata() |
| | | }) |
| | |
| | | * @description 表格刷新 |
| | | */ |
| | | reloadtable = () => { |
| | | MKEmitter.emit('resetTable', this.props.MenuID) // 列表重置 |
| | | this.setState({ |
| | | loading: true, |
| | | pageIndex: 1, |
| | | selectedData: [], |
| | | resetTable: !this.state.resetTable |
| | | selectedData: [] |
| | | }, () => { |
| | | this.loadmaindata() |
| | | }) |
| | |
| | | }, () => { |
| | | this.loadconfig() |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * @description 按钮操作完成后(成功或失败),页面刷新,重置页码及选择项 |
| | | */ |
| | | refreshbyaction = (btn, type) => { |
| | | if (btn.execSuccess === 'grid' && type === 'success') { |
| | | this.reloadtable() |
| | | } else if (btn.execError === 'grid' && type === 'error') { |
| | | this.reloadtable() |
| | | } else if (btn.execSuccess === 'view' && type === 'success') { |
| | | this.reloadview() |
| | | } else if (btn.execError === 'view' && type === 'error') { |
| | | this.reloadview() |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | }) |
| | | } |
| | | |
| | | reloadMenuView = (menuId) => { |
| | | const { MenuID } = this.props |
| | | |
| | | if (MenuID !== menuId) return |
| | | |
| | | this.reloadview() |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | // 组件加载时,获取菜单数据 |
| | | this.loadconfig() |
| | | } |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('reloadMenuView', this.reloadMenuView) |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | MKEmitter.removeListener('reloadMenuView', this.reloadMenuView) |
| | | } |
| | | |
| | | render() { |
| | | const { dict, searchlist, config, setting, actions, columns, pickup, selectedData } = this.state |
| | | const { searchlist, setting, actions, columns, pickup, selectedData } = this.state |
| | | |
| | | return ( |
| | | <div className="script-manage-table" id={this.state.ContainerId}> |
| | | <TopSearch |
| | | dict={dict} |
| | | searchlist={searchlist} |
| | | refreshdata={this.refreshbysearch} |
| | | /> |
| | | <MainSearch searchlist={searchlist} menuType="HS" refreshdata={this.refreshbysearch}/> |
| | | <MainAction |
| | | BID="" |
| | | type="main" |
| | |
| | | dict={this.state.dict} |
| | | MenuID={this.props.MenuID} |
| | | selectedData={selectedData} |
| | | logcolumns={this.state.logcolumns} |
| | | ContainerId={this.state.ContainerId} |
| | | refreshdata={this.refreshbyaction} |
| | | refreshdata={this.reloadtable} |
| | | /> |
| | | <div className="main-table-box"> |
| | | {this.state.data && this.state.data.length > 0 ? |
| | |
| | | </div> : null |
| | | } |
| | | <MainTable |
| | | tableId="mainTable" |
| | | tableId={this.props.MenuID} |
| | | pickup={pickup} |
| | | config={config} |
| | | setting={setting} |
| | | columns={columns} |
| | | dict={this.state.dict} |
| | |
| | | loading={this.state.loading} |
| | | refreshdata={this.refreshbytable} |
| | | buttonTrigger={() => {}} |
| | | handleTableId={() => {}} |
| | | resetTable={this.state.resetTable} |
| | | chgSelectData={this.changeSelectedData} |
| | | /> |
| | | </div> |