index.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-04-14 10:20:46
  6. * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import BMSPagecontainer from '@/components/BMSPageContainer';
  10. import { BMSTable } from '@/components/BMSTable';
  11. import { createFromIconfontCN } from '@ant-design/icons';
  12. import { ActionType, ProFormRadio } from '@ant-design/pro-components';
  13. import { ModalForm, ProFormCascader, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
  14. import { ProColumns } from '@ant-design/pro-table';
  15. import { Input, message, Popconfirm } from 'antd';
  16. import { useEffect, useRef, useState } from 'react'
  17. import { addData, delData, editData, getData } from './service';
  18. import './style.less';
  19. const IconFont = createFromIconfontCN({
  20. scriptUrl: '//at.alicdn.com/t/c/font_1927152_4nm5kxbv4m3.js',
  21. });
  22. export default function ParamsMana() {
  23. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  24. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  25. const tableRef = useRef<ActionType>();
  26. const columns = [
  27. {
  28. title: '参数名称',
  29. dataIndex: 'name',
  30. },
  31. {
  32. title: '参数代码',
  33. dataIndex: 'code',
  34. },
  35. {
  36. title: '描述',
  37. dataIndex: 'description',
  38. },
  39. {
  40. title: '参数值',
  41. dataIndex: 'value',
  42. },
  43. {
  44. title: '启用',
  45. dataIndex: 'status',
  46. render: (_: any, record: any) => {
  47. return _ == 1?'是':'否'
  48. }
  49. },
  50. {
  51. title: '操作',
  52. key: 'option',
  53. width: 120,
  54. valueType: 'option',
  55. render: (_: any, record: any) => {
  56. return [
  57. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  58. <Popconfirm
  59. title="是否确认删除?"
  60. key="del"
  61. onConfirm={() => delTableData(record)}
  62. >
  63. <a>删除</a>
  64. </Popconfirm>
  65. ]
  66. },
  67. },
  68. ]
  69. const getTableData = async (params: any) => {
  70. const resp = await getData(params);
  71. if (resp) {
  72. return {
  73. data: resp.list,
  74. success: true,
  75. total: resp.totalCount,
  76. pageSize: resp.pageSize,
  77. totalPage: resp.totalPage,
  78. }
  79. }
  80. return []
  81. }
  82. const delTableData = async (record: any) => {
  83. const resp = await delData(record.id);
  84. if (resp) {
  85. message.success('操作成功!');
  86. tableRef.current?.reload();
  87. // message.success('操作成功!');
  88. }
  89. }
  90. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  91. if (type == 'ADD') {
  92. const resp = await addData({ ...formVal});
  93. if (resp) {
  94. tableRef.current?.reload();
  95. message.success('操作成功!');
  96. }
  97. }
  98. if (type == 'EDIT') {
  99. const resp = await editData({ ...formVal});
  100. if (resp) {
  101. tableRef.current?.reload();
  102. message.success('操作成功!');
  103. }
  104. }
  105. return true;
  106. }
  107. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' }) => {
  108. return (
  109. <ModalForm
  110. title={`${type == 'EDIT' ? '编辑' : '新增'}参数`}
  111. width={352}
  112. initialValues={type == 'EDIT' ? { ...record } : {}}
  113. trigger={
  114. type == 'EDIT' ? <a key="edit" >编辑</a> : <span className='add'>新增</span>
  115. }
  116. onFinish={(val) => {
  117. return updateTable(type == 'EDIT'?{...record,...val}:{...val}, type);
  118. }}
  119. modalProps={{destroyOnClose:true}}
  120. colProps={{span:24}}
  121. grid
  122. >
  123. <ProFormText
  124. name="name"
  125. label="参数名称:"
  126. placeholder="请输入"
  127. rules={[{ required: true, message: '名称不能为空!' }]}
  128. />
  129. <ProFormTextArea
  130. name="description"
  131. label="描述"
  132. placeholder="请输入"
  133. rules={[{ required: true, message: '类型代码不能为空!' }]}
  134. />
  135. <ProFormText
  136. name="value"
  137. label="参数值:"
  138. placeholder="请输入"
  139. rules={[{ required: true, message: '名称不能为空!' }]}
  140. />
  141. <ProFormRadio.Group
  142. name="status"
  143. label="启用:"
  144. fieldProps={{
  145. buttonStyle: 'solid'
  146. }}
  147. options={[
  148. {
  149. label: '是',
  150. value: 1,
  151. },
  152. {
  153. label: '否',
  154. value: 0,
  155. },
  156. ]}
  157. rules={[{ required: true, message: '默认不能为空!' }]}
  158. />
  159. </ModalForm>
  160. )
  161. }
  162. const tableDataSearchHandle = (paramName: string) => {
  163. set_tableDataFilterParams({
  164. ...tableDataFilterParams,
  165. [`${paramName}`]: tableDataSearchKeywords
  166. })
  167. }
  168. useEffect(()=>{
  169. },[])
  170. return (
  171. <BMSPagecontainer className='ParamsMana' title={false}>
  172. <div className='toolBar'>
  173. <div className='filter'>
  174. <div className='filterItem'>
  175. <span className='label' style={{whiteSpace:'nowrap'}}> 检索:</span>
  176. <Input placeholder={'请输入参数名称'} allowClear
  177. suffix={
  178. <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('parameterName')} />
  179. }
  180. onChange={(e) => {
  181. set_tableDataSearchKeywords(e.target.value);
  182. if (e.target.value.length == 0) {
  183. set_tableDataFilterParams({
  184. ...tableDataFilterParams,
  185. parameterName: ''
  186. });
  187. }
  188. }}
  189. onPressEnter={(e)=>{
  190. set_tableDataFilterParams({
  191. ...tableDataFilterParams,
  192. parameterName:(e.target as HTMLInputElement).value
  193. });
  194. }}
  195. />
  196. </div>
  197. </div>
  198. <div className='btnGroup'>
  199. <UpDataActBtn record type='ADD' />
  200. </div>
  201. </div>
  202. <div style={{ marginTop: 16 }}>
  203. <BMSTable columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  204. </div>
  205. </BMSPagecontainer>
  206. )
  207. }