ModalCreateKb.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <a-modal v-model:visible="show_modal" :align-center="false" top="15vh" @ok="handleOk" @cancel="handleCancel">
  3. <template #title> 添加知识库 </template>
  4. <div class="section">
  5. <div class="form-item">
  6. <div class="label">图标&名称</div>
  7. <div class="value">
  8. <img class="icon" :src="getImageKnowLedge(target_icon)" alt="" @click="handleSelectIcon" />
  9. <a-input v-model="form.name" placeholder="请输入名称" />
  10. </div>
  11. </div>
  12. <div class="form-item">
  13. <div class="label">描述</div>
  14. <a-textarea v-model="form.description" placeholder="描述" :auto-size="{ minRows: 2, maxRows: 5 }" />
  15. </div>
  16. </div>
  17. </a-modal>
  18. </template>
  19. <script setup>
  20. import { ref, computed } from 'vue';
  21. import { Message } from '@arco-design/web-vue';
  22. import { bus_knowledgeSearch } from '../../base/event-bus';
  23. import { createKb } from '../../apis/rgflow-dify';
  24. import { createOwnKnowledge } from '../../apis/knowledge';
  25. import { dialogType } from '../../views/manage/common';
  26. import { getImageKnowLedge } from '../common/icon-map.js';
  27. const props = defineProps({
  28. visible: {
  29. type: Boolean,
  30. default: false
  31. },
  32. target_icon: {
  33. type: String,
  34. default: 'knowledgeFrame1'
  35. }
  36. });
  37. const emit = defineEmits(['update:visible', 'select_icon']);
  38. const formInit = {
  39. name: '',
  40. description: '',
  41. icon: '',
  42. klgType: dialogType.RAGFLOW
  43. };
  44. const form = ref(Object.assign({}, formInit));
  45. const show_modal = computed(() => props.visible);
  46. const handleOk = () => {
  47. if (form.value.name.trim().length) {
  48. // TODO:添加知识库b
  49. createKnowledgeBase();
  50. } else {
  51. Message.warning('名称不能为空');
  52. }
  53. };
  54. const handleCancel = () => {
  55. form.value.name = '';
  56. emit('update:visible', false);
  57. };
  58. const createKnowledgeBase = async () => {
  59. const { name, description } = form.value;
  60. const res = await createKb(name);
  61. if (res.data && res.data.kb_id) {
  62. const data = {
  63. id: res.data.kb_id,
  64. name,
  65. description,
  66. icon: props.target_icon,
  67. klgType: dialogType.RAGFLOW
  68. };
  69. createOwnKnowledgeBase(data);
  70. }
  71. };
  72. const createOwnKnowledgeBase = async (data) => {
  73. try {
  74. const res = await createOwnKnowledge(data);
  75. if (res.code == 200) {
  76. bus_knowledgeSearch.emit('');
  77. form.value = Object.assign({}, formInit);
  78. emit('update:visible', false);
  79. Message.success('创建成功');
  80. }
  81. } catch (error) {
  82. console.log('创建知识库失败', error);
  83. Message.error('创建失败');
  84. }
  85. };
  86. const handleSelectIcon = () => {
  87. emit('select_icon');
  88. };
  89. </script>
  90. <style scoped lang="css">
  91. .section {
  92. padding: 0 20px;
  93. }
  94. .form-item {
  95. display: flex;
  96. flex-direction: column;
  97. gap: 10px;
  98. margin-top: 20px;
  99. }
  100. .value {
  101. display: flex;
  102. align-items: center;
  103. gap: 10px;
  104. }
  105. .value .icon {
  106. width: 44px;
  107. cursor: pointer;
  108. }
  109. .arco-input-wrapper {
  110. height: 32px;
  111. background-color: var(--color-neutral-2);
  112. }
  113. </style>