2025-07-19 03:30:44 +08:00
|
|
|
|
/*
|
|
|
|
|
|
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
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
import React, { useEffect, useState, useContext, useRef } from 'react';
|
2024-03-23 21:24:39 +08:00
|
|
|
|
import {
|
|
|
|
|
|
API,
|
|
|
|
|
|
showError,
|
|
|
|
|
|
showSuccess,
|
|
|
|
|
|
timestamp2string,
|
2025-06-03 23:56:39 +08:00
|
|
|
|
renderGroupOption,
|
2025-06-16 22:15:12 +08:00
|
|
|
|
renderQuotaWithPrompt,
|
2025-07-13 19:32:01 +08:00
|
|
|
|
getModelCategories,
|
2025-07-19 00:12:04 +08:00
|
|
|
|
} from '../../../../helpers';
|
|
|
|
|
|
import { useIsMobile } from '../../../../hooks/common/useIsMobile.js';
|
2024-01-08 16:23:54 +08:00
|
|
|
|
import {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
Button,
|
|
|
|
|
|
SideSheet,
|
|
|
|
|
|
Space,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
Spin,
|
|
|
|
|
|
Typography,
|
2025-05-23 00:24:08 +08:00
|
|
|
|
Card,
|
|
|
|
|
|
Tag,
|
🎨 style: unify card header UI, switch to Avatar icons & remove oversized props
Summary
• Replaced gradient header blocks with compact, neutral headers wrapped in `Avatar` across the following pages:
- Channel / EditChannel.js
- Channel / EditTagModal.js
- Redemption / EditRedemption.js
- Token / EditToken.js
- User / EditUser.js
- User / AddUser.js
Details
1. Added `Avatar` import and substituted raw icon elements, assigning semantic colors (`blue`, `green`, `purple`, `orange`, etc.) and consistent 16 px icons for a cleaner look.
2. Removed gradient backgrounds, decorative “blur-ball” shapes, and extra paddings from header containers to achieve a tight, flat design.
3. Stripped all `size="large"` attributes from `Button`, `Input`, `Select`, `DatePicker`, `AutoComplete`, and `Avatar` components, allowing default sizing for better visual density.
4. Eliminated redundant `bodyStyle` background overrides in some `SideSheet` components.
5. No business logic touched; all changes are purely presentational.
Result
The editing and creation dialogs now share a unified, compact style consistent with the latest design language, improving readability and user experience without altering functionality.
2025-06-26 16:05:13 +08:00
|
|
|
|
Avatar,
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
Form,
|
|
|
|
|
|
Col,
|
|
|
|
|
|
Row,
|
2024-03-15 16:05:33 +08:00
|
|
|
|
} from '@douyinfe/semi-ui';
|
2025-05-23 00:24:08 +08:00
|
|
|
|
import {
|
|
|
|
|
|
IconCreditCard,
|
|
|
|
|
|
IconLink,
|
|
|
|
|
|
IconSave,
|
|
|
|
|
|
IconClose,
|
2025-06-29 02:32:09 +08:00
|
|
|
|
IconKey,
|
2025-05-23 00:24:08 +08:00
|
|
|
|
} from '@douyinfe/semi-icons';
|
2024-12-24 18:40:18 +08:00
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2025-07-19 00:12:04 +08:00
|
|
|
|
import { StatusContext } from '../../../../context/Status';
|
2023-04-23 12:43:10 +08:00
|
|
|
|
|
2025-05-23 00:24:08 +08:00
|
|
|
|
const { Text, Title } = Typography;
|
|
|
|
|
|
|
2025-07-19 00:12:04 +08:00
|
|
|
|
const EditTokenModal = (props) => {
|
2025-05-23 00:24:08 +08:00
|
|
|
|
const { t } = useTranslation();
|
2025-06-16 22:15:12 +08:00
|
|
|
|
const [statusState, statusDispatch] = useContext(StatusContext);
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
const [loading, setLoading] = useState(false);
|
📱 refactor(web): remove legacy isMobile util and migrate to useIsMobile hook
BREAKING CHANGE:
helpers/utils.js no longer exports `isMobile()`.
Any external code that relied on this function must switch to the `useIsMobile` React hook.
Summary
-------
1. Deleted the obsolete `isMobile()` function from helpers/utils.js.
2. Introduced `MOBILE_BREAKPOINT` constant and `matchMedia`-based detection for non-React contexts.
3. Reworked toast positioning logic in utils.js to rely on `matchMedia`.
4. Updated render.js:
• Removed isMobile import.
• Added MOBILE_BREAKPOINT detection in `truncateText`.
5. Migrated every page/component to the `useIsMobile` hook:
• Layout: HeaderBar, PageLayout, SiderBar
• Pages: Home, Detail, Playground, User (Add/Edit), Token, Channel, Redemption, Ratio Sync
• Components: ChannelsTable, ChannelSelectorModal, ConflictConfirmModal
6. Purged all remaining `isMobile()` calls and legacy imports.
7. Added missing `const isMobile = useIsMobile()` declarations where required.
Benefits
--------
• Unifies mobile detection with a React-friendly hook.
• Eliminates duplicated logic and improves maintainability.
• Keeps non-React helpers lightweight by using `matchMedia` directly.
2025-07-16 02:54:58 +08:00
|
|
|
|
const isMobile = useIsMobile();
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
const formApiRef = useRef(null);
|
|
|
|
|
|
const [models, setModels] = useState([]);
|
|
|
|
|
|
const [groups, setGroups] = useState([]);
|
2025-06-29 02:32:09 +08:00
|
|
|
|
const isEdit = props.editingToken.id !== undefined;
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
|
|
|
|
|
|
const getInitValues = () => ({
|
2024-03-15 16:05:33 +08:00
|
|
|
|
name: '',
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
remain_quota: 500000,
|
2024-03-15 16:05:33 +08:00
|
|
|
|
expired_time: -1,
|
|
|
|
|
|
unlimited_quota: false,
|
|
|
|
|
|
model_limits_enabled: false,
|
2024-03-23 21:24:39 +08:00
|
|
|
|
model_limits: [],
|
2024-09-17 20:49:51 +08:00
|
|
|
|
allow_ips: '',
|
2024-09-18 05:19:10 +08:00
|
|
|
|
group: '',
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
tokenCount: 1,
|
|
|
|
|
|
});
|
2025-05-23 00:24:08 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const handleCancel = () => {
|
|
|
|
|
|
props.handleClose();
|
|
|
|
|
|
};
|
2025-05-23 00:24:08 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const setExpiredTime = (month, day, hour, minute) => {
|
|
|
|
|
|
let now = new Date();
|
|
|
|
|
|
let timestamp = now.getTime() / 1000;
|
|
|
|
|
|
let seconds = month * 30 * 24 * 60 * 60;
|
|
|
|
|
|
seconds += day * 24 * 60 * 60;
|
|
|
|
|
|
seconds += hour * 60 * 60;
|
|
|
|
|
|
seconds += minute * 60;
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
if (!formApiRef.current) return;
|
2024-03-15 16:05:33 +08:00
|
|
|
|
if (seconds !== 0) {
|
|
|
|
|
|
timestamp += seconds;
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
formApiRef.current.setValue('expired_time', timestamp2string(timestamp));
|
2024-03-15 16:05:33 +08:00
|
|
|
|
} else {
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
formApiRef.current.setValue('expired_time', -1);
|
2023-04-24 20:52:40 +08:00
|
|
|
|
}
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-04-24 20:52:40 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const loadModels = async () => {
|
|
|
|
|
|
let res = await API.get(`/api/user/models`);
|
|
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
2025-07-13 19:32:01 +08:00
|
|
|
|
const categories = getModelCategories(t);
|
|
|
|
|
|
let localModelOptions = data.map((model) => {
|
|
|
|
|
|
let icon = null;
|
|
|
|
|
|
for (const [key, category] of Object.entries(categories)) {
|
|
|
|
|
|
if (key !== 'all' && category.filter({ model_name: model })) {
|
|
|
|
|
|
icon = category.icon;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
|
|
|
label: (
|
|
|
|
|
|
<span className="flex items-center gap-1">
|
|
|
|
|
|
{icon}
|
|
|
|
|
|
{model}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
),
|
|
|
|
|
|
value: model,
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
2024-03-15 16:05:33 +08:00
|
|
|
|
setModels(localModelOptions);
|
|
|
|
|
|
} else {
|
2024-12-24 18:40:18 +08:00
|
|
|
|
showError(t(message));
|
2024-01-08 16:23:54 +08:00
|
|
|
|
}
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2024-01-08 16:23:54 +08:00
|
|
|
|
|
2024-09-18 05:19:10 +08:00
|
|
|
|
const loadGroups = async () => {
|
2024-10-14 16:15:10 +08:00
|
|
|
|
let res = await API.get(`/api/user/self/groups`);
|
2024-09-18 05:19:10 +08:00
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
2024-12-30 19:51:00 +08:00
|
|
|
|
let localGroupOptions = Object.entries(data).map(([group, info]) => ({
|
|
|
|
|
|
label: info.desc,
|
2024-12-24 18:40:18 +08:00
|
|
|
|
value: group,
|
2025-04-04 12:00:38 +08:00
|
|
|
|
ratio: info.ratio,
|
2024-12-24 18:40:18 +08:00
|
|
|
|
}));
|
2025-06-16 22:15:12 +08:00
|
|
|
|
if (statusState?.status?.default_use_auto_group) {
|
|
|
|
|
|
if (localGroupOptions.some((group) => group.value === 'auto')) {
|
|
|
|
|
|
localGroupOptions.sort((a, b) => (a.value === 'auto' ? -1 : 1));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
localGroupOptions.unshift({ label: t('自动选择'), value: 'auto' });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-12-24 18:40:18 +08:00
|
|
|
|
setGroups(localGroupOptions);
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
if (statusState?.status?.default_use_auto_group && formApiRef.current) {
|
|
|
|
|
|
formApiRef.current.setValue('group', 'auto');
|
2025-06-16 22:15:12 +08:00
|
|
|
|
}
|
2024-09-18 05:19:10 +08:00
|
|
|
|
} else {
|
2024-12-24 18:40:18 +08:00
|
|
|
|
showError(t(message));
|
2024-09-18 05:19:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const loadToken = async () => {
|
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
let res = await API.get(`/api/token/${props.editingToken.id}`);
|
|
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
if (data.expired_time !== -1) {
|
|
|
|
|
|
data.expired_time = timestamp2string(data.expired_time);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (data.model_limits !== '') {
|
|
|
|
|
|
data.model_limits = data.model_limits.split(',');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
data.model_limits = [];
|
|
|
|
|
|
}
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
if (formApiRef.current) {
|
|
|
|
|
|
formApiRef.current.setValues({ ...getInitValues(), ...data });
|
|
|
|
|
|
}
|
2024-03-15 16:05:33 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
};
|
2025-05-23 00:24:08 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
useEffect(() => {
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
if (formApiRef.current) {
|
|
|
|
|
|
if (!isEdit) {
|
|
|
|
|
|
formApiRef.current.setValues(getInitValues());
|
|
|
|
|
|
}
|
2024-03-15 16:05:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
loadModels();
|
2024-09-18 05:19:10 +08:00
|
|
|
|
loadGroups();
|
2025-06-29 02:32:09 +08:00
|
|
|
|
}, [props.editingToken.id]);
|
2023-04-23 12:43:10 +08:00
|
|
|
|
|
✨ refactor(EditChannel&EditToken): refactor Channel & Token edit pages with Semi Form and UX enhancements
Overview
• Migrated both `EditChannel.js` and `EditToken.js` to fully leverage Semi UI `Form.*` components, removing legacy `Input/Select/TextArea` + manual labels.
• Unified data-loading strategy: when the drawer becomes visible we load (or reset) data via `props.visible + id` effect and `formApi.setValues()`, guaranteeing fields are always populated; form resets on close.
• Fixed blank-form bug when opening the same record twice.
Key improvements
1. Validation
• `type`, `models` always required.
• `key` required only while creating (not on edit).
2. Batch key creation
• Checkbox moved into `extraText`; hidden when editing or when channel type = 41.
3. Layout & UI
• `Row / Col` (12 + 12) for “Priority” and “Weight”.
• Placeholders revised; model selector now shows creation hint; removed obsolete banner.
• Help / extraText used for long hints, template buttons (`model_mapping`, `status_code_mapping`, `param_override`, etc.), and API address notice.
• Added `showClear`, `min`, rounded card class names for consistency.
4. Reusable helpers
• `batchAllowed`, `batchExtra` utilities.
• `getInitValues()` + centralized `inputs`→form synchronization.
5. Token editor aligned to the same pattern (`props.visiable` watcher).
Result
Cleaner code, consistent UX, instant field population on every open, and clearer validation/error feedback across both editors.
2025-07-04 05:36:10 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (props.visiable) {
|
|
|
|
|
|
if (isEdit) {
|
|
|
|
|
|
loadToken();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
formApiRef.current?.setValues(getInitValues());
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
formApiRef.current?.reset();
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [props.visiable, props.editingToken.id]);
|
|
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const generateRandomSuffix = () => {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const characters =
|
|
|
|
|
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
2024-03-15 16:05:33 +08:00
|
|
|
|
let result = '';
|
|
|
|
|
|
for (let i = 0; i < 6; i++) {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
result += characters.charAt(
|
|
|
|
|
|
Math.floor(Math.random() * characters.length),
|
|
|
|
|
|
);
|
2024-03-15 16:05:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
};
|
2023-11-19 14:06:08 +08:00
|
|
|
|
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
const submit = async (values) => {
|
2024-03-15 16:05:33 +08:00
|
|
|
|
setLoading(true);
|
|
|
|
|
|
if (isEdit) {
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
let { tokenCount: _tc, ...localInputs } = values;
|
2024-03-15 16:05:33 +08:00
|
|
|
|
localInputs.remain_quota = parseInt(localInputs.remain_quota);
|
|
|
|
|
|
if (localInputs.expired_time !== -1) {
|
|
|
|
|
|
let time = Date.parse(localInputs.expired_time);
|
|
|
|
|
|
if (isNaN(time)) {
|
2024-12-24 18:40:18 +08:00
|
|
|
|
showError(t('过期时间格式错误!'));
|
2024-03-15 16:05:33 +08:00
|
|
|
|
setLoading(false);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
localInputs.expired_time = Math.ceil(time / 1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
localInputs.model_limits = localInputs.model_limits.join(',');
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
localInputs.model_limits_enabled = localInputs.model_limits.length > 0;
|
2024-03-23 21:24:39 +08:00
|
|
|
|
let res = await API.put(`/api/token/`, {
|
|
|
|
|
|
...localInputs,
|
|
|
|
|
|
id: parseInt(props.editingToken.id),
|
|
|
|
|
|
});
|
2024-03-15 16:05:33 +08:00
|
|
|
|
const { success, message } = res.data;
|
|
|
|
|
|
if (success) {
|
2024-12-24 18:40:18 +08:00
|
|
|
|
showSuccess(t('令牌更新成功!'));
|
2024-03-15 16:05:33 +08:00
|
|
|
|
props.refresh();
|
|
|
|
|
|
props.handleClose();
|
|
|
|
|
|
} else {
|
2024-12-24 18:40:18 +08:00
|
|
|
|
showError(t(message));
|
2024-03-15 16:05:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
const count = parseInt(values.tokenCount, 10) || 1;
|
|
|
|
|
|
let successCount = 0;
|
|
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
|
|
let { tokenCount: _tc, ...localInputs } = values;
|
|
|
|
|
|
const baseName = values.name.trim() === '' ? 'default' : values.name.trim();
|
|
|
|
|
|
if (i !== 0 || values.name.trim() === '') {
|
2025-06-08 12:38:03 +08:00
|
|
|
|
localInputs.name = `${baseName}-${generateRandomSuffix()}`;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
localInputs.name = baseName;
|
2023-11-19 14:06:08 +08:00
|
|
|
|
}
|
2024-03-15 16:05:33 +08:00
|
|
|
|
localInputs.remain_quota = parseInt(localInputs.remain_quota);
|
2023-11-19 14:06:08 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
if (localInputs.expired_time !== -1) {
|
|
|
|
|
|
let time = Date.parse(localInputs.expired_time);
|
|
|
|
|
|
if (isNaN(time)) {
|
2024-12-24 18:40:18 +08:00
|
|
|
|
showError(t('过期时间格式错误!'));
|
2024-03-15 16:05:33 +08:00
|
|
|
|
setLoading(false);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
localInputs.expired_time = Math.ceil(time / 1000);
|
2023-11-19 14:06:08 +08:00
|
|
|
|
}
|
2024-03-15 16:05:33 +08:00
|
|
|
|
localInputs.model_limits = localInputs.model_limits.join(',');
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
localInputs.model_limits_enabled = localInputs.model_limits.length > 0;
|
2024-03-15 16:05:33 +08:00
|
|
|
|
let res = await API.post(`/api/token/`, localInputs);
|
|
|
|
|
|
const { success, message } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
successCount++;
|
2023-11-01 02:50:14 +08:00
|
|
|
|
} else {
|
2024-12-24 18:40:18 +08:00
|
|
|
|
showError(t(message));
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
break;
|
2023-11-01 02:50:14 +08:00
|
|
|
|
}
|
2024-03-15 16:05:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (successCount > 0) {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
showSuccess(t('令牌创建成功,请在列表页面点击复制获取令牌!'));
|
2024-03-15 16:05:33 +08:00
|
|
|
|
props.refresh();
|
|
|
|
|
|
props.handleClose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
setLoading(false);
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
formApiRef.current?.setValues(getInitValues());
|
2024-03-15 16:05:33 +08:00
|
|
|
|
};
|
2023-11-01 02:50:14 +08:00
|
|
|
|
|
2024-03-15 16:05:33 +08:00
|
|
|
|
return (
|
2025-05-23 00:24:08 +08:00
|
|
|
|
<SideSheet
|
|
|
|
|
|
placement={isEdit ? 'right' : 'left'}
|
|
|
|
|
|
title={
|
|
|
|
|
|
<Space>
|
2025-06-16 22:15:12 +08:00
|
|
|
|
{isEdit ? (
|
|
|
|
|
|
<Tag color='blue' shape='circle'>
|
|
|
|
|
|
{t('更新')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Tag color='green' shape='circle'>
|
|
|
|
|
|
{t('新建')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
)}
|
|
|
|
|
|
<Title heading={4} className='m-0'>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{isEdit ? t('更新令牌信息') : t('创建新的令牌')}
|
|
|
|
|
|
</Title>
|
2025-05-23 00:24:08 +08:00
|
|
|
|
</Space>
|
|
|
|
|
|
}
|
🎨 style: unify card header UI, switch to Avatar icons & remove oversized props
Summary
• Replaced gradient header blocks with compact, neutral headers wrapped in `Avatar` across the following pages:
- Channel / EditChannel.js
- Channel / EditTagModal.js
- Redemption / EditRedemption.js
- Token / EditToken.js
- User / EditUser.js
- User / AddUser.js
Details
1. Added `Avatar` import and substituted raw icon elements, assigning semantic colors (`blue`, `green`, `purple`, `orange`, etc.) and consistent 16 px icons for a cleaner look.
2. Removed gradient backgrounds, decorative “blur-ball” shapes, and extra paddings from header containers to achieve a tight, flat design.
3. Stripped all `size="large"` attributes from `Button`, `Input`, `Select`, `DatePicker`, `AutoComplete`, and `Avatar` components, allowing default sizing for better visual density.
4. Eliminated redundant `bodyStyle` background overrides in some `SideSheet` components.
5. No business logic touched; all changes are purely presentational.
Result
The editing and creation dialogs now share a unified, compact style consistent with the latest design language, improving readability and user experience without altering functionality.
2025-06-26 16:05:13 +08:00
|
|
|
|
bodyStyle={{ padding: '0' }}
|
2025-05-23 00:24:08 +08:00
|
|
|
|
visible={props.visiable}
|
📱 refactor(web): remove legacy isMobile util and migrate to useIsMobile hook
BREAKING CHANGE:
helpers/utils.js no longer exports `isMobile()`.
Any external code that relied on this function must switch to the `useIsMobile` React hook.
Summary
-------
1. Deleted the obsolete `isMobile()` function from helpers/utils.js.
2. Introduced `MOBILE_BREAKPOINT` constant and `matchMedia`-based detection for non-React contexts.
3. Reworked toast positioning logic in utils.js to rely on `matchMedia`.
4. Updated render.js:
• Removed isMobile import.
• Added MOBILE_BREAKPOINT detection in `truncateText`.
5. Migrated every page/component to the `useIsMobile` hook:
• Layout: HeaderBar, PageLayout, SiderBar
• Pages: Home, Detail, Playground, User (Add/Edit), Token, Channel, Redemption, Ratio Sync
• Components: ChannelsTable, ChannelSelectorModal, ConflictConfirmModal
6. Purged all remaining `isMobile()` calls and legacy imports.
7. Added missing `const isMobile = useIsMobile()` declarations where required.
Benefits
--------
• Unifies mobile detection with a React-friendly hook.
• Eliminates duplicated logic and improves maintainability.
• Keeps non-React helpers lightweight by using `matchMedia` directly.
2025-07-16 02:54:58 +08:00
|
|
|
|
width={isMobile ? '100%' : 600}
|
2025-05-23 00:24:08 +08:00
|
|
|
|
footer={
|
2025-06-16 22:15:12 +08:00
|
|
|
|
<div className='flex justify-end bg-white'>
|
2025-05-23 00:24:08 +08:00
|
|
|
|
<Space>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<Button
|
2025-06-16 22:15:12 +08:00
|
|
|
|
theme='solid'
|
2025-06-29 02:32:09 +08:00
|
|
|
|
className='!rounded-lg'
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
onClick={() => formApiRef.current?.submitForm()}
|
2025-05-23 00:24:08 +08:00
|
|
|
|
icon={<IconSave />}
|
|
|
|
|
|
loading={loading}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
>
|
2025-05-23 00:24:08 +08:00
|
|
|
|
{t('提交')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Button>
|
2025-05-23 00:24:08 +08:00
|
|
|
|
<Button
|
2025-06-16 22:15:12 +08:00
|
|
|
|
theme='light'
|
2025-06-29 02:32:09 +08:00
|
|
|
|
className='!rounded-lg'
|
2025-06-16 22:15:12 +08:00
|
|
|
|
type='primary'
|
2025-05-23 00:24:08 +08:00
|
|
|
|
onClick={handleCancel}
|
|
|
|
|
|
icon={<IconClose />}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('取消')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
}
|
|
|
|
|
|
closeIcon={null}
|
|
|
|
|
|
onCancel={() => handleCancel()}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Spin spinning={loading}>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
<Form
|
|
|
|
|
|
key={isEdit ? 'edit' : 'new'}
|
|
|
|
|
|
initValues={getInitValues()}
|
|
|
|
|
|
getFormApi={(api) => (formApiRef.current = api)}
|
|
|
|
|
|
onSubmit={submit}
|
|
|
|
|
|
>
|
|
|
|
|
|
{({ values }) => (
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<div className='p-2'>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
{/* 基本信息 */}
|
|
|
|
|
|
<Card className='!rounded-2xl shadow-sm border-0'>
|
|
|
|
|
|
<div className='flex items-center mb-2'>
|
|
|
|
|
|
<Avatar size='small' color='blue' className='mr-2 shadow-md'>
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<IconKey size={16} />
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
</Avatar>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<Text className='text-lg font-medium'>{t('基本信息')}</Text>
|
|
|
|
|
|
<div className='text-xs text-gray-600'>{t('设置令牌的基本信息')}</div>
|
|
|
|
|
|
</div>
|
2025-05-23 00:24:08 +08:00
|
|
|
|
</div>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
<Row gutter={12}>
|
|
|
|
|
|
<Col span={24}>
|
|
|
|
|
|
<Form.Input
|
|
|
|
|
|
field='name'
|
|
|
|
|
|
label={t('名称')}
|
|
|
|
|
|
placeholder={t('请输入名称')}
|
|
|
|
|
|
rules={[{ required: true, message: t('请输入名称') }]}
|
|
|
|
|
|
showClear
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
<Col span={24}>
|
|
|
|
|
|
{groups.length > 0 ? (
|
|
|
|
|
|
<Form.Select
|
|
|
|
|
|
field='group'
|
|
|
|
|
|
label={t('令牌分组')}
|
|
|
|
|
|
placeholder={t('令牌分组,默认为用户的分组')}
|
|
|
|
|
|
optionList={groups}
|
|
|
|
|
|
renderOptionItem={renderGroupOption}
|
2025-06-29 02:32:09 +08:00
|
|
|
|
showClear
|
|
|
|
|
|
style={{ width: '100%' }}
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
/>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Form.Select
|
|
|
|
|
|
placeholder={t('管理员未设置用户可选分组')}
|
|
|
|
|
|
disabled
|
|
|
|
|
|
label={t('令牌分组')}
|
2025-06-29 02:32:09 +08:00
|
|
|
|
style={{ width: '100%' }}
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Col>
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<Col xs={24} sm={24} md={24} lg={10} xl={10}>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
<Form.DatePicker
|
|
|
|
|
|
field='expired_time'
|
|
|
|
|
|
label={t('过期时间')}
|
|
|
|
|
|
type='dateTime'
|
|
|
|
|
|
placeholder={t('请选择过期时间')}
|
2025-07-12 03:42:05 +08:00
|
|
|
|
rules={[
|
|
|
|
|
|
{ required: true, message: t('请选择过期时间') },
|
|
|
|
|
|
{
|
|
|
|
|
|
validator: (rule, value) => {
|
|
|
|
|
|
// 允许 -1 表示永不过期,也允许空值在必填校验时被拦截
|
|
|
|
|
|
if (value === -1 || !value) return Promise.resolve();
|
|
|
|
|
|
const time = Date.parse(value);
|
|
|
|
|
|
if (isNaN(time)) {
|
|
|
|
|
|
return Promise.reject(t('过期时间格式错误!'));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (time <= Date.now()) {
|
|
|
|
|
|
return Promise.reject(t('过期时间不能早于当前时间!'));
|
|
|
|
|
|
}
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
]}
|
2025-06-29 02:32:09 +08:00
|
|
|
|
showClear
|
|
|
|
|
|
style={{ width: '100%' }}
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</Col>
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<Col xs={24} sm={24} md={24} lg={14} xl={14}>
|
|
|
|
|
|
<Form.Slot label={t('过期时间快捷设置')}>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
<Space wrap>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
|
|
|
|
|
type='primary'
|
|
|
|
|
|
onClick={() => setExpiredTime(0, 0, 0, 0)}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('永不过期')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
|
|
|
|
|
type='tertiary'
|
|
|
|
|
|
onClick={() => setExpiredTime(1, 0, 0, 0)}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('一个月')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
|
|
|
|
|
type='tertiary'
|
|
|
|
|
|
onClick={() => setExpiredTime(0, 1, 0, 0)}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('一天')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
|
|
|
|
|
type='tertiary'
|
|
|
|
|
|
onClick={() => setExpiredTime(0, 0, 1, 0)}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('一小时')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
</Form.Slot>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
{!isEdit && (
|
|
|
|
|
|
<Col span={24}>
|
|
|
|
|
|
<Form.InputNumber
|
|
|
|
|
|
field='tokenCount'
|
|
|
|
|
|
label={t('新建数量')}
|
|
|
|
|
|
min={1}
|
|
|
|
|
|
extraText={t('批量创建时会在名称后自动添加随机后缀')}
|
|
|
|
|
|
rules={[{ required: true, message: t('请输入新建数量') }]}
|
2025-06-29 02:32:09 +08:00
|
|
|
|
style={{ width: '100%' }}
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 额度设置 */}
|
|
|
|
|
|
<Card className='!rounded-2xl shadow-sm border-0'>
|
|
|
|
|
|
<div className='flex items-center mb-2'>
|
|
|
|
|
|
<Avatar size='small' color='green' className='mr-2 shadow-md'>
|
|
|
|
|
|
<IconCreditCard size={16} />
|
|
|
|
|
|
</Avatar>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<Text className='text-lg font-medium'>{t('额度设置')}</Text>
|
|
|
|
|
|
<div className='text-xs text-gray-600'>{t('设置令牌可用额度和数量')}</div>
|
|
|
|
|
|
</div>
|
2025-05-23 00:24:08 +08:00
|
|
|
|
</div>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
<Row gutter={12}>
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<Col span={24}>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
<Form.AutoComplete
|
|
|
|
|
|
field='remain_quota'
|
|
|
|
|
|
label={t('额度')}
|
|
|
|
|
|
placeholder={t('请输入额度')}
|
|
|
|
|
|
type='number'
|
|
|
|
|
|
disabled={values.unlimited_quota}
|
|
|
|
|
|
extraText={renderQuotaWithPrompt(values.remain_quota)}
|
|
|
|
|
|
rules={values.unlimited_quota ? [] : [{ required: true, message: t('请输入额度') }]}
|
|
|
|
|
|
data={[
|
|
|
|
|
|
{ value: 500000, label: '1$' },
|
|
|
|
|
|
{ value: 5000000, label: '10$' },
|
|
|
|
|
|
{ value: 25000000, label: '50$' },
|
|
|
|
|
|
{ value: 50000000, label: '100$' },
|
|
|
|
|
|
{ value: 250000000, label: '500$' },
|
|
|
|
|
|
{ value: 500000000, label: '1000$' },
|
|
|
|
|
|
]}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Col>
|
2025-06-29 02:32:09 +08:00
|
|
|
|
<Col span={24}>
|
|
|
|
|
|
<Form.Switch
|
|
|
|
|
|
field='unlimited_quota'
|
|
|
|
|
|
label={t('无限额度')}
|
|
|
|
|
|
size='large'
|
|
|
|
|
|
extraText={t('令牌的额度仅用于限制令牌本身的最大额度使用量,实际的使用受到账户的剩余额度限制')}
|
|
|
|
|
|
/>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
</Col>
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
</Card>
|
2025-05-23 00:24:08 +08:00
|
|
|
|
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
{/* 访问限制 */}
|
|
|
|
|
|
<Card className='!rounded-2xl shadow-sm border-0'>
|
2025-06-16 22:15:12 +08:00
|
|
|
|
<div className='flex items-center mb-2'>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
<Avatar size='small' color='purple' className='mr-2 shadow-md'>
|
|
|
|
|
|
<IconLink size={16} />
|
|
|
|
|
|
</Avatar>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<Text className='text-lg font-medium'>{t('访问限制')}</Text>
|
|
|
|
|
|
<div className='text-xs text-gray-600'>{t('设置令牌的访问限制')}</div>
|
|
|
|
|
|
</div>
|
2025-05-23 00:24:08 +08:00
|
|
|
|
</div>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
<Row gutter={12}>
|
|
|
|
|
|
<Col span={24}>
|
|
|
|
|
|
<Form.Select
|
|
|
|
|
|
field='model_limits'
|
|
|
|
|
|
label={t('模型限制列表')}
|
|
|
|
|
|
placeholder={t('请选择该令牌支持的模型,留空支持所有模型')}
|
|
|
|
|
|
multiple
|
|
|
|
|
|
optionList={models}
|
|
|
|
|
|
extraText={t('非必要,不建议启用模型限制')}
|
2025-07-13 18:25:05 +08:00
|
|
|
|
filter
|
|
|
|
|
|
searchPosition='dropdown'
|
|
|
|
|
|
showClear
|
|
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
<Col span={24}>
|
|
|
|
|
|
<Form.TextArea
|
|
|
|
|
|
field='allow_ips'
|
|
|
|
|
|
label={t('IP白名单')}
|
|
|
|
|
|
placeholder={t('允许的IP,一行一个,不填写则不限制')}
|
|
|
|
|
|
autosize
|
|
|
|
|
|
rows={1}
|
|
|
|
|
|
extraText={t('请勿过度信任此功能,IP可能被伪造')}
|
2025-06-29 02:32:09 +08:00
|
|
|
|
showClear
|
|
|
|
|
|
style={{ width: '100%' }}
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
</Card>
|
2025-05-23 00:24:08 +08:00
|
|
|
|
</div>
|
✨ refactor(ui/token): migrate EditToken page to Semi Form API and polish UX
SUMMARY
• Re-implemented `EditToken.js` with Semi Form components, eliminating manual state handling and reducing re-renders.
• Added grid-based layout; “Expiration Time” selector now sits inline with quick-set buttons for consistent alignment on desktop & mobile.
• Introduced dedicated “Quota”, “Access”, “Model Limits”, and “Group” cards for clearer field grouping.
• Reworked model-limit interaction: single multi-select list replaces checkbox toggle; backend flag `model_limits_enabled` is now inferred automatically.
• Applied required validation rules to critical fields (`name`, `remain_quota`, `group`, `expired_time`, `tokenCount`) with localized messages.
• Enabled dynamic option loading for models & groups; default auto-group honoured.
• Added unlimited-quota switch, quota presets, and helpful extraText/tooltips.
• Removed obsolete `handleInputChange` & `setUnlimitedQuota` helpers; formApi now manages all data flow.
• Cleaned imports (e.g., dropped unused `IconUserGroup`), fixed linter errors, and updated submit logic to use `formApi.submitForm()`.
RESULT
The token creation/editing experience is faster, more accessible, and easier to maintain, fully aligned with Semi Design best practices.
2025-06-26 22:58:25 +08:00
|
|
|
|
)}
|
|
|
|
|
|
</Form>
|
2025-05-23 00:24:08 +08:00
|
|
|
|
</Spin>
|
|
|
|
|
|
</SideSheet>
|
2024-03-15 16:05:33 +08:00
|
|
|
|
);
|
2023-04-23 12:43:10 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-07-19 00:12:04 +08:00
|
|
|
|
export default EditTokenModal;
|