You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui.tsx 1.8 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * @Author: 赵伟
  3. * @Date: 2024-04-19 14:42:51
  4. * @Description: UI 公共方法
  5. */
  6. import { PageEnum } from '@/enums/pagesEnums';
  7. import themes from '@/styles/theme.less';
  8. import { history } from '@umijs/max';
  9. import { Modal, type ModalFuncProps, type UploadFile } from 'antd';
  10. // 自定义 Confirm 弹框
  11. export function modalConfirm({ title, content, onOk, ...rest }: ModalFuncProps) {
  12. Modal.confirm({
  13. ...rest,
  14. title: (
  15. <div>
  16. <img
  17. src="/assets/images/delete-icon.png"
  18. style={{ width: '120px', marginBottom: '24px' }}
  19. alt=""
  20. />
  21. <div style={{ color: themes.textColor, fontSize: '16px', fontWeight: 500 }}>{title}</div>
  22. </div>
  23. ),
  24. content: content && <div style={{ color: themes.textColor, fontSize: '15px' }}>{content}</div>,
  25. okText: '确认',
  26. cancelText: '取消',
  27. onOk: onOk,
  28. });
  29. }
  30. // 从事件中获取上传文件列表,用于 Upload + Form 中
  31. export const getFileListFromEvent = (e: any) => {
  32. const fileList: UploadFile[] = (Array.isArray(e) ? e : e?.fileList) || [];
  33. return fileList.map((item) => {
  34. if (item.status === 'done') {
  35. const { response } = item;
  36. if (response?.code !== 200) {
  37. return {
  38. ...item,
  39. status: 'error',
  40. };
  41. }
  42. }
  43. return item;
  44. });
  45. };
  46. // 去登录页面
  47. export const gotoLoginPage = (toHome: boolean = true) => {
  48. const { pathname, search } = window.location;
  49. const urlParams = new URLSearchParams();
  50. urlParams.append('redirect', pathname + search);
  51. const newSearch = toHome && pathname && pathname !== PageEnum.LOGIN ? '' : urlParams.toString();
  52. if (window.location.pathname !== PageEnum.LOGIN) {
  53. history.replace({
  54. pathname: PageEnum.LOGIN,
  55. search: newSearch,
  56. });
  57. }
  58. };