|
|
@@ -1,13 +1,36 @@
|
|
|
<script setup lang="ts">
|
|
|
+import { useClipboard } from "@/libs/clipboard.lib";
|
|
|
import type { ChapterSearchDocResponse } from "@/types/search.types";
|
|
|
+import { message } from "ant-design-vue";
|
|
|
import type { PropType } from "vue";
|
|
|
|
|
|
-defineProps({
|
|
|
+const props = defineProps({
|
|
|
data: {
|
|
|
type: Object as PropType<ChapterSearchDocResponse>,
|
|
|
required: true
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+const clipboard = useClipboard()
|
|
|
+
|
|
|
+function getSelectedText() {
|
|
|
+ if (window.getSelection) {
|
|
|
+ const range = window.getSelection()
|
|
|
+ return range?.toString()
|
|
|
+ } else {
|
|
|
+ message.warning("暂不支持此版本浏览器选择复制")
|
|
|
+ }
|
|
|
+ return null
|
|
|
+}
|
|
|
+
|
|
|
+function onCopy() {
|
|
|
+ const selectedText = getSelectedText()
|
|
|
+ const text = selectedText || props.data.content
|
|
|
+ const msg = selectedText && "复制所选内容成功" || "复制内容成功"
|
|
|
+ clipboard.copy(text).then(() => {
|
|
|
+ message.success(msg)
|
|
|
+ })
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
@@ -26,7 +49,7 @@ defineProps({
|
|
|
<div class="btn-group">
|
|
|
<a-radio-group>
|
|
|
<a-radio-button value="large">标记使用</a-radio-button>
|
|
|
- <a-radio-button value="default">复制</a-radio-button>
|
|
|
+ <a-radio-button value="default" @mousedown="onCopy">复制</a-radio-button>
|
|
|
<a-radio-button value="small">插入</a-radio-button>
|
|
|
</a-radio-group>
|
|
|
</div>
|