Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
@@ -0,0 +1,126 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useState, useRef } from 'react';
import { Banner, Button, Card, Checkbox, Form, Spin } from '@douyinfe/semi-ui';
import { API, isRoot, showError, showSuccess } from '../../../helpers';
import { useTranslation } from 'react-i18next';
import { DELEGATABLE_SETTING_TABS } from '../../../constants/settingTabs';
const OPTION_KEY = 'AdminDelegatedSettingTabs';
function parseTabs(raw) {
if (!raw) return [];
try {
const parsed = JSON.parse(raw);
return Array.isArray(parsed) ? parsed : [];
} catch (e) {
return [];
}
}
export default function SettingsAdminDelegation(props) {
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
const [selected, setSelected] = useState([]);
const [savedRaw, setSavedRaw] = useState('');
const refForm = useRef();
useEffect(() => {
const raw = props.options?.[OPTION_KEY] ?? '';
setSavedRaw(raw);
const tabs = parseTabs(raw);
setSelected(tabs);
refForm.current?.setValues({ [OPTION_KEY]: tabs });
}, [props.options]);
// 该配置项属于权限下放的「控制开关」,仅超级管理员可见可改(后端亦强制 root-only)。
if (!isRoot()) {
return null;
}
function onSubmit() {
const value = JSON.stringify(selected);
if (value === JSON.stringify(parseTabs(savedRaw))) {
showSuccess(t('保存成功'));
return;
}
setLoading(true);
API.put('/api/option/', { key: OPTION_KEY, value })
.then((res) => {
const { success, message } = res.data;
if (success) {
showSuccess(t('保存成功'));
props.refresh?.();
} else {
showError(message);
}
})
.catch(() => {
showError(t('保存失败,请重试'));
})
.finally(() => {
setLoading(false);
});
}
return (
<Card style={{ marginTop: '10px' }}>
<Spin spinning={loading}>
<Form
values={{ [OPTION_KEY]: selected }}
getFormApi={(formAPI) => (refForm.current = formAPI)}
style={{ marginBottom: 15 }}
>
<Form.Section text={t('普通管理员可见的系统设置页')}>
<Banner
type='warning'
description={t(
'勾选后,普通管理员(非超级管理员)将能够看到并编辑这些系统设置 Tab。请谨慎下放含密钥的页面(如系统设置、支付设置、数据安全)。未勾选的 Tab 仍仅超级管理员可见。',
)}
bordered
fullMode={false}
closeIcon={null}
style={{ marginBottom: 16 }}
/>
<Form.CheckboxGroup
field={OPTION_KEY}
noLabel
direction='horizontal'
onChange={(value) => setSelected(value)}
>
{DELEGATABLE_SETTING_TABS.map((tab) => (
<Checkbox key={tab.key} value={tab.key}>
{t(tab.labelKey)}
</Checkbox>
))}
</Form.CheckboxGroup>
<Button
size='default'
theme='solid'
onClick={onSubmit}
style={{ marginTop: 12 }}
>
{t('保存')}
</Button>
</Form.Section>
</Form>
</Spin>
</Card>
);
}