提交 5cc8e9cc authored 作者: matian's avatar matian

updates

上级 3262c991
...@@ -3,6 +3,7 @@ import ShareDialog from './ShareDialog.vue' ...@@ -3,6 +3,7 @@ import ShareDialog from './ShareDialog.vue'
import ContactDialog from '../components/ContactDialog.vue' import ContactDialog from '../components/ContactDialog.vue'
import { useDevice } from '@/composables/useDevice' import { useDevice } from '@/composables/useDevice'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
const user = useUserStore() const user = useUserStore()
const { mobile } = useDevice() const { mobile } = useDevice()
const props = defineProps({ const props = defineProps({
...@@ -52,26 +53,46 @@ const handleShare = () => { ...@@ -52,26 +53,46 @@ const handleShare = () => {
} }
// 微信分享复制到粘贴板 // 微信分享复制到粘贴板
const handleCopy = () => { const handleCopy = () => {
// 创建模拟 输入框
const cInput = document.createElement('input')
cInput.value = shareUrl.value
document.body.appendChild(cInput)
cInput.select() // 选取文本框内容
// 执行浏览器复制命令
// 复制命令会将当前选中的内容复制到剪切板中(这里就是创建的input标签)
// Input要在正常的编辑状态下原生复制方法才会生效
document.execCommand('copy')
// 复制成功后再将构造的标签 移除
document.body.removeChild(cInput)
isShowShare.value = '2' isShowShare.value = '2'
} }
// 复制
const onCopy = (val: any) => {
if (navigator.clipboard) {
return navigator.clipboard
.writeText(val)
.then((text) => {})
.catch((err) => {
onExecCommand(val)
})
} else {
onExecCommand(val)
}
}
const onExecCommand = (val: any) => {
const input = document.createElement('input')
input.setAttribute('readonly', 'readonly')
input.setAttribute('value', val)
input.style.position = 'absolute'
input.style.opacity = '0'
input.style.left = '-999999px'
input.style.top = '-999999px'
document.body.appendChild(input)
input.focus()
input.select()
input.setSelectionRange(0, 9999)
if (document.execCommand('copy')) {
document.execCommand('copy')
}
document.body.removeChild(input)
}
const handleCancel = () => { const handleCancel = () => {
isShowShare.value = '1' isShowShare.value = '1'
show.value = false
} }
// 复制链接控制显示 // 复制链接控制显示
const handleCopyLink = () => { const handleCopyLink = () => {
onCopy(shareUrl.value)
isShowShare.value = '3' isShowShare.value = '3'
} }
</script> </script>
...@@ -199,7 +220,7 @@ const handleCopyLink = () => { ...@@ -199,7 +220,7 @@ const handleCopyLink = () => {
<div class="content1" v-if="isShowShare === '2'"> <div class="content1" v-if="isShowShare === '2'">
<div class="content_con"> <div class="content_con">
<div class="con_desc con_desc2"> <div class="con_desc con_desc2">
请长按下方链接进行复制发给好友- 请长按下方链接进行复制发给好友-<br />
{{ shareUrl }} {{ shareUrl }}
</div> </div>
</div> </div>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论