ModelAddItem.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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="getIconIntelligent(props.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 { createDify } from '../../apis/rgflow-dify';
  22. import { createDialog } from '../../apis/intelligent';
  23. import { getIconIntelligent, dialogType } from '../../views/manage/common';
  24. const props = defineProps({
  25. show_model_item: {
  26. type: Boolean,
  27. default: false
  28. },
  29. target_intell_type: {
  30. type: String,
  31. default: 'advanced-chat'
  32. },
  33. target_icon: {
  34. type: String,
  35. default: 'intellFrame1'
  36. }
  37. });
  38. const formInit = {
  39. name: '',
  40. description: ''
  41. };
  42. const form = ref(Object.assign({}, formInit));
  43. const emit = defineEmits(['update:show_model_item', 'select_icon', 'updateIntelligentList']);
  44. let show_modal = computed(() => props.show_model_item);
  45. const handleOk = () => {
  46. if (form.value.name.trim().length) {
  47. const data = {
  48. name: form.value.name,
  49. description: form.value.description,
  50. mode: props.target_intell_type
  51. };
  52. createDify(data)
  53. .then((res) => {
  54. if (res.id && res.id.length) {
  55. const dialogData = {
  56. id: res.id,
  57. name: form.value.name,
  58. description: form.value.description,
  59. icon: props.target_icon,
  60. dialogType: dialogType.DIFY,
  61. mode: props.target_intell_type
  62. };
  63. createOwnDialog(dialogData);
  64. }
  65. })
  66. .catch((err) => {
  67. console.log('新建失败', err);
  68. })
  69. .finally(() => {});
  70. }
  71. };
  72. const createOwnDialog = async (data) => {
  73. try {
  74. const res = await createDialog(data);
  75. if (res.code == 200) {
  76. form.value = Object.assign({}, formInit);
  77. emit('update:show_model_item', false);
  78. emit('updateIntelligentList');
  79. }
  80. } catch (err) {
  81. console.log('创建对话失败', err);
  82. }
  83. };
  84. const handleCancel = () => {
  85. form.value = Object.assign({}, formInit);
  86. emit('update:show_model_item', false);
  87. };
  88. const handleSelectIcon = () => {
  89. emit('select_icon');
  90. };
  91. </script>
  92. <style scoped lang="css">
  93. .section {
  94. padding: 0 20px;
  95. }
  96. .form-item {
  97. display: flex;
  98. flex-direction: column;
  99. gap: 10px;
  100. margin-top: 20px;
  101. }
  102. .value {
  103. display: flex;
  104. align-items: center;
  105. gap: 10px;
  106. }
  107. .value .icon {
  108. width: 44px;
  109. cursor: pointer;
  110. }
  111. .arco-input-wrapper {
  112. height: 32px;
  113. background-color: var(--color-neutral-2);
  114. }
  115. </style>