From da4f08e9a16c84bdfd937fa2c5c34b8fce705666 Mon Sep 17 00:00:00 2001
From: duorameng <2997944583@qq.com>
Date: Tue, 9 Jun 2026 16:12:55 +0800
Subject: [PATCH] refactor: use fallback clipboard for non-https env (#111)
---
.../views/agents/components/TokenListTab.vue | 6 ++--
web/src/views/notify/Notify.vue | 13 +++++----
web/src/views/notify/components/ApiUsage.vue | 29 ++++++++++---------
.../views/notify/components/ChannelList.vue | 19 +++++++-----
web/src/views/settings/SiteSettings.vue | 7 +++--
web/src/views/tasks/RepoDialog.vue | 6 ++--
web/src/views/tasks/Tasks.vue | 13 +++++----
web/src/views/terminal/Terminal.vue | 28 ++++--------------
8 files changed, 60 insertions(+), 61 deletions(-)
diff --git a/web/src/views/agents/components/TokenListTab.vue b/web/src/views/agents/components/TokenListTab.vue
index 038375a..38d886d 100644
--- a/web/src/views/agents/components/TokenListTab.vue
+++ b/web/src/views/agents/components/TokenListTab.vue
@@ -3,6 +3,7 @@ import { Button } from '@/components/ui/button'
import { Plus, Ticket, Check, X, Copy, Pencil, Trash2 } from 'lucide-vue-next'
import { type AgentToken, api } from '@/api'
import { toast } from 'vue-sonner'
+import { copyToClipboard } from '@/utils/clipboard'
const props = defineProps<{
tokens: AgentToken[]
@@ -25,8 +26,9 @@ function isTokenExhausted(token: AgentToken) {
}
function copyToken(token: string) {
- navigator.clipboard.writeText(token)
- toast.success('已复制')
+ copyToClipboard(token).then((success) => {
+ if (success) toast.success('已复制')
+ })
}
function openTokenDialog() {
diff --git a/web/src/views/notify/Notify.vue b/web/src/views/notify/Notify.vue
index 6ae7eb9..117077c 100644
--- a/web/src/views/notify/Notify.vue
+++ b/web/src/views/notify/Notify.vue
@@ -11,6 +11,7 @@ import EventBinding from './components/EventBinding.vue'
import ApiUsage from './components/ApiUsage.vue'
import ChannelDialog from './components/ChannelDialog.vue'
import TemplateSettings from './components/TemplateSettings.vue'
+import { copyToClipboard } from '@/utils/clipboard'
const activeTab = ref('channels')
@@ -291,10 +292,10 @@ async function copyApiToken() {
toast.error('请先生成 Token')
return
}
- try {
- await navigator.clipboard.writeText(apiToken.value)
+ const success = await copyToClipboard(apiToken.value)
+ if (success) {
toast.success('Token 已复制到剪贴板')
- } catch {
+ } else {
toast.error('复制失败')
}
}
@@ -311,10 +312,10 @@ async function copyApiExample() {
-H "Content-Type: application/json" \\
-H "notify-token: ${token}" \\
-d '{"channel_id": "${ch.id}", "title": "测试通知", "text": "来自脚本的通知"}'`
- try {
- await navigator.clipboard.writeText(example)
+ const success = await copyToClipboard(example)
+ if (success) {
toast.success('API 调用示例已复制到剪贴板')
- } catch {
+ } else {
toast.error('复制失败')
}
}
diff --git a/web/src/views/notify/components/ApiUsage.vue b/web/src/views/notify/components/ApiUsage.vue
index 11e6456..1cf3cd5 100644
--- a/web/src/views/notify/components/ApiUsage.vue
+++ b/web/src/views/notify/components/ApiUsage.vue
@@ -19,6 +19,7 @@ import {
import type { NotifyChannel, ChannelType } from '@/api'
import { ref, computed } from 'vue'
import { toast } from 'vue-sonner'
+import { copyToClipboard } from '@/utils/clipboard'
const props = defineProps<{
channels: NotifyChannel[]
@@ -49,13 +50,15 @@ function handleConfirmGenerate() {
emit('generateToken')
}
-function copyToClipboard(text: string, blockId: string) {
- navigator.clipboard.writeText(text).then(() => {
- copiedBlock.value = blockId
- toast.success('已复制到剪贴板')
- setTimeout(() => {
- copiedBlock.value = null
- }, 2000)
+function handleCopy(text: string, blockId: string) {
+ copyToClipboard(text).then((success) => {
+ if (success) {
+ copiedBlock.value = blockId
+ toast.success('已复制到剪贴板')
+ setTimeout(() => {
+ copiedBlock.value = null
+ }, 2000)
+ }
})
}
@@ -264,7 +267,7 @@ const currentExample = computed(() => {
-
@@ -361,7 +364,7 @@ const currentExample = computed(() => {
@@ -389,7 +392,7 @@ const currentExample = computed(() => {
import baihu
baihu.notify("标题", "内容")
@@ -406,7 +409,7 @@ const currentExample = computed(() => {
const baihu = require('baihu');
baihu.notify("标题", "内容");
@@ -452,7 +455,7 @@ const currentExample = computed(() => {