index.tsx 8.2 KB

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