No Description

utils.ts 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. export const IMAGE_PROCESS = '?x-oss-process=image/resize,h_350';
  2. export const IMAGE_PROCESS_SMALL = '?x-oss-process=image/resize,h_100';
  3. export const IMAGE_PROCESS_LARGE = '?x-oss-process=image/resize,h_500';
  4. type AddImageProcessOptions = {
  5. small?: boolean;
  6. large?: boolean;
  7. custom?: boolean;
  8. width?: string;
  9. height?: string;
  10. }
  11. export function addImageProcess(url: string, options: AddImageProcessOptions = { width: '36px', height: '36px' }) {
  12. // 防止重复添加导致的url不正确
  13. if (url && url.indexOf('x-oss-process') > -1) {
  14. return url;
  15. }
  16. if (options.small) {
  17. return url + IMAGE_PROCESS_SMALL;
  18. }
  19. if (options.large) {
  20. return url + IMAGE_PROCESS_LARGE;
  21. }
  22. if (options.custom) {
  23. return `${url}?x-oss-process=image/resize,limit_0,m_fill,w_${options.width},h_${options.height}`;
  24. }
  25. return url + IMAGE_PROCESS;
  26. }
  27. export function formatMoney(input: any, fuzz = 2) {
  28. if (isNaN(+input)) {
  29. return input;
  30. }
  31. return (+input).toFixed(fuzz);
  32. }
  33. type classSize = 'small'|'normal'|'large';
  34. export function exportStyleSizeClass(styles: any, size: classSize) {
  35. return {
  36. [styles[size]]: true,
  37. }
  38. }