feat: 完善官网配置、预约管理与文章编辑
This commit is contained in:
@@ -18,7 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { Card, Spin } from '@douyinfe/semi-ui';
|
||||
import { Banner, Button, Card, Spin } from '@douyinfe/semi-ui';
|
||||
import SettingsGeneral from '../../pages/Setting/Operation/SettingsGeneral';
|
||||
import SettingsLanguage from '../../pages/Setting/Operation/SettingsLanguage';
|
||||
import SettingsHeaderNavModules from '../../pages/Setting/Operation/SettingsHeaderNavModules';
|
||||
@@ -35,7 +35,34 @@ import SettingsFallback from '../../pages/Setting/Operation/SettingsFallback';
|
||||
import SettingsTheme from '../../pages/Setting/Operation/SettingsTheme';
|
||||
import SettingsAdminDelegation from '../../pages/Setting/Operation/SettingsAdminDelegation';
|
||||
import SettingsSkillInject from '../../pages/Setting/Operation/SettingsSkillInject';
|
||||
import { API, showError, toBoolean } from '../../helpers';
|
||||
import { API, toBoolean } from '../../helpers';
|
||||
|
||||
const ProgressiveSettingsSections = ({ children, loading }) => {
|
||||
const sections = React.Children.toArray(children);
|
||||
const [visibleCount, setVisibleCount] = useState(1);
|
||||
|
||||
useEffect(() => {
|
||||
if (visibleCount >= sections.length) return;
|
||||
// Yield between sections so mounting all forms cannot block one task.
|
||||
const timer = setTimeout(() => setVisibleCount((count) => count + 1), 0);
|
||||
return () => clearTimeout(timer);
|
||||
}, [visibleCount, sections.length]);
|
||||
|
||||
return (
|
||||
<Spin spinning={loading} size='large'>
|
||||
{sections.slice(0, visibleCount)}
|
||||
{visibleCount < sections.length && (
|
||||
<div
|
||||
role='status'
|
||||
aria-busy='true'
|
||||
className='flex justify-center py-6'
|
||||
>
|
||||
<Spin spinning />
|
||||
</div>
|
||||
)}
|
||||
</Spin>
|
||||
);
|
||||
};
|
||||
|
||||
const OperationSetting = () => {
|
||||
let [inputs, setInputs] = useState({
|
||||
@@ -98,6 +125,13 @@ const OperationSetting = () => {
|
||||
/* 提示词采集(实验性,方案 §35 一期) */
|
||||
GlobalPromptArchiveEnabled: false,
|
||||
|
||||
/* Skill switches arrive as strings from the options API. */
|
||||
SkillMarketRequireAuth: false,
|
||||
SkillInjectEnabled: false,
|
||||
SkillInjectMaxSkills: '5',
|
||||
SkillInjectMaxRunes: '3000',
|
||||
SkillInjectCacheTTLSeconds: '60',
|
||||
|
||||
/* 监控设置 */
|
||||
ChannelDisableThreshold: 0,
|
||||
QuotaRemindThreshold: 0,
|
||||
@@ -135,13 +169,15 @@ const OperationSetting = () => {
|
||||
'fallback_setting.max_attempts_per_request': 10,
|
||||
});
|
||||
|
||||
let [loading, setLoading] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [optionsLoaded, setOptionsLoaded] = useState(false);
|
||||
const [loadError, setLoadError] = useState('');
|
||||
const inputTypes = useRef(inputs);
|
||||
|
||||
const getOptions = useCallback(async () => {
|
||||
const res = await API.get('/api/option/');
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
if (success && Array.isArray(data)) {
|
||||
let newInputs = {};
|
||||
data.forEach((item) => {
|
||||
if (typeof inputTypes.current[item.key] === 'boolean') {
|
||||
@@ -153,16 +189,17 @@ const OperationSetting = () => {
|
||||
|
||||
setInputs(newInputs);
|
||||
} else {
|
||||
showError(message);
|
||||
throw new Error(message || '运营设置读取失败,请重试');
|
||||
}
|
||||
}, []);
|
||||
const onRefresh = useCallback(async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setLoadError('');
|
||||
await getOptions();
|
||||
// showSuccess('刷新成功');
|
||||
setOptionsLoaded(true);
|
||||
} catch (error) {
|
||||
showError('刷新失败');
|
||||
setLoadError(error.message || '运营设置读取失败,请重试');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -172,9 +209,26 @@ const OperationSetting = () => {
|
||||
onRefresh();
|
||||
}, [onRefresh]);
|
||||
|
||||
const errorBanner = loadError && (
|
||||
<Banner type='danger' closeIcon={null} description={loadError}>
|
||||
<Button onClick={onRefresh} disabled={loading}>
|
||||
重新加载运营设置
|
||||
</Button>
|
||||
</Banner>
|
||||
);
|
||||
|
||||
// Never mount editable defaults when the initial request fails.
|
||||
if (!optionsLoaded) {
|
||||
if (loadError) return errorBanner;
|
||||
return (
|
||||
<Spin spinning size='large' style={{ minHeight: 200, width: '100%' }} />
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Spin spinning={loading} size='large'>
|
||||
{errorBanner}
|
||||
<ProgressiveSettingsSections loading={loading}>
|
||||
{/* 通用设置 */}
|
||||
<Card style={{ marginTop: '10px' }}>
|
||||
<SettingsGeneral options={inputs} refresh={onRefresh} />
|
||||
@@ -235,7 +289,7 @@ const OperationSetting = () => {
|
||||
<SettingsExperienceCenter options={inputs} refresh={onRefresh} />
|
||||
{/* 普通管理员可见的系统设置页(权限下放) */}
|
||||
<SettingsAdminDelegation options={inputs} refresh={onRefresh} />
|
||||
</Spin>
|
||||
</ProgressiveSettingsSections>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user