Skip to content

Commit f1d3361

Browse files
committed
✨ feat: 支持复制后直接粘贴
1 parent b4afcf1 commit f1d3361

File tree

3 files changed

+76
-26
lines changed

3 files changed

+76
-26
lines changed

src/components/ConfigView.vue

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ const allClassifyRules = computed(() => {
6565
});
6666
6767
68-
const isKill = computed({
69-
get: () => settingsStore.isKill.value,
70-
set: (val) => { settingsStore.isKill.value = val }
68+
const copyAction = computed({
69+
get: () => settingsStore.copyAction?.value ?? 'copy-close-paste',
70+
set: (val) => { settingsStore.copyAction.value = val }
7171
});
7272
7373
const useIcon = computed({
@@ -85,6 +85,13 @@ const theme = computed({
8585
set: (val) => { settingsStore.theme.value = val }
8686
});
8787
88+
// 复制后的操作选项
89+
const copyActionOptions = [
90+
{ label: '仅复制', value: 'copy-only' },
91+
{ label: '复制并关闭', value: 'copy-close' },
92+
{ label: '复制、关闭并粘贴', value: 'copy-close-paste' }
93+
];
94+
8895
// 主题选项
8996
const themeOptions = [
9097
{ label: '跟随系统', value: 'system' },
@@ -288,7 +295,7 @@ const exportConfig = () => {
288295
settings: {
289296
useIcon: settingsStore.useIcon.value,
290297
autoClassify: settingsStore.autoClassify.value,
291-
isKill: settingsStore.isKill.value,
298+
copyAction: settingsStore.copyAction.value,
292299
theme: settingsStore.theme.value,
293300
classifyRules: settingsStore.classifyRules.value
294301
},
@@ -336,8 +343,8 @@ const importConfig = () => {
336343
if (config.settings.autoClassify !== undefined) {
337344
settingsStore.setAutoClassify(config.settings.autoClassify);
338345
}
339-
if (config.settings.isKill !== undefined) {
340-
settingsStore.setIsKill(config.settings.isKill);
346+
if (config.settings.copyAction !== undefined) {
347+
settingsStore.setCopyAction(config.settings.copyAction);
341348
}
342349
if (config.settings.theme !== undefined) {
343350
settingsStore.setTheme(config.settings.theme);
@@ -372,9 +379,16 @@ const importConfig = () => {
372379
<template>
373380
<div class="config-view">
374381
<div class="config-row">
375-
<a-switch v-model:checked="isKill" />
376-
<a-typography-text v-if="isKill">复制后立即退出插件</a-typography-text>
377-
<a-typography-text class="forbidden-item" v-else>复制后不主动退出插件</a-typography-text>
382+
<a-typography-text style="margin-right: 10px;">复制后的操作:</a-typography-text>
383+
<a-radio-group v-model:value="copyAction" button-style="solid">
384+
<a-radio-button v-for="option in copyActionOptions" :key="option.value" :value="option.value">
385+
{{ option.label }}
386+
</a-radio-button>
387+
</a-radio-group>
388+
</div>
389+
<div class="config-row" v-if="copyAction === 'copy-close-paste'" style="padding-left: 20px;">
390+
<a-alert message="注意" description="复制、关闭并粘贴功能在分离窗口模式下无法正常工作。如果你将 uTools 窗口设置为分离窗口,请选择其他模式。" type="warning"
391+
show-icon closable />
378392
</div>
379393
<div class="config-row">
380394
<a-switch v-model:checked="useIcon" />

src/components/HomeView.vue

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,26 +149,53 @@ const generatedGitCommitMessage = computed(() => {
149149
return `git commit -m"${generatedCommitMessage.value}"`;
150150
});
151151
152-
const onCopy = () => {
152+
const resetInputs = () => {
153153
commitMessage.value = '';
154154
scope.value = '';
155155
contributors.value = '';
156156
issueId.value = '';
157+
};
158+
159+
const onCopy = () => {
160+
resetInputs();
161+
162+
const action = settingsStore.copyAction?.value ?? 'copy-close-paste';
157163
158-
if (settingsStore.isKill.value) {
164+
if (action === 'copy-only') {
165+
// 仅复制,不关闭
166+
message.success('复制好了');
167+
} else if (action === 'copy-close') {
168+
// 复制并关闭
159169
utools.hideMainWindow();
160170
utools.outPlugin();
161-
return;
162171
}
163-
message.success('复制好了');
172+
// copy-close-paste 模式不需要在这里处理,因为已经在 copyText 中处理了
164173
};
165174
166175
const copyText = (text) => {
167-
navigator.clipboard.writeText(text).then(() => {
168-
onCopy();
169-
}).catch(() => {
170-
message.error('复制失败');
171-
});
176+
const action = settingsStore.copyAction?.value ?? 'copy-close-paste';
177+
178+
if (action === 'copy-close-paste') {
179+
// 检查是否为分离窗口
180+
if (window.utools.getWindowType() === 'detach') {
181+
// 分离窗口下仅复制并提示
182+
navigator.clipboard.writeText(text);
183+
message.warning('分离窗口模式下无法自动粘贴,已复制到剪贴板', 3);
184+
resetInputs();
185+
return;
186+
}
187+
188+
// 主窗口模式:复制、关闭并粘贴
189+
resetInputs();
190+
setTimeout(() => window.utools.hideMainWindowPasteText(text), 100);
191+
} else {
192+
// 其他模式:普通复制
193+
navigator.clipboard.writeText(text).then(() => {
194+
onCopy();
195+
}).catch(() => {
196+
message.error('复制失败');
197+
});
198+
}
172199
};
173200
</script>
174201

src/stores/settings.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const defaultSettings = {
4848
useIcon: true,
4949
autoClassify: true,
5050
classifyRules: { ...defaultClassifyRules },
51-
isKill: true,
51+
copyAction: 'copy-close-paste', // 'copy-only' | 'copy-close' | 'copy-close-paste'
5252
theme: 'system',
5353
isCustomType: false,
5454
customFileUrl: '',
@@ -60,6 +60,15 @@ const defaultSettings = {
6060
const loadSettings = () => {
6161
const saved = getData(SETTINGS_KEY, null)
6262
if (saved) {
63+
// 向后兼容:将旧的 isKill 转换为 copyAction
64+
if (saved.isKill !== undefined && saved.copyAction === undefined) {
65+
saved.copyAction = saved.isKill ? 'copy-close' : 'copy-only'
66+
delete saved.isKill
67+
}
68+
// 确保 copyAction 有默认值
69+
if (!saved.copyAction) {
70+
saved.copyAction = 'copy-close-paste'
71+
}
6372
return { ...defaultSettings, ...saved }
6473
}
6574
return { ...defaultSettings }
@@ -99,9 +108,9 @@ export function useSettingsStore() {
99108
set: (val) => { settings.value.classifyRules = val }
100109
})
101110

102-
const isKill = computed({
103-
get: () => settings.value.isKill,
104-
set: (val) => { settings.value.isKill = val }
111+
const copyAction = computed({
112+
get: () => settings.value.copyAction,
113+
set: (val) => { settings.value.copyAction = val }
105114
})
106115

107116
const theme = computed({
@@ -146,8 +155,8 @@ export function useSettingsStore() {
146155
settings.value.classifyRules = { ...defaultClassifyRules }
147156
}
148157

149-
const setIsKill = (value) => {
150-
settings.value.isKill = value
158+
const setCopyAction = (value) => {
159+
settings.value.copyAction = value
151160
}
152161

153162
const setTheme = (theme) => {
@@ -173,7 +182,7 @@ export function useSettingsStore() {
173182
useIcon,
174183
autoClassify,
175184
classifyRules,
176-
isKill,
185+
copyAction,
177186
theme,
178187
isCustomType,
179188
customFileUrl,
@@ -185,7 +194,7 @@ export function useSettingsStore() {
185194
setAutoClassify,
186195
setClassifyRules,
187196
resetClassifyRules,
188-
setIsKill,
197+
setCopyAction,
189198
setTheme,
190199
setCustomType,
191200
setCustomIcon,

0 commit comments

Comments
 (0)