roles.jsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import React from 'react';
  2. import ReactDom from 'react-dom';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import { Form,Radio, Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker, Modal, Upload } from 'antd';
  6. import Newrole from "./newRole.jsx"
  7. import './userMangagement.less'
  8. import {} from '../../../dataDic.js';
  9. const Roles=Form.create()(React.createClass({
  10. loadData(pageNo) {
  11. this.state.data = [];
  12. this.setState({
  13. loading: true
  14. });
  15. $.ajax({
  16. method: "post",
  17. dataType: "json",
  18. crossDomain: false,
  19. url: globalConfig.context + '/api/admin/roles',
  20. data: {
  21. pageNo: pageNo || 1,
  22. pageSize: this.state.pagination.pageSize,
  23. roleName:this.state.roleNameSearch,
  24. },
  25. success: function (data) {
  26. let theArr = [];
  27. if (!data.data) {
  28. if (data.error && data.error.length) {
  29. message.warning(data.error[0].message);
  30. };
  31. } else {
  32. for (let i = 0; i < data.data.list.length; i++) {
  33. let thisdata = data.data.list[i];
  34. theArr.push({
  35. key: i,
  36. id: thisdata.id,
  37. roleName: thisdata.roleName,
  38. creater:thisdata.creater,
  39. createTime:thisdata.createTimez,
  40. });
  41. };
  42. this.state.pagination.current = data.data.pageNo;
  43. this.state.pagination.total = data.data.totalCount;
  44. };
  45. this.setState({
  46. dataSource: theArr,
  47. pagination: this.state.pagination,
  48. selectedRowKeys:[]
  49. });
  50. }.bind(this),
  51. }).always(function () {
  52. this.setState({
  53. loading: false
  54. });
  55. }.bind(this));
  56. },
  57. getInitialState() {
  58. return {
  59. datauser:{},
  60. selectedRowKeys: [],
  61. selectedRows: [],
  62. loading: false,
  63. pagination: {
  64. defaultCurrent: 1,
  65. defaultPageSize: 10,
  66. showQuickJumper: true,
  67. pageSize: 10,
  68. onChange: function (page) {
  69. this.loadData(page);
  70. }.bind(this),
  71. showTotal: function (total) {
  72. return '共' + total + '条数据';
  73. }
  74. },
  75. columns: [
  76. {
  77. title: '角色名称',
  78. dataIndex: 'roleName',
  79. key: 'roleName',
  80. width:'300px'
  81. }, {
  82. title: '创建人',
  83. dataIndex: 'creater',
  84. key: 'creater',
  85. width:'300px'
  86. }, {
  87. title: '创建时间',
  88. dataIndex: 'createTime',
  89. key: 'createTime',
  90. }
  91. ],
  92. dataSource: [],
  93. };
  94. },
  95. componentWillMount() {
  96. this.loadData();
  97. },
  98. tableRowClick(record, index) {
  99. this.state.userDetaile=true;
  100. this.state.datauser = record;
  101. this.setState({
  102. showDesc: true
  103. });
  104. },
  105. //删除
  106. delectRow() {
  107. let deletedIds = [];
  108. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  109. let rowItem = this.state.selectedRows[idx];
  110. if (rowItem.id) {
  111. deletedIds.push(rowItem.id)
  112. };
  113. };
  114. this.setState({
  115. selectedRowKeys: [],
  116. loading: true
  117. });
  118. $.ajax({
  119. method: "POST",
  120. dataType: "json",
  121. crossDomain: false,
  122. url: globalConfig.context + "/api/admin/role/delete",
  123. data: {
  124. data:JSON.stringify(
  125. deletedIds
  126. )
  127. }
  128. }).done(function (data) {
  129. if (!data.error.length) {
  130. message.success('删除成功!');
  131. this.setState({
  132. loading: false,
  133. });
  134. } else {
  135. message.warning(data.error[0].message);
  136. };
  137. this.loadData();
  138. }.bind(this));
  139. },
  140. addClick() {
  141. this.state.userDetaile=false;
  142. this.setState({
  143. showDesc: true
  144. });
  145. },
  146. closeDesc(e, s) {
  147. this.state.userDetaile=false;
  148. this.state.showDesc = e;
  149. if (s) {
  150. this.loadData();
  151. };
  152. },
  153. search() {
  154. this.loadData();
  155. },
  156. reset() {
  157. this.state.roleNameSearch='';
  158. this.loadData();
  159. },
  160. render() {
  161. const rowSelection = {
  162. selectedRowKeys: this.state.selectedRowKeys,
  163. onChange: (selectedRowKeys, selectedRows) => {
  164. this.setState({
  165. selectedRows: selectedRows.slice(-1),
  166. selectedRowKeys: selectedRowKeys.slice(-1)
  167. });
  168. },
  169. onSelectAll: (selected, selectedRows, changeRows) => {
  170. this.setState({
  171. selectedRowKeys:[]
  172. })
  173. },
  174. };
  175. const hasSelected = this.state.selectedRowKeys.length > 0;
  176. return (
  177. <div className="user-content" >
  178. <div className="content-title">
  179. <div className="user-search">
  180. <Input placeholder="角色名称" style={{width:'150px'}}
  181. value={this.state.roleNameSearch}
  182. onChange={(e) => { this.setState({ roleNameSearch: e.target.value }); }} />
  183. <Button type="primary" onClick={this.search}>搜索</Button>
  184. <Button onClick={this.reset}>重置</Button>
  185. <Button type="danger"
  186. disabled={!hasSelected}
  187. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  188. <Button type="primary" className="addButton" onClick={this.addClick} >新增用户<Icon type="user" /></Button>
  189. </div>
  190. <div className="patent-table">
  191. <Spin spinning={this.state.loading}>
  192. <Table columns={this.state.columns}
  193. dataSource={this.state.dataSource}
  194. rowSelection={rowSelection}
  195. pagination={this.state.pagination}
  196. onRowClick={this.tableRowClick} />
  197. </Spin>
  198. </div>
  199. <Newrole
  200. userDetaile={this.state.userDetaile}
  201. datauser={this.state.datauser}
  202. showDesc={this.state.showDesc}
  203. closeDesc={this.closeDesc} />
  204. </div >
  205. </div>
  206. );
  207. }
  208. }));
  209. export default Roles;