Skip to content

Commit e3d7a99

Browse files
committed
feat(projects): the topic configuration replication function was added
1 parent 0abdd0c commit e3d7a99

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import KeepAlive from 'keepalive-for-react';
2+
3+
const Content = ({ cacheKey, reloadFlag }: { cacheKey: string; reloadFlag: boolean }) => {
4+
const currentOutlet = useOutlet();
5+
return (
6+
<KeepAlive
7+
activeName={cacheKey}
8+
max={10}
9+
strategy={'LRU'}
10+
>
11+
{reloadFlag && currentOutlet}
12+
</KeepAlive>
13+
);
14+
};
15+
16+
export default Content;

src/layouts/modules/theme-drawer/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import DarkMode from './modules/DarkMode';
55
import ThemeColor from './modules/ThemeColor';
66
import LayoutMode from './modules/LayoutMode';
77
import PageFun from './modules/PageFun';
8+
import ConfigOperation from './modules/ConfigOperation';
89

910
const ThemeDrawer = memo(() => {
1011
const { t } = useTranslation();
@@ -29,6 +30,7 @@ const ThemeDrawer = memo(() => {
2930
onClick={close}
3031
/>
3132
}
33+
footer={<ConfigOperation />}
3234
>
3335
<SimpleScrollbar>
3436
<div className="px-24px pb-24px pt-8px">
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import Clipboard from 'clipboard';
2+
import { resetTheme, settingsJson } from '@/store/slice/theme';
3+
4+
const ConfigOperation = () => {
5+
const { t } = useTranslation();
6+
7+
const domRef = useRef<HTMLDivElement | null>(null);
8+
9+
const themeSettingsJson = useAppSelector(settingsJson);
10+
11+
const dispatch = useAppDispatch();
12+
13+
function getClipboardText() {
14+
const reg = /"\w+":/g;
15+
16+
return themeSettingsJson.replace(reg, match => match.replace(/"/g, ''));
17+
}
18+
19+
function initClipboard() {
20+
if (!domRef.current) return;
21+
22+
const clipboard = new Clipboard(domRef.current, {
23+
text: () => getClipboardText()
24+
});
25+
26+
clipboard.on('success', () => {
27+
window.$message?.success(t('theme.configOperation.copySuccessMsg'));
28+
});
29+
}
30+
31+
function handleReset() {
32+
dispatch(resetTheme());
33+
34+
setTimeout(() => {
35+
window.$message?.success(t('theme.configOperation.resetSuccessMsg'));
36+
}, 50);
37+
}
38+
39+
useMount(() => {
40+
initClipboard();
41+
});
42+
43+
return (
44+
<div className="flex justify-between">
45+
<AButton
46+
danger
47+
onClick={handleReset}
48+
>
49+
{t('theme.configOperation.resetConfig')}
50+
</AButton>
51+
<div ref={domRef}>
52+
<AButton type="primary">{t('theme.configOperation.copyConfig')}</AButton>
53+
</div>
54+
</div>
55+
);
56+
};
57+
58+
export default ConfigOperation;

src/store/slice/theme/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ export const themeSlice = createSlice({
124124
},
125125
changeReverseHorizontalMix(state, { payload }: PayloadAction<boolean>) {
126126
state.settings.layout.reverseHorizontalMix = payload;
127+
},
128+
resetTheme() {
129+
return initialState;
127130
}
128131
},
129132
selectors: {
@@ -148,6 +151,7 @@ export const {
148151
setFixedHeaderAndTab,
149152
setHeader,
150153
setTab,
154+
resetTheme,
151155
setWatermark,
152156
setSider,
153157
setFooter,
@@ -166,6 +170,10 @@ export const themeColors = createSelector([getThemeSettings], ({ themeColor, oth
166170
return colors;
167171
});
168172

173+
export const settingsJson = createSelector([getThemeSettings], settings => {
174+
return JSON.stringify(settings);
175+
});
176+
169177
export const toggleThemeScheme = (): AppThunk<boolean> => (dispatch, getState) => {
170178
const themeSettings = getThemeSettings(getState());
171179
const index = themeSchemes.findIndex(item => item === themeSettings.themeScheme);

0 commit comments

Comments
 (0)