eidtDetails.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <a-modal
  3. v-model:visible="visible"
  4. :title="$t('knowledgeLib.edit_parser_block')"
  5. @before-open="handleOpened"
  6. @cancel="handleCancel"
  7. :footer="false"
  8. title-align="start"
  9. >
  10. <a-form ref="formRef" :rules="rules" :model="form" @submit="handleSubmit" layout="vertical">
  11. <!-- 解析块 -->
  12. <a-form-item field="content_with_weight" :label="$t('knowledgeLib.parse_block')">
  13. <a-textarea v-model="form.content_with_weight" placeholder="" style="height: 100px; overflow: auto" auto-size />
  14. </a-form-item>
  15. <!-- 关键词 -->
  16. <a-form-item field="important_kwd_key" :label="$t('knowledgeLib.keyword')">
  17. <div style="width: auto">
  18. <a-tag
  19. v-for="(item, index) in form.important_kwd"
  20. :key="item"
  21. closable
  22. bordered
  23. @close="deleteKey(item)"
  24. style="margin-right: 10px"
  25. >
  26. {{ item }}
  27. </a-tag>
  28. <a-input
  29. ref="formInput"
  30. v-show="keyVisible"
  31. v-model="form.important_kwd_key"
  32. placeholder=""
  33. size="small"
  34. style="width: 80px; margin-right: 16px"
  35. @blur="inputChange"
  36. />
  37. <a-button type="dashed" shape="circle" size="small" @click="addKey">
  38. <icon-plus />
  39. </a-button>
  40. </div>
  41. </a-form-item>
  42. <!-- <div>-->
  43. <!-- <a-divider style="margin: 10px 0" />-->
  44. <!-- <a-switch size="small" />-->
  45. <!-- <span style="color: var(&#45;&#45;color-text-2)">启用</span>-->
  46. <!-- <a-button type="text" style="color: var(&#45;&#45;color-text-2)">-->
  47. <!-- <template #icon>-->
  48. <!-- <icon-delete />-->
  49. <!-- </template>-->
  50. <!-- 删除-->
  51. <!-- </a-button>-->
  52. <!-- </div>-->
  53. <a-form-item>
  54. <div style="width: 100%; text-align: right">
  55. <!-- 取消 -->
  56. <a-button @click="visible = false">{{ $t('knowledgeLib.cancel') }}</a-button>
  57. <!-- 确定 -->
  58. <a-button style="margin-left: 10px" type="primary" html-type="submit">{{
  59. $t('knowledgeLib.submit')
  60. }}</a-button>
  61. </div>
  62. </a-form-item>
  63. </a-form>
  64. </a-modal>
  65. </template>
  66. <script setup>
  67. import { onMounted, onBeforeMount, reactive, ref, nextTick } from 'vue';
  68. import { achunkCreate, achunkSet } from '../../../../apis/rgflow-dify';
  69. const props = defineProps(['item']);
  70. const visible = defineModel('eidtDilVisible');
  71. const emit = defineEmits(['canplaythrough']);
  72. const keyVisible = ref(false);
  73. const loading = ref(false);
  74. const form = reactive({
  75. content_with_weight: '',
  76. important_kwd: [],
  77. important_kwd_key: ''
  78. });
  79. const formRef = ref(null);
  80. const formInput = ref(null);
  81. const rules = {
  82. content_with_weight: [
  83. {
  84. required: true,
  85. message: '请输入值!'
  86. }
  87. ]
  88. };
  89. const handleSubmit = async ({ values, errors }) => {
  90. if (!errors) {
  91. const res = await achunkSet({
  92. content_with_weight: values.content_with_weight,
  93. important_kwd: values.important_kwd,
  94. doc_id: props.item.doc_id,
  95. chunk_id: props.item.chunk_id
  96. });
  97. if (res.retcode === 0) {
  98. visible.value = false;
  99. emit('canplaythrough');
  100. }
  101. }
  102. };
  103. const handleClick = () => {
  104. visible.value = true;
  105. };
  106. const handleBeforeOk = (done) => {
  107. formRef.value.validate().then((res) => {
  108. console.log('form:', form);
  109. });
  110. };
  111. const handleCancel = () => {
  112. visible.value = false;
  113. };
  114. const handleOpened = (el) => {
  115. console.log(props.item);
  116. nextTick(() => {
  117. Object.assign(form, props.item);
  118. console.log(form.important_kwd);
  119. });
  120. formRef.value.resetFields();
  121. keyVisible.value = false;
  122. };
  123. const deleteKey = (row) => {
  124. console.log(form.important_kwd);
  125. console.log(row);
  126. // form.important_kwd.splice(index, 1);
  127. form.important_kwd = form.important_kwd.filter((item) => item !== row);
  128. };
  129. const addKey = () => {
  130. form.important_kwd_key = '';
  131. formInput.value.focus();
  132. keyVisible.value = true;
  133. };
  134. const inputChange = (e) => {
  135. if (!form.important_kwd.includes(form.important_kwd_key) && form.important_kwd_key) {
  136. form.important_kwd.push(form.important_kwd_key);
  137. } else {
  138. }
  139. keyVisible.value = false;
  140. };
  141. onBeforeMount(() => {});
  142. onMounted(() => {});
  143. </script>