newPermission.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import React, { Component } from 'react';
  2. import {Button, message} from "antd";
  3. import ProForm, {
  4. ModalForm,
  5. ProFormText,
  6. ProFormDateRangePicker,
  7. ProFormSelect,
  8. } from '@ant-design/pro-form';
  9. import {
  10. addSupPermission,
  11. addPermission,
  12. } from '../services/API';
  13. import {
  14. urlType
  15. } from '@/utils/dataDic';
  16. class NewPermission extends Component{
  17. constructor(props) {
  18. super(props);
  19. this.newPermission = this.newPermission.bind(this);
  20. this.addNewPermission = this.addNewPermission.bind(this);
  21. }
  22. // 添加导航权限
  23. newPermission= async(values) => {
  24. const msg = await addSupPermission(values);
  25. if(msg.error.length === 0){
  26. message.success('新增成功');
  27. this.props.tableRef.current.reload();// 刷新列表
  28. this.props.onCancel();
  29. }else{
  30. message.warning(msg.error[0].message);
  31. }
  32. }
  33. // 添加导航下级权限
  34. addNewPermission= async(values) => {
  35. const msg = await addPermission({...values,superId:this.props.superData.name});
  36. if(msg.error.length === 0){
  37. message.success('新增成功');
  38. this.props.tableRef.current.reload();// 刷新列表
  39. this.props.onCancel();
  40. }else{
  41. message.warning(msg.error[0].message);
  42. }
  43. }
  44. render() {
  45. return (
  46. <ModalForm
  47. preserve={false}
  48. visible={this.props.visible}
  49. title={this.props.superData ? "新建下级权限模板":"新建权限"}
  50. initialValues={this.props.superData ? null : {
  51. type: 0// 导航级别
  52. }}
  53. modalProps={{
  54. onCancel: (e) => {e.stopPropagation();this.props.onCancel && this.props.onCancel();},
  55. }}
  56. onFinish={this.props.superData ? this.addNewPermission : this.newPermission}
  57. >
  58. <ProForm.Group>
  59. <ProFormText
  60. rules={
  61. [{
  62. required: true,
  63. message: '请输入接口名称!',
  64. }]
  65. }
  66. width="xl"
  67. name="name"
  68. label="接口名称:"
  69. placeholder="请输入名称"
  70. />
  71. </ProForm.Group>
  72. <ProForm.Group>
  73. <ProFormText
  74. rules={
  75. [{
  76. required: true,
  77. message: '请输入接口路径'
  78. }]
  79. }
  80. width="xl"
  81. name="url"
  82. label="接口路径:"
  83. placeholder="请输入接口路径"
  84. />
  85. </ProForm.Group>
  86. <ProForm.Group>
  87. <ProFormSelect
  88. rules={[
  89. {
  90. required:true,
  91. message:'请选择接口类型'
  92. }
  93. ]}
  94. width="xl"
  95. name="type"
  96. label="接口类型:"
  97. placeholder="请选择接口类型"
  98. disabled={!this.props.superData}
  99. request={async () => urlType}
  100. />
  101. </ProForm.Group>
  102. {this.props.superData && <ProForm.Group>
  103. <span>上级功能模块:</span>
  104. <span>{this.props.superData.name}</span>
  105. </ProForm.Group>}
  106. </ModalForm>
  107. );
  108. }
  109. }
  110. export default NewPermission