refactor(接口测试): 简化复制到剪贴板代码
This commit is contained in:
parent
7dc0db5377
commit
eb23e4b212
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
import { useClipboard } from '@vueuse/core';
|
||||||
import { Message } from '@arco-design/web-vue';
|
import { Message } from '@arco-design/web-vue';
|
||||||
|
|
||||||
import MsButton from '@/components/pure/ms-button/index.vue';
|
import MsButton from '@/components/pure/ms-button/index.vue';
|
||||||
|
@ -56,6 +57,7 @@
|
||||||
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const { copy, isSupported } = useClipboard({ legacy: true });
|
||||||
|
|
||||||
const innerVisible = defineModel<boolean>('visible', {
|
const innerVisible = defineModel<boolean>('visible', {
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -140,23 +142,11 @@
|
||||||
shareLink.value = `${origin}/#/${RouteEnum.SHARE}/${
|
shareLink.value = `${origin}/#/${RouteEnum.SHARE}/${
|
||||||
props.isScenario ? RouteEnum.SHARE_REPORT_SCENARIO : RouteEnum.SHARE_REPORT_CASE
|
props.isScenario ? RouteEnum.SHARE_REPORT_SCENARIO : RouteEnum.SHARE_REPORT_CASE
|
||||||
}${shareId}`;
|
}${shareId}`;
|
||||||
if (navigator.clipboard) {
|
if (isSupported) {
|
||||||
navigator.clipboard.writeText(shareLink.value).then(
|
copy(shareLink.value);
|
||||||
() => {
|
|
||||||
Message.info(t('bugManagement.detail.shareTip'));
|
Message.info(t('bugManagement.detail.shareTip'));
|
||||||
},
|
|
||||||
(e) => {
|
|
||||||
Message.error(e);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
const input = document.createElement('input');
|
Message.error(t('common.copyNotSupport'));
|
||||||
input.value = shareLink.value;
|
|
||||||
document.body.appendChild(input);
|
|
||||||
input.select();
|
|
||||||
document.execCommand('copy');
|
|
||||||
document.body.removeChild(input);
|
|
||||||
Message.info(t('bugManagement.detail.shareTip'));
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
|
|
Loading…
Reference in New Issue