index.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @author tuonian
  3. * @date 2023/7/5
  4. */
  5. import {AutoTypeInputProps} from 'planning-tools'
  6. import './index.less'
  7. import config from './config.json'
  8. import {IContentProps, NgxBasicInput, registerInput} from "../basic";
  9. type ErrorPageData = {
  10. error_pages?: {
  11. /**
  12. * 处理的错误状态码
  13. */
  14. codes: string[]
  15. /**
  16. * 响应状态码
  17. */
  18. respCode?: string
  19. /**
  20. * 错误路由,或者命名路由
  21. */
  22. uri: string
  23. }[]
  24. }
  25. export const ErrorPageInput = ({...props}: AutoTypeInputProps)=>{
  26. const ShowContent = ({data}: IContentProps<ErrorPageData>)=>{
  27. const lines = renderLines(data);
  28. return (<div className="error-pages">
  29. {
  30. lines.map((line,index)=>(<div className="error-page-item" key={index}>{line}</div>))
  31. }
  32. {
  33. lines.length ? null : '未配置'
  34. }
  35. </div>)
  36. }
  37. const renderLines = (values: ErrorPageData = {})=>{
  38. const lines: string[] = []
  39. if (!values.error_pages || !values.error_pages.length){
  40. return lines
  41. }
  42. values.error_pages.forEach(item=>{
  43. if (!item.codes || item.codes.length ===0 || !item.uri){
  44. lines.push(`#error_page code or uri is empty, skip`)
  45. return
  46. }
  47. let text = `error_page ${item.codes.join(' ')}`
  48. if (item.respCode){
  49. text += ` =${item.respCode}`
  50. }
  51. text +=` ${item.uri};`
  52. lines.push(text)
  53. })
  54. return lines;
  55. }
  56. return <NgxBasicInput
  57. {...props}
  58. columns={config.form}
  59. renderLines={renderLines}
  60. content={ShowContent}
  61. overlayClassName="error-page-overlay"
  62. labelCol={0}
  63. />
  64. }
  65. registerInput('error_page', ErrorPageInput)