ModelAddItem.vue 3.3 KB

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