jurisdiction.jsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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, Popconfirm, Spin, Table, Switch, message, DatePicker, Modal, Upload } from 'antd';
  6. import Addjurisdiction from "./addjurisdiction.jsx"
  7. import './userMangagement.less'
  8. import { techAuditStatusList, station, post,urlType } from '../../../dataDic.js';
  9. const Jurisdiction = 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/permissions',
  20. success: function(data) {
  21. console.log(data)
  22. if(!data.data || !data.data.one) {
  23. if(data.error && data.error.length) {
  24. message.warning(data.error[0].message);
  25. };
  26. } else {
  27. this.setState({
  28. dataSource: data.data.one,
  29. });
  30. }
  31. }.bind(this),
  32. }).always(function() {
  33. this.setState({
  34. loading: false
  35. });
  36. }.bind(this));
  37. },
  38. getInitialState() {
  39. return {
  40. datauser: {},
  41. selectedRowKeys: [],
  42. selectedRows: [],
  43. loading: false,
  44. addnextVisible: false,
  45. columns: [{
  46. title: '接口名称',
  47. dataIndex: 'name',
  48. key: 'name',
  49. width: '400px'
  50. }, {
  51. title: '接口路径',
  52. dataIndex: 'url',
  53. key: 'url',
  54. }, {
  55. title: '操作',
  56. dataIndex: 'id',
  57. key: 'id',
  58. render: (text, recard) => {
  59. return(
  60. <div>
  61. {recard.url.indexOf('.html#')<=0&&<Button type="primary" onClick={(e)=>{e.stopPropagation(),this.addNextURL(recard)}} style={{marginRight:'15px'}}>新建下级权限</Button>}
  62. <Popconfirm
  63. title={"是否真的删除?"}
  64. onConfirm={(e)=>{this.delectRow(recard)}}
  65. okText="确认"
  66. cancelText="取消"
  67. placement="topLeft">
  68. <Button type="danger" onClick={(e)=>{e.stopPropagation()}}>删除</Button>
  69. </Popconfirm>
  70. </div>
  71. )
  72. }
  73. }],
  74. dataSource: [],
  75. };
  76. },
  77. componentWillMount() {
  78. this.loadData();
  79. },
  80. tableRowClick(record, index) {
  81. this.state.userDetaile = true;
  82. this.state.datauser = record;
  83. this.setState({
  84. ids:record.id,
  85. showDesc: true
  86. });
  87. },
  88. //删除(已改接口)
  89. delectRow(ids) {
  90. this.setState({
  91. loading: true
  92. });
  93. $.ajax({
  94. method: "POST",
  95. dataType: "json",
  96. crossDomain: false,
  97. url: globalConfig.context + "/api/admin/deleteById",
  98. data: {
  99. id: ids.id
  100. }
  101. }).done(function(data) {
  102. if(!data.error.length) {
  103. message.success('删除成功!');
  104. this.setState({
  105. loading: false,
  106. });
  107. } else {
  108. message.warning(data.error[0].message);
  109. };
  110. this.loadData();
  111. }.bind(this));
  112. },
  113. addClick() {
  114. this.state.userDetaile = false;
  115. this.setState({
  116. showDesc: true
  117. });
  118. },
  119. closeDesc(e, s) {
  120. this.state.userDetaile = false;
  121. this.state.showDesc = e;
  122. if(s) {
  123. this.loadData();
  124. };
  125. },
  126. //新建下级
  127. addNext() {
  128. this.setState({
  129. addnextVisible: false
  130. })
  131. },
  132. nextCancel() {
  133. this.setState({
  134. addnextVisible: false
  135. })
  136. },
  137. addNextURL(e) {
  138. this.state.name = '';
  139. this.state.url = '';
  140. this.state.urlType = undefined;
  141. this.setState({
  142. ids: e.id,
  143. preName: e.name,
  144. addnextVisible: true
  145. })
  146. },
  147. //项目任务旧数据处理
  148. handles(){
  149. this.setState({
  150. loading: true
  151. });
  152. $.ajax({
  153. method: "get",
  154. dataType: "json",
  155. crossDomain: false,
  156. url: globalConfig.context + "/api/admin/order/addContractTaskLog",
  157. data: {
  158. },
  159. success: function(data) {
  160. }.bind(this),
  161. }).always(function() {
  162. this.setState({
  163. loading: false
  164. });
  165. }.bind(this));
  166. },
  167. //新建二级接口保存
  168. nextSubmit(e) {
  169. e.preventDefault();
  170. this.setState({
  171. loading: true
  172. });
  173. $.ajax({
  174. method: "POST",
  175. dataType: "json",
  176. crossDomain: false,
  177. url: globalConfig.context + '/api/admin/addPermission',
  178. data: {
  179. superId: this.state.preName,
  180. name: this.state.name, //接口名称
  181. type:this.state.urlType,//接口类型
  182. url: this.state.url //接口路径
  183. }
  184. }).done(function(data) {
  185. this.setState({
  186. loading: false
  187. });
  188. if(!data.error.length) {
  189. message.success('保存成功!');
  190. this.addNext();
  191. this.loadData();
  192. } else {
  193. message.warning(data.error[0].message);
  194. }
  195. }.bind(this));
  196. },
  197. render() {
  198. const FormItem = Form.Item;
  199. const formItemLayout = {
  200. labelCol: { span: 8 },
  201. wrapperCol: { span: 14 },
  202. };
  203. const hasSelected = this.state.selectedRowKeys.length > 0;
  204. return(
  205. <div className="user-content" >
  206. <div className="content-title">
  207. <div className="user-search">
  208. <Button type="primary" onClick={this.handles} style={{marginLeft:'10px',float:'right'}}>项目任务数据处理</Button>
  209. <Button type="primary" className="addButton" onClick={this.addClick} style={{marginBottom:'15px'}}>新增权限<Icon type="user"/></Button>
  210. </div>
  211. <div className="patent-table">
  212. <Spin spinning={this.state.loading}>
  213. <Table columns={this.state.columns}
  214. dataSource={this.state.dataSource}
  215. pagination={false}
  216. onRowClick={this.tableRowClick} />
  217. </Spin>
  218. </div>
  219. <Addjurisdiction
  220. userDetaile={this.state.userDetaile}
  221. datauser={this.state.datauser}
  222. showDesc={this.state.showDesc}
  223. closeDesc={this.closeDesc} />
  224. </div >
  225. <Modal maskClosable={false} visible={this.state.addnextVisible}
  226. onOk={this.addNext} onCancel={this.nextCancel}
  227. width='600px'
  228. title='新建下级权限模块'
  229. footer=''
  230. className="admin-desc-content">
  231. <Form layout="horizontal" onSubmit={this.nextSubmit} id="demand-form">
  232. <Spin spinning={this.state.loading}>
  233. <div className="clearfix">
  234. <FormItem className="half-middle"
  235. {...formItemLayout}
  236. label="接口名称" >
  237. <Input placeholder="接口名称" value={this.state.name} style={{width:'230px'}}
  238. onChange={(e)=>{this.setState({name:e.target.value})}} required="required"/>
  239. <span className="mandatory">*</span>
  240. </FormItem>
  241. <FormItem className="half-middle"
  242. {...formItemLayout}
  243. label="接口路径" >
  244. <Input placeholder="接口路径" value={this.state.url} style={{width:'230px'}}
  245. onChange={(e)=>{this.setState({url:e.target.value})}} required="required"/>
  246. <span className="mandatory">*</span>
  247. </FormItem>
  248. <FormItem className="half-middle"
  249. {...formItemLayout}
  250. label="接口类型" >
  251. <Select placeholder="选择接口类型" style={{width:'230px'}}
  252. value={this.state.urlType}
  253. onChange={(e) => { this.setState({ urlType: e }) }}>
  254. {
  255. urlType.map(function (item) {
  256. return <Select.Option key={item.value} >{item.key}</Select.Option>
  257. })
  258. }
  259. </Select>
  260. <span className="mandatory">*</span>
  261. </FormItem>
  262. <FormItem className="half-middle"
  263. {...formItemLayout}
  264. label="上级功能模块" >
  265. <span>{this.state.preName}</span>
  266. </FormItem>
  267. </div>
  268. <FormItem wrapperCol={{ span: 12, offset: 4 }} className="half-middle">
  269. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  270. <Button className="set-submit" type="ghost" onClick={this.nextCancel}>取消</Button>
  271. </FormItem>
  272. </Spin>
  273. </Form >
  274. </Modal>
  275. </div>
  276. );
  277. }
  278. }));
  279. export default Jurisdiction;