chore: sync local latest state and repository cleanup
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { useMosquito } from '../index'
|
||||
import { useMosquito, type ShortenResponse } from '../index'
|
||||
|
||||
interface Props {
|
||||
activityId: number
|
||||
@@ -99,20 +99,40 @@ const toastClasses = computed(() => {
|
||||
// 处理点击事件
|
||||
const handleClick = async () => {
|
||||
if (loading.value || props.disabled) return
|
||||
|
||||
|
||||
try {
|
||||
loading.value = true
|
||||
const shareUrl = await getShareUrl(props.activityId, props.userId, props.template)
|
||||
|
||||
const shareResponse = await getShareUrl(props.activityId, props.userId, props.template)
|
||||
|
||||
// 从 ShortenResponse 对象中提取正确的 URL
|
||||
// 优先使用 originalUrl,否则拼接 baseUrl + path
|
||||
let urlToCopy: string
|
||||
if (shareResponse && typeof shareResponse === 'object') {
|
||||
const shortenResponse = shareResponse as ShortenResponse
|
||||
if (shortenResponse.originalUrl) {
|
||||
urlToCopy = shortenResponse.originalUrl
|
||||
} else if (shortenResponse.path) {
|
||||
// 需要从配置中获取 baseUrl,这里做个兼容处理
|
||||
// 如果 path 是完整URL直接使用,否则需要拼接
|
||||
urlToCopy = shortenResponse.path.startsWith('http')
|
||||
? shortenResponse.path
|
||||
: `${window.location.origin}${shortenResponse.path}`
|
||||
} else {
|
||||
throw new Error('分享链接响应格式异常')
|
||||
}
|
||||
} else {
|
||||
throw new Error('分享链接响应格式异常')
|
||||
}
|
||||
|
||||
// 复制到剪贴板
|
||||
try {
|
||||
await navigator.clipboard.writeText(shareUrl)
|
||||
await navigator.clipboard.writeText(urlToCopy)
|
||||
showCopiedToast()
|
||||
emit('copied')
|
||||
} catch (clipboardError) {
|
||||
// 如果剪贴板API不可用,回退到传统方法
|
||||
const textArea = document.createElement('textarea')
|
||||
textArea.value = shareUrl
|
||||
textArea.value = urlToCopy
|
||||
document.body.appendChild(textArea)
|
||||
textArea.select()
|
||||
document.execCommand('copy')
|
||||
|
||||
Reference in New Issue
Block a user