ModelUpdateItem.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <a-modal v-model:visible="show_modal" :align-center="false" top="15vh" @ok="handleOk" @cancel="handleCancel">
  3. <template #title> {{ $t('management.update_intelligent_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(icon_name)" 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. <ModelSelectIcon
  23. v-model:show_select_icon="show_select_icon"
  24. :target_icon="target_icon"
  25. @sendIcon="sendIcon"
  26. ></ModelSelectIcon>
  27. </template>
  28. <script setup>
  29. import { ref, computed } from 'vue';
  30. import { useRouter } from 'vue-router';
  31. import { createDify, updateDify } from '../../apis/rgflow-dify';
  32. import { createDialog, updateOwnIntelligentIcon } from '../../apis/intelligent';
  33. import { dialogType } from '../../views/manage/common';
  34. import { getIconIntelligent } from '../common/icon-map.js';
  35. import { Message } from '../../3rd-libs/arco-vue-libs';
  36. import { useI18n } from 'vue-i18n';
  37. import ModelSelectIcon from './ModalSelectIcon.vue';
  38. const { t } = useI18n();
  39. const props = defineProps({
  40. show_model_item: {
  41. type: Boolean,
  42. default: false
  43. },
  44. target_intell_type: {
  45. type: String,
  46. default: 'advanced-chat'
  47. },
  48. target_icon: {
  49. type: String,
  50. default: 'intellFrame1'
  51. },
  52. name: {
  53. type: String,
  54. default: ''
  55. },
  56. description: {
  57. type: String,
  58. default: ''
  59. },
  60. id: {
  61. type: String,
  62. default: ''
  63. }
  64. });
  65. const router = useRouter();
  66. const emit = defineEmits(['closeModel', 'select_icon', 'updateIntelligentList', 'clearSelectIcon']);
  67. const formInit = {
  68. name: '',
  69. description: ''
  70. };
  71. const form = ref(Object.assign({}, formInit));
  72. form.value = Object.assign({}, formInit, {
  73. name: props.name,
  74. description: props.description
  75. });
  76. const show_select_icon = ref(false);
  77. const icon_name = ref(props.target_icon);
  78. let show_modal = computed(() => props.show_model_item);
  79. const sendIcon = (icon) => {
  80. icon_name.value = icon;
  81. };
  82. const handleOk = async () => {
  83. const edit_id = props.id;
  84. const data = {
  85. name: form.value.name,
  86. description: form.value.description,
  87. use_icon_as_answer_icon: false
  88. };
  89. // if (icon_name.value !== props.target_icon) {
  90. // await updateOwnIntelligentIcon(edit_id, icon_name.value);
  91. // }
  92. const res = await updateDify(edit_id, data);
  93. if (res) {
  94. const response = await updateOwnIntelligentIcon(edit_id, icon_name.value, data.name, data.description);
  95. if (response.code == 200) {
  96. Message.success(t('management.edit_success'));
  97. emit('updateIntelligentList');
  98. handleCancel();
  99. } else {
  100. Message.error(t('management.edit_fail'));
  101. }
  102. } else {
  103. Message.error(t('management.edit_fail'));
  104. }
  105. };
  106. // const createOwnDialog = async (data) => {
  107. // try {
  108. // const res = await createDialog(data);
  109. // if (res.code == 200) {
  110. // handleCancel();
  111. // emit('updateIntelligentList');
  112. // // 新建成功
  113. // Message.success(t('management.create_success'));
  114. // // 新建成功进入dify详情页F
  115. // router.push({ path: '/intelligent/detail', query: { id: data.id, name: data.name, mode: data.mode } });
  116. // } else {
  117. // Message.error(t('management.create_fail'));
  118. // }
  119. // } catch (err) {
  120. // console.log(t('management.create_fail'), err);
  121. // }
  122. // };
  123. const handleCancel = () => {
  124. form.value = Object.assign({}, formInit);
  125. emit('closeModel', false);
  126. };
  127. const handleSelectIcon = () => {
  128. // emit('select_icon');
  129. show_select_icon.value = true;
  130. };
  131. </script>
  132. <style scoped lang="css">
  133. .section {
  134. padding: 0 20px;
  135. }
  136. .form-item {
  137. display: flex;
  138. flex-direction: column;
  139. gap: 10px;
  140. margin-top: 20px;
  141. }
  142. .value {
  143. display: flex;
  144. align-items: center;
  145. gap: 10px;
  146. }
  147. .value .icon {
  148. width: 44px;
  149. cursor: pointer;
  150. }
  151. .arco-input-wrapper {
  152. height: 32px;
  153. background-color: var(--color-fill-2);
  154. }
  155. .arco-input-wrapper:hover {
  156. background-color: var(--color-fill-3);
  157. }
  158. </style>