123456789101112131415161718192021222324252627282930313233343536 |
-
- export const IMAGE_PROCESS = '?x-oss-process=image/resize,h_350';
- export const IMAGE_PROCESS_SMALL = '?x-oss-process=image/resize,h_100';
- export const IMAGE_PROCESS_LARGE = '?x-oss-process=image/resize,h_500';
-
- type AddImageProcessOptions = {
- small?: boolean;
- large?: boolean;
- custom?: boolean;
- width?: string;
- height?: string;
- }
-
- export function addImageProcess(url: string, options: AddImageProcessOptions = { width: '36px', height: '36px' }) {
- // 防止重复添加导致的url不正确
- if (url && url.indexOf('x-oss-process') > -1) {
- return url;
- }
- if (options.small) {
- return url + IMAGE_PROCESS_SMALL;
- }
- if (options.large) {
- return url + IMAGE_PROCESS_LARGE;
- }
- if (options.custom) {
- return `${url}?x-oss-process=image/resize,limit_0,m_fill,w_${options.width},h_${options.height}`;
- }
- return url + IMAGE_PROCESS;
- }
-
- export function formatMoney(input: any, fuzz = 2) {
- if (isNaN(+input)) {
- return input;
- }
- return (+input).toFixed(fuzz);
- }
|