roles.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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 ,Checkbox,Tabs} from 'antd';
  6. import Newrole from "./newRole.jsx"
  7. import './userMangagement.less'
  8. import {roleResources} from '../../../dataDic.js';
  9. import {ChooseList} from "../../order/orderNew/chooseList";
  10. const CheckboxGroup = Checkbox.Group;
  11. const {TabPane} = Tabs
  12. const Roles=Form.create()(React.createClass({
  13. loadData(pageNo) {
  14. this.state.data = [];
  15. this.setState({
  16. loading: true
  17. });
  18. $.ajax({
  19. method: "post",
  20. dataType: "json",
  21. crossDomain: false,
  22. url: globalConfig.context + '/api/admin/roles',
  23. data: {
  24. pageNo: pageNo || 1,
  25. pageSize: this.state.pagination.pageSize,
  26. roleName:this.state.roleNameSearch,
  27. },
  28. success: function (data) {
  29. let theArr = [];
  30. if (!data.data) {
  31. if (data.error && data.error.length) {
  32. message.warning(data.error[0].message);
  33. };
  34. } else {
  35. for (let i = 0; i < data.data.list.length; i++) {
  36. let thisdata = data.data.list[i];
  37. theArr.push({
  38. key: i,
  39. id: thisdata.id,
  40. roleName: thisdata.roleName,
  41. creater:thisdata.creater,
  42. createTime:thisdata.createTimez,
  43. });
  44. };
  45. this.setState({
  46. page: data.data.pageNo
  47. })
  48. this.state.pagination.current = data.data.pageNo;
  49. this.state.pagination.total = data.data.totalCount;
  50. };
  51. if(!data.data.list.length){
  52. this.state.pagination.current=0
  53. this.state.pagination.total=0
  54. }
  55. this.setState({
  56. dataSource: theArr,
  57. pagination: this.state.pagination,
  58. selectedRowKeys:[]
  59. });
  60. }.bind(this),
  61. }).always(function () {
  62. this.setState({
  63. loading: false
  64. });
  65. }.bind(this));
  66. },
  67. getInitialState() {
  68. return {
  69. datauser:{},
  70. selectedRowKeys: [],
  71. selectedRows: [],
  72. loading: false,
  73. page: 1,
  74. pagination: {
  75. defaultCurrent: 1,
  76. defaultPageSize: 10,
  77. showQuickJumper: true,
  78. pageSize: 10,
  79. onChange: function (page) {
  80. this.loadData(page);
  81. }.bind(this),
  82. showTotal: function (total) {
  83. return '共' + total + '条数据';
  84. }
  85. },
  86. columns: [
  87. {
  88. title: '角色名称',
  89. dataIndex: 'roleName',
  90. key: 'roleName',
  91. width:'300px'
  92. }, {
  93. title: '创建人',
  94. dataIndex: 'creater',
  95. key: 'creater',
  96. width:'300px'
  97. }, {
  98. title: '创建时间',
  99. dataIndex: 'createTime',
  100. key: 'createTime',
  101. },{
  102. title: '离职转交配置',
  103. dataIndex: 'ee',
  104. key: 'ee',
  105. render: (text, record, index) => {
  106. return <div>
  107. <Button onClick={(e) =>{ e.stopPropagation(), this.visit(record)}} type="primary">离职转交配置</Button>
  108. </div>
  109. }
  110. },
  111. ],
  112. dataSource: [],
  113. };
  114. },
  115. //进入离职权限配置
  116. visit(record) {
  117. let rid=record.id;
  118. this.state.resources=undefined;
  119. this.setState({
  120. visible2: true,
  121. rid:record.id,
  122. name:record.roleName,
  123. });
  124. this.resourcesDetail(rid);
  125. },
  126. //关闭离职配置
  127. handleCancel2(){
  128. this.setState({
  129. visible2: false
  130. });
  131. },
  132. //点击离职资源配置保存
  133. resourcesDetail(rid) {
  134. this.setState({
  135. selectedRowKeys: [],
  136. loading: true,
  137. });
  138. $.ajax({
  139. method: "POST",
  140. dataType: "json",
  141. crossDomain: false,
  142. url: globalConfig.context + "/api/admin/role/ResourcesDetail",
  143. data: {
  144. rid:rid,
  145. }
  146. }).done(function (data) {
  147. if (!data.error.length) {
  148. let resourcesData=[];
  149. for(let i=0;i<data.data.length;i++){
  150. resourcesData.push(data.data[i].resources.toString())
  151. }
  152. this.setState({
  153. loading: false,
  154. resources:resourcesData
  155. });
  156. } else {
  157. message.warning(data.error[0].message);
  158. };
  159. }.bind(this));
  160. },
  161. //点击离职资源配置保存
  162. resourcesSubmit(e) {
  163. e.preventDefault();
  164. this.setState({
  165. selectedRowKeys: [],
  166. loading: true
  167. });
  168. $.ajax({
  169. method: "POST",
  170. dataType: "json",
  171. crossDomain: false,
  172. url: globalConfig.context + "/api/admin/role/addResources",
  173. data: {
  174. rid:this.state.rid,
  175. resources:this.state.resources.join(","),
  176. }
  177. }).done(function (data) {
  178. if (!data.error.length) {
  179. message.success('配置成功!');
  180. this.setState({
  181. loading: false,
  182. visible2: false
  183. });
  184. } else {
  185. message.warning(data.error[0].message);
  186. };
  187. }.bind(this));
  188. },
  189. componentWillMount() {
  190. this.loadData();
  191. },
  192. tableRowClick(record, index) {
  193. this.state.userDetaile=true;
  194. this.state.datauser = record;
  195. this.setState({
  196. showDesc: true
  197. });
  198. },
  199. //删除
  200. delectRow() {
  201. let deletedIds = [];
  202. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  203. let rowItem = this.state.selectedRows[idx];
  204. if (rowItem.id) {
  205. deletedIds.push(rowItem.id)
  206. };
  207. };
  208. this.setState({
  209. selectedRowKeys: [],
  210. loading: true
  211. });
  212. $.ajax({
  213. method: "POST",
  214. dataType: "json",
  215. crossDomain: false,
  216. url: globalConfig.context + "/api/admin/role/delete",
  217. data: {
  218. data:JSON.stringify(
  219. deletedIds
  220. )
  221. }
  222. }).done(function (data) {
  223. if (!data.error.length) {
  224. message.success('删除成功!');
  225. this.setState({
  226. loading: false,
  227. });
  228. } else {
  229. message.warning(data.error[0].message);
  230. };
  231. this.loadData(this.state.page);
  232. }.bind(this));
  233. },
  234. addClick() {
  235. this.state.userDetaile=false;
  236. this.setState({
  237. showDesc: true
  238. });
  239. },
  240. closeDesc(e, s) {
  241. this.state.userDetaile=false;
  242. this.state.showDesc = e;
  243. if (s) {
  244. this.loadData();
  245. };
  246. },
  247. search() {
  248. this.loadData();
  249. },
  250. reset() {
  251. this.state.roleNameSearch='';
  252. this.loadData();
  253. },
  254. changeList(arr) {
  255. const newArr = [];
  256. this.state.columns.forEach(item => {
  257. arr.forEach(val => {
  258. if (val === item.title) {
  259. newArr.push(item);
  260. }
  261. });
  262. });
  263. this.setState({
  264. changeList: newArr
  265. });
  266. },
  267. render() {
  268. const rowSelection = {
  269. selectedRowKeys: this.state.selectedRowKeys,
  270. onChange: (selectedRowKeys, selectedRows) => {
  271. this.setState({
  272. selectedRows: selectedRows.slice(-1),
  273. selectedRowKeys: selectedRowKeys.slice(-1)
  274. });
  275. },
  276. onSelectAll: (selected, selectedRows, changeRows) => {
  277. this.setState({
  278. selectedRowKeys:[]
  279. })
  280. },
  281. };
  282. const hasSelected = this.state.selectedRowKeys.length > 0;
  283. const FormItem = Form.Item
  284. return (
  285. <div className="user-content" >
  286. <div className="content-title">
  287. <Tabs
  288. defaultActiveKey="1"
  289. onChange={this.callback}
  290. className="test">
  291. <TabPane tab="搜索" key="1">
  292. <div className="user-search">
  293. <Input placeholder="角色名称" style={{width:'150px'}}
  294. value={this.state.roleNameSearch}
  295. onChange={(e) => { this.setState({ roleNameSearch: e.target.value }); }} />
  296. <Button type="primary" onClick={this.search}>搜索</Button>
  297. <Button onClick={this.reset}>重置</Button>
  298. <Button type="danger"
  299. disabled={!hasSelected}
  300. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  301. </div>
  302. </TabPane>
  303. <TabPane tab="新增角色" key="2">
  304. <Button type="primary" className="addButton" style={{float:"left",marginBottom:10,marginLeft:10}} onClick={this.addClick} >新增角色<Icon type="user" /></Button>
  305. </TabPane>
  306. <TabPane tab="更改表格显示数据" key="3">
  307. <div style={{ marginLeft: 10 }}>
  308. <ChooseList
  309. columns={this.state.columns}
  310. changeFn={this.changeList}
  311. changeList={this.state.changeList}
  312. top={55}
  313. margin={11}
  314. />
  315. </div>
  316. </TabPane>
  317. </Tabs>
  318. <div className="patent-table">
  319. <Spin spinning={this.state.loading}>
  320. <Table columns={
  321. this.state.changeList
  322. ? this.state.changeList
  323. : this.state.columns
  324. }
  325. style={{
  326. cursor: 'pointer',
  327. }}
  328. dataSource={this.state.dataSource}
  329. rowSelection={rowSelection}
  330. pagination={this.state.pagination}
  331. onRowClick={this.tableRowClick} />
  332. </Spin>
  333. </div>
  334. <Newrole
  335. userDetaile={this.state.userDetaile}
  336. datauser={this.state.datauser}
  337. showDesc={this.state.showDesc}
  338. closeDesc={this.closeDesc} />
  339. </div >
  340. <div className="patent-desc">
  341. <Modal maskClosable={false} visible={this.state.visible2}
  342. onOk={this.checkResources} onCancel={this.handleCancel2}
  343. width='600px'
  344. title='离职转交配置'
  345. footer=''
  346. className="admin-desc-content">
  347. <Form horizontal onSubmit={this.resourcesSubmit} id="add-form">
  348. <Spin spinning={this.state.loading}>
  349. <FormItem
  350. labelCol={{ span: 10 }}
  351. wrapperCol={{ span: 4 }}
  352. label="角色名称"
  353. >
  354. {this.state.name}
  355. </FormItem>
  356. <FormItem
  357. labelCol={{ span: 10 }}
  358. wrapperCol={{ span: 4 }}
  359. label="请选择离职转交配置"
  360. >
  361. <CheckboxGroup options={roleResources} value={this.state.resources} onChange={(e)=>{this.setState({resources:e})}} />
  362. </FormItem>
  363. <FormItem wrapperCol={{ span: 12, offset: 7 }}>
  364. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  365. <Button className="set-submit" type="ghost" onClick={this.handleCancel2} style={{marginLeft:'100px'}}>取消</Button>
  366. </FormItem>
  367. </Spin>
  368. </Form >
  369. </Modal>
  370. </div>
  371. </div>
  372. );
  373. }
  374. }));
  375. export default Roles;