mirror of https://gitee.com/answerdev/answer.git
feat(admin/theme): Complete theme api interfacing
This commit is contained in:
parent
a5a95c5f3d
commit
b062a71234
|
@ -982,7 +982,7 @@ ui:
|
||||||
seo: SEO
|
seo: SEO
|
||||||
customize: Customize
|
customize: Customize
|
||||||
themes: Themes
|
themes: Themes
|
||||||
css_and_html: CSS/HTML
|
css-html: CSS/HTML
|
||||||
login: Login
|
login: Login
|
||||||
admin:
|
admin:
|
||||||
admin_header:
|
admin_header:
|
||||||
|
|
|
@ -60,7 +60,7 @@ export const ADMIN_NAV_MENUS = [
|
||||||
name: 'themes',
|
name: 'themes',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'css_and_html',
|
name: 'css-html',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -346,6 +346,16 @@ export interface AdminSettingsSeo {
|
||||||
robots: string;
|
robots: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type themeConfig = {
|
||||||
|
navbar_style: string;
|
||||||
|
primary_color: string;
|
||||||
|
[k: string]: string | number;
|
||||||
|
};
|
||||||
|
export interface AdminSettingsTheme {
|
||||||
|
theme: string;
|
||||||
|
theme_config: Record<string, themeConfig>;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description interface for Activity
|
* @description interface for Activity
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -35,7 +35,6 @@ const Index: FC = () => {
|
||||||
if (!tryLoggedAndActivated().ok) {
|
if (!tryLoggedAndActivated().ok) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isEdit ? (
|
return isEdit ? (
|
||||||
<Card className="mb-4">
|
<Card className="mb-4">
|
||||||
<Card.Header className="text-nowrap d-flex justify-content-between">
|
<Card.Header className="text-nowrap d-flex justify-content-between">
|
||||||
|
@ -80,7 +79,9 @@ const Index: FC = () => {
|
||||||
<>
|
<>
|
||||||
<div className="text-muted">{t('follow_tag_tip')}</div>
|
<div className="text-muted">{t('follow_tag_tip')}</div>
|
||||||
<NavLink className="d-inline-block my-2" to="/tags">
|
<NavLink className="d-inline-block my-2" to="/tags">
|
||||||
<Button variant="outline-primary">{t('follow_a_tag')}</Button>
|
<Button size="sm" variant="outline-primary">
|
||||||
|
{t('follow_a_tag')}
|
||||||
|
</Button>
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { FC, useEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import type * as Type from '@/common/interface';
|
import type * as Type from '@/common/interface';
|
||||||
import { getSeoSetting, putSeoSetting } from '@/services';
|
import { getThemeSetting, putThemeSetting } from '@/services';
|
||||||
import { SchemaForm, JSONSchema, initFormData, UISchema } from '@/components';
|
import { SchemaForm, JSONSchema, initFormData, UISchema } from '@/components';
|
||||||
import { useToast } from '@/hooks';
|
import { useToast } from '@/hooks';
|
||||||
import { handleFormError } from '@/utils';
|
import { handleFormError } from '@/utils';
|
||||||
|
@ -21,6 +21,7 @@ const Index: FC = () => {
|
||||||
description: t('themes.text'),
|
description: t('themes.text'),
|
||||||
enum: ['default'],
|
enum: ['default'],
|
||||||
enumNames: ['Default'],
|
enumNames: ['Default'],
|
||||||
|
default: 'default',
|
||||||
},
|
},
|
||||||
navbar_style: {
|
navbar_style: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -33,6 +34,7 @@ const Index: FC = () => {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
title: t('primary_color.label'),
|
title: t('primary_color.label'),
|
||||||
description: t('primary_color.text'),
|
description: t('primary_color.text'),
|
||||||
|
default: '#ffffff',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -49,17 +51,22 @@ const Index: FC = () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const [themeSetting, setThemeSetting] = useState<Type.AdminSettingsTheme>();
|
||||||
const [formData, setFormData] = useState(initFormData(schema));
|
const [formData, setFormData] = useState(initFormData(schema));
|
||||||
|
|
||||||
const onSubmit = (evt) => {
|
const onSubmit = (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
|
const themeName = formData.themes.value;
|
||||||
const reqParams: Type.AdminSettingsSeo = {
|
const reqParams: Type.AdminSettingsTheme = {
|
||||||
robots: formData.robots.value,
|
theme: themeName,
|
||||||
|
theme_config: {
|
||||||
|
[themeName]: {
|
||||||
|
navbar_style: formData.navbar_style.value,
|
||||||
|
primary_color: formData.primary_color.value,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
putThemeSetting(reqParams)
|
||||||
putSeoSetting(reqParams)
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
Toast.onShow({
|
Toast.onShow({
|
||||||
msg: t('update', { keyPrefix: 'toast' }),
|
msg: t('update', { keyPrefix: 'toast' }),
|
||||||
|
@ -75,17 +82,32 @@ const Index: FC = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getSeoSetting().then((setting) => {
|
getThemeSetting().then((setting) => {
|
||||||
if (setting) {
|
if (setting) {
|
||||||
// const formMeta = { ...formData };
|
setThemeSetting(setting);
|
||||||
// formMeta.robots.value = setting.robots;
|
const themeName = setting.theme;
|
||||||
// setFormData(formMeta);
|
const themeConfig = setting.theme_config[themeName];
|
||||||
|
const formMeta = { ...formData };
|
||||||
|
formMeta.themes.value = themeName;
|
||||||
|
formMeta.navbar_style.value = themeConfig?.navbar_style;
|
||||||
|
formMeta.primary_color.value = themeConfig?.primary_color;
|
||||||
|
setFormData({ ...formMeta });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleOnChange = (data) => {
|
const handleOnChange = (cd) => {
|
||||||
setFormData(data);
|
console.log('cd: ', cd);
|
||||||
|
setFormData(cd);
|
||||||
|
const themeConfig = themeSetting?.theme_config[cd.themes.value];
|
||||||
|
if (themeConfig) {
|
||||||
|
themeConfig.navbar_style = cd.navbar_style.value;
|
||||||
|
themeConfig.primary_color = cd.primary_color.value;
|
||||||
|
setThemeSetting({
|
||||||
|
theme: themeSetting?.theme,
|
||||||
|
theme_config: themeSetting?.theme_config,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -16,6 +16,8 @@ const formPaths = [
|
||||||
'branding',
|
'branding',
|
||||||
'legal',
|
'legal',
|
||||||
'write',
|
'write',
|
||||||
|
'themes',
|
||||||
|
'css-html',
|
||||||
];
|
];
|
||||||
|
|
||||||
const Index: FC = () => {
|
const Index: FC = () => {
|
||||||
|
|
|
@ -242,7 +242,7 @@ const routes: RouteNode[] = [
|
||||||
page: 'pages/Admin/Themes',
|
page: 'pages/Admin/Themes',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'css_and_html',
|
path: 'css-html',
|
||||||
page: 'pages/Admin/CssAndHtml',
|
page: 'pages/Admin/CssAndHtml',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -109,3 +109,13 @@ export const getSeoSetting = () => {
|
||||||
export const putSeoSetting = (params: Type.AdminSettingsSeo) => {
|
export const putSeoSetting = (params: Type.AdminSettingsSeo) => {
|
||||||
return request.put('/answer/admin/api/siteinfo/seo', params);
|
return request.put('/answer/admin/api/siteinfo/seo', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getThemeSetting = () => {
|
||||||
|
return request.get<Type.AdminSettingsTheme>(
|
||||||
|
'/answer/admin/api/siteinfo/theme',
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const putThemeSetting = (params: Type.AdminSettingsTheme) => {
|
||||||
|
return request.put('/answer/admin/api/siteinfo/theme', params);
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue