Files
orion-visor/orion-ops-ui/src/hooks/copy.ts

23 lines
487 B
TypeScript
Raw Normal View History

2023-09-11 16:33:57 +08:00
import { useClipboard } from '@vueuse/core';
import { Message } from '@arco-design/web-vue';
export default function useCopy() {
const { isSupported, copy: c, text, copied } = useClipboard();
2023-11-14 15:05:47 +08:00
const copy = async (value: string, tips = `${value} 已复制`) => {
2023-09-24 23:28:02 +08:00
try {
await c(value);
2023-09-11 16:33:57 +08:00
if (tips) {
Message.success(tips);
}
2023-11-14 15:05:47 +08:00
} catch (e) {
2023-09-11 16:33:57 +08:00
Message.error('复制失败');
2023-09-24 23:28:02 +08:00
}
2023-09-11 16:33:57 +08:00
};
return {
isSupported,
copy,
text,
copied
};
}