jurisdiction.jsx 8.4 KB

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