datasource.jsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import React from 'react'
  2. import { Tabs, Input, Button, Table, Icon, Tag, Menu, Dropdown } from 'antd'
  3. const { TabPane } = Tabs
  4. const { Search } = Input
  5. import { connect } from 'dva'
  6. import { Link } from 'react-router-dom'
  7. import DataSourceBox from './dataSourceBox'
  8. import dataSource from '../../models/dataSource'
  9. import './dataSource.less'
  10. class DataSource extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. operation: 'create', // 打开数据编辑界面的类型
  15. visibleBox: false, // 数据编辑界面显示标识
  16. selectedCode: -1, // 当前选中的table行code
  17. filterDropdownVisible: false,
  18. search: {} // 搜索条件
  19. }
  20. };
  21. showDataSourceBox = (o) => {
  22. this.setState({
  23. operation: o,
  24. visibleBox: true
  25. });
  26. }
  27. hideBox = () => {
  28. this.setState({
  29. visibleBox: false
  30. });
  31. }
  32. onInputChange = (name, value) => {
  33. const { search } = this.state;
  34. let newSearch = Object.assign({}, search );
  35. newSearch[name] = value;
  36. this.setState({ search: newSearch });
  37. }
  38. onSearch = () => {
  39. const { search } = this.state;
  40. const reg = new RegExp(search.name, 'gi');
  41. this.setState({
  42. filterDropdownVisible: false
  43. });
  44. }
  45. render() {
  46. const { dataSource, dispatch } = this.props;
  47. const { search, visibleBox, operation, selectedCode } = this.state;
  48. console.log(dataSource.list);
  49. const moreOperatingMenu = (
  50. <Menu className='operationmenu'>
  51. <Menu.Item
  52. onClick={(e) => {
  53. let selectedModel = dataSource.list.find((i) => { return i.code == selectedCode })
  54. dispatch({ type: 'dataSource/setNewModel', model: selectedModel });
  55. this.showDataSourceBox('edit');
  56. }}>
  57. <Icon type="info-circle-o" />属性设置
  58. </Menu.Item>
  59. <Menu.Item>
  60. {/* <Link to='/dataSource/1111'> */}
  61. <Icon type="home" /><Icon type="table" />数据列设置
  62. {/* </Link> */}
  63. </Menu.Item>
  64. <Menu.Item><Icon type="search" />预览数据</Menu.Item>
  65. <Menu.Item><Icon type="lock" />权限设置</Menu.Item>
  66. <Menu.Divider />
  67. <Menu.Item
  68. onClick={(e) => {
  69. let selectedModel = dataSource.list.find((i) => { return i.code == selectedCode })
  70. dispatch({ type: 'dataSource/delete', model: selectedModel });
  71. }}
  72. ><Icon type="delete" />删除</Menu.Item>
  73. </Menu>
  74. );
  75. const columns = [{
  76. title: '名称',
  77. dataIndex: 'name',
  78. key: 'name',
  79. width: 100,
  80. sorter: (a, b) => a.name.localeCompare(b.name, 'zh-Hans-CN', {sensitivity: 'accent'}),
  81. filterDropdown: (
  82. <div className="custom-filter-dropdown">
  83. <Input
  84. ref={ele => this.searchInput = ele}
  85. placeholder="Search name"
  86. value={this.state.search.name}
  87. onChange={(e) => { this.onInputChange('name', e.target.value) }}
  88. onPressEnter={this.onSearch}
  89. />
  90. <Button type="primary" onClick={this.onSearch}>Search</Button>
  91. </div>
  92. ),
  93. className: `column-${this.state.search.name?'filtered':'nofiltered'}`,
  94. filterIcon: <Icon type="smile-o"/>,
  95. filterDropdownVisible: this.state.filterDropdownVisible,
  96. onFilterDropdownVisibleChange: (visible) => {
  97. this.setState({
  98. filterDropdownVisible: visible,
  99. }, () => this.searchInput && this.searchInput.focus());
  100. },
  101. render: (text, record) => {
  102. return <div className='datasource-name'>
  103. <div className={`datasource-type type-${record.type.key}`}></div>
  104. <div>{text}</div>
  105. </div>
  106. }
  107. }, {
  108. title: '标签',
  109. dataIndex: 'tags',
  110. key: 'tag',
  111. width: 150,
  112. render: (text, record) => {
  113. text=text.join(',');
  114. let tags = text ? text.split(',').map((t, i) => {
  115. return <Tag className='datasource-tag' key={i}>{t}</Tag>
  116. }) : '';
  117. return (<div>
  118. {tags}
  119. </div>)
  120. }
  121. }, {
  122. title: '说明',
  123. dataIndex: 'description',
  124. key: 'description',
  125. width: 200
  126. }, {
  127. title: '创建人',
  128. dataIndex: 'creator',
  129. key: 'creator',
  130. width: 100
  131. }, {
  132. title: '创建时间',
  133. dataIndex: 'createTime',
  134. key: 'createTime',
  135. render: (text, record) => text.format('yyyy-MM-dd hh:mm:ss'),
  136. width: 100
  137. }, {
  138. title: '图表',
  139. dataIndex: 'chartSum',
  140. key: 'chartSum',
  141. width: 80
  142. }, {
  143. title: '操作',
  144. key: 'action',
  145. render: (text, record, index) => (
  146. <Dropdown code={record.code} overlay={moreOperatingMenu} trigger={['click']} >
  147. <Icon type="setting" />
  148. </Dropdown>
  149. ),
  150. width: 80
  151. }];
  152. const data = [{
  153. key: '1',
  154. name: '销售数据',
  155. type: 'oracle',
  156. tag: '销售,常常常常文本',
  157. description: '这是一个测试数据',
  158. creator: 'zhuth',
  159. createTime: new Date('2018-07-01 08:33:18').format('yyyy-MM-dd hh:mm:ss'),
  160. chartSum: 9
  161. }, {
  162. key: '2',
  163. name: '采购数据',
  164. type: 'sqlserver',
  165. tag: '采购',
  166. description: '这是一个测试数据',
  167. creator: 'zhuth',
  168. createTime: new Date('2018-07-04 10:38:29').format('yyyy-MM-dd hh:mm:ss'),
  169. chartSum: 7
  170. }];
  171. return (
  172. <Tabs
  173. className='datasource-tabs'
  174. type="card"
  175. defaultActiveKey="1"
  176. tabBarExtraContent={
  177. <div className='datasource-tabs-tools'>
  178. <Button onClick={()=>{
  179. dispatch({type: 'dataSource/testData'});
  180. }}>测试数据</Button>
  181. <Search
  182. placeholder="请输入关键字"
  183. onSearch={value => console.log(value)}
  184. />
  185. <Button onClick={() => {
  186. dispatch({ type: 'dataSource/resetNewModel' });
  187. this.showDataSourceBox('create')}
  188. }>
  189. {/* <Link to='./'> */}
  190. <Icon type="plus" />添加数据源
  191. {/* </Link> */}
  192. </Button>
  193. <DataSourceBox operation={operation} visibleBox={visibleBox} hideBox={this.hideBox} />
  194. </div>
  195. }
  196. >
  197. <TabPane className='datasource-tab public-datasource' tab="公共数据源" key="1" >
  198. <Table
  199. className='datasource-table public-datasource-table'
  200. columns={columns}
  201. dataSource={dataSource.list}
  202. loading={false}
  203. size='small'
  204. scroll={{x: false, y: 471}} // TODO 需要计算
  205. pagination={false}
  206. onRow={(record) => {
  207. return {
  208. onClick: () => {this.setState({ selectedCode: record.code})}
  209. }
  210. }}
  211. />
  212. </TabPane>
  213. <TabPane className='datasource-tab my-datasource' tab="我的数据源" key="2" >
  214. <Table
  215. className='datasource-table my-datasource-table'
  216. columns={columns}
  217. dataSource={dataSource.my}
  218. loading={false}
  219. size='small'
  220. />
  221. </TabPane>
  222. </Tabs>
  223. )
  224. }
  225. }
  226. function mapStateToProps({present: {dataSource}}) {
  227. return { dataSource }
  228. }
  229. export default connect(mapStateToProps)(DataSource)