EditKBDialog.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <div class="edit-kb-dialog">
  3. <el-dialog v-model="dialogVisible" title="知识库设置" width="500" align-center
  4. @closed="emit('update:modelValue', false)">
  5. <el-form ref="formRef" style="max-width: 600px" :model="formData" label-width="auto" class="demo-dynamic">
  6. <label for="">知识库名称</label>
  7. <el-form-item prop="name" label="">
  8. <el-input v-model="formData.name" />
  9. </el-form-item>
  10. <label for="">知识库描述</label>
  11. <el-form-item prop="description" label="">
  12. <el-input type="textarea" v-model="formData.description" resize="none"
  13. :autosize="{ minRows: 3, maxRows: 3 }" />
  14. </el-form-item>
  15. </el-form>
  16. <template #footer>
  17. <div class="dialog-footer">
  18. <el-button @click="handleCancel">取消</el-button>
  19. <el-button type="primary" @click="handleConfirm">
  20. 保存
  21. </el-button>
  22. </div>
  23. </template>
  24. </el-dialog>
  25. </div>
  26. </template>
  27. <script setup>
  28. import { ref, watch, getCurrentInstance, toRaw } from "vue"
  29. import { api } from "@/utils/config"
  30. const { proxy } = getCurrentInstance()
  31. const props = defineProps({ modelValue: Boolean, knowledgeBase: Object })
  32. const emit = defineEmits(['update:modelValue', 'updateKB'])
  33. const formData = ref({ id: null, name: "", description: "" })
  34. let dialogVisible = ref(false)
  35. const handleCancel = () => {
  36. emit('update:modelValue', false)
  37. }
  38. const handleConfirm = () => {
  39. emit('update:modelValue', false)
  40. updateKB(formData.value)
  41. }
  42. watch(() => props.modelValue, (newVal) => {
  43. dialogVisible.value = newVal
  44. }, { immediate: true })
  45. watch(() => props.knowledgeBase, (newVal) => {
  46. formData.value = JSON.parse(JSON.stringify(newVal))
  47. }, { immediate: true, deep: true })
  48. const updateKB = async (formData) => {
  49. try {
  50. const data = await proxy.$http.put(api.knowledgeBase + `/${formData.id}`, {
  51. "name": formData.name,
  52. "description": formData.description,
  53. "tags": formData.tags
  54. })
  55. emit('updateKB')
  56. } catch (e) {
  57. console.log(e)
  58. }
  59. }
  60. </script>
  61. <style lang="less" scoped>
  62. .edit-kb-dialog {
  63. ::v-deep .el-dialog {
  64. label {
  65. margin: 20px 0px 10px;
  66. display: block;
  67. }
  68. }
  69. ::v-deep .el-form {
  70. .el-textarea__inner,
  71. .el-input__wrapper {
  72. background-color: #F1F3F6;
  73. }
  74. }
  75. }
  76. </style>