增加提示词管理

This commit is contained in:
2025-10-21 16:38:01 +08:00
parent 7021ab6bec
commit 14750e0895
7 changed files with 112 additions and 286 deletions

View File

@@ -1,4 +1,7 @@
import React from 'react';
import { save } from '@tauri-apps/plugin-dialog';
import { usePromptFilesStore } from '@/stores/promptFilesStore';
import { useTranslation } from '@/hooks/useTranslation';
import { Edit, Play, Tag as TagIcon, Clock, Calendar } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
@@ -28,6 +31,8 @@ export const PromptFilePreview: React.FC<PromptFilePreviewProps> = ({
onEdit,
onApply,
}) => {
const { applyFile } = usePromptFilesStore();
const { t } = useTranslation();
const formatDate = (timestamp: number) => {
return new Date(timestamp * 1000).toLocaleString('zh-CN', {
year: 'numeric',
@@ -38,6 +43,19 @@ export const PromptFilePreview: React.FC<PromptFilePreviewProps> = ({
});
};
const handleApplyToCustom = async () => {
const selectedPath = await save({
defaultPath: 'CLAUDE.md',
filters: [
{ name: 'Markdown', extensions: ['md'] },
{ name: 'All Files', extensions: ['*'] },
],
});
if (!selectedPath) return;
await applyFile(file.id, String(selectedPath));
onOpenChange(false);
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
@@ -100,6 +118,11 @@ export const PromptFilePreview: React.FC<PromptFilePreviewProps> = ({
使
</Button>
)}
<Button variant="outline" onClick={handleApplyToCustom}>
<Play className="mr-2 h-4 w-4" />
{/** 使用管理页 i18n key避免重复 */}
{t('promptFiles.applyToCustomPath')}
</Button>
</div>
</DialogFooter>
</DialogContent>
@@ -108,4 +131,3 @@ export const PromptFilePreview: React.FC<PromptFilePreviewProps> = ({
};
export default PromptFilePreview;

View File

@@ -37,6 +37,7 @@ import type { PromptFile } from '@/lib/api';
import { cn } from '@/lib/utils';
import { PromptFileEditor } from './PromptFileEditor';
import { PromptFilePreview } from './PromptFilePreview';
import { save } from '@tauri-apps/plugin-dialog';
interface PromptFilesManagerProps {
onBack?: () => void;
@@ -96,6 +97,29 @@ export const PromptFilesManager: React.FC<PromptFilesManagerProps> = ({ onBack,
}
};
// 应用到自定义路径(文件路径),跨平台
const handleApplyToCustom = async (file: PromptFile) => {
try {
const selectedPath = await save({
defaultPath: 'CLAUDE.md',
filters: [
{ name: 'Markdown', extensions: ['md'] },
{ name: 'All Files', extensions: ['*'] },
],
});
if (!selectedPath) return; // 用户取消
setApplyingFileId(file.id);
const resultPath = await applyFile(file.id, String(selectedPath));
showToast(`已应用到: ${resultPath}`, 'success');
await loadFiles();
} catch (error) {
showToast(t('promptFiles.applyToCustomPathFailed'), 'error');
} finally {
setApplyingFileId(null);
}
};
const handleDeactivate = async () => {
try {
await deactivateAll();
@@ -183,8 +207,8 @@ export const PromptFilesManager: React.FC<PromptFilesManagerProps> = ({ onBack,
</Button>
)}
<div>
<h1 className="text-3xl font-bold"></h1>
<p className="text-muted-foreground"> Claude </p>
<h1 className="text-3xl font-bold">{t('promptFiles.title')}</h1>
<p className="text-muted-foreground">{t('promptFiles.description')}</p>
</div>
</div>
<div className="flex gap-2">
@@ -289,6 +313,15 @@ export const PromptFilesManager: React.FC<PromptFilesManagerProps> = ({ onBack,
</>
)}
</Button>
<Button
variant="outline"
size="sm"
onClick={() => handleApplyToCustom(file)}
disabled={applyingFileId === file.id}
>
<Play className="mr-2 h-4 w-4" />
{t('promptFiles.applyToCustomPath')}
</Button>
<Button variant="outline" size="sm" onClick={() => openPreview(file)}>
<Eye className="mr-2 h-4 w-4" />
@@ -374,6 +407,16 @@ export const PromptFilesManager: React.FC<PromptFilesManagerProps> = ({ onBack,
</>
)}
</Button>
<Button
variant="outline"
size="sm"
className="w-full"
onClick={() => handleApplyToCustom(file)}
disabled={applyingFileId === file.id}
>
<Play className="mr-2 h-4 w-4" />
{t('promptFiles.applyToCustomPath')}
</Button>
<div className="flex gap-2 justify-center">
<Button
variant="outline"
@@ -586,4 +629,3 @@ const ImportFromClaudeMdDialog: React.FC<{
};
export default PromptFilesManager;