assistant.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <script setup lang="ts">
  2. import { onMounted, onUnmounted, ref } from 'vue';
  3. import { useScriptTag } from '@vueuse/core';
  4. interface AssistantProps {
  5. botIcon?: string;
  6. botId?: string;
  7. botTitle?: string;
  8. isMobile?: boolean;
  9. }
  10. const props = withDefaults(defineProps<AssistantProps>(), {
  11. botIcon:
  12. 'https://cdn.jsdelivr.net/npm/@vbenjs/static-source@0.1.3/source/avatar-v1-transparent-bg.webp',
  13. botId: '7374674983739621392',
  14. botTitle: 'Vben Admin Assistant',
  15. isMobile: false,
  16. });
  17. let client: any;
  18. const wrapperEl = ref();
  19. const { load, unload } = useScriptTag(
  20. 'https://sf-cdn.coze.com/obj/unpkg-va/flow-platform/chat-app-sdk/0.1.0-beta.4/libs/oversea/index.js',
  21. () => {
  22. client = new (window as any).CozeWebSDK.WebChatClient({
  23. componentProps: {
  24. icon: props.botIcon,
  25. layout: props.isMobile ? 'mobile' : 'pc',
  26. // lang: 'zh-CN',
  27. title: props.botTitle,
  28. },
  29. config: {
  30. bot_id: props.botId,
  31. },
  32. el: wrapperEl.value,
  33. });
  34. },
  35. {
  36. manual: true,
  37. },
  38. );
  39. onMounted(() => {
  40. load();
  41. });
  42. onUnmounted(() => {
  43. unload();
  44. client?.destroy();
  45. });
  46. </script>
  47. <template>
  48. <div ref="wrapperEl" class="coze-assistant"></div>
  49. </template>
  50. <style>
  51. .coze-assistant {
  52. position: absolute;
  53. right: 30px;
  54. bottom: 30px;
  55. z-index: 1000;
  56. img {
  57. width: 42px !important;
  58. height: 42px !important;
  59. border-radius: 50%;
  60. }
  61. }
  62. </style>