index.tsx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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-11 19:51:04
  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, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
  13. import { ModalForm, ProFormDependency, ProFormDigit, ProFormSelect } 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 { getClolumnTableData, getReportColumn } from '../reportSetting/service';
  18. import { addData, delData, editData, getSqlListTableData, getSqlTypeList } from './service';
  19. import './style.less';
  20. const IconFont = createFromIconfontCN({
  21. scriptUrl: '//at.alicdn.com/t/c/font_1927152_4nm5kxbv4m3.js',
  22. });
  23. export default function DiySqlMana() {
  24. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  25. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  26. const tableRef = useRef<ActionType>();
  27. const columns: ProColumns[] = [
  28. {
  29. title: 'SQL代码',
  30. dataIndex: 'sqlCode',
  31. },
  32. {
  33. title: 'SQL语句',
  34. dataIndex: 'sql',
  35. },
  36. {
  37. title: 'SQL说明',
  38. dataIndex: 'sqlDefinition',
  39. // render:(_:any)=>_ == 1?'指标':'自定义SQL'
  40. },
  41. {
  42. title: 'SQL类型',
  43. dataIndex: 'sqlTypeName',
  44. },
  45. {
  46. title: '序号',
  47. dataIndex: 'sort',
  48. },
  49. {
  50. title: '操作',
  51. key: 'option',
  52. width: 120,
  53. valueType: 'option',
  54. render: (_: any, record: any) => {
  55. return [
  56. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  57. <Popconfirm
  58. title="是否确认删除?"
  59. key="del"
  60. onConfirm={() => delTableData(record)}
  61. >
  62. <a>删除</a>
  63. </Popconfirm>
  64. ]
  65. },
  66. },
  67. ]
  68. const getTableData = async (params: any) => {
  69. const resp = await getSqlListTableData(params);
  70. if (resp) {
  71. return {
  72. data: resp.list,
  73. success: true,
  74. total: resp.totalCount,
  75. pageSize: resp.pageSize,
  76. totalPage: resp.totalPage,
  77. }
  78. }
  79. return []
  80. }
  81. const delTableData = async (record: any) => {
  82. const resp = await delData(record.id);
  83. if (resp) {
  84. message.success('操作成功!');
  85. tableRef.current?.reload();
  86. // message.success('操作成功!');
  87. }
  88. }
  89. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  90. if (type == 'ADD') {
  91. const resp = await addData({
  92. sqlCode: formVal.sqlCode,
  93. sql: formVal.sql,
  94. sqlDefinition: formVal.sqlDefinition,
  95. sqlType: formVal.sqlType.value,
  96. sort: formVal.sort
  97. });
  98. if (resp) {
  99. tableRef.current?.reload();
  100. message.success('操作成功!');
  101. }
  102. }
  103. if (type == 'EDIT') {
  104. const resp = await editData({
  105. id: formVal.id,
  106. sql: formVal.sql,
  107. sqlDefinition: formVal.sqlDefinition,
  108. sqlType: formVal.sqlType,
  109. sort: formVal.sort
  110. });
  111. if (resp) {
  112. tableRef.current?.reload();
  113. message.success('操作成功!');
  114. }
  115. }
  116. return true;
  117. }
  118. const formRef = useRef();
  119. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' }) => {
  120. return (
  121. <ModalForm
  122. title={`${type == 'EDIT' ? '编辑' : '新增'}报表列`}
  123. width={352}
  124. formRef={formRef}
  125. initialValues={type == 'EDIT' ? { ...record } : {}}
  126. trigger={
  127. type == 'EDIT' ? <a key="edit" >编辑</a> : <span className='add'>新增</span>
  128. }
  129. onFinish={(val) => {
  130. return updateTable(type == 'EDIT' ? { ...record, ...val } : { ...val }, type);
  131. }}
  132. colProps={{ span: 24 }}
  133. grid
  134. >
  135. {
  136. type != 'EDIT' && (
  137. <ProFormText
  138. name="sqlCode"
  139. label="SQL代码:"
  140. placeholder="请输入"
  141. rules={[{ required: true, message: '列名称不能为空!' }]}
  142. />
  143. )
  144. }
  145. <ProFormTextArea placeholder="请输入" name={'sql'} label='SQL语句:' rules={[{ required: true, message: 'SQL不能为空!' }]} />
  146. <ProFormTextArea placeholder="请输入" name={'sqlDefinition'} label='SQL说明:' rules={[{ required: true, message: '说明不能为空!' }]} />
  147. <ProFormSelect
  148. name="sqlType"
  149. label="SQL类型:"
  150. placeholder="请选择"
  151. request={async () => {
  152. const resp = await getSqlTypeList();
  153. if (resp) {
  154. return resp.list.map((a: any) => ({ label: a.name, value: a.code }))
  155. }
  156. }}
  157. fieldProps={{
  158. labelInValue: true
  159. }}
  160. rules={[{ required: true, message: '类型不能为空!' }]}
  161. />
  162. <ProFormDigit
  163. name="sort"
  164. label="顺序号:"
  165. placeholder="请输入"
  166. rules={[{ required: true, message: '顺序号不能为空!' }]}
  167. />
  168. </ModalForm>
  169. )
  170. }
  171. const tableDataSearchHandle = (paramName: string) => {
  172. set_tableDataFilterParams({
  173. ...tableDataFilterParams,
  174. [`${paramName}`]: tableDataSearchKeywords
  175. })
  176. }
  177. useEffect(() => {
  178. }, [])
  179. return (
  180. <BMSPagecontainer className='DiySqlMana' title={false}>
  181. <div className='toolBar'>
  182. <div className='filter'>
  183. <div className='filterItem'>
  184. <span className='label' style={{ whiteSpace: 'nowrap' }}> 检索:</span>
  185. <Input placeholder={'请输入SQL类型'} allowClear
  186. suffix={
  187. <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('sqlType')} />
  188. }
  189. onChange={(e) => {
  190. set_tableDataSearchKeywords(e.target.value);
  191. if (e.target.value.length == 0) {
  192. set_tableDataFilterParams({
  193. ...tableDataFilterParams,
  194. sqlType: ''
  195. });
  196. }
  197. }}
  198. onPressEnter={(e) => {
  199. set_tableDataFilterParams({
  200. ...tableDataFilterParams,
  201. sqlType: (e.target as HTMLInputElement).value
  202. });
  203. }}
  204. />
  205. </div>
  206. </div>
  207. <div className='btnGroup'>
  208. <UpDataActBtn record type='ADD' />
  209. </div>
  210. </div>
  211. <div style={{ marginTop: 16 }}>
  212. <BMSTable columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  213. </div>
  214. </BMSPagecontainer>
  215. )
  216. }