SystemLogComponent.config.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import type { SmartColumn, SmartSearchFormSchema } from '@/components/SmartTable';
  2. import dayjs from 'dayjs';
  3. export type LoginIdent = 'LOGIN_LOG' | 'INTERFACE_LOG';
  4. /**
  5. * 获取表格列表
  6. * @param ident 标识位
  7. */
  8. export const getTableColumns = (ident: LoginIdent): SmartColumn[] => {
  9. return tableColumns.filter((item) => {
  10. return item.ident === undefined || item.ident.includes(ident);
  11. }) as SmartColumn[];
  12. };
  13. const tableColumns: Array<SmartColumn & { ident?: LoginIdent[] }> = [
  14. {
  15. type: 'seq',
  16. width: 80,
  17. },
  18. {
  19. title: '{system.views.log.title.operation}',
  20. field: 'operation',
  21. minWidth: 200,
  22. },
  23. {
  24. title: '{system.views.log.title.logSource}',
  25. field: 'logSource',
  26. width: 180,
  27. },
  28. {
  29. title: '{system.views.log.title.createUserId}',
  30. field: 'createBy',
  31. width: 120,
  32. },
  33. {
  34. title: '{system.views.log.title.ip}',
  35. field: 'ip',
  36. width: 160,
  37. },
  38. {
  39. title: '{system.views.log.title.operationType}',
  40. field: 'operationType',
  41. headerAlign: 'left',
  42. align: 'center',
  43. width: 120,
  44. ident: ['INTERFACE_LOG'],
  45. },
  46. {
  47. title: '{system.views.log.title.requestPath}',
  48. field: 'requestPath',
  49. width: 200,
  50. ident: ['INTERFACE_LOG'],
  51. },
  52. {
  53. title: '{system.views.log.title.statusCode}',
  54. field: 'statusCode',
  55. width: 120,
  56. headerAlign: 'left',
  57. align: 'center',
  58. slots: {
  59. default: 'table-statusCode',
  60. },
  61. sortable: true,
  62. },
  63. {
  64. title: '{system.views.log.title.method}',
  65. field: 'method',
  66. width: 200,
  67. ident: ['INTERFACE_LOG'],
  68. },
  69. {
  70. title: '{system.views.log.title.useTime}',
  71. field: 'useTime',
  72. width: 140,
  73. headerAlign: 'left',
  74. align: 'center',
  75. sortable: true,
  76. slots: {
  77. default: 'table-useTime',
  78. },
  79. ident: ['INTERFACE_LOG'],
  80. },
  81. {
  82. title: '{system.views.log.title.createTime}',
  83. field: 'createTime',
  84. width: 180,
  85. sortable: true,
  86. },
  87. {
  88. title: '{common.table.operation}',
  89. field: 'table-operation',
  90. width: 100,
  91. fixed: 'right',
  92. slots: {
  93. default: 'table-operation',
  94. },
  95. },
  96. ];
  97. const logSourceEnum = [
  98. {
  99. value: '10',
  100. enumName: 'AUTO_POINTCUT',
  101. label: 'system.views.log.title.logSourceAuto',
  102. ident: ['INTERFACE_LOG'],
  103. },
  104. {
  105. value: '20',
  106. enumName: 'MANUAL',
  107. label: 'system.views.log.title.logSourceManual',
  108. ident: ['INTERFACE_LOG'],
  109. },
  110. {
  111. value: '30',
  112. enumName: 'LOGIN',
  113. label: 'system.views.log.title.logSourceLoginSuccess',
  114. ident: ['LOGIN_LOG'],
  115. },
  116. {
  117. value: '40',
  118. enumName: 'LOGOUT',
  119. label: 'system.views.log.title.logSourceLogout',
  120. ident: ['LOGIN_LOG'],
  121. },
  122. {
  123. value: '50',
  124. enumName: 'LOGIN_FAIL',
  125. label: 'system.views.log.title.logSourceLoginFail',
  126. ident: ['LOGIN_LOG'],
  127. },
  128. ];
  129. export const getLogSourceEnum = (ident: LoginIdent, t: Function) => {
  130. return logSourceEnum
  131. .filter((item) => item.ident === undefined || item.ident.includes(ident))
  132. .map((item) => {
  133. return {
  134. value: item.value,
  135. label: t(item.label),
  136. };
  137. });
  138. };
  139. const operationTypeEnum = [
  140. {
  141. value: 'ADD',
  142. label: 'system.views.log.title.operationTypeAdd',
  143. },
  144. {
  145. value: 'DELETE',
  146. label: 'system.views.log.title.operationTypeDelete',
  147. },
  148. {
  149. value: 'UPDATE',
  150. label: 'system.views.log.title.operationTypeUpdate',
  151. },
  152. {
  153. value: 'QUERY',
  154. label: 'system.views.log.title.operationTypeQuery',
  155. },
  156. ];
  157. export const getOperationTypeEnum = (t: Function) => {
  158. return operationTypeEnum.map((item) => {
  159. return {
  160. label: t(item.label),
  161. value: item.value,
  162. };
  163. });
  164. };
  165. /**
  166. * 获取搜索表单
  167. * @param t
  168. * @param ident
  169. */
  170. export const getSearchFormSchemas = (t: Function, ident: LoginIdent) => {
  171. const schemas: Array<SmartSearchFormSchema & { ident?: LoginIdent[] }> = [
  172. {
  173. label: t('system.views.log.title.operation'),
  174. field: 'operation',
  175. component: 'Input',
  176. searchSymbol: 'like',
  177. },
  178. {
  179. label: t('system.views.log.title.logSource'),
  180. field: 'logSource',
  181. component: 'Select',
  182. componentProps: {
  183. mode: 'multiple',
  184. style: { width: '200px' },
  185. options: getLogSourceEnum(ident, t),
  186. },
  187. searchSymbol: 'in',
  188. },
  189. {
  190. label: t('system.views.log.title.statusCode'),
  191. field: 'statusCode',
  192. component: 'Input',
  193. searchSymbol: '=',
  194. componentProps: {
  195. style: { width: '120px' },
  196. },
  197. },
  198. {
  199. label: t('system.views.log.title.createTime'),
  200. field: 'createTime',
  201. component: 'RangePicker',
  202. searchSymbol: 'between',
  203. componentProps: {
  204. style: { width: '340px' },
  205. showTime: {
  206. defaultValue: [dayjs('00:00:00', 'HH:mm:ss')],
  207. },
  208. },
  209. },
  210. {
  211. label: t('system.views.log.title.operationType'),
  212. field: 'operationType',
  213. component: 'Select',
  214. searchSymbol: '=',
  215. ident: ['INTERFACE_LOG'],
  216. componentProps: {
  217. optionLabelProp: 'children',
  218. mode: 'multiple',
  219. style: { width: '120px' },
  220. options: getOperationTypeEnum(t),
  221. },
  222. },
  223. ];
  224. return schemas.filter((item) => item.ident === undefined || item.ident.includes(ident));
  225. };