修改复制逻辑

This commit is contained in:
2025-11-11 15:21:13 +08:00
parent 38d8e24e90
commit f71205369a
+46 -12
View File
@@ -2,6 +2,7 @@
import { ref, computed, onMounted, onUnmounted } from 'vue'; import { ref, computed, onMounted, onUnmounted } from 'vue';
import { usePromptStore } from '../stores/promptStore'; import { usePromptStore } from '../stores/promptStore';
import type { PromptPreset } from '../types'; import type { PromptPreset } from '../types';
import NotificationToast from './NotificationToast.vue';
const store = usePromptStore(); const store = usePromptStore();
@@ -28,6 +29,20 @@ const showCreateForm = ref(false);
const sortBy = ref<'name' | 'date'>('date'); const sortBy = ref<'name' | 'date'>('date');
const sortOrder = ref<'asc' | 'desc'>('desc'); const sortOrder = ref<'asc' | 'desc'>('desc');
// 通知状态与方法(复用现有提示框架)
const notification = ref<{ message: string; type: 'success' | 'error' | 'info'; show: boolean }>({
message: '',
type: 'info',
show: false
});
function showNotification(message: string, type: 'success' | 'error' | 'info' = 'info') {
notification.value = { message, type, show: true };
setTimeout(() => {
notification.value.show = false;
}, 3000);
}
// 计算属性 // 计算属性
const filteredPresets = computed(() => { const filteredPresets = computed(() => {
const q = presetSearch.value.trim().toLowerCase(); const q = presetSearch.value.trim().toLowerCase();
@@ -196,18 +211,30 @@ function cancelRename() {
renamingValue.value = ''; renamingValue.value = '';
} }
function duplicatePreset(preset: any) { async function copyPresetToClipboard(preset: any) {
const newName = `${preset.name} - 副本`; const text = preset?.text || '';
if (!text) return;
// 只复制到扩展预设系统 try {
const defaultFolder = store.presetManagement?.settings?.defaultFolder; await navigator.clipboard.writeText(text);
store.createExtendedPreset({ showNotification('已复制到剪贴板', 'success');
name: newName, } catch (err) {
type: preset.type || 'positive', try {
content: preset.text, const ta = document.createElement('textarea');
description: preset.description || '复制的预设', ta.value = text;
folderId: defaultFolder ta.style.position = 'fixed';
}); ta.style.left = '-9999px';
document.body.appendChild(ta);
ta.focus();
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
showNotification('已复制到剪贴板', 'success');
} catch (e) {
console.error('复制到剪贴板失败:', e);
showNotification('复制失败,请手动复制', 'error');
}
}
} }
function exportPreset(preset: any) { function exportPreset(preset: any) {
@@ -452,7 +479,7 @@ onUnmounted(() => {
</div> </div>
<div class="pd-item-actions"> <div class="pd-item-actions">
<button @click.stop="duplicatePreset(p)" class="pd-action-btn" title="复制"> <button @click.stop="copyPresetToClipboard(p)" class="pd-action-btn" title="复制到剪贴板">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="12" height="12" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2" stroke="currentColor" stroke-width="2"/> <rect x="9" y="9" width="13" height="13" rx="2" ry="2" stroke="currentColor" stroke-width="2"/>
<path d="m5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" stroke="currentColor" stroke-width="2"/> <path d="m5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" stroke="currentColor" stroke-width="2"/>
@@ -515,6 +542,13 @@ onUnmounted(() => {
<span> ESC 关闭面板</span> <span> ESC 关闭面板</span>
</div> </div>
</div> </div>
<!-- 通知组件 -->
<NotificationToast
:message="notification.message"
:type="notification.type"
:show="notification.show"
/>
</div> </div>
</Transition> </Transition>
</template> </template>