Skip to content

Commit bf813c5

Browse files
authored
Merge pull request #948 from xieliuduo/fix-imageUrl
refactor: convertImageUrl
2 parents 76c51f5 + bba2f94 commit bf813c5

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

frontend/src/app/pages/DashBoardPage/pages/Board/components/StyledBackground.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ import {
1919
BackgroundConfig,
2020
BorderConfig,
2121
} from 'app/pages/DashBoardPage/pages/Board/slice/types';
22-
import { convertImageUrl } from 'app/pages/DashBoardPage/utils';
22+
import { getBackgroundImage } from 'app/pages/DashBoardPage/utils';
2323
import styled from 'styled-components/macro';
2424
export interface StyledBackgroundProps {
2525
bg: BackgroundConfig;
2626
bd?: BorderConfig;
2727
}
28+
2829
const StyledBackground = styled.div<StyledBackgroundProps>`
2930
background-color: ${p => p.bg?.color};
30-
background-image: ${p => 'url(' + convertImageUrl(p.bg?.image) + ')'};
31+
background-image: ${p => getBackgroundImage(p.bg?.image)};
3132
background-repeat: ${p => p.bg?.repeat};
3233
background-size: ${p => p.bg?.size};
3334
border-color: ${p => p?.bd?.color};

frontend/src/app/pages/DashBoardPage/utils/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ export const convertImageUrl = (urlKey: string = ''): string => {
6767
}
6868
return urlKey;
6969
};
70+
export const getBackgroundImage = (url: string = ''): string => {
71+
return url ? `url(${convertImageUrl(url)})` : 'none';
72+
};
73+
7074
/**
7175
* @description '为了server 复制board 副本,原有board资源文件 和新副本资源文件 脱离关系 不受影响'
7276
* 将当前前端渲染环境 id 替换掉原有的id ,原来的和当前的相等不受影响

frontend/src/app/pages/DashBoardPage/utils/widget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { DeltaStatic } from 'quill';
2929
import { CSSProperties } from 'react';
3030
import { FONT_FAMILY, G90, WHITE } from 'styles/StyleConstants';
3131
import { uuidv4 } from 'utils/utils';
32-
import { convertImageUrl, fillPx } from '.';
32+
import { fillPx, getBackgroundImage } from '.';
3333
import {
3434
AutoBoardWidgetBackgroundDefault,
3535
BackgroundDefault,
@@ -705,7 +705,7 @@ export const getFreeWidgetStyle = (widget: Widget) => {
705705
export const getBackgroundCss = (bg: BackgroundConfig) => {
706706
let css: CSSProperties = {
707707
backgroundColor: bg.color,
708-
backgroundImage: `url(${convertImageUrl(bg.image)})`,
708+
backgroundImage: getBackgroundImage(bg.image),
709709
backgroundRepeat: bg.repeat,
710710
backgroundSize: bg.size,
711711
};

0 commit comments

Comments
 (0)