From c81296b147b3b6e578a241e21bae7bded4b5f6c6 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 24 十月 2023 16:58:16 +0800 Subject: [PATCH] 2023-10-24 --- src/tabviews/custom/components/table/edit-table/index.jsx | 29 +++++ src/tabviews/custom/components/share/normalTable/index.jsx | 81 +++++++++++++++- src/tabviews/custom/components/table/normal-table/index.jsx | 29 +++++ src/menu/components/table/normal-table/columns/index.jsx | 2 src/tabviews/custom/components/table/edit-table/normalTable/index.jsx | 100 ++++++++++++++++++- 5 files changed, 222 insertions(+), 19 deletions(-) diff --git a/src/menu/components/table/normal-table/columns/index.jsx b/src/menu/components/table/normal-table/columns/index.jsx index 029fdae..585012a 100644 --- a/src/menu/components/table/normal-table/columns/index.jsx +++ b/src/menu/components/table/normal-table/columns/index.jsx @@ -655,7 +655,7 @@ <PlusOutlined style={{color: '#26C281'}} title="娣诲姞鍒�" onClick={this.addColumns}/> <CopyOutlined title="澶嶅埗鏄剧ず鍒�" onClick={this.copycolumn} /> <MarkColumn columns={fields} type="line" marks={lineMarks} onSubmit={this.updateLineMarks} /> - <ColsControl config={config} onSubmit={this.props.updatecolumn}/> + {appType !== 'mob' ? <ColsControl config={config} onSubmit={this.props.updatecolumn}/> : null} <FileSyncOutlined title="鍚屾瀛楁闆�" onClick={this.syncfield} /> <DeleteOutlined title="娓呯┖鏄剧ず鍒�" onClick={this.clear}/> </div> diff --git a/src/tabviews/custom/components/share/normalTable/index.jsx b/src/tabviews/custom/components/share/normalTable/index.jsx index f7c2b8d..b090fc7 100644 --- a/src/tabviews/custom/components/share/normalTable/index.jsx +++ b/src/tabviews/custom/components/share/normalTable/index.jsx @@ -442,7 +442,9 @@ loading: PropTypes.bool, // 琛ㄦ牸鍔犺浇涓� refreshdata: PropTypes.func, // 琛ㄦ牸涓帓搴忓垪銆侀〉鐮佺殑鍙樺寲鏃跺埛鏂� chgSelectData: PropTypes.func, // 鏁版嵁鍒囨崲 - autoMatic: PropTypes.any + autoMatic: PropTypes.any, + allSearch: PropTypes.any, + colsCtrls: PropTypes.any } state = { @@ -455,11 +457,13 @@ rowspans: null, // 琛屽悎骞跺瓧娈典俊鎭� pickup: false, // 鏀惰捣鏈�夋嫨椤� orderfields: {}, // 鎺掑簭id涓巉ield杞崲 - pageOptions: [] + pageOptions: [], + allColumns: null, + reseting: false } UNSAFE_componentWillMount () { - const { setting, fields, columns } = this.props + const { setting, columns, fields, colsCtrls } = this.props let radio = 5 // 铏氬寲姣斾緥 let _format = false // 鏄惁铏氬寲澶勭悊 let rowspans = [] @@ -483,7 +487,7 @@ let cell = null if (item.type === 'colspan') { - cell = { title: item.label, align: item.Align } + cell = { title: item.label, align: item.Align, $key: item.uuid } cell.children = getColumns(item.subcols) } else { if (item.rowspan === 'true') { @@ -507,6 +511,7 @@ } cell = { + $key: item.uuid, align: item.Align, dataIndex: item.uuid, title: item.label, @@ -532,6 +537,7 @@ fields.push(item.field) _columns.push({ + $key: item.uuid, align: item.Align, dataIndex: item.field, title: item.label, @@ -564,9 +570,17 @@ pageOptions = pageOptions.sort((a, b) => a - b) } + let allColumns = null + if (colsCtrls) { + rowspans = null + allColumns = [..._columns] + _columns = this.getCurColumns(_columns, this.props.allSearch) + } + this.setState({ pageSize: setting.pageSize || 10, pageOptions, + allColumns, columns: _columns, rowspans, tableId, @@ -582,6 +596,20 @@ shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) + } + + UNSAFE_componentWillReceiveProps(nextProps) { + const { allSearch } = this.props + const { allColumns } = this.state + + if (allSearch && !is(fromJS(allSearch), fromJS(nextProps.allSearch))) { + this.setState({ + reseting: true, + columns: this.getCurColumns(allColumns, nextProps.allSearch) + }, () => { + this.setState({reseting: false}) + }) + } } componentDidMount () { @@ -610,6 +638,47 @@ MKEmitter.removeListener('autoQueryData', this.autoQueryData) MKEmitter.removeListener('autoSelectData', this.autoSelectData) MKEmitter.removeListener('mkCheckTopLine', this.mkCheckTopLine) + } + + getCurColumns = (columns, allSearch) => { + const { colsCtrls } = this.props + + let values = {} + allSearch.forEach(item => { + values[item.key] = item.value + }) + let cols = null + colsCtrls.some(item => { + let originVal = item.field.map(f => values[f] || '').join('') + let contrastVal = item.contrastValue + let result = false + + if (item.match === '=') { + result = originVal === contrastVal + } else if (item.match === '!=') { + result = originVal !== contrastVal + } else { + originVal = isNaN(originVal) ? originVal : +originVal + contrastVal = isNaN(contrastVal) ? contrastVal : +contrastVal + if (item.match === '>') { + result = originVal > contrastVal + } else if (item.match === '<') { + result = originVal < contrastVal + } + } + + if (!result) return false + + cols = item.cols + + return true + }) + + if (cols) { + return columns.filter(col => cols.includes(col.$key)) + } + + return columns } autoSelectData = (id, index) => { @@ -1004,7 +1073,9 @@ render() { const { setting, statFValue, lineMarks, data } = this.props - const { selectedRowKeys, activeIndex, pickup, tableId, pageOptions, columns } = this.state + const { selectedRowKeys, activeIndex, pickup, tableId, pageOptions, columns, reseting } = this.state + + if (reseting) return null // 璁剧疆琛ㄦ牸閫夋嫨灞炴�э細鍗曢�夈�佸閫夈�佷笉鍙�� let rowSelection = null diff --git a/src/tabviews/custom/components/table/edit-table/index.jsx b/src/tabviews/custom/components/table/edit-table/index.jsx index fd88ed1..3922902 100644 --- a/src/tabviews/custom/components/table/edit-table/index.jsx +++ b/src/tabviews/custom/components/table/edit-table/index.jsx @@ -35,7 +35,8 @@ pageIndex: 1, // 椤电爜 pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 orderBy: '', // 鎺掑簭 - search: '' // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞� + search: '', // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞� + allSearch: null } /** @@ -163,6 +164,18 @@ _config.lineMarks = null } + let allSearch = null + if (_config.colsCtrls && _config.colsCtrls.length > 0) { + allSearch = [{key: 'BID', value: BID || ''}] + allSearch.push(..._config.$searches) + if (_config.setting.useMSearch) { + let mainSearch = window.GLOB.SearchBox.get(_config.$searchId) || [] + allSearch.push(...mainSearch) + } + } else { + _config.colsCtrls = null + } + this.setState({ pageSize: setting.pageSize || 10, BID: BID || '', @@ -172,7 +185,8 @@ setting: setting, actions: _config.action, columns: _columns, - search: _config.$searches + search: _config.$searches, + allSearch }, () => { if (_config.setting.onload === 'true') { setTimeout(() => { @@ -255,9 +269,16 @@ total = data[data.length - 1].mk_total || 0 } + let allSearch = null + if (config.colsCtrls) { + allSearch = [{key: 'BID', value: BID || ''}] + allSearch.push(...searches) + } + this.setState({ data: data, selectedData: [], + allSearch: allSearch, total: total, loading: false }) @@ -585,7 +606,7 @@ } render() { - const { BID, setting, actions, config, columns, BData, data, selectedData } = this.state + const { BID, setting, actions, config, columns, BData, data, selectedData, allSearch } = this.state let style = {...config.style} if (config.wrap.empty === 'hidden' && data.length === 0) { @@ -611,9 +632,11 @@ setting={setting} columns={columns} MenuID={config.uuid} + allSearch={allSearch} submit={config.submit} fields={config.columns} total={this.state.total} + colsCtrls={config.colsCtrls} lineMarks={config.lineMarks} loading={this.state.loading} refreshdata={this.refreshbytable} diff --git a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx index 053c122..710d647 100644 --- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx +++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx @@ -1128,6 +1128,8 @@ loading: PropTypes.bool, // 琛ㄦ牸鍔犺浇涓� refreshdata: PropTypes.func, // 琛ㄦ牸涓帓搴忓垪銆侀〉鐮佺殑鍙樺寲鏃跺埛鏂� chgSelectData: PropTypes.func, + allSearch: PropTypes.any, + colsCtrls: PropTypes.any } state = { @@ -1144,11 +1146,13 @@ pageOptions: [], deForms: null, visible: false, - midData: null + midData: null, + allColumns: null, + reseting: false } UNSAFE_componentWillMount () { - const { setting, fields, columns, BID } = this.props + const { setting, fields, columns, BID, colsCtrls } = this.props let orderfields = {} let _columns = [] @@ -1162,7 +1166,7 @@ let cell = null if (item.type === 'colspan') { - cell = { title: item.label, align: item.Align } + cell = { title: item.label, align: item.Align, $key: item.uuid } cell.children = getColumns(item.subcols) } else { if (item.editable === 'true') { @@ -1217,7 +1221,8 @@ title: item.editable === 'true' ? <span>{item.label}<EditOutlined className="system-color mk-edit-sign"/></span> : item.label, sorter: (item.field || item.sortField) && item.IsSort === 'true', width: item.Width || 120, - $type: item.type, + // $type: item.type, + $key: item.uuid, onCell: record => ({ record, col: item, @@ -1257,9 +1262,16 @@ pageOptions = pageOptions.sort((a, b) => a - b) } + let allColumns = null + if (colsCtrls) { + allColumns = [..._columns] + _columns = this.getCurColumns(_columns, this.props.allSearch) + } + this.setState({ forms, signForms, + allColumns, pageSize: setting.pageSize || 10, pageOptions, columns: _columns, @@ -1321,6 +1333,47 @@ MKEmitter.removeListener('changeRecord', this.changeRecord) } + getCurColumns = (columns, allSearch) => { + const { colsCtrls } = this.props + + let values = {} + allSearch.forEach(item => { + values[item.key] = item.value + }) + let cols = null + colsCtrls.some(item => { + let originVal = item.field.map(f => values[f] || '').join('') + let contrastVal = item.contrastValue + let result = false + + if (item.match === '=') { + result = originVal === contrastVal + } else if (item.match === '!=') { + result = originVal !== contrastVal + } else { + originVal = isNaN(originVal) ? originVal : +originVal + contrastVal = isNaN(contrastVal) ? contrastVal : +contrastVal + if (item.match === '>') { + result = originVal > contrastVal + } else if (item.match === '<') { + result = originVal < contrastVal + } + } + + if (!result) return false + + cols = item.cols + + return true + }) + + if (cols) { + return columns.filter(col => cols.includes(col.$key)) + } + + return columns + } + transferData = (menuid, data, type) => { const { MenuID, setting } = this.props const { edData, signForms } = this.state @@ -1367,7 +1420,24 @@ } updateMutil = (data) => { - const { setting } = this.props + const { setting, colsCtrls, allSearch } = this.props + const { allColumns } = this.state + + if (colsCtrls) { + this.setState({ + columns: this.getCurColumns(allColumns, allSearch), + reseting: true, + edData: data, + visible: false, + midData: null + }, () => { + this.setState({ + reseting: false + }) + }) + + return + } if (setting.editType === 'multi' && data.length > 0) { this.setState({edData: []}, () => { @@ -1561,7 +1631,21 @@ return item }) - this.setState({columns: [], edData: []}, () => { + let _cols = this.state.allColumns + if (_cols) { + _cols = _cols.map(item => { + if (reCols[item.dataIndex]) { + item.onCell = record => ({ + record, + col: reCols[item.dataIndex] + }) + } + + return item + }) + } + + this.setState({columns: [], edData: [], allColumns: _cols}, () => { this.setState({columns: _edColumns, edData: edData}) }) } @@ -2144,7 +2228,9 @@ render() { const { setting, lineMarks, submit } = this.props - const { tableId, edData, columns, loading, pageOptions, selectedRowKeys, visible, midData } = this.state + const { tableId, edData, columns, loading, pageOptions, selectedRowKeys, visible, midData, reseting } = this.state + + if (reseting) return null const components = { body: { diff --git a/src/tabviews/custom/components/table/normal-table/index.jsx b/src/tabviews/custom/components/table/normal-table/index.jsx index 63b75d4..97af3a8 100644 --- a/src/tabviews/custom/components/table/normal-table/index.jsx +++ b/src/tabviews/custom/components/table/normal-table/index.jsx @@ -38,7 +38,8 @@ pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 orderBy: '', // 鎺掑簭 search: '', // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞� - statFValue: [] // 鍚堣鍊� + statFValue: [], // 鍚堣鍊� + allSearch: null } loaded = false @@ -138,6 +139,18 @@ _config.style = _config.style || {} + let allSearch = null + if (_config.colsCtrls && _config.colsCtrls.length > 0) { + allSearch = [{key: 'BID', value: BID || ''}] + allSearch.push(..._config.$searches) + if (_config.setting.useMSearch) { + let mainSearch = window.GLOB.SearchBox.get(_config.$searchId) || [] + allSearch.push(...mainSearch) + } + } else { + _config.colsCtrls = null + } + this.setState({ pageSize: setting.pageSize || 10, BID: BID || '', @@ -148,7 +161,8 @@ setting: setting, actions: _config.action, columns: _config.cols, - search: _config.$searches + search: _config.$searches, + allSearch }) } @@ -467,9 +481,16 @@ total = data[data.length - 1].mk_total || 0 } + let allSearch = null + if (config.colsCtrls) { + allSearch = [{key: 'BID', value: BID || ''}] + allSearch.push(...searches) + } + this.setState({ data: data, selectedData: [], + allSearch: allSearch, total: total, loading: false }) @@ -801,7 +822,7 @@ } render() { - const { BID, setting, actions, config, columns, selectedData, BData, data } = this.state + const { BID, setting, actions, config, columns, selectedData, BData, data, allSearch } = this.state let style = {...config.style} if (config.wrap.empty === 'hidden' && (!data || data.length === 0)) { @@ -825,9 +846,11 @@ setting={setting} columns={columns} MenuID={config.uuid} + allSearch={allSearch} data={this.state.data} fields={config.columns} total={this.state.total} + colsCtrls={config.colsCtrls} lineMarks={config.lineMarks} loading={this.state.loading} refreshdata={this.refreshbytable} -- Gitblit v1.8.0