ModelAddItem.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <a-modal v-model:visible="show_modal" :align-center="false" top="15vh" @ok="handleOk" @cancel="handleCancel">
  3. <template #title> {{ $t('management.create_intel_title') }}</template>
  4. <div class="section">
  5. <div class="form-item">
  6. <div class="label">{{ $t('management.label_name') }}</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="$t('management.input_placeholder')" />
  10. </div>
  11. </div>
  12. <div class="form-item">
  13. <div class="label">{{ $t('management.label_desc') }}</div>
  14. <a-textarea
  15. v-model="form.description"
  16. :placeholder="$t('management.label_desc')"
  17. :auto-size="{ minRows: 2, maxRows: 5 }"
  18. />
  19. </div>
  20. </div>
  21. </a-modal>
  22. </template>
  23. <script setup>
  24. import { ref, computed } from 'vue';
  25. import { useRouter } from 'vue-router';
  26. import { createDify } from '../../apis/rgflow-dify';
  27. import { createDialog } from '../../apis/intelligent';
  28. import { dialogType } from '../../views/manage/common';
  29. import { getIconIntelligent } from '../common/icon-map.js';
  30. import { Message } from '@arco-design/web-vue';
  31. import { useI18n } from 'vue-i18n';
  32. const { t } = useI18n();
  33. const props = defineProps({
  34. show_model_item: {
  35. type: Boolean,
  36. default: false
  37. },
  38. target_intell_type: {
  39. type: String,
  40. default: 'advanced-chat'
  41. },
  42. target_icon: {
  43. type: String,
  44. default: 'intellFrame1'
  45. }
  46. });
  47. const router = useRouter();
  48. const formInit = {
  49. name: '',
  50. description: ''
  51. };
  52. const form = ref(Object.assign({}, formInit));
  53. const emit = defineEmits(['update:show_model_item', 'select_icon', 'updateIntelligentList', 'clearSelectIcon']);
  54. let show_modal = computed(() => props.show_model_item);
  55. const handleOk = () => {
  56. if (form.value.name.trim().length) {
  57. const data = {
  58. name: form.value.name,
  59. description: form.value.description,
  60. mode: props.target_intell_type
  61. };
  62. createDify(data)
  63. .then((res) => {
  64. if (res.id && res.id.length) {
  65. const dialogData = {
  66. id: res.id,
  67. name: form.value.name,
  68. description: form.value.description,
  69. icon: props.target_icon,
  70. dialogType: dialogType.DIFY,
  71. mode: props.target_intell_type
  72. };
  73. createOwnDialog(dialogData);
  74. }
  75. })
  76. .catch((err) => {
  77. // 新建失败
  78. console.log(t('management.create_fail'), err);
  79. })
  80. .finally(() => {});
  81. }
  82. };
  83. const createOwnDialog = async (data) => {
  84. try {
  85. const res = await createDialog(data);
  86. if (res.code == 200) {
  87. handleCancel();
  88. emit('updateIntelligentList');
  89. // 新建成功
  90. Message.success(t('management.create_success'));
  91. // 新建成功进入dify详情页
  92. router.push({ path: '/intelligent/detail', query: { id: data.id, name: data.name, mode: data.mode } });
  93. } else {
  94. Message.error(t('management.create_fail'));
  95. }
  96. } catch (err) {
  97. console.log(t('management.create_fail'), err);
  98. }
  99. };
  100. const handleCancel = () => {
  101. form.value = Object.assign({}, formInit);
  102. emit('update:show_model_item', false);
  103. emit('clearSelectIcon');
  104. };
  105. const handleSelectIcon = () => {
  106. emit('select_icon');
  107. };
  108. </script>
  109. <style scoped lang="css">
  110. .section {
  111. padding: 0 20px;
  112. }
  113. .form-item {
  114. display: flex;
  115. flex-direction: column;
  116. gap: 10px;
  117. margin-top: 20px;
  118. }
  119. .value {
  120. display: flex;
  121. align-items: center;
  122. gap: 10px;
  123. }
  124. .value .icon {
  125. width: 44px;
  126. cursor: pointer;
  127. }
  128. .arco-input-wrapper {
  129. height: 32px;
  130. background-color: var(--color-fill-2);
  131. }
  132. .arco-input-wrapper:hover {
  133. background-color: var(--color-fill-3);
  134. }
  135. </style>