roles.jsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. if(!data.data.list.length){
  46. this.state.pagination.current=0
  47. this.state.pagination.total=0
  48. }
  49. this.setState({
  50. dataSource: theArr,
  51. pagination: this.state.pagination,
  52. selectedRowKeys:[]
  53. });
  54. }.bind(this),
  55. }).always(function () {
  56. this.setState({
  57. loading: false
  58. });
  59. }.bind(this));
  60. },
  61. getInitialState() {
  62. return {
  63. datauser:{},
  64. selectedRowKeys: [],
  65. selectedRows: [],
  66. loading: false,
  67. pagination: {
  68. defaultCurrent: 1,
  69. defaultPageSize: 10,
  70. showQuickJumper: true,
  71. pageSize: 10,
  72. onChange: function (page) {
  73. this.loadData(page);
  74. }.bind(this),
  75. showTotal: function (total) {
  76. return '共' + total + '条数据';
  77. }
  78. },
  79. columns: [
  80. {
  81. title: '角色名称',
  82. dataIndex: 'roleName',
  83. key: 'roleName',
  84. width:'300px'
  85. }, {
  86. title: '创建人',
  87. dataIndex: 'creater',
  88. key: 'creater',
  89. width:'300px'
  90. }, {
  91. title: '创建时间',
  92. dataIndex: 'createTime',
  93. key: 'createTime',
  94. }
  95. ],
  96. dataSource: [],
  97. };
  98. },
  99. componentWillMount() {
  100. this.loadData();
  101. },
  102. tableRowClick(record, index) {
  103. this.state.userDetaile=true;
  104. this.state.datauser = record;
  105. this.setState({
  106. showDesc: true
  107. });
  108. },
  109. //删除
  110. delectRow() {
  111. let deletedIds = [];
  112. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  113. let rowItem = this.state.selectedRows[idx];
  114. if (rowItem.id) {
  115. deletedIds.push(rowItem.id)
  116. };
  117. };
  118. this.setState({
  119. selectedRowKeys: [],
  120. loading: true
  121. });
  122. $.ajax({
  123. method: "POST",
  124. dataType: "json",
  125. crossDomain: false,
  126. url: globalConfig.context + "/api/admin/role/delete",
  127. data: {
  128. data:JSON.stringify(
  129. deletedIds
  130. )
  131. }
  132. }).done(function (data) {
  133. if (!data.error.length) {
  134. message.success('删除成功!');
  135. this.setState({
  136. loading: false,
  137. });
  138. } else {
  139. message.warning(data.error[0].message);
  140. };
  141. this.loadData();
  142. }.bind(this));
  143. },
  144. addClick() {
  145. this.state.userDetaile=false;
  146. this.setState({
  147. showDesc: true
  148. });
  149. },
  150. closeDesc(e, s) {
  151. this.state.userDetaile=false;
  152. this.state.showDesc = e;
  153. if (s) {
  154. this.loadData();
  155. };
  156. },
  157. search() {
  158. this.loadData();
  159. },
  160. reset() {
  161. this.state.roleNameSearch='';
  162. this.loadData();
  163. },
  164. render() {
  165. const rowSelection = {
  166. selectedRowKeys: this.state.selectedRowKeys,
  167. onChange: (selectedRowKeys, selectedRows) => {
  168. this.setState({
  169. selectedRows: selectedRows.slice(-1),
  170. selectedRowKeys: selectedRowKeys.slice(-1)
  171. });
  172. },
  173. onSelectAll: (selected, selectedRows, changeRows) => {
  174. this.setState({
  175. selectedRowKeys:[]
  176. })
  177. },
  178. };
  179. const hasSelected = this.state.selectedRowKeys.length > 0;
  180. return (
  181. <div className="user-content" >
  182. <div className="content-title">
  183. <div className="user-search">
  184. <Input placeholder="角色名称" style={{width:'150px'}}
  185. value={this.state.roleNameSearch}
  186. onChange={(e) => { this.setState({ roleNameSearch: e.target.value }); }} />
  187. <Button type="primary" onClick={this.search}>搜索</Button>
  188. <Button onClick={this.reset}>重置</Button>
  189. <Button type="danger"
  190. disabled={!hasSelected}
  191. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  192. <Button type="primary" className="addButton" onClick={this.addClick} >新增用户<Icon type="user" /></Button>
  193. </div>
  194. <div className="patent-table">
  195. <Spin spinning={this.state.loading}>
  196. <Table columns={this.state.columns}
  197. dataSource={this.state.dataSource}
  198. rowSelection={rowSelection}
  199. pagination={this.state.pagination}
  200. onRowClick={this.tableRowClick} />
  201. </Spin>
  202. </div>
  203. <Newrole
  204. userDetaile={this.state.userDetaile}
  205. datauser={this.state.datauser}
  206. showDesc={this.state.showDesc}
  207. closeDesc={this.closeDesc} />
  208. </div >
  209. </div>
  210. );
  211. }
  212. }));
  213. export default Roles;