From cf8e332b14ca79859fcd89f2ac097ed7c6aa66c5 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 01 十二月 2019 18:15:45 +0800 Subject: [PATCH] 2019-12-01 --- src/components/preview/index.scss | 1 src/tabviews/commontable/mainAction/index.jsx | 6 src/templates/comtableconfig/source.jsx | 1 src/components/sidemenu/editthdmenu/index.jsx | 57 ++++++-- src/templates/comtableconfig/index.jsx | 5 src/templates/comtableconfig/settingform/index.jsx | 30 ++++ src/templates/comtableconfig/editcard/index.scss | 5 src/tabviews/commontable/mainTable/index.scss | 3 src/tabviews/commontable/index.jsx | 148 ++++++++++++-------- src/components/sidemenu/editthdmenu/index.scss | 1 src/tabviews/commontable/mainTable/index.jsx | 4 src/templates/comtableconfig/editcard/index.jsx | 52 +++++- src/utils/utils.js | 62 ++++++++ 13 files changed, 285 insertions(+), 90 deletions(-) diff --git a/src/components/preview/index.scss b/src/components/preview/index.scss index fadcb88..ea0d380 100644 --- a/src/components/preview/index.scss +++ b/src/components/preview/index.scss @@ -10,6 +10,7 @@ text-align: center; opacity: 0; transition: opacity 0.5s; + cursor: zoom-out; img { max-width: 80vw; max-height: 90vh; diff --git a/src/components/sidemenu/editthdmenu/index.jsx b/src/components/sidemenu/editthdmenu/index.jsx index 2e9a742..3e5a4d9 100644 --- a/src/components/sidemenu/editthdmenu/index.jsx +++ b/src/components/sidemenu/editthdmenu/index.jsx @@ -3,7 +3,7 @@ import { is, fromJS } from 'immutable' import { DndProvider } from 'react-dnd' import HTML5Backend from 'react-dnd-html5-backend' -import { notification, Modal, Button, Spin, Icon, Col, Card, Tabs, Row } from 'antd' +import { notification, Modal, Button, Spin, Icon, Col, Card, Tabs, Row, Input } from 'antd' import Preview from '@/components/preview' import TransferForm from '@/components/transferform' import Utils from '@/utils/utils.js' @@ -19,6 +19,7 @@ const ModalConfig = asyncLoadComponent(() => import('@/templates/modalconfig')) const { confirm } = Modal const { TabPane } = Tabs +const { Search } = Input const illust = { CommonTable: nortable } @@ -48,6 +49,7 @@ selectTemp: '', // 閫夋嫨妯℃澘 usedTemplates: null, menuConfig: '', + tempSearchKey: '', baseTemplates: [{ title: '鍩虹琛ㄦ牸', type: 'CommonTable', @@ -146,8 +148,24 @@ handleSubBtn = (type) => { // 鎿嶄綔鎸夐挳锛氭坊鍔犮�佽В闄ゅ喕缁撱�佺‘璁ゅ強鍏抽棴 if (type === 'add') { // 鐐瑰嚮娣诲姞鏃讹紝灞曞紑妯℃澘 + if (previewList && !is(fromJS(previewList), fromJS(this.state.subMenulist))) { + notification.warning({ + top: 92, + message: this.state.dict['header.menu.presave'], + duration: 10 + }) + return + } this.setState({tabview: 'template', type: 'add'}) } else if (type === 'thaw') { + if (previewList && !is(fromJS(previewList), fromJS(this.state.subMenulist))) { + notification.warning({ + top: 92, + message: this.state.dict['header.menu.presave'], + duration: 10 + }) + return + } this.setState({ thawMvisible: true }) @@ -403,9 +421,9 @@ <Col key={template.type} span={8}> <Card title={template.title}> - <img src={template.url} alt=""/> + <img onClick={() => {this.previewPicture(template.url)}} src={template.url} alt=""/> <div className="card-operation"> - <Button type="primary" onClick={() => {this.previewPicture(template.url)}}>棰勮</Button> + {/* <Button type="primary" onClick={() => {this.previewPicture(template.url)}}>棰勮</Button> */} <Button type="primary" onClick={() => {this.useTemplate(template)}}>浣跨敤妯℃澘</Button> </div> </Card> @@ -416,19 +434,28 @@ </TabPane> <TabPane tab="宸蹭娇鐢ㄦā鏉�" key="2"> <Row> + <Col span={8}> + <Search placeholder="璇疯緭鍏ヨ彍鍗曞悕绉�" defaultValue={this.state.tempSearchKey} onSearch={value => {this.setState({tempSearchKey: value})}} enterButton /> + </Col> + </Row> + <Row> {this.state.usedTemplates && this.state.usedTemplates.map((template, index) => { - return ( - <Col key={template.type + index} span={8}> - <Card - title={template.title}> - <img src={template.url} alt=""/> - <div className="card-operation"> - <Button type="primary" onClick={() => {this.previewPicture(template.url)}}>棰勮</Button> - <Button type="primary" onClick={() => {this.useTemplate(template)}}>浣跨敤妯℃澘</Button> - </div> - </Card> - </Col> - ) + if (template.title.toLowerCase().indexOf(this.state.tempSearchKey.toLowerCase()) >= 0) { + return ( + <Col key={template.type + index} span={8}> + <Card + title={template.title}> + <img onClick={() => {this.previewPicture(template.url)}} src={template.url} alt=""/> + <div className="card-operation"> + {/* <Button type="primary" onClick={() => {this.previewPicture(template.url)}}>棰勮</Button> */} + <Button type="primary" onClick={() => {this.useTemplate(template)}}>浣跨敤妯℃澘</Button> + </div> + </Card> + </Col> + ) + } else { + return '' + } })} </Row> </TabPane> diff --git a/src/components/sidemenu/editthdmenu/index.scss b/src/components/sidemenu/editthdmenu/index.scss index 2e00631..0ebba4f 100644 --- a/src/components/sidemenu/editthdmenu/index.scss +++ b/src/components/sidemenu/editthdmenu/index.scss @@ -78,6 +78,7 @@ } img { max-width: 100%; + cursor: zoom-in; } } } diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx index c87be74..027f7fb 100644 --- a/src/tabviews/commontable/index.jsx +++ b/src/tabviews/commontable/index.jsx @@ -27,17 +27,16 @@ searchlist: null, actions: null, columns: null, + arr_field: '', setting: null, data: null, total: 0, loading: false, - param: { - pageIndex: 1, - pageSize: 10, - orderColumn: '', - orderType: '', - search: '' - }, + pageIndex: 1, + pageSize: 10, + orderColumn: '', + orderType: 'asc', + search: '', fixed: {} } @@ -67,14 +66,29 @@ duration: 10 }) } + + let _search = Utils.mainjointsearchkey(config.search) + let _arrField = [] + + config.columns.forEach(col => { + if (col.field) { + _arrField.push(col.field) + } + }) + this.setState({ config: config, setting: config.setting, searchlist: config.search, actions: config.action, - columns: config.columns + columns: config.columns, + arr_field: _arrField.join(','), + search: _search ? 'where (' + _search + ')' : '', + orderColumn: config.setting.orderColumn, + loading: true }, () => { this.improveSearch() + this.loadmaindata() }) } else { this.setState({ @@ -159,66 +173,82 @@ }) } - async loadmaindata (pageIndex = 1, pageSize = 10, orderColumn = '', orderType = '', search = '') { + async loadmaindata () { + const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state // 鑾峰彇鍒楄〃鏁版嵁 - let result = await Api.getMainTableData(this.props.MenuNo, pageIndex, pageSize, orderColumn, orderType, search) + let param = { + func: 'sPC_Get_TableData', + obj_name: 'data', + arr_field: arr_field + } + + let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderColumn} ${orderType}) as rows from ${setting.dataresource} ${search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows` + let DateCount = `select count(1) as total from ${setting.dataresource} ${search}` + console.log(LText) + console.log(DateCount) + param.LText = Utils.formatOptions(LText) + param.DateCount = Utils.formatOptions(DateCount) + let result = await Api.genericInterface(param) if (result.status) { this.setState({ data: result.data.map((item, index) => { item.key = index - item.rows = item.mkrows return item }), total: result.total, loading: false + }) + } else { + this.setState({ + loading: false + }) + notification.error({ + top: 92, + message: result.message, + duration: 15 }) } } refreshbysearch = (searches) => { // 鎼滅储鏉′欢鍙樺寲 - console.log(searches) - // searches = Utils.jointsearchkey(searches) - // this.loadmaindata(this.state.param.pageIndex, this.state.param.pageSize, this.state.param.orderColumn, this.state.param.orderType, searches) - // let param = Object.assign({}, this.state.param, { - // search: searches - // }) - // this.setState({ - // loading: true, - // param: param - // }) + let search = Utils.mainjointsearchkey(searches) + this.refs.mainTable.resetTable() + + this.setState({ + loading: true, + search: search ? 'where (' + search + ')' : '' + }, () => { + this.loadmaindata() + }) } refreshbytable = (pagination, filters, sorter) => { // 琛ㄦ牸鏌ヨ鏉′欢淇敼 - console.log(pagination) - console.log(filters) - console.log(sorter) - // if (sorter.order) { - // let _chg = { - // ascend: 'asc', - // descend: 'desc' - // } - // sorter.order = _chg[sorter.order] - // } - // this.loadmaindata(pagination.current, pagination.pageSize, sorter.field, sorter.order, this.state.param.search) - // let param = Object.assign({}, this.state.param, { - // pageIndex: pagination.current, - // pageSize: pagination.pageSize, - // orderColumn: sorter.field, - // orderType: sorter.order - // }) - // this.setState({ - // loading: true, - // param: param - // }) + if (sorter.order) { + let _chg = { + ascend: 'asc', + descend: 'desc' + } + sorter.order = _chg[sorter.order] + } + + this.setState({ + loading: true, + pageIndex: pagination.current, + pageSize: pagination.pageSize, + orderColumn: sorter.field || this.state.setting.orderColumn, + orderType: sorter.order || 'asc' + }, () => { + this.loadmaindata() + }) } refreshbyaction = (btn, type) => { // 鎸夐挳鎿嶄綔鍚庡埛鏂拌〃鏍�,閲嶇疆椤电爜鍙婇�夋嫨椤� console.log(btn) console.log(type) - // this.refs.mainTable.resetTable() + this.refs.mainTable.resetTable() // this.loadmaindata(1, this.state.param.pageSize, this.state.param.orderColumn, this.state.param.orderType, this.state.param.search) // this.setState({ // loading: true @@ -239,22 +269,22 @@ this.loadconfig() // this.loadmaindata() - this.setState({ - data: [1,2,3,4,5,6,7,8,9,10].map((item, index) => { - return { - key: index, - ID: item + 'mainkey', - ExRateName: '$', - SupplierName: '澶╃尗' + item + '搴�', - SupShortName: '澶╃尗', - SupplierCode: '201922' + item, - OrgName: '闃块噷宸村反', - OrgCode: '302999', - PlanDate: '2019-11-' + (item < 10 ? '0' + item : item) - } - }), - total: 329 - }) + // this.setState({ + // data: [1,2,3,4,5,6,7,8,9,10].map((item, index) => { + // return { + // key: index, + // ID: item + 'mainkey', + // ExRateName: '$', + // SupplierName: '澶╃尗' + item + '搴�', + // SupShortName: '澶╃尗', + // SupplierCode: '201922' + item, + // OrgName: '闃块噷宸村反', + // OrgCode: '302999', + // PlanDate: '2019-11-' + (item < 10 ? '0' + item : item) + // } + // }), + // total: 329 + // }) } shouldComponentUpdate (nextProps, nextState) { diff --git a/src/tabviews/commontable/mainAction/index.jsx b/src/tabviews/commontable/mainAction/index.jsx index 4124488..e028e73 100644 --- a/src/tabviews/commontable/mainAction/index.jsx +++ b/src/tabviews/commontable/mainAction/index.jsx @@ -74,6 +74,12 @@ this.execSubmit(item, data, () => { this.setState({loadingUuid: ''}) }) + } else { + notification.warning({ + top: 92, + message: '瀹屽杽涓�傘�傘��', + duration: 10 + }) } } diff --git a/src/tabviews/commontable/mainTable/index.jsx b/src/tabviews/commontable/mainTable/index.jsx index 013563c..050544c 100644 --- a/src/tabviews/commontable/mainTable/index.jsx +++ b/src/tabviews/commontable/mainTable/index.jsx @@ -35,9 +35,9 @@ let cell = { align: item.Align, - dataIndex: item.uuid, + dataIndex: item.field || item.uuid, title: item.label, - sorter: item.IsSort === 'true', + sorter: item.field && item.IsSort === 'true', width: item.Width || 120, render: (text, record) => { let content = '' diff --git a/src/tabviews/commontable/mainTable/index.scss b/src/tabviews/commontable/mainTable/index.scss index d71f1fc..2556ca0 100644 --- a/src/tabviews/commontable/mainTable/index.scss +++ b/src/tabviews/commontable/mainTable/index.scss @@ -14,6 +14,9 @@ .ant-table-tbody > tr.ant-table-row-selected td { background-color: #c4ebfd; } + .ant-table-tbody > tr.ant-table-row-selected:hover .ant-table-column-sort { + background-color: #c4ebfd; + } } .ant-table-body { overflow-x: auto!important; diff --git a/src/templates/comtableconfig/editcard/index.jsx b/src/templates/comtableconfig/editcard/index.jsx index 51cb8b6..bb0e5e5 100644 --- a/src/templates/comtableconfig/editcard/index.jsx +++ b/src/templates/comtableconfig/editcard/index.jsx @@ -1,6 +1,8 @@ import React, {Component} from 'react' -import { Row, Col, Icon, Radio } from 'antd' +import { Row, Col, Icon, Radio, Input } from 'antd' import './index.scss' + +const { Search } = Input class EditCardCell extends Component { constructor(props) { @@ -29,6 +31,8 @@ const { card } = this.state this.setState({ card: {...card, selected: !card.selected} + }, () => { + this.props.changeCard(this.state.card) }) } @@ -72,16 +76,29 @@ this.state = { dataSource: props.data, - type: props.type + selectCards: props.data.filter(item => item.selected), + type: props.type, + searchKey: '' } } - getSelectedCard = () => { - let box = [] - this.state.dataSource.forEach((item, index) => { - box.push(this.refs['cellCard' + index].state.card) + changeCard = (item) => { + let cards = JSON.parse(JSON.stringify(this.state.selectCards)) + let isAdd = true + cards = cards.map(card => { + if (card.field === item.field) { + isAdd = false + return item + } else { + return card + } }) - return box + if (isAdd) { + cards.push(item) + } + this.setState({ + selectCards: cards + }) } render() { @@ -89,12 +106,23 @@ return ( <div className="common-modal-edit-card"> + <Row className="search-row"> + <Col span={8}> + <Search placeholder="璇疯緭鍏ュ瓧娈靛悕" onSearch={value => {this.setState({searchKey: value})}} enterButton /> + </Col> + </Row> <Row> - {dataSource.map((item, index) => ( - <Col key={index} span={8}> - <EditCardCell ref={'cellCard' + index} type={type} card={item} /> - </Col> - ))} + {dataSource.map((item, index) => { + if (item.field.toLowerCase().indexOf(this.state.searchKey.toLowerCase()) >= 0) { + return ( + <Col key={index} span={8}> + <EditCardCell ref={'cellCard' + index} type={type} card={item} changeCard={this.changeCard} /> + </Col> + ) + } else { + return '' + } + })} </Row> </div> ) diff --git a/src/templates/comtableconfig/editcard/index.scss b/src/templates/comtableconfig/editcard/index.scss index b4cb7ce..52f6905 100644 --- a/src/templates/comtableconfig/editcard/index.scss +++ b/src/templates/comtableconfig/editcard/index.scss @@ -40,4 +40,9 @@ } } } + .search-row { + .ant-col { + padding-top: 0px; + } + } } diff --git a/src/templates/comtableconfig/index.jsx b/src/templates/comtableconfig/index.jsx index ada6e79..2bb23da 100644 --- a/src/templates/comtableconfig/index.jsx +++ b/src/templates/comtableconfig/index.jsx @@ -137,7 +137,7 @@ * 2銆佹牴鎹厤缃俊鎭腑宸蹭娇鐢ㄨ〃鑾峰彇鐩稿叧瀛楁淇℃伅 */ componentDidMount () { - let _text = "select TbName ,Remark from sDataDictionary where IsKey!='' and Deleted =0" + let _text = 'select TbName ,Remark from sDataDictionary where IsKey!=\'\' and Deleted =0' _text = Utils.formatOptions(_text) Api.getSystemConfig({func: 'sPC_Get_SelectedList', LText: _text, obj_name: 'data', arr_field: 'TbName,Remark'}).then(res => { @@ -811,6 +811,7 @@ const { menu } = this.props const { config, originMenu } = this.state this.menuformRef.handleConfirm().then(res => { + config.search = config.search.filter(item => !item.origin) if (config.search[0] && config.search[0].origin) { notification.warning({ top: 92, @@ -1073,7 +1074,7 @@ } // 鑾峰彇宸查�夊瓧娈甸泦鍚� - let cards = this.refs.searchcard.getSelectedCard() + let cards = this.refs.searchcard.state.selectCards let columnsMap = new Map() cards.forEach(card => { columnsMap.set(card.field, card) diff --git a/src/templates/comtableconfig/settingform/index.jsx b/src/templates/comtableconfig/settingform/index.jsx index da4b682..25d9a0b 100644 --- a/src/templates/comtableconfig/settingform/index.jsx +++ b/src/templates/comtableconfig/settingform/index.jsx @@ -47,6 +47,15 @@ primaryKey = '' } } + + let orderColumn = data.orderColumn + if (orderColumn) { + let field = this.props.columns.filter(column => column.field === orderColumn) + if (field.length !== 1) { + orderColumn = '' + } + } + return ( <Form {...formItemLayout} className="ant-advanced-search-form commontable-setting-form" id="commontable-setting-form"> <Row gutter={24}> @@ -131,6 +140,27 @@ )} </Form.Item> </Col> + <Col span={12}> + <Form.Item label="榛樿鎺掑簭"> + {getFieldDecorator('orderColumn', { + initialValue: orderColumn, + rules: [ + { + required: true, + message: dict['form.required.select'] + '榛樿鎺掑簭瀛楁!' + } + ] + })( + <Select + getPopupContainer={() => document.getElementById('commontable-setting-form')} + > + {this.props.columns.map(option => + <Select.Option id={option.uuid} title={option.label} key={option.uuid} value={option.field}>{option.label}</Select.Option> + )} + </Select> + )} + </Form.Item> + </Col> </Row> </Form> ) diff --git a/src/templates/comtableconfig/source.jsx b/src/templates/comtableconfig/source.jsx index d52cb61..fd7dd82 100644 --- a/src/templates/comtableconfig/source.jsx +++ b/src/templates/comtableconfig/source.jsx @@ -13,6 +13,7 @@ tableName: '', tableType: 'checkbox', primaryKey: '', + orderColumn: '', dataresource: '' }, tables: [], diff --git a/src/utils/utils.js b/src/utils/utils.js index 407b182..a312464 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -1,3 +1,5 @@ +import moment from 'moment' + export default class Utils { /** * @description 鐢熸垚32浣島uid string + 鏃堕棿 @@ -163,6 +165,66 @@ * @param {Array} searches 鎼滅储鏉′欢 * @return {String} searchText 鎷兼帴缁撴灉 */ + static mainjointsearchkey (searches) { + if (!searches || searches.length === 0) return '' + + if (searches[0].hasOwnProperty('initval')) { + let newsearches = [] + searches.forEach(search => { + let item = { + key: search.field, + match: search.match, + type: search.type, + value: search.initval + } + if (item.type === 'date') { + item.value = item.value ? moment().subtract(item.value, 'days').format('YYYY-MM-DD') : '' + } else if (item.type === 'datemonth') { + item.value = item.value ? moment().subtract(item.value, 'month').format('YYYY-MM') : '' + } else if (item.type === 'dateweek') { + item.value = item.value ? [moment().subtract(item.value * 7, 'days').startOf('week').format('YYYY-MM-DD'), + moment().subtract(item.value * 7, 'days').endOf('week').format('YYYY-MM-DD')] : '' + } else if (item.type === 'daterange') { + item.value = item.value ? [moment().subtract(item.value, 'days').format('YYYY-MM-DD'), + moment().subtract(item.value === 1 ? 1 : 0, 'days').format('YYYY-MM-DD')] : '' + } + newsearches.push(item) + }) + searches = newsearches + } + + let searchText = '' + searches.forEach(item => { + if (!item.value) return + // eslint-disable-next-line + searchText += (searchText !== '' ? ' ' + 'AND' + ' ' : '') + if (item.type === 'text' || item.type === 'select') { + // eslint-disable-next-line + let str = item.match === '=' ? '' : '%' + // eslint-disable-next-line + searchText += item.key + ' ' + item.match + ' ' + '\'' + str + item.value + str + '\'' + } else if (item.type === 'date' || item.type === 'datemonth') { + // eslint-disable-next-line + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' + } else if (item.type === 'dateweek') { + // eslint-disable-next-line + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')' + } else if (item.type === 'daterange') { + // eslint-disable-next-line + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')' + } else { + // eslint-disable-next-line + searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' + } + }) + return searchText + } + + /** + * @description 鎷兼帴鎼滅储鏉′欢 + * @param {Array} searches 鎼滅储鏉′欢 + * @return {String} searchText 鎷兼帴缁撴灉 + */ static jointsearchkey (searches) { if (!searches || searches.length === 0) return '' let searchText = '' -- Gitblit v1.8.0